Exemplo n.º 1
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));
        
    },
Exemplo n.º 2
0
    jump : function(options) {
        var row     = options.row;
        var column  = options.column || 0;
        var text    = options.text;
        var page    = options.page;
        
        var hasData;
        if (!options.doc) {
            var node    = options.node;
            var path    = node.getAttribute("path");
            var tabs    = tabEditors;
            
            hasData = page && (tabs.getPage(path) || { }).$doc ? true : false;
        }
        
        var _self   = this;

        if (row !== undefined) {
            var jumpTo = function(){
                var f;
                setTimeout(f = function() {
                    // TODO move this to the editor
                    var editor = _self.currentEditor.amlEditor;
                    editor.$editor.gotoLine(row, column, options.animate !== false);
                    if (text)
                        editor.$editor.session.highlight(text);

                    editor.focus();
                    ide.dispatchEvent("aftereditorfocus");
                }, 1); 
            };

            if (hasData) {
                tabs.set(path);
                jumpTo();
            }
            else
                ide.addEventListener("afteropenfile", function(e) {
                    var node = e.doc.getNode();

                    if (node.getAttribute("path") == path) {
                        ide.removeEventListener("afteropenfile", arguments.callee);
                        jumpTo();
                    }
                });
        }

        if (!hasData) {
            options.origin = "jump";
            if (!options.doc)
                options.doc = ide.createDocument(options.node);

            var extraOptions = this.openEditor(options.doc, options.init, options.active, options.forceOpen);
            ide.dispatchEvent("openfile", apf.extend(options, extraOptions));
        }
        else
            tabs.set(path);
    },
Exemplo n.º 3
0
    enableEventListeners: function() {
        if (this.$onMessageFn)
            ide.addEventListener("socketMessage", this.$onMessageFn);

        if (this.$onOpenFileFn)
            ide.addEventListener("afteropenfile", this.$onOpenFileFn);

        if (this.$onCloseFileFn)
            ide.addEventListener("closefile", this.$onCloseFileFn);

        if (this.$onFileSaveFn)
            ide.addEventListener("afterfilesave", this.$onFileSaveFn);

        if (this.$onSwitchFileFn)
            ide.addEventListener("tab.afterswitch", this.$onSwitchFileFn);

        if (this.$afterSelectFn)
            lstRevisions.addEventListener("afterselect", this.$afterSelectFn);

        if (this.$onAfterOnline)
            ide.addEventListener("onafteronline", this.$onAfterOnline);

        if (this.$onRevisionSaved)
            ide.addEventListener("revisionSaved", this.$onRevisionSaved);
    },
Exemplo n.º 4
0
 ide.addEventListener("loadsettings", function(e){
     function checkExpand(path, doc) {
         var parent_path = apf.getDirname(path).replace(/\/$/, "");
         var expandEventListener = function(e) {
             if (e.xmlNode && e.xmlNode.getAttribute("path") == parent_path) {
                 if (doc.getNode().getAttribute("newfile") != 1)
                     doc.setNode(e.xmlNode.selectSingleNode("node()[@path='" + path + "']"));
                 trFiles.removeEventListener("expand", expandEventListener);
             }
         };
         
         trFiles.addEventListener("expand", expandEventListener);
     }
     
     var model = e.model;
     ide.addEventListener("extload", function(){            
         
         // you can load a file from the hash tag, if that succeeded then return
         var loadFileFromHash =  (_self.loadFileFromHash(window.location.hash, checkExpand));
         if (loadFileFromHash) {
             window.location.hash = loadFileFromHash; // update hash
             return;
         }
         
         // otherwise, restore state from the .config file
         var active = model.queryValue("auto/files/@active");
         var nodes  = model.queryNodes("auto/files/file");
         
         for (var doc, i = 0, l = nodes.length; i < l; i++) {
             doc = ide.createDocument(nodes[i]);
             
             var state = nodes[i].getAttribute("state");
             try {
                 if (state)
                     doc.state = JSON.parse(state);
             }
             catch (ex) {}
             
             if (nodes[i].getAttribute("changed") == 1) {
                 doc.cachedValue = nodes[i].firstChild.nodeValue
                     .replace(/\n]\n]/g, "]]")
                     .replace(/\\r/g, "\r")
                     .replace(/\\n/g, "\n");
             }
             
             ide.dispatchEvent("openfile", {
                 doc    : doc,
                 init   : true,
                 active : active 
                     ? active == nodes[i].getAttribute("path")
                     : i == l - 1
             });
             
             checkExpand(nodes[i].getAttribute("path"), doc);
         }
     });
 });
Exemplo n.º 5
0
        init : function(){
            var _self = this;

            ide.addEventListener("settings.load", function(e){
                e.ext.setDefaults("general/keybindings", [["preset", "auto"]]);

                var preset = e.model.queryValue("general/keybindings/@preset");
                if (preset && preset != "auto")
                    _self.changePlatform(preset);
            });

            ide.addEventListener("init.ext/settings/settings", function(e){
                e.ext.addSettings("General", markupSettings, function(){
                    ddKeyBind.addEventListener("afterchange", function(){
                        _self.changePlatform(this.selected.getAttribute("value"));
                    });
                });
            });
        },
Exemplo n.º 6
0
 ide.addEventListener("loadsettings", function(e) {
     if (!e.model || !e.model.data)
         return;
     var data = e.model.data;
     ide.addEventListener("extload", function(){
         setTimeout(function() {
             _self.restore(data);
         });
     });
 });
Exemplo n.º 7
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));

    },
Exemplo n.º 8
0
 hook : function() {
     var commitFunc = this.onCommit.bind(this),
         name       = this.name;
     
     //Settings Support
     ide.addEventListener("init.ext/settings/settings", function(e){
         e.ext.addSection("code", name, "editors", commitFunc);
         barSettings.insertMarkup(settings);
     });
     
     ide.addEventListener("loadsettings", function(e) {
         // pre load theme
         var theme = e.model.queryValue("editors/code/@theme");
         if (theme) 
             require([theme], function() {});
     });
     
     // preload common language modes
     require(["ace/mode/javascript", "ace/mode/html", "ace/mode/css"], function() {});
 },
Exemplo n.º 9
0
        ide.addEventListener("extload", function() {
            var worker;
            if (!isWorkerEnabled()) {
                worker = _self.worker = createUIWorkerClient();
            }
            else {
                worker = _self.worker = new WorkerClient(
                    ["treehugger", "ext", "ace", "c9"], "worker.js",
                    "ext/language/worker", "LanguageWorker");
            }
            complete.setWorker(worker);

            ide.addEventListener("afteropenfile", function(event){
                if (!event.node)
                    return;
                if (!editors.currentEditor || !editors.currentEditor.amlEditor) // No editor, for some reason
                    return;
                ext.initExtension(_self);
                var path = event.node.getAttribute("path");
                worker.call("switchFile", [path, editors.currentEditor.amlEditor.syntax, event.doc.getValue()]);
                event.doc.addEventListener("close", function() {
                    worker.emit("documentClose", {data: path});
                });
                // This is necessary to know which file was opened last, for some reason the afteropenfile events happen out of sequence
                deferred.cancel().schedule(100);
            });

            // Language features
            marker.hook(_self, worker);
            complete.hook(_self, worker);
            refactor.hook(_self, worker);
            outline.hook(_self, worker);
            keyhandler.hook(_self, worker);

            ide.dispatchEvent("language.worker", {worker: worker});
            ide.addEventListener("$event.language.worker", function(callback){
                callback({worker: worker});
            });
        }, true);
Exemplo n.º 10
0
    init: function() {
        var self = this;
        var page = ide.getActivePage();
        if (page) {
            this.$switchToPageModel(page);
        }

        apf.importCssString(cssString);

        this.nodes.push(this.panel = new apf.bar({
                id: "revisionsPanel",
                visible: false,
                top: 6,
                bottom: 0,
                right: 0,
                width: BAR_WIDTH,
                height: "100%",
                "class": "revisionsBar"
            })
        );

        ide.addEventListener("init.ext/code/code", function(e) {
            self.panel = e.ext.amlEditor.parentNode.appendChild(self.panel);
            revisionsPanel.appendChild(pgRevisions);
        });

        apf.addEventListener("exit", function() {
            localStorage.offlineQueue = JSON.stringify(self.offlineQueue);
        });

        this.$afterSelectFn = this.afterSelect.bind(this);
        this.$afterModelUpdate = this.afterModelUpdate.bind(this);
        this.$onSwitchFileFn = this.onSwitchFile.bind(this);

        lstRevisions.addEventListener("afterselect", this.$afterSelectFn);
        ide.addEventListener("tab.afterswitch", this.$onSwitchFileFn);

        this.$setRevisionListClass();
    },
Exemplo n.º 11
0
    init : function(){
        ide.onLine = -1;
        ide.addEventListener("socketConnect", function(e){
            ide.onLine = true;

            ide.dispatchEvent("beforeonline");
            ide.dispatchEvent("afteronline");
            
            stServerConnected.activate();
            winReconnect.hide();
        });
        
        ide.addEventListener("socketDisconnect", function(e){
            ide.onLine = false;

            ide.dispatchEvent("beforeoffline");
            ide.dispatchEvent("afteroffline");
            
            stServerConnected.deactivate();
            winReconnect.show();
        });
    },
Exemplo n.º 12
0
    registerLanguageHandler: function(modulePath, contents, callback) {
        var _self = this;

        // We have to wait until the paths for ace are set - a nice module system will fix this
        ide.addEventListener("extload", function(){
            _self.worker.on("registered", function reply(e) {
                if (e.data.path !== modulePath)
                    return;
                _self.worker.removeEventListener(reply);
                callback && callback(e.data.err);
            });
            _self.worker.call("register", [modulePath, contents]);
        });
    },
Exemplo n.º 13
0
Arquivo: vim.js Projeto: Jalen/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) {
            var heading = e.ext.getHeading("Code Editor");
            heading.appendChild(new apf.checkbox({
                "class" : "underlined",
                skin  : "checkbox_grey",
                value : "[editors/code/@vimmode]",
                label : "Vim mode"
            }))
        });

        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");
        });
    },
Exemplo n.º 14
0
    init : function(amlNode){
        this.panel = winDbgStack;
        this.rightPane = colRight;
        this.nodes.push(this.rightPane.appendChild(winDbgStack));

        this.paths = {};
        var _self = this;
        mdlDbgSources.addEventListener("afterload", function() {
            _self.$syncTree();
        });
        mdlDbgSources.addEventListener("update", function(e) {
            if (e.action != "add")
                return;
            // TODO: optimize this!
            _self.$syncTree();
        });
        fs.model.addEventListener("update", function(e) {
            if (e.action != "insert")
                return;
            // TODO: optimize this!
            _self.$syncTree();
        });
        //@todo move this to noderunner...
        dbg.addEventListener("changeframe", function(e) {
            e.data && _self.showDebugFile(e.data.getAttribute("scriptid"));
        });

        lstBreakpoints.addEventListener("afterselect", function(e) {
            if (e.selected && e.selected.getAttribute("scriptid"))
                _self.showDebugFile(e.selected.getAttribute("scriptid"), parseInt(e.selected.getAttribute("line")) + 1);
            // TODO sometimes we don't have a scriptID
        });

        ide.addEventListener("afterfilesave", function(e) {
            var node = e.node;
            var doc = e.doc;
            
            var scriptId = node.getAttribute("scriptid");
            if (!scriptId)
                return;
                
            var value = e.value || doc.getValue();
            var NODE_PREFIX = "(function (exports, require, module, __filename, __dirname) { "
            var NODE_POSTFIX = "\n});";
            dbg.changeLive(scriptId, NODE_PREFIX + value + NODE_POSTFIX, false, function(e) {
                //console.log("v8 updated", e);
            });
        })
    },
Exemplo n.º 15
0
 hook: function(ext) {
     var _self = this;
     quickfix = this;
               
     ide.addEventListener("paneAfterswitch", function(e) {
         var tab = e.nextTab;
         if (!tab || !tab.$editor || tab.$editor.path != "ext/code/code")
             return;
         var ace = tab.$editor.amlEditor.$editor;
         
         if (!ace.$markerListener)
             _self.initEditor(ace);           
     });
     
     commands.addCommand({
         name: "quickfix",
         hint: "quickfix",
         bindKey: {mac: "Ctrl-Shift-Q|Ctrl-Alt-Q", win: "Ctrl-Shift-Q|Alt-Shift-Q"},
         isAvailable: function(editor) {
             return apf.activeElement.localName == "codeeditor";
         },
         exec: function(editor) {
             _self.invoke();
         }
     });
     
     ide.addEventListener("init.ext/code/code", function() {
         ext.nodes.push(
             menus.addItemByPath("Tools/Quickfix", new apf.item({
                 caption: "Quickfix",
                 command: "quickfix"
             }), 20001)
         );
     });
        
 },
Exemplo n.º 16
0
    init : function(){
        var _self = this;
        
        this.stylesheet = apf.createStylesheet();
        
        this.nodes.push(
            this.group = new apf.group()
        );
        
        var mnuThemes = menus.addItemByPath("View/Themes/", new apf.menu({
            "onprop.visible" : function(e){
                if (e.value) {
                    mnuThemes.select(null, 
                      settings.model.queryValue("editors/code/@theme") 
                        || _self.defaultTheme);
                }
            },
            "onitemclick" : function(e){
                var path = e.relatedNode.value;
                _self.set(path);
                ide.dispatchEvent("track_action", {type: "theme change", theme: path});
            }
        }), 350000);

        ide.addEventListener("init.ext/code/code", function() {
            if (ceEditor && ceEditor.$editor)
                mnuThemes.select(null, _self.defaultTheme);
        });
        
        ide.addEventListener("settings.load", function(e){
            var theme = _self.currTheme = e.model.queryValue("editors/code/@theme")
                || _self.defaultTheme;
            
            _self.setThemedGUI(theme);
        });
    },
Exemplo n.º 17
0
 var readfileCallback = function(data, state, extra) {
     if (state == apf.OFFLINE) {
         ide.addEventListener("afteronline", function(e) {
             fs.readFile(path, readfileCallback);
             ide.removeEventListener("afteronline", arguments.callee);
         });
     } else if (state != apf.SUCCESS) {
         if (extra.status == 404)
             ide.dispatchEvent("filenotfound", {
                 node : node,
                 url  : extra.url,
                 path : path
             });
     } else {
        ide.dispatchEvent("afterreload", {doc : doc, data : data});
     }
 };
Exemplo n.º 18
0
 hook : function(){
     var _self = this;
     ide.addEventListener("init.ext/tree/tree", function(){
         _self.nodes.push(
             menus.addItemByPath("File/~", new apf.divider(), 350),
             menus.addItemByPath("File/Upload Files", new apf.item({
                 onclick : function(){
                     ext.initExtension(_self);
                     winUploadFiles.show();
                 }
             }), 370)
         );
         
         mnuCtxTree.addEventListener("afterrender", function(){
             _self.nodes.push(
                 mnuCtxTree.insertBefore(new apf.item({
                     id : "mnuCtxTreeUpload",
                     match : "[folder]",
                     visible : "{trFiles.selected.getAttribute('type')=='folder'}",
                     caption : "Upload to this folder",
                     onclick : function(){
                         ext.initExtension(_self);
                         
                         winUploadFiles.show();
                     }
                 }), itemCtxTreeNewFile),
                 mnuCtxTree.insertBefore(new apf.divider({
                     visible : "{mnuCtxTreeUpload.visible}"
                 }), itemCtxTreeNewFile)
             )
         });
         
         if(ide.infraEnv) {
             _self.nodes.push(
                 menus.addItemByPath("File/Download Project", new apf.item({
                     onclick : function(){
                         window.open("/api/project/download/zip/" + ide.projectName);
                     }
                 }), 390)
             );
             btnUploadFiles.setProperty("right", "81");
         }
     });
 },
Exemplo n.º 19
0
 readFile : function (path, callback){
     if (!this.webdav) return;
     
     var self = this;
     
     // in webdav.read, if ide.onLine === 0, it is calling callback immediately without content
     // if we're not online, we'll add an event handler that listens to the socket connecting (or the ping or so)
     if (!ide.onLine) {
         var afterOnlineHandler = function () {
             self.webdav.read(path, callback);
             ide.removeEventListener("afteronline", afterOnlineHandler);
         };
         ide.addEventListener("afteronline", afterOnlineHandler);
     }
     else {
         // otherwise just redirect it
         this.webdav.read(path, callback);
     }
 },
Exemplo n.º 20
0
    init : function(amlNode){
        var _self = this;

        this.nodes.push(
            this.group = apf.document.documentElement.appendChild(new apf.group({
                value : "[{req" + "uire('core/settings').model}::auto/panels/@active]"
            })),

            menus.addItemByPath("View/Side Bar/", null, 100),
            menus.addItemByPath("View/~", new apf.divider(), 200),

            this.mnuPanelsNone =
              menus.addItemByPath("View/Side Bar/None", new apf.item({
                type: "radio",
                selected : "true",
                group: this.group,
                "onclick": function(e){
                    _self.deactivate(null, true);
                }
              }), 100),
            menus.addItemByPath("View/Side Bar/~", new apf.divider(), 200)
        );

        splitterPanelLeft.addEventListener("dragdrop", function(e){
            if (!_self.currentPanel)
                return;

            var query = "auto/panels/panel[@path="
                + util.escapeXpathString(_self.currentPanel.path) + "]/@width";

            if (settings.model.queryValue(query) != colLeft.getWidth())
                settings.model.setQueryValue(query, colLeft.getWidth());
        });

        /**** Support for state preservation ****/

        var _self = this;
        ide.addEventListener("settings.load", function(e){
            settings.setDefaults("general", [["animateui", true]]);
        });
    },
Exemplo n.º 21
0
            function checkExpand(path, doc) {
                ide.addEventListener("init.ext/tree/tree", function(){
                    var parent_path = (apf.getDirname(path) || "").replace(/\/$/, "");
                    var expandEventListener = function(e) {
                        if (e.xmlNode && e.xmlNode.getAttribute("path") == parent_path) {
                            // if the file has been loaded from the tree
                            if (doc.getNode().getAttribute("newfile") != 1) {
                                // databind the node from the tree to the document
                                doc.setNode(e.xmlNode.selectSingleNode("node()[@path='" + path + "']"));
                            }
                            else {
                                // if not? then keep it this way, but invoke setNode() anyway because
                                // it triggers events
                                doc.setNode(doc.getNode());
                            }
                            trFiles.removeEventListener("expand", expandEventListener);
                        }
                    };

                    trFiles.addEventListener("expand", expandEventListener);
                });
            }
Exemplo n.º 22
0
    hook: function () {
        var _self = this;

        var menuItem = new apf.item({
            id : "beautify_selection",
            disabled : "true",
            onclick: function () {
                _self.beautify();
            }
        });

        menus.addItemByPath("Tools/Beautify Selection", menuItem, 100);

        this.hotitems.beautify = [menuItem];

        code.commandManager.addCommand({
            name: "beautify",
            exec: function () {
                _self.beautify();
            }
        });

        require("ext/settings/settings").addSettings("JS Beautify", markupSettings );

        ide.addEventListener("loadsettings", function(e){
            var model = e.model;

            if (!model.queryNode("beautify/jsbeautify")) {
                model.setQueryValue("beautify/jsbeautify/@preserveempty", "true");
                model.setQueryValue("beautify/jsbeautify/@keeparrayindentation", "false");
                model.setQueryValue("beautify/jsbeautify/@jslinthappy", "false");
                model.setQueryValue("beautify/jsbeautify/@braces", "end-expand");
                model.setQueryValue("editors/code/@tabsize", "4");
                model.setQueryValue("editors/code/@softtabs", "true");
            }
        });

        ext.initExtension(this);
    },
Exemplo n.º 23
0
    init: function () {
        var _self = this;
        tabEditors.addEventListener("afterswitch", function() {
            if (_self.$selectionEvent) {
                _self.editorSession.selection.removeEventListener("changeSelection",
                    _self.$selectionEvent);
            }

            setTimeout(function() {
                if(editors.currentEditor.ceEditor) {
                    _self.editorSession = editors.currentEditor.ceEditor.$editor.session;
                    _self.editorSession.selection.addEventListener("changeSelection",
                        _self.$selectionEvent = function(e) {
                            if (typeof beautify_selection === "undefined")
                                return;

                            var range = ceEditor.$editor.getSelectionRange();
                            if (range.start.row == range.end.row && range.start.column == range.end.column) {
                                _self.disabled = true;
                                beautify_selection.disable();
                            }
                            else {
                                _self.disabled = false;
                                beautify_selection.enable();
                            }
                        }
                    );
                }
            }, 200);
        });

        ide.addEventListener("revisions.visibility", function(e) {
            if (e.visibility === "shown")
                _self.disable();
            else
                _self.enable();
        });
    },
Exemplo n.º 24
0
    hook: function() {
        var _self = this;
        settings.addSettings("General", markupSettings);
        ide.addEventListener("settings.load", function(e){
            e.ext.setDefaults("general", [["autosaveenabled", "false"]]);
            _self.isAutoSaveEnabled = apf.isTrue(e.model.queryValue("general/@autosaveenabled"));
        });

        ide.addEventListener("settings.save", function(e) {
            if (!e.model.data)
                return;

            _self.isAutoSaveEnabled = apf.isTrue(e.model.queryValue("general/@autosaveenabled"));
        });

        // when we're back online we'll trigger an autosave if enabled
        ide.addEventListener("afteronline", function() {
            // the autosave thing will update the UI
            _self.doAutoSave();
        });

        btnSave.setAttribute("caption", "");
        btnSave.setAttribute("margin", "0 20");
        btnSave.removeAttribute("tooltip");
        btnSave.removeAttribute("command");
        apf.setStyleClass(btnSave.$ext, "btnSave");

        tooltip.add(btnSave, {
            message : "Changes to your file are automatically saved.<br />\
                View all your changes through <a href='javascript:void(0)' \
                onclick='require(\"ext/revisions/revisions\").toggle();' \
                class='revisionsInfoLink'>the Revision History pane</a>. \
                Rollback to a previous state, or make comparisons.",
            width : "250px",
            hideonclick : true
        });

        this.$onOpenFileFn = this.onOpenFile.bind(this);
        this.$onCloseFileFn = this.onCloseFile.bind(this);
        this.$onBeforeSaveWarning = this.onBeforeSaveWarning.bind(this);

        ide.addEventListener("afteropenfile", this.$onOpenFileFn);
        ide.addEventListener("closefile", this.$onCloseFileFn);
        ide.addEventListener("beforesavewarn", this.$onBeforeSaveWarning);
    },
Exemplo n.º 25
0
    jump : function(fileEl, row, column, text, doc, page) {
        var path    = fileEl.getAttribute("path");
        var hasData = page && tabEditors.getPage(path).$doc ? true : false;

        if (row !== undefined) {
            var jumpTo = function(){
                setTimeout(function() {
                    // TODO move this to the editor
                    ceEditor.$editor.gotoLine(row, column);
                    if (text)
                        ceEditor.$editor.find(text);
                    ceEditor.focus();
                }, 100);
            };

            if (hasData) {
                tabEditors.set(path);
                jumpTo();
            }
            else
                ide.addEventListener("afteropenfile", function(e) {
                    var node = e.doc.getNode();
                    
                    if (node.getAttribute("path") == path) {
                        ide.removeEventListener("afteropenfile", arguments.callee);
                        jumpTo();
                    }
                });
        }
        
        if (!hasData && !page) 
            ide.dispatchEvent("openfile", {
                doc: doc || ide.createDocument(fileEl)
            });
        else
            tabEditors.set(path);
    },
Exemplo n.º 26
0
    hook : function(){
        var _self = this;
        
        commands.commands["findnext"].hint = "search for the next occurrence of the search query your entered last";
        commands.commands["findnext"].msg = "Navigating to next match.";
        commands.commands["findprevious"].hint = "search for the previous occurrence of the search query your entered last";
        commands.commands["findprevious"].msg = "Navigating to previous match.";
        
        commands.addCommand({
            name: "find",
            hint: "open the quicksearch dialog to quickly search for a phrase",
            bindKey: {mac: "Command-F", win: "Ctrl-F"},
            isAvailable : function(editor){
                return editor && editor.ceEditor;
            },
            exec: function(env, args, request) {
                _self.toggleDialog(1);
            }
        });

        ide.addEventListener("minimap.visibility", function(e) {
            if (e.visibility === "shown")
                _self.offsetWidth = _self.defaultOffset + e.width;
            else
                _self.offsetWidth = _self.defaultOffset;

            _self.updateBarPosition();
        });
        
        this.nodes.push(
            menus.addItemByPath("Find/~", new apf.divider(), 1000),

            menus.addItemByPath("Find/Quick Find", new apf.item({
                command : "find"
            }), 1100)
        );
    },
Exemplo n.º 27
0
    jumpToFileAndLineNumber: function(path, lineNo) {
        var name;
        // This is ok if there is no / because then lastIndexOf returns -1
        // so we get the whole string.
        name = path.slice(path.lastIndexOf("/") + 1)

        // Remove any leading /s and prepend the davPrefix.
        var fullPath = path;
        fullPath = fullPath.replace(/^(\/)*/, "");
        fullPath = ide.davPrefix + "/" + fullPath;

        var node = apf.n("<file />")
            .attr("name", name)
            .attr("contenttype", util.getContentType(name))
            .attr("path", fullPath)
            .node();

        ide.addEventListener("afteropenfile", function(e) {
            ceEditor.$editor.gotoLine(lineNo);
            ide.removeEventListener("afteropenfile", arguments.callee);
        })

        ide.dispatchEvent("openfile", { doc: ide.createDocument(node) });
    },
Exemplo n.º 28
0
        ide.addEventListener("extload", function(e){
            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"))
                );
            });
        });
Exemplo n.º 29
0
        hook: function() {
            var _self = this;
            this.nodes.push(
            ide.mnuEdit.appendChild(new apf.divider()), ide.mnuEdit.appendChild(new apf.item({
                caption: "Beautify Selection",
                onclick: function() {
                    ext.initExtension(_self);
                    _self.beautify();
                }
            })));

            this.hotitems["beautify"] = [this.nodes[1]];
            canon.addCommand({
                name: "beautify",
                exec: function(env, args, request) {
                    _self.beautify();
                }
            });

            ide.addEventListener("init.ext/settings/settings", function(e) {
                e.ext.addSection("jsbeautify", _self.name, "beautify", function() {});
                barSettings.insertMarkup(settings);
            });
        },
Exemplo n.º 30
0
    load : function(xml){
        try {
            this.model.load(xml);
        } catch(e) {
            this.model.load(template);
        }

        if (!cloud9config.debug) {
            try {
                ide.dispatchEvent("settings.load", {
                    model : this.model,
                    ext   : this
                });
            } catch(e) {
                self["requ"+"ire"]("ext/filesystem/filesystem")
                  .saveFile("/workspace/.c9.brokensettings.xml", xml.xml || xml);

                this.model.load(template);

                ide.dispatchEvent("settings.load", {
                    model : this.model,
                    ext   : this
                });
            }
        }
        else {
            ide.dispatchEvent("settings.load", {
                model : this.model,
                ext   : this
            });
        }

        ide.addEventListener("$event.settings.load", this.$loadsettings);

        this.loaded = true;
    },