Skip to content

Commit

Permalink
主菜单改成单例
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Mar 28, 2024
1 parent 6f8ca23 commit 8de73cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@ import * as tools from "./tools";
import * as preset from './preset';
import { englishPathToChinese } from './constants';
import { CSVeditor } from './editorTable/CSVeditor';
import { MainMenu } from './mainMenu';
import * as mainMenu from './mainMenu';

class Helper {
private context: vscode.ExtensionContext;
private env: Env;
private mainMenu: MainMenu;

constructor(context: vscode.ExtensionContext) {
this.context = context;

this.env = new Env();
this.mainMenu = new MainMenu(this.env);
mainMenu.init(this.env);
}

private async reload() {
this.env = new Env();
await this.env.waitReady();
this.mainMenu.reload(this.env);
mainMenu.init(this.env);
}

private reloadEnvWhenConfigChange() {
Expand Down Expand Up @@ -154,7 +153,7 @@ class Helper {
this.context.globalState.update("NewProjectPath", scriptUri.fsPath);
await vscode.commands.executeCommand('vscode.openFolder', scriptUri);

this.mainMenu.reload(this.env);
mainMenu.init(this.env);
});
running = false;
});
Expand Down
16 changes: 13 additions & 3 deletions src/mainMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ class TreeProvider implements vscode.TreeDataProvider<TreeNode> {
}
}

export class MainMenu {
private view: vscode.TreeView<TreeNode>;
private tree: TreeProvider;
class MainMenu {
readonly view: vscode.TreeView<TreeNode>;
readonly tree: TreeProvider;
private state: 'not init' | 'initing' | 'inited' = 'not init';

constructor (env: Env) {
Expand Down Expand Up @@ -239,3 +239,13 @@ export class MainMenu {
this.refresh(env);
}
}

export let mainMenu: MainMenu | undefined;

export function init(env: Env) {
if (mainMenu) {
mainMenu.reload(env);
} else {
mainMenu = new MainMenu(env);
}
}

0 comments on commit 8de73cc

Please sign in to comment.