From a9a8f569b644718ed58aa30171fda775244651bd Mon Sep 17 00:00:00 2001 From: fofolee Date: Tue, 30 Jun 2020 19:53:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=8F=8A=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=E6=8B=89=E6=A1=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/assets/options.js | 95 +++++++++++++++++++++++++++---------------- src/img/file.svg | 1 + src/img/key.svg | 1 + src/img/regex.svg | 1 + src/img/window.svg | 1 + 5 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 src/img/file.svg create mode 100644 src/img/key.svg create mode 100644 src/img/regex.svg create mode 100644 src/img/window.svg diff --git a/src/assets/options.js b/src/assets/options.js index 535fda8..f2889d4 100644 --- a/src/assets/options.js +++ b/src/assets/options.js @@ -278,13 +278,8 @@ }) let customWindow = `

- 模 式 - + 匹 配 + 关键字

说 明 @@ -357,17 +352,12 @@ $("#icon").attr('src', 'logo/quickcommand.png'); getSpecialVars() createEditor() - $('#program, #type, #output').select2({ - width: '40%', - minimumResultsForSearch: Infinity, - dropdownParent: $("#customize") - }); - $('#vars').select2({ - width: '40%', - placeholder: "插入特殊变量", - minimumResultsForSearch: Infinity, - dropdownParent: $("#customize") - }); + createProgramSelect2('40%') + createTypeSelect2('40%') + var singleSelectOpt = { width: '40%', minimumResultsForSearch: Infinity, dropdownParent: $("#customize") } + $('#output').select2(singleSelectOpt); + singleSelectOpt.placeholder = "插入特殊变量" + $('#vars').select2(singleSelectOpt); $('#tags').select2({ width: '40%', placeholder: "选择或添加标签, 最多3个", @@ -382,6 +372,53 @@ (e.params.args.data.text == "默认" || e.params.args.data.text == "未分类") && !fofoCommon.isDev() && e.preventDefault(); }) } + + let getSelect2Option = (data, width, dropdownAutoWidth = false) => { + var options = { + data: data, + minimumResultsForSearch: Infinity, + dropdownParent: $("#customize"), + dropdownAutoWidth: dropdownAutoWidth, + escapeMarkup: markup => markup, + templateSelection: data => data.text, + templateResult: data => data.html + } + if (width) options.width = width + return options + } + + let createTypeSelect2 = (width = false) => { + var data = [ + { + id: "key", + text: "关键字", + html: "关键字

在主输入框输入对应关键字进入插件,最通用的一种模式,关键字可以设置多个
" + }, + { + id: "regex", + text: "正则/划词", + html: "正则/划词
正则匹配主输入框文本或唤出语音面板时选中的文本,可以获取输入框文本或选中文本作为变量
" + }, + { + id: "window", + text: "窗口/进程", + html: "窗口/进程
匹配呼出uTools前或唤出语音面板时的活动窗口,可以获取窗口的信息或文件夹路径作为变量
" + }, + { + id: "files", + text: "复制/选中文件", + html: "复制/选中文件
匹配拖入主输入框的文件或唤出语音面板时选中的文件,可以获取复制及选中的文件信息作为变量
" + } + ] + $('#type').select2(getSelect2Option(data, width)); + } + + let createProgramSelect2 = (width, dropdownAutoWidth = false) => { + var programStyled = p => `${p}` + var data = [{ id: "quickcommand", text: 'quickcommand', html: programStyled('quickcommand') }] + data = data.concat(Object.keys(programs).map(x => { return { id: x, text: x, html: programStyled(x) } })) + $('#program').select2(getSelect2Option(data, width, dropdownAutoWidth)); + } let createEditor = () => { window.editor = CodeMirror.fromTextArea(document.getElementById("cmd"), { @@ -673,7 +710,7 @@ - + @@ -705,6 +742,7 @@ json = getDB('customFts')[code], options = { title: '选择保存位置', + defaultPath: `${json.features.explain}.json`, filters: [ { name: 'json', extensions: ['json'] }, ] @@ -999,14 +1037,9 @@ } showCodeEditor = file => { - let options = `` var customWindow = ` -
- + @@ -1030,16 +1063,16 @@ $("#customize").css({ top: '0px', padding: '0px' }); $("span.customscript > input").css({"height": "30px"}) var db = getDB('codeHistory') + createProgramSelect2(140, true) if (file) { var fileinfo = getFileInfo({ type: 'file', argvs: file, readfile: true }) - console.log(fileinfo); window.editor.setValue(fileinfo.data) var program = Object.keys(programs).filter(x => `.${programs[x].ext}` == fileinfo.ext) - if (program) $('#program').val(program[0]) + if (program) $('#program').val(program[0]).trigger('change') // runCurrentCommand() } else if(db.history){ window.editor.setValue(db.history.cmd) - $('#program').val(db.history.program) + $('#program').val(db.history.program).trigger('change') $('#scptarg').val(db.history.scptarg) var custom = db.history.customoptions if (db.history.program = 'custom' && custom) { @@ -1050,12 +1083,6 @@ } } programCheck() - $('#program').select2({ - width: 140, - minimumResultsForSearch: Infinity, - dropdownParent: $("#customize"), - dropdownAutoWidth: true - }); $("#options").show() } diff --git a/src/img/file.svg b/src/img/file.svg new file mode 100644 index 0000000..97f938f --- /dev/null +++ b/src/img/file.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/img/key.svg b/src/img/key.svg new file mode 100644 index 0000000..5ed52c2 --- /dev/null +++ b/src/img/key.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/img/regex.svg b/src/img/regex.svg new file mode 100644 index 0000000..42acdb4 --- /dev/null +++ b/src/img/regex.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/img/window.svg b/src/img/window.svg new file mode 100644 index 0000000..3c1654b --- /dev/null +++ b/src/img/window.svg @@ -0,0 +1 @@ + \ No newline at end of file