it("should comment/uncomment lines that were partially commented out already, comment closer to code", function () {
     // Start with line 3 commented out, with "//" snug against the code
     var lines = defaultContent.split("\n");
     lines[3] = "        //a();";
     var startingContent = lines.join("\n");
     myDocument.setText(startingContent);
     
     // select lines 1-3
     myEditor.setSelection({line: 1, ch: 0}, {line: 4, ch: 0});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     lines = defaultContent.split("\n");
     lines[1] = "//    function bar() {";
     lines[2] = "//        ";
     lines[3] = "//        //a();";
     var expectedText = lines.join("\n");
     
     expect(myDocument.getText()).toEqual(expectedText);
     expectSelection({start: {line: 1, ch: 0}, end: {line: 4, ch: 0}});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     expect(myDocument.getText()).toEqual(startingContent);
     expectSelection({start: {line: 1, ch: 0}, end: {line: 4, ch: 0}});
 });
    /**
     * @private
     * Common implementation for close/quit/reload which all mostly
     * the same except for the final step
    */
    function _handleWindowGoingAway(commandData, postCloseHandler, failHandler) {
        if (_windowGoingAway) {
            //if we get called back while we're closing, then just return
            return (new $.Deferred()).reject().promise();
        }

        return CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true })
            .done(function () {
                _windowGoingAway = true;
                
                // Give everyone a chance to save their state - but don't let any problems block
                // us from quitting
                try {
                    $(ProjectManager).triggerHandler("beforeAppClose");
                } catch (ex) {
                    console.error(ex);
                }
                
                PreferencesManager.savePreferences();
                
                postCloseHandler();
            })
            .fail(function () {
                _windowGoingAway = false;
                if (failHandler) {
                    failHandler();
                }
            });
    }
 this.onDocumentClick = function(model, event){
     CommandManager.execute('file.open', {
         fullPath: model._path
     }).always(function(){
         MainViewManager.focusActivePane();
     });
 }
Example #4
0
 /**
  * Displays a browser dialog where the user can choose a folder to load.
  * (If the user cancels the dialog, nothing more happens).
  */
 function openProject() {
     // Confirm any unsaved changes first. We run the command in "prompt-only" mode, meaning it won't
     // actually close any documents even on success; we'll do that manually after the user also oks
     //the folder-browse dialog.
     CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true })
         .done(function () {
             // Pop up a folder browse dialog
             NativeFileSystem.showOpenDialog(false, true, "Choose a folder", _projectRoot.fullPath, null,
                 function (files) {
                     // If length == 0, user canceled the dialog; length should never be > 1
                     if (files.length > 0) {
                         // Actually close all the old files now that we know for sure we're proceeding
                         DocumentManager.closeAll();
                         
                         // Load the new project into the folder tree
                         loadProject(files[0]);
                     }
                 },
                 function (error) {
                     Dialogs.showModalDialog(
                         Dialogs.DIALOG_ID_ERROR,
                         Strings.ERROR_LOADING_PROJECT,
                         Strings.format(Strings.OPEN_DIALOG_ERROR, error.code)
                     );
                 }
                 );
         });
     // if fail, don't open new project: user canceled (or we failed to save its unsaved changes)
 }
Example #5
0
 /**
  * Process the keybinding for the current key.
  *
  * @param {string} A key-description string.
  * @return {boolean} true if the key was processed, false otherwise
  */
 function handleKey(key) {
     if (_enabled && _keymap && _keymap.map[key]) {
         CommandManager.execute(_keymap.map[key]);
         return true;
     }
     return false;
 }
 it("should select all in one-line file", function () {
     myDocument.setText("// x");
     myEditor.setSelection({line: 0, ch: 0}, {line: 0, ch: 0});
     CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);
     
     expectSelection({start: {line: 0, ch: 0}, end: {line: 0, ch: 4}});
 });
 it("should delete multiple lines ending at the bottom when selection spans them", function () {
     myEditor.setSelection({line: 5, ch: 5}, {line: 7, ch: 0});
     CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
     
     var expectedText = defaultContent.split("\n").slice(0, 5).join("\n");
     expect(myDocument.getText()).toEqual(expectedText);
 });
 it("should delete the last line when selection is a range in that line", function () {
     myEditor.setSelection({line: 7, ch: 0}, {line: 7, ch: 1});
     CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
     
     var expectedText = defaultContent.split("\n").slice(0, 7).join("\n");
     expect(myDocument.getText()).toEqual(expectedText);
 });
 it("should extend selection to include last line of visible range", function () {
     makeEditorWithRange({startLine: 1, endLine: 5});
     myEditor.setSelection({line: 4, ch: 4}, {line: 4, ch: 4});
     CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);
     
     expectSelection({start: {line: 4, ch: 0}, end: {line: 5, ch: 0}});
 });
 it("shouldn't select past end of visible range, IP at start of last visible line", function () {
     makeEditorWithRange({startLine: 1, endLine: 5});
     myEditor.setSelection({line: 5, ch: 0}, {line: 5, ch: 0});
     CommandManager.execute(Commands.EDIT_SELECT_LINE, myEditor);
     
     expectSelection({start: {line: 5, ch: 0}, end: {line: 5, ch: 5}});
 });
Example #11
0
 FileSystem.resolve(initialProjectPath + "index.html", function (err, file) {
     if (!err) {
         var promise = CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, { fullPath: file.fullPath });
         promise.then(deferred.resolve, deferred.reject);
     } else {
         deferred.reject();
     }
 });
 it("should comment/uncomment a single line, cursor at start", function () {
     myEditor.setCursorPos(3, 0);
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     var lines = defaultContent.split("\n");
     lines[3] = "//        a();";
     var expectedText = lines.join("\n");
     
     expect(myDocument.getText()).toEqual(expectedText);
     expectCursorAt({line: 3, ch: 2});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     expect(myDocument.getText()).toEqual(defaultContent);
     expectCursorAt({line: 3, ch: 0});
 });
 it("should delete a middle line when selection is a range in that line", function () {
     myEditor.setSelection({line: 2, ch: 5}, {line: 2, ch: 8});
     CommandManager.execute(Commands.EDIT_DELETE_LINES, myEditor);
     
     var lines = defaultContent.split("\n");
     lines.splice(2, 1);
     expect(myDocument.getText()).toEqual(lines.join("\n"));
 });
 it("shouldn't move down after select all", function () {
     myEditor.setSelection({line: 0, ch: 0}, {line: 7, ch: 1});
     
     CommandManager.execute(Commands.EDIT_LINE_DOWN, myEditor);
     
     expect(myDocument.getText()).toEqual(defaultContent);
     expectSelection({start: {line: 0, ch: 0}, end: {line: 7, ch: 1}});
 });
 it("should comment/uncomment first line in file", function () {
     myEditor.setCursorPos(0, 0);
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     var lines = defaultContent.split("\n");
     lines[0] = "//function foo() {";
     var expectedText = lines.join("\n");
     
     expect(myDocument.getText()).toEqual(expectedText);
     expectCursorAt({line: 0, ch: 2});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     expect(myDocument.getText()).toEqual(defaultContent);
     expectCursorAt({line: 0, ch: 0});
 });
Example #16
0
 FileSystem.resolve(initialProjectPath.replace(Urls.GETTING_STARTED, '').replace('//', '/') + "blink.ino", function (err, file){                     
     if (!err) {
         var promise = CommandManager.execute(Commands.CMD_ADD_TO_WORKINGSET_AND_OPEN, { fullPath: file.fullPath });
         promise.then(deferred.resolve, deferred.reject);
     } else {
         deferred.reject();
     }
 });
Example #17
0
                    Handlers.handleFile(transformedPath, data, function(err) {
                        if(err) {
                            console.error("[Bramble Error] unable to rewrite URL for transformed file", transformedPath, err);
                            return callback(err);
                        }

                        // Refresh the file tree so this new file shows up.
                        CommandManager.execute(Commands.FILE_REFRESH).always(callback);
                    });
Example #18
0
            .on("click.searchResults .table-container", function (e) {
                var $row = $(e.target).closest("tr");

                if ($row.length) {
                    if (self._$selectedRow) {
                        self._$selectedRow.removeClass("selected");
                    }
                    $row.addClass("selected");
                    self._$selectedRow = $row;

                    var searchItem = self._searchList[$row.data("file-index")],
                        fullPath   = searchItem.fullPath;

                    // This is a file title row, expand/collapse on click
                    if ($row.hasClass("file-section")) {
                        var $titleRows,
                            collapsed = !self._model.results[fullPath].collapsed;

                        if (e.metaKey || e.ctrlKey) { //Expand all / Collapse all
                            $titleRows = $(e.target).closest("table").find(".file-section");
                        } else {
                            // Clicking the file section header collapses/expands result rows for that file
                            $titleRows = $row;
                        }

                        $titleRows.each(function () {
                            fullPath   = self._searchList[$(this).data("file-index")].fullPath;
                            searchItem = self._model.results[fullPath];

                            if (searchItem.collapsed !== collapsed) {
                                searchItem.collapsed = collapsed;
                                $(this).nextUntil(".file-section").toggle();
                                $(this).find(".disclosure-triangle").toggleClass("expanded");
                            }
                        });

                        //In Expand/Collapse all, reset all search results 'collapsed' flag to same value(true/false).
                        if (e.metaKey || e.ctrlKey) {
                            FindUtils.setCollapseResults(collapsed);
                            _.forEach(self._model.results, function (item) {
                                item.collapsed = collapsed;
                            });
                        }

                    // This is a file row, show the result on click
                    } else {
                        // Grab the required item data
                        var item = searchItem.items[$row.data("item-index")];

                        CommandManager.execute(Commands.FILE_OPEN, {fullPath: fullPath})
                            .done(function (doc) {
                                // Opened document is now the current main editor
                                EditorManager.getCurrentFullEditor().setSelection(item.start, item.end, true);
                            });
                    }
                }
            });
Example #19
0
            it("shouldn't freeze on /.*/ regexp", function () {
                myEditor.setCursorPos(0, 0);

                CommandManager.execute(Commands.EDIT_FIND);

                enterSearchText("/.*/");
                pressEnter();
                expectSelection({start: {line: 0, ch: 0}, end: {line: 0, ch: 18}});
            });
Example #20
0
 /**
  * The native function BracketsShellAPI::DispatchBracketsJSCommand calls this function in order to enable
  * calling Brackets commands from the native shell.
  */
 function executeCommand(eventName) {
     var evt = window.document.createEvent("Event");
     evt.initEvent(eventName, false, true);
     
     CommandManager.execute(eventName, {evt: evt});
     
     //return if default was prevented
     return evt.defaultPrevented;
 }
Example #21
0
 it("shouldn't choke on empty regexp", function () {
     myEditor.setCursorPos(0, 0);
     
     CommandManager.execute(Commands.EDIT_FIND);
     
     enterSearchText("//");
     expectHighlightedMatches([]);
     expect(myEditor).toHaveCursorPosition(0, 0); // no change
 });
 it("shouldn't move up first line", function () {
     // place cursor at start of line 0
     myEditor.setCursorPos(0, 0);
     
     CommandManager.execute(Commands.EDIT_LINE_UP, myEditor);
     
     expect(myDocument.getText()).toEqual(defaultContent);
     expectCursorAt({line: 0, ch: 0});
 });
 it("should comment/uncomment a single fully-selected line (including LF)", function () {
     // selection including \n at end of line
     myEditor.setSelection({line: 1, ch: 0}, {line: 2, ch: 0});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     var lines = defaultContent.split("\n");
     lines[1] = "//    function bar() {";
     var expectedText = lines.join("\n");
     
     expect(myDocument.getText()).toEqual(expectedText);
     expectSelection({start: {line: 1, ch: 0}, end: {line: 2, ch: 0}});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     expect(myDocument.getText()).toEqual(defaultContent);
     expectSelection({start: {line: 1, ch: 0}, end: {line: 2, ch: 0}});
 });
 it("should comment/uncomment a single selected line", function () {
     // selection covers all of line's text, but not \n at end
     myEditor.setSelection({line: 1, ch: 0}, {line: 1, ch: 20});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     var lines = defaultContent.split("\n");
     lines[1] = "//    function bar() {";
     var expectedText = lines.join("\n");
     
     expect(myDocument.getText()).toEqual(expectedText);
     expectSelection({start: {line: 1, ch: 0}, end: {line: 1, ch: 22}});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     expect(myDocument.getText()).toEqual(defaultContent);
     expectSelection({start: {line: 1, ch: 0}, end: {line: 1, ch: 20}});
 });
 it("should comment/uncomment a single partly-selected line", function () {
     // select "function" on line 1
     myEditor.setSelection({line: 1, ch: 4}, {line: 1, ch: 12});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     var lines = defaultContent.split("\n");
     lines[1] = "//    function bar() {";
     var expectedText = lines.join("\n");
     
     expect(myDocument.getText()).toEqual(expectedText);
     expectSelection({start: {line: 1, ch: 6}, end: {line: 1, ch: 14}});
     
     CommandManager.execute(Commands.EDIT_LINE_COMMENT, myEditor);
     
     expect(myDocument.getText()).toEqual(defaultContent);
     expectSelection({start: {line: 1, ch: 4}, end: {line: 1, ch: 12}});
 });
 it("should duplicate after select all", function () {
     myEditor.setSelection({line: 0, ch: 0}, {line: 7, ch: 1});
     
     CommandManager.execute(Commands.EDIT_DUPLICATE, myEditor);
     
     var expectedText = defaultContent + defaultContent;
     
     expect(myDocument.getText()).toEqual(expectedText);
     expectSelection({start: {line: 7, ch: 1}, end: {line: 14, ch: 1}});
 });
Example #27
0
 file.exists(function (err, doesExist) {
     if (doesExist) {
         CommandManager.execute(Commands.FILE_OPEN, { fullPath: fullPath });
     } else {
         FileUtils.writeText(file, "", true)
             .done(function () {
                 CommandManager.execute(Commands.FILE_OPEN, { fullPath: fullPath });
             });
     }
 });
Example #28
0
 /**
  * Process the keybinding for the current key.
  *
  * @param {string} A key-description string.
  * @return {boolean} true if the key was processed, false otherwise
  */
 function handleKey(key) {
     if (_enabled && _keyMap[key]) {
         // The execute() function returns a promise because some commands are async.
         // Generally, commands decide whether they can run or not synchronously,
         // and reject immediately, so we can test for that synchronously.
         var promise = CommandManager.execute(_keyMap[key].commandID);
         return (promise.state() === "rejected") ? false : true;
     }
     return false;
 }
Example #29
0
 function openAlternateFile() {
     var fileToOpen = DocumentManager.getNextPrevFile(1);
     if (fileToOpen) {
         CommandManager.execute(Commands.FILE_OPEN, {fullPath: fileToOpen.fullPath});
     } else {
         _removeCustomViewer();
         _showNoEditor();
         _setCurrentlyViewedPath();
     }
 }
Example #30
0
 it("should collapse selection when appending to prepopulated text causes no result", function () {
     myEditor.setSelection({line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_PAREN});
     
     CommandManager.execute(Commands.EDIT_FIND);
     expectSelection({start: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_START}, end: {line: LINE_FIRST_REQUIRE, ch: CH_REQUIRE_PAREN}});
     
     enterSearchText("requireX");
     expectHighlightedMatches([]);
     expect(myEditor).toHaveCursorPosition(LINE_FIRST_REQUIRE, CH_REQUIRE_PAREN);
 });