From ac6af68999abe97856ef43ea7039af435f59b04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Sun, 18 May 2025 00:11:11 +0800 Subject: [PATCH] =?UTF-8?q?chore(core):=20=E8=B0=83=E6=95=B4=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0menu=E6=97=B6=E7=9A=84=E5=AF=B9=E5=BA=94=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/modules/mixly-modules/common/boards.js | 10 -------- .../mixly-modules/common/context-menu.js | 2 +- .../mixly-modules/common/editor-code.js | 16 ++++++------ .../mixly-modules/common/editor-mix.js | 10 ++++---- .../modules/mixly-modules/common/file-tree.js | 20 +++++++-------- .../common/footerlayer-board-config.js | 3 ++- common/modules/mixly-modules/common/menu.js | 14 +++++++++-- .../mixly-modules/common/statusbar-ampy.js | 24 +++++++++--------- .../modules/mixly-modules/common/statusbar.js | 6 +++-- .../common/statusbars-manager.js | 25 ++++++++++--------- 10 files changed, 68 insertions(+), 62 deletions(-) diff --git a/common/modules/mixly-modules/common/boards.js b/common/modules/mixly-modules/common/boards.js index a1aa3d18..18e300b6 100644 --- a/common/modules/mixly-modules/common/boards.js +++ b/common/modules/mixly-modules/common/boards.js @@ -39,16 +39,6 @@ const { BOARD, USER, SELECTED_BOARD } = Config; -/** - * INFO = { - * "boardName": { - * "key": string | null, - * "config": object | null, - * "default": object | null - * } - * } - **/ -Boards.INFO = {}; Boards.NAME = []; diff --git a/common/modules/mixly-modules/common/context-menu.js b/common/modules/mixly-modules/common/context-menu.js index c19b949e..59717fdd 100644 --- a/common/modules/mixly-modules/common/context-menu.js +++ b/common/modules/mixly-modules/common/context-menu.js @@ -35,7 +35,7 @@ class ContextMenu { if (item.children) { item.data.items = this.generate(item.children); } - menuItems[item.type] = item.data; + menuItems[item.id] = item.data; } return menuItems; } diff --git a/common/modules/mixly-modules/common/editor-code.js b/common/modules/mixly-modules/common/editor-code.js index 92514a2a..1eadc0f4 100644 --- a/common/modules/mixly-modules/common/editor-code.js +++ b/common/modules/mixly-modules/common/editor-code.js @@ -45,11 +45,13 @@ class EditorCode extends EditorMonaco { } #addContextMenu_() { - this.#contextMenu_ = new ContextMenu(`div[page-id="${this.getId()}"]`); + this.#contextMenu_ = new ContextMenu(`div[page-id="${this.getId()}"]`, { + zIndex: 300 + }); let menu = new Menu(); menu.add({ weight: 0, - type: 'cut', + id: 'cut', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.cut'], 'Ctrl+X'), @@ -58,7 +60,7 @@ class EditorCode extends EditorMonaco { }); menu.add({ weight: 1, - type: 'copy', + id: 'copy', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.copy'], 'Ctrl+C'), @@ -67,7 +69,7 @@ class EditorCode extends EditorMonaco { }); menu.add({ weight: 2, - type: 'paste', + id: 'paste', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.paste'], 'Ctrl+V'), @@ -76,12 +78,12 @@ class EditorCode extends EditorMonaco { }); menu.add({ weight: 3, - type: 'sep1', + id: 'sep1', data: '---------' }); menu.add({ weight: 4, - type: 'togglecomment', + id: 'togglecomment', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.togglecomment'], 'Ctrl+/'), @@ -90,7 +92,7 @@ class EditorCode extends EditorMonaco { }); menu.add({ weight: 5, - type: 'toggleBlockComment', + id: 'toggleBlockComment', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.toggleBlockComment'], 'Shift+Alt+A'), diff --git a/common/modules/mixly-modules/common/editor-mix.js b/common/modules/mixly-modules/common/editor-mix.js index 07398a02..8dd0d6e7 100644 --- a/common/modules/mixly-modules/common/editor-mix.js +++ b/common/modules/mixly-modules/common/editor-mix.js @@ -94,12 +94,12 @@ class EditorMix extends EditorBase { let codeMenu = contextMenu.getItem('code'); codeMenu.add({ weight: 6, - type: 'sep2', + id: 'sep2', data: '---------' }); codeMenu.add({ weight: 7, - type: 'block', + id: 'block', data: { isHtmlName: false, name: Msg.Lang['editor.contextMenu.exitCodeEditor'], @@ -109,7 +109,7 @@ class EditorMix extends EditorBase { let blockMenu = new Menu(); blockMenu.add({ weight: 0, - type: 'copy', + id: 'copy', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.copy'], 'Ctrl+C'), @@ -118,12 +118,12 @@ class EditorMix extends EditorBase { }); blockMenu.add({ weight: 1, - type: 'sep1', + id: 'sep1', data: '---------' }); blockMenu.add({ weight: 2, - type: 'code', + id: 'code', data: { isHtmlName: false, name: Msg.Lang['editor.contextMenu.enterCodeEditor'], diff --git a/common/modules/mixly-modules/common/file-tree.js b/common/modules/mixly-modules/common/file-tree.js index 9f57694f..416aba42 100644 --- a/common/modules/mixly-modules/common/file-tree.js +++ b/common/modules/mixly-modules/common/file-tree.js @@ -250,7 +250,7 @@ class FileTree extends Component { let menu = new Menu(); menu.add({ weight: 0, - type: 'new_folder', + id: 'new_folder', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['root', 'folder'].includes(type); @@ -272,7 +272,7 @@ class FileTree extends Component { }); menu.add({ weight: 1, - type: 'new_file', + id: 'new_file', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['root', 'folder'].includes(type); @@ -294,7 +294,7 @@ class FileTree extends Component { }); menu.add({ weight: 2, - type: 'sep1', + id: 'sep1', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['folder'].includes(type); @@ -303,7 +303,7 @@ class FileTree extends Component { }); menu.add({ weight: 3, - type: 'cut', + id: 'cut', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['file', 'folder'].includes(type); @@ -319,7 +319,7 @@ class FileTree extends Component { }); menu.add({ weight: 4, - type: 'copy', + id: 'copy', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['file', 'folder'].includes(type); @@ -335,7 +335,7 @@ class FileTree extends Component { }); menu.add({ weight: 5, - type: 'paste', + id: 'paste', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['folder'].includes(type); @@ -351,12 +351,12 @@ class FileTree extends Component { }); menu.add({ weight: 6, - type: 'sep2', + id: 'sep2', data: '---------' }); menu.add({ weight: 7, - type: 'copy_path', + id: 'copy_path', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['fileTree.copyPath'], ''), @@ -375,7 +375,7 @@ class FileTree extends Component { }); menu.add({ weight: 8, - type: 'rename', + id: 'rename', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['file', 'folder'].includes(type); @@ -396,7 +396,7 @@ class FileTree extends Component { }); menu.add({ weight: 9, - type: 'del', + id: 'del', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['file', 'folder'].includes(type); diff --git a/common/modules/mixly-modules/common/footerlayer-board-config.js b/common/modules/mixly-modules/common/footerlayer-board-config.js index a6ec2d94..fa69483d 100644 --- a/common/modules/mixly-modules/common/footerlayer-board-config.js +++ b/common/modules/mixly-modules/common/footerlayer-board-config.js @@ -1,6 +1,7 @@ goog.loadJs('common', () => { goog.require('path'); +goog.require('tippy'); goog.require('Blockly'); goog.require('layui'); goog.require('$.select2'); @@ -148,7 +149,7 @@ class FooterLayerBoardConfig extends FooterLayer { allowHTML: true, interactive: true, placement: 'left', - offset: [ 0, 16 ] + offset: [0, 16] }); } diff --git a/common/modules/mixly-modules/common/menu.js b/common/modules/mixly-modules/common/menu.js index 25f19808..3ec767a6 100644 --- a/common/modules/mixly-modules/common/menu.js +++ b/common/modules/mixly-modules/common/menu.js @@ -45,7 +45,7 @@ class Menu { break; } this.#menuItems_.splice(i, 0, item); - this.#ids_[id] = true; + this.#ids_[id] = item; return id; } @@ -68,13 +68,23 @@ class Menu { this.#menuItems_ = []; } + hasKey(id) { + return !!this.#ids_[id]; + } + getItem(id) { return this.#ids_[id] ?? null; } getAllItems() { if (this.#isDynamic_) { - this.runEvent('onRead'); + this.empty(); + const results = this.runEvent('onRead'); + if (results?.length) { + for (let item of results[0]) { + this.add(item); + } + } } return this.#menuItems_; } diff --git a/common/modules/mixly-modules/common/statusbar-ampy.js b/common/modules/mixly-modules/common/statusbar-ampy.js index ba307f5d..e370865f 100644 --- a/common/modules/mixly-modules/common/statusbar-ampy.js +++ b/common/modules/mixly-modules/common/statusbar-ampy.js @@ -141,7 +141,7 @@ class StatusBarAmpy extends PageBase { fileTreeMenu.add({ weight: 14, - type: 'sep5', + id: 'sep5', preconditionFn: ($trigger) => { const selectedNodeId = this.#fileTree_.getSelectedNodeId(); let type = $trigger.attr('type'); @@ -156,7 +156,7 @@ class StatusBarAmpy extends PageBase { fileTreeMenu.add({ weight: 15, - type: 'refresh', + id: 'refresh', preconditionFn: ($trigger) => { const selectedNodeId = this.#fileTree_.getSelectedNodeId(); let type = $trigger.attr('type'); @@ -188,7 +188,7 @@ class StatusBarAmpy extends PageBase { fileTreeMenu.add({ weight: 16, - type: 'sep6', + id: 'sep6', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['root'].includes(type); @@ -198,7 +198,7 @@ class StatusBarAmpy extends PageBase { fileTreeMenu.add({ weight: 17, - type: 'exit', + id: 'exit', preconditionFn: ($trigger) => { let type = $trigger.attr('type'); return ['root'].includes(type); @@ -224,7 +224,7 @@ class StatusBarAmpy extends PageBase { editorMenu.add({ weight: 0, - type: 'cut', + id: 'cut', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.cut'], 'Ctrl+X'), @@ -233,7 +233,7 @@ class StatusBarAmpy extends PageBase { }); editorMenu.add({ weight: 1, - type: 'copy', + id: 'copy', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.copy'], 'Ctrl+C'), @@ -242,7 +242,7 @@ class StatusBarAmpy extends PageBase { }); editorMenu.add({ weight: 2, - type: 'paste', + id: 'paste', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.paste'], 'Ctrl+V'), @@ -251,12 +251,12 @@ class StatusBarAmpy extends PageBase { }); editorMenu.add({ weight: 3, - type: 'sep1', + id: 'sep1', data: '---------' }); editorMenu.add({ weight: 4, - type: 'togglecomment', + id: 'togglecomment', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.togglecomment'], 'Ctrl+/'), @@ -265,7 +265,7 @@ class StatusBarAmpy extends PageBase { }); /*editorMenu.add({ weight: 5, - type: 'toggleBlockComment', + id: 'toggleBlockComment', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.toggleBlockComment'], 'Shift+Alt+A'), @@ -275,7 +275,7 @@ class StatusBarAmpy extends PageBase { editorMenu.add({ weight: 6, - type: 'sep2', + id: 'sep2', preconditionFn: () => { return this.#changed_; }, @@ -284,7 +284,7 @@ class StatusBarAmpy extends PageBase { editorMenu.add({ weight: 7, - type: 'save', + id: 'save', preconditionFn: () => { return this.#changed_; }, diff --git a/common/modules/mixly-modules/common/statusbar.js b/common/modules/mixly-modules/common/statusbar.js index ed761e68..01e9578a 100644 --- a/common/modules/mixly-modules/common/statusbar.js +++ b/common/modules/mixly-modules/common/statusbar.js @@ -35,11 +35,13 @@ class StatusBar extends EditorAce { } #addContextMenu_() { - this.#contextMenu_ = new ContextMenu(`div[page-id="${this.getId()}"]`); + this.#contextMenu_ = new ContextMenu(`div[page-id="${this.getId()}"]`, { + zIndex: 300 + }); let menu = new Menu(); menu.add({ weight: 0, - type: 'copy', + id: 'copy', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['editor.contextMenu.copy'], 'Ctrl+C'), diff --git a/common/modules/mixly-modules/common/statusbars-manager.js b/common/modules/mixly-modules/common/statusbars-manager.js index e06e7b32..d873a29c 100644 --- a/common/modules/mixly-modules/common/statusbars-manager.js +++ b/common/modules/mixly-modules/common/statusbars-manager.js @@ -151,7 +151,7 @@ class StatusBarsManager extends PagesManager { let serialChildMenu = new Menu(true); menu.add({ weight: 0, - type: 'serial-default', + id: 'serial-default', preconditionFn: () => { return !!Serial.getCurrentPortsName().length; }, @@ -165,7 +165,7 @@ class StatusBarsManager extends PagesManager { }); menu.add({ weight: 1, - type: 'serial', + id: 'serial', children: serialChildMenu, data: { isHtmlName: true, @@ -175,7 +175,7 @@ class StatusBarsManager extends PagesManager { /*menu.add({ weight: 2, - type: 'lib', + id: 'lib', data: { isHtmlName: true, name: ContextMenu.getItem('第三方库管理', ''), @@ -190,19 +190,19 @@ class StatusBarsManager extends PagesManager { && !['BBC micro:bit', 'Mithon CC'].includes(BOARD.boardType)) { menu.add({ weight: 2, - type: 'sep1', + id: 'sep1', data: '---------' }); menu.add({ weight: 3, - type: 'ampy', + id: 'ampy', data: { isHtmlName: true, name: ContextMenu.getItem(Msg.Lang['statusbar.ampy'], ''), callback: (key, opt) => { this.add({ - type: 'ampy', id: 'ampy', + type: 'ampy', name: Msg.Lang['statusbar.ampy'], title: Msg.Lang['statusbar.ampy'] }); @@ -212,14 +212,14 @@ class StatusBarsManager extends PagesManager { }); } serialChildMenu.bind('onRead', () => { - let options = this.#getMenu_() ?? {}; + const options = this.#getMenu_() ?? {}; options.list = options.list ?? []; options.empty = options.empty ?? Msg.Lang['statusbar.serial.noPort']; - serialChildMenu.empty(); + const result = []; if (!options.list.length) { - serialChildMenu.add({ + result.push({ weight: 1, - type: 'empty', + id: 'empty', data: { isHtmlName: true, name: options.empty, @@ -228,9 +228,9 @@ class StatusBarsManager extends PagesManager { }); } for (let i in options.list) { - serialChildMenu.add({ + result.push({ weight: 1, - type: `serial${i}`, + id: `serial${i}`, data: { isHtmlName: true, name: options.list[i], @@ -238,6 +238,7 @@ class StatusBarsManager extends PagesManager { } }); } + return result; }); this.#dropdownMenu_ = new DropdownMenu(selector); this.#dropdownMenu_.register('menu', menu);