|
4 | 4 | import * as fse from "fs-extra";
|
5 | 5 | import * as _ from "lodash";
|
6 | 6 | import * as path from "path";
|
7 |
| -import { commands, Disposable, ExtensionContext, TextEditor, TreeView, |
| 7 | +import { commands, Disposable, ExtensionContext, QuickPickItem, TextEditor, TreeView, |
8 | 8 | TreeViewExpansionEvent, TreeViewSelectionChangeEvent, TreeViewVisibilityChangeEvent, Uri, window } from "vscode";
|
9 | 9 | import { instrumentOperationAsVsCodeCommand, sendInfo } from "vscode-extension-telemetry-wrapper";
|
10 | 10 | import { Commands } from "../commands";
|
11 | 11 | import { Build } from "../constants";
|
12 | 12 | import { deleteFiles } from "../explorerCommands/delete";
|
| 13 | +import { newJavaClass, newPackage } from "../explorerCommands/new"; |
13 | 14 | import { renameFile } from "../explorerCommands/rename";
|
14 | 15 | import { getCmdNode } from "../explorerCommands/utility";
|
15 | 16 | import { Jdtls } from "../java/jdtls";
|
@@ -96,29 +97,43 @@ export class DependencyExplorer implements Disposable {
|
96 | 97 |
|
97 | 98 | // register keybinding commands
|
98 | 99 | context.subscriptions.push(
|
| 100 | + instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_CLASS, async (node?: DataNode) => { |
| 101 | + let cmdNode = getCmdNode(this._dependencyViewer.selection, node); |
| 102 | + if (!cmdNode) { |
| 103 | + cmdNode = await this.promptForProjectNode(); |
| 104 | + } |
| 105 | + newJavaClass(cmdNode); |
| 106 | + }), |
| 107 | + instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_PACKAGE, async (node?: DataNode) => { |
| 108 | + let cmdNode = getCmdNode(this._dependencyViewer.selection, node); |
| 109 | + if (!cmdNode) { |
| 110 | + cmdNode = await this.promptForProjectNode(); |
| 111 | + } |
| 112 | + newPackage(cmdNode); |
| 113 | + }), |
99 | 114 | instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_REVEAL_FILE_OS, (node?: DataNode) => {
|
100 |
| - const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node); |
101 |
| - if (cmdNode.uri) { |
| 115 | + const cmdNode = getCmdNode(this._dependencyViewer.selection, node); |
| 116 | + if (cmdNode?.uri) { |
102 | 117 | commands.executeCommand("revealFileInOS", Uri.parse(cmdNode.uri));
|
103 | 118 | }
|
104 | 119 | }),
|
105 | 120 | instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_FILE_PATH, (node?: DataNode) => {
|
106 |
| - const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node); |
107 |
| - if (cmdNode.uri) { |
| 121 | + const cmdNode = getCmdNode(this._dependencyViewer.selection, node); |
| 122 | + if (cmdNode?.uri) { |
108 | 123 | commands.executeCommand("copyFilePath", Uri.parse(cmdNode.uri));
|
109 | 124 | }
|
110 | 125 | }),
|
111 | 126 | instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_COPY_RELATIVE_FILE_PATH, (node?: DataNode) => {
|
112 |
| - const cmdNode = getCmdNode(this._dependencyViewer.selection[0], node); |
113 |
| - if (cmdNode.uri) { |
| 127 | + const cmdNode = getCmdNode(this._dependencyViewer.selection, node); |
| 128 | + if (cmdNode?.uri) { |
114 | 129 | commands.executeCommand("copyRelativeFilePath", Uri.parse(cmdNode.uri));
|
115 | 130 | }
|
116 | 131 | }),
|
117 | 132 | instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_RENAME_FILE, (node?: DataNode) => {
|
118 |
| - renameFile(getCmdNode(this._dependencyViewer.selection[0], node)); |
| 133 | + renameFile(getCmdNode(this._dependencyViewer.selection, node)); |
119 | 134 | }),
|
120 | 135 | instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_MOVE_FILE_TO_TRASH, (node?: DataNode) => {
|
121 |
| - deleteFiles(getCmdNode(this._dependencyViewer.selection[0], node)); |
| 136 | + deleteFiles(getCmdNode(this._dependencyViewer.selection, node)); |
122 | 137 | }),
|
123 | 138 | );
|
124 | 139 | }
|
@@ -162,4 +177,31 @@ export class DependencyExplorer implements Disposable {
|
162 | 177 | public get dataProvider(): DependencyDataProvider {
|
163 | 178 | return this._dataProvider;
|
164 | 179 | }
|
| 180 | + |
| 181 | + private async promptForProjectNode(): Promise<DataNode | undefined> { |
| 182 | + const projects = await this._dataProvider.getRootProjects(); |
| 183 | + if (projects.length === 0) { |
| 184 | + window.showInformationMessage("There is no Java projects in current workspace."); |
| 185 | + return undefined; |
| 186 | + } else if (projects.length === 1) { |
| 187 | + return projects[0] as DataNode; |
| 188 | + } else { |
| 189 | + const options: IProjectPickItem[] = projects.map((p: DataNode) => { |
| 190 | + return { |
| 191 | + label: p.name, |
| 192 | + node: p, |
| 193 | + }; |
| 194 | + }); |
| 195 | + const choice: IProjectPickItem | undefined = await window.showQuickPick(options, { |
| 196 | + placeHolder: "Choose a project", |
| 197 | + ignoreFocusOut: true, |
| 198 | + }); |
| 199 | + |
| 200 | + return choice?.node as DataNode; |
| 201 | + } |
| 202 | + } |
| 203 | +} |
| 204 | + |
| 205 | +interface IProjectPickItem extends QuickPickItem { |
| 206 | + node: ExplorerNode; |
165 | 207 | }
|
0 commit comments