feat(core): Mixly.PagesManager中add方法允许使用Object对tab进行配置

This commit is contained in:
王立帮
2025-04-29 19:07:07 +08:00
parent 805858b367
commit a0f85c8eb0
11 changed files with 81 additions and 232 deletions

View File

@@ -1,316 +1,161 @@
[ [
{ {
"boardImg": "./boards/default/micropython_esp32s2/media/mixgoce_compressed.png", "boardImg": "./boards/default/micropython_esp32s2/media/mixgoce_compressed.png",
"boardType": "MixGo CE", "boardType": "MixGo CE",
"boardIndex": "./boards/default/micropython_esp32s2/index.xml", "boardIndex": "./boards/default/micropython_esp32s2/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/micropython_esp32s3/media/mixgo_nova.png", "boardImg": "./boards/default/micropython_esp32s3/media/mixgo_nova.png",
"boardType": "Python ESP32-S3", "boardType": "Python ESP32-S3",
"boardIndex": "./boards/default/micropython_esp32s3/index.xml", "boardIndex": "./boards/default/micropython_esp32s3/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/micropython_esp32c3/media/esp32c3_compressed.png", "boardImg": "./boards/default/micropython_esp32c3/media/esp32c3_compressed.png",
"boardType": "Python ESP32-C3", "boardType": "Python ESP32-C3",
"boardIndex": "./boards/default/micropython_esp32c3/index.xml", "boardIndex": "./boards/default/micropython_esp32c3/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/micropython_esp32c2/media/esp32c2_compressed.png", "boardImg": "./boards/default/micropython_esp32c2/media/esp32c2_compressed.png",
"boardType": "Python ESP32-C2", "boardType": "Python ESP32-C2",
"boardIndex": "./boards/default/micropython_esp32c2/index.xml", "boardIndex": "./boards/default/micropython_esp32c2/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/micropython_esp32/media/esp32_compressed.png", "boardImg": "./boards/default/micropython_esp32/media/esp32_compressed.png",
"boardType": "Python ESP32", "boardType": "Python ESP32",
"boardIndex": "./boards/default/micropython_esp32/index.xml", "boardIndex": "./boards/default/micropython_esp32/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/arduino_avr/media/uno_compressed.png", "boardImg": "./boards/default/arduino_avr/media/uno_compressed.png",
"boardType": "Arduino AVR", "boardType": "Arduino AVR",
"boardIndex": "./boards/default/arduino_avr/index.xml", "boardIndex": "./boards/default/arduino_avr/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": false, "web": false,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "C/C++" "language": "C/C++"
}, },
{ {
"boardImg": "./boards/default/python_mixpy/media/py.png", "boardImg": "./boards/default/python_mixpy/media/py.png",
"boardType": "Python 3", "boardType": "Python 3",
"boardIndex": "./boards/default/python_mixpy/index.xml", "boardIndex": "./boards/default/python_mixpy/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": false, "web": false,
"webCompiler": false, "webCompiler": false,
"webSocket": false "webSocket": false
}, },
"language": "Python" "language": "Python"
}, },
{ {
"boardImg": "./boards/default/python_skulpt/media/webpy.png", "boardImg": "./boards/default/python_skulpt/media/webpy.png",
"boardType": "Python 3 Lite", "boardType": "Python 3 Lite",
"boardIndex": "./boards/default/python_skulpt/index.xml", "boardIndex": "./boards/default/python_skulpt/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "Python" "language": "Python"
}, },
/*{ /*{
"boardImg": "./boards/default/python_skulpt/media/webpy.png", "boardImg": "./boards/default/python_skulpt/media/webpy.png",
"boardType": "Python 3 MixToy", "boardType": "Python 3 MixToy",
"boardIndex": "./boards/default/python_skulpt_mixtoy/index.xml", "boardIndex": "./boards/default/python_skulpt_mixtoy/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "Python" "language": "Python"
},*/ },*/
{ {
"boardImg": "./boards/default/python_skulpt/media/webpy.png", "boardImg": "./boards/default/python_skulpt/media/webpy.png",
"boardType": "Python 3 Car", "boardType": "Python 3 Car",
"boardIndex": "./boards/default/python_skulpt_car/index.xml", "boardIndex": "./boards/default/python_skulpt_car/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "Python" "language": "Python"
}, },
{ {
"boardImg": "./boards/default/python_pyodide/media/webpy.png", "boardImg": "./boards/default/python_pyodide/media/webpy.png",
"boardType": "Python 3 Online", "boardType": "Python 3 Online",
"boardIndex": "./boards/default/python_pyodide/index.xml", "boardIndex": "./boards/default/python_pyodide/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": false, "webCompiler": false,
"webSocket": false "webSocket": false
}, },
"language": "Python" "language": "Python"
}, },
{ {
"boardImg": "./boards/default/micropython_robot/media/mixbot.png", "boardImg": "./boards/default/micropython_robot/media/mixbot.png",
"boardType": "Python Robot", "boardType": "Python Robot",
"boardIndex": "./boards/default/micropython_robot/index.xml", "boardIndex": "./boards/default/micropython_robot/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/micropython_k210_mixgoai/media/mixgoai_compressed.png", "boardImg": "./boards/default/micropython_k210_mixgoai/media/mixgoai_compressed.png",
"boardType": "MixGo AI", "boardType": "MixGo AI",
"boardIndex": "./boards/default/micropython_k210_mixgoai/index.xml", "boardIndex": "./boards/default/micropython_k210_mixgoai/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
/* { /* {
"boardImg": "./boards/default/micropython_educore/media/educore.png", "boardImg": "./boards/default/micropython_educore/media/educore.png",
"boardType": "Python Educore", "boardType": "Python Educore",
"boardIndex": "./boards/default/micropython_educore/index.xml", "boardIndex": "./boards/default/micropython_educore/index.xml",
@@ -323,101 +168,51 @@
"language": "MicroPython" "language": "MicroPython"
},*/ },*/
{ {
"boardImg": "./boards/default/micropython_nrf51822_mithoncc/media/mithon_compressed.png", "boardImg": "./boards/default/micropython_nrf51822_mithoncc/media/mithon_compressed.png",
"boardType": "Mithon CC", "boardType": "Mithon CC",
"boardIndex": "./boards/default/micropython_nrf51822_mithoncc/index.xml", "boardIndex": "./boards/default/micropython_nrf51822_mithoncc/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/micropython_nrf51822_microbit/media/microbit_compressed.png", "boardImg": "./boards/default/micropython_nrf51822_microbit/media/microbit_compressed.png",
"boardType": "BBC micro:bit", "boardType": "BBC micro:bit",
"boardIndex": "./boards/default/micropython_nrf51822_microbit/index.xml", "boardIndex": "./boards/default/micropython_nrf51822_microbit/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": true, "web": true,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "MicroPython" "language": "MicroPython"
}, },
{ {
"boardImg": "./boards/default/arduino_esp8266/media/esp8266_compressed.png", "boardImg": "./boards/default/arduino_esp8266/media/esp8266_compressed.png",
"boardType": "Arduino ESP8266", "boardType": "Arduino ESP8266",
"boardIndex": "./boards/default/arduino_esp8266/index.xml", "boardIndex": "./boards/default/arduino_esp8266/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": false, "web": false,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "C/C++" "language": "C/C++"
}, },
{ {
"boardImg": "./boards/default/arduino_esp32/media/esp32_compressed.png", "boardImg": "./boards/default/arduino_esp32/media/esp32_compressed.png",
"boardType": "Arduino ESP32", "boardType": "Arduino ESP32",
"boardIndex": "./boards/default/arduino_esp32/index.xml", "boardIndex": "./boards/default/arduino_esp32/index.xml",
"env": { "env": {
"electron": true, "electron": true,
"web": false, "web": false,
"webCompiler": true, "webCompiler": true,
"webSocket": true "webSocket": true
}, },
"language": "C/C++" "language": "C/C++"
} }
]
]

View File

@@ -1,7 +1,8 @@
import * as goog from 'goog'; import * as goog from 'goog';
import { Msg } from 'blockly/core';
import { Workspace, ContextMenu } from 'mixly'; import { Workspace, ContextMenu } from 'mixly';
import FSArduEsp32Handler from './fs-board-handler'; import FSArduEsp32Handler from './fs-board-handler';
import { Msg } from 'blockly/core';
export default function addBoardFSItem () { export default function addBoardFSItem () {
const mainWorkspace = Workspace.getMain(); const mainWorkspace = Workspace.getMain();
@@ -26,7 +27,12 @@ export default function addBoardFSItem () {
isHtmlName: true, isHtmlName: true,
name: ContextMenu.getItem(Msg.BOARD_FS, ''), name: ContextMenu.getItem(Msg.BOARD_FS, ''),
callback: () => { callback: () => {
statusBarsManager.add('board-fs', 'board-fs', Msg.BOARD_FS, Msg.BOARD_FS); statusBarsManager.add({
type: 'board-fs',
id: 'board-fs',
name: Msg.BOARD_FS,
title: Msg.BOARD_FS
});
statusBarsManager.changeTo('board-fs'); statusBarsManager.changeTo('board-fs');
const fsStatusBar = statusBarsManager.getStatusBarById('board-fs'); const fsStatusBar = statusBarsManager.getStatusBarById('board-fs');
fsStatusBar.setHandler(new FSArduEsp32Handler()); fsStatusBar.setHandler(new FSArduEsp32Handler());

View File

@@ -1,7 +1,7 @@
import * as goog from 'goog';
import { Msg } from 'blockly/core';
import { Workspace, ContextMenu } from 'mixly'; import { Workspace, ContextMenu } from 'mixly';
import FSArduEsp8266Handler from './fs-board-handler'; import FSArduEsp8266Handler from './fs-board-handler';
import { Msg } from 'blockly/core';
import * as goog from 'goog';
export default function addBoardFSItem () { export default function addBoardFSItem () {
@@ -27,7 +27,12 @@ export default function addBoardFSItem () {
isHtmlName: true, isHtmlName: true,
name: ContextMenu.getItem(Msg.BOARD_FS, ''), name: ContextMenu.getItem(Msg.BOARD_FS, ''),
callback: () => { callback: () => {
statusBarsManager.add('board-fs', 'board-fs', Msg.BOARD_FS, Msg.BOARD_FS); statusBarsManager.add({
type: 'board-fs',
id: 'board-fs',
name: Msg.BOARD_FS,
title: Msg.BOARD_FS
});
statusBarsManager.changeTo('board-fs'); statusBarsManager.changeTo('board-fs');
const fsStatusBar = statusBarsManager.getStatusBarById('board-fs'); const fsStatusBar = statusBarsManager.getStatusBarById('board-fs');
fsStatusBar.setHandler(new FSArduEsp8266Handler()); fsStatusBar.setHandler(new FSArduEsp8266Handler());

View File

@@ -41,7 +41,12 @@ export default class StatusBarFileSystem extends PageBase {
StatusBarsManager.typesRegistry.register(['file-system'], StatusBarFileSystem); StatusBarsManager.typesRegistry.register(['file-system'], StatusBarFileSystem);
const mainWorkspace = Workspace.getMain(); const mainWorkspace = Workspace.getMain();
const statusBarsManager = mainWorkspace.getStatusBarsManager(); const statusBarsManager = mainWorkspace.getStatusBarsManager();
statusBarsManager.add('file-system', 'file-system', Blockly.Msg.PYTHON_PYODIDE_FILE_SYSTEM); statusBarsManager.add({
type: 'file-system',
id: 'file-system',
name: Blockly.Msg.PYTHON_PYODIDE_FILE_SYSTEM,
title: Blockly.Msg.PYTHON_PYODIDE_FILE_SYSTEM
});
statusBarsManager.changeTo('output'); statusBarsManager.changeTo('output');
return statusBarsManager.get('file-system'); return statusBarsManager.get('file-system');
} }

View File

@@ -1,11 +1,11 @@
import * as Blockly from 'blockly/core'; import $ from 'jquery';
import { Msg } from 'blockly/core';
import { import {
PageBase, PageBase,
HTMLTemplate, HTMLTemplate,
StatusBarsManager, StatusBarsManager,
Workspace Workspace
} from 'mixly'; } from 'mixly';
import $ from 'jquery';
import '../language/loader'; import '../language/loader';
import STATUS_BAR_IMAGE_TEMPLATE from '../templates/html/statusbar-image.html'; import STATUS_BAR_IMAGE_TEMPLATE from '../templates/html/statusbar-image.html';
@@ -21,7 +21,12 @@ export default class StatusBarImage extends PageBase {
StatusBarsManager.typesRegistry.register(['images'], StatusBarImage); StatusBarsManager.typesRegistry.register(['images'], StatusBarImage);
const mainWorkspace = Workspace.getMain(); const mainWorkspace = Workspace.getMain();
const statusBarsManager = mainWorkspace.getStatusBarsManager(); const statusBarsManager = mainWorkspace.getStatusBarsManager();
statusBarsManager.add('images', 'images', Blockly.Msg.PYTHON_PYODIDE_IMAGE); statusBarsManager.add({
type: 'images',
id: 'images',
name: Msg.PYTHON_PYODIDE_IMAGE,
title: Msg.PYTHON_PYODIDE_IMAGE
});
statusBarsManager.changeTo('output'); statusBarsManager.changeTo('output');
return statusBarsManager.get('images'); return statusBarsManager.get('images');
} }

View File

@@ -1,11 +1,13 @@
import STATUS_BAR_IMAGE_TEMPLATE from '../templates/html/statusbar-image.html'; import $ from 'jquery';
import { Msg } from 'blockly/core';
import { import {
PageBase, PageBase,
HTMLTemplate, HTMLTemplate,
StatusBarsManager, StatusBarsManager,
Workspace Workspace
} from 'mixly'; } from 'mixly';
import $ from 'jquery'; import STATUS_BAR_IMAGE_TEMPLATE from '../templates/html/statusbar-image.html';
class StatusBarImage extends PageBase { class StatusBarImage extends PageBase {
static { static {
@@ -18,7 +20,12 @@ class StatusBarImage extends PageBase {
StatusBarsManager.typesRegistry.register(['images'], StatusBarImage); StatusBarsManager.typesRegistry.register(['images'], StatusBarImage);
const mainWorkspace = Workspace.getMain(); const mainWorkspace = Workspace.getMain();
const statusBarsManager = mainWorkspace.getStatusBarsManager(); const statusBarsManager = mainWorkspace.getStatusBarsManager();
statusBarsManager.add('images', 'images', '图像'); statusBarsManager.add({
type: 'images',
id: 'images',
name: Msg.MIXLY_MICROBIT_IMAGE,
title: Msg.MIXLY_MICROBIT_IMAGE
});
statusBarsManager.changeTo('output'); statusBarsManager.changeTo('output');
} }
} }

View File

@@ -1,11 +1,13 @@
import STATUS_BAR_IMAGE_TEMPLATE from '../templates/html/statusbar-image.html'; import $ from 'jquery';
import { Msg } from 'blockly/core';
import { import {
PageBase, PageBase,
HTMLTemplate, HTMLTemplate,
StatusBarsManager, StatusBarsManager,
Workspace Workspace
} from 'mixly'; } from 'mixly';
import $ from 'jquery'; import STATUS_BAR_IMAGE_TEMPLATE from '../templates/html/statusbar-image.html';
class StatusBarImage extends PageBase { class StatusBarImage extends PageBase {
static { static {
@@ -18,7 +20,12 @@ class StatusBarImage extends PageBase {
StatusBarsManager.typesRegistry.register(['images'], StatusBarImage); StatusBarsManager.typesRegistry.register(['images'], StatusBarImage);
const mainWorkspace = Workspace.getMain(); const mainWorkspace = Workspace.getMain();
const statusBarsManager = mainWorkspace.getStatusBarsManager(); const statusBarsManager = mainWorkspace.getStatusBarsManager();
statusBarsManager.add('images', 'images', '图像'); statusBarsManager.add({
type: 'images',
id: 'images',
name: Msg.MIXLY_MICROBIT_IMAGE,
title: Msg.MIXLY_MICROBIT_IMAGE
});
statusBarsManager.changeTo('output'); statusBarsManager.changeTo('output');
} }
} }

View File

@@ -105,10 +105,12 @@ class App extends Component {
this.#nav_ = new Nav(); this.#nav_ = new Nav();
this.#nav_.mountOn($content.find('.mixly-nav')); this.#nav_.mountOn($content.find('.mixly-nav'));
this.#workspace_ = new Workspace($content.find('.mixly-workspace')[0]); this.#workspace_ = new Workspace($content.find('.mixly-workspace')[0]);
this.#workspace_.getEditorsManager().getTabs().addTab({ const editorsManager = this.#workspace_.getEditorsManager();
editorsManager.add({
type: '.mix',
id: 'Untitled-1.mix',
name: 'Untitled-1.mix', name: 'Untitled-1.mix',
title: 'Untitled-1.mix', title: 'Untitled-1.mix',
type: '.mix',
favicon: 'fileicon-mix' favicon: 'fileicon-mix'
}); });
this.#footerbar_ = new FooterBar(); this.#footerbar_ = new FooterBar();

View File

@@ -152,12 +152,19 @@ class PagesManager extends Component {
return this.get(this.#activeId_); return this.get(this.#activeId_);
} }
add(type, id, name = null, title = null, favicon = null) { add(...args) {
this.#tabs_.addTab({ if (args[0] && typeof args[0] === 'object') {
name: name ?? id, this.#tabs_.addTab(args[0]);
title: title ?? id, } else {
type, favicon, id const [type, id, name, title, favicon] = args;
}); this.#tabs_.addTab({
type,
id,
name: name ?? id,
title: title ?? id,
favicon
});
}
} }
remove(id) { remove(id) {

View File

@@ -200,7 +200,12 @@ class StatusBarsManager extends PagesManager {
isHtmlName: true, isHtmlName: true,
name: ContextMenu.getItem(Msg.Lang['statusbar.ampy'], ''), name: ContextMenu.getItem(Msg.Lang['statusbar.ampy'], ''),
callback: (key, opt) => { callback: (key, opt) => {
this.add('ampy', 'ampy', Msg.Lang['statusbar.ampy'], ''); this.add({
type: 'ampy',
id: 'ampy',
name: Msg.Lang['statusbar.ampy'],
title: Msg.Lang['statusbar.ampy']
});
this.changeTo('ampy'); this.changeTo('ampy');
} }
} }

View File

@@ -83,7 +83,12 @@ class Workspace extends Component {
this.#$dragVRight_ = $content.find('.drag-v-right'); this.#$dragVRight_ = $content.find('.drag-v-right');
this.#$dragH_ = $content.find('.drag-h'); this.#$dragH_ = $content.find('.drag-h');
this.#statusBarsManager_ = new StatusBarsManager($content.find('.statusbars')[0]); this.#statusBarsManager_ = new StatusBarsManager($content.find('.statusbars')[0]);
this.#statusBarsManager_.add('terminal', 'output', Msg.Lang['statusbar.output']); this.#statusBarsManager_.add({
type: 'terminal',
id: 'output',
name: Msg.Lang['statusbar.output'],
title: Msg.Lang['statusbar.output']
});
this.#statusBarsManager_.changeTo('output'); this.#statusBarsManager_.changeTo('output');
this.#editorsManager_ = new EditorsManager($content.find('.editors')[0]); this.#editorsManager_ = new EditorsManager($content.find('.editors')[0]);
this.#leftSideBarsManager_ = new LeftSideBarsManager($content.find('.left-sidebars')[0]); this.#leftSideBarsManager_ = new LeftSideBarsManager($content.find('.left-sidebars')[0]);