提交 d1c082f1 编写于 作者: R rsercano

resolves #385

上级 8ea75359
......@@ -358,7 +358,15 @@ Helper.prototype = {
},
initializeCodeMirror (divSelector, txtAreaId, keepValue, height = 100, noResize) {
const autoCompleteShortcut = Settings.findOne().autoCompleteShortcut || "Ctrl-Space";
let codeMirror;
let extraKeys = {
"Ctrl-Q": function (cm) {
cm.foldCode(cm.getCursor());
}
};
extraKeys[autoCompleteShortcut] = "autocomplete";
if (!divSelector.data('editor')) {
codeMirror = CodeMirror.fromTextArea(document.getElementById(txtAreaId), {
mode: "javascript",
......@@ -366,12 +374,7 @@ Helper.prototype = {
styleActiveLine: true,
lineNumbers: true,
lineWrapping: false,
extraKeys: {
"Ctrl-Q": function (cm) {
cm.foldCode(cm.getCursor());
},
"Ctrl-Space": "autocomplete"
},
extraKeys: extraKeys,
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});
......@@ -461,6 +464,10 @@ export default helper;
return null;
};
Template.registerHelper('getConfiguredAutoCompletionKey', function () {
return Settings.findOne().autoCompleteShortcut || "Ctrl-Space";
});
Template.registerHelper('isOptionSelected', function (option, sessionVar) {
if (!sessionVar || Object.prototype.toString.call(sessionVar) !== '[object String]') return $.inArray(option, Session.get(helper.strSessionSelectedOptions)) !== -1;
......
......@@ -26,7 +26,7 @@
<div class="form-group">
<div id="divShellCommand" class="col-lg-12">
<textarea id="txtShellCommand" class="form-control"></textarea>
<span class="help-block m-b-none">Shell command to execute, <b>ENTER</b> executes it, <b>CTRL+SPACE</b> for autocompletion</span>
<span class="help-block m-b-none">Shell command to execute, <b>ENTER</b> executes it, <b>{{getConfiguredAutoCompletionKey}}</b> for autocompletion</span>
</div>
</div>
......
......@@ -8,7 +8,7 @@ import {FlowRouter} from "meteor/kadira:flow-router";
import {initShellHistories} from "./shell_histories/shell_histories";
import Enums from "/lib/imports/enums";
import Helper from "/client/imports/helper";
import {ShellCommands} from "/lib/imports/collections";
import {ShellCommands, Settings} from "/lib/imports/collections";
import "./mc_shell.html";
const CodeMirror = require("codemirror");
......@@ -123,7 +123,20 @@ const gatherCommandAutoCompletions = function (editorValue, curWord) {
};
const initializeCommandCodeMirror = function () {
const autoCompleteShortcut = Settings.findOne().autoCompleteShortcut || "Ctrl-Space";
let codeMirror;
let extraKeys = {
"Ctrl-Q": function (cm) {
cm.foldCode(cm.getCursor());
},
"Enter": function (cm) {
Meteor.call("executeShellCommand", cm.getValue(), Session.get(Helper.strSessionConnection), Session.get(Helper.strSessionPromptedUsername), Session.get(Helper.strSessionPromptedPassword), Meteor.default_connection._lastSessionId, (err) => {
if (err) Helper.showMeteorFuncError(err, null, "Couldn't execute shell command");
else addCommandToHistory(cm.getValue());
})
}
};
extraKeys[autoCompleteShortcut] = "autocomplete";
let divCommand = $('#divShellCommand');
if (!divCommand.data('editor')) {
codeMirror = CodeMirror.fromTextArea(document.getElementById('txtShellCommand'), {
......@@ -132,18 +145,7 @@ const initializeCommandCodeMirror = function () {
styleActiveLine: true,
lineNumbers: true,
lineWrapping: false,
extraKeys: {
"Ctrl-Q": function (cm) {
cm.foldCode(cm.getCursor());
},
"Ctrl-Space": "autocomplete",
"Enter": function (cm) {
Meteor.call("executeShellCommand", cm.getValue(), Session.get(Helper.strSessionConnection), Session.get(Helper.strSessionPromptedUsername), Session.get(Helper.strSessionPromptedPassword), Meteor.default_connection._lastSessionId, (err) => {
if (err) Helper.showMeteorFuncError(err, null, "Couldn't execute shell command");
else addCommandToHistory(cm.getValue());
})
}
},
extraKeys: extraKeys,
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});
......@@ -192,7 +194,7 @@ Template.mcShell.onRendered(function () {
return;
}
this.subscribe('settings');
const settings = this.subscribe('settings');
this.subscribe('connections');
this.subscribe('shell_commands');
......@@ -229,7 +231,11 @@ Template.mcShell.onRendered(function () {
}
});
initializeCommandCodeMirror();
this.autorun(() => {
if (settings.ready()) {
initializeCommandCodeMirror();
}
});
Meteor.call("connectToShell", Session.get(Helper.strSessionConnection), Session.get(Helper.strSessionPromptedUsername), Session.get(Helper.strSessionPromptedPassword), Meteor.default_connection._lastSessionId, (err, result) => {
if (err || result.error) Helper.showMeteorFuncError(err, result, "Couldn't connect via shell");
......
......@@ -105,6 +105,15 @@
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Autocomplete shortcut</label>
<div class="col-lg-9">
<input id="inputAutocompleteShortcut" required="true" type="text"
class="form-control">
<span class="help-block m-b-none">Combination should be seperated by dash. E.g. <b>Ctrl-Space</b>, <b>Alt-A</b>. Shell also uses this combination.</span>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Single tab for results</label>
<div class="col-lg-9">
......
......@@ -12,6 +12,7 @@ const Ladda = require('ladda');
const proceedSavingSettings = function () {
const settings = {};
settings.autoCompleteSamplesCount = $('#inputAutoCompleteSamplesCount').val();
settings.autoCompleteShortcut = $('#inputAutocompleteShortcut').val();
settings.scale = $("#cmbScale").chosen().val();
settings.defaultResultView = $("#cmbResultView").chosen().val();
settings.maxAllowedFetchSize = $("#inputMaxAllowedFetchSize").val();
......@@ -80,5 +81,5 @@ const load = function () {
$('#inputShowDBStats').iCheck(settings.showDBStats ? 'check' : 'uncheck');
$('#inputMongoExecutable').val(settings.mongoBinaryPath || '');
$('#inputMaxChartPoints').val(settings.maxLiveChartDataPoints || 15);
$('#inputAutocompleteShortcut').val(settings.autoCompleteShortcut || 'Ctrl-Space');
};
\ No newline at end of file
......@@ -3,7 +3,7 @@
<label class="col-lg-1 control-label">Selector</label>
<div id="divSelector" class="col-lg-11">
<textarea id="txtSelector" class="form-control"></textarea>
<span class="help-block m-b-none"><b>Extended json</b> is valid for all selectors</span>
<span class="help-block m-b-none"><b>Extended json</b> is valid for all selectors, <b>{{getConfiguredAutoCompletionKey}}</b> for autocompletion</span>
</div>
</div>
</template>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册