@opensumi/ide-opened-editor 2.21.13 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/opened-editor-node.d.ts +1 -1
- package/lib/browser/opened-editor-node.d.ts.map +1 -1
- package/lib/browser/opened-editor-node.define.d.ts +1 -2
- package/lib/browser/opened-editor-node.define.d.ts.map +1 -1
- package/lib/browser/opened-editor-node.define.js +5 -9
- package/lib/browser/opened-editor-node.define.js.map +1 -1
- package/lib/browser/opened-editor-node.js +1 -1
- package/lib/browser/opened-editor-node.js.map +1 -1
- package/lib/browser/opened-editor-node.module.less +2 -14
- package/lib/browser/opened-editor.contribution.js.map +1 -1
- package/lib/browser/opened-editor.d.ts.map +1 -1
- package/lib/browser/opened-editor.js +15 -15
- package/lib/browser/opened-editor.js.map +1 -1
- package/lib/browser/services/opened-editor-decoration.service.js.map +1 -1
- package/lib/browser/services/opened-editor-event.service.d.ts +1 -1
- package/lib/browser/services/opened-editor-event.service.d.ts.map +1 -1
- package/lib/browser/services/opened-editor-event.service.js.map +1 -1
- package/lib/browser/services/opened-editor-model.js.map +1 -1
- package/lib/browser/services/opened-editor-model.service.d.ts +2 -2
- package/lib/browser/services/opened-editor-model.service.d.ts.map +1 -1
- package/lib/browser/services/opened-editor-model.service.js.map +1 -1
- package/lib/browser/services/opened-editor-tree.service.js.map +1 -1
- package/package.json +16 -15
- package/src/browser/index.module.less +24 -0
- package/src/browser/index.ts +26 -0
- package/src/browser/opened-editor-node.define.ts +82 -0
- package/src/browser/opened-editor-node.module.less +182 -0
- package/src/browser/opened-editor-node.tsx +232 -0
- package/src/browser/opened-editor.contribution.ts +193 -0
- package/src/browser/opened-editor.tsx +183 -0
- package/src/browser/services/opened-editor-decoration.service.ts +63 -0
- package/src/browser/services/opened-editor-event.service.ts +51 -0
- package/src/browser/services/opened-editor-model.service.ts +549 -0
- package/src/browser/services/opened-editor-model.ts +47 -0
- package/src/browser/services/opened-editor-tree.service.ts +151 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Provider, Injectable } from '@opensumi/di';
|
|
2
|
+
import { BrowserModule } from '@opensumi/ide-core-browser';
|
|
3
|
+
|
|
4
|
+
import { OpenedEditorContribution } from './opened-editor.contribution';
|
|
5
|
+
import { OpenedEditorDecorationService } from './services/opened-editor-decoration.service';
|
|
6
|
+
import { OpenedEditorModelService } from './services/opened-editor-model.service';
|
|
7
|
+
import { OpenedEditorService } from './services/opened-editor-tree.service';
|
|
8
|
+
|
|
9
|
+
@Injectable()
|
|
10
|
+
export class OpenedEditorModule extends BrowserModule {
|
|
11
|
+
providers: Provider[] = [
|
|
12
|
+
{
|
|
13
|
+
token: OpenedEditorDecorationService,
|
|
14
|
+
useClass: OpenedEditorDecorationService,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
token: OpenedEditorService,
|
|
18
|
+
useClass: OpenedEditorService,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
token: OpenedEditorModelService,
|
|
22
|
+
useClass: OpenedEditorModelService,
|
|
23
|
+
},
|
|
24
|
+
OpenedEditorContribution,
|
|
25
|
+
];
|
|
26
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { TreeNode, CompositeTreeNode, ITree } from '@opensumi/ide-components';
|
|
2
|
+
import { formatLocalize, URI } from '@opensumi/ide-core-browser';
|
|
3
|
+
import { IEditorGroup, IResource } from '@opensumi/ide-editor';
|
|
4
|
+
|
|
5
|
+
import { OpenedEditorService } from './services/opened-editor-tree.service';
|
|
6
|
+
|
|
7
|
+
export type OpenedEditorData = IEditorGroup | IResource;
|
|
8
|
+
|
|
9
|
+
export class EditorFileRoot extends CompositeTreeNode {
|
|
10
|
+
static is(node: EditorFileGroup | EditorFileRoot): node is EditorFileRoot {
|
|
11
|
+
return !!node && !node.parent;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
constructor(tree: OpenedEditorService) {
|
|
15
|
+
super(tree as ITree, undefined);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get expanded() {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// EditorFileGroup 节点不包含父节点, 同时默认为展开状态
|
|
24
|
+
export class EditorFileGroup extends CompositeTreeNode {
|
|
25
|
+
static isEditorGroup(data: OpenedEditorData): data is IEditorGroup {
|
|
26
|
+
return typeof (data as any).resources !== 'undefined';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static is(node: EditorFileGroup | EditorFile): node is EditorFileGroup {
|
|
30
|
+
return !!node && !!(node as EditorFileGroup).group;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private groupIndex: number;
|
|
34
|
+
|
|
35
|
+
constructor(tree: OpenedEditorService, public readonly group: IEditorGroup, parent: EditorFileRoot) {
|
|
36
|
+
super(tree as ITree, parent);
|
|
37
|
+
this.groupIndex = this.group.index;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get expanded() {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get name() {
|
|
45
|
+
return formatLocalize('opened.editors.group.title', this.groupIndex + 1);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get displayName() {
|
|
49
|
+
return this.name;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get tooltip() {
|
|
53
|
+
return this.name;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
dispose() {
|
|
57
|
+
super.dispose();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class EditorFile extends TreeNode {
|
|
62
|
+
constructor(
|
|
63
|
+
tree: OpenedEditorService,
|
|
64
|
+
public readonly resource: IResource,
|
|
65
|
+
public tooltip: string,
|
|
66
|
+
parent: EditorFileGroup | undefined,
|
|
67
|
+
) {
|
|
68
|
+
super(tree as ITree, parent, undefined, { name: `${resource.uri.toString()}` });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get displayName() {
|
|
72
|
+
return this.resource ? this.resource.name : '';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get uri() {
|
|
76
|
+
return this.resource ? this.resource.uri : new URI();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
dispose() {
|
|
80
|
+
super.dispose();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
.opened_editor_node {
|
|
2
|
+
height: 22px;
|
|
3
|
+
line-height: 22px;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
position: relative;
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
|
|
9
|
+
&:hover {
|
|
10
|
+
color: var(--kt-tree-hoverForeground);
|
|
11
|
+
background: var(--kt-tree-hoverBackground);
|
|
12
|
+
.opened_editor_action_bar {
|
|
13
|
+
display: block;
|
|
14
|
+
}
|
|
15
|
+
&::before {
|
|
16
|
+
display: none !important;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
&.mod_selected {
|
|
21
|
+
color: var(--kt-tree-inactiveSelectionForeground) !important;
|
|
22
|
+
background: var(--kt-tree-inactiveSelectionBackground);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&.mod_focused {
|
|
26
|
+
outline: 1px solid var(--list-focusOutline);
|
|
27
|
+
outline-offset: -1px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&.mod_actived {
|
|
31
|
+
outline: 1px solid var(--list-focusOutline);
|
|
32
|
+
outline-offset: -1px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&.mod_dirty {
|
|
36
|
+
&::before {
|
|
37
|
+
content: '';
|
|
38
|
+
display: block;
|
|
39
|
+
width: 8px;
|
|
40
|
+
height: 8px;
|
|
41
|
+
border-radius: 4px;
|
|
42
|
+
margin: 7px 5px;
|
|
43
|
+
background: var(--kt-dirtyDot-foreground);
|
|
44
|
+
position: absolute;
|
|
45
|
+
left: 18px;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.opened_editor_node_description {
|
|
51
|
+
display: inline;
|
|
52
|
+
transform: scale(0.96);
|
|
53
|
+
color: var(--descriptionForeground);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.opened_editor_node_content {
|
|
57
|
+
position: relative;
|
|
58
|
+
display: flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
width: 100%;
|
|
61
|
+
|
|
62
|
+
match {
|
|
63
|
+
background-color: var(--editor-findMatchHighlightBackground);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.opened_editor_node_status {
|
|
68
|
+
opacity: 0.75;
|
|
69
|
+
text-align: center;
|
|
70
|
+
font-size: 12px;
|
|
71
|
+
padding-right: 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.opened_editor_node_segment {
|
|
75
|
+
flex-grow: 0;
|
|
76
|
+
white-space: nowrap;
|
|
77
|
+
color: inherit;
|
|
78
|
+
&_grow {
|
|
79
|
+
flex-grow: 1 !important;
|
|
80
|
+
text-align: left;
|
|
81
|
+
z-index: 10;
|
|
82
|
+
padding-right: 5px;
|
|
83
|
+
|
|
84
|
+
&.overflow_visible {
|
|
85
|
+
overflow: visible !important;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.opened_editor_node_displayname {
|
|
91
|
+
margin-right: 6px;
|
|
92
|
+
display: inline;
|
|
93
|
+
white-space: pre;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.opened_editor_node_description {
|
|
97
|
+
display: inline;
|
|
98
|
+
transform: scale(0.96);
|
|
99
|
+
color: var(--descriptionForeground);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.opened_editor_node_overflow_wrap {
|
|
103
|
+
flex: 1;
|
|
104
|
+
flex-shrink: 0;
|
|
105
|
+
overflow: hidden;
|
|
106
|
+
text-overflow: ellipsis;
|
|
107
|
+
white-space: nowrap;
|
|
108
|
+
text-align: left;
|
|
109
|
+
color: var(--foreground);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.opened_editor_node_flex_wrap {
|
|
113
|
+
display: flex;
|
|
114
|
+
flex-direction: row;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.opened_editor_node_segment_grow {
|
|
118
|
+
flex-grow: 1 !important;
|
|
119
|
+
text-align: left;
|
|
120
|
+
z-index: 10;
|
|
121
|
+
padding-right: 5px;
|
|
122
|
+
|
|
123
|
+
&.overflow_visible {
|
|
124
|
+
overflow: visible !important;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.file_icon {
|
|
129
|
+
position: relative;
|
|
130
|
+
color: var(--icon-foreground);
|
|
131
|
+
margin-right: 4px;
|
|
132
|
+
&:before {
|
|
133
|
+
font-size: 16px;
|
|
134
|
+
text-align: center;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.file_icon:global(&.fileIcon:before) {
|
|
139
|
+
font-size: 18px;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.opened_editor_node_tail {
|
|
143
|
+
text-align: center;
|
|
144
|
+
margin-right: 10px;
|
|
145
|
+
position: relative;
|
|
146
|
+
height: 22px;
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.opened_editor_action_bar {
|
|
152
|
+
position: absolute;
|
|
153
|
+
top: 0;
|
|
154
|
+
left: 0;
|
|
155
|
+
width: 100%;
|
|
156
|
+
display: flex;
|
|
157
|
+
display: none;
|
|
158
|
+
z-index: 10;
|
|
159
|
+
.action_icon {
|
|
160
|
+
margin-left: 6px;
|
|
161
|
+
font-size: 14px;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.opened_editor_left_actions {
|
|
166
|
+
position: absolute;
|
|
167
|
+
left: 14px;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.opened_editor_right_actions {
|
|
171
|
+
right: 0;
|
|
172
|
+
position: absolute;
|
|
173
|
+
margin-right: 10px;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.opened_editor_left_actions,
|
|
177
|
+
.opened_editor_right_actions {
|
|
178
|
+
display: flex;
|
|
179
|
+
align-items: center;
|
|
180
|
+
justify-content: center;
|
|
181
|
+
height: 22px;
|
|
182
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import cls from 'classnames';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
TreeNode,
|
|
6
|
+
CompositeTreeNode,
|
|
7
|
+
INodeRendererProps,
|
|
8
|
+
ClasslistComposite,
|
|
9
|
+
TreeNodeType,
|
|
10
|
+
Button,
|
|
11
|
+
} from '@opensumi/ide-components';
|
|
12
|
+
import { URI, OPEN_EDITORS_COMMANDS, localize, getIcon, CommandService } from '@opensumi/ide-core-browser';
|
|
13
|
+
import { LabelService } from '@opensumi/ide-core-browser/lib/services';
|
|
14
|
+
import { EDITOR_WEBVIEW_SCHEME } from '@opensumi/ide-webview';
|
|
15
|
+
|
|
16
|
+
import { EditorFileGroup, EditorFile } from './opened-editor-node.define';
|
|
17
|
+
import styles from './opened-editor-node.module.less';
|
|
18
|
+
import { OpenedEditorDecorationService } from './services/opened-editor-decoration.service';
|
|
19
|
+
|
|
20
|
+
export interface IEditorNodeProps {
|
|
21
|
+
item: any;
|
|
22
|
+
defaultLeftPadding?: number;
|
|
23
|
+
leftPadding?: number;
|
|
24
|
+
decorationService: OpenedEditorDecorationService;
|
|
25
|
+
commandService: CommandService;
|
|
26
|
+
labelService: LabelService;
|
|
27
|
+
decorations?: ClasslistComposite;
|
|
28
|
+
onClick: (ev: React.MouseEvent, item: TreeNode | CompositeTreeNode, type: TreeNodeType, activeUri?: URI) => void;
|
|
29
|
+
onContextMenu: (
|
|
30
|
+
ev: React.MouseEvent,
|
|
31
|
+
item: TreeNode | CompositeTreeNode,
|
|
32
|
+
type: TreeNodeType,
|
|
33
|
+
activeUri?: URI,
|
|
34
|
+
) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type EditorNodeRenderedProps = IEditorNodeProps & INodeRendererProps;
|
|
38
|
+
|
|
39
|
+
export const EditorTreeNode: React.FC<EditorNodeRenderedProps> = ({
|
|
40
|
+
item,
|
|
41
|
+
defaultLeftPadding = 8,
|
|
42
|
+
leftPadding = 8,
|
|
43
|
+
onClick,
|
|
44
|
+
onContextMenu,
|
|
45
|
+
itemType,
|
|
46
|
+
decorationService,
|
|
47
|
+
labelService,
|
|
48
|
+
commandService,
|
|
49
|
+
decorations,
|
|
50
|
+
}: EditorNodeRenderedProps) => {
|
|
51
|
+
const decoration = EditorFileGroup.is(item) ? null : decorationService.getDecoration(item.uri, false);
|
|
52
|
+
|
|
53
|
+
const handleClick = (ev: React.MouseEvent) => {
|
|
54
|
+
if (itemType === TreeNodeType.TreeNode || itemType === TreeNodeType.CompositeTreeNode) {
|
|
55
|
+
onClick(ev, item as EditorFile, itemType);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleContextMenu = (ev: React.MouseEvent) => {
|
|
60
|
+
if (ev.nativeEvent.which === 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (itemType === TreeNodeType.TreeNode || itemType === TreeNodeType.CompositeTreeNode) {
|
|
64
|
+
onContextMenu(ev, item as TreeNode, itemType);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const paddingLeft = `${
|
|
69
|
+
defaultLeftPadding + (item.depth || 0) * (leftPadding || 0) + (!EditorFileGroup.is(item) ? 16 : 0)
|
|
70
|
+
}px`;
|
|
71
|
+
|
|
72
|
+
const editorNodeStyle = {
|
|
73
|
+
color: decoration ? decoration.color : '',
|
|
74
|
+
height: OPENED_EDITOR_TREE_NODE_HEIGHT,
|
|
75
|
+
lineHeight: `${OPENED_EDITOR_TREE_NODE_HEIGHT}px`,
|
|
76
|
+
paddingLeft,
|
|
77
|
+
} as React.CSSProperties;
|
|
78
|
+
|
|
79
|
+
const renderIcon = (node: EditorFileGroup | EditorFile) => {
|
|
80
|
+
if (EditorFileGroup.is(node)) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const iconClass = node.resource.icon || labelService.getIcon((node as EditorFile).uri, { isDirectory: false });
|
|
84
|
+
return (
|
|
85
|
+
<div
|
|
86
|
+
className={cls(styles.file_icon, iconClass)}
|
|
87
|
+
style={{ height: OPENED_EDITOR_TREE_NODE_HEIGHT, lineHeight: `${OPENED_EDITOR_TREE_NODE_HEIGHT}px` }}
|
|
88
|
+
></div>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const getNodeName = (node: EditorFileGroup | EditorFile) => {
|
|
93
|
+
if (!EditorFileGroup.is(node)) {
|
|
94
|
+
if (node.uri.scheme === EDITOR_WEBVIEW_SCHEME) {
|
|
95
|
+
return node.displayName;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return node.displayName || labelService.getName(node.uri);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return node.displayName;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const renderDisplayName = (node: EditorFileGroup | EditorFile) => (
|
|
105
|
+
<div className={cls(styles.opened_editor_node_segment, styles.opened_editor_node_displayname)}>
|
|
106
|
+
{getNodeName(node)}
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const renderDescription = (node: EditorFileGroup | EditorFile) => {
|
|
111
|
+
if (EditorFileGroup.is(node)) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return (
|
|
115
|
+
<div className={cls(styles.opened_editor_node_segment_grow, styles.opened_editor_node_description)}>
|
|
116
|
+
{node.tooltip}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const renderStatusTail = () => (
|
|
122
|
+
<div className={cls(styles.opened_editor_node_segment, styles.opened_editor_node_tail)}>{renderBadge()}</div>
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const renderBadge = () => {
|
|
126
|
+
if (!decoration) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
return <div className={styles.opened_editor_node_status}>{decoration.badge.slice()}</div>;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const getItemTooltip = () => {
|
|
133
|
+
let tooltip = item.tooltip;
|
|
134
|
+
if (decoration && decoration.badge) {
|
|
135
|
+
tooltip += ` • ${decoration.tooltip}`;
|
|
136
|
+
}
|
|
137
|
+
return tooltip;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const renderAction = () => {
|
|
141
|
+
let actions: any[] = [];
|
|
142
|
+
if (EditorFileGroup.is(item)) {
|
|
143
|
+
actions = [
|
|
144
|
+
{
|
|
145
|
+
icon: getIcon('save-all'),
|
|
146
|
+
title: localize('opened.editors.save.byGroup'),
|
|
147
|
+
command: OPEN_EDITORS_COMMANDS.SAVE_BY_GROUP.id,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
icon: getIcon('clear'),
|
|
151
|
+
title: localize('opened.editors.close.byGroup'),
|
|
152
|
+
command: OPEN_EDITORS_COMMANDS.CLOSE_BY_GROUP.id,
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
return (
|
|
156
|
+
<div className={styles.opened_editor_right_actions}>
|
|
157
|
+
{actions.map((action) => {
|
|
158
|
+
const clickHandler = (event: React.MouseEvent) => {
|
|
159
|
+
event.stopPropagation();
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
commandService.executeCommand(action.command, item);
|
|
162
|
+
};
|
|
163
|
+
return (
|
|
164
|
+
<Button
|
|
165
|
+
type='icon'
|
|
166
|
+
key={`${item.id}-${action.command}`}
|
|
167
|
+
iconClass={cls(styles.action_icon, action.icon)}
|
|
168
|
+
title={action.title}
|
|
169
|
+
onClick={clickHandler}
|
|
170
|
+
/>
|
|
171
|
+
);
|
|
172
|
+
})}
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
} else {
|
|
176
|
+
actions = [
|
|
177
|
+
{
|
|
178
|
+
icon: getIcon('close'),
|
|
179
|
+
title: localize('file.close'),
|
|
180
|
+
command: OPEN_EDITORS_COMMANDS.CLOSE.id,
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
return (
|
|
184
|
+
<div className={styles.opened_editor_left_actions}>
|
|
185
|
+
{actions.map((action) => {
|
|
186
|
+
const clickHandler = (event: React.MouseEvent) => {
|
|
187
|
+
event.stopPropagation();
|
|
188
|
+
event.preventDefault();
|
|
189
|
+
commandService.executeCommand(action.command, item);
|
|
190
|
+
};
|
|
191
|
+
return (
|
|
192
|
+
<Button
|
|
193
|
+
type='icon'
|
|
194
|
+
key={`${item.id}-${action.command}`}
|
|
195
|
+
iconClass={cls(styles.action_icon, action.icon)}
|
|
196
|
+
title={action.title}
|
|
197
|
+
onClick={clickHandler}
|
|
198
|
+
/>
|
|
199
|
+
);
|
|
200
|
+
})}
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const renderActionBar = () => <div className={styles.opened_editor_action_bar}>{renderAction()}</div>;
|
|
207
|
+
|
|
208
|
+
return (
|
|
209
|
+
<div
|
|
210
|
+
key={item.id}
|
|
211
|
+
onClick={handleClick}
|
|
212
|
+
onContextMenu={handleContextMenu}
|
|
213
|
+
title={getItemTooltip()}
|
|
214
|
+
className={cls(styles.opened_editor_node, decorations ? decorations.classlist : null)}
|
|
215
|
+
style={editorNodeStyle}
|
|
216
|
+
data-id={item.id}
|
|
217
|
+
>
|
|
218
|
+
{renderActionBar()}
|
|
219
|
+
<div className={cls(styles.opened_editor_node_content)}>
|
|
220
|
+
{renderIcon(item)}
|
|
221
|
+
<div className={styles.opened_editor_node_overflow_wrap}>
|
|
222
|
+
{renderDisplayName(item)}
|
|
223
|
+
{renderDescription(item)}
|
|
224
|
+
</div>
|
|
225
|
+
{renderStatusTail()}
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
);
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export const OPENED_EDITOR_TREE_NODE_HEIGHT = 22;
|
|
232
|
+
export const OPENED_EDITOR_BADGE_LIMIT = 99;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Autowired } from '@opensumi/di';
|
|
2
|
+
import {
|
|
3
|
+
Domain,
|
|
4
|
+
localize,
|
|
5
|
+
CommandContribution,
|
|
6
|
+
CommandRegistry,
|
|
7
|
+
OPEN_EDITORS_COMMANDS,
|
|
8
|
+
CommandService,
|
|
9
|
+
FILE_COMMANDS,
|
|
10
|
+
EDITOR_COMMANDS,
|
|
11
|
+
} from '@opensumi/ide-core-browser';
|
|
12
|
+
import { ClientAppContribution } from '@opensumi/ide-core-browser';
|
|
13
|
+
import { ToolbarRegistry, TabBarToolbarContribution } from '@opensumi/ide-core-browser/lib/layout';
|
|
14
|
+
import { MenuContribution, IMenuRegistry, MenuId } from '@opensumi/ide-core-browser/lib/menu/next';
|
|
15
|
+
import { WorkbenchEditorService } from '@opensumi/ide-editor';
|
|
16
|
+
import { EXPLORER_CONTAINER_ID } from '@opensumi/ide-explorer/lib/browser/explorer-contribution';
|
|
17
|
+
import { IMainLayoutService } from '@opensumi/ide-main-layout';
|
|
18
|
+
|
|
19
|
+
import { ExplorerOpenEditorPanel } from './opened-editor';
|
|
20
|
+
import { EditorFile, EditorFileGroup } from './opened-editor-node.define';
|
|
21
|
+
import { OpenedEditorModelService } from './services/opened-editor-model.service';
|
|
22
|
+
|
|
23
|
+
export const ExplorerOpenedEditorViewId = 'file-opened-editor';
|
|
24
|
+
|
|
25
|
+
@Domain(ClientAppContribution, TabBarToolbarContribution, CommandContribution, MenuContribution)
|
|
26
|
+
export class OpenedEditorContribution
|
|
27
|
+
implements ClientAppContribution, TabBarToolbarContribution, CommandContribution, MenuContribution
|
|
28
|
+
{
|
|
29
|
+
@Autowired(IMainLayoutService)
|
|
30
|
+
private readonly mainLayoutService: IMainLayoutService;
|
|
31
|
+
|
|
32
|
+
@Autowired(WorkbenchEditorService)
|
|
33
|
+
private readonly workbenchEditorService: WorkbenchEditorService;
|
|
34
|
+
|
|
35
|
+
@Autowired(OpenedEditorModelService)
|
|
36
|
+
private readonly openedEditorModelService: OpenedEditorModelService;
|
|
37
|
+
|
|
38
|
+
@Autowired(CommandService)
|
|
39
|
+
private readonly commandService: CommandService;
|
|
40
|
+
|
|
41
|
+
async onStart() {
|
|
42
|
+
this.mainLayoutService.collectViewComponent(
|
|
43
|
+
{
|
|
44
|
+
id: ExplorerOpenedEditorViewId,
|
|
45
|
+
name: localize('opened.editors.title'),
|
|
46
|
+
weight: 1,
|
|
47
|
+
priority: 10,
|
|
48
|
+
collapsed: true,
|
|
49
|
+
component: ExplorerOpenEditorPanel,
|
|
50
|
+
},
|
|
51
|
+
EXPLORER_CONTAINER_ID,
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
registerCommands(commands: CommandRegistry) {
|
|
56
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.SAVE_ALL, {
|
|
57
|
+
execute: () => {
|
|
58
|
+
this.workbenchEditorService.saveAll();
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.CLOSE_ALL, {
|
|
63
|
+
execute: async () => {
|
|
64
|
+
await this.workbenchEditorService.closeAll();
|
|
65
|
+
this.openedEditorModelService.clear();
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.CLOSE_BY_GROUP, {
|
|
70
|
+
execute: (node: EditorFileGroup) => {
|
|
71
|
+
this.openedEditorModelService.closeAllByGroup(node);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.SAVE_BY_GROUP, {
|
|
76
|
+
execute: (node: EditorFileGroup) => {
|
|
77
|
+
this.openedEditorModelService.saveAllByGroup(node);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.CLOSE, {
|
|
82
|
+
execute: async (node: EditorFile) => {
|
|
83
|
+
let group;
|
|
84
|
+
if (node.parent && EditorFileGroup.is(node.parent as EditorFileGroup)) {
|
|
85
|
+
group = (node.parent as EditorFileGroup).group;
|
|
86
|
+
}
|
|
87
|
+
await this.commandService.executeCommand(EDITOR_COMMANDS.CLOSE.id, { group, uri: node.uri });
|
|
88
|
+
// 提前移除节点
|
|
89
|
+
(node.parent as EditorFileGroup).unlinkItem(node);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.OPEN, {
|
|
94
|
+
execute: (node: EditorFile) => {
|
|
95
|
+
let groupIndex = 0;
|
|
96
|
+
if (node.parent && EditorFileGroup.is(node.parent as EditorFileGroup)) {
|
|
97
|
+
groupIndex = (node.parent as EditorFileGroup).group.index;
|
|
98
|
+
}
|
|
99
|
+
this.commandService.executeCommand(EDITOR_COMMANDS.OPEN_RESOURCE.id, node.uri, { groupIndex });
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.OPEN_TO_THE_SIDE, {
|
|
104
|
+
execute: (node: EditorFile) => {
|
|
105
|
+
let groupIndex = 0;
|
|
106
|
+
if (node.parent && EditorFileGroup.is(node.parent as EditorFileGroup)) {
|
|
107
|
+
groupIndex = (node.parent as EditorFileGroup).group.index;
|
|
108
|
+
}
|
|
109
|
+
this.commandService.executeCommand(EDITOR_COMMANDS.OPEN_RESOURCE.id, node.uri, {
|
|
110
|
+
groupIndex,
|
|
111
|
+
split: 4 /** right */,
|
|
112
|
+
focus: true,
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.COMPARE_SELECTED, {
|
|
118
|
+
execute: (node: EditorFile) => {
|
|
119
|
+
this.commandService.executeCommand(FILE_COMMANDS.COMPARE_SELECTED.id, node.uri, [node.uri]);
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.COPY_PATH, {
|
|
124
|
+
execute: (node: EditorFile) => {
|
|
125
|
+
this.commandService.executeCommand(FILE_COMMANDS.COPY_PATH.id, node.uri, [node.uri]);
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
commands.registerCommand(OPEN_EDITORS_COMMANDS.COPY_RELATIVE_PATH, {
|
|
130
|
+
execute: (node: EditorFile) => {
|
|
131
|
+
this.commandService.executeCommand(FILE_COMMANDS.COPY_RELATIVE_PATH.id, node.uri, [node.uri]);
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
registerToolbarItems(registry: ToolbarRegistry) {
|
|
137
|
+
registry.registerItem({
|
|
138
|
+
id: OPEN_EDITORS_COMMANDS.SAVE_ALL.id,
|
|
139
|
+
command: OPEN_EDITORS_COMMANDS.SAVE_ALL.id,
|
|
140
|
+
viewId: ExplorerOpenedEditorViewId,
|
|
141
|
+
label: localize('opened.editors.save.all'),
|
|
142
|
+
});
|
|
143
|
+
registry.registerItem({
|
|
144
|
+
id: OPEN_EDITORS_COMMANDS.CLOSE_ALL.id,
|
|
145
|
+
command: OPEN_EDITORS_COMMANDS.CLOSE_ALL.id,
|
|
146
|
+
viewId: ExplorerOpenedEditorViewId,
|
|
147
|
+
label: localize('opened.editors.close.all'),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
registerMenus(menuRegistry: IMenuRegistry): void {
|
|
152
|
+
menuRegistry.registerMenuItem(MenuId.OpenEditorsContext, {
|
|
153
|
+
command: {
|
|
154
|
+
id: OPEN_EDITORS_COMMANDS.OPEN.id,
|
|
155
|
+
label: localize('opened.editors.open'),
|
|
156
|
+
},
|
|
157
|
+
order: 1,
|
|
158
|
+
group: '1_open',
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
menuRegistry.registerMenuItem(MenuId.OpenEditorsContext, {
|
|
162
|
+
command: {
|
|
163
|
+
id: OPEN_EDITORS_COMMANDS.OPEN_TO_THE_SIDE.id,
|
|
164
|
+
label: localize('opened.editors.openToTheSide'),
|
|
165
|
+
},
|
|
166
|
+
order: 2,
|
|
167
|
+
group: '1_open',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
menuRegistry.registerMenuItem(MenuId.OpenEditorsContext, {
|
|
171
|
+
command: {
|
|
172
|
+
id: OPEN_EDITORS_COMMANDS.COMPARE_SELECTED.id,
|
|
173
|
+
label: localize('opened.editors.compare'),
|
|
174
|
+
},
|
|
175
|
+
group: '2_operator',
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
menuRegistry.registerMenuItem(MenuId.OpenEditorsContext, {
|
|
179
|
+
command: {
|
|
180
|
+
id: OPEN_EDITORS_COMMANDS.COPY_PATH.id,
|
|
181
|
+
label: localize('opened.editors.copyPath'),
|
|
182
|
+
},
|
|
183
|
+
group: '3_path',
|
|
184
|
+
});
|
|
185
|
+
menuRegistry.registerMenuItem(MenuId.OpenEditorsContext, {
|
|
186
|
+
command: {
|
|
187
|
+
id: OPEN_EDITORS_COMMANDS.COPY_RELATIVE_PATH.id,
|
|
188
|
+
label: localize('opened.editors.copyRelativePath'),
|
|
189
|
+
},
|
|
190
|
+
group: '3_path',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|