add button to CLI for loading commands from file

10.7.0-preview
Károly Kiripolszky 2018-11-20 11:27:05 +01:00
parent 55b11e90b4
commit 3560d7b716
3 changed files with 43 additions and 0 deletions

View File

@ -2289,6 +2289,12 @@
"cliCopySuccessful": {
"message": "Copied!"
},
"cliLoadFromFileBtn": {
"message": "Load from file"
},
"cliCommandsLoadedNotice": {
"message": "Commands loaded from `{{filename}}`. Press ENTER to confirm execution!"
},
"loggingNote": {
"message": "Data will be logged in this tab <span class=\"message-negative\">only</span>, leaving the tab will <span class=\"message-negative\">cancel</span> logging and application will return to its normal <strong>\"configurator\"</strong> state.<br /> You are free to select the global update period, data will be written into the log file every <strong>1</strong> second for performance reasons."

View File

@ -174,6 +174,42 @@ TABS.cli.initialize = function (callback, nwGui) {
$('.tab-cli .copy').hide();
}
$('.tab-cli .load').click(function() {
var suffix = 'txt',
accepts = [{
description: suffix.toUpperCase() + ' files', extensions: [suffix],
}];
chrome.fileSystem.chooseEntry({type: 'openFile', accepts: accepts}, function(entry) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}
if (!entry) {
console.log('No file selected');
return;
}
function setCommands(result) {
let notice = i18n.getMessage("cliCommandsLoadedNotice", {
filename: entry.name,
});
textarea.val(result + "\n" + "# " + notice);
// scroll to the last line to show confirmation notice
textarea.scrollTop(textarea[0].scrollHeight);
}
entry.file((file) => {
let reader = new FileReader();
reader.onload =
() => setCommands(reader.result);
reader.onerror = () => console.error(reader.error);
reader.readAsText(file);
});
});
});
// Tab key detection must be on keydown,
// `keypress`/`keyup` happens too late, as `textarea` will have already lost focus.
textarea.keydown(function (event) {

View File

@ -16,6 +16,7 @@
<div class="content_toolbar">
<div class="btn save_btn pull-right">
<a class="save" href="#" i18n="cliSaveToFileBtn"></a>
<a class="load" href="#" i18n="cliLoadFromFileBtn"></a>
<a class="clear" href="#" i18n="cliClearOutputHistoryBtn"></a>
<a class="copy" href="#" i18n="cliCopyToClipboardBtn"></a>
</div>