Пример #1
0
        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));
        },
Пример #2
0
 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);
 },
Пример #3
0
    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;
    },
Пример #4
0
 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);
Пример #5
0
    doAutoSave: function() {
        var autoSaveEnabled = apf.isTrue(settings.model.queryValue("general/@autosaveenabled"));
        if (!tabEditors || !autoSaveEnabled)
            return;

        tabEditors.getPages().forEach(this.save, this);
    },
Пример #6
0
 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?";
     }        
 },
Пример #7
0
 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});
 },
Пример #8
0
Файл: vim.js Проект: ESGR/cloud9
    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");
        });
    },
Пример #9
0
 setUnusedFunctionArgs: function(yeah) {
     if(extSettings.model.queryValue("language/@unusedFunctionArgs") != "false")
         this.worker.call("enableFeature", ["unusedFunctionArgs"]);
     else
         this.worker.call("disableFeature", ["unusedFunctionArgs"]);
     this.setPath();
 },
Пример #10
0
 setJSHint: function() {
     if(extSettings.model.queryValue("language/@jshint") != "false")
         this.worker.call("enableFeature", ["jshint"]);
     else
         this.worker.call("disableFeature", ["jshint"]);
     this.setPath();
 },
Пример #11
0
 setUndeclaredVars: function() {
     if(extSettings.model.queryValue("language/@undeclaredVars") != "false")
         this.worker.call("enableFeature", ["undeclaredVars"]);
     else
         this.worker.call("disableFeature", ["undeclaredVars"]);
     this.setPath();
 },
Пример #12
0
 "onprop.visible" : function(e){
     if (e.value) {
         mnuThemes.select(null, 
           settings.model.queryValue("editors/code/@theme") 
             || _self.defaultTheme);
     }
 }
Пример #13
0
    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;
    },
Пример #14
0
 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();
 });
Пример #15
0
 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);
     }
 };
Пример #16
0
        this.$timer = setTimeout(function(){
            var state = _self.layout.getState();

            settings.model.setQueryValue(
                "auto/dockpanel/text()",
                JSON.stringify(state)
            );
        });
Пример #17
0
    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);
        }
    },
Пример #18
0
    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));
        
    },
Пример #19
0
 set : function(path, preview){
     settings.model.setQueryValue("editors/code/@theme", path);
     
     this.setThemedGUI(path);
     
     this.saved = !preview;
     if (!preview)
         this.currTheme = path;
 },
Пример #20
0
 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});
 },
Пример #21
0
 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();
 },
Пример #22
0
 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});
 },
Пример #23
0
    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();
    },
Пример #24
0
    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;
    },
Пример #25
0
 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
     });
 }
Пример #26
0
 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"
         + ");";
 },
Пример #27
0
    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();
        }

    },
Пример #28
0
    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));

    },
Пример #29
0
 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();
 },
Пример #30
0
            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"))
                );
            });