mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 23:16:18 +08:00
feat: 新增“新建快捷命令”功能
This commit is contained in:
parent
d230da2228
commit
3c9d826aaa
@ -78,6 +78,15 @@
|
|||||||
// utools.setExpendHeight(600);
|
// utools.setExpendHeight(600);
|
||||||
if (type == 'files') file = payload[0].path
|
if (type == 'files') file = payload[0].path
|
||||||
showCodeEditor(file)
|
showCodeEditor(file)
|
||||||
|
} else if (code == 'newcommand') {
|
||||||
|
utools.setExpendHeight(600)
|
||||||
|
$("#options").empty().fadeIn();
|
||||||
|
qc = {"program": "quickcommand","cmd": "","output": "ignore"}
|
||||||
|
if (payload != 'NewCommand' && payload != '新建快捷命令') {
|
||||||
|
let qcparser = quickCommandParser(payload, false)
|
||||||
|
if (qcparser.single) qc = qcparser.qc
|
||||||
|
}
|
||||||
|
editCurrentCommand(qc, false)
|
||||||
} else {
|
} else {
|
||||||
// console.log(new Date().getTime() - window.startTime);
|
// console.log(new Date().getTime() - window.startTime);
|
||||||
$('body').css({overflow: 'auto'})
|
$('body').css({overflow: 'auto'})
|
||||||
@ -312,21 +321,21 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 是否含有 quickcommand 键值
|
// 是否含有 quickcommand 键值
|
||||||
let isJsonQc = obj => {
|
let isJsonQc = (obj, strict = true) => {
|
||||||
var keys = ["features", "program", "cmd", "output"]
|
var keys = strict ? ["features", "program", "cmd", "output"] : ["program", "cmd"]
|
||||||
if (keys.filter(x => typeof obj[x] == 'undefined').length) return false
|
if (keys.filter(x => typeof obj[x] == 'undefined').length) return false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否为可导入的快捷命令
|
// 判断是否为可导入的快捷命令
|
||||||
let quickCommandParser = json => {
|
let quickCommandParser = (json, strict = true) => {
|
||||||
try {
|
try {
|
||||||
var qc = JSON.parse(json)
|
var qc = JSON.parse(json)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (isJsonQc(qc)) return { single: true, qc: qc }
|
if (isJsonQc(qc, strict)) return { single: true, qc: qc }
|
||||||
else if (!Object.values(qc).filter(q => !isJsonQc(q)).length) return { single: false, qc: qc }
|
else if (!Object.values(qc).filter(q => !isJsonQc(q, strict)).length) return { single: false, qc: qc }
|
||||||
else return false
|
else return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1006,9 +1015,10 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
let editCurrentCommand = data => {
|
let editCurrentCommand = async (data, animate = true) => {
|
||||||
let code = data.features.code
|
let features = data.features || {}
|
||||||
let platform = data.features.platform
|
let code = features.code
|
||||||
|
let platform = features.platform
|
||||||
let readonly = false
|
let readonly = false
|
||||||
let extraInfo = {
|
let extraInfo = {
|
||||||
authorName: data.authorName,
|
authorName: data.authorName,
|
||||||
@ -1020,7 +1030,8 @@
|
|||||||
$('#customize').data('extraInfo', extraInfo)
|
$('#customize').data('extraInfo', extraInfo)
|
||||||
data.tags && $('#tags').val(data.tags).trigger('change')
|
data.tags && $('#tags').val(data.tags).trigger('change')
|
||||||
platform && ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled')))
|
platform && ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled')))
|
||||||
let cmds = data.features.cmds
|
let cmds = features.cmds
|
||||||
|
if (cmds) {
|
||||||
let type = getCmdsType(cmds)
|
let type = getCmdsType(cmds)
|
||||||
$('#type').val(type).trigger("change")
|
$('#type').val(type).trigger("change")
|
||||||
if (type == 'professional') {
|
if (type == 'professional') {
|
||||||
@ -1035,15 +1046,20 @@
|
|||||||
else $('#rule').val(cmds.match.app);
|
else $('#rule').val(cmds.match.app);
|
||||||
} else {
|
} else {
|
||||||
$('#type').val('key').trigger("change")
|
$('#type').val('key').trigger("change")
|
||||||
$('#rule').val(data.features.cmds.toString());
|
$('#rule').val(features.cmds.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$('#type').val('key').trigger("change")
|
||||||
|
}
|
||||||
$('#code').val(code);
|
$('#code').val(code);
|
||||||
$('#program').val(data.program).trigger("change");
|
$('#program').val(data.program).trigger("change");
|
||||||
$('#output').val(data.output).trigger("change");
|
$('#output').val(data.output).trigger("change");
|
||||||
$('#desc').val(data.features.explain);
|
$('#desc').val(features.explain);
|
||||||
$('#scptarg').val(data.scptarg);
|
$('#scptarg').val(data.scptarg);
|
||||||
$("#icon").attr('src', data.features.icon);
|
let icon = features.icon || ''
|
||||||
|
if (icon && !/^(data:image\/png;base64,|logo\/)/.test(icon) ) icon = await getBase64Ico(icon)
|
||||||
|
$("#icon").attr('src', icon);
|
||||||
let mode = data.program;
|
let mode = data.program;
|
||||||
if (mode == 'custom') {
|
if (mode == 'custom') {
|
||||||
$('#custombin').show().val(data.customOptions.bin);
|
$('#custombin').show().val(data.customOptions.bin);
|
||||||
@ -1054,10 +1070,15 @@
|
|||||||
typeCheck();
|
typeCheck();
|
||||||
programCheck();
|
programCheck();
|
||||||
// 分段载入,保障动画流畅
|
// 分段载入,保障动画流畅
|
||||||
|
if (animate) {
|
||||||
window.editor.setValue(data.cmd.slice(0, 2000));
|
window.editor.setValue(data.cmd.slice(0, 2000));
|
||||||
$("#customize").animate({ top: '0px' }, () => {
|
$("#customize").animate({ top: '0px' }, () => {
|
||||||
window.editor.replaceRange(data.cmd.slice(2000), {line: Infinity});
|
window.editor.replaceRange(data.cmd.slice(2000), {line: Infinity});
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$("#customize").css({ top: '0px' })
|
||||||
|
window.editor.setValue(data.cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑
|
// 编辑
|
||||||
|
Loading…
x
Reference in New Issue
Block a user