InlineTextEditor.prototype.createInlineEditorFromText = function (doc, startLine, endLine, container, additionalKeys) {
        var self = this;
        
        var range = {
            startLine: startLine,
            endLine: endLine
        };
        
        // close handler attached to each inline codemirror instance
        function closeThisInline() {
            self.close();
        }
        
        // create the filename div
        var wrapperDiv = document.createElement("div");
        var $wrapperDiv = $(wrapperDiv);
        
        // dirty indicator followed by filename
        var $filenameDiv = $(document.createElement("div")).addClass("filename");
        
        // save file path data to dirty-indicator
        var $dirtyIndicatorDiv = $(document.createElement("div"))
            .addClass("dirty-indicator")
            .width(0); // initialize indicator as hidden
        $dirtyIndicatorDiv.data("fullPath", doc.file.fullPath);
        
        var $nameWithTooltip = $("<span></span>").text(doc.file.name).attr("title", doc.file.fullPath);
        var $lineNumber = $("<span class='lineNumber'>" + (startLine + 1) + "</span>");

        $filenameDiv.append($dirtyIndicatorDiv)
            .append($nameWithTooltip)
            .append(" : ")
            .append($lineNumber);
        $wrapperDiv.append($filenameDiv);

        var inlineInfo = EditorManager.createInlineEditorForDocument(doc, range, wrapperDiv, closeThisInline, additionalKeys);
        this.editors.push(inlineInfo.editor);
        container.appendChild(wrapperDiv);

        // Size editor to content whenever it changes (via edits here or any other view of the doc)
        $(inlineInfo.editor).on("change", function () {
            self.sizeInlineWidgetToContents();
            
            // And update line number since a change to the Editor equals a change to the Document,
            // which may mean a change to the line range too
            $lineNumber.text(inlineInfo.editor.getFirstVisibleLine() + 1);
        });
        
        // If Document's file is deleted, or Editor loses sync with Document, just close
        $(inlineInfo.editor).on("lostContent", function () {
            // Note: this closes the entire inline widget if any one Editor loses sync. This seems
            // better than leaving it open but suddenly removing one rule from the result list.
            self.close();
        });
        
        // set dirty indicator state
        _showDirtyIndicator($dirtyIndicatorDiv, doc.isDirty);
    };
Example #2
0
    InlineTextEditor.prototype.createInlineEditorFromText = function (doc, startLine, endLine, container, additionalKeys) {
        var self = this;
        
        var range = {
            startLine: startLine,
            endLine: endLine
        };
        
        // root container holding header & editor
        var $wrapperDiv = $("<div/>");
        var wrapperDiv = $wrapperDiv[0];
        
        // header containing filename, dirty indicator, line number
        var $header = $("<div/>").addClass("inline-editor-header");
        var $filenameInfo = $("<a/>").addClass("filename");
        
        // dirty indicator, with file path stored on it
        var $dirtyIndicatorDiv = $("<div/>")
            .addClass("dirty-indicator")
            .width(0); // initialize indicator as hidden
        $dirtyIndicatorDiv.data("fullPath", doc.file.fullPath);
        
        var $lineNumber = $("<span class='line-number'>" + (startLine + 1) + "</span>");

        // wrap filename & line number in clickable link with tooltip
        $filenameInfo.append($dirtyIndicatorDiv)
            .append(doc.file.name + " : ")
            .append($lineNumber)
            .attr("title", doc.file.fullPath);
        
        // clicking filename jumps to full editor view
        $filenameInfo.click(function () {
            CommandManager.execute(Commands.FILE_OPEN, { fullPath: doc.file.fullPath })
                .done(function () {
                    EditorManager.getCurrentFullEditor().setCursorPos(startLine);
                });
        });

        $header.append($filenameInfo);
        $wrapperDiv.append($header);
        
        
        // Create actual Editor instance
        var inlineInfo = EditorManager.createInlineEditorForDocument(doc, range, wrapperDiv, additionalKeys);
        this.editors.push(inlineInfo.editor);
        container.appendChild(wrapperDiv);

        // Size editor to content whenever text changes (via edits here or any other view of the doc: Editor
        // fires "change" any time its text changes, regardless of origin)
        $(inlineInfo.editor).on("change", function () {
            self.sizeInlineWidgetToContents();
            
            // Changes above the inline range could change our line number, so update label
            $lineNumber.text(inlineInfo.editor.getFirstVisibleLine() + 1);
        });
        
        // If Document's file is deleted, or Editor loses sync with Document, delegate to this._onLostContent()
        $(inlineInfo.editor).on("lostContent", function () {
            self._onLostContent.apply(self, arguments);
        });
        
        // set dirty indicator state
        _showDirtyIndicator($dirtyIndicatorDiv, doc.isDirty);
    };
Example #3
0
    InlineTextEditor.prototype.setInlineContent = function (doc, startLine, endLine) {
        var self = this;
        
        // Destroy the previous editor if we had one and clear out the filename info.
        if (this.editor) {
            this.editor.off(".InlineTextEditor");
            this.editor.destroy(); // remove from DOM and release ref on Document
            this.editor = null;
            this.$filename.off(".InlineTextEditor")
                .removeAttr("title");
            this.$filename.html("");
        }
        
        if (!doc) {
            return;
        }
        
        var range = {
            startLine: startLine,
            endLine: endLine
        };
        
        // dirty indicator, with file path stored on it
        var $dirtyIndicatorDiv = $("<div/>")
            .addClass("dirty-indicator")
            .html("&bull;")
            .width(0); // initialize indicator as hidden
        $dirtyIndicatorDiv.data("fullPath", doc.file.fullPath);
        
        this.$lineNumber = $("<span class='line-number'/>");

        // update contents of filename link
        this.$filename.append($dirtyIndicatorDiv)
            .append(doc.file.name + " : ")
            .append(this.$lineNumber)
            .attr("title", doc.file.fullPath);
        
        // clicking filename jumps to full editor view
        this.$filename.on("click.InlineTextEditor", function () {
            CommandManager.execute(Commands.FILE_OPEN, { fullPath: doc.file.fullPath })
                .done(function () {
                    EditorManager.getCurrentFullEditor().setCursorPos(startLine, 0, true);
                });
        });

        var inlineInfo = EditorManager.createInlineEditorForDocument(doc, range, this.$editorHolder.get(0));
        this.editor = inlineInfo.editor;
        
        // Init line number display
        this._updateLineRange(inlineInfo.editor);

        // Always update the widget height when an inline editor completes a
        // display update
        this.editor.on("update.InlineTextEditor", function (event, editor) {
            self.sizeInlineWidgetToContents();
        });

        // Size editor to content whenever text changes (via edits here or any
        // other view of the doc: Editor fires "change" any time its text
        // changes, regardless of origin)
        this.editor.on("change.InlineTextEditor", function (event, editor) {
            if (self.hostEditor.isFullyVisible()) {
                self.sizeInlineWidgetToContents();
                self._updateLineRange(editor);
            }
        });
        
        // If Document's file is deleted, or Editor loses sync with Document, delegate to this._onLostContent()
        this.editor.on("lostContent.InlineTextEditor", function () {
            self._onLostContent.apply(self, arguments);
        });
        
        // set dirty indicator state
        _showDirtyIndicator($dirtyIndicatorDiv, doc.isDirty);
    };