chore(core): 调整添加menu时的对应参数设置
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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_;
|
||||
}
|
||||
|
||||
@@ -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_;
|
||||
},
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user