beautify: function() { var editor = editors.currentEditor; var sel = editor.getSelection(); var doc = editor.getDocument(); var range = sel.getRange(); var value = doc.getTextRange(range); // Load up current settings data var preserveEmpty = extSettings.model.queryValue("beautify/jsbeautify/@preserveempty") == "true" ? true : false; var keepIndentation = extSettings.model.queryValue("beautify/jsbeautify/@keeparrayindentation") == "true" ? true : false; var braces = extSettings.model.queryValue("beautify/jsbeautify/@braces") || "end-expand"; var indentSize = extSettings.model.queryValue("editors/code/@tabsize") || "4"; var indentTab = extSettings.model.queryValue("editors/code/@softtabs") == "true" ? " " : "\t"; if (indentTab == "\t") indentSize = 1; try { value = jsbeautify.js_beautify(value, { indent_size: indentSize, indent_char: indentTab, preserve_newlines: preserveEmpty, keep_array_indentation: keepIndentation, brace_style: braces }); } catch (e) { util.alert("Error", "This code could not be beautified", "Please correct any JavaScript errors and try again"); return; } var end = doc.replace(range, value); sel.setSelectionRange(Range.fromPoints(range.start, end)); },
function() { // on yes if (_self.cbAutoMerge.checked) settings.model.setQueryValue("general/@dontaskautomerge", "true"); settings.model.setQueryValue("general/@automergeenabled", "true"); settings.save(); winQuestion.hide(); _self.cbAutoMerge.parentNode.removeChild(_self.cbAutoMerge); },
show: function() { ext.initExtension(this); settings.model.setQueryValue("general/@revisionsvisible", true); ide.dispatchEvent("revisions.visibility", { visibility: "shown", width: BAR_WIDTH }); ceEditor.$editor.container.style.right = BAR_WIDTH + "px"; this.panel.show(); this.populateModel(); var all = this.allTimestamps; var cmp = this.compactTimestamps; var lastTimeStamp; if (this.useCompactList === true && cmp && cmp.length > 0) { lastTimeStamp = cmp[cmp.length - 1]; } else if (all && all.length > 0) { lastTimeStamp = all[all.length - 1]; } if (lastTimeStamp) { var node = this.model.queryNode("revision[@id='" + lastTimeStamp + "']"); if (node) { lstRevisions.select(node); } } tabEditors.getPage().$showRevisions = true; },
this.docChangeTimeout = setTimeout(function() { var autoSaveEnabled = apf.isTrue(settings.model.queryValue("general/@autosaveenabled")); if (doc.$page && autoSaveEnabled) { self.setSaveButtonCaption(); self.save(doc.$page); } }, CHANGE_TIMEOUT);
doAutoSave: function() { var autoSaveEnabled = apf.isTrue(settings.model.queryValue("general/@autosaveenabled")); if (!tabEditors || !autoSaveEnabled) return; tabEditors.getPages().forEach(this.save, this); },
onBeforeUnloadHandler : function () { // see what's in the settings var settingsNode = settings.model.queryNode("general/@confirmexit"); if (settingsNode && apf.isTrue(settingsNode.value)) { return "Are you sure you want to leave Cloud9?"; } },
set : function(path, dispatch){ //Save theme settings settings.model.setQueryValue("editors/code/@theme", path); settings.save(); this.saved = true; ide.dispatchEvent("track_action", {type: "theme change", theme: path}); },
hook : function() { var menuItem = new apf.item({ caption: "Vim mode", type: "check", checked : "[{require('ext/settings/settings').model}::editors/code/@vimmode]" }); // In order to behave like a code extension (i.e. hiding when we are not // in a code editor) we import it into the code plugin nodes instead of // ours. require("ext/code/code").nodes.push(mnuView.appendChild(menuItem)); var self = this; this.afterOpenFileFn = function() { enableVim.call(self); }; ide.addEventListener("init.ext/settings/settings", function (e) { setTimeout(function() { barSettings.insertMarkup(settings); }, 0); }); ide.addEventListener("code.ext:defaultbindingsrestored", function(e) { if (VIM_ENABLED === true) { enableVim.call(self); } }); extSettings.model.addEventListener("update", function(e) { var vimEnabled = e.currentTarget.queryValue("editors/code/@vimmode"); self.toggle(vimEnabled === "true"); }); },
setUnusedFunctionArgs: function(yeah) { if(extSettings.model.queryValue("language/@unusedFunctionArgs") != "false") this.worker.call("enableFeature", ["unusedFunctionArgs"]); else this.worker.call("disableFeature", ["unusedFunctionArgs"]); this.setPath(); },
setJSHint: function() { if(extSettings.model.queryValue("language/@jshint") != "false") this.worker.call("enableFeature", ["jshint"]); else this.worker.call("disableFeature", ["jshint"]); this.setPath(); },
setUndeclaredVars: function() { if(extSettings.model.queryValue("language/@undeclaredVars") != "false") this.worker.call("enableFeature", ["undeclaredVars"]); else this.worker.call("disableFeature", ["undeclaredVars"]); this.setPath(); },
"onprop.visible" : function(e){ if (e.value) { mnuThemes.select(null, settings.model.queryValue("editors/code/@theme") || _self.defaultTheme); } }
onExternalChange: function(e) { if (e.action == "remove") return; // We want to prevent autosave to keep saving while we are resolving // this query. this.prevAutoSaveValue = this.isAutoSaveEnabled; settings.model.setQueryValue("general/@autosaveenabled", false); var path = CoreUtil.stripWSFromPath(e.path); this.changedPaths.push(path); // Force initialization of extension (so that UI is available) ext.initExtension(this); if (winQuestionRev.visible === true || this.isCollab()) return; ide.send({ command: "revisions", subCommand: "getRealFileContents", path: path }); return false; },
ide.addEventListener("settings.load", function(e){ settings.setDefaults("editors/codewidget", [ ["colorpicker", "false"] ]); _self.updateSetting(); if (apf.isTrue(settings.model.queryValue("editors/codewidget/@colorpicker"))) _self.setEvents(); });
var tryEnabling = function () { if (settings.model) { var sholdEnable = apf.isTrue(settings.model.queryNode("editors/code").getAttribute("emacsmode")); if (EMACS_ENABLED == sholdEnable) return; self.enable(sholdEnable === true); } };
this.$timer = setTimeout(function(){ var state = _self.layout.getState(); settings.model.setQueryValue( "auto/dockpanel/text()", JSON.stringify(state) ); });
init : function(){ var _self = this; ide.addEventListener("theme.init", function(e){ var cssClass = e.theme.cssClass; var bg = apf.getStyleRule("." + cssClass + " .ace_scroller", "background-color"); apf.importStylesheet([ ["." + cssClass + " .bar-status", "background-color", bg + ", 0.0)"], ["." + cssClass + " .bar-status:hover", "background-color", bg + ", 0.95)"] ]); }); ide.addEventListener("vim.changeMode", function(e) { if (!window.lblInsertActive) return; if (e.mode === "insert") lblInsertActive.show(); else lblInsertActive.hide(); }); ide.addEventListener("minimap.visibility", function(e) { if (e.visibility === "shown") _self.offsetWidth = e.width; else _self.offsetWidth = 0; _self.setPosition(); }); ide.addEventListener("init.ext/editors/editors", function(e){ ide.addEventListener("tab.afterswitch", function(e){ var editor = e.nextPage.$editor; _self.onAfterSwitch(editor); }); }); this.sbWidth = code.amlEditor.$editor.renderer.scrollBar.fullWidth; barIdeStatus.setAttribute("right", this.sbWidth + this.edgeDistance); barIdeStatus.setAttribute("bottom", this.edgeDistance); code.amlEditor.$ext.parentNode.appendChild(barIdeStatus.$ext); // load model with initial values var state = mdlStatusBar.data.selectSingleNode("//state"); apf.xmldb.setAttribute(state, "isCodeEditor", !!(editors.currentEditor && editors.currentEditor.path == "ext/code/code")); apf.xmldb.setAttribute(state, "showStatusbar", apf.isTrue(settings.model.queryValue("auto/statusbar/@show"))); // if we assign this before the plugin has been init'ed it will create some empty model // itself because we reference a non existing model _self.viewStatusBarMenuItem.setAttribute("disabled", '{apf.isFalse([mdlStatusBar::state/@isCodeEditor])}'); // if we have an editor, make sure to update the UI if (editors.currentEditor) { _self.onAfterSwitch(editors.currentEditor); } },
init : function() { var _self = this; var worker = this.worker; apf.importCssString(css); if (!editors.currentEditor || !editors.currentEditor.amlEditor) return; this.editor = editors.currentEditor.amlEditor.$editor; this.$onCursorChange = this.onCursorChangeDefer.bind(this); this.editor.selection.on("changeCursor", this.$onCursorChange); var oldSelection = this.editor.selection; this.setPath(); ceEditor.addEventListener("loadmode", function(e) { if (e.name === "ace/mode/javascript") { e.mode.createWorker = function() { return null; }; } }); this.updateSettings(); var defaultHandler = this.editor.keyBinding.onTextInput.bind(this.editor.keyBinding); var defaultCommandHandler = this.editor.keyBinding.onCommandKey.bind(this.editor.keyBinding); this.editor.keyBinding.onTextInput = keyhandler.composeHandlers(keyhandler.onTextInput, defaultHandler); this.editor.keyBinding.onCommandKey = keyhandler.composeHandlers(keyhandler.onCommandKey, defaultCommandHandler); this.editor.on("changeSession", function() { // Time out a litle, to let the page path be updated setTimeout(function() { _self.setPath(); oldSelection.removeEventListener("changeCursor", _self.$onCursorChange); _self.editor.selection.on("changeCursor", _self.$onCursorChange); oldSelection = _self.editor.selection; }, 100); }); this.editor.on("change", function(e) { e.range = { start: e.data.range.start, end: e.data.range.end }; worker.emit("change", e); marker.onChange(_self.editor.session, e); }); ide.addEventListener("liveinspect", function (e) { worker.emit("inspect", { data: { row: e.row, col: e.col } }); }); settings.model.addEventListener("update", this.updateSettings.bind(this)); this.editor.addEventListener("mousedown", this.onEditorClick.bind(this)); },
set : function(path, preview){ settings.model.setQueryValue("editors/code/@theme", path); this.setThemedGUI(path); this.saved = !preview; if (!preview) this.currTheme = path; },
setInstanceHighlight: function() { if(extSettings.model.queryValue("language/@instanceHighlight") != "false") this.worker.call("enableFeature", ["instanceHighlight"]); else this.worker.call("disableFeature", ["instanceHighlight"]); var cursorPos = this.editor.getCursorPosition(); cursorPos.force = true; this.worker.emit("cursormove", {data: cursorPos}); },
uploadCanceled: function() { this.uploadInProgress = false; this.cancelAllUploads = false; this.existingOverwriteAll = false; this.existingSkipAll = false; this.totalNumUploads = 0; (davProject.realWebdav || davProject).setAttribute("showhidden", settings.model.queryValue("auto/projecttree/@showhidden")); require("ext/tree/tree").refresh(); },
set : function(path){ settings.model.setQueryValue("editors/code/@theme", path); this.setThemedGUI(path); ide.dispatchEvent("theme_change", {theme: path}); this.saved = true; ide.dispatchEvent("track_action", {type: "theme change", theme: path}); },
setCustomType: function(ext, mime) { var node; if (typeof ext === "string") { node = settings.model.queryNode('auto/customtypes/mime[@ext="' + ext + '"]'); if (!node) settings.model.appendXml('<mime name="' + mime + '" ext="' + ext + '" />', "auto/customtypes"); } else { var name = ext.getAttribute("name") || ""; node = settings.model.queryNode('auto/customtypes/mime[@filename="' + name + '"]'); if (node) apf.xmldb.removeAttribute(node, "ext"); else settings.model.appendXml('<mime name="' + mime + '" filename="' + name + '" />', "auto/customtypes"); } apf.xmldb.setAttribute(node, "name", mime); settings.save(); },
hide: function() { settings.model.setQueryValue("general/@revisionsvisible", false); ceEditor.$editor.container.style.right = "0"; this.panel.hide(); this.goToEditView(); ide.dispatchEvent("revisions.visibility", { visibility: "hidden" }); tabEditors.getPage().$showRevisions = false; },
onFirstUse: function(event) { // Enable autosave since it makes linereport trigger automatically autosave.isAutoSaveEnabled = true; settings.model.setQueryValue("general/@autosaveenabled", true); ide.dispatchEvent("track_action", { type: "linereport_firstuse", language: event.data.language, source: event.data.source }); }
getPattern : function(){ return settings.model.queryValue("auto/testpanel/pattern/text()") || "// Enter any code below that returns the paths of the tests in an array of strings.\n" + "// You have access to the 'path' variable.\n" + "// Save this file to store the pattern.\n" + "var tests = [];\n" + "return tests.pushUnique(\n" + " path.replace(/(?:_test)?\.js$/, \"_test.js\"),\n" + " path.replace(/(?:_Test)?\.js$/, \"Test.js\")\n" + ");"; },
removeSession : function(name) { if (!settings.model.queryNode("auto/sessions/session[@name=\"" + name + "\"]")) return; settings.model.removeXml("auto/sessions/session[@name=\"" + name + "\"]"); settings.save(); var menuitems = this.mnuTabLoadSessions.childNodes.concat(this.mnuTabDeleteSessions.childNodes); for (var item, i = 0, l = menuitems.length; i < l; i++) { item = menuitems[i]; if (item.value == name) this.mnuTabLoadSessions.removeChild(item); } if (menuitems.length == 2) { this.mnuFileLoadSession.disable(); this.mnuFileDeleteSession.disable(); } },
init : function() { var _self = this; var worker = this.worker; apf.importCssString(css); if (!editors.currentEditor || editors.currentEditor.path != "ext/code/code") return; this.editor = editors.currentEditor.amlEditor.$editor; this.$onCursorChange = this.onCursorChangeDefer.bind(this); this.editor.session.selection.on("changeCursor", this.$onCursorChange); var oldSession = this.editor.session; worker.$doc = oldSession; this.setPath(); this.updateSettings(); var defaultHandler = this.editor.keyBinding.onTextInput.bind(this.editor.keyBinding); var defaultCommandHandler = this.editor.keyBinding.onCommandKey.bind(this.editor.keyBinding); this.editor.keyBinding.onTextInput = keyhandler.composeHandlers(keyhandler.onTextInput, defaultHandler); this.editor.keyBinding.onCommandKey = keyhandler.composeHandlers(keyhandler.onCommandKey, defaultCommandHandler); this.editor.on("changeSession", function() { oldSession.selection.removeEventListener("changeCursor", _self.$onCursorChange); _self.editor.selection.on("changeCursor", _self.$onCursorChange); oldSession = _self.editor.session; clearTimeout(_self.$timeout); // Time out a litle, to let the page path be updated _self.$timeout = setTimeout(function() { _self.setPath(); }, 100); worker.$doc = oldSession; }); this.editor.on("changeMode", function() { _self.$timeout = setTimeout(function() { _self.setPath(); }, 100); }); this.editor.on("change", function(e) { worker.changeListener(e); marker.onChange(_self.editor.session, e); }); ide.addEventListener("liveinspect", function (e) { worker.emit("inspect", { data: { row: e.row, col: e.col } }); }); settings.model.addEventListener("update", this.updateSettings.bind(this)); this.editor.addEventListener("mousedown", this.onEditorClick.bind(this)); },
updateSettings: function() { // Currently no code editor active if (!editors.currentEditor || !editors.currentEditor.amlEditor || !tabEditors.getPage()) return; if(settings.model.queryValue("language/@jshint") != "false") this.worker.call("enableFeature", ["jshint"]); else this.worker.call("disableFeature", ["jshint"]); if(settings.model.queryValue("language/@instanceHighlight") != "false") this.worker.call("enableFeature", ["instanceHighlight"]); else this.worker.call("disableFeature", ["instanceHighlight"]); if(settings.model.queryValue("language/@unusedFunctionArgs") != "false") this.worker.call("enableFeature", ["unusedFunctionArgs"]); else this.worker.call("disableFeature", ["unusedFunctionArgs"]); if(settings.model.queryValue("language/@undeclaredVars") != "false") this.worker.call("enableFeature", ["undeclaredVars"]); else this.worker.call("disableFeature", ["undeclaredVars"]); this.worker.call("setWarningLevel", [settings.model.queryValue("language/@warnLevel") || "info"]); var cursorPos = this.editor.getCursorPosition(); cursorPos.force = true; this.worker.emit("cursormove", {data: cursorPos}); isContinuousCompletionEnabled = settings.model.queryValue("language/@continuousComplete") === "true"; this.setPath(); },
ide.addEventListener("settings.load", function(e){ var model = settings.model; var strSettings = model.queryValue("auto/dockpanel/text()"); var state = _self.defaultState; if (strSettings) { // JSON parse COULD fail try { state = JSON.parse(strSettings); } catch (ex) {} } ide.dispatchEvent("dockpanel.load.settings", {state: state}); _self.layout.loadState(state); _self.loaded = true; _self.setParentHboxTop( apf.isFalse(settings.model.queryValue("auto/tabs/@show")) ? -15 : 0, apf.isFalse(settings.model.queryValue("general/@animateui")) ); });