workspace add servers

This commit is contained in:
zhandouxiaojiji committed 2020-11-19 20:34:49 +08:00
1 parent 32312fc40b
commit c7f65abccf
3 files changed
+76 -17

No files matched your search

+17
View File
@@ -303,9 +303,26 @@ export default class AppMenu {
} }
private createToolsMenu() { private createToolsMenu() {
const serverItems: MenuItemConstructorOptions[] = [];
const curServerName = this.settings.serverName;
for (let model of this.settings.curWorkspace.getServers()) {
serverItems.push({
label: `${model.name} ${model.host}`,
type: 'checkbox',
checked: curServerName == model.name,
click: () => {
this.settings.serverName = model.name;
this.mainProcess.rebuildMenu();
}
})
}
return new MenuItem({ return new MenuItem({
label: "开发工具", label: "开发工具",
submenu: [ submenu: [
{
label: "联调服务器",
submenu: serverItems,
},
{ {
label: "打开控制台", label: "打开控制台",
accelerator: "Ctrl+Shift+I", accelerator: "Ctrl+Shift+I",
+45 -17
View File
@@ -1,5 +1,4 @@
import * as fs from "fs"; import * as fs from "fs";
import { BehaviorNodeTypeModel } from "../common/BehaviorTreeModel";
import Workspace from "./Workspace"; import Workspace from "./Workspace";
export interface BehaviorNodeClassify { export interface BehaviorNodeClassify {
@@ -10,6 +9,7 @@ export interface BehaviorNodeClassify {
export interface SettingsModel { export interface SettingsModel {
recentWorkspaces?: string[]; recentWorkspaces?: string[];
recentFiles?: string[]; recentFiles?: string[];
serverName?: string;
nodeClassify?: BehaviorNodeClassify[]; nodeClassify?: BehaviorNodeClassify[];
} }
@@ -22,7 +22,7 @@ const sampleNodeClassify: BehaviorNodeClassify[] = [
]; ];
export default class Settings { export default class Settings {
private settings: SettingsModel; private model: SettingsModel;
curWorkspace?: Workspace; curWorkspace?: Workspace;
constructor() { constructor() {
@@ -33,21 +33,52 @@ export default class Settings {
return this.curWorkspace.getNodeConfPath(); return this.curWorkspace.getNodeConfPath();
} }
get recentWorkspaces() { get recentWorkspaces() {
return this.settings.recentWorkspaces; return this.model.recentWorkspaces;
} }
get recentFiles() { get recentFiles() {
return this.settings.recentFiles; return this.model.recentFiles;
} }
get nodeConfig() { get nodeConfig() {
return this.curWorkspace.nodeConf; return this.curWorkspace.nodeConf;
} }
get nodeClassify() { get nodeClassify() {
return this.settings.nodeClassify; return this.model.nodeClassify;
}
get serverModel() {
const servers = this.curWorkspace.getServers()
if (!servers) {
return;
}
for (let server of servers) {
if (server.name == this.model.serverName) {
return server;
}
}
return servers[0];
}
get serverName() {
const servers = this.curWorkspace.getServers()
if (!servers) {
return "";
}
for (let server of servers) {
if (server.name == this.model.serverName) {
return this.model.serverName;
}
}
if(servers[0]) {
return servers[0].name;
} else {
return ''
}
}
set serverName(name: string) {
this.model.serverName = name;
} }
set(config: SettingsModel) { set(config: SettingsModel) {
this.settings = { this.model = {
...this.settings, ...this.model,
...config, ...config,
}; };
this.save(); this.save();
@@ -56,21 +87,21 @@ export default class Settings {
load() { load() {
if (fs.existsSync(settingPath)) { if (fs.existsSync(settingPath)) {
const str = fs.readFileSync(settingPath, "utf8"); const str = fs.readFileSync(settingPath, "utf8");
this.settings = JSON.parse(str); this.model = JSON.parse(str);
} else { } else {
this.settings = { this.model = {
recentWorkspaces: ["sample/workspace.json"], recentWorkspaces: ["sample/workspace.json"],
recentFiles: [], recentFiles: [],
nodeClassify: sampleNodeClassify, nodeClassify: sampleNodeClassify,
}; };
this.save(); this.save();
} }
this.curWorkspace = new Workspace(this.settings.recentWorkspaces[0]); this.curWorkspace = new Workspace(this.model.recentWorkspaces[0]);
this.curWorkspace.load(); this.curWorkspace.load();
} }
save() { save() {
fs.writeFileSync(settingPath, JSON.stringify(this.settings, null, 2)); fs.writeFileSync(settingPath, JSON.stringify(this.model, null, 2));
} }
getNodeConf(name: string) { getNodeConf(name: string) {
@@ -78,12 +109,9 @@ export default class Settings {
} }
pushRecentWorkspace(path: string) { pushRecentWorkspace(path: string) {
if (this.settings.recentWorkspaces.indexOf(path) < 0) { if (this.model.recentWorkspaces.indexOf(path) < 0) {
this.settings.recentWorkspaces.unshift(path); this.model.recentWorkspaces.unshift(path);
console.log("push", path); this.save();
} else {
console.log("already in path", this.settings.recentWorkspaces, path);
} }
this.save();
} }
} }
+14
View File
@@ -3,10 +3,16 @@ import { BehaviorNodeTypeModel } from "../common/BehaviorTreeModel";
import * as glob from "glob"; import * as glob from "glob";
import * as path from "path"; import * as path from "path";
export interface ServerModel {
name: string;
host: string;
}
export interface WorkspaceModel { export interface WorkspaceModel {
isRelative?: boolean; isRelative?: boolean;
nodeConfPath: string; nodeConfPath: string;
workdir: string; workdir: string;
servers?: ServerModel[];
} }
const unknowNodeType: BehaviorNodeTypeModel = { const unknowNodeType: BehaviorNodeTypeModel = {
@@ -19,6 +25,7 @@ export default class Workspace {
private filepath: string; private filepath: string;
private nodeConfPath: string; private nodeConfPath: string;
private workdir: string; private workdir: string;
private model: WorkspaceModel;
private name2conf: { [name: string]: BehaviorNodeTypeModel } = {}; private name2conf: { [name: string]: BehaviorNodeTypeModel } = {};
private types: BehaviorNodeTypeModel[] = []; private types: BehaviorNodeTypeModel[] = [];
@@ -42,6 +49,7 @@ export default class Workspace {
this.nodeConfPath = model.nodeConfPath; this.nodeConfPath = model.nodeConfPath;
this.workdir = model.workdir; this.workdir = model.workdir;
} }
this.model = model;
this.initNodeConf(); this.initNodeConf();
} catch (error) { } catch (error) {
@@ -77,6 +85,12 @@ export default class Workspace {
setWorkdir(workdir: string) { setWorkdir(workdir: string) {
this.workdir = workdir; this.workdir = workdir;
} }
getServers() {
return this.model.servers || [];
}
getModel() {
return this.model;
}
writeAllTrees(outFilePath: string, cb?: (err: string) => void) { writeAllTrees(outFilePath: string, cb?: (err: string) => void) {
if (!fs.existsSync(this.getWorkdir())) { if (!fs.existsSync(this.getWorkdir())) {