Skip to content

Commit

Permalink
UX: Show shortcut for reload all projects (#1259)
Browse files Browse the repository at this point in the history
  • Loading branch information
CsCherrYY committed Jul 25, 2022
1 parent f05965f commit bf32b56
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
17 changes: 16 additions & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
{
"command": "gradle.refresh",
"category": "Gradle",
"title": "Refresh Gradle Tasks",
"title": "Refresh Gradle Projects View",
"icon": {
"light": "resources/light/refresh.svg",
"dark": "resources/dark/refresh.svg"
Expand Down Expand Up @@ -337,6 +337,12 @@
"command": "gradle.runTasks",
"category": "Gradle",
"title": "Run Gradle Tasks..."
},
{
"command": "gradle.java.projectConfiguration.update",
"category": "Gradle",
"title": "Reload All Gradle Projects",
"icon": "$(sync)"
}
],
"menus": {
Expand Down Expand Up @@ -480,6 +486,10 @@
{
"command": "gradle.runTasks",
"when": "false"
},
{
"command": "gradle.java.projectConfiguration.update",
"when": "false"
}
],
"view/title": [
Expand Down Expand Up @@ -514,6 +524,11 @@
{
"command": "gradle.refresh",
"when": "view == gradleTasksView || view == gradleDefaultProjectsView",
"group": "overflow@3"
},
{
"command": "gradle.java.projectConfiguration.update",
"when": "view == gradleTasksView && javaLSReady",
"group": "navigation@3"
},
{
Expand Down
5 changes: 5 additions & 0 deletions extension/src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ import { GradleClient } from "../client";
import { GradleBuildContentProvider } from "../client/GradleBuildContentProvider";
import { PinnedTasksStore, RecentTasksStore, RootProjectsStore, TaskTerminalsStore } from "../stores";
import { GradleTaskProvider } from "../tasks";
import { isJavaExtEnabled } from "../util/javaExtension";
import { GradleDaemonsTreeDataProvider, GradleTasksTreeDataProvider, RecentTasksTreeDataProvider } from "../views";
import { Command } from "./Command";
import { COMMAND_CREATE_PROJECT, COMMAND_CREATE_PROJECT_ADVANCED, CreateProjectCommand } from "./CreateProjectCommand";
import { HideStoppedDaemonsCommand, HIDE_STOPPED_DAEMONS } from "./HideStoppedDaemonsCommand";
import { COMMAND_RELOAD_JAVA_PROJECT, ReloadJavaProjectsCommand } from "./ReloadJavaProjectsCommand";
import { COMMAND_RUN_TASKS, RunTasksCommand } from "./RunTasksCommand";
import { ShowStoppedDaemonsCommand, SHOW_STOPPED_DAEMONS } from "./ShowStoppedDaemonsCommand";

Expand Down Expand Up @@ -186,5 +188,8 @@ export class Commands {
this.registerCommand(COMMAND_CREATE_PROJECT, new CreateProjectCommand(this.client), [false]);
this.registerCommand(COMMAND_CREATE_PROJECT_ADVANCED, new CreateProjectCommand(this.client), [true]);
this.registerCommand(COMMAND_RUN_TASKS, new RunTasksCommand(this.gradleTaskProvider));
if (isJavaExtEnabled()) {
this.registerCommand(COMMAND_RELOAD_JAVA_PROJECT, new ReloadJavaProjectsCommand());
}
}
}
23 changes: 23 additions & 0 deletions extension/src/commands/ReloadJavaProjectsCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as vscode from "vscode";
import { getProjectTreeItemMap } from "../views/gradleTasks/GradleTasksTreeDataProvider";
import { Command } from "./Command";
export const COMMAND_RELOAD_JAVA_PROJECT = "gradle.java.projectConfiguration.update";

export class ReloadJavaProjectsCommand extends Command {
constructor() {
super();
}
async run(): Promise<void> {
const projectsMap = getProjectTreeItemMap();
if (projectsMap?.size) {
// call Reload All Java Projects in redhat.java
vscode.commands.executeCommand(
"java.projectConfiguration.update",
Array.from(projectsMap.keys()).map((p) => vscode.Uri.file(p))
);
}
}
}
12 changes: 12 additions & 0 deletions extension/src/util/javaExtension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as vscode from "vscode";

const JAVA_EXTENSION_ID = "redhat.java";

export function isJavaExtEnabled(): boolean {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const javaExt: vscode.Extension<any> | undefined = vscode.extensions.getExtension(JAVA_EXTENSION_ID);
return !!javaExt;
}

0 comments on commit bf32b56

Please sign in to comment.