diff --git a/package.json b/package.json index fbc0ec4e..969f11a9 100644 --- a/package.json +++ b/package.json @@ -147,7 +147,12 @@ "category": "ONE" }, { - "command": "one.explorer.reveal", + "command": "one.explorer.revealInOneExplorer", + "title": "Reveal in ONE Explorer View", + "category": "ONE" + }, + { + "command": "one.explorer.revealInDefaultExplorer", "title": "Reveal in Explorer View", "category": "ONE" }, @@ -252,7 +257,7 @@ "group": "3_open@1" }, { - "command": "one.explorer.reveal", + "command": "one.explorer.revealInDefaultExplorer", "when": "view == OneExplorerView && viewItem != directory", "group": "3_open@3" }, @@ -306,7 +311,7 @@ "when": "false" }, { - "command": "one.explorer.reveal", + "command": "one.explorer.revealInDefaultExplorer", "when": "false" }, { diff --git a/src/CfgEditor/CfgEditorPanel.ts b/src/CfgEditor/CfgEditorPanel.ts index 132cd125..1de1c5cc 100644 --- a/src/CfgEditor/CfgEditorPanel.ts +++ b/src/CfgEditor/CfgEditorPanel.ts @@ -175,6 +175,9 @@ export class CfgEditorPanel implements vscode.CustomTextEditorProvider { }); webviewPanel.onDidChangeViewState(e => { + if (webviewPanel.visible) { + vscode.commands.executeCommand('one.explorer.revealInOneExplorer', document.fileName); + } vscode.commands.executeCommand('setContext', CfgEditorPanel.viewType, webviewPanel.visible); }, null, this._disposables); diff --git a/src/OneExplorer/OneExplorer.ts b/src/OneExplorer/OneExplorer.ts index 9c038a6c..530e81ec 100644 --- a/src/OneExplorer/OneExplorer.ts +++ b/src/OneExplorer/OneExplorer.ts @@ -468,7 +468,9 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { private fileWatcher = vscode.workspace.createFileSystemWatcher(`**/*`); - private tree: DirectoryNode|undefined; + private _tree: DirectoryNode|undefined; + private _nodeMap: Map = new Map(); + public static didHideExtra: boolean = false; public static register(context: vscode.ExtensionContext) { @@ -493,20 +495,30 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { const provider = new OneTreeDataProvider(workspaceRoot, context.extension.extensionKind); + const _treeView = vscode.window.createTreeView( + 'OneExplorerView', + {treeDataProvider: provider, showCollapseAll: true, canSelectMany: true}); + let registrations = [ provider.fileWatcher.onDidCreate(() => provider.refresh()), provider.fileWatcher.onDidChange(() => provider.refresh()), provider.fileWatcher.onDidDelete(() => provider.refresh()), - vscode.window.createTreeView( - 'OneExplorerView', - {treeDataProvider: provider, showCollapseAll: true, canSelectMany: true}), + _treeView, + vscode.commands.registerCommand( + 'one.explorer.revealInOneExplorer', + (path: string) => { + const node = provider._nodeMap.get(path); + if (node) { + _treeView ?.reveal(node, {select: true, focus: true, expand: true}); + } + }), vscode.commands.registerCommand( 'one.explorer.openAsText', (node: Node) => { vscode.commands.executeCommand('vscode.openWith', node.uri, 'default'); }), vscode.commands.registerCommand( - 'one.explorer.reveal', + 'one.explorer.revealInDefaultExplorer', (node: Node) => { vscode.commands.executeCommand('revealInExplorer', node.uri); }), @@ -602,7 +614,8 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { if (!node) { // Reset the root in order to build from scratch (at OneTreeDataProvider.getTree) - this.tree = undefined; + this._tree = undefined; + this._nodeMap.clear(); this._onDidChangeTreeData.fire(undefined); } else { this._onDidChangeTreeData.fire(node); @@ -772,11 +785,27 @@ input_path=${modelName}.${extName} return undefined; } - if (!this.tree) { - this.tree = NodeFactory.create(NodeType.directory, this.workspaceRoot.fsPath, undefined) as + if (!this._tree) { + this._tree = NodeFactory.create(NodeType.directory, this.workspaceRoot.fsPath, undefined) as DirectoryNode; + + // NOTE That this change reverts the 'build children on demand' optimization. + // + // 'buildNodeMap' is required for revealing the corresponding TreeItem when a cfg file is + // opened in cfg editor, because it pre-builts all the nodes to find the Node from a given + // string path. + // + // TODO Let's try to build nodes on demand (only with string path) + const buildNodeMap = (node: Node) => { + node.getChildren().forEach(childNode => { + this._nodeMap.set(childNode.path, childNode); + buildNodeMap(childNode); + }); + }; + + buildNodeMap(this._tree); } - return this.tree; + return this._tree; } }