Update: 调整Ampy板卡文件管理
本次更新用以配置Ampy板卡文件管理使其仅支持编辑文本文件
This commit is contained in:
@@ -23,7 +23,8 @@ class EditorAce extends EditorBase {
|
||||
static {
|
||||
this.CTRL_BTNS = ['resetFontSize', 'increaseFontSize', 'decreaseFontSize'];
|
||||
this.CTRL_BTN_TEMPLATE = '<div m-id="{{d.mId}}" class="code-editor-btn setFontSize"></div>';
|
||||
|
||||
this.MODE_MAP = goog.getJSON(path.join(Env.templatePath, 'json/ace-mode-map.json'));
|
||||
|
||||
HTMLTemplate.add(
|
||||
'html/editor/editor-code.html',
|
||||
new HTMLTemplate(goog.get(path.join(Env.templatePath, 'html/editor/editor-code.html')))
|
||||
@@ -279,6 +280,24 @@ class EditorAce extends EditorBase {
|
||||
this.#editor_.setReadOnly(status);
|
||||
}
|
||||
|
||||
setMode(type) {
|
||||
this.#editor_.session.setMode(`ace/mode/${type}`);
|
||||
}
|
||||
|
||||
setFileMode(extname) {
|
||||
const mode = this.getFileMode(extname) ?? 'text';
|
||||
this.setMode(mode);
|
||||
}
|
||||
|
||||
getFileMode(extname) {
|
||||
for (const [mode, extensions] of Object.entries(EditorAce.MODE_MAP)) {
|
||||
if (extensions.includes(extname)) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
cut() {
|
||||
const { selection, session } = this.#editor_;
|
||||
const cutLine = selection.isEmpty();
|
||||
|
||||
@@ -130,7 +130,7 @@ class FileTree extends Component {
|
||||
});
|
||||
this.#jstree_ = this.#$fileTree_.jstree(true);
|
||||
this.addEventsType([
|
||||
'selectLeaf', 'afterOpenNode', 'afterCloseNode', 'afterRefreshNode',
|
||||
'beforeSelectLeaf', 'afterSelectLeaf', 'afterOpenNode', 'afterCloseNode', 'afterRefreshNode',
|
||||
'afterCreateNode', 'afterDeleteNode', 'afterRenameNode'
|
||||
]);
|
||||
this.#addEventsListener_();
|
||||
@@ -202,8 +202,14 @@ class FileTree extends Component {
|
||||
if (selected[0].id === this.#selected_) {
|
||||
return;
|
||||
}
|
||||
this.#selected_ = selected[0].id;
|
||||
this.runEvent('selectLeaf', selected);
|
||||
const result = this.runEvent('beforeSelectLeaf', selected);
|
||||
if ((result.length && result[0]) || !result.length) {
|
||||
this.#selected_ = selected[0].id;
|
||||
this.runEvent('afterSelectLeaf', selected);
|
||||
} else {
|
||||
this.deselect(selected[0].id);
|
||||
this.reselect();
|
||||
}
|
||||
})
|
||||
.on('refresh.jstree', (e, data) => {
|
||||
this.runEvent('afterRefreshNode', data.node);
|
||||
|
||||
@@ -89,9 +89,20 @@ class StatusBarAmpy extends PageBase {
|
||||
this.openFS();
|
||||
});
|
||||
|
||||
this.#fileTree_.bind('selectLeaf', async (selected) => {
|
||||
this.#fileTree_.showProgress();
|
||||
this.#fileTree_.bind('beforeSelectLeaf', (selected) => {
|
||||
const filePath = selected[0].id;
|
||||
const mode = this.#editor_.getFileMode(path.extname(filePath));
|
||||
if (!mode) {
|
||||
layer.msg(Msg.Lang['statusbar.ampy.cannotEdit'], { time: 1000 });
|
||||
return false;
|
||||
}
|
||||
this.#editor_.setMode(mode);
|
||||
return true;
|
||||
});
|
||||
|
||||
this.#fileTree_.bind('afterSelectLeaf', async (selected) => {
|
||||
const filePath = selected[0].id;
|
||||
this.#fileTree_.showProgress();
|
||||
const fs = this.#fileTree_.getFS();
|
||||
const [error, result] = await fs.readFile(filePath);
|
||||
if (error) {
|
||||
@@ -103,9 +114,6 @@ class StatusBarAmpy extends PageBase {
|
||||
this.#editor_.scrollToTop();
|
||||
this.#editor_.focus();
|
||||
this.setStatus(false);
|
||||
this.#editor_.getEditor().session.setMode(
|
||||
`ace/mode/${this.getLanguageByExt(path.extname(filePath))}`
|
||||
);
|
||||
}
|
||||
this.#fileTree_.hideProgress();
|
||||
});
|
||||
@@ -173,7 +181,7 @@ class StatusBarAmpy extends PageBase {
|
||||
this.#fileTree_.refreshFolder(id);
|
||||
} else {
|
||||
const nodes = this.#fileTree_.getSelectedNodes();
|
||||
this.#fileTree_.runEvent('selectLeaf', nodes);
|
||||
this.#fileTree_.runEvent('afterSelectLeaf', nodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -439,38 +447,6 @@ class StatusBarAmpy extends PageBase {
|
||||
}
|
||||
}
|
||||
|
||||
getLanguageByExt(ext) {
|
||||
let language = 'text';
|
||||
switch(ext) {
|
||||
case '.json':
|
||||
language = 'json';
|
||||
break;
|
||||
case '.c':
|
||||
case '.cpp':
|
||||
case '.h':
|
||||
case '.hpp':
|
||||
case '.ino':
|
||||
language = 'c_cpp';
|
||||
break;
|
||||
case '.js':
|
||||
language = 'javascript';
|
||||
break;
|
||||
case '.py':
|
||||
language = 'python';
|
||||
break;
|
||||
case '.lua':
|
||||
language = 'lua';
|
||||
break;
|
||||
case '.md':
|
||||
case '.mdx':
|
||||
language = 'markdown';
|
||||
break;
|
||||
default:
|
||||
language = 'text';
|
||||
}
|
||||
return language;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.#editor_.dispose();
|
||||
this.#fileTree_.dispose();
|
||||
|
||||
@@ -103,7 +103,7 @@ class Workspace extends Component {
|
||||
#addEventsListenerForFileTree_() {
|
||||
const leftSideBarLocalStorage = this.getLeftSideBarsManager().get('local_storage');
|
||||
const fileTree = leftSideBarLocalStorage.getFileTree();
|
||||
fileTree.bind('selectLeaf', (selected) => {
|
||||
fileTree.bind('afterSelectLeaf', (selected) => {
|
||||
const tabs = this.#editorsManager_.getTabs();
|
||||
tabs.addTab({
|
||||
name: selected[0].text,
|
||||
|
||||
@@ -137,7 +137,7 @@ BU.burnByUSB = () => {
|
||||
const hex2Blob = new Blob([ hexStr ], { type: 'text/plain' });
|
||||
const buffer = await hex2Blob.arrayBuffer();
|
||||
if (!buffer) {
|
||||
layer.msg(Msg.Lang['固件读取出错'], { time: 1000 });
|
||||
layer.msg(Msg.Lang['shell.bin.readFailed'], { time: 1000 });
|
||||
return;
|
||||
}
|
||||
BU.burning = true;
|
||||
|
||||
@@ -244,6 +244,7 @@
|
||||
"statusbar.ampy.loadBoardFS": "Load board FS",
|
||||
"statusbar.ampy.refresh": "Refresh",
|
||||
"statusbar.ampy.exit": "Exit",
|
||||
"statusbar.ampy.cannotEdit": "This file type does not support editing",
|
||||
"statusbar.dropdownMenu.noOptions": "No options",
|
||||
"statusbar.fs.newMapFolder": "Create a new mapping directory",
|
||||
"statusbar.fs.localFolderNotExist": "Local mapping directory does not exist",
|
||||
|
||||
@@ -244,6 +244,7 @@
|
||||
"statusbar.ampy.loadBoardFS": "载入板卡文件夹",
|
||||
"statusbar.ampy.refresh": "刷新",
|
||||
"statusbar.ampy.exit": "退出",
|
||||
"statusbar.ampy.cannotEdit": "该文件类型不支持编辑",
|
||||
"statusbar.dropdownMenu.noOptions": "无选项",
|
||||
"statusbar.fs.newMapFolder": "新建映射目录",
|
||||
"statusbar.fs.localFolderNotExist": "本地映射目录不存在",
|
||||
|
||||
@@ -244,6 +244,7 @@
|
||||
"statusbar.ampy.loadBoardFS": "載入卡卡資料夾",
|
||||
"statusbar.ampy.refresh": "刷新",
|
||||
"statusbar.ampy.exit": "退出",
|
||||
"statusbar.ampy.cannotEdit": "該文件類型不支援編輯",
|
||||
"statusbar.dropdownMenu.noOptions": "無選項",
|
||||
"statusbar.fs.newMapFolder": "新映射目錄",
|
||||
"statusbar.fs.localFolderNotExist": "本機映射目錄不存在",
|
||||
|
||||
171
common/templates/json/ace-mode-map.json
Normal file
171
common/templates/json/ace-mode-map.json
Normal file
@@ -0,0 +1,171 @@
|
||||
{
|
||||
"abap": [".abap"],
|
||||
"abc": [".abc"],
|
||||
"actionscript": [".as"],
|
||||
"ada": [".ada", ".adb", ".ads"],
|
||||
"alda": [".alda"],
|
||||
"apex": [".apex"],
|
||||
"aql": [".aql"],
|
||||
"asciidoc": [".adoc", ".asciidoc"],
|
||||
"asl": [".dsl", ".asl"],
|
||||
"assembly_x86": [".asm", ".a", ".s"],
|
||||
"autohotkey": [".ahk"],
|
||||
"batchfile": [".bat", ".cmd"],
|
||||
"bro": [".bro"],
|
||||
"c9search": [".c9search_results"],
|
||||
"c_cpp": [".c", ".cpp", ".cc", ".cxx", ".h", ".hh", ".hpp", ".ino"],
|
||||
"cirru": [".cirru", ".cr"],
|
||||
"clojure": [".clj", ".cljs"],
|
||||
"cobol": [".cbl", ".cob"],
|
||||
"coffee": [".coffee", ".cf", ".cson", ".iced"],
|
||||
"coldfusion": [".cfm"],
|
||||
"crystal": [".cr"],
|
||||
"csharp": [".cs"],
|
||||
"csound_document": [".csd"],
|
||||
"csound_orchestra": [".orc"],
|
||||
"csound_score": [".sco"],
|
||||
"css": [".css"],
|
||||
"curly": [".curl"],
|
||||
"d": [".d", ".di"],
|
||||
"dart": [".dart"],
|
||||
"diff": [".diff", ".patch"],
|
||||
"dockerfile": [".dockerfile"],
|
||||
"dot": [".dot"],
|
||||
"drools": [".drl"],
|
||||
"edifact": [".edi"],
|
||||
"eiffel": [".e"],
|
||||
"ejs": [".ejs"],
|
||||
"elixir": [".ex", ".exs"],
|
||||
"elm": [".elm"],
|
||||
"erlang": [".erl", ".hrl"],
|
||||
"forth": [".frt", ".fs", ".ldr", ".fth"],
|
||||
"fortran": [".f", ".f77", ".f90", ".f95", ".f03", ".for", ".fpp"],
|
||||
"fsharp": [".fs", ".fsi", ".ml", ".mli"],
|
||||
"gcode": [".gcode"],
|
||||
"gherkin": [".feature"],
|
||||
"gitignore": [".gitignore"],
|
||||
"glsl": [".glsl", ".frag", ".vert"],
|
||||
"gobstones": [".gbs"],
|
||||
"golang": [".go"],
|
||||
"graphqlschema": [".gql", ".graphql"],
|
||||
"groovy": [".groovy"],
|
||||
"haml": [".haml"],
|
||||
"handlebars": [".hbs", ".handlebars"],
|
||||
"haskell": [".hs"],
|
||||
"haskell_cabal": [".cabal"],
|
||||
"haxe": [".hx"],
|
||||
"hjson": [".hjson"],
|
||||
"html": [".html", ".htm", ".xhtml"],
|
||||
"ini": [".ini", ".cfg", ".prefs"],
|
||||
"io": [".io"],
|
||||
"jack": [".jack"],
|
||||
"jade": [".jade"],
|
||||
"java": [".java"],
|
||||
"javascript": [".js", ".jsm", ".jsx"],
|
||||
"json": [".json"],
|
||||
"json5": [".json5"],
|
||||
"jsoniq": [".jq"],
|
||||
"jsp": [".jsp"],
|
||||
"jssm": [".jssm", ".jssm_state"],
|
||||
"jsx": [".jsx"],
|
||||
"julia": [".jl"],
|
||||
"kotlin": [".kt", ".kts"],
|
||||
"latex": [".tex", ".latex", ".ltx", ".bib"],
|
||||
"less": [".less"],
|
||||
"liquid": [".liquid"],
|
||||
"lisp": [".lisp"],
|
||||
"livescript": [".ls"],
|
||||
"logiql": [".logic", ".lql"],
|
||||
"logtalk": [".logtalk"],
|
||||
"lsl": [".lsl"],
|
||||
"lua": [".lua"],
|
||||
"luapage": [".lp"],
|
||||
"lucene": [".lucene"],
|
||||
"makefile": [".makefile", ".gnumakefile", ".ocamlmakefile", ".make"],
|
||||
"markdown": [".md", ".markdown"],
|
||||
"mask": [".mask"],
|
||||
"matlab": [".matlab"],
|
||||
"maze": [".mz"],
|
||||
"mediawiki": [".wiki", ".mediawiki"],
|
||||
"mel": [".mel"],
|
||||
"mips": [".s", ".asm"],
|
||||
"mithril": [".mjs"],
|
||||
"moonscript": [".moon"],
|
||||
"mysql": [".mysql"],
|
||||
"nginx": [".nginx", ".conf"],
|
||||
"nim": [".nim"],
|
||||
"nix": [".nix"],
|
||||
"nsis": [".nsi", ".nsh"],
|
||||
"nunjucks": [".njk", ".nunjucks"],
|
||||
"objectivec": [".m", ".mm"],
|
||||
"ocaml": [".ml", ".mli"],
|
||||
"pascal": [".pas", ".pp"],
|
||||
"perl": [".pl", ".pm"],
|
||||
"pgsql": [".pgsql"],
|
||||
"php": [".php", ".inc"],
|
||||
"php_laravel_blade": [".blade.php"],
|
||||
"pig": [".pig"],
|
||||
"powershell": [".ps1"],
|
||||
"praat": [".praat", ".praatscript", ".psc", ".proc"],
|
||||
"prisma": [".prisma"],
|
||||
"prolog": [".plg", ".prolog"],
|
||||
"properties": [".properties"],
|
||||
"protobuf": [".proto"],
|
||||
"puppet": [".pp"],
|
||||
"purescript": [".purs"],
|
||||
"python": [".py"],
|
||||
"q": [".q"],
|
||||
"qml": [".qml"],
|
||||
"r": [".r"],
|
||||
"raku": [".raku", ".rakumod", ".rakutest", ".pl6", ".pm6"],
|
||||
"razor": [".cshtml", ".razor"],
|
||||
"rdoc": [".rdoc"],
|
||||
"red": [".red", ".reds"],
|
||||
"rhtml": [".erb", ".rhtml"],
|
||||
"robot": [".robot"],
|
||||
"rst": [".rst"],
|
||||
"ruby": [".rb"],
|
||||
"rust": [".rs"],
|
||||
"sass": [".sass"],
|
||||
"scad": [".scad"],
|
||||
"scala": [".scala"],
|
||||
"scheme": [".scm", ".sm", ".rkt", ".oak"],
|
||||
"scrypt": [".scrypt"],
|
||||
"scss": [".scss"],
|
||||
"sh": [".sh", ".bash", ".bats", ".cgi", ".command", ".fcgi", ".ksh", ".sh.in", ".tmux", ".tool", ".zsh"],
|
||||
"sjs": [".sjs"],
|
||||
"slim": [".slim"],
|
||||
"smarty": [".tpl"],
|
||||
"smithy": [".smithy"],
|
||||
"snippets": [".snippets"],
|
||||
"soy_template": [".soy"],
|
||||
"space": [".space"],
|
||||
"sparql": [".rq"],
|
||||
"sql": [".sql"],
|
||||
"sqlserver": [".sqlserver"],
|
||||
"stylus": [".styl", ".stylus"],
|
||||
"svg": [".svg"],
|
||||
"swift": [".swift"],
|
||||
"tcl": [".tcl"],
|
||||
"terraform": [".tf", ".tfvars", ".terragrunt"],
|
||||
"tex": [".tex"],
|
||||
"text": [".txt"],
|
||||
"textile": [".textile"],
|
||||
"toml": [".toml"],
|
||||
"tsx": [".tsx"],
|
||||
"turtle": [".ttl"],
|
||||
"twig": [".twig"],
|
||||
"typescript": [".ts"],
|
||||
"vala": [".vala"],
|
||||
"vbscript": [".vbs"],
|
||||
"velocity": [".vm"],
|
||||
"verilog": [".v", ".vh", ".sv", ".svh"],
|
||||
"vhdl": [".vhd", ".vhdl"],
|
||||
"visualforce": [".vfp", ".component", ".page"],
|
||||
"wollok": [".wlk", ".wpgm"],
|
||||
"xml": [".xml", ".rdf", ".rss", ".wsdl", ".xslt", ".atom", ".mathml", ".mml", ".xul", ".xbl", ".xaml"],
|
||||
"xquery": [".xq"],
|
||||
"yaml": [".yaml", ".yml"],
|
||||
"zeek": [".zeek"],
|
||||
"zig": [".zig"]
|
||||
}
|
||||
Reference in New Issue
Block a user