Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Show Gradle commands in Project Manager's submenu #1252

Merged
merged 3 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@
"command": "gradle.createProjectAdvanced",
"category": "Gradle",
"title": "Create a Gradle Java Project... (Advanced)"
},
{
"command": "gradle.showGradleProjectsView",
"category": "Gradle",
"title": "Focus on Gradle Projects View"
jdneo marked this conversation as resolved.
Show resolved Hide resolved
}
],
"menus": {
Expand Down Expand Up @@ -471,6 +476,10 @@
{
"command": "gradle.createProject",
"when": "!java:projectManagerActivated"
},
{
"command": "gradle.showGradleProjectsView",
"when": "false"
}
],
"view/title": [
Expand Down Expand Up @@ -653,6 +662,16 @@
"command": "gradle.showTasks",
"group": "gradle@0"
}
],
"javaProject.gradle": [
{
"command": "gradle.showGradleProjectsView",
"group": "gradle@20"
},
{
"command": "gradle.openBuildFile",
"group": "gradle@30"
}
]
},
"configuration": {
Expand Down
2 changes: 2 additions & 0 deletions extension/src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import { GradleDaemonsTreeDataProvider, GradleTasksTreeDataProvider, RecentTasks
import { Command } from "./Command";
import { COMMAND_CREATE_PROJECT, COMMAND_CREATE_PROJECT_ADVANCED, CreateProjectCommand } from "./CreateProjectCommand";
import { HideStoppedDaemonsCommand, HIDE_STOPPED_DAEMONS } from "./HideStoppedDaemonsCommand";
import { COMMAND_SHOW_PROJECTS_VIEW, ShowGradleProjectsViewCommand } from "./ShowGradleProjectsViewCommand";
import { ShowStoppedDaemonsCommand, SHOW_STOPPED_DAEMONS } from "./ShowStoppedDaemonsCommand";

export class Commands {
Expand Down Expand Up @@ -184,5 +185,6 @@ export class Commands {
this.registerCommand(HIDE_STOPPED_DAEMONS, new HideStoppedDaemonsCommand(this.gradleDaemonsTreeDataProvider));
this.registerCommand(COMMAND_CREATE_PROJECT, new CreateProjectCommand(this.client), [false]);
this.registerCommand(COMMAND_CREATE_PROJECT_ADVANCED, new CreateProjectCommand(this.client), [true]);
this.registerCommand(COMMAND_SHOW_PROJECTS_VIEW, new ShowGradleProjectsViewCommand());
}
}
21 changes: 17 additions & 4 deletions extension/src/commands/OpenBuildFileCommand.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import * as vscode from "vscode";
import * as path from "path";
import * as fse from "fs-extra";
import { GradleTaskTreeItem } from "../views";
import { Command } from "./Command";

export const COMMAND_OPEN_BUILD_FILE = "gradle.openBuildFile";

async function run(taskItem: GradleTaskTreeItem): Promise<void> {
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(taskItem.task.definition.buildFile));
async function run(path: string): Promise<void> {
await vscode.commands.executeCommand("vscode.open", vscode.Uri.file(path));
}

export class OpenBuildFileCommand extends Command {
async run(taskItem: GradleTaskTreeItem): Promise<void> {
return run(taskItem);
async run(item: GradleTaskTreeItem | { uri: string }): Promise<void> {
if (item instanceof GradleTaskTreeItem) {
return run(item.task.definition.buildFile);
} else if (item.uri) {
const buildFilePath: string = path.join(vscode.Uri.parse(item.uri).fsPath, "build.gradle");
if (await fse.pathExists(buildFilePath)) {
return run(buildFilePath);
}
const settingsFilePath: string = path.join(vscode.Uri.parse(item.uri).fsPath, "settings.gradle");
if (await fse.pathExists(settingsFilePath)) {
return run(settingsFilePath);
}
}
}
}
18 changes: 18 additions & 0 deletions extension/src/commands/ShowGradleProjectsViewCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as vscode from "vscode";
import { Command } from "./Command";
export const COMMAND_SHOW_PROJECTS_VIEW = "gradle.showGradleProjectsView";

/**
* Mock VS Code build-in command gradleTasksView.focus
*/
export class ShowGradleProjectsViewCommand extends Command {
constructor() {
super();
}
async run(): Promise<void> {
await vscode.commands.executeCommand("gradleTasksView.focus");
}
}