@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,151 @@
|
|
|
1
|
+
import { Injectable, Autowired } from '@opensumi/di';
|
|
2
|
+
import { Tree, ITreeNodeOrCompositeTreeNode, TreeNodeType } from '@opensumi/ide-components';
|
|
3
|
+
import { URI, formatLocalize, Emitter, Event, path, Schemes } from '@opensumi/ide-core-browser';
|
|
4
|
+
import { LabelService } from '@opensumi/ide-core-browser/lib/services';
|
|
5
|
+
import { WorkbenchEditorService, IEditorGroup, IResource, ResourceService } from '@opensumi/ide-editor';
|
|
6
|
+
import { IWorkspaceService } from '@opensumi/ide-workspace';
|
|
7
|
+
|
|
8
|
+
import { EditorFileGroup, EditorFile, EditorFileRoot, OpenedEditorData } from '../opened-editor-node.define';
|
|
9
|
+
|
|
10
|
+
const { Path } = path;
|
|
11
|
+
|
|
12
|
+
@Injectable()
|
|
13
|
+
export class OpenedEditorService extends Tree {
|
|
14
|
+
@Autowired(WorkbenchEditorService)
|
|
15
|
+
private readonly workbenchEditorService: WorkbenchEditorService;
|
|
16
|
+
|
|
17
|
+
@Autowired(IWorkspaceService)
|
|
18
|
+
private readonly workspaceService: IWorkspaceService;
|
|
19
|
+
|
|
20
|
+
@Autowired(LabelService)
|
|
21
|
+
public readonly labelService: LabelService;
|
|
22
|
+
|
|
23
|
+
@Autowired(ResourceService)
|
|
24
|
+
private readonly resourceService: ResourceService;
|
|
25
|
+
|
|
26
|
+
// 是否为分组的节点树
|
|
27
|
+
private isGroupTree = false;
|
|
28
|
+
|
|
29
|
+
private onDirtyNodesChangeEmitter: Emitter<EditorFile[]> = new Emitter();
|
|
30
|
+
|
|
31
|
+
get onDirtyNodesChange(): Event<EditorFile[]> {
|
|
32
|
+
return this.onDirtyNodesChangeEmitter.event;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async resolveChildren(
|
|
36
|
+
parent?: EditorFileRoot | EditorFileGroup,
|
|
37
|
+
): Promise<(EditorFileGroup | EditorFileRoot | EditorFile)[]> {
|
|
38
|
+
let children: (EditorFileGroup | EditorFileRoot | EditorFile)[] = [];
|
|
39
|
+
if (!parent) {
|
|
40
|
+
this._root = new EditorFileRoot(this);
|
|
41
|
+
children = [this._root as EditorFileRoot];
|
|
42
|
+
} else if (EditorFileRoot.is(parent)) {
|
|
43
|
+
// 重制isGroupTree状态
|
|
44
|
+
this.isGroupTree = false;
|
|
45
|
+
let groupOrResource: OpenedEditorData[] = [];
|
|
46
|
+
if (this.workbenchEditorService.sortedEditorGroups.length <= 1) {
|
|
47
|
+
groupOrResource = this.workbenchEditorService.sortedEditorGroups[0].resources.slice();
|
|
48
|
+
} else {
|
|
49
|
+
groupOrResource = this.workbenchEditorService.sortedEditorGroups;
|
|
50
|
+
}
|
|
51
|
+
for (const item of groupOrResource) {
|
|
52
|
+
if (!(item as IEditorGroup).resources) {
|
|
53
|
+
const tooltip = await this.getReadableTooltip((item as IResource).uri);
|
|
54
|
+
children.push(new EditorFile(this, item as IResource, tooltip, parent as EditorFileGroup));
|
|
55
|
+
} else {
|
|
56
|
+
this.isGroupTree = true;
|
|
57
|
+
const groupItem = new EditorFileGroup(this, item as IEditorGroup, parent);
|
|
58
|
+
children.push(groupItem);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
for (const resource of (parent as EditorFileGroup).group.resources) {
|
|
63
|
+
const tooltip = await this.getReadableTooltip(resource.uri);
|
|
64
|
+
children.push(new EditorFile(this, resource, tooltip, parent));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return children;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
sortComparator = (a: ITreeNodeOrCompositeTreeNode, b: ITreeNodeOrCompositeTreeNode) => {
|
|
71
|
+
if (a.constructor === b.constructor) {
|
|
72
|
+
if ((a as EditorFile).resource && (b as EditorFile).resource) {
|
|
73
|
+
const parent = (a as EditorFile).parent as EditorFileGroup;
|
|
74
|
+
if (parent.group) {
|
|
75
|
+
return (
|
|
76
|
+
parent.group.resources.indexOf((a as EditorFile).resource) -
|
|
77
|
+
parent.group.resources.indexOf((b as EditorFile).resource)
|
|
78
|
+
);
|
|
79
|
+
} else {
|
|
80
|
+
const currentGroup = this.workbenchEditorService.currentEditorGroup;
|
|
81
|
+
if (currentGroup && currentGroup.resources) {
|
|
82
|
+
return (
|
|
83
|
+
currentGroup.resources.indexOf((a as EditorFile).resource) -
|
|
84
|
+
currentGroup.resources.indexOf((b as EditorFile).resource)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// numeric 参数确保数字为第一排序优先级
|
|
90
|
+
return a.name.localeCompare(b.name, 'kn', { numeric: true }) as any;
|
|
91
|
+
}
|
|
92
|
+
return a.type === TreeNodeType.CompositeTreeNode ? -1 : b.type === TreeNodeType.CompositeTreeNode ? 1 : 0;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
public getEditorNodeByUri(resource?: IResource | URI, group?: IEditorGroup) {
|
|
96
|
+
let path = this.root!.path;
|
|
97
|
+
if (resource) {
|
|
98
|
+
if (this.isGroupTree) {
|
|
99
|
+
if (!group) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const groupName = formatLocalize('opened.editors.group.title', group.index + 1);
|
|
103
|
+
path = new Path(path)
|
|
104
|
+
.join(groupName)
|
|
105
|
+
.join(
|
|
106
|
+
resource && (resource as IResource).uri
|
|
107
|
+
? (resource as IResource).uri.toString()
|
|
108
|
+
: (resource as URI).toString(),
|
|
109
|
+
)
|
|
110
|
+
.toString();
|
|
111
|
+
} else {
|
|
112
|
+
path = new Path(path)
|
|
113
|
+
.join(
|
|
114
|
+
resource && (resource as IResource).uri
|
|
115
|
+
? (resource as IResource).uri.toString()
|
|
116
|
+
: (resource as URI).toString(),
|
|
117
|
+
)
|
|
118
|
+
.toString();
|
|
119
|
+
}
|
|
120
|
+
return this.root?.getTreeNodeByPath(path);
|
|
121
|
+
} else {
|
|
122
|
+
if (!group) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const groupName = formatLocalize('opened.editors.group.title', group.index + 1);
|
|
126
|
+
path = new Path(path).join(groupName).toString();
|
|
127
|
+
return this.root?.getTreeNodeByPath(path);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 获取相对路径的Tooltip
|
|
133
|
+
* 无法获取相对路径,则完整显示uri路径
|
|
134
|
+
* @param {URI} path
|
|
135
|
+
* @returns
|
|
136
|
+
* @memberof FileTreeAPI
|
|
137
|
+
*/
|
|
138
|
+
public async getReadableTooltip(path: URI) {
|
|
139
|
+
if (path.scheme !== Schemes.file) {
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
const roots = await this.workspaceService.roots;
|
|
143
|
+
for (const root of roots) {
|
|
144
|
+
const rootUri = new URI(root.uri);
|
|
145
|
+
if (rootUri.isEqualOrParent(path)) {
|
|
146
|
+
return decodeURIComponent(rootUri.relative(path)?.toString()!);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return path.toString();
|
|
150
|
+
}
|
|
151
|
+
}
|