Skip to content

Commit 2f19d45

Browse files
authored
Only show the shortcut when Maven extension is enabled (#232)
1 parent 3948146 commit 2f19d45

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
},
263263
{
264264
"command": "java.project.maven.addDependency",
265-
"when": "view == javaDependencyExplorer && viewItem =~ /container\/maven-dependencies/",
265+
"when": "view == javaDependencyExplorer && mavenEnabled && viewItem =~ /container\/maven-dependencies/",
266266
"group": "inline@0"
267267
}
268268
]

src/extension.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { commands, ExtensionContext } from "vscode";
4+
import { commands, Extension, ExtensionContext, extensions } from "vscode";
55
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation } from "vscode-extension-telemetry-wrapper";
66
import { Commands } from "./commands";
77
import { LibraryController } from "./controllers/libraryController";
@@ -21,11 +21,21 @@ function activateExtension(operationId: string, context: ExtensionContext) {
2121
Services.initialize(context);
2222
Settings.initialize(context);
2323

24+
setMavenEnabledContext();
25+
2426
context.subscriptions.push(new ProjectController(context));
2527
context.subscriptions.push(new LibraryController(context));
2628
context.subscriptions.push(new DependencyExplorer(context));
2729
}
2830

31+
// determine if the add dependency shortcut will show or not
32+
function setMavenEnabledContext() {
33+
const mavenExt: Extension<any> | undefined = extensions.getExtension("vscjava.vscode-maven");
34+
if (mavenExt) {
35+
commands.executeCommand("setContext", "mavenEnabled", true);
36+
}
37+
}
38+
2939
// this method is called when your extension is deactivated
3040
export async function deactivate() {
3141
await disposeTelemetryWrapper();

0 commit comments

Comments
 (0)