refactor: add type ProfilesMenu (#950)

This commit is contained in:
Yan Zhang 2023-03-13 14:20:14 +08:00 коммит произвёл GitHub
Родитель e1728f65a7
Коммит 9cbc25fd75
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 47 добавлений и 17 удалений

Просмотреть файл

@ -63,14 +63,17 @@ export class MavenExplorerProvider implements TreeDataProvider<ITreeItem> {
if (!vscode.workspace.isTrusted) {
return undefined;
}
if (element === undefined) {
if (element === undefined) { // Top level elements
if (!vscode.workspace.workspaceFolders) {
return undefined;
}
if (vscode.workspace.workspaceFolders.length === 1) {
// single root workspace
return await new WorkspaceFolder(vscode.workspace.workspaceFolders[0]).getChildren();
} else {
// multi-root workspace
return vscode.workspace.workspaceFolders.map(workspaceFolder => new WorkspaceFolder(workspaceFolder));
}
return vscode.workspace.workspaceFolders.map(workspaceFolder => new WorkspaceFolder(workspaceFolder));
} else {
return element.getChildren ? element.getChildren() : undefined;
}

Просмотреть файл

@ -10,9 +10,9 @@ import { Dependency } from "./Dependency";
import { HintNode } from "./HintNode";
import { ITreeItem } from "./ITreeItem";
import { MavenProject } from "./MavenProject";
import { Menu } from "./Menu";
import { ProjectMenu } from "./Menu";
export class DependenciesMenu extends Menu implements ITreeItem {
export class DependenciesMenu extends ProjectMenu implements ITreeItem {
constructor(project: MavenProject) {
super(project);
this.name = "Dependencies";

Просмотреть файл

@ -2,13 +2,13 @@
// Licensed under the MIT license.
import * as vscode from "vscode";
import { Menu } from "./Menu";
import { ProjectMenu } from "./Menu";
import { ITreeItem } from "./ITreeItem";
import { MavenProject } from "./MavenProject";
import { FavoriteCommand } from "./FavoriteCommand";
import { Settings } from "../../Settings";
export class FavoritesMenu extends Menu implements ITreeItem {
export class FavoritesMenu extends ProjectMenu implements ITreeItem {
constructor(project: MavenProject) {
super(project);

Просмотреть файл

@ -6,9 +6,9 @@ import { DEFAULT_MAVEN_LIFECYCLES } from "../../completion/constants";
import { ITreeItem } from "./ITreeItem";
import { LifecyclePhase } from "./LifecyclePhase";
import { MavenProject } from "./MavenProject";
import { Menu } from "./Menu";
import { ProjectMenu } from "./Menu";
export class LifecycleMenu extends Menu implements ITreeItem {
export class LifecycleMenu extends ProjectMenu implements ITreeItem {
constructor(project: MavenProject) {
super(project);

Просмотреть файл

@ -10,10 +10,6 @@ const CONTEXT_VALUE: string = "maven:menu";
export abstract class Menu implements ITreeItem {
protected name: string;
constructor(
public project: MavenProject,
) { }
public abstract getChildren(): ITreeItem[] | undefined | Promise<ITreeItem[] | undefined>;
public getContextValue(): string {
@ -26,3 +22,11 @@ export abstract class Menu implements ITreeItem {
return treeItem;
}
}
export abstract class ProjectMenu extends Menu {
constructor(
public project: MavenProject,
) {
super();
}
}

Просмотреть файл

@ -6,9 +6,9 @@ import { MavenExplorerProvider } from "../MavenExplorerProvider";
import { ITreeItem } from "./ITreeItem";
import { MavenPlugin } from "./MavenPlugin";
import { MavenProject } from "./MavenProject";
import { Menu } from "./Menu";
import { ProjectMenu } from "./Menu";
export class PluginsMenu extends Menu implements ITreeItem {
export class PluginsMenu extends ProjectMenu implements ITreeItem {
constructor(project: MavenProject) {
super(project);
this.name = "Plugins";

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { ITreeItem } from "./ITreeItem";
import { Menu } from "./Menu";
export class ProfilesMenu extends Menu implements ITreeItem {
constructor() {
super();
this.name = "Profiles";
}
public getContextValue(): string {
return "maven:profilesMenu";
}
public getChildren() : any[] {
return [];
}
}

Просмотреть файл

@ -8,6 +8,7 @@ import { Settings } from "../../Settings";
import { HintNode } from "./HintNode";
import { ITreeItem } from "./ITreeItem";
import { MavenProject } from "./MavenProject";
// import { ProfilesMenu } from "./ProfilesMenu";
const CONTEXT_VALUE: string = "maven:workspaceFolder";
@ -21,6 +22,8 @@ export class WorkspaceFolder implements ITreeItem {
}
public async getChildren(): Promise<ITreeItem[]> {
const ret: ITreeItem[] = []; // TODO: show profiles menu when available
// const ret: ITreeItem[] = [new ProfilesMenu()];
const allProjects: MavenProject[] = await MavenProjectManager.loadProjects(this.workspaceFolder);
if (allProjects.length === 0) {
return [new HintNode("No Maven project found.")];
@ -28,12 +31,12 @@ export class WorkspaceFolder implements ITreeItem {
switch (Settings.viewType()) {
case "hierarchical":
return this.sortByName(allProjects.filter(m => !m.parent));
ret.push(...this.sortByName(allProjects.filter(m => !m.parent)));
case "flat":
return this.sortByName(allProjects);
ret.push(...this.sortByName(allProjects));
default:
return [];
}
return ret;
}
public getTreeItem(): vscode.TreeItem | Thenable<vscode.TreeItem> {