fix node layout error and support subtree

This commit is contained in:
codetypes committed 2024-03-11 09:35:39 +08:00
1 parent d3c5bf53e7
commit 258a006383
21 files changed
+6019 -11457

No files matched your search

+32 -32
View File
@@ -54,7 +54,7 @@ export default class AppMenu {
submenu: [
{
label: "新建",
accelerator: "ctrl+n",
accelerator: "CommandOrControl+n",
click: () => {
(async () => {
const res = await dialog.showSaveDialog({
@@ -74,7 +74,7 @@ export default class AppMenu {
},
{
label: "打开文件",
accelerator: "Ctrl+O",
accelerator: "CommandOrControl+O",
click: () => {
(async () => {
const res = await dialog.showOpenDialog({
@@ -102,14 +102,14 @@ export default class AppMenu {
{ type: "separator" },
{
label: "保存",
accelerator: "ctrl+s",
accelerator: "CommandOrControl+s",
click: () => {
this.webContents.send(MainEventType.SAVE);
},
},
{
label: "全部保存",
accelerator: "ctrl+shift+s",
accelerator: "CommandOrControl+shift+s",
click: () => {
this.webContents.send(MainEventType.SAVE_ALL);
},
@@ -136,6 +136,13 @@ export default class AppMenu {
})();
},
},
{
label: "构建",
accelerator: "CommandOrControl+b",
click: () => {
this.webContents.send(MainEventType.BUILD);
},
},
],
});
}
@@ -146,29 +153,29 @@ export default class AppMenu {
submenu: [
{
label: "撤销",
accelerator: "ctrl+z",
accelerator: "CommandOrControl+z",
click: () => {
this.webContents.send(MainEventType.UNDO);
}
},
},
{
label: "恢复",
accelerator: "ctrl+y",
accelerator: "CommandOrControl+y",
click: () => {
this.webContents.send(MainEventType.REDO);
}
},
},
{ type: "separator" },
{
label: "新建节点",
accelerator: "insert",
accelerator: process.platform === "darwin" ? "enter" : "insert",
click: () => {
this.webContents.send(MainEventType.CREATE_NODE, "unknow");
},
},
{
label: "删除节点",
accelerator: "delete",
accelerator: process.platform === "darwin" ? "backspace" : "delete",
click: () => {
this.webContents.send(MainEventType.DELETE_NODE);
},
@@ -176,21 +183,14 @@ export default class AppMenu {
{ type: "separator" },
{
label: "复制节点",
accelerator: "ctrl+c",
role: "copy",
click: () => {
this.webContents.send(MainEventType.COPY_NODE);
},
},
{
label: "粘贴节点",
accelerator: "ctrl+v",
click: () => {
this.webContents.send(MainEventType.PASTE_NODE);
},
role: "paste",
},
]
})
],
});
}
private createWorkspaceMenu() {
@@ -277,7 +277,7 @@ export default class AppMenu {
{ type: "separator" },
{
label: "打开目录",
accelerator: "Ctrl+Shift+O",
accelerator: "CommandOrControl+Shift+O",
click: () => {
if (!this.settings.curWorkspace.getNodeConfPath()) {
dialog.showErrorBox("警告", "请先指定节点定义配置!");
@@ -341,23 +341,23 @@ export default class AppMenu {
for (let model of this.settings.curWorkspace.getServers()) {
serverItems.push({
label: `${model.name} ${model.host}`,
type: 'checkbox',
type: "checkbox",
checked: curServerName == model.name,
click: () => {
this.settings.serverName = model.name;
this.mainProcess.rebuildMenu();
}
})
},
});
}
return new MenuItem({
label: "开发工具",
submenu: [
{
label: "热更",
accelerator: "Ctrl+R",
accelerator: "CommandOrControl+R",
click: () => {
this.webContents.send(MainEventType.RELOAD_SERVER);
}
},
},
{
label: "联调服务器",
@@ -375,14 +375,14 @@ export default class AppMenu {
this.webContents.send(MainEventType.BATCH_EXEC, res.filePaths[0]);
}
})();
}
},
},
{
type: 'separator',
type: "separator",
},
{
label: "打开控制台",
accelerator: "Ctrl+Shift+I",
accelerator: "CommandOrControl+Shift+I",
click: (_, browserWindow) => {
browserWindow.webContents.toggleDevTools();
},
@@ -394,11 +394,11 @@ export default class AppMenu {
},
},
{
type: 'separator',
type: "separator",
},
{
label: `当前版本:${packageConf.version}`
}
label: `当前版本:${packageConf.version}`,
},
],
});
}
+4 -4
View File
@@ -18,10 +18,10 @@ export class MainProcess {
nativeTheme.themeSource = "dark";
app.on("ready", () => {
this.createWindow();
electronLocalshortcut.register(this.mainWindow, "Ctrl+C", () => {
electronLocalshortcut.register(this.mainWindow, "CommandOrControl+C", () => {
this.mainWindow.webContents.send(MainEventType.COPY_NODE);
});
electronLocalshortcut.register(this.mainWindow, "Ctrl+V", () => {
electronLocalshortcut.register(this.mainWindow, "CommandOrControl+V", () => {
this.mainWindow.webContents.send(MainEventType.PASTE_NODE);
});
});
@@ -46,12 +46,12 @@ export class MainProcess {
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation:false,
contextIsolation: false,
},
// fullscreenable:false,
// maximizable:false
});
require("@electron/remote/main").initialize();
require("@electron/remote/main").enable(this.mainWindow.webContents);
this.mainWindow.maximize();
+20 -8
View File
@@ -1,5 +1,6 @@
import * as fs from "fs";
import Workspace from "./Workspace";
import { app } from "electron";
export interface BehaviorNodeClassify {
classify: string;
@@ -14,7 +15,10 @@ export interface SettingsModel {
treesDesc?: { [name: string]: string };
}
const settingPath = "settings.json";
const settingPath = app.getPath("userData") + "/settings.json";
console.log("setting path:", settingPath);
const sampleNodeClassify: BehaviorNodeClassify[] = [
{ classify: "Composite", desc: "复合节点" },
{ classify: "Decorator", desc: "修饰节点" },
@@ -35,7 +39,7 @@ export default class Settings {
fs.writeFileSync(settingPath, JSON.stringify(this.model, null, 2));
this.dirty = false;
}
}, 1000)
}, 1000);
}
get nodeConfPath() {
@@ -54,7 +58,7 @@ export default class Settings {
return this.model.nodeClassify;
}
get serverModel() {
const servers = this.curWorkspace.getServers()
const servers = this.curWorkspace.getServers();
if (!servers) {
return;
}
@@ -66,7 +70,7 @@ export default class Settings {
return servers[0];
}
get serverName() {
const servers = this.curWorkspace.getServers()
const servers = this.curWorkspace.getServers();
if (!servers) {
return "";
}
@@ -78,7 +82,7 @@ export default class Settings {
if (servers[0]) {
return servers[0].name;
} else {
return ''
return "";
}
}
set serverName(name: string) {
@@ -119,10 +123,18 @@ export default class Settings {
this.dirty = true;
}
get workdir() {
return this.curWorkspace.getWorkdir();
}
getNodeConf(name: string) {
return this.curWorkspace.getNodeConf(name);
}
hasNodeConf(name: string) {
return this.curWorkspace.hasNodeConf(name);
}
pushRecentWorkspace(path: string) {
var list = this.model.recentWorkspaces;
if (list.indexOf(path) >= 0) {
@@ -137,12 +149,12 @@ export default class Settings {
}
getTreeDesc(name: string) {
const key = this.curWorkspace.getFilepath() + ' ' + name;
const key = this.curWorkspace.getFilepath() + " " + name;
var desc = this.model.treesDesc[key];
if (!desc) {
const str = fs.readFileSync(name, "utf8");
const tree = JSON.parse(str);
desc = tree.desc ? tree.desc : '';
desc = tree.desc ? tree.desc : "";
this.model.treesDesc[key] = desc;
this.save();
}
@@ -150,7 +162,7 @@ export default class Settings {
}
setTreeDesc(name: string, desc?: string) {
const key = this.curWorkspace.getFilepath() + ' ' + name;
const key = this.curWorkspace.getFilepath() + " " + name;
this.model.treesDesc[key] = desc;
}
}
+7 -3
View File
@@ -43,8 +43,8 @@ export default class Workspace {
const model = JSON.parse(str) as WorkspaceModel;
if (model.isRelative) {
const root = path.dirname(this.filepath);
this.nodeConfPath = path.join(root,model.nodeConfPath);
this.workdir = path.join(root,model.workdir);
this.nodeConfPath = path.join(root, model.nodeConfPath);
this.workdir = path.join(root, model.workdir);
} else {
this.nodeConfPath = model.nodeConfPath;
this.workdir = model.workdir;
@@ -86,7 +86,7 @@ export default class Workspace {
this.workdir = workdir;
}
getServers() {
if(this.model && this.model.servers) {
if (this.model && this.model.servers) {
return this.model.servers;
} else {
return [];
@@ -154,4 +154,8 @@ export default class Workspace {
getNodeConf(name: string) {
return this.name2conf[name] || unknowNodeType;
}
hasNodeConf(name: string) {
return !!this.name2conf[name];
}
}