id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
sequence
docstring
stringlengths
4
11.8k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
86
226
2,400
adobe/brackets
src/language/HTMLDOMDiff.js
function () { var prev = prevNode(); if (prev && !prev.children) { newEdit = { type: "textReplace", content: prev.content }; } else { newEdit = { type: "textDelete" }; } // When elements are deleted or moved from the old set of children, you // can end up with multiple text nodes in a row. A single textReplace edit // will take care of those (and will contain all of the right content since // the text nodes between elements in the new DOM are merged together). // The check below looks to see if we're already in the process of adding // a textReplace edit following the same element. var previousEdit = newEdits.length > 0 && newEdits[newEdits.length - 1]; if (previousEdit && previousEdit.type === "textReplace" && previousEdit.afterID === textAfterID) { oldIndex++; return; } newEdit.parentID = oldChild.parent.tagID; // If there was only one child previously, we just pass along // textDelete/textReplace with the parentID and the browser will // clear all of the children if (oldChild.parent.children.length === 1) { newEdits.push(newEdit); } else { if (textAfterID) { newEdit.afterID = textAfterID; } newEdits.push(newEdit); } // This text appeared in the old tree but not the new one, so we // increment the old children counter. oldIndex++; }
javascript
function () { var prev = prevNode(); if (prev && !prev.children) { newEdit = { type: "textReplace", content: prev.content }; } else { newEdit = { type: "textDelete" }; } // When elements are deleted or moved from the old set of children, you // can end up with multiple text nodes in a row. A single textReplace edit // will take care of those (and will contain all of the right content since // the text nodes between elements in the new DOM are merged together). // The check below looks to see if we're already in the process of adding // a textReplace edit following the same element. var previousEdit = newEdits.length > 0 && newEdits[newEdits.length - 1]; if (previousEdit && previousEdit.type === "textReplace" && previousEdit.afterID === textAfterID) { oldIndex++; return; } newEdit.parentID = oldChild.parent.tagID; // If there was only one child previously, we just pass along // textDelete/textReplace with the parentID and the browser will // clear all of the children if (oldChild.parent.children.length === 1) { newEdits.push(newEdit); } else { if (textAfterID) { newEdit.afterID = textAfterID; } newEdits.push(newEdit); } // This text appeared in the old tree but not the new one, so we // increment the old children counter. oldIndex++; }
[ "function", "(", ")", "{", "var", "prev", "=", "prevNode", "(", ")", ";", "if", "(", "prev", "&&", "!", "prev", ".", "children", ")", "{", "newEdit", "=", "{", "type", ":", "\"textReplace\"", ",", "content", ":", "prev", ".", "content", "}", ";", "}", "else", "{", "newEdit", "=", "{", "type", ":", "\"textDelete\"", "}", ";", "}", "// When elements are deleted or moved from the old set of children, you", "// can end up with multiple text nodes in a row. A single textReplace edit", "// will take care of those (and will contain all of the right content since", "// the text nodes between elements in the new DOM are merged together).", "// The check below looks to see if we're already in the process of adding", "// a textReplace edit following the same element.", "var", "previousEdit", "=", "newEdits", ".", "length", ">", "0", "&&", "newEdits", "[", "newEdits", ".", "length", "-", "1", "]", ";", "if", "(", "previousEdit", "&&", "previousEdit", ".", "type", "===", "\"textReplace\"", "&&", "previousEdit", ".", "afterID", "===", "textAfterID", ")", "{", "oldIndex", "++", ";", "return", ";", "}", "newEdit", ".", "parentID", "=", "oldChild", ".", "parent", ".", "tagID", ";", "// If there was only one child previously, we just pass along", "// textDelete/textReplace with the parentID and the browser will", "// clear all of the children", "if", "(", "oldChild", ".", "parent", ".", "children", ".", "length", "===", "1", ")", "{", "newEdits", ".", "push", "(", "newEdit", ")", ";", "}", "else", "{", "if", "(", "textAfterID", ")", "{", "newEdit", ".", "afterID", "=", "textAfterID", ";", "}", "newEdits", ".", "push", "(", "newEdit", ")", ";", "}", "// This text appeared in the old tree but not the new one, so we", "// increment the old children counter.", "oldIndex", "++", ";", "}" ]
Adds a textDelete edit for text node that is not in the new tree. Note that we actually create a textReplace rather than a textDelete if the previous node in current tree was a text node. We do this because text nodes are not individually addressable and a delete event would end up clearing out both that previous text node that we want to keep and this text node that we want to eliminate. Instead, we just log a textReplace which will result in the deletion of this node and the maintaining of the old content.
[ "Adds", "a", "textDelete", "edit", "for", "text", "node", "that", "is", "not", "in", "the", "new", "tree", ".", "Note", "that", "we", "actually", "create", "a", "textReplace", "rather", "than", "a", "textDelete", "if", "the", "previous", "node", "in", "current", "tree", "was", "a", "text", "node", ".", "We", "do", "this", "because", "text", "nodes", "are", "not", "individually", "addressable", "and", "a", "delete", "event", "would", "end", "up", "clearing", "out", "both", "that", "previous", "text", "node", "that", "we", "want", "to", "keep", "and", "this", "text", "node", "that", "we", "want", "to", "eliminate", ".", "Instead", "we", "just", "log", "a", "textReplace", "which", "will", "result", "in", "the", "deletion", "of", "this", "node", "and", "the", "maintaining", "of", "the", "old", "content", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L266-L309
2,401
adobe/brackets
src/language/HTMLDOMDiff.js
function () { // This check looks a little strange, but it suits what we're trying // to do: as we're walking through the children, a child node that has moved // from one parent to another will be found but would look like some kind // of insert. The check that we're doing here is looking up the current // child's ID in the *old* map and seeing if this child used to have a // different parent. var possiblyMovedElement = oldNodeMap[newChild.tagID]; if (possiblyMovedElement && newParent.tagID !== getParentID(possiblyMovedElement)) { newEdit = { type: "elementMove", tagID: newChild.tagID, parentID: newChild.parent.tagID }; moves.push(newEdit.tagID); newEdits.push(newEdit); // this element in the new tree was a move to this spot, so we can move // on to the next child in the new tree. newIndex++; return true; } return false; }
javascript
function () { // This check looks a little strange, but it suits what we're trying // to do: as we're walking through the children, a child node that has moved // from one parent to another will be found but would look like some kind // of insert. The check that we're doing here is looking up the current // child's ID in the *old* map and seeing if this child used to have a // different parent. var possiblyMovedElement = oldNodeMap[newChild.tagID]; if (possiblyMovedElement && newParent.tagID !== getParentID(possiblyMovedElement)) { newEdit = { type: "elementMove", tagID: newChild.tagID, parentID: newChild.parent.tagID }; moves.push(newEdit.tagID); newEdits.push(newEdit); // this element in the new tree was a move to this spot, so we can move // on to the next child in the new tree. newIndex++; return true; } return false; }
[ "function", "(", ")", "{", "// This check looks a little strange, but it suits what we're trying", "// to do: as we're walking through the children, a child node that has moved", "// from one parent to another will be found but would look like some kind", "// of insert. The check that we're doing here is looking up the current", "// child's ID in the *old* map and seeing if this child used to have a", "// different parent.", "var", "possiblyMovedElement", "=", "oldNodeMap", "[", "newChild", ".", "tagID", "]", ";", "if", "(", "possiblyMovedElement", "&&", "newParent", ".", "tagID", "!==", "getParentID", "(", "possiblyMovedElement", ")", ")", "{", "newEdit", "=", "{", "type", ":", "\"elementMove\"", ",", "tagID", ":", "newChild", ".", "tagID", ",", "parentID", ":", "newChild", ".", "parent", ".", "tagID", "}", ";", "moves", ".", "push", "(", "newEdit", ".", "tagID", ")", ";", "newEdits", ".", "push", "(", "newEdit", ")", ";", "// this element in the new tree was a move to this spot, so we can move", "// on to the next child in the new tree.", "newIndex", "++", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Adds an elementMove edit if the parent has changed between the old and new trees. These are fairly infrequent and generally occur if you make a change across tag boundaries. @return {boolean} true if an elementMove was generated
[ "Adds", "an", "elementMove", "edit", "if", "the", "parent", "has", "changed", "between", "the", "old", "and", "new", "trees", ".", "These", "are", "fairly", "infrequent", "and", "generally", "occur", "if", "you", "make", "a", "change", "across", "tag", "boundaries", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L318-L343
2,402
adobe/brackets
src/language/HTMLDOMDiff.js
function (oldChild) { var oldChildInNewTree = newNodeMap[oldChild.tagID]; return oldChild.children && oldChildInNewTree && getParentID(oldChild) !== getParentID(oldChildInNewTree); }
javascript
function (oldChild) { var oldChildInNewTree = newNodeMap[oldChild.tagID]; return oldChild.children && oldChildInNewTree && getParentID(oldChild) !== getParentID(oldChildInNewTree); }
[ "function", "(", "oldChild", ")", "{", "var", "oldChildInNewTree", "=", "newNodeMap", "[", "oldChild", ".", "tagID", "]", ";", "return", "oldChild", ".", "children", "&&", "oldChildInNewTree", "&&", "getParentID", "(", "oldChild", ")", "!==", "getParentID", "(", "oldChildInNewTree", ")", ";", "}" ]
Looks to see if the element in the old tree has moved by checking its current and former parents. @return {boolean} true if the element has moved
[ "Looks", "to", "see", "if", "the", "element", "in", "the", "old", "tree", "has", "moved", "by", "checking", "its", "current", "and", "former", "parents", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L351-L355
2,403
adobe/brackets
src/language/HTMLDOMDiff.js
function (delta) { edits.push.apply(edits, delta.edits); moves.push.apply(moves, delta.moves); queue.push.apply(queue, delta.newElements); }
javascript
function (delta) { edits.push.apply(edits, delta.edits); moves.push.apply(moves, delta.moves); queue.push.apply(queue, delta.newElements); }
[ "function", "(", "delta", ")", "{", "edits", ".", "push", ".", "apply", "(", "edits", ",", "delta", ".", "edits", ")", ";", "moves", ".", "push", ".", "apply", "(", "moves", ",", "delta", ".", "moves", ")", ";", "queue", ".", "push", ".", "apply", "(", "queue", ",", "delta", ".", "newElements", ")", ";", "}" ]
Aggregates the child edits in the proper data structures. @param {Object} delta edits, moves and newElements to add
[ "Aggregates", "the", "child", "edits", "in", "the", "proper", "data", "structures", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/HTMLDOMDiff.js#L561-L565
2,404
adobe/brackets
src/editor/ImageViewer.js
_handleFileSystemChange
function _handleFileSystemChange(event, entry, added, removed) { // this may have been called because files were added // or removed to the file system. We don't care about those if (!entry || entry.isDirectory) { return; } // Look for a viewer for the changed file var viewer = _viewers[entry.fullPath]; // viewer found, call its refresh method if (viewer) { viewer.refresh(); } }
javascript
function _handleFileSystemChange(event, entry, added, removed) { // this may have been called because files were added // or removed to the file system. We don't care about those if (!entry || entry.isDirectory) { return; } // Look for a viewer for the changed file var viewer = _viewers[entry.fullPath]; // viewer found, call its refresh method if (viewer) { viewer.refresh(); } }
[ "function", "_handleFileSystemChange", "(", "event", ",", "entry", ",", "added", ",", "removed", ")", "{", "// this may have been called because files were added", "// or removed to the file system. We don't care about those", "if", "(", "!", "entry", "||", "entry", ".", "isDirectory", ")", "{", "return", ";", "}", "// Look for a viewer for the changed file", "var", "viewer", "=", "_viewers", "[", "entry", ".", "fullPath", "]", ";", "// viewer found, call its refresh method", "if", "(", "viewer", ")", "{", "viewer", ".", "refresh", "(", ")", ";", "}", "}" ]
Handles file system change events so we can refresh image viewers for the files that changed on disk due to external editors @param {jQuery.event} event - event object @param {?File} file - file object that changed @param {Array.<FileSystemEntry>=} added If entry is a Directory, contains zero or more added children @param {Array.<FileSystemEntry>=} removed If entry is a Directory, contains zero or more removed children
[ "Handles", "file", "system", "change", "events", "so", "we", "can", "refresh", "image", "viewers", "for", "the", "files", "that", "changed", "on", "disk", "due", "to", "external", "editors" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/ImageViewer.js#L437-L451
2,405
adobe/brackets
src/view/ViewCommandHandlers.js
setFontSize
function setFontSize(fontSize) { if (currFontSize === fontSize) { return; } _removeDynamicFontSize(); if (fontSize) { _addDynamicFontSize(fontSize); } // Update scroll metrics in viewed editors _.forEach(MainViewManager.getPaneIdList(), function (paneId) { var currentPath = MainViewManager.getCurrentlyViewedPath(paneId), doc = currentPath && DocumentManager.getOpenDocumentForPath(currentPath); if (doc && doc._masterEditor) { _updateScroll(doc._masterEditor, fontSize); } }); exports.trigger("fontSizeChange", fontSize, currFontSize); currFontSize = fontSize; prefs.set("fontSize", fontSize); }
javascript
function setFontSize(fontSize) { if (currFontSize === fontSize) { return; } _removeDynamicFontSize(); if (fontSize) { _addDynamicFontSize(fontSize); } // Update scroll metrics in viewed editors _.forEach(MainViewManager.getPaneIdList(), function (paneId) { var currentPath = MainViewManager.getCurrentlyViewedPath(paneId), doc = currentPath && DocumentManager.getOpenDocumentForPath(currentPath); if (doc && doc._masterEditor) { _updateScroll(doc._masterEditor, fontSize); } }); exports.trigger("fontSizeChange", fontSize, currFontSize); currFontSize = fontSize; prefs.set("fontSize", fontSize); }
[ "function", "setFontSize", "(", "fontSize", ")", "{", "if", "(", "currFontSize", "===", "fontSize", ")", "{", "return", ";", "}", "_removeDynamicFontSize", "(", ")", ";", "if", "(", "fontSize", ")", "{", "_addDynamicFontSize", "(", "fontSize", ")", ";", "}", "// Update scroll metrics in viewed editors", "_", ".", "forEach", "(", "MainViewManager", ".", "getPaneIdList", "(", ")", ",", "function", "(", "paneId", ")", "{", "var", "currentPath", "=", "MainViewManager", ".", "getCurrentlyViewedPath", "(", "paneId", ")", ",", "doc", "=", "currentPath", "&&", "DocumentManager", ".", "getOpenDocumentForPath", "(", "currentPath", ")", ";", "if", "(", "doc", "&&", "doc", ".", "_masterEditor", ")", "{", "_updateScroll", "(", "doc", ".", "_masterEditor", ",", "fontSize", ")", ";", "}", "}", ")", ";", "exports", ".", "trigger", "(", "\"fontSizeChange\"", ",", "fontSize", ",", "currFontSize", ")", ";", "currFontSize", "=", "fontSize", ";", "prefs", ".", "set", "(", "\"fontSize\"", ",", "fontSize", ")", ";", "}" ]
Font size setter to set the font size for the document editor @param {string} fontSize The font size with size unit as 'px' or 'em'
[ "Font", "size", "setter", "to", "set", "the", "font", "size", "for", "the", "document", "editor" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L236-L258
2,406
adobe/brackets
src/view/ViewCommandHandlers.js
setFontFamily
function setFontFamily(fontFamily) { var editor = EditorManager.getCurrentFullEditor(); if (currFontFamily === fontFamily) { return; } _removeDynamicFontFamily(); if (fontFamily) { _addDynamicFontFamily(fontFamily); } exports.trigger("fontFamilyChange", fontFamily, currFontFamily); currFontFamily = fontFamily; prefs.set("fontFamily", fontFamily); if (editor) { editor.refreshAll(); } }
javascript
function setFontFamily(fontFamily) { var editor = EditorManager.getCurrentFullEditor(); if (currFontFamily === fontFamily) { return; } _removeDynamicFontFamily(); if (fontFamily) { _addDynamicFontFamily(fontFamily); } exports.trigger("fontFamilyChange", fontFamily, currFontFamily); currFontFamily = fontFamily; prefs.set("fontFamily", fontFamily); if (editor) { editor.refreshAll(); } }
[ "function", "setFontFamily", "(", "fontFamily", ")", "{", "var", "editor", "=", "EditorManager", ".", "getCurrentFullEditor", "(", ")", ";", "if", "(", "currFontFamily", "===", "fontFamily", ")", "{", "return", ";", "}", "_removeDynamicFontFamily", "(", ")", ";", "if", "(", "fontFamily", ")", "{", "_addDynamicFontFamily", "(", "fontFamily", ")", ";", "}", "exports", ".", "trigger", "(", "\"fontFamilyChange\"", ",", "fontFamily", ",", "currFontFamily", ")", ";", "currFontFamily", "=", "fontFamily", ";", "prefs", ".", "set", "(", "\"fontFamily\"", ",", "fontFamily", ")", ";", "if", "(", "editor", ")", "{", "editor", ".", "refreshAll", "(", ")", ";", "}", "}" ]
Font family setter to set the font family for the document editor @param {string} fontFamily The font family to be set. It can be a string with multiple comma separated fonts
[ "Font", "family", "setter", "to", "set", "the", "font", "family", "for", "the", "document", "editor" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L273-L292
2,407
adobe/brackets
src/view/ViewCommandHandlers.js
init
function init() { currFontFamily = prefs.get("fontFamily"); _addDynamicFontFamily(currFontFamily); currFontSize = prefs.get("fontSize"); _addDynamicFontSize(currFontSize); _updateUI(); }
javascript
function init() { currFontFamily = prefs.get("fontFamily"); _addDynamicFontFamily(currFontFamily); currFontSize = prefs.get("fontSize"); _addDynamicFontSize(currFontSize); _updateUI(); }
[ "function", "init", "(", ")", "{", "currFontFamily", "=", "prefs", ".", "get", "(", "\"fontFamily\"", ")", ";", "_addDynamicFontFamily", "(", "currFontFamily", ")", ";", "currFontSize", "=", "prefs", ".", "get", "(", "\"fontSize\"", ")", ";", "_addDynamicFontSize", "(", "currFontSize", ")", ";", "_updateUI", "(", ")", ";", "}" ]
Initializes the different settings that need to loaded
[ "Initializes", "the", "different", "settings", "that", "need", "to", "loaded" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L393-L399
2,408
adobe/brackets
src/view/ViewCommandHandlers.js
restoreFontSize
function restoreFontSize() { var fsStyle = prefs.get("fontSize"), fsAdjustment = PreferencesManager.getViewState("fontSizeAdjustment"); if (fsAdjustment) { // Always remove the old view state even if we also have the new view state. PreferencesManager.setViewState("fontSizeAdjustment"); if (!fsStyle) { // Migrate the old view state to the new one. fsStyle = (DEFAULT_FONT_SIZE + fsAdjustment) + "px"; prefs.set("fontSize", fsStyle); } } if (fsStyle) { _removeDynamicFontSize(); _addDynamicFontSize(fsStyle); } }
javascript
function restoreFontSize() { var fsStyle = prefs.get("fontSize"), fsAdjustment = PreferencesManager.getViewState("fontSizeAdjustment"); if (fsAdjustment) { // Always remove the old view state even if we also have the new view state. PreferencesManager.setViewState("fontSizeAdjustment"); if (!fsStyle) { // Migrate the old view state to the new one. fsStyle = (DEFAULT_FONT_SIZE + fsAdjustment) + "px"; prefs.set("fontSize", fsStyle); } } if (fsStyle) { _removeDynamicFontSize(); _addDynamicFontSize(fsStyle); } }
[ "function", "restoreFontSize", "(", ")", "{", "var", "fsStyle", "=", "prefs", ".", "get", "(", "\"fontSize\"", ")", ",", "fsAdjustment", "=", "PreferencesManager", ".", "getViewState", "(", "\"fontSizeAdjustment\"", ")", ";", "if", "(", "fsAdjustment", ")", "{", "// Always remove the old view state even if we also have the new view state.", "PreferencesManager", ".", "setViewState", "(", "\"fontSizeAdjustment\"", ")", ";", "if", "(", "!", "fsStyle", ")", "{", "// Migrate the old view state to the new one.", "fsStyle", "=", "(", "DEFAULT_FONT_SIZE", "+", "fsAdjustment", ")", "+", "\"px\"", ";", "prefs", ".", "set", "(", "\"fontSize\"", ",", "fsStyle", ")", ";", "}", "}", "if", "(", "fsStyle", ")", "{", "_removeDynamicFontSize", "(", ")", ";", "_addDynamicFontSize", "(", "fsStyle", ")", ";", "}", "}" ]
Restores the font size using the saved style and migrates the old fontSizeAdjustment view state to the new fontSize, when required
[ "Restores", "the", "font", "size", "using", "the", "saved", "style", "and", "migrates", "the", "old", "fontSizeAdjustment", "view", "state", "to", "the", "new", "fontSize", "when", "required" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ViewCommandHandlers.js#L405-L424
2,409
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
CubicBezier
function CubicBezier(coordinates) { if (typeof coordinates === "string") { this.coordinates = coordinates.split(","); } else { this.coordinates = coordinates; } if (!this.coordinates) { throw "No offsets were defined"; } this.coordinates = this.coordinates.map(function (n) { return +n; }); var i; for (i = 3; i >= 0; i--) { var xy = this.coordinates[i]; if (isNaN(xy) || (((i % 2) === 0) && (xy < 0 || xy > 1))) { throw "Wrong coordinate at " + i + "(" + xy + ")"; } } }
javascript
function CubicBezier(coordinates) { if (typeof coordinates === "string") { this.coordinates = coordinates.split(","); } else { this.coordinates = coordinates; } if (!this.coordinates) { throw "No offsets were defined"; } this.coordinates = this.coordinates.map(function (n) { return +n; }); var i; for (i = 3; i >= 0; i--) { var xy = this.coordinates[i]; if (isNaN(xy) || (((i % 2) === 0) && (xy < 0 || xy > 1))) { throw "Wrong coordinate at " + i + "(" + xy + ")"; } } }
[ "function", "CubicBezier", "(", "coordinates", ")", "{", "if", "(", "typeof", "coordinates", "===", "\"string\"", ")", "{", "this", ".", "coordinates", "=", "coordinates", ".", "split", "(", "\",\"", ")", ";", "}", "else", "{", "this", ".", "coordinates", "=", "coordinates", ";", "}", "if", "(", "!", "this", ".", "coordinates", ")", "{", "throw", "\"No offsets were defined\"", ";", "}", "this", ".", "coordinates", "=", "this", ".", "coordinates", ".", "map", "(", "function", "(", "n", ")", "{", "return", "+", "n", ";", "}", ")", ";", "var", "i", ";", "for", "(", "i", "=", "3", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "var", "xy", "=", "this", ".", "coordinates", "[", "i", "]", ";", "if", "(", "isNaN", "(", "xy", ")", "||", "(", "(", "(", "i", "%", "2", ")", "===", "0", ")", "&&", "(", "xy", "<", "0", "||", "xy", ">", "1", ")", ")", ")", "{", "throw", "\"Wrong coordinate at \"", "+", "i", "+", "\"(\"", "+", "xy", "+", "\")\"", ";", "}", "}", "}" ]
CubicBezier object constructor @param {string|Array.number[4]} coordinates Four parameters passes to cubic-bezier() either in string or array format.
[ "CubicBezier", "object", "constructor" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L50-L70
2,410
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
BezierCanvas
function BezierCanvas(canvas, bezier, padding) { this.canvas = canvas; this.bezier = bezier; this.padding = this.getPadding(padding); // Convert to a cartesian coordinate system with axes from 0 to 1 var ctx = this.canvas.getContext("2d"), p = this.padding; ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * 0.5 * (1 - p[0] - p[2])); ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2])) - 0.5); }
javascript
function BezierCanvas(canvas, bezier, padding) { this.canvas = canvas; this.bezier = bezier; this.padding = this.getPadding(padding); // Convert to a cartesian coordinate system with axes from 0 to 1 var ctx = this.canvas.getContext("2d"), p = this.padding; ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * 0.5 * (1 - p[0] - p[2])); ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2])) - 0.5); }
[ "function", "BezierCanvas", "(", "canvas", ",", "bezier", ",", "padding", ")", "{", "this", ".", "canvas", "=", "canvas", ";", "this", ".", "bezier", "=", "bezier", ";", "this", ".", "padding", "=", "this", ".", "getPadding", "(", "padding", ")", ";", "// Convert to a cartesian coordinate system with axes from 0 to 1", "var", "ctx", "=", "this", ".", "canvas", ".", "getContext", "(", "\"2d\"", ")", ",", "p", "=", "this", ".", "padding", ";", "ctx", ".", "scale", "(", "canvas", ".", "width", "*", "(", "1", "-", "p", "[", "1", "]", "-", "p", "[", "3", "]", ")", ",", "-", "canvas", ".", "height", "*", "0.5", "*", "(", "1", "-", "p", "[", "0", "]", "-", "p", "[", "2", "]", ")", ")", ";", "ctx", ".", "translate", "(", "p", "[", "3", "]", "/", "(", "1", "-", "p", "[", "1", "]", "-", "p", "[", "3", "]", ")", ",", "(", "-", "1", "-", "p", "[", "0", "]", "/", "(", "1", "-", "p", "[", "0", "]", "-", "p", "[", "2", "]", ")", ")", "-", "0.5", ")", ";", "}" ]
BezierCanvas object constructor @param {Element} canvas Inline editor <canvas> element @param {CubicBezier} bezier Associated CubicBezier object @param {number|Array.number} padding Element padding
[ "BezierCanvas", "object", "constructor" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L79-L90
2,411
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
function (element) { var p = this.padding, w = this.canvas.width, h = this.canvas.height * 0.5; // Convert padding percentage to actual padding p = p.map(function (a, i) { return a * ((i % 2) ? w : h); }); return [ this.prettify((parseInt($(element).css("left"), 10) - p[3]) / (w + p[1] + p[3])), this.prettify((h - parseInt($(element).css("top"), 10) - p[2]) / (h - p[0] - p[2])) ]; }
javascript
function (element) { var p = this.padding, w = this.canvas.width, h = this.canvas.height * 0.5; // Convert padding percentage to actual padding p = p.map(function (a, i) { return a * ((i % 2) ? w : h); }); return [ this.prettify((parseInt($(element).css("left"), 10) - p[3]) / (w + p[1] + p[3])), this.prettify((h - parseInt($(element).css("top"), 10) - p[2]) / (h - p[0] - p[2])) ]; }
[ "function", "(", "element", ")", "{", "var", "p", "=", "this", ".", "padding", ",", "w", "=", "this", ".", "canvas", ".", "width", ",", "h", "=", "this", ".", "canvas", ".", "height", "*", "0.5", ";", "// Convert padding percentage to actual padding", "p", "=", "p", ".", "map", "(", "function", "(", "a", ",", "i", ")", "{", "return", "a", "*", "(", "(", "i", "%", "2", ")", "?", "w", ":", "h", ")", ";", "}", ")", ";", "return", "[", "this", ".", "prettify", "(", "(", "parseInt", "(", "$", "(", "element", ")", ".", "css", "(", "\"left\"", ")", ",", "10", ")", "-", "p", "[", "3", "]", ")", "/", "(", "w", "+", "p", "[", "1", "]", "+", "p", "[", "3", "]", ")", ")", ",", "this", ".", "prettify", "(", "(", "h", "-", "parseInt", "(", "$", "(", "element", ")", ".", "css", "(", "\"top\"", ")", ",", "10", ")", "-", "p", "[", "2", "]", ")", "/", "(", "h", "-", "p", "[", "0", "]", "-", "p", "[", "2", "]", ")", ")", "]", ";", "}" ]
Get CSS left, top offsets for endpoint handle @param {Element} element Endpoint handle <button> element @return {Array.string[2]}
[ "Get", "CSS", "left", "top", "offsets", "for", "endpoint", "handle" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L129-L143
2,412
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
function (padding) { var p = (typeof padding === "number") ? [padding] : padding; if (p.length === 1) { p[1] = p[0]; } if (p.length === 2) { p[2] = p[0]; } if (p.length === 3) { p[3] = p[1]; } return p; }
javascript
function (padding) { var p = (typeof padding === "number") ? [padding] : padding; if (p.length === 1) { p[1] = p[0]; } if (p.length === 2) { p[2] = p[0]; } if (p.length === 3) { p[3] = p[1]; } return p; }
[ "function", "(", "padding", ")", "{", "var", "p", "=", "(", "typeof", "padding", "===", "\"number\"", ")", "?", "[", "padding", "]", ":", "padding", ";", "if", "(", "p", ".", "length", "===", "1", ")", "{", "p", "[", "1", "]", "=", "p", "[", "0", "]", ";", "}", "if", "(", "p", ".", "length", "===", "2", ")", "{", "p", "[", "2", "]", "=", "p", "[", "0", "]", ";", "}", "if", "(", "p", ".", "length", "===", "3", ")", "{", "p", "[", "3", "]", "=", "p", "[", "1", "]", ";", "}", "return", "p", ";", "}" ]
Convert CSS padding shorthand to longhand @param {number|Array.number} padding Element padding @return {Array.number}
[ "Convert", "CSS", "padding", "shorthand", "to", "longhand" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L218-L232
2,413
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
handlePointMove
function handlePointMove(e, x, y) { var self = e.target, bezierEditor = self.bezierEditor; // Helper function to redraw curve function mouseMoveRedraw() { if (!bezierEditor.dragElement) { animationRequest = null; return; } // Update code bezierEditor._commitTimingFunction(); bezierEditor._updateCanvas(); animationRequest = window.requestAnimationFrame(mouseMoveRedraw); } // This is a dragging state, but left button is no longer down, so mouse // exited element, was released, and re-entered element. Treat like a drop. if (bezierEditor.dragElement && (e.which !== 1)) { bezierEditor.dragElement = null; bezierEditor._commitTimingFunction(); bezierEditor._updateCanvas(); bezierEditor = null; return; } // Constrain time (x-axis) to 0 to 1 range. Progression (y-axis) is // theoretically not constrained, although canvas to drawing curve is // arbitrarily constrained to -0.5 to 1.5 range. x = Math.min(Math.max(0, x), WIDTH_MAIN); if (bezierEditor.dragElement) { $(bezierEditor.dragElement).css({ left: x + "px", top: y + "px" }); } // update coords bezierEditor._cubicBezierCoords = bezierEditor.bezierCanvas .offsetsToCoordinates(bezierEditor.P1) .concat(bezierEditor.bezierCanvas.offsetsToCoordinates(bezierEditor.P2)); if (!animationRequest) { animationRequest = window.requestAnimationFrame(mouseMoveRedraw); } }
javascript
function handlePointMove(e, x, y) { var self = e.target, bezierEditor = self.bezierEditor; // Helper function to redraw curve function mouseMoveRedraw() { if (!bezierEditor.dragElement) { animationRequest = null; return; } // Update code bezierEditor._commitTimingFunction(); bezierEditor._updateCanvas(); animationRequest = window.requestAnimationFrame(mouseMoveRedraw); } // This is a dragging state, but left button is no longer down, so mouse // exited element, was released, and re-entered element. Treat like a drop. if (bezierEditor.dragElement && (e.which !== 1)) { bezierEditor.dragElement = null; bezierEditor._commitTimingFunction(); bezierEditor._updateCanvas(); bezierEditor = null; return; } // Constrain time (x-axis) to 0 to 1 range. Progression (y-axis) is // theoretically not constrained, although canvas to drawing curve is // arbitrarily constrained to -0.5 to 1.5 range. x = Math.min(Math.max(0, x), WIDTH_MAIN); if (bezierEditor.dragElement) { $(bezierEditor.dragElement).css({ left: x + "px", top: y + "px" }); } // update coords bezierEditor._cubicBezierCoords = bezierEditor.bezierCanvas .offsetsToCoordinates(bezierEditor.P1) .concat(bezierEditor.bezierCanvas.offsetsToCoordinates(bezierEditor.P2)); if (!animationRequest) { animationRequest = window.requestAnimationFrame(mouseMoveRedraw); } }
[ "function", "handlePointMove", "(", "e", ",", "x", ",", "y", ")", "{", "var", "self", "=", "e", ".", "target", ",", "bezierEditor", "=", "self", ".", "bezierEditor", ";", "// Helper function to redraw curve", "function", "mouseMoveRedraw", "(", ")", "{", "if", "(", "!", "bezierEditor", ".", "dragElement", ")", "{", "animationRequest", "=", "null", ";", "return", ";", "}", "// Update code", "bezierEditor", ".", "_commitTimingFunction", "(", ")", ";", "bezierEditor", ".", "_updateCanvas", "(", ")", ";", "animationRequest", "=", "window", ".", "requestAnimationFrame", "(", "mouseMoveRedraw", ")", ";", "}", "// This is a dragging state, but left button is no longer down, so mouse", "// exited element, was released, and re-entered element. Treat like a drop.", "if", "(", "bezierEditor", ".", "dragElement", "&&", "(", "e", ".", "which", "!==", "1", ")", ")", "{", "bezierEditor", ".", "dragElement", "=", "null", ";", "bezierEditor", ".", "_commitTimingFunction", "(", ")", ";", "bezierEditor", ".", "_updateCanvas", "(", ")", ";", "bezierEditor", "=", "null", ";", "return", ";", "}", "// Constrain time (x-axis) to 0 to 1 range. Progression (y-axis) is", "// theoretically not constrained, although canvas to drawing curve is", "// arbitrarily constrained to -0.5 to 1.5 range.", "x", "=", "Math", ".", "min", "(", "Math", ".", "max", "(", "0", ",", "x", ")", ",", "WIDTH_MAIN", ")", ";", "if", "(", "bezierEditor", ".", "dragElement", ")", "{", "$", "(", "bezierEditor", ".", "dragElement", ")", ".", "css", "(", "{", "left", ":", "x", "+", "\"px\"", ",", "top", ":", "y", "+", "\"px\"", "}", ")", ";", "}", "// update coords", "bezierEditor", ".", "_cubicBezierCoords", "=", "bezierEditor", ".", "bezierCanvas", ".", "offsetsToCoordinates", "(", "bezierEditor", ".", "P1", ")", ".", "concat", "(", "bezierEditor", ".", "bezierCanvas", ".", "offsetsToCoordinates", "(", "bezierEditor", ".", "P2", ")", ")", ";", "if", "(", "!", "animationRequest", ")", "{", "animationRequest", "=", "window", ".", "requestAnimationFrame", "(", "mouseMoveRedraw", ")", ";", "}", "}" ]
Helper function for handling point move @param {Event} e Mouse move event @param {number} x New horizontal position @param {number} y New vertical position
[ "Helper", "function", "for", "handling", "point", "move" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L286-L334
2,414
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
mouseMoveRedraw
function mouseMoveRedraw() { if (!bezierEditor.dragElement) { animationRequest = null; return; } // Update code bezierEditor._commitTimingFunction(); bezierEditor._updateCanvas(); animationRequest = window.requestAnimationFrame(mouseMoveRedraw); }
javascript
function mouseMoveRedraw() { if (!bezierEditor.dragElement) { animationRequest = null; return; } // Update code bezierEditor._commitTimingFunction(); bezierEditor._updateCanvas(); animationRequest = window.requestAnimationFrame(mouseMoveRedraw); }
[ "function", "mouseMoveRedraw", "(", ")", "{", "if", "(", "!", "bezierEditor", ".", "dragElement", ")", "{", "animationRequest", "=", "null", ";", "return", ";", "}", "// Update code", "bezierEditor", ".", "_commitTimingFunction", "(", ")", ";", "bezierEditor", ".", "_updateCanvas", "(", ")", ";", "animationRequest", "=", "window", ".", "requestAnimationFrame", "(", "mouseMoveRedraw", ")", ";", "}" ]
Helper function to redraw curve
[ "Helper", "function", "to", "redraw", "curve" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L291-L302
2,415
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js
BezierCurveEditor
function BezierCurveEditor($parent, bezierCurve, callback) { // Create the DOM structure, filling in localized strings via Mustache this.$element = $(Mustache.render(BezierCurveEditorTemplate, Strings)); $parent.append(this.$element); this._callback = callback; this.dragElement = null; // current cubic-bezier() function params this._cubicBezierCoords = this._getCubicBezierCoords(bezierCurve); this.hint = {}; this.hint.elem = $(".hint", this.$element); // If function was auto-corrected, then originalString holds the original function, // and an informational message needs to be shown if (bezierCurve.originalString) { TimingFunctionUtils.showHideHint(this.hint, true, bezierCurve.originalString, "cubic-bezier(" + this._cubicBezierCoords.join(", ") + ")"); } else { TimingFunctionUtils.showHideHint(this.hint, false); } this.P1 = this.$element.find(".P1")[0]; this.P2 = this.$element.find(".P2")[0]; this.curve = this.$element.find(".curve")[0]; this.P1.bezierEditor = this.P2.bezierEditor = this.curve.bezierEditor = this; this.bezierCanvas = new BezierCanvas(this.curve, null, [0, 0]); // redraw canvas this._updateCanvas(); $(this.curve) .on("click", _curveClick) .on("mousemove", _curveMouseMove); $(this.P1) .on("mousemove", _pointMouseMove) .on("mousedown", _pointMouseDown) .on("mouseup", _pointMouseUp) .on("keydown", _pointKeyDown); $(this.P2) .on("mousemove", _pointMouseMove) .on("mousedown", _pointMouseDown) .on("mouseup", _pointMouseUp) .on("keydown", _pointKeyDown); }
javascript
function BezierCurveEditor($parent, bezierCurve, callback) { // Create the DOM structure, filling in localized strings via Mustache this.$element = $(Mustache.render(BezierCurveEditorTemplate, Strings)); $parent.append(this.$element); this._callback = callback; this.dragElement = null; // current cubic-bezier() function params this._cubicBezierCoords = this._getCubicBezierCoords(bezierCurve); this.hint = {}; this.hint.elem = $(".hint", this.$element); // If function was auto-corrected, then originalString holds the original function, // and an informational message needs to be shown if (bezierCurve.originalString) { TimingFunctionUtils.showHideHint(this.hint, true, bezierCurve.originalString, "cubic-bezier(" + this._cubicBezierCoords.join(", ") + ")"); } else { TimingFunctionUtils.showHideHint(this.hint, false); } this.P1 = this.$element.find(".P1")[0]; this.P2 = this.$element.find(".P2")[0]; this.curve = this.$element.find(".curve")[0]; this.P1.bezierEditor = this.P2.bezierEditor = this.curve.bezierEditor = this; this.bezierCanvas = new BezierCanvas(this.curve, null, [0, 0]); // redraw canvas this._updateCanvas(); $(this.curve) .on("click", _curveClick) .on("mousemove", _curveMouseMove); $(this.P1) .on("mousemove", _pointMouseMove) .on("mousedown", _pointMouseDown) .on("mouseup", _pointMouseUp) .on("keydown", _pointKeyDown); $(this.P2) .on("mousemove", _pointMouseMove) .on("mousedown", _pointMouseDown) .on("mouseup", _pointMouseUp) .on("keydown", _pointKeyDown); }
[ "function", "BezierCurveEditor", "(", "$parent", ",", "bezierCurve", ",", "callback", ")", "{", "// Create the DOM structure, filling in localized strings via Mustache", "this", ".", "$element", "=", "$", "(", "Mustache", ".", "render", "(", "BezierCurveEditorTemplate", ",", "Strings", ")", ")", ";", "$parent", ".", "append", "(", "this", ".", "$element", ")", ";", "this", ".", "_callback", "=", "callback", ";", "this", ".", "dragElement", "=", "null", ";", "// current cubic-bezier() function params", "this", ".", "_cubicBezierCoords", "=", "this", ".", "_getCubicBezierCoords", "(", "bezierCurve", ")", ";", "this", ".", "hint", "=", "{", "}", ";", "this", ".", "hint", ".", "elem", "=", "$", "(", "\".hint\"", ",", "this", ".", "$element", ")", ";", "// If function was auto-corrected, then originalString holds the original function,", "// and an informational message needs to be shown", "if", "(", "bezierCurve", ".", "originalString", ")", "{", "TimingFunctionUtils", ".", "showHideHint", "(", "this", ".", "hint", ",", "true", ",", "bezierCurve", ".", "originalString", ",", "\"cubic-bezier(\"", "+", "this", ".", "_cubicBezierCoords", ".", "join", "(", "\", \"", ")", "+", "\")\"", ")", ";", "}", "else", "{", "TimingFunctionUtils", ".", "showHideHint", "(", "this", ".", "hint", ",", "false", ")", ";", "}", "this", ".", "P1", "=", "this", ".", "$element", ".", "find", "(", "\".P1\"", ")", "[", "0", "]", ";", "this", ".", "P2", "=", "this", ".", "$element", ".", "find", "(", "\".P2\"", ")", "[", "0", "]", ";", "this", ".", "curve", "=", "this", ".", "$element", ".", "find", "(", "\".curve\"", ")", "[", "0", "]", ";", "this", ".", "P1", ".", "bezierEditor", "=", "this", ".", "P2", ".", "bezierEditor", "=", "this", ".", "curve", ".", "bezierEditor", "=", "this", ";", "this", ".", "bezierCanvas", "=", "new", "BezierCanvas", "(", "this", ".", "curve", ",", "null", ",", "[", "0", ",", "0", "]", ")", ";", "// redraw canvas", "this", ".", "_updateCanvas", "(", ")", ";", "$", "(", "this", ".", "curve", ")", ".", "on", "(", "\"click\"", ",", "_curveClick", ")", ".", "on", "(", "\"mousemove\"", ",", "_curveMouseMove", ")", ";", "$", "(", "this", ".", "P1", ")", ".", "on", "(", "\"mousemove\"", ",", "_pointMouseMove", ")", ".", "on", "(", "\"mousedown\"", ",", "_pointMouseDown", ")", ".", "on", "(", "\"mouseup\"", ",", "_pointMouseUp", ")", ".", "on", "(", "\"keydown\"", ",", "_pointKeyDown", ")", ";", "$", "(", "this", ".", "P2", ")", ".", "on", "(", "\"mousemove\"", ",", "_pointMouseMove", ")", ".", "on", "(", "\"mousedown\"", ",", "_pointMouseDown", ")", ".", "on", "(", "\"mouseup\"", ",", "_pointMouseUp", ")", ".", "on", "(", "\"keydown\"", ",", "_pointKeyDown", ")", ";", "}" ]
Constructor for BezierCurveEditor Object. This control may be used standalone or within an InlineTimingFunctionEditor inline widget. @param {!jQuery} $parent DOM node into which to append the root of the bezier curve editor UI @param {!RegExpMatch} bezierCurve RegExp match object of initially selected bezierCurve @param {!function(string)} callback Called whenever selected bezierCurve changes
[ "Constructor", "for", "BezierCurveEditor", "Object", ".", "This", "control", "may", "be", "used", "standalone", "or", "within", "an", "InlineTimingFunctionEditor", "inline", "widget", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/BezierCurveEditor.js#L515-L560
2,416
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/StepEditor.js
StepCanvas
function StepCanvas(canvas, stepParams, padding) { this.canvas = canvas; this.stepParams = stepParams; this.padding = this.getPadding(padding); // Convert to a cartesian coordinate system with axes from 0 to 1 var ctx = this.canvas.getContext("2d"), p = this.padding; ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * (1 - p[0] - p[2])); ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2]))); }
javascript
function StepCanvas(canvas, stepParams, padding) { this.canvas = canvas; this.stepParams = stepParams; this.padding = this.getPadding(padding); // Convert to a cartesian coordinate system with axes from 0 to 1 var ctx = this.canvas.getContext("2d"), p = this.padding; ctx.scale(canvas.width * (1 - p[1] - p[3]), -canvas.height * (1 - p[0] - p[2])); ctx.translate(p[3] / (1 - p[1] - p[3]), (-1 - p[0] / (1 - p[0] - p[2]))); }
[ "function", "StepCanvas", "(", "canvas", ",", "stepParams", ",", "padding", ")", "{", "this", ".", "canvas", "=", "canvas", ";", "this", ".", "stepParams", "=", "stepParams", ";", "this", ".", "padding", "=", "this", ".", "getPadding", "(", "padding", ")", ";", "// Convert to a cartesian coordinate system with axes from 0 to 1", "var", "ctx", "=", "this", ".", "canvas", ".", "getContext", "(", "\"2d\"", ")", ",", "p", "=", "this", ".", "padding", ";", "ctx", ".", "scale", "(", "canvas", ".", "width", "*", "(", "1", "-", "p", "[", "1", "]", "-", "p", "[", "3", "]", ")", ",", "-", "canvas", ".", "height", "*", "(", "1", "-", "p", "[", "0", "]", "-", "p", "[", "2", "]", ")", ")", ";", "ctx", ".", "translate", "(", "p", "[", "3", "]", "/", "(", "1", "-", "p", "[", "1", "]", "-", "p", "[", "3", "]", ")", ",", "(", "-", "1", "-", "p", "[", "0", "]", "/", "(", "1", "-", "p", "[", "0", "]", "-", "p", "[", "2", "]", ")", ")", ")", ";", "}" ]
StepCanvas object constructor @param {Element} canvas Inline editor <canvas> element @param {StepParameters} stepParams Associated StepParameters object @param {number|Array.number} padding Element padding
[ "StepCanvas", "object", "constructor" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/StepEditor.js#L62-L73
2,417
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/StepEditor.js
StepEditor
function StepEditor($parent, stepMatch, callback) { // Create the DOM structure, filling in localized strings via Mustache this.$element = $(Mustache.render(StepEditorTemplate, Strings)); $parent.append(this.$element); this._callback = callback; // current step function params this._stepParams = this._getStepParams(stepMatch); this.hint = {}; this.hint.elem = $(".hint", this.$element); // If function was auto-corrected, then originalString holds the original function, // and an informational message needs to be shown if (stepMatch.originalString) { TimingFunctionUtils.showHideHint(this.hint, true, stepMatch.originalString, "steps(" + this._stepParams.count.toString() + ", " + this._stepParams.timing + ")"); } else { TimingFunctionUtils.showHideHint(this.hint, false); } this.canvas = this.$element.find(".steps")[0]; this.canvas.stepEditor = this; // Padding (3rd param)is scaled, so 0.1 translates to 15px // Note that this is rendered inside canvas CSS "content" // (i.e. this does not map to CSS padding) this.stepCanvas = new StepCanvas(this.canvas, null, [0.1]); // redraw canvas this._updateCanvas(); $(this.canvas).on("keydown", _canvasKeyDown); }
javascript
function StepEditor($parent, stepMatch, callback) { // Create the DOM structure, filling in localized strings via Mustache this.$element = $(Mustache.render(StepEditorTemplate, Strings)); $parent.append(this.$element); this._callback = callback; // current step function params this._stepParams = this._getStepParams(stepMatch); this.hint = {}; this.hint.elem = $(".hint", this.$element); // If function was auto-corrected, then originalString holds the original function, // and an informational message needs to be shown if (stepMatch.originalString) { TimingFunctionUtils.showHideHint(this.hint, true, stepMatch.originalString, "steps(" + this._stepParams.count.toString() + ", " + this._stepParams.timing + ")"); } else { TimingFunctionUtils.showHideHint(this.hint, false); } this.canvas = this.$element.find(".steps")[0]; this.canvas.stepEditor = this; // Padding (3rd param)is scaled, so 0.1 translates to 15px // Note that this is rendered inside canvas CSS "content" // (i.e. this does not map to CSS padding) this.stepCanvas = new StepCanvas(this.canvas, null, [0.1]); // redraw canvas this._updateCanvas(); $(this.canvas).on("keydown", _canvasKeyDown); }
[ "function", "StepEditor", "(", "$parent", ",", "stepMatch", ",", "callback", ")", "{", "// Create the DOM structure, filling in localized strings via Mustache", "this", ".", "$element", "=", "$", "(", "Mustache", ".", "render", "(", "StepEditorTemplate", ",", "Strings", ")", ")", ";", "$parent", ".", "append", "(", "this", ".", "$element", ")", ";", "this", ".", "_callback", "=", "callback", ";", "// current step function params", "this", ".", "_stepParams", "=", "this", ".", "_getStepParams", "(", "stepMatch", ")", ";", "this", ".", "hint", "=", "{", "}", ";", "this", ".", "hint", ".", "elem", "=", "$", "(", "\".hint\"", ",", "this", ".", "$element", ")", ";", "// If function was auto-corrected, then originalString holds the original function,", "// and an informational message needs to be shown", "if", "(", "stepMatch", ".", "originalString", ")", "{", "TimingFunctionUtils", ".", "showHideHint", "(", "this", ".", "hint", ",", "true", ",", "stepMatch", ".", "originalString", ",", "\"steps(\"", "+", "this", ".", "_stepParams", ".", "count", ".", "toString", "(", ")", "+", "\", \"", "+", "this", ".", "_stepParams", ".", "timing", "+", "\")\"", ")", ";", "}", "else", "{", "TimingFunctionUtils", ".", "showHideHint", "(", "this", ".", "hint", ",", "false", ")", ";", "}", "this", ".", "canvas", "=", "this", ".", "$element", ".", "find", "(", "\".steps\"", ")", "[", "0", "]", ";", "this", ".", "canvas", ".", "stepEditor", "=", "this", ";", "// Padding (3rd param)is scaled, so 0.1 translates to 15px", "// Note that this is rendered inside canvas CSS \"content\"", "// (i.e. this does not map to CSS padding)", "this", ".", "stepCanvas", "=", "new", "StepCanvas", "(", "this", ".", "canvas", ",", "null", ",", "[", "0.1", "]", ")", ";", "// redraw canvas", "this", ".", "_updateCanvas", "(", ")", ";", "$", "(", "this", ".", "canvas", ")", ".", "on", "(", "\"keydown\"", ",", "_canvasKeyDown", ")", ";", "}" ]
Constructor for StepEditor Object. This control may be used standalone or within an InlineTimingFunctionEditor inline widget. @param {!jQuery} $parent DOM node into which to append the root of the step editor UI @param {!RegExpMatch} stepMatch RegExp match object of initially selected step function @param {!function(string)} callback Called whenever selected step function changes
[ "Constructor", "for", "StepEditor", "Object", ".", "This", "control", "may", "be", "used", "standalone", "or", "within", "an", "InlineTimingFunctionEditor", "inline", "widget", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/StepEditor.js#L295-L328
2,418
adobe/brackets
src/editor/CodeHintList.js
CodeHintList
function CodeHintList(editor, insertHintOnTab, maxResults) { /** * The list of hints to display * * @type {Array.<string|jQueryObject>} */ this.hints = []; /** * The selected position in the list; otherwise -1. * * @type {number} */ this.selectedIndex = -1; /** * The maximum number of hints to display. Can be overriden via maxCodeHints pref * * @type {number} */ this.maxResults = ValidationUtils.isIntegerInRange(maxResults, 1, 1000) ? maxResults : 50; /** * Is the list currently open? * * @type {boolean} */ this.opened = false; /** * The editor context * * @type {Editor} */ this.editor = editor; /** * Whether the currently selected hint should be inserted on a tab key event * * @type {boolean} */ this.insertHintOnTab = insertHintOnTab; /** * Pending text insertion * * @type {string} */ this.pendingText = ""; /** * The hint selection callback function * * @type {Function} */ this.handleSelect = null; /** * The hint list closure callback function * * @type {Function} */ this.handleClose = null; /** * The hint list menu object * * @type {jQuery.Object} */ this.$hintMenu = $("<li class='dropdown codehint-menu'></li>") .append($("<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>") .hide()) .append("<ul class='dropdown-menu'></ul>"); this._keydownHook = this._keydownHook.bind(this); }
javascript
function CodeHintList(editor, insertHintOnTab, maxResults) { /** * The list of hints to display * * @type {Array.<string|jQueryObject>} */ this.hints = []; /** * The selected position in the list; otherwise -1. * * @type {number} */ this.selectedIndex = -1; /** * The maximum number of hints to display. Can be overriden via maxCodeHints pref * * @type {number} */ this.maxResults = ValidationUtils.isIntegerInRange(maxResults, 1, 1000) ? maxResults : 50; /** * Is the list currently open? * * @type {boolean} */ this.opened = false; /** * The editor context * * @type {Editor} */ this.editor = editor; /** * Whether the currently selected hint should be inserted on a tab key event * * @type {boolean} */ this.insertHintOnTab = insertHintOnTab; /** * Pending text insertion * * @type {string} */ this.pendingText = ""; /** * The hint selection callback function * * @type {Function} */ this.handleSelect = null; /** * The hint list closure callback function * * @type {Function} */ this.handleClose = null; /** * The hint list menu object * * @type {jQuery.Object} */ this.$hintMenu = $("<li class='dropdown codehint-menu'></li>") .append($("<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>") .hide()) .append("<ul class='dropdown-menu'></ul>"); this._keydownHook = this._keydownHook.bind(this); }
[ "function", "CodeHintList", "(", "editor", ",", "insertHintOnTab", ",", "maxResults", ")", "{", "/**\n * The list of hints to display\n *\n * @type {Array.<string|jQueryObject>}\n */", "this", ".", "hints", "=", "[", "]", ";", "/**\n * The selected position in the list; otherwise -1.\n *\n * @type {number}\n */", "this", ".", "selectedIndex", "=", "-", "1", ";", "/**\n * The maximum number of hints to display. Can be overriden via maxCodeHints pref\n *\n * @type {number}\n */", "this", ".", "maxResults", "=", "ValidationUtils", ".", "isIntegerInRange", "(", "maxResults", ",", "1", ",", "1000", ")", "?", "maxResults", ":", "50", ";", "/**\n * Is the list currently open?\n *\n * @type {boolean}\n */", "this", ".", "opened", "=", "false", ";", "/**\n * The editor context\n *\n * @type {Editor}\n */", "this", ".", "editor", "=", "editor", ";", "/**\n * Whether the currently selected hint should be inserted on a tab key event\n *\n * @type {boolean}\n */", "this", ".", "insertHintOnTab", "=", "insertHintOnTab", ";", "/**\n * Pending text insertion\n *\n * @type {string}\n */", "this", ".", "pendingText", "=", "\"\"", ";", "/**\n * The hint selection callback function\n *\n * @type {Function}\n */", "this", ".", "handleSelect", "=", "null", ";", "/**\n * The hint list closure callback function\n *\n * @type {Function}\n */", "this", ".", "handleClose", "=", "null", ";", "/**\n * The hint list menu object\n *\n * @type {jQuery.Object}\n */", "this", ".", "$hintMenu", "=", "$", "(", "\"<li class='dropdown codehint-menu'></li>\"", ")", ".", "append", "(", "$", "(", "\"<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>\"", ")", ".", "hide", "(", ")", ")", ".", "append", "(", "\"<ul class='dropdown-menu'></ul>\"", ")", ";", "this", ".", "_keydownHook", "=", "this", ".", "_keydownHook", ".", "bind", "(", "this", ")", ";", "}" ]
Displays a popup list of hints for a given editor context. @constructor @param {Editor} editor @param {boolean} insertHintOnTab Whether pressing tab inserts the selected hint @param {number} maxResults Maximum hints displayed at once. Defaults to 50
[ "Displays", "a", "popup", "list", "of", "hints", "for", "a", "given", "editor", "context", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintList.js#L47-L124
2,419
adobe/brackets
src/editor/CodeHintList.js
_itemsPerPage
function _itemsPerPage() { var itemsPerPage = 1, $items = self.$hintMenu.find("li"), $view = self.$hintMenu.find("ul.dropdown-menu"), itemHeight; if ($items.length !== 0) { itemHeight = $($items[0]).height(); if (itemHeight) { // round down to integer value itemsPerPage = Math.floor($view.height() / itemHeight); itemsPerPage = Math.max(1, Math.min(itemsPerPage, $items.length)); } } return itemsPerPage; }
javascript
function _itemsPerPage() { var itemsPerPage = 1, $items = self.$hintMenu.find("li"), $view = self.$hintMenu.find("ul.dropdown-menu"), itemHeight; if ($items.length !== 0) { itemHeight = $($items[0]).height(); if (itemHeight) { // round down to integer value itemsPerPage = Math.floor($view.height() / itemHeight); itemsPerPage = Math.max(1, Math.min(itemsPerPage, $items.length)); } } return itemsPerPage; }
[ "function", "_itemsPerPage", "(", ")", "{", "var", "itemsPerPage", "=", "1", ",", "$items", "=", "self", ".", "$hintMenu", ".", "find", "(", "\"li\"", ")", ",", "$view", "=", "self", ".", "$hintMenu", ".", "find", "(", "\"ul.dropdown-menu\"", ")", ",", "itemHeight", ";", "if", "(", "$items", ".", "length", "!==", "0", ")", "{", "itemHeight", "=", "$", "(", "$items", "[", "0", "]", ")", ".", "height", "(", ")", ";", "if", "(", "itemHeight", ")", "{", "// round down to integer value", "itemsPerPage", "=", "Math", ".", "floor", "(", "$view", ".", "height", "(", ")", "/", "itemHeight", ")", ";", "itemsPerPage", "=", "Math", ".", "max", "(", "1", ",", "Math", ".", "min", "(", "itemsPerPage", ",", "$items", ".", "length", ")", ")", ";", "}", "}", "return", "itemsPerPage", ";", "}" ]
Calculate the number of items per scroll page.
[ "Calculate", "the", "number", "of", "items", "per", "scroll", "page", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintList.js#L389-L405
2,420
adobe/brackets
src/language/JSONUtils.js
stripQuotes
function stripQuotes(string) { if (string) { if (/^['"]$/.test(string.charAt(0))) { string = string.substr(1); } if (/^['"]$/.test(string.substr(-1, 1))) { string = string.substr(0, string.length - 1); } } return string; }
javascript
function stripQuotes(string) { if (string) { if (/^['"]$/.test(string.charAt(0))) { string = string.substr(1); } if (/^['"]$/.test(string.substr(-1, 1))) { string = string.substr(0, string.length - 1); } } return string; }
[ "function", "stripQuotes", "(", "string", ")", "{", "if", "(", "string", ")", "{", "if", "(", "/", "^['\"]$", "/", ".", "test", "(", "string", ".", "charAt", "(", "0", ")", ")", ")", "{", "string", "=", "string", ".", "substr", "(", "1", ")", ";", "}", "if", "(", "/", "^['\"]$", "/", ".", "test", "(", "string", ".", "substr", "(", "-", "1", ",", "1", ")", ")", ")", "{", "string", "=", "string", ".", "substr", "(", "0", ",", "string", ".", "length", "-", "1", ")", ";", "}", "}", "return", "string", ";", "}" ]
Removes the quotes around a string @param {!String} string @return {String}
[ "Removes", "the", "quotes", "around", "a", "string" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/JSONUtils.js#L75-L85
2,421
adobe/brackets
src/extensions/default/RecentProjects/main.js
add
function add() { var root = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath), recentProjects = getRecentProjects(), index = recentProjects.indexOf(root); if (index !== -1) { recentProjects.splice(index, 1); } recentProjects.unshift(root); if (recentProjects.length > MAX_PROJECTS) { recentProjects = recentProjects.slice(0, MAX_PROJECTS); } PreferencesManager.setViewState("recentProjects", recentProjects); }
javascript
function add() { var root = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath), recentProjects = getRecentProjects(), index = recentProjects.indexOf(root); if (index !== -1) { recentProjects.splice(index, 1); } recentProjects.unshift(root); if (recentProjects.length > MAX_PROJECTS) { recentProjects = recentProjects.slice(0, MAX_PROJECTS); } PreferencesManager.setViewState("recentProjects", recentProjects); }
[ "function", "add", "(", ")", "{", "var", "root", "=", "FileUtils", ".", "stripTrailingSlash", "(", "ProjectManager", ".", "getProjectRoot", "(", ")", ".", "fullPath", ")", ",", "recentProjects", "=", "getRecentProjects", "(", ")", ",", "index", "=", "recentProjects", ".", "indexOf", "(", "root", ")", ";", "if", "(", "index", "!==", "-", "1", ")", "{", "recentProjects", ".", "splice", "(", "index", ",", "1", ")", ";", "}", "recentProjects", ".", "unshift", "(", "root", ")", ";", "if", "(", "recentProjects", ".", "length", ">", "MAX_PROJECTS", ")", "{", "recentProjects", "=", "recentProjects", ".", "slice", "(", "0", ",", "MAX_PROJECTS", ")", ";", "}", "PreferencesManager", ".", "setViewState", "(", "\"recentProjects\"", ",", "recentProjects", ")", ";", "}" ]
Add a project to the stored list of recent projects, up to MAX_PROJECTS.
[ "Add", "a", "project", "to", "the", "stored", "list", "of", "recent", "projects", "up", "to", "MAX_PROJECTS", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L78-L91
2,422
adobe/brackets
src/extensions/default/RecentProjects/main.js
checkHovers
function checkHovers(pageX, pageY) { $dropdown.children().each(function () { var offset = $(this).offset(), width = $(this).outerWidth(), height = $(this).outerHeight(); if (pageX >= offset.left && pageX <= offset.left + width && pageY >= offset.top && pageY <= offset.top + height) { $(".recent-folder-link", this).triggerHandler("mouseenter"); } }); }
javascript
function checkHovers(pageX, pageY) { $dropdown.children().each(function () { var offset = $(this).offset(), width = $(this).outerWidth(), height = $(this).outerHeight(); if (pageX >= offset.left && pageX <= offset.left + width && pageY >= offset.top && pageY <= offset.top + height) { $(".recent-folder-link", this).triggerHandler("mouseenter"); } }); }
[ "function", "checkHovers", "(", "pageX", ",", "pageY", ")", "{", "$dropdown", ".", "children", "(", ")", ".", "each", "(", "function", "(", ")", "{", "var", "offset", "=", "$", "(", "this", ")", ".", "offset", "(", ")", ",", "width", "=", "$", "(", "this", ")", ".", "outerWidth", "(", ")", ",", "height", "=", "$", "(", "this", ")", ".", "outerHeight", "(", ")", ";", "if", "(", "pageX", ">=", "offset", ".", "left", "&&", "pageX", "<=", "offset", ".", "left", "+", "width", "&&", "pageY", ">=", "offset", ".", "top", "&&", "pageY", "<=", "offset", ".", "top", "+", "height", ")", "{", "$", "(", "\".recent-folder-link\"", ",", "this", ")", ".", "triggerHandler", "(", "\"mouseenter\"", ")", ";", "}", "}", ")", ";", "}" ]
Check the list of items to see if any of them are hovered, and if so trigger a mouseenter. Normally the mouseenter event handles this, but when a previous item is deleted and the next item moves up to be underneath the mouse, we don't get a mouseenter event for that item.
[ "Check", "the", "list", "of", "items", "to", "see", "if", "any", "of", "them", "are", "hovered", "and", "if", "so", "trigger", "a", "mouseenter", ".", "Normally", "the", "mouseenter", "event", "handles", "this", "but", "when", "a", "previous", "item", "is", "deleted", "and", "the", "next", "item", "moves", "up", "to", "be", "underneath", "the", "mouse", "we", "don", "t", "get", "a", "mouseenter", "event", "for", "that", "item", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L98-L109
2,423
adobe/brackets
src/extensions/default/RecentProjects/main.js
renderDelete
function renderDelete() { return $("<div id='recent-folder-delete' class='trash-icon'>&times;</div>") .mouseup(function (e) { // Don't let the click bubble upward. e.stopPropagation(); // Remove the project from the preferences. var recentProjects = getRecentProjects(), index = recentProjects.indexOf($(this).parent().data("path")), newProjects = [], i; for (i = 0; i < recentProjects.length; i++) { if (i !== index) { newProjects.push(recentProjects[i]); } } PreferencesManager.setViewState("recentProjects", newProjects); $(this).closest("li").remove(); checkHovers(e.pageX, e.pageY); if (newProjects.length === 1) { $dropdown.find(".divider").remove(); } }); }
javascript
function renderDelete() { return $("<div id='recent-folder-delete' class='trash-icon'>&times;</div>") .mouseup(function (e) { // Don't let the click bubble upward. e.stopPropagation(); // Remove the project from the preferences. var recentProjects = getRecentProjects(), index = recentProjects.indexOf($(this).parent().data("path")), newProjects = [], i; for (i = 0; i < recentProjects.length; i++) { if (i !== index) { newProjects.push(recentProjects[i]); } } PreferencesManager.setViewState("recentProjects", newProjects); $(this).closest("li").remove(); checkHovers(e.pageX, e.pageY); if (newProjects.length === 1) { $dropdown.find(".divider").remove(); } }); }
[ "function", "renderDelete", "(", ")", "{", "return", "$", "(", "\"<div id='recent-folder-delete' class='trash-icon'>&times;</div>\"", ")", ".", "mouseup", "(", "function", "(", "e", ")", "{", "// Don't let the click bubble upward.", "e", ".", "stopPropagation", "(", ")", ";", "// Remove the project from the preferences.", "var", "recentProjects", "=", "getRecentProjects", "(", ")", ",", "index", "=", "recentProjects", ".", "indexOf", "(", "$", "(", "this", ")", ".", "parent", "(", ")", ".", "data", "(", "\"path\"", ")", ")", ",", "newProjects", "=", "[", "]", ",", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "recentProjects", ".", "length", ";", "i", "++", ")", "{", "if", "(", "i", "!==", "index", ")", "{", "newProjects", ".", "push", "(", "recentProjects", "[", "i", "]", ")", ";", "}", "}", "PreferencesManager", ".", "setViewState", "(", "\"recentProjects\"", ",", "newProjects", ")", ";", "$", "(", "this", ")", ".", "closest", "(", "\"li\"", ")", ".", "remove", "(", ")", ";", "checkHovers", "(", "e", ".", "pageX", ",", "e", ".", "pageY", ")", ";", "if", "(", "newProjects", ".", "length", "===", "1", ")", "{", "$dropdown", ".", "find", "(", "\".divider\"", ")", ".", "remove", "(", ")", ";", "}", "}", ")", ";", "}" ]
Create the "delete" button that shows up when you hover over a project.
[ "Create", "the", "delete", "button", "that", "shows", "up", "when", "you", "hover", "over", "a", "project", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L114-L138
2,424
adobe/brackets
src/extensions/default/RecentProjects/main.js
selectNextItem
function selectNextItem(direction) { var $links = $dropdown.find("a"), index = $dropdownItem ? $links.index($dropdownItem) : (direction > 0 ? -1 : 0), $newItem = $links.eq((index + direction) % $links.length); if ($dropdownItem) { $dropdownItem.removeClass("selected"); } $newItem.addClass("selected"); $dropdownItem = $newItem; removeDeleteButton(); }
javascript
function selectNextItem(direction) { var $links = $dropdown.find("a"), index = $dropdownItem ? $links.index($dropdownItem) : (direction > 0 ? -1 : 0), $newItem = $links.eq((index + direction) % $links.length); if ($dropdownItem) { $dropdownItem.removeClass("selected"); } $newItem.addClass("selected"); $dropdownItem = $newItem; removeDeleteButton(); }
[ "function", "selectNextItem", "(", "direction", ")", "{", "var", "$links", "=", "$dropdown", ".", "find", "(", "\"a\"", ")", ",", "index", "=", "$dropdownItem", "?", "$links", ".", "index", "(", "$dropdownItem", ")", ":", "(", "direction", ">", "0", "?", "-", "1", ":", "0", ")", ",", "$newItem", "=", "$links", ".", "eq", "(", "(", "index", "+", "direction", ")", "%", "$links", ".", "length", ")", ";", "if", "(", "$dropdownItem", ")", "{", "$dropdownItem", ".", "removeClass", "(", "\"selected\"", ")", ";", "}", "$newItem", ".", "addClass", "(", "\"selected\"", ")", ";", "$dropdownItem", "=", "$newItem", ";", "removeDeleteButton", "(", ")", ";", "}" ]
Selects the next or previous item in the list @param {number} direction +1 for next, -1 for prev
[ "Selects", "the", "next", "or", "previous", "item", "in", "the", "list" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L162-L174
2,425
adobe/brackets
src/extensions/default/RecentProjects/main.js
removeSelectedItem
function removeSelectedItem(e) { var recentProjects = getRecentProjects(), $cacheItem = $dropdownItem, index = recentProjects.indexOf($cacheItem.data("path")); // When focus is not on project item if (index === -1) { return false; } // remove project recentProjects.splice(index, 1); PreferencesManager.setViewState("recentProjects", recentProjects); checkHovers(e.pageX, e.pageY); if (recentProjects.length === 1) { $dropdown.find(".divider").remove(); } selectNextItem(+1); $cacheItem.closest("li").remove(); return true; }
javascript
function removeSelectedItem(e) { var recentProjects = getRecentProjects(), $cacheItem = $dropdownItem, index = recentProjects.indexOf($cacheItem.data("path")); // When focus is not on project item if (index === -1) { return false; } // remove project recentProjects.splice(index, 1); PreferencesManager.setViewState("recentProjects", recentProjects); checkHovers(e.pageX, e.pageY); if (recentProjects.length === 1) { $dropdown.find(".divider").remove(); } selectNextItem(+1); $cacheItem.closest("li").remove(); return true; }
[ "function", "removeSelectedItem", "(", "e", ")", "{", "var", "recentProjects", "=", "getRecentProjects", "(", ")", ",", "$cacheItem", "=", "$dropdownItem", ",", "index", "=", "recentProjects", ".", "indexOf", "(", "$cacheItem", ".", "data", "(", "\"path\"", ")", ")", ";", "// When focus is not on project item", "if", "(", "index", "===", "-", "1", ")", "{", "return", "false", ";", "}", "// remove project", "recentProjects", ".", "splice", "(", "index", ",", "1", ")", ";", "PreferencesManager", ".", "setViewState", "(", "\"recentProjects\"", ",", "recentProjects", ")", ";", "checkHovers", "(", "e", ".", "pageX", ",", "e", ".", "pageY", ")", ";", "if", "(", "recentProjects", ".", "length", "===", "1", ")", "{", "$dropdown", ".", "find", "(", "\".divider\"", ")", ".", "remove", "(", ")", ";", "}", "selectNextItem", "(", "+", "1", ")", ";", "$cacheItem", ".", "closest", "(", "\"li\"", ")", ".", "remove", "(", ")", ";", "return", "true", ";", "}" ]
Deletes the selected item and move the focus to next item in list. @return {boolean} TRUE if project is removed
[ "Deletes", "the", "selected", "item", "and", "move", "the", "focus", "to", "next", "item", "in", "list", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L182-L203
2,426
adobe/brackets
src/extensions/default/RecentProjects/main.js
keydownHook
function keydownHook(event) { var keyHandled = false; switch (event.keyCode) { case KeyEvent.DOM_VK_UP: selectNextItem(-1); keyHandled = true; break; case KeyEvent.DOM_VK_DOWN: selectNextItem(+1); keyHandled = true; break; case KeyEvent.DOM_VK_ENTER: case KeyEvent.DOM_VK_RETURN: if ($dropdownItem) { $dropdownItem.trigger("click"); } keyHandled = true; break; case KeyEvent.DOM_VK_BACK_SPACE: case KeyEvent.DOM_VK_DELETE: if ($dropdownItem) { removeSelectedItem(event); keyHandled = true; } break; } if (keyHandled) { event.stopImmediatePropagation(); event.preventDefault(); } return keyHandled; }
javascript
function keydownHook(event) { var keyHandled = false; switch (event.keyCode) { case KeyEvent.DOM_VK_UP: selectNextItem(-1); keyHandled = true; break; case KeyEvent.DOM_VK_DOWN: selectNextItem(+1); keyHandled = true; break; case KeyEvent.DOM_VK_ENTER: case KeyEvent.DOM_VK_RETURN: if ($dropdownItem) { $dropdownItem.trigger("click"); } keyHandled = true; break; case KeyEvent.DOM_VK_BACK_SPACE: case KeyEvent.DOM_VK_DELETE: if ($dropdownItem) { removeSelectedItem(event); keyHandled = true; } break; } if (keyHandled) { event.stopImmediatePropagation(); event.preventDefault(); } return keyHandled; }
[ "function", "keydownHook", "(", "event", ")", "{", "var", "keyHandled", "=", "false", ";", "switch", "(", "event", ".", "keyCode", ")", "{", "case", "KeyEvent", ".", "DOM_VK_UP", ":", "selectNextItem", "(", "-", "1", ")", ";", "keyHandled", "=", "true", ";", "break", ";", "case", "KeyEvent", ".", "DOM_VK_DOWN", ":", "selectNextItem", "(", "+", "1", ")", ";", "keyHandled", "=", "true", ";", "break", ";", "case", "KeyEvent", ".", "DOM_VK_ENTER", ":", "case", "KeyEvent", ".", "DOM_VK_RETURN", ":", "if", "(", "$dropdownItem", ")", "{", "$dropdownItem", ".", "trigger", "(", "\"click\"", ")", ";", "}", "keyHandled", "=", "true", ";", "break", ";", "case", "KeyEvent", ".", "DOM_VK_BACK_SPACE", ":", "case", "KeyEvent", ".", "DOM_VK_DELETE", ":", "if", "(", "$dropdownItem", ")", "{", "removeSelectedItem", "(", "event", ")", ";", "keyHandled", "=", "true", ";", "}", "break", ";", "}", "if", "(", "keyHandled", ")", "{", "event", ".", "stopImmediatePropagation", "(", ")", ";", "event", ".", "preventDefault", "(", ")", ";", "}", "return", "keyHandled", ";", "}" ]
Handles the Key Down events @param {KeyboardEvent} event @return {boolean} True if the key was handled
[ "Handles", "the", "Key", "Down", "events" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L210-L243
2,427
adobe/brackets
src/extensions/default/RecentProjects/main.js
cleanupDropdown
function cleanupDropdown() { $("html").off("click", closeDropdown); $("#project-files-container").off("scroll", closeDropdown); $("#titlebar .nav").off("click", closeDropdown); $dropdown = null; MainViewManager.focusActivePane(); $(window).off("keydown", keydownHook); }
javascript
function cleanupDropdown() { $("html").off("click", closeDropdown); $("#project-files-container").off("scroll", closeDropdown); $("#titlebar .nav").off("click", closeDropdown); $dropdown = null; MainViewManager.focusActivePane(); $(window).off("keydown", keydownHook); }
[ "function", "cleanupDropdown", "(", ")", "{", "$", "(", "\"html\"", ")", ".", "off", "(", "\"click\"", ",", "closeDropdown", ")", ";", "$", "(", "\"#project-files-container\"", ")", ".", "off", "(", "\"scroll\"", ",", "closeDropdown", ")", ";", "$", "(", "\"#titlebar .nav\"", ")", ".", "off", "(", "\"click\"", ",", "closeDropdown", ")", ";", "$dropdown", "=", "null", ";", "MainViewManager", ".", "focusActivePane", "(", ")", ";", "$", "(", "window", ")", ".", "off", "(", "\"keydown\"", ",", "keydownHook", ")", ";", "}" ]
Remove the various event handlers that close the dropdown. This is called by the PopUpManager when the dropdown is closed.
[ "Remove", "the", "various", "event", "handlers", "that", "close", "the", "dropdown", ".", "This", "is", "called", "by", "the", "PopUpManager", "when", "the", "dropdown", "is", "closed", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L262-L271
2,428
adobe/brackets
src/extensions/default/RecentProjects/main.js
parsePath
function parsePath(path) { var lastSlash = path.lastIndexOf("/"), folder, rest; if (lastSlash === path.length - 1) { lastSlash = path.slice(0, path.length - 1).lastIndexOf("/"); } if (lastSlash >= 0) { rest = " - " + (lastSlash ? path.slice(0, lastSlash) : "/"); folder = path.slice(lastSlash + 1); } else { rest = "/"; folder = path; } return {path: path, folder: folder, rest: rest}; }
javascript
function parsePath(path) { var lastSlash = path.lastIndexOf("/"), folder, rest; if (lastSlash === path.length - 1) { lastSlash = path.slice(0, path.length - 1).lastIndexOf("/"); } if (lastSlash >= 0) { rest = " - " + (lastSlash ? path.slice(0, lastSlash) : "/"); folder = path.slice(lastSlash + 1); } else { rest = "/"; folder = path; } return {path: path, folder: folder, rest: rest}; }
[ "function", "parsePath", "(", "path", ")", "{", "var", "lastSlash", "=", "path", ".", "lastIndexOf", "(", "\"/\"", ")", ",", "folder", ",", "rest", ";", "if", "(", "lastSlash", "===", "path", ".", "length", "-", "1", ")", "{", "lastSlash", "=", "path", ".", "slice", "(", "0", ",", "path", ".", "length", "-", "1", ")", ".", "lastIndexOf", "(", "\"/\"", ")", ";", "}", "if", "(", "lastSlash", ">=", "0", ")", "{", "rest", "=", "\" - \"", "+", "(", "lastSlash", "?", "path", ".", "slice", "(", "0", ",", "lastSlash", ")", ":", "\"/\"", ")", ";", "folder", "=", "path", ".", "slice", "(", "lastSlash", "+", "1", ")", ";", "}", "else", "{", "rest", "=", "\"/\"", ";", "folder", "=", "path", ";", "}", "return", "{", "path", ":", "path", ",", "folder", ":", "folder", ",", "rest", ":", "rest", "}", ";", "}" ]
Parses the path and returns an object with the full path, the folder name and the path without the folder. @param {string} path The full path to the folder. @return {{path: string, folder: string, rest: string}}
[ "Parses", "the", "path", "and", "returns", "an", "object", "with", "the", "full", "path", "the", "folder", "name", "and", "the", "path", "without", "the", "folder", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L334-L348
2,429
adobe/brackets
src/extensions/default/RecentProjects/main.js
renderList
function renderList() { var recentProjects = getRecentProjects(), currentProject = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath), templateVars = { projectList : [], Strings : Strings }; recentProjects.forEach(function (root) { if (root !== currentProject) { templateVars.projectList.push(parsePath(root)); } }); return Mustache.render(ProjectsMenuTemplate, templateVars); }
javascript
function renderList() { var recentProjects = getRecentProjects(), currentProject = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath), templateVars = { projectList : [], Strings : Strings }; recentProjects.forEach(function (root) { if (root !== currentProject) { templateVars.projectList.push(parsePath(root)); } }); return Mustache.render(ProjectsMenuTemplate, templateVars); }
[ "function", "renderList", "(", ")", "{", "var", "recentProjects", "=", "getRecentProjects", "(", ")", ",", "currentProject", "=", "FileUtils", ".", "stripTrailingSlash", "(", "ProjectManager", ".", "getProjectRoot", "(", ")", ".", "fullPath", ")", ",", "templateVars", "=", "{", "projectList", ":", "[", "]", ",", "Strings", ":", "Strings", "}", ";", "recentProjects", ".", "forEach", "(", "function", "(", "root", ")", "{", "if", "(", "root", "!==", "currentProject", ")", "{", "templateVars", ".", "projectList", ".", "push", "(", "parsePath", "(", "root", ")", ")", ";", "}", "}", ")", ";", "return", "Mustache", ".", "render", "(", "ProjectsMenuTemplate", ",", "templateVars", ")", ";", "}" ]
Create the list of projects in the dropdown menu. @return {string} The html content
[ "Create", "the", "list", "of", "projects", "in", "the", "dropdown", "menu", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L354-L369
2,430
adobe/brackets
src/extensions/default/RecentProjects/main.js
showDropdown
function showDropdown(position) { // If the dropdown is already visible, just return (so the root click handler on html // will close it). if ($dropdown) { return; } Menus.closeAll(); $dropdown = $(renderList()) .css({ left: position.pageX, top: position.pageY }) .appendTo($("body")); PopUpManager.addPopUp($dropdown, cleanupDropdown, true); // TODO: should use capture, otherwise clicking on the menus doesn't close it. More fallout // from the fact that we can't use the Boostrap (1.4) dropdowns. $("html").on("click", closeDropdown); // Hide the menu if the user scrolls in the project tree. Otherwise the Lion scrollbar // overlaps it. // TODO: This duplicates logic that's already in ProjectManager (which calls Menus.close()). // We should fix this when the popup handling is centralized in PopupManager, as well // as making Esc close the dropdown. See issue #1381. $("#project-files-container").on("scroll", closeDropdown); // Note: PopUpManager will automatically hide the sidebar in other cases, such as when a // command is run, Esc is pressed, or the menu is focused. // Hacky: if we detect a click in the menubar, close ourselves. // TODO: again, we should have centralized popup management. $("#titlebar .nav").on("click", closeDropdown); _handleListEvents(); $(window).on("keydown", keydownHook); }
javascript
function showDropdown(position) { // If the dropdown is already visible, just return (so the root click handler on html // will close it). if ($dropdown) { return; } Menus.closeAll(); $dropdown = $(renderList()) .css({ left: position.pageX, top: position.pageY }) .appendTo($("body")); PopUpManager.addPopUp($dropdown, cleanupDropdown, true); // TODO: should use capture, otherwise clicking on the menus doesn't close it. More fallout // from the fact that we can't use the Boostrap (1.4) dropdowns. $("html").on("click", closeDropdown); // Hide the menu if the user scrolls in the project tree. Otherwise the Lion scrollbar // overlaps it. // TODO: This duplicates logic that's already in ProjectManager (which calls Menus.close()). // We should fix this when the popup handling is centralized in PopupManager, as well // as making Esc close the dropdown. See issue #1381. $("#project-files-container").on("scroll", closeDropdown); // Note: PopUpManager will automatically hide the sidebar in other cases, such as when a // command is run, Esc is pressed, or the menu is focused. // Hacky: if we detect a click in the menubar, close ourselves. // TODO: again, we should have centralized popup management. $("#titlebar .nav").on("click", closeDropdown); _handleListEvents(); $(window).on("keydown", keydownHook); }
[ "function", "showDropdown", "(", "position", ")", "{", "// If the dropdown is already visible, just return (so the root click handler on html", "// will close it).", "if", "(", "$dropdown", ")", "{", "return", ";", "}", "Menus", ".", "closeAll", "(", ")", ";", "$dropdown", "=", "$", "(", "renderList", "(", ")", ")", ".", "css", "(", "{", "left", ":", "position", ".", "pageX", ",", "top", ":", "position", ".", "pageY", "}", ")", ".", "appendTo", "(", "$", "(", "\"body\"", ")", ")", ";", "PopUpManager", ".", "addPopUp", "(", "$dropdown", ",", "cleanupDropdown", ",", "true", ")", ";", "// TODO: should use capture, otherwise clicking on the menus doesn't close it. More fallout", "// from the fact that we can't use the Boostrap (1.4) dropdowns.", "$", "(", "\"html\"", ")", ".", "on", "(", "\"click\"", ",", "closeDropdown", ")", ";", "// Hide the menu if the user scrolls in the project tree. Otherwise the Lion scrollbar", "// overlaps it.", "// TODO: This duplicates logic that's already in ProjectManager (which calls Menus.close()).", "// We should fix this when the popup handling is centralized in PopupManager, as well", "// as making Esc close the dropdown. See issue #1381.", "$", "(", "\"#project-files-container\"", ")", ".", "on", "(", "\"scroll\"", ",", "closeDropdown", ")", ";", "// Note: PopUpManager will automatically hide the sidebar in other cases, such as when a", "// command is run, Esc is pressed, or the menu is focused.", "// Hacky: if we detect a click in the menubar, close ourselves.", "// TODO: again, we should have centralized popup management.", "$", "(", "\"#titlebar .nav\"", ")", ".", "on", "(", "\"click\"", ",", "closeDropdown", ")", ";", "_handleListEvents", "(", ")", ";", "$", "(", "window", ")", ".", "on", "(", "\"keydown\"", ",", "keydownHook", ")", ";", "}" ]
Show or hide the recent projects dropdown. @param {{pageX:number, pageY:number}} position - the absolute position where to open the dropdown
[ "Show", "or", "hide", "the", "recent", "projects", "dropdown", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L376-L414
2,431
adobe/brackets
src/extensions/default/RecentProjects/main.js
handleKeyEvent
function handleKeyEvent() { if (!$dropdown) { if (!SidebarView.isVisible()) { SidebarView.show(); } $("#project-dropdown-toggle").trigger("click"); $dropdown.focus(); $links = $dropdown.find("a"); // By default, select the most recent project (which is at the top of the list underneath Open Folder), // but if there are none, select Open Folder instead. $dropdownItem = $links.eq($links.length > 1 ? 1 : 0); $dropdownItem.addClass("selected"); // If focusing the dropdown caused a modal bar to close, we need to refocus the dropdown window.setTimeout(function () { $dropdown.focus(); }, 0); } }
javascript
function handleKeyEvent() { if (!$dropdown) { if (!SidebarView.isVisible()) { SidebarView.show(); } $("#project-dropdown-toggle").trigger("click"); $dropdown.focus(); $links = $dropdown.find("a"); // By default, select the most recent project (which is at the top of the list underneath Open Folder), // but if there are none, select Open Folder instead. $dropdownItem = $links.eq($links.length > 1 ? 1 : 0); $dropdownItem.addClass("selected"); // If focusing the dropdown caused a modal bar to close, we need to refocus the dropdown window.setTimeout(function () { $dropdown.focus(); }, 0); } }
[ "function", "handleKeyEvent", "(", ")", "{", "if", "(", "!", "$dropdown", ")", "{", "if", "(", "!", "SidebarView", ".", "isVisible", "(", ")", ")", "{", "SidebarView", ".", "show", "(", ")", ";", "}", "$", "(", "\"#project-dropdown-toggle\"", ")", ".", "trigger", "(", "\"click\"", ")", ";", "$dropdown", ".", "focus", "(", ")", ";", "$links", "=", "$dropdown", ".", "find", "(", "\"a\"", ")", ";", "// By default, select the most recent project (which is at the top of the list underneath Open Folder),", "// but if there are none, select Open Folder instead.", "$dropdownItem", "=", "$links", ".", "eq", "(", "$links", ".", "length", ">", "1", "?", "1", ":", "0", ")", ";", "$dropdownItem", ".", "addClass", "(", "\"selected\"", ")", ";", "// If focusing the dropdown caused a modal bar to close, we need to refocus the dropdown", "window", ".", "setTimeout", "(", "function", "(", ")", "{", "$dropdown", ".", "focus", "(", ")", ";", "}", ",", "0", ")", ";", "}", "}" ]
Show or hide the recent projects dropdown from the toogle command.
[ "Show", "or", "hide", "the", "recent", "projects", "dropdown", "from", "the", "toogle", "command", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L420-L440
2,432
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_validateFrame
function _validateFrame(entry) { var deferred = new $.Deferred(), fileEntry = FileSystem.getFileForPath(entry.filePath); if (entry.inMem) { var indexInWS = MainViewManager.findInWorkingSet(entry.paneId, entry.filePath); // Remove entry if InMemoryFile is not found in Working set if (indexInWS === -1) { deferred.reject(); } else { deferred.resolve(); } } else { fileEntry.exists(function (err, exists) { if (!err && exists) { // Additional check to handle external modification and mutation of the doc text affecting markers if (fileEntry._hash !== entry._hash) { deferred.reject(); } else if (!entry._validateMarkers()) { deferred.reject(); } else { deferred.resolve(); } } else { deferred.reject(); } }); } return deferred.promise(); }
javascript
function _validateFrame(entry) { var deferred = new $.Deferred(), fileEntry = FileSystem.getFileForPath(entry.filePath); if (entry.inMem) { var indexInWS = MainViewManager.findInWorkingSet(entry.paneId, entry.filePath); // Remove entry if InMemoryFile is not found in Working set if (indexInWS === -1) { deferred.reject(); } else { deferred.resolve(); } } else { fileEntry.exists(function (err, exists) { if (!err && exists) { // Additional check to handle external modification and mutation of the doc text affecting markers if (fileEntry._hash !== entry._hash) { deferred.reject(); } else if (!entry._validateMarkers()) { deferred.reject(); } else { deferred.resolve(); } } else { deferred.reject(); } }); } return deferred.promise(); }
[ "function", "_validateFrame", "(", "entry", ")", "{", "var", "deferred", "=", "new", "$", ".", "Deferred", "(", ")", ",", "fileEntry", "=", "FileSystem", ".", "getFileForPath", "(", "entry", ".", "filePath", ")", ";", "if", "(", "entry", ".", "inMem", ")", "{", "var", "indexInWS", "=", "MainViewManager", ".", "findInWorkingSet", "(", "entry", ".", "paneId", ",", "entry", ".", "filePath", ")", ";", "// Remove entry if InMemoryFile is not found in Working set", "if", "(", "indexInWS", "===", "-", "1", ")", "{", "deferred", ".", "reject", "(", ")", ";", "}", "else", "{", "deferred", ".", "resolve", "(", ")", ";", "}", "}", "else", "{", "fileEntry", ".", "exists", "(", "function", "(", "err", ",", "exists", ")", "{", "if", "(", "!", "err", "&&", "exists", ")", "{", "// Additional check to handle external modification and mutation of the doc text affecting markers", "if", "(", "fileEntry", ".", "_hash", "!==", "entry", ".", "_hash", ")", "{", "deferred", ".", "reject", "(", ")", ";", "}", "else", "if", "(", "!", "entry", ".", "_validateMarkers", "(", ")", ")", "{", "deferred", ".", "reject", "(", ")", ";", "}", "else", "{", "deferred", ".", "resolve", "(", ")", ";", "}", "}", "else", "{", "deferred", ".", "reject", "(", ")", ";", "}", "}", ")", ";", "}", "return", "deferred", ".", "promise", "(", ")", ";", "}" ]
Function to check existence of a file entry, validity of markers @private
[ "Function", "to", "check", "existence", "of", "a", "file", "entry", "validity", "of", "markers" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L98-L128
2,433
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_navigateBack
function _navigateBack() { if (!jumpForwardStack.length) { if (activePosNotSynced) { currentEditPos = new NavigationFrame(EditorManager.getCurrentFullEditor(), {ranges: EditorManager.getCurrentFullEditor()._codeMirror.listSelections()}); jumpForwardStack.push(currentEditPos); } } var navFrame = jumpBackwardStack.pop(); // Check if the poped frame is the current active frame or doesn't have any valid marker information // if true, jump again if (navFrame && navFrame === currentEditPos) { jumpForwardStack.push(navFrame); _validateNavigationCmds(); CommandManager.execute(NAVIGATION_JUMP_BACK); return; } if (navFrame) { // We will check for the file existence now, if it doesn't exist we will jump back again // but discard the popped frame as invalid. _validateFrame(navFrame).done(function () { jumpForwardStack.push(navFrame); navFrame.goTo(); currentEditPos = navFrame; }).fail(function () { CommandManager.execute(NAVIGATION_JUMP_BACK); }).always(function () { _validateNavigationCmds(); }); } }
javascript
function _navigateBack() { if (!jumpForwardStack.length) { if (activePosNotSynced) { currentEditPos = new NavigationFrame(EditorManager.getCurrentFullEditor(), {ranges: EditorManager.getCurrentFullEditor()._codeMirror.listSelections()}); jumpForwardStack.push(currentEditPos); } } var navFrame = jumpBackwardStack.pop(); // Check if the poped frame is the current active frame or doesn't have any valid marker information // if true, jump again if (navFrame && navFrame === currentEditPos) { jumpForwardStack.push(navFrame); _validateNavigationCmds(); CommandManager.execute(NAVIGATION_JUMP_BACK); return; } if (navFrame) { // We will check for the file existence now, if it doesn't exist we will jump back again // but discard the popped frame as invalid. _validateFrame(navFrame).done(function () { jumpForwardStack.push(navFrame); navFrame.goTo(); currentEditPos = navFrame; }).fail(function () { CommandManager.execute(NAVIGATION_JUMP_BACK); }).always(function () { _validateNavigationCmds(); }); } }
[ "function", "_navigateBack", "(", ")", "{", "if", "(", "!", "jumpForwardStack", ".", "length", ")", "{", "if", "(", "activePosNotSynced", ")", "{", "currentEditPos", "=", "new", "NavigationFrame", "(", "EditorManager", ".", "getCurrentFullEditor", "(", ")", ",", "{", "ranges", ":", "EditorManager", ".", "getCurrentFullEditor", "(", ")", ".", "_codeMirror", ".", "listSelections", "(", ")", "}", ")", ";", "jumpForwardStack", ".", "push", "(", "currentEditPos", ")", ";", "}", "}", "var", "navFrame", "=", "jumpBackwardStack", ".", "pop", "(", ")", ";", "// Check if the poped frame is the current active frame or doesn't have any valid marker information", "// if true, jump again", "if", "(", "navFrame", "&&", "navFrame", "===", "currentEditPos", ")", "{", "jumpForwardStack", ".", "push", "(", "navFrame", ")", ";", "_validateNavigationCmds", "(", ")", ";", "CommandManager", ".", "execute", "(", "NAVIGATION_JUMP_BACK", ")", ";", "return", ";", "}", "if", "(", "navFrame", ")", "{", "// We will check for the file existence now, if it doesn't exist we will jump back again", "// but discard the popped frame as invalid.", "_validateFrame", "(", "navFrame", ")", ".", "done", "(", "function", "(", ")", "{", "jumpForwardStack", ".", "push", "(", "navFrame", ")", ";", "navFrame", ".", "goTo", "(", ")", ";", "currentEditPos", "=", "navFrame", ";", "}", ")", ".", "fail", "(", "function", "(", ")", "{", "CommandManager", ".", "execute", "(", "NAVIGATION_JUMP_BACK", ")", ";", "}", ")", ".", "always", "(", "function", "(", ")", "{", "_validateNavigationCmds", "(", ")", ";", "}", ")", ";", "}", "}" ]
Command handler to navigate backward
[ "Command", "handler", "to", "navigate", "backward" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L339-L371
2,434
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_navigateForward
function _navigateForward() { var navFrame = jumpForwardStack.pop(); if (!navFrame) { return; } // Check if the poped frame is the current active frame or doesn't have any valid marker information // if true, jump again if (navFrame === currentEditPos) { jumpBackwardStack.push(navFrame); _validateNavigationCmds(); CommandManager.execute(NAVIGATION_JUMP_FWD); return; } // We will check for the file existence now, if it doesn't exist we will jump back again // but discard the popped frame as invalid. _validateFrame(navFrame).done(function () { jumpBackwardStack.push(navFrame); navFrame.goTo(); currentEditPos = navFrame; }).fail(function () { _validateNavigationCmds(); CommandManager.execute(NAVIGATION_JUMP_FWD); }).always(function () { _validateNavigationCmds(); }); }
javascript
function _navigateForward() { var navFrame = jumpForwardStack.pop(); if (!navFrame) { return; } // Check if the poped frame is the current active frame or doesn't have any valid marker information // if true, jump again if (navFrame === currentEditPos) { jumpBackwardStack.push(navFrame); _validateNavigationCmds(); CommandManager.execute(NAVIGATION_JUMP_FWD); return; } // We will check for the file existence now, if it doesn't exist we will jump back again // but discard the popped frame as invalid. _validateFrame(navFrame).done(function () { jumpBackwardStack.push(navFrame); navFrame.goTo(); currentEditPos = navFrame; }).fail(function () { _validateNavigationCmds(); CommandManager.execute(NAVIGATION_JUMP_FWD); }).always(function () { _validateNavigationCmds(); }); }
[ "function", "_navigateForward", "(", ")", "{", "var", "navFrame", "=", "jumpForwardStack", ".", "pop", "(", ")", ";", "if", "(", "!", "navFrame", ")", "{", "return", ";", "}", "// Check if the poped frame is the current active frame or doesn't have any valid marker information", "// if true, jump again", "if", "(", "navFrame", "===", "currentEditPos", ")", "{", "jumpBackwardStack", ".", "push", "(", "navFrame", ")", ";", "_validateNavigationCmds", "(", ")", ";", "CommandManager", ".", "execute", "(", "NAVIGATION_JUMP_FWD", ")", ";", "return", ";", "}", "// We will check for the file existence now, if it doesn't exist we will jump back again", "// but discard the popped frame as invalid.", "_validateFrame", "(", "navFrame", ")", ".", "done", "(", "function", "(", ")", "{", "jumpBackwardStack", ".", "push", "(", "navFrame", ")", ";", "navFrame", ".", "goTo", "(", ")", ";", "currentEditPos", "=", "navFrame", ";", "}", ")", ".", "fail", "(", "function", "(", ")", "{", "_validateNavigationCmds", "(", ")", ";", "CommandManager", ".", "execute", "(", "NAVIGATION_JUMP_FWD", ")", ";", "}", ")", ".", "always", "(", "function", "(", ")", "{", "_validateNavigationCmds", "(", ")", ";", "}", ")", ";", "}" ]
Command handler to navigate forward
[ "Command", "handler", "to", "navigate", "forward" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L376-L405
2,435
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_initNavigationMenuItems
function _initNavigationMenuItems() { var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU); menu.addMenuItem(NAVIGATION_JUMP_BACK, "", Menus.AFTER, Commands.NAVIGATE_PREV_DOC); menu.addMenuItem(NAVIGATION_JUMP_FWD, "", Menus.AFTER, NAVIGATION_JUMP_BACK); }
javascript
function _initNavigationMenuItems() { var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU); menu.addMenuItem(NAVIGATION_JUMP_BACK, "", Menus.AFTER, Commands.NAVIGATE_PREV_DOC); menu.addMenuItem(NAVIGATION_JUMP_FWD, "", Menus.AFTER, NAVIGATION_JUMP_BACK); }
[ "function", "_initNavigationMenuItems", "(", ")", "{", "var", "menu", "=", "Menus", ".", "getMenu", "(", "Menus", ".", "AppMenuBar", ".", "NAVIGATE_MENU", ")", ";", "menu", ".", "addMenuItem", "(", "NAVIGATION_JUMP_BACK", ",", "\"\"", ",", "Menus", ".", "AFTER", ",", "Commands", ".", "NAVIGATE_PREV_DOC", ")", ";", "menu", ".", "addMenuItem", "(", "NAVIGATION_JUMP_FWD", ",", "\"\"", ",", "Menus", ".", "AFTER", ",", "NAVIGATION_JUMP_BACK", ")", ";", "}" ]
Function to initialize navigation menu items. @private
[ "Function", "to", "initialize", "navigation", "menu", "items", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L411-L415
2,436
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_initNavigationCommands
function _initNavigationCommands() { CommandManager.register(Strings.CMD_NAVIGATE_BACKWARD, NAVIGATION_JUMP_BACK, _navigateBack); CommandManager.register(Strings.CMD_NAVIGATE_FORWARD, NAVIGATION_JUMP_FWD, _navigateForward); commandJumpBack = CommandManager.get(NAVIGATION_JUMP_BACK); commandJumpFwd = CommandManager.get(NAVIGATION_JUMP_FWD); commandJumpBack.setEnabled(false); commandJumpFwd.setEnabled(false); KeyBindingManager.addBinding(NAVIGATION_JUMP_BACK, KeyboardPrefs[NAVIGATION_JUMP_BACK]); KeyBindingManager.addBinding(NAVIGATION_JUMP_FWD, KeyboardPrefs[NAVIGATION_JUMP_FWD]); _initNavigationMenuItems(); }
javascript
function _initNavigationCommands() { CommandManager.register(Strings.CMD_NAVIGATE_BACKWARD, NAVIGATION_JUMP_BACK, _navigateBack); CommandManager.register(Strings.CMD_NAVIGATE_FORWARD, NAVIGATION_JUMP_FWD, _navigateForward); commandJumpBack = CommandManager.get(NAVIGATION_JUMP_BACK); commandJumpFwd = CommandManager.get(NAVIGATION_JUMP_FWD); commandJumpBack.setEnabled(false); commandJumpFwd.setEnabled(false); KeyBindingManager.addBinding(NAVIGATION_JUMP_BACK, KeyboardPrefs[NAVIGATION_JUMP_BACK]); KeyBindingManager.addBinding(NAVIGATION_JUMP_FWD, KeyboardPrefs[NAVIGATION_JUMP_FWD]); _initNavigationMenuItems(); }
[ "function", "_initNavigationCommands", "(", ")", "{", "CommandManager", ".", "register", "(", "Strings", ".", "CMD_NAVIGATE_BACKWARD", ",", "NAVIGATION_JUMP_BACK", ",", "_navigateBack", ")", ";", "CommandManager", ".", "register", "(", "Strings", ".", "CMD_NAVIGATE_FORWARD", ",", "NAVIGATION_JUMP_FWD", ",", "_navigateForward", ")", ";", "commandJumpBack", "=", "CommandManager", ".", "get", "(", "NAVIGATION_JUMP_BACK", ")", ";", "commandJumpFwd", "=", "CommandManager", ".", "get", "(", "NAVIGATION_JUMP_FWD", ")", ";", "commandJumpBack", ".", "setEnabled", "(", "false", ")", ";", "commandJumpFwd", ".", "setEnabled", "(", "false", ")", ";", "KeyBindingManager", ".", "addBinding", "(", "NAVIGATION_JUMP_BACK", ",", "KeyboardPrefs", "[", "NAVIGATION_JUMP_BACK", "]", ")", ";", "KeyBindingManager", ".", "addBinding", "(", "NAVIGATION_JUMP_FWD", ",", "KeyboardPrefs", "[", "NAVIGATION_JUMP_FWD", "]", ")", ";", "_initNavigationMenuItems", "(", ")", ";", "}" ]
Function to initialize navigation commands and it's keyboard shortcuts. @private
[ "Function", "to", "initialize", "navigation", "commands", "and", "it", "s", "keyboard", "shortcuts", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L421-L431
2,437
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_captureFrame
function _captureFrame(editor) { // Capture the active position now if it was not captured earlier if ((activePosNotSynced || !jumpBackwardStack.length) && !jumpInProgress) { jumpBackwardStack.push(new NavigationFrame(editor, {ranges: editor._codeMirror.listSelections()})); } }
javascript
function _captureFrame(editor) { // Capture the active position now if it was not captured earlier if ((activePosNotSynced || !jumpBackwardStack.length) && !jumpInProgress) { jumpBackwardStack.push(new NavigationFrame(editor, {ranges: editor._codeMirror.listSelections()})); } }
[ "function", "_captureFrame", "(", "editor", ")", "{", "// Capture the active position now if it was not captured earlier", "if", "(", "(", "activePosNotSynced", "||", "!", "jumpBackwardStack", ".", "length", ")", "&&", "!", "jumpInProgress", ")", "{", "jumpBackwardStack", ".", "push", "(", "new", "NavigationFrame", "(", "editor", ",", "{", "ranges", ":", "editor", ".", "_codeMirror", ".", "listSelections", "(", ")", "}", ")", ")", ";", "}", "}" ]
Function to request a navigation frame creation explicitly. @private
[ "Function", "to", "request", "a", "navigation", "frame", "creation", "explicitly", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L437-L442
2,438
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_backupLiveMarkers
function _backupLiveMarkers(frames, editor) { var index, frame; for (index in frames) { frame = frames[index]; if (frame.cm === editor._codeMirror) { frame._handleEditorDestroy(); } } }
javascript
function _backupLiveMarkers(frames, editor) { var index, frame; for (index in frames) { frame = frames[index]; if (frame.cm === editor._codeMirror) { frame._handleEditorDestroy(); } } }
[ "function", "_backupLiveMarkers", "(", "frames", ",", "editor", ")", "{", "var", "index", ",", "frame", ";", "for", "(", "index", "in", "frames", ")", "{", "frame", "=", "frames", "[", "index", "]", ";", "if", "(", "frame", ".", "cm", "===", "editor", ".", "_codeMirror", ")", "{", "frame", ".", "_handleEditorDestroy", "(", ")", ";", "}", "}", "}" ]
Create snapshot of last known live markers. @private
[ "Create", "snapshot", "of", "last", "known", "live", "markers", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L448-L456
2,439
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_handleExternalChange
function _handleExternalChange(evt, doc) { if (doc) { _removeBackwardFramesForFile(doc.file); _removeForwardFramesForFile(doc.file); _validateNavigationCmds(); } }
javascript
function _handleExternalChange(evt, doc) { if (doc) { _removeBackwardFramesForFile(doc.file); _removeForwardFramesForFile(doc.file); _validateNavigationCmds(); } }
[ "function", "_handleExternalChange", "(", "evt", ",", "doc", ")", "{", "if", "(", "doc", ")", "{", "_removeBackwardFramesForFile", "(", "doc", ".", "file", ")", ";", "_removeForwardFramesForFile", "(", "doc", ".", "file", ")", ";", "_validateNavigationCmds", "(", ")", ";", "}", "}" ]
Handles explicit content reset for a document caused by external changes @private
[ "Handles", "explicit", "content", "reset", "for", "a", "document", "caused", "by", "external", "changes" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L491-L497
2,440
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_reinstateMarkers
function _reinstateMarkers(editor, frames) { var index, frame; for (index in frames) { frame = frames[index]; if (!frame.cm && frame.filePath === editor.document.file._path) { frame._reinstateMarkers(editor); } } }
javascript
function _reinstateMarkers(editor, frames) { var index, frame; for (index in frames) { frame = frames[index]; if (!frame.cm && frame.filePath === editor.document.file._path) { frame._reinstateMarkers(editor); } } }
[ "function", "_reinstateMarkers", "(", "editor", ",", "frames", ")", "{", "var", "index", ",", "frame", ";", "for", "(", "index", "in", "frames", ")", "{", "frame", "=", "frames", "[", "index", "]", ";", "if", "(", "!", "frame", ".", "cm", "&&", "frame", ".", "filePath", "===", "editor", ".", "document", ".", "file", ".", "_path", ")", "{", "frame", ".", "_reinstateMarkers", "(", "editor", ")", ";", "}", "}", "}" ]
Required to make offline markers alive again to track document mutation @private
[ "Required", "to", "make", "offline", "markers", "alive", "again", "to", "track", "document", "mutation" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L508-L516
2,441
adobe/brackets
src/extensions/default/NavigationAndHistory/NavigationProvider.js
_handleActiveEditorChange
function _handleActiveEditorChange(event, current, previous) { if (previous && previous._paneId) { // Handle only full editors previous.off("beforeSelectionChange", _recordJumpDef); _captureFrame(previous); _validateNavigationCmds(); } if (current && current._paneId) { // Handle only full editors activePosNotSynced = true; current.off("beforeSelectionChange", _recordJumpDef); current.on("beforeSelectionChange", _recordJumpDef); current.off("beforeDestroy", _handleEditorCleanup); current.on("beforeDestroy", _handleEditorCleanup); } }
javascript
function _handleActiveEditorChange(event, current, previous) { if (previous && previous._paneId) { // Handle only full editors previous.off("beforeSelectionChange", _recordJumpDef); _captureFrame(previous); _validateNavigationCmds(); } if (current && current._paneId) { // Handle only full editors activePosNotSynced = true; current.off("beforeSelectionChange", _recordJumpDef); current.on("beforeSelectionChange", _recordJumpDef); current.off("beforeDestroy", _handleEditorCleanup); current.on("beforeDestroy", _handleEditorCleanup); } }
[ "function", "_handleActiveEditorChange", "(", "event", ",", "current", ",", "previous", ")", "{", "if", "(", "previous", "&&", "previous", ".", "_paneId", ")", "{", "// Handle only full editors", "previous", ".", "off", "(", "\"beforeSelectionChange\"", ",", "_recordJumpDef", ")", ";", "_captureFrame", "(", "previous", ")", ";", "_validateNavigationCmds", "(", ")", ";", "}", "if", "(", "current", "&&", "current", ".", "_paneId", ")", "{", "// Handle only full editors", "activePosNotSynced", "=", "true", ";", "current", ".", "off", "(", "\"beforeSelectionChange\"", ",", "_recordJumpDef", ")", ";", "current", ".", "on", "(", "\"beforeSelectionChange\"", ",", "_recordJumpDef", ")", ";", "current", ".", "off", "(", "\"beforeDestroy\"", ",", "_handleEditorCleanup", ")", ";", "current", ".", "on", "(", "\"beforeDestroy\"", ",", "_handleEditorCleanup", ")", ";", "}", "}" ]
Handle Active Editor change to update navigation information @private
[ "Handle", "Active", "Editor", "change", "to", "update", "navigation", "information" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L522-L536
2,442
adobe/brackets
src/utils/Resizer.js
repositionResizer
function repositionResizer(elementSize) { var resizerPosition = elementSize || 1; if (position === POSITION_RIGHT || position === POSITION_BOTTOM) { $resizer.css(resizerCSSPosition, resizerPosition); } }
javascript
function repositionResizer(elementSize) { var resizerPosition = elementSize || 1; if (position === POSITION_RIGHT || position === POSITION_BOTTOM) { $resizer.css(resizerCSSPosition, resizerPosition); } }
[ "function", "repositionResizer", "(", "elementSize", ")", "{", "var", "resizerPosition", "=", "elementSize", "||", "1", ";", "if", "(", "position", "===", "POSITION_RIGHT", "||", "position", "===", "POSITION_BOTTOM", ")", "{", "$resizer", ".", "css", "(", "resizerCSSPosition", ",", "resizerPosition", ")", ";", "}", "}" ]
If the resizer is positioned right or bottom of the panel, we need to listen to reposition it if the element size changes externally
[ "If", "the", "resizer", "is", "positioned", "right", "or", "bottom", "of", "the", "panel", "we", "need", "to", "listen", "to", "reposition", "it", "if", "the", "element", "size", "changes", "externally" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/Resizer.js#L291-L296
2,443
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
_enqueueChange
function _enqueueChange(changedPath, stats) { _pendingChanges[changedPath] = stats; if (!_changeTimeout) { _changeTimeout = window.setTimeout(function () { if (_changeCallback) { Object.keys(_pendingChanges).forEach(function (path) { _changeCallback(path, _pendingChanges[path]); }); } _changeTimeout = null; _pendingChanges = {}; }, FILE_WATCHER_BATCH_TIMEOUT); } }
javascript
function _enqueueChange(changedPath, stats) { _pendingChanges[changedPath] = stats; if (!_changeTimeout) { _changeTimeout = window.setTimeout(function () { if (_changeCallback) { Object.keys(_pendingChanges).forEach(function (path) { _changeCallback(path, _pendingChanges[path]); }); } _changeTimeout = null; _pendingChanges = {}; }, FILE_WATCHER_BATCH_TIMEOUT); } }
[ "function", "_enqueueChange", "(", "changedPath", ",", "stats", ")", "{", "_pendingChanges", "[", "changedPath", "]", "=", "stats", ";", "if", "(", "!", "_changeTimeout", ")", "{", "_changeTimeout", "=", "window", ".", "setTimeout", "(", "function", "(", ")", "{", "if", "(", "_changeCallback", ")", "{", "Object", ".", "keys", "(", "_pendingChanges", ")", ".", "forEach", "(", "function", "(", "path", ")", "{", "_changeCallback", "(", "path", ",", "_pendingChanges", "[", "path", "]", ")", ";", "}", ")", ";", "}", "_changeTimeout", "=", "null", ";", "_pendingChanges", "=", "{", "}", ";", "}", ",", "FILE_WATCHER_BATCH_TIMEOUT", ")", ";", "}", "}" ]
Enqueue a file change event for eventual reporting back to the FileSystem. @param {string} changedPath The path that was changed @param {object} stats Stats coming from the underlying watcher, if available @private
[ "Enqueue", "a", "file", "change", "event", "for", "eventual", "reporting", "back", "to", "the", "FileSystem", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L84-L98
2,444
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
_fileWatcherChange
function _fileWatcherChange(evt, event, parentDirPath, entryName, statsObj) { var change; switch (event) { case "changed": // an existing file/directory was modified; stats are passed if available var fsStats; if (statsObj) { fsStats = new FileSystemStats(statsObj); } else { console.warn("FileWatcherDomain was expected to deliver stats for changed event!"); } _enqueueChange(parentDirPath + entryName, fsStats); break; case "created": case "deleted": // file/directory was created/deleted; fire change on parent to reload contents _enqueueChange(parentDirPath, null); break; default: console.error("Unexpected 'change' event:", event); } }
javascript
function _fileWatcherChange(evt, event, parentDirPath, entryName, statsObj) { var change; switch (event) { case "changed": // an existing file/directory was modified; stats are passed if available var fsStats; if (statsObj) { fsStats = new FileSystemStats(statsObj); } else { console.warn("FileWatcherDomain was expected to deliver stats for changed event!"); } _enqueueChange(parentDirPath + entryName, fsStats); break; case "created": case "deleted": // file/directory was created/deleted; fire change on parent to reload contents _enqueueChange(parentDirPath, null); break; default: console.error("Unexpected 'change' event:", event); } }
[ "function", "_fileWatcherChange", "(", "evt", ",", "event", ",", "parentDirPath", ",", "entryName", ",", "statsObj", ")", "{", "var", "change", ";", "switch", "(", "event", ")", "{", "case", "\"changed\"", ":", "// an existing file/directory was modified; stats are passed if available", "var", "fsStats", ";", "if", "(", "statsObj", ")", "{", "fsStats", "=", "new", "FileSystemStats", "(", "statsObj", ")", ";", "}", "else", "{", "console", ".", "warn", "(", "\"FileWatcherDomain was expected to deliver stats for changed event!\"", ")", ";", "}", "_enqueueChange", "(", "parentDirPath", "+", "entryName", ",", "fsStats", ")", ";", "break", ";", "case", "\"created\"", ":", "case", "\"deleted\"", ":", "// file/directory was created/deleted; fire change on parent to reload contents", "_enqueueChange", "(", "parentDirPath", ",", "null", ")", ";", "break", ";", "default", ":", "console", ".", "error", "(", "\"Unexpected 'change' event:\"", ",", "event", ")", ";", "}", "}" ]
Event handler for the Node fileWatcher domain's change event. @param {jQuery.Event} The underlying change event @param {string} event The type of the event: "changed", "created" or "deleted" @param {string} parentDirPath The path to the directory holding entry that has changed @param {string=} entryName The name of the file/directory that has changed @param {object} statsObj Object that can be used to construct FileSystemStats @private
[ "Event", "handler", "for", "the", "Node", "fileWatcher", "domain", "s", "change", "event", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L110-L131
2,445
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
_mapError
function _mapError(err) { if (!err) { return null; } switch (err) { case appshell.fs.ERR_INVALID_PARAMS: return FileSystemError.INVALID_PARAMS; case appshell.fs.ERR_NOT_FOUND: return FileSystemError.NOT_FOUND; case appshell.fs.ERR_CANT_READ: return FileSystemError.NOT_READABLE; case appshell.fs.ERR_CANT_WRITE: return FileSystemError.NOT_WRITABLE; case appshell.fs.ERR_UNSUPPORTED_ENCODING: return FileSystemError.UNSUPPORTED_ENCODING; case appshell.fs.ERR_OUT_OF_SPACE: return FileSystemError.OUT_OF_SPACE; case appshell.fs.ERR_FILE_EXISTS: return FileSystemError.ALREADY_EXISTS; case appshell.fs.ERR_ENCODE_FILE_FAILED: return FileSystemError.ENCODE_FILE_FAILED; case appshell.fs.ERR_DECODE_FILE_FAILED: return FileSystemError.DECODE_FILE_FAILED; case appshell.fs.ERR_UNSUPPORTED_UTF16_ENCODING: return FileSystemError.UNSUPPORTED_UTF16_ENCODING; } return FileSystemError.UNKNOWN; }
javascript
function _mapError(err) { if (!err) { return null; } switch (err) { case appshell.fs.ERR_INVALID_PARAMS: return FileSystemError.INVALID_PARAMS; case appshell.fs.ERR_NOT_FOUND: return FileSystemError.NOT_FOUND; case appshell.fs.ERR_CANT_READ: return FileSystemError.NOT_READABLE; case appshell.fs.ERR_CANT_WRITE: return FileSystemError.NOT_WRITABLE; case appshell.fs.ERR_UNSUPPORTED_ENCODING: return FileSystemError.UNSUPPORTED_ENCODING; case appshell.fs.ERR_OUT_OF_SPACE: return FileSystemError.OUT_OF_SPACE; case appshell.fs.ERR_FILE_EXISTS: return FileSystemError.ALREADY_EXISTS; case appshell.fs.ERR_ENCODE_FILE_FAILED: return FileSystemError.ENCODE_FILE_FAILED; case appshell.fs.ERR_DECODE_FILE_FAILED: return FileSystemError.DECODE_FILE_FAILED; case appshell.fs.ERR_UNSUPPORTED_UTF16_ENCODING: return FileSystemError.UNSUPPORTED_UTF16_ENCODING; } return FileSystemError.UNKNOWN; }
[ "function", "_mapError", "(", "err", ")", "{", "if", "(", "!", "err", ")", "{", "return", "null", ";", "}", "switch", "(", "err", ")", "{", "case", "appshell", ".", "fs", ".", "ERR_INVALID_PARAMS", ":", "return", "FileSystemError", ".", "INVALID_PARAMS", ";", "case", "appshell", ".", "fs", ".", "ERR_NOT_FOUND", ":", "return", "FileSystemError", ".", "NOT_FOUND", ";", "case", "appshell", ".", "fs", ".", "ERR_CANT_READ", ":", "return", "FileSystemError", ".", "NOT_READABLE", ";", "case", "appshell", ".", "fs", ".", "ERR_CANT_WRITE", ":", "return", "FileSystemError", ".", "NOT_WRITABLE", ";", "case", "appshell", ".", "fs", ".", "ERR_UNSUPPORTED_ENCODING", ":", "return", "FileSystemError", ".", "UNSUPPORTED_ENCODING", ";", "case", "appshell", ".", "fs", ".", "ERR_OUT_OF_SPACE", ":", "return", "FileSystemError", ".", "OUT_OF_SPACE", ";", "case", "appshell", ".", "fs", ".", "ERR_FILE_EXISTS", ":", "return", "FileSystemError", ".", "ALREADY_EXISTS", ";", "case", "appshell", ".", "fs", ".", "ERR_ENCODE_FILE_FAILED", ":", "return", "FileSystemError", ".", "ENCODE_FILE_FAILED", ";", "case", "appshell", ".", "fs", ".", "ERR_DECODE_FILE_FAILED", ":", "return", "FileSystemError", ".", "DECODE_FILE_FAILED", ";", "case", "appshell", ".", "fs", ".", "ERR_UNSUPPORTED_UTF16_ENCODING", ":", "return", "FileSystemError", ".", "UNSUPPORTED_UTF16_ENCODING", ";", "}", "return", "FileSystemError", ".", "UNKNOWN", ";", "}" ]
Convert appshell error codes to FileSystemError values. @param {?number} err An appshell error code @return {?string} A FileSystemError string, or null if there was no error code. @private
[ "Convert", "appshell", "error", "codes", "to", "FileSystemError", "values", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L143-L171
2,446
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
showOpenDialog
function showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, callback) { appshell.fs.showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, _wrap(callback)); }
javascript
function showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, callback) { appshell.fs.showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, _wrap(callback)); }
[ "function", "showOpenDialog", "(", "allowMultipleSelection", ",", "chooseDirectories", ",", "title", ",", "initialPath", ",", "fileTypes", ",", "callback", ")", "{", "appshell", ".", "fs", ".", "showOpenDialog", "(", "allowMultipleSelection", ",", "chooseDirectories", ",", "title", ",", "initialPath", ",", "fileTypes", ",", "_wrap", "(", "callback", ")", ")", ";", "}" ]
Display an open-files dialog to the user and call back asynchronously with either a FileSystmError string or an array of path strings, which indicate the entry or entries selected. @param {boolean} allowMultipleSelection @param {boolean} chooseDirectories @param {string} title @param {string} initialPath @param {Array.<string>=} fileTypes @param {function(?string, Array.<string>=)} callback
[ "Display", "an", "open", "-", "files", "dialog", "to", "the", "user", "and", "call", "back", "asynchronously", "with", "either", "a", "FileSystmError", "string", "or", "an", "array", "of", "path", "strings", "which", "indicate", "the", "entry", "or", "entries", "selected", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L201-L203
2,447
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
showSaveDialog
function showSaveDialog(title, initialPath, proposedNewFilename, callback) { appshell.fs.showSaveDialog(title, initialPath, proposedNewFilename, _wrap(callback)); }
javascript
function showSaveDialog(title, initialPath, proposedNewFilename, callback) { appshell.fs.showSaveDialog(title, initialPath, proposedNewFilename, _wrap(callback)); }
[ "function", "showSaveDialog", "(", "title", ",", "initialPath", ",", "proposedNewFilename", ",", "callback", ")", "{", "appshell", ".", "fs", ".", "showSaveDialog", "(", "title", ",", "initialPath", ",", "proposedNewFilename", ",", "_wrap", "(", "callback", ")", ")", ";", "}" ]
Display a save-file dialog and call back asynchronously with either a FileSystemError string or the path to which the user has chosen to save the file. If the dialog is cancelled, the path string will be empty. @param {string} title @param {string} initialPath @param {string} proposedNewFilename @param {function(?string, string=)} callback
[ "Display", "a", "save", "-", "file", "dialog", "and", "call", "back", "asynchronously", "with", "either", "a", "FileSystemError", "string", "or", "the", "path", "to", "which", "the", "user", "has", "chosen", "to", "save", "the", "file", ".", "If", "the", "dialog", "is", "cancelled", "the", "path", "string", "will", "be", "empty", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L215-L217
2,448
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
stat
function stat(path, callback) { appshell.fs.stat(path, function (err, stats) { if (err) { callback(_mapError(err)); } else { var options = { isFile: stats.isFile(), mtime: stats.mtime, size: stats.size, realPath: stats.realPath, hash: stats.mtime.getTime() }; var fsStats = new FileSystemStats(options); callback(null, fsStats); } }); }
javascript
function stat(path, callback) { appshell.fs.stat(path, function (err, stats) { if (err) { callback(_mapError(err)); } else { var options = { isFile: stats.isFile(), mtime: stats.mtime, size: stats.size, realPath: stats.realPath, hash: stats.mtime.getTime() }; var fsStats = new FileSystemStats(options); callback(null, fsStats); } }); }
[ "function", "stat", "(", "path", ",", "callback", ")", "{", "appshell", ".", "fs", ".", "stat", "(", "path", ",", "function", "(", "err", ",", "stats", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "_mapError", "(", "err", ")", ")", ";", "}", "else", "{", "var", "options", "=", "{", "isFile", ":", "stats", ".", "isFile", "(", ")", ",", "mtime", ":", "stats", ".", "mtime", ",", "size", ":", "stats", ".", "size", ",", "realPath", ":", "stats", ".", "realPath", ",", "hash", ":", "stats", ".", "mtime", ".", "getTime", "(", ")", "}", ";", "var", "fsStats", "=", "new", "FileSystemStats", "(", "options", ")", ";", "callback", "(", "null", ",", "fsStats", ")", ";", "}", "}", ")", ";", "}" ]
Stat the file or directory at the given path, calling back asynchronously with either a FileSystemError string or the entry's associated FileSystemStats object. @param {string} path @param {function(?string, FileSystemStats=)} callback
[ "Stat", "the", "file", "or", "directory", "at", "the", "given", "path", "calling", "back", "asynchronously", "with", "either", "a", "FileSystemError", "string", "or", "the", "entry", "s", "associated", "FileSystemStats", "object", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L227-L245
2,449
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
exists
function exists(path, callback) { stat(path, function (err) { if (err) { if (err === FileSystemError.NOT_FOUND) { callback(null, false); } else { callback(err); } return; } callback(null, true); }); }
javascript
function exists(path, callback) { stat(path, function (err) { if (err) { if (err === FileSystemError.NOT_FOUND) { callback(null, false); } else { callback(err); } return; } callback(null, true); }); }
[ "function", "exists", "(", "path", ",", "callback", ")", "{", "stat", "(", "path", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "if", "(", "err", "===", "FileSystemError", ".", "NOT_FOUND", ")", "{", "callback", "(", "null", ",", "false", ")", ";", "}", "else", "{", "callback", "(", "err", ")", ";", "}", "return", ";", "}", "callback", "(", "null", ",", "true", ")", ";", "}", ")", ";", "}" ]
Determine whether a file or directory exists at the given path by calling back asynchronously with either a FileSystemError string or a boolean, which is true if the file exists and false otherwise. The error will never be FileSystemError.NOT_FOUND; in that case, there will be no error and the boolean parameter will be false. @param {string} path @param {function(?string, boolean)} callback
[ "Determine", "whether", "a", "file", "or", "directory", "exists", "at", "the", "given", "path", "by", "calling", "back", "asynchronously", "with", "either", "a", "FileSystemError", "string", "or", "a", "boolean", "which", "is", "true", "if", "the", "file", "exists", "and", "false", "otherwise", ".", "The", "error", "will", "never", "be", "FileSystemError", ".", "NOT_FOUND", ";", "in", "that", "case", "there", "will", "be", "no", "error", "and", "the", "boolean", "parameter", "will", "be", "false", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L257-L270
2,450
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
mkdir
function mkdir(path, mode, callback) { if (typeof mode === "function") { callback = mode; mode = parseInt("0755", 8); } appshell.fs.makedir(path, mode, function (err) { if (err) { callback(_mapError(err)); } else { stat(path, function (err, stat) { callback(err, stat); }); } }); }
javascript
function mkdir(path, mode, callback) { if (typeof mode === "function") { callback = mode; mode = parseInt("0755", 8); } appshell.fs.makedir(path, mode, function (err) { if (err) { callback(_mapError(err)); } else { stat(path, function (err, stat) { callback(err, stat); }); } }); }
[ "function", "mkdir", "(", "path", ",", "mode", ",", "callback", ")", "{", "if", "(", "typeof", "mode", "===", "\"function\"", ")", "{", "callback", "=", "mode", ";", "mode", "=", "parseInt", "(", "\"0755\"", ",", "8", ")", ";", "}", "appshell", ".", "fs", ".", "makedir", "(", "path", ",", "mode", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "_mapError", "(", "err", ")", ")", ";", "}", "else", "{", "stat", "(", "path", ",", "function", "(", "err", ",", "stat", ")", "{", "callback", "(", "err", ",", "stat", ")", ";", "}", ")", ";", "}", "}", ")", ";", "}" ]
Create a directory at the given path, and call back asynchronously with either a FileSystemError string or a stats object for the newly created directory. The octal mode parameter is optional; if unspecified, the mode of the created directory is implementation dependent. @param {string} path @param {number=} mode The base-eight mode of the newly created directory. @param {function(?string, FileSystemStats=)=} callback
[ "Create", "a", "directory", "at", "the", "given", "path", "and", "call", "back", "asynchronously", "with", "either", "a", "FileSystemError", "string", "or", "a", "stats", "object", "for", "the", "newly", "created", "directory", ".", "The", "octal", "mode", "parameter", "is", "optional", ";", "if", "unspecified", "the", "mode", "of", "the", "created", "directory", "is", "implementation", "dependent", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L319-L333
2,451
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
rename
function rename(oldPath, newPath, callback) { appshell.fs.rename(oldPath, newPath, _wrap(callback)); }
javascript
function rename(oldPath, newPath, callback) { appshell.fs.rename(oldPath, newPath, _wrap(callback)); }
[ "function", "rename", "(", "oldPath", ",", "newPath", ",", "callback", ")", "{", "appshell", ".", "fs", ".", "rename", "(", "oldPath", ",", "newPath", ",", "_wrap", "(", "callback", ")", ")", ";", "}" ]
Rename the file or directory at oldPath to newPath, and call back asynchronously with a possibly null FileSystemError string. @param {string} oldPath @param {string} newPath @param {function(?string)=} callback
[ "Rename", "the", "file", "or", "directory", "at", "oldPath", "to", "newPath", "and", "call", "back", "asynchronously", "with", "a", "possibly", "null", "FileSystemError", "string", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L343-L345
2,452
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
doReadFile
function doReadFile(stat) { if (stat.size > (FileUtils.MAX_FILE_SIZE)) { callback(FileSystemError.EXCEEDS_MAX_FILE_SIZE); } else { appshell.fs.readFile(path, encoding, function (_err, _data, encoding, preserveBOM) { if (_err) { callback(_mapError(_err)); } else { callback(null, _data, encoding, preserveBOM, stat); } }); } }
javascript
function doReadFile(stat) { if (stat.size > (FileUtils.MAX_FILE_SIZE)) { callback(FileSystemError.EXCEEDS_MAX_FILE_SIZE); } else { appshell.fs.readFile(path, encoding, function (_err, _data, encoding, preserveBOM) { if (_err) { callback(_mapError(_err)); } else { callback(null, _data, encoding, preserveBOM, stat); } }); } }
[ "function", "doReadFile", "(", "stat", ")", "{", "if", "(", "stat", ".", "size", ">", "(", "FileUtils", ".", "MAX_FILE_SIZE", ")", ")", "{", "callback", "(", "FileSystemError", ".", "EXCEEDS_MAX_FILE_SIZE", ")", ";", "}", "else", "{", "appshell", ".", "fs", ".", "readFile", "(", "path", ",", "encoding", ",", "function", "(", "_err", ",", "_data", ",", "encoding", ",", "preserveBOM", ")", "{", "if", "(", "_err", ")", "{", "callback", "(", "_mapError", "(", "_err", ")", ")", ";", "}", "else", "{", "callback", "(", "null", ",", "_data", ",", "encoding", ",", "preserveBOM", ",", "stat", ")", ";", "}", "}", ")", ";", "}", "}" ]
callback to be executed when the call to stat completes or immediately if a stat object was passed as an argument
[ "callback", "to", "be", "executed", "when", "the", "call", "to", "stat", "completes", "or", "immediately", "if", "a", "stat", "object", "was", "passed", "as", "an", "argument" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L368-L380
2,453
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
moveToTrash
function moveToTrash(path, callback) { appshell.fs.moveToTrash(path, function (err) { callback(_mapError(err)); }); }
javascript
function moveToTrash(path, callback) { appshell.fs.moveToTrash(path, function (err) { callback(_mapError(err)); }); }
[ "function", "moveToTrash", "(", "path", ",", "callback", ")", "{", "appshell", ".", "fs", ".", "moveToTrash", "(", "path", ",", "function", "(", "err", ")", "{", "callback", "(", "_mapError", "(", "err", ")", ")", ";", "}", ")", ";", "}" ]
Move the file or directory at the given path to a system dependent trash location, calling back asynchronously with a possibly null FileSystemError string. Directories will be moved even when non-empty. @param {string} path @param {function(string)=} callback
[ "Move", "the", "file", "or", "directory", "at", "the", "given", "path", "to", "a", "system", "dependent", "trash", "location", "calling", "back", "asynchronously", "with", "a", "possibly", "null", "FileSystemError", "string", ".", "Directories", "will", "be", "moved", "even", "when", "non", "-", "empty", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L484-L488
2,454
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
watchPath
function watchPath(path, ignored, callback) { if (_isRunningOnWindowsXP) { callback(FileSystemError.NOT_SUPPORTED); return; } appshell.fs.isNetworkDrive(path, function (err, isNetworkDrive) { if (err || isNetworkDrive) { if (isNetworkDrive) { callback(FileSystemError.NETWORK_DRIVE_NOT_SUPPORTED); } else { callback(FileSystemError.UNKNOWN); } return; } _nodeDomain.exec("watchPath", path, ignored) .then(callback, callback); }); }
javascript
function watchPath(path, ignored, callback) { if (_isRunningOnWindowsXP) { callback(FileSystemError.NOT_SUPPORTED); return; } appshell.fs.isNetworkDrive(path, function (err, isNetworkDrive) { if (err || isNetworkDrive) { if (isNetworkDrive) { callback(FileSystemError.NETWORK_DRIVE_NOT_SUPPORTED); } else { callback(FileSystemError.UNKNOWN); } return; } _nodeDomain.exec("watchPath", path, ignored) .then(callback, callback); }); }
[ "function", "watchPath", "(", "path", ",", "ignored", ",", "callback", ")", "{", "if", "(", "_isRunningOnWindowsXP", ")", "{", "callback", "(", "FileSystemError", ".", "NOT_SUPPORTED", ")", ";", "return", ";", "}", "appshell", ".", "fs", ".", "isNetworkDrive", "(", "path", ",", "function", "(", "err", ",", "isNetworkDrive", ")", "{", "if", "(", "err", "||", "isNetworkDrive", ")", "{", "if", "(", "isNetworkDrive", ")", "{", "callback", "(", "FileSystemError", ".", "NETWORK_DRIVE_NOT_SUPPORTED", ")", ";", "}", "else", "{", "callback", "(", "FileSystemError", ".", "UNKNOWN", ")", ";", "}", "return", ";", "}", "_nodeDomain", ".", "exec", "(", "\"watchPath\"", ",", "path", ",", "ignored", ")", ".", "then", "(", "callback", ",", "callback", ")", ";", "}", ")", ";", "}" ]
Start providing change notifications for the file or directory at the given path, calling back asynchronously with a possibly null FileSystemError string when the initialization is complete. Notifications are provided using the changeCallback function provided by the initWatchers method. Note that change notifications are only provided recursively for directories when the recursiveWatch property of this module is true. @param {string} path @param {Array<string>} ignored @param {function(?string)=} callback
[ "Start", "providing", "change", "notifications", "for", "the", "file", "or", "directory", "at", "the", "given", "path", "calling", "back", "asynchronously", "with", "a", "possibly", "null", "FileSystemError", "string", "when", "the", "initialization", "is", "complete", ".", "Notifications", "are", "provided", "using", "the", "changeCallback", "function", "provided", "by", "the", "initWatchers", "method", ".", "Note", "that", "change", "notifications", "are", "only", "provided", "recursively", "for", "directories", "when", "the", "recursiveWatch", "property", "of", "this", "module", "is", "true", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L527-L544
2,455
adobe/brackets
src/filesystem/impls/appshell/AppshellFileSystem.js
unwatchPath
function unwatchPath(path, ignored, callback) { _nodeDomain.exec("unwatchPath", path) .then(callback, callback); }
javascript
function unwatchPath(path, ignored, callback) { _nodeDomain.exec("unwatchPath", path) .then(callback, callback); }
[ "function", "unwatchPath", "(", "path", ",", "ignored", ",", "callback", ")", "{", "_nodeDomain", ".", "exec", "(", "\"unwatchPath\"", ",", "path", ")", ".", "then", "(", "callback", ",", "callback", ")", ";", "}" ]
Stop providing change notifications for the file or directory at the given path, calling back asynchronously with a possibly null FileSystemError string when the operation is complete. This function needs to mirror the signature of watchPath because of FileSystem.prototype._watchOrUnwatchEntry implementation. @param {string} path @param {Array<string>} ignored @param {function(?string)=} callback
[ "Stop", "providing", "change", "notifications", "for", "the", "file", "or", "directory", "at", "the", "given", "path", "calling", "back", "asynchronously", "with", "a", "possibly", "null", "FileSystemError", "string", "when", "the", "operation", "is", "complete", ".", "This", "function", "needs", "to", "mirror", "the", "signature", "of", "watchPath", "because", "of", "FileSystem", ".", "prototype", ".", "_watchOrUnwatchEntry", "implementation", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L556-L559
2,456
adobe/brackets
src/project/FileSyncManager.js
reloadDoc
function reloadDoc(doc) { var promise = FileUtils.readAsText(doc.file); promise.done(function (text, readTimestamp) { doc.refreshText(text, readTimestamp); }); promise.fail(function (error) { console.log("Error reloading contents of " + doc.file.fullPath, error); }); return promise; }
javascript
function reloadDoc(doc) { var promise = FileUtils.readAsText(doc.file); promise.done(function (text, readTimestamp) { doc.refreshText(text, readTimestamp); }); promise.fail(function (error) { console.log("Error reloading contents of " + doc.file.fullPath, error); }); return promise; }
[ "function", "reloadDoc", "(", "doc", ")", "{", "var", "promise", "=", "FileUtils", ".", "readAsText", "(", "doc", ".", "file", ")", ";", "promise", ".", "done", "(", "function", "(", "text", ",", "readTimestamp", ")", "{", "doc", ".", "refreshText", "(", "text", ",", "readTimestamp", ")", ";", "}", ")", ";", "promise", ".", "fail", "(", "function", "(", "error", ")", "{", "console", ".", "log", "(", "\"Error reloading contents of \"", "+", "doc", ".", "file", ".", "fullPath", ",", "error", ")", ";", "}", ")", ";", "return", "promise", ";", "}" ]
Reloads the Document's contents from disk, discarding any unsaved changes in the editor. @param {!Document} doc @return {$.Promise} Resolved after editor has been refreshed; rejected if unable to load the file's new content. Errors are logged but no UI is shown.
[ "Reloads", "the", "Document", "s", "contents", "from", "disk", "discarding", "any", "unsaved", "changes", "in", "the", "editor", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileSyncManager.js#L218-L229
2,457
adobe/brackets
src/extensibility/node/package-validator.js
parsePersonString
function parsePersonString(obj) { if (typeof (obj) === "string") { var parts = _personRegex.exec(obj); // No regex match, so we just synthesize an object with an opaque name string if (!parts) { return { name: obj }; } else { var result = { name: parts[1] }; if (parts[2]) { result.email = parts[2]; } if (parts[3]) { result.url = parts[3]; } return result; } } else { // obj is not a string, so return as is return obj; } }
javascript
function parsePersonString(obj) { if (typeof (obj) === "string") { var parts = _personRegex.exec(obj); // No regex match, so we just synthesize an object with an opaque name string if (!parts) { return { name: obj }; } else { var result = { name: parts[1] }; if (parts[2]) { result.email = parts[2]; } if (parts[3]) { result.url = parts[3]; } return result; } } else { // obj is not a string, so return as is return obj; } }
[ "function", "parsePersonString", "(", "obj", ")", "{", "if", "(", "typeof", "(", "obj", ")", "===", "\"string\"", ")", "{", "var", "parts", "=", "_personRegex", ".", "exec", "(", "obj", ")", ";", "// No regex match, so we just synthesize an object with an opaque name string", "if", "(", "!", "parts", ")", "{", "return", "{", "name", ":", "obj", "}", ";", "}", "else", "{", "var", "result", "=", "{", "name", ":", "parts", "[", "1", "]", "}", ";", "if", "(", "parts", "[", "2", "]", ")", "{", "result", ".", "email", "=", "parts", "[", "2", "]", ";", "}", "if", "(", "parts", "[", "3", "]", ")", "{", "result", ".", "url", "=", "parts", "[", "3", "]", ";", "}", "return", "result", ";", "}", "}", "else", "{", "// obj is not a string, so return as is", "return", "obj", ";", "}", "}" ]
Normalizes person fields from package.json. These fields can be an object with name, email and url properties or a string of the form "name <email> <url>". This does a tolerant parsing of the data to try to return an object with name and optional email and url. If the string does not match the format, the string is returned as the name on the resulting object. If an object other than a string is passed in, it's returned as is. @param <String|Object> obj to normalize @return {Object} person object with name and optional email and url
[ "Normalizes", "person", "fields", "from", "package", ".", "json", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L97-L122
2,458
adobe/brackets
src/extensibility/node/package-validator.js
containsWords
function containsWords(wordlist, str) { var i; var matches = []; for (i = 0; i < wordlist.length; i++) { var re = new RegExp("\\b" + wordlist[i] + "\\b", "i"); if (re.exec(str)) { matches.push(wordlist[i]); } } return matches; }
javascript
function containsWords(wordlist, str) { var i; var matches = []; for (i = 0; i < wordlist.length; i++) { var re = new RegExp("\\b" + wordlist[i] + "\\b", "i"); if (re.exec(str)) { matches.push(wordlist[i]); } } return matches; }
[ "function", "containsWords", "(", "wordlist", ",", "str", ")", "{", "var", "i", ";", "var", "matches", "=", "[", "]", ";", "for", "(", "i", "=", "0", ";", "i", "<", "wordlist", ".", "length", ";", "i", "++", ")", "{", "var", "re", "=", "new", "RegExp", "(", "\"\\\\b\"", "+", "wordlist", "[", "i", "]", "+", "\"\\\\b\"", ",", "\"i\"", ")", ";", "if", "(", "re", ".", "exec", "(", "str", ")", ")", "{", "matches", ".", "push", "(", "wordlist", "[", "i", "]", ")", ";", "}", "}", "return", "matches", ";", "}" ]
Determines if any of the words in wordlist appear in str. @param {String[]} wordlist list of words to check @param {String} str to check for words @return {String[]} words that matched
[ "Determines", "if", "any", "of", "the", "words", "in", "wordlist", "appear", "in", "str", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L131-L141
2,459
adobe/brackets
src/extensibility/node/package-validator.js
findCommonPrefix
function findCommonPrefix(extractDir, callback) { fs.readdir(extractDir, function (err, files) { ignoredFolders.forEach(function (folder) { var index = files.indexOf(folder); if (index !== -1) { files.splice(index, 1); } }); if (err) { callback(err); } else if (files.length === 1) { var name = files[0]; if (fs.statSync(path.join(extractDir, name)).isDirectory()) { callback(null, name); } else { callback(null, ""); } } else { callback(null, ""); } }); }
javascript
function findCommonPrefix(extractDir, callback) { fs.readdir(extractDir, function (err, files) { ignoredFolders.forEach(function (folder) { var index = files.indexOf(folder); if (index !== -1) { files.splice(index, 1); } }); if (err) { callback(err); } else if (files.length === 1) { var name = files[0]; if (fs.statSync(path.join(extractDir, name)).isDirectory()) { callback(null, name); } else { callback(null, ""); } } else { callback(null, ""); } }); }
[ "function", "findCommonPrefix", "(", "extractDir", ",", "callback", ")", "{", "fs", ".", "readdir", "(", "extractDir", ",", "function", "(", "err", ",", "files", ")", "{", "ignoredFolders", ".", "forEach", "(", "function", "(", "folder", ")", "{", "var", "index", "=", "files", ".", "indexOf", "(", "folder", ")", ";", "if", "(", "index", "!==", "-", "1", ")", "{", "files", ".", "splice", "(", "index", ",", "1", ")", ";", "}", "}", ")", ";", "if", "(", "err", ")", "{", "callback", "(", "err", ")", ";", "}", "else", "if", "(", "files", ".", "length", "===", "1", ")", "{", "var", "name", "=", "files", "[", "0", "]", ";", "if", "(", "fs", ".", "statSync", "(", "path", ".", "join", "(", "extractDir", ",", "name", ")", ")", ".", "isDirectory", "(", ")", ")", "{", "callback", "(", "null", ",", "name", ")", ";", "}", "else", "{", "callback", "(", "null", ",", "\"\"", ")", ";", "}", "}", "else", "{", "callback", "(", "null", ",", "\"\"", ")", ";", "}", "}", ")", ";", "}" ]
Finds the common prefix, if any, for the files in a package file. In some package files, all of the files are contained in a subdirectory, and this function will identify that directory if it exists. @param {string} extractDir directory into which the package was extracted @param {function(Error, string)} callback function to accept err, commonPrefix (which will be "" if there is none)
[ "Finds", "the", "common", "prefix", "if", "any", "for", "the", "files", "in", "a", "package", "file", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L152-L173
2,460
adobe/brackets
src/extensibility/node/package-validator.js
validatePackageJSON
function validatePackageJSON(path, packageJSON, options, callback) { var errors = []; if (fs.existsSync(packageJSON)) { fs.readFile(packageJSON, { encoding: "utf8" }, function (err, data) { if (err) { callback(err, null, null); return; } var metadata; try { metadata = JSON.parse(data); } catch (e) { errors.push([Errors.INVALID_PACKAGE_JSON, e.toString(), path]); callback(null, errors, undefined); return; } // confirm required fields in the metadata if (!metadata.name) { errors.push([Errors.MISSING_PACKAGE_NAME, path]); } else if (!validateName(metadata.name)) { errors.push([Errors.BAD_PACKAGE_NAME, metadata.name]); } if (!metadata.version) { errors.push([Errors.MISSING_PACKAGE_VERSION, path]); } else if (!semver.valid(metadata.version)) { errors.push([Errors.INVALID_VERSION_NUMBER, metadata.version, path]); } // normalize the author if (metadata.author) { metadata.author = parsePersonString(metadata.author); } // contributors should be an array of people. // normalize each entry. if (metadata.contributors) { if (metadata.contributors.map) { metadata.contributors = metadata.contributors.map(function (person) { return parsePersonString(person); }); } else { metadata.contributors = [ parsePersonString(metadata.contributors) ]; } } if (metadata.engines && metadata.engines.brackets) { var range = metadata.engines.brackets; if (!semver.validRange(range)) { errors.push([Errors.INVALID_BRACKETS_VERSION, range, path]); } } if (options.disallowedWords) { ["title", "description", "name"].forEach(function (field) { var words = containsWords(options.disallowedWords, metadata[field]); if (words.length > 0) { errors.push([Errors.DISALLOWED_WORDS, field, words.toString(), path]); } }); } callback(null, errors, metadata); }); } else { if (options.requirePackageJSON) { errors.push([Errors.MISSING_PACKAGE_JSON, path]); } callback(null, errors, null); } }
javascript
function validatePackageJSON(path, packageJSON, options, callback) { var errors = []; if (fs.existsSync(packageJSON)) { fs.readFile(packageJSON, { encoding: "utf8" }, function (err, data) { if (err) { callback(err, null, null); return; } var metadata; try { metadata = JSON.parse(data); } catch (e) { errors.push([Errors.INVALID_PACKAGE_JSON, e.toString(), path]); callback(null, errors, undefined); return; } // confirm required fields in the metadata if (!metadata.name) { errors.push([Errors.MISSING_PACKAGE_NAME, path]); } else if (!validateName(metadata.name)) { errors.push([Errors.BAD_PACKAGE_NAME, metadata.name]); } if (!metadata.version) { errors.push([Errors.MISSING_PACKAGE_VERSION, path]); } else if (!semver.valid(metadata.version)) { errors.push([Errors.INVALID_VERSION_NUMBER, metadata.version, path]); } // normalize the author if (metadata.author) { metadata.author = parsePersonString(metadata.author); } // contributors should be an array of people. // normalize each entry. if (metadata.contributors) { if (metadata.contributors.map) { metadata.contributors = metadata.contributors.map(function (person) { return parsePersonString(person); }); } else { metadata.contributors = [ parsePersonString(metadata.contributors) ]; } } if (metadata.engines && metadata.engines.brackets) { var range = metadata.engines.brackets; if (!semver.validRange(range)) { errors.push([Errors.INVALID_BRACKETS_VERSION, range, path]); } } if (options.disallowedWords) { ["title", "description", "name"].forEach(function (field) { var words = containsWords(options.disallowedWords, metadata[field]); if (words.length > 0) { errors.push([Errors.DISALLOWED_WORDS, field, words.toString(), path]); } }); } callback(null, errors, metadata); }); } else { if (options.requirePackageJSON) { errors.push([Errors.MISSING_PACKAGE_JSON, path]); } callback(null, errors, null); } }
[ "function", "validatePackageJSON", "(", "path", ",", "packageJSON", ",", "options", ",", "callback", ")", "{", "var", "errors", "=", "[", "]", ";", "if", "(", "fs", ".", "existsSync", "(", "packageJSON", ")", ")", "{", "fs", ".", "readFile", "(", "packageJSON", ",", "{", "encoding", ":", "\"utf8\"", "}", ",", "function", "(", "err", ",", "data", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "err", ",", "null", ",", "null", ")", ";", "return", ";", "}", "var", "metadata", ";", "try", "{", "metadata", "=", "JSON", ".", "parse", "(", "data", ")", ";", "}", "catch", "(", "e", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "INVALID_PACKAGE_JSON", ",", "e", ".", "toString", "(", ")", ",", "path", "]", ")", ";", "callback", "(", "null", ",", "errors", ",", "undefined", ")", ";", "return", ";", "}", "// confirm required fields in the metadata", "if", "(", "!", "metadata", ".", "name", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "MISSING_PACKAGE_NAME", ",", "path", "]", ")", ";", "}", "else", "if", "(", "!", "validateName", "(", "metadata", ".", "name", ")", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "BAD_PACKAGE_NAME", ",", "metadata", ".", "name", "]", ")", ";", "}", "if", "(", "!", "metadata", ".", "version", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "MISSING_PACKAGE_VERSION", ",", "path", "]", ")", ";", "}", "else", "if", "(", "!", "semver", ".", "valid", "(", "metadata", ".", "version", ")", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "INVALID_VERSION_NUMBER", ",", "metadata", ".", "version", ",", "path", "]", ")", ";", "}", "// normalize the author", "if", "(", "metadata", ".", "author", ")", "{", "metadata", ".", "author", "=", "parsePersonString", "(", "metadata", ".", "author", ")", ";", "}", "// contributors should be an array of people.", "// normalize each entry.", "if", "(", "metadata", ".", "contributors", ")", "{", "if", "(", "metadata", ".", "contributors", ".", "map", ")", "{", "metadata", ".", "contributors", "=", "metadata", ".", "contributors", ".", "map", "(", "function", "(", "person", ")", "{", "return", "parsePersonString", "(", "person", ")", ";", "}", ")", ";", "}", "else", "{", "metadata", ".", "contributors", "=", "[", "parsePersonString", "(", "metadata", ".", "contributors", ")", "]", ";", "}", "}", "if", "(", "metadata", ".", "engines", "&&", "metadata", ".", "engines", ".", "brackets", ")", "{", "var", "range", "=", "metadata", ".", "engines", ".", "brackets", ";", "if", "(", "!", "semver", ".", "validRange", "(", "range", ")", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "INVALID_BRACKETS_VERSION", ",", "range", ",", "path", "]", ")", ";", "}", "}", "if", "(", "options", ".", "disallowedWords", ")", "{", "[", "\"title\"", ",", "\"description\"", ",", "\"name\"", "]", ".", "forEach", "(", "function", "(", "field", ")", "{", "var", "words", "=", "containsWords", "(", "options", ".", "disallowedWords", ",", "metadata", "[", "field", "]", ")", ";", "if", "(", "words", ".", "length", ">", "0", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "DISALLOWED_WORDS", ",", "field", ",", "words", ".", "toString", "(", ")", ",", "path", "]", ")", ";", "}", "}", ")", ";", "}", "callback", "(", "null", ",", "errors", ",", "metadata", ")", ";", "}", ")", ";", "}", "else", "{", "if", "(", "options", ".", "requirePackageJSON", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "MISSING_PACKAGE_JSON", ",", "path", "]", ")", ";", "}", "callback", "(", "null", ",", "errors", ",", "null", ")", ";", "}", "}" ]
Validates the contents of package.json. @param {string} path path to package file (used in error reporting) @param {string} packageJSON path to the package.json file to check @param {Object} options validation options passed to `validate()` @param {function(Error, Array.<Array.<string, ...>>, Object)} callback function to call with array of errors and metadata
[ "Validates", "the", "contents", "of", "package", ".", "json", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L183-L258
2,461
adobe/brackets
src/extensibility/node/package-validator.js
extractAndValidateFiles
function extractAndValidateFiles(zipPath, extractDir, options, callback) { var unzipper = new DecompressZip(zipPath); unzipper.on("error", function (err) { // General error to report for problems reading the file callback(null, { errors: [[Errors.INVALID_ZIP_FILE, zipPath, err]] }); return; }); unzipper.on("extract", function (log) { findCommonPrefix(extractDir, function (err, commonPrefix) { if (err) { callback(err, null); return; } var packageJSON = path.join(extractDir, commonPrefix, "package.json"); validatePackageJSON(zipPath, packageJSON, options, function (err, errors, metadata) { if (err) { callback(err, null); return; } var mainJS = path.join(extractDir, commonPrefix, "main.js"), isTheme = metadata && metadata.theme; // Throw missing main.js file only for non-theme extensions if (!isTheme && !fs.existsSync(mainJS)) { errors.push([Errors.MISSING_MAIN, zipPath, mainJS]); } var npmOptions = ['--production']; if (options.proxy) { npmOptions.push('--proxy ' + options.proxy); } if (process.platform.startsWith('win')) { // On Windows force a 32 bit build until nodejs 64 bit is supported. npmOptions.push('--arch=ia32'); npmOptions.push('--npm_config_arch=ia32'); npmOptions.push('--npm_config_target_arch=ia32'); } performNpmInstallIfRequired(npmOptions, { errors: errors, metadata: metadata, commonPrefix: commonPrefix, extractDir: extractDir }, callback); }); }); }); unzipper.extract({ path: extractDir, filter: function (file) { return file.type !== "SymbolicLink"; } }); }
javascript
function extractAndValidateFiles(zipPath, extractDir, options, callback) { var unzipper = new DecompressZip(zipPath); unzipper.on("error", function (err) { // General error to report for problems reading the file callback(null, { errors: [[Errors.INVALID_ZIP_FILE, zipPath, err]] }); return; }); unzipper.on("extract", function (log) { findCommonPrefix(extractDir, function (err, commonPrefix) { if (err) { callback(err, null); return; } var packageJSON = path.join(extractDir, commonPrefix, "package.json"); validatePackageJSON(zipPath, packageJSON, options, function (err, errors, metadata) { if (err) { callback(err, null); return; } var mainJS = path.join(extractDir, commonPrefix, "main.js"), isTheme = metadata && metadata.theme; // Throw missing main.js file only for non-theme extensions if (!isTheme && !fs.existsSync(mainJS)) { errors.push([Errors.MISSING_MAIN, zipPath, mainJS]); } var npmOptions = ['--production']; if (options.proxy) { npmOptions.push('--proxy ' + options.proxy); } if (process.platform.startsWith('win')) { // On Windows force a 32 bit build until nodejs 64 bit is supported. npmOptions.push('--arch=ia32'); npmOptions.push('--npm_config_arch=ia32'); npmOptions.push('--npm_config_target_arch=ia32'); } performNpmInstallIfRequired(npmOptions, { errors: errors, metadata: metadata, commonPrefix: commonPrefix, extractDir: extractDir }, callback); }); }); }); unzipper.extract({ path: extractDir, filter: function (file) { return file.type !== "SymbolicLink"; } }); }
[ "function", "extractAndValidateFiles", "(", "zipPath", ",", "extractDir", ",", "options", ",", "callback", ")", "{", "var", "unzipper", "=", "new", "DecompressZip", "(", "zipPath", ")", ";", "unzipper", ".", "on", "(", "\"error\"", ",", "function", "(", "err", ")", "{", "// General error to report for problems reading the file", "callback", "(", "null", ",", "{", "errors", ":", "[", "[", "Errors", ".", "INVALID_ZIP_FILE", ",", "zipPath", ",", "err", "]", "]", "}", ")", ";", "return", ";", "}", ")", ";", "unzipper", ".", "on", "(", "\"extract\"", ",", "function", "(", "log", ")", "{", "findCommonPrefix", "(", "extractDir", ",", "function", "(", "err", ",", "commonPrefix", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "err", ",", "null", ")", ";", "return", ";", "}", "var", "packageJSON", "=", "path", ".", "join", "(", "extractDir", ",", "commonPrefix", ",", "\"package.json\"", ")", ";", "validatePackageJSON", "(", "zipPath", ",", "packageJSON", ",", "options", ",", "function", "(", "err", ",", "errors", ",", "metadata", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "err", ",", "null", ")", ";", "return", ";", "}", "var", "mainJS", "=", "path", ".", "join", "(", "extractDir", ",", "commonPrefix", ",", "\"main.js\"", ")", ",", "isTheme", "=", "metadata", "&&", "metadata", ".", "theme", ";", "// Throw missing main.js file only for non-theme extensions", "if", "(", "!", "isTheme", "&&", "!", "fs", ".", "existsSync", "(", "mainJS", ")", ")", "{", "errors", ".", "push", "(", "[", "Errors", ".", "MISSING_MAIN", ",", "zipPath", ",", "mainJS", "]", ")", ";", "}", "var", "npmOptions", "=", "[", "'--production'", "]", ";", "if", "(", "options", ".", "proxy", ")", "{", "npmOptions", ".", "push", "(", "'--proxy '", "+", "options", ".", "proxy", ")", ";", "}", "if", "(", "process", ".", "platform", ".", "startsWith", "(", "'win'", ")", ")", "{", "// On Windows force a 32 bit build until nodejs 64 bit is supported.", "npmOptions", ".", "push", "(", "'--arch=ia32'", ")", ";", "npmOptions", ".", "push", "(", "'--npm_config_arch=ia32'", ")", ";", "npmOptions", ".", "push", "(", "'--npm_config_target_arch=ia32'", ")", ";", "}", "performNpmInstallIfRequired", "(", "npmOptions", ",", "{", "errors", ":", "errors", ",", "metadata", ":", "metadata", ",", "commonPrefix", ":", "commonPrefix", ",", "extractDir", ":", "extractDir", "}", ",", "callback", ")", ";", "}", ")", ";", "}", ")", ";", "}", ")", ";", "unzipper", ".", "extract", "(", "{", "path", ":", "extractDir", ",", "filter", ":", "function", "(", "file", ")", "{", "return", "file", ".", "type", "!==", "\"SymbolicLink\"", ";", "}", "}", ")", ";", "}" ]
Extracts the package into the given directory and then validates it. @param {string} zipPath path to package zip file @param {string} extractDir directory to extract package into @param {Object} options validation options @param {function(Error, {errors: Array, metadata: Object, commonPrefix: string, extractDir: string})} callback function to call with the result
[ "Extracts", "the", "package", "into", "the", "given", "directory", "and", "then", "validates", "it", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L268-L327
2,462
adobe/brackets
src/extensibility/node/package-validator.js
validate
function validate(path, options, callback) { options = options || {}; fs.exists(path, function (doesExist) { if (!doesExist) { callback(null, { errors: [[Errors.NOT_FOUND_ERR, path]] }); return; } temp.mkdir("bracketsPackage_", function _tempDirCreated(err, extractDir) { if (err) { callback(err, null); return; } extractAndValidateFiles(path, extractDir, options, callback); }); }); }
javascript
function validate(path, options, callback) { options = options || {}; fs.exists(path, function (doesExist) { if (!doesExist) { callback(null, { errors: [[Errors.NOT_FOUND_ERR, path]] }); return; } temp.mkdir("bracketsPackage_", function _tempDirCreated(err, extractDir) { if (err) { callback(err, null); return; } extractAndValidateFiles(path, extractDir, options, callback); }); }); }
[ "function", "validate", "(", "path", ",", "options", ",", "callback", ")", "{", "options", "=", "options", "||", "{", "}", ";", "fs", ".", "exists", "(", "path", ",", "function", "(", "doesExist", ")", "{", "if", "(", "!", "doesExist", ")", "{", "callback", "(", "null", ",", "{", "errors", ":", "[", "[", "Errors", ".", "NOT_FOUND_ERR", ",", "path", "]", "]", "}", ")", ";", "return", ";", "}", "temp", ".", "mkdir", "(", "\"bracketsPackage_\"", ",", "function", "_tempDirCreated", "(", "err", ",", "extractDir", ")", "{", "if", "(", "err", ")", "{", "callback", "(", "err", ",", "null", ")", ";", "return", ";", "}", "extractAndValidateFiles", "(", "path", ",", "extractDir", ",", "options", ",", "callback", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Implements the "validate" command in the "extensions" domain. Validates the zipped package at path. The "err" parameter of the callback is only set if there was an unexpected error. Otherwise, errors are reported in the result. The result object has an "errors" property. It is an array of arrays of strings. Each array in the array is a set of parameters that can be passed to StringUtils.format for internationalization. The array will be empty if there are no errors. The result will have a "metadata" property if the metadata was read successfully from package.json in the zip file. @param {string} path Absolute path to the package zip file @param {{requirePackageJSON: ?boolean, disallowedWords: ?Array.<string>, proxy: ?<string>}} options for validation @param {function} callback (err, result)
[ "Implements", "the", "validate", "command", "in", "the", "extensions", "domain", ".", "Validates", "the", "zipped", "package", "at", "path", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L348-L365
2,463
adobe/brackets
src/extensions/default/CodeFolding/foldhelpers/foldSelected.js
SelectionFold
function SelectionFold(cm, start) { if (!cm.somethingSelected()) { return; } var from = cm.getCursor("from"), to = cm.getCursor("to"); if (from.line === start.line) { return {from: from, to: to}; } }
javascript
function SelectionFold(cm, start) { if (!cm.somethingSelected()) { return; } var from = cm.getCursor("from"), to = cm.getCursor("to"); if (from.line === start.line) { return {from: from, to: to}; } }
[ "function", "SelectionFold", "(", "cm", ",", "start", ")", "{", "if", "(", "!", "cm", ".", "somethingSelected", "(", ")", ")", "{", "return", ";", "}", "var", "from", "=", "cm", ".", "getCursor", "(", "\"from\"", ")", ",", "to", "=", "cm", ".", "getCursor", "(", "\"to\"", ")", ";", "if", "(", "from", ".", "line", "===", "start", ".", "line", ")", "{", "return", "{", "from", ":", "from", ",", "to", ":", "to", "}", ";", "}", "}" ]
This helper returns the start and end range representing the current selection in the editor. @param {Object} cm The Codemirror instance @param {Object} start A Codemirror.Pos object {line, ch} representing the current line we are checking for fold ranges @returns {Object} The fold range, {from, to} representing the current selection.
[ "This", "helper", "returns", "the", "start", "and", "end", "range", "representing", "the", "current", "selection", "in", "the", "editor", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/foldhelpers/foldSelected.js#L17-L27
2,464
adobe/brackets
src/LiveDevelopment/Inspector/Inspector.js
_send
function _send(method, signature, varargs) { if (!_socket) { console.log("You must connect to the WebSocket before sending messages."); // FUTURE: Our current implementation closes and re-opens an inspector connection whenever // a new HTML file is selected. If done quickly enough, pending requests from the previous // connection could come in before the new socket connection is established. For now we // simply ignore this condition. // This race condition will go away once we support multiple inspector connections and turn // off auto re-opening when a new HTML file is selected. return (new $.Deferred()).reject().promise(); } var id, callback, args, i, params = {}, promise, msg; // extract the parameters, the callback function, and the message id args = Array.prototype.slice.call(arguments, 2); if (typeof args[args.length - 1] === "function") { callback = args.pop(); } else { var deferred = new $.Deferred(); promise = deferred.promise(); callback = function (result, error) { if (error) { deferred.reject(error); } else { deferred.resolve(result); } }; } id = _messageId++; // verify the parameters against the method signature // this also constructs the params object of type {name -> value} if (signature) { for (i in signature) { if (_verifySignature(args[i], signature[i])) { params[signature[i].name] = args[i]; } } } // Store message callback and send message msg = { method: method, id: id, params: params }; _messageCallbacks[id] = { callback: callback, message: msg }; _socket.send(JSON.stringify(msg)); return promise; }
javascript
function _send(method, signature, varargs) { if (!_socket) { console.log("You must connect to the WebSocket before sending messages."); // FUTURE: Our current implementation closes and re-opens an inspector connection whenever // a new HTML file is selected. If done quickly enough, pending requests from the previous // connection could come in before the new socket connection is established. For now we // simply ignore this condition. // This race condition will go away once we support multiple inspector connections and turn // off auto re-opening when a new HTML file is selected. return (new $.Deferred()).reject().promise(); } var id, callback, args, i, params = {}, promise, msg; // extract the parameters, the callback function, and the message id args = Array.prototype.slice.call(arguments, 2); if (typeof args[args.length - 1] === "function") { callback = args.pop(); } else { var deferred = new $.Deferred(); promise = deferred.promise(); callback = function (result, error) { if (error) { deferred.reject(error); } else { deferred.resolve(result); } }; } id = _messageId++; // verify the parameters against the method signature // this also constructs the params object of type {name -> value} if (signature) { for (i in signature) { if (_verifySignature(args[i], signature[i])) { params[signature[i].name] = args[i]; } } } // Store message callback and send message msg = { method: method, id: id, params: params }; _messageCallbacks[id] = { callback: callback, message: msg }; _socket.send(JSON.stringify(msg)); return promise; }
[ "function", "_send", "(", "method", ",", "signature", ",", "varargs", ")", "{", "if", "(", "!", "_socket", ")", "{", "console", ".", "log", "(", "\"You must connect to the WebSocket before sending messages.\"", ")", ";", "// FUTURE: Our current implementation closes and re-opens an inspector connection whenever", "// a new HTML file is selected. If done quickly enough, pending requests from the previous", "// connection could come in before the new socket connection is established. For now we", "// simply ignore this condition.", "// This race condition will go away once we support multiple inspector connections and turn", "// off auto re-opening when a new HTML file is selected.", "return", "(", "new", "$", ".", "Deferred", "(", ")", ")", ".", "reject", "(", ")", ".", "promise", "(", ")", ";", "}", "var", "id", ",", "callback", ",", "args", ",", "i", ",", "params", "=", "{", "}", ",", "promise", ",", "msg", ";", "// extract the parameters, the callback function, and the message id", "args", "=", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ",", "2", ")", ";", "if", "(", "typeof", "args", "[", "args", ".", "length", "-", "1", "]", "===", "\"function\"", ")", "{", "callback", "=", "args", ".", "pop", "(", ")", ";", "}", "else", "{", "var", "deferred", "=", "new", "$", ".", "Deferred", "(", ")", ";", "promise", "=", "deferred", ".", "promise", "(", ")", ";", "callback", "=", "function", "(", "result", ",", "error", ")", "{", "if", "(", "error", ")", "{", "deferred", ".", "reject", "(", "error", ")", ";", "}", "else", "{", "deferred", ".", "resolve", "(", "result", ")", ";", "}", "}", ";", "}", "id", "=", "_messageId", "++", ";", "// verify the parameters against the method signature", "// this also constructs the params object of type {name -> value}", "if", "(", "signature", ")", "{", "for", "(", "i", "in", "signature", ")", "{", "if", "(", "_verifySignature", "(", "args", "[", "i", "]", ",", "signature", "[", "i", "]", ")", ")", "{", "params", "[", "signature", "[", "i", "]", ".", "name", "]", "=", "args", "[", "i", "]", ";", "}", "}", "}", "// Store message callback and send message", "msg", "=", "{", "method", ":", "method", ",", "id", ":", "id", ",", "params", ":", "params", "}", ";", "_messageCallbacks", "[", "id", "]", "=", "{", "callback", ":", "callback", ",", "message", ":", "msg", "}", ";", "_socket", ".", "send", "(", "JSON", ".", "stringify", "(", "msg", ")", ")", ";", "return", "promise", ";", "}" ]
Send a message to the remote debugger All passed arguments after the signature are passed on as parameters. If the last argument is a function, it is used as the callback function. @param {string} remote method @param {object} the method signature
[ "Send", "a", "message", "to", "the", "remote", "debugger", "All", "passed", "arguments", "after", "the", "signature", "are", "passed", "on", "as", "parameters", ".", "If", "the", "last", "argument", "is", "a", "function", "it", "is", "used", "as", "the", "callback", "function", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L117-L166
2,465
adobe/brackets
src/LiveDevelopment/Inspector/Inspector.js
_onError
function _onError(error) { if (_connectDeferred) { _connectDeferred.reject(); _connectDeferred = null; } exports.trigger("error", error); }
javascript
function _onError(error) { if (_connectDeferred) { _connectDeferred.reject(); _connectDeferred = null; } exports.trigger("error", error); }
[ "function", "_onError", "(", "error", ")", "{", "if", "(", "_connectDeferred", ")", "{", "_connectDeferred", ".", "reject", "(", ")", ";", "_connectDeferred", "=", "null", ";", "}", "exports", ".", "trigger", "(", "\"error\"", ",", "error", ")", ";", "}" ]
WebSocket reported an error
[ "WebSocket", "reported", "an", "error" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L186-L192
2,466
adobe/brackets
src/LiveDevelopment/Inspector/Inspector.js
disconnect
function disconnect() { var deferred = new $.Deferred(), promise = deferred.promise(); if (_socket && (_socket.readyState === WebSocket.OPEN)) { _socket.onclose = function () { // trigger disconnect event _onDisconnect(); deferred.resolve(); }; promise = Async.withTimeout(promise, 5000); _socket.close(); } else { if (_socket) { delete _socket.onmessage; delete _socket.onopen; delete _socket.onclose; delete _socket.onerror; _socket = undefined; } deferred.resolve(); } return promise; }
javascript
function disconnect() { var deferred = new $.Deferred(), promise = deferred.promise(); if (_socket && (_socket.readyState === WebSocket.OPEN)) { _socket.onclose = function () { // trigger disconnect event _onDisconnect(); deferred.resolve(); }; promise = Async.withTimeout(promise, 5000); _socket.close(); } else { if (_socket) { delete _socket.onmessage; delete _socket.onopen; delete _socket.onclose; delete _socket.onerror; _socket = undefined; } deferred.resolve(); } return promise; }
[ "function", "disconnect", "(", ")", "{", "var", "deferred", "=", "new", "$", ".", "Deferred", "(", ")", ",", "promise", "=", "deferred", ".", "promise", "(", ")", ";", "if", "(", "_socket", "&&", "(", "_socket", ".", "readyState", "===", "WebSocket", ".", "OPEN", ")", ")", "{", "_socket", ".", "onclose", "=", "function", "(", ")", "{", "// trigger disconnect event", "_onDisconnect", "(", ")", ";", "deferred", ".", "resolve", "(", ")", ";", "}", ";", "promise", "=", "Async", ".", "withTimeout", "(", "promise", ",", "5000", ")", ";", "_socket", ".", "close", "(", ")", ";", "}", "else", "{", "if", "(", "_socket", ")", "{", "delete", "_socket", ".", "onmessage", ";", "delete", "_socket", ".", "onopen", ";", "delete", "_socket", ".", "onclose", ";", "delete", "_socket", ".", "onerror", ";", "_socket", "=", "undefined", ";", "}", "deferred", ".", "resolve", "(", ")", ";", "}", "return", "promise", ";", "}" ]
Disconnect from the remote debugger WebSocket @return {jQuery.Promise} Promise that is resolved immediately if not currently connected or asynchronously when the socket is closed.
[ "Disconnect", "from", "the", "remote", "debugger", "WebSocket" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L272-L301
2,467
adobe/brackets
src/LiveDevelopment/Inspector/Inspector.js
connect
function connect(socketURL) { disconnect().done(function () { _socket = new WebSocket(socketURL); _socket.onmessage = _onMessage; _socket.onopen = _onConnect; _socket.onclose = _onDisconnect; _socket.onerror = _onError; }); }
javascript
function connect(socketURL) { disconnect().done(function () { _socket = new WebSocket(socketURL); _socket.onmessage = _onMessage; _socket.onopen = _onConnect; _socket.onclose = _onDisconnect; _socket.onerror = _onError; }); }
[ "function", "connect", "(", "socketURL", ")", "{", "disconnect", "(", ")", ".", "done", "(", "function", "(", ")", "{", "_socket", "=", "new", "WebSocket", "(", "socketURL", ")", ";", "_socket", ".", "onmessage", "=", "_onMessage", ";", "_socket", ".", "onopen", "=", "_onConnect", ";", "_socket", ".", "onclose", "=", "_onDisconnect", ";", "_socket", ".", "onerror", "=", "_onError", ";", "}", ")", ";", "}" ]
Connect to the remote debugger WebSocket at the given URL. Clients must listen for the `connect` event. @param {string} WebSocket URL
[ "Connect", "to", "the", "remote", "debugger", "WebSocket", "at", "the", "given", "URL", ".", "Clients", "must", "listen", "for", "the", "connect", "event", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L308-L316
2,468
adobe/brackets
src/LiveDevelopment/Inspector/Inspector.js
connectToURL
function connectToURL(url) { if (_connectDeferred) { // reject an existing connection attempt _connectDeferred.reject("CANCEL"); } var deferred = new $.Deferred(); _connectDeferred = deferred; var promise = getDebuggableWindows(); promise.done(function onGetAvailableSockets(response) { var i, page; for (i in response) { page = response[i]; if (page.webSocketDebuggerUrl && page.url.indexOf(url) === 0) { connect(page.webSocketDebuggerUrl); // _connectDeferred may be resolved by onConnect or rejected by onError return; } } deferred.reject(FileError.ERR_NOT_FOUND); // Reject with a "not found" error }); promise.fail(function onFail(err) { deferred.reject(err); }); return deferred.promise(); }
javascript
function connectToURL(url) { if (_connectDeferred) { // reject an existing connection attempt _connectDeferred.reject("CANCEL"); } var deferred = new $.Deferred(); _connectDeferred = deferred; var promise = getDebuggableWindows(); promise.done(function onGetAvailableSockets(response) { var i, page; for (i in response) { page = response[i]; if (page.webSocketDebuggerUrl && page.url.indexOf(url) === 0) { connect(page.webSocketDebuggerUrl); // _connectDeferred may be resolved by onConnect or rejected by onError return; } } deferred.reject(FileError.ERR_NOT_FOUND); // Reject with a "not found" error }); promise.fail(function onFail(err) { deferred.reject(err); }); return deferred.promise(); }
[ "function", "connectToURL", "(", "url", ")", "{", "if", "(", "_connectDeferred", ")", "{", "// reject an existing connection attempt", "_connectDeferred", ".", "reject", "(", "\"CANCEL\"", ")", ";", "}", "var", "deferred", "=", "new", "$", ".", "Deferred", "(", ")", ";", "_connectDeferred", "=", "deferred", ";", "var", "promise", "=", "getDebuggableWindows", "(", ")", ";", "promise", ".", "done", "(", "function", "onGetAvailableSockets", "(", "response", ")", "{", "var", "i", ",", "page", ";", "for", "(", "i", "in", "response", ")", "{", "page", "=", "response", "[", "i", "]", ";", "if", "(", "page", ".", "webSocketDebuggerUrl", "&&", "page", ".", "url", ".", "indexOf", "(", "url", ")", "===", "0", ")", "{", "connect", "(", "page", ".", "webSocketDebuggerUrl", ")", ";", "// _connectDeferred may be resolved by onConnect or rejected by onError", "return", ";", "}", "}", "deferred", ".", "reject", "(", "FileError", ".", "ERR_NOT_FOUND", ")", ";", "// Reject with a \"not found\" error", "}", ")", ";", "promise", ".", "fail", "(", "function", "onFail", "(", "err", ")", "{", "deferred", ".", "reject", "(", "err", ")", ";", "}", ")", ";", "return", "deferred", ".", "promise", "(", ")", ";", "}" ]
Connect to the remote debugger of the page that is at the given URL @param {string} url
[ "Connect", "to", "the", "remote", "debugger", "of", "the", "page", "that", "is", "at", "the", "given", "URL" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L321-L345
2,469
adobe/brackets
src/widgets/StatusBar.js
showBusyIndicator
function showBusyIndicator(updateCursor) { if (!_init) { console.error("StatusBar API invoked before status bar created"); return; } if (updateCursor) { _busyCursor = true; $("*").addClass("busyCursor"); } $busyIndicator.addClass("spin"); }
javascript
function showBusyIndicator(updateCursor) { if (!_init) { console.error("StatusBar API invoked before status bar created"); return; } if (updateCursor) { _busyCursor = true; $("*").addClass("busyCursor"); } $busyIndicator.addClass("spin"); }
[ "function", "showBusyIndicator", "(", "updateCursor", ")", "{", "if", "(", "!", "_init", ")", "{", "console", ".", "error", "(", "\"StatusBar API invoked before status bar created\"", ")", ";", "return", ";", "}", "if", "(", "updateCursor", ")", "{", "_busyCursor", "=", "true", ";", "$", "(", "\"*\"", ")", ".", "addClass", "(", "\"busyCursor\"", ")", ";", "}", "$busyIndicator", ".", "addClass", "(", "\"spin\"", ")", ";", "}" ]
Shows the 'busy' indicator @param {boolean} updateCursor Sets the cursor to "wait"
[ "Shows", "the", "busy", "indicator" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/StatusBar.js#L58-L70
2,470
adobe/brackets
src/widgets/StatusBar.js
addIndicator
function addIndicator(id, indicator, visible, style, tooltip, insertBefore) { if (!_init) { console.error("StatusBar API invoked before status bar created"); return; } indicator = indicator || window.document.createElement("div"); tooltip = tooltip || ""; style = style || ""; id = id.replace(_indicatorIDRegexp, "-") || ""; var $indicator = $(indicator); $indicator.attr("id", id); $indicator.attr("title", tooltip); $indicator.addClass("indicator"); $indicator.addClass(style); if (!visible) { $indicator.hide(); } // This code looks backwards because the DOM model is ordered // top-to-bottom but the UI view is ordered right-to-left. The concept // of "before" in the model is "after" in the view, and vice versa. if (insertBefore && $("#" + insertBefore).length > 0) { $indicator.insertAfter("#" + insertBefore); } else { // No positioning is provided, put on left end of indicators, but // to right of "busy" indicator (which is usually hidden). var $busyIndicator = $("#status-bar .spinner"); $indicator.insertBefore($busyIndicator); } }
javascript
function addIndicator(id, indicator, visible, style, tooltip, insertBefore) { if (!_init) { console.error("StatusBar API invoked before status bar created"); return; } indicator = indicator || window.document.createElement("div"); tooltip = tooltip || ""; style = style || ""; id = id.replace(_indicatorIDRegexp, "-") || ""; var $indicator = $(indicator); $indicator.attr("id", id); $indicator.attr("title", tooltip); $indicator.addClass("indicator"); $indicator.addClass(style); if (!visible) { $indicator.hide(); } // This code looks backwards because the DOM model is ordered // top-to-bottom but the UI view is ordered right-to-left. The concept // of "before" in the model is "after" in the view, and vice versa. if (insertBefore && $("#" + insertBefore).length > 0) { $indicator.insertAfter("#" + insertBefore); } else { // No positioning is provided, put on left end of indicators, but // to right of "busy" indicator (which is usually hidden). var $busyIndicator = $("#status-bar .spinner"); $indicator.insertBefore($busyIndicator); } }
[ "function", "addIndicator", "(", "id", ",", "indicator", ",", "visible", ",", "style", ",", "tooltip", ",", "insertBefore", ")", "{", "if", "(", "!", "_init", ")", "{", "console", ".", "error", "(", "\"StatusBar API invoked before status bar created\"", ")", ";", "return", ";", "}", "indicator", "=", "indicator", "||", "window", ".", "document", ".", "createElement", "(", "\"div\"", ")", ";", "tooltip", "=", "tooltip", "||", "\"\"", ";", "style", "=", "style", "||", "\"\"", ";", "id", "=", "id", ".", "replace", "(", "_indicatorIDRegexp", ",", "\"-\"", ")", "||", "\"\"", ";", "var", "$indicator", "=", "$", "(", "indicator", ")", ";", "$indicator", ".", "attr", "(", "\"id\"", ",", "id", ")", ";", "$indicator", ".", "attr", "(", "\"title\"", ",", "tooltip", ")", ";", "$indicator", ".", "addClass", "(", "\"indicator\"", ")", ";", "$indicator", ".", "addClass", "(", "style", ")", ";", "if", "(", "!", "visible", ")", "{", "$indicator", ".", "hide", "(", ")", ";", "}", "// This code looks backwards because the DOM model is ordered", "// top-to-bottom but the UI view is ordered right-to-left. The concept", "// of \"before\" in the model is \"after\" in the view, and vice versa.", "if", "(", "insertBefore", "&&", "$", "(", "\"#\"", "+", "insertBefore", ")", ".", "length", ">", "0", ")", "{", "$indicator", ".", "insertAfter", "(", "\"#\"", "+", "insertBefore", ")", ";", "}", "else", "{", "// No positioning is provided, put on left end of indicators, but", "// to right of \"busy\" indicator (which is usually hidden).", "var", "$busyIndicator", "=", "$", "(", "\"#status-bar .spinner\"", ")", ";", "$indicator", ".", "insertBefore", "(", "$busyIndicator", ")", ";", "}", "}" ]
Registers a new status indicator @param {string} id Registration id of the indicator to be updated. @param {(DOMNode|jQueryObject)=} indicator Optional DOMNode for the indicator @param {boolean=} visible Shows or hides the indicator over the statusbar. @param {string=} style Sets the attribute "class" of the indicator. @param {string=} tooltip Sets the attribute "title" of the indicator. @param {string=} insertBefore An id of an existing status bar indicator. The new indicator will be inserted before (i.e. to the left of) the indicator specified by this parameter.
[ "Registers", "a", "new", "status", "indicator" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/StatusBar.js#L102-L135
2,471
adobe/brackets
src/widgets/StatusBar.js
updateIndicator
function updateIndicator(id, visible, style, tooltip) { if (!_init && !!brackets.test) { console.error("StatusBar API invoked before status bar created"); return; } var $indicator = $("#" + id.replace(_indicatorIDRegexp, "-")); if ($indicator) { if (visible) { $indicator.show(); } else { $indicator.hide(); } if (style) { $indicator.removeClass(); $indicator.addClass(style); } else { $indicator.removeClass(); $indicator.addClass("indicator"); } if (tooltip) { $indicator.attr("title", tooltip); } } }
javascript
function updateIndicator(id, visible, style, tooltip) { if (!_init && !!brackets.test) { console.error("StatusBar API invoked before status bar created"); return; } var $indicator = $("#" + id.replace(_indicatorIDRegexp, "-")); if ($indicator) { if (visible) { $indicator.show(); } else { $indicator.hide(); } if (style) { $indicator.removeClass(); $indicator.addClass(style); } else { $indicator.removeClass(); $indicator.addClass("indicator"); } if (tooltip) { $indicator.attr("title", tooltip); } } }
[ "function", "updateIndicator", "(", "id", ",", "visible", ",", "style", ",", "tooltip", ")", "{", "if", "(", "!", "_init", "&&", "!", "!", "brackets", ".", "test", ")", "{", "console", ".", "error", "(", "\"StatusBar API invoked before status bar created\"", ")", ";", "return", ";", "}", "var", "$indicator", "=", "$", "(", "\"#\"", "+", "id", ".", "replace", "(", "_indicatorIDRegexp", ",", "\"-\"", ")", ")", ";", "if", "(", "$indicator", ")", "{", "if", "(", "visible", ")", "{", "$indicator", ".", "show", "(", ")", ";", "}", "else", "{", "$indicator", ".", "hide", "(", ")", ";", "}", "if", "(", "style", ")", "{", "$indicator", ".", "removeClass", "(", ")", ";", "$indicator", ".", "addClass", "(", "style", ")", ";", "}", "else", "{", "$indicator", ".", "removeClass", "(", ")", ";", "$indicator", ".", "addClass", "(", "\"indicator\"", ")", ";", "}", "if", "(", "tooltip", ")", "{", "$indicator", ".", "attr", "(", "\"title\"", ",", "tooltip", ")", ";", "}", "}", "}" ]
Updates a status indicator @param {string} id Registration id of the indicator to be updated. @param {boolean} visible Shows or hides the indicator over the statusbar. @param {string=} style Sets the attribute "class" of the indicator. @param {string=} tooltip Sets the attribute "title" of the indicator.
[ "Updates", "a", "status", "indicator" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/StatusBar.js#L144-L172
2,472
adobe/brackets
src/view/ThemeView.js
updateScrollbars
function updateScrollbars(theme) { theme = theme || {}; if (prefs.get("themeScrollbars")) { var scrollbar = (theme.scrollbar || []).join(" "); $scrollbars.text(scrollbar || ""); } else { $scrollbars.text(""); } }
javascript
function updateScrollbars(theme) { theme = theme || {}; if (prefs.get("themeScrollbars")) { var scrollbar = (theme.scrollbar || []).join(" "); $scrollbars.text(scrollbar || ""); } else { $scrollbars.text(""); } }
[ "function", "updateScrollbars", "(", "theme", ")", "{", "theme", "=", "theme", "||", "{", "}", ";", "if", "(", "prefs", ".", "get", "(", "\"themeScrollbars\"", ")", ")", "{", "var", "scrollbar", "=", "(", "theme", ".", "scrollbar", "||", "[", "]", ")", ".", "join", "(", "\" \"", ")", ";", "$scrollbars", ".", "text", "(", "scrollbar", "||", "\"\"", ")", ";", "}", "else", "{", "$scrollbars", ".", "text", "(", "\"\"", ")", ";", "}", "}" ]
Load scrollbar styling based on whether or not theme scrollbars are enabled. @param {ThemeManager.Theme} theme Is the theme object with the corresponding scrollbar style to be updated
[ "Load", "scrollbar", "styling", "based", "on", "whether", "or", "not", "theme", "scrollbars", "are", "enabled", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ThemeView.js#L40-L48
2,473
adobe/brackets
src/view/ThemeView.js
updateThemes
function updateThemes(cm) { var newTheme = prefs.get("theme"), cmTheme = (cm.getOption("theme") || "").replace(/[\s]*/, ""); // Normalize themes string // Check if the editor already has the theme applied... if (cmTheme === newTheme) { return; } // Setup current and further documents to get the new theme... CodeMirror.defaults.theme = newTheme; cm.setOption("theme", newTheme); }
javascript
function updateThemes(cm) { var newTheme = prefs.get("theme"), cmTheme = (cm.getOption("theme") || "").replace(/[\s]*/, ""); // Normalize themes string // Check if the editor already has the theme applied... if (cmTheme === newTheme) { return; } // Setup current and further documents to get the new theme... CodeMirror.defaults.theme = newTheme; cm.setOption("theme", newTheme); }
[ "function", "updateThemes", "(", "cm", ")", "{", "var", "newTheme", "=", "prefs", ".", "get", "(", "\"theme\"", ")", ",", "cmTheme", "=", "(", "cm", ".", "getOption", "(", "\"theme\"", ")", "||", "\"\"", ")", ".", "replace", "(", "/", "[\\s]*", "/", ",", "\"\"", ")", ";", "// Normalize themes string", "// Check if the editor already has the theme applied...", "if", "(", "cmTheme", "===", "newTheme", ")", "{", "return", ";", "}", "// Setup current and further documents to get the new theme...", "CodeMirror", ".", "defaults", ".", "theme", "=", "newTheme", ";", "cm", ".", "setOption", "(", "\"theme\"", ",", "newTheme", ")", ";", "}" ]
Handles updating codemirror with the current selection of themes. @param {CodeMirror} cm is the CodeMirror instance currently loaded
[ "Handles", "updating", "codemirror", "with", "the", "current", "selection", "of", "themes", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ThemeView.js#L56-L68
2,474
adobe/brackets
src/project/ProjectManager.js
getSelectedItem
function getSelectedItem() { // Prefer file tree context, then file tree selection, else use working set var selectedEntry = getFileTreeContext(); if (!selectedEntry) { selectedEntry = model.getSelected(); } if (!selectedEntry) { selectedEntry = MainViewManager.getCurrentlyViewedFile(); } return selectedEntry; }
javascript
function getSelectedItem() { // Prefer file tree context, then file tree selection, else use working set var selectedEntry = getFileTreeContext(); if (!selectedEntry) { selectedEntry = model.getSelected(); } if (!selectedEntry) { selectedEntry = MainViewManager.getCurrentlyViewedFile(); } return selectedEntry; }
[ "function", "getSelectedItem", "(", ")", "{", "// Prefer file tree context, then file tree selection, else use working set", "var", "selectedEntry", "=", "getFileTreeContext", "(", ")", ";", "if", "(", "!", "selectedEntry", ")", "{", "selectedEntry", "=", "model", ".", "getSelected", "(", ")", ";", "}", "if", "(", "!", "selectedEntry", ")", "{", "selectedEntry", "=", "MainViewManager", ".", "getCurrentlyViewedFile", "(", ")", ";", "}", "return", "selectedEntry", ";", "}" ]
Returns the File or Directory corresponding to the item selected in the sidebar panel, whether in the file tree OR in the working set; or null if no item is selected anywhere in the sidebar. May NOT be identical to the current Document - a folder may be selected in the sidebar, or the sidebar may not have the current document visible in the tree & working set. @return {?(File|Directory)}
[ "Returns", "the", "File", "or", "Directory", "corresponding", "to", "the", "item", "selected", "in", "the", "sidebar", "panel", "whether", "in", "the", "file", "tree", "OR", "in", "the", "working", "set", ";", "or", "null", "if", "no", "item", "is", "selected", "anywhere", "in", "the", "sidebar", ".", "May", "NOT", "be", "identical", "to", "the", "current", "Document", "-", "a", "folder", "may", "be", "selected", "in", "the", "sidebar", "or", "the", "sidebar", "may", "not", "have", "the", "current", "document", "visible", "in", "the", "tree", "&", "working", "set", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L441-L451
2,475
adobe/brackets
src/project/ProjectManager.js
setBaseUrl
function setBaseUrl(projectBaseUrl) { var context = _getProjectViewStateContext(); projectBaseUrl = model.setBaseUrl(projectBaseUrl); PreferencesManager.setViewState("project.baseUrl", projectBaseUrl, context); }
javascript
function setBaseUrl(projectBaseUrl) { var context = _getProjectViewStateContext(); projectBaseUrl = model.setBaseUrl(projectBaseUrl); PreferencesManager.setViewState("project.baseUrl", projectBaseUrl, context); }
[ "function", "setBaseUrl", "(", "projectBaseUrl", ")", "{", "var", "context", "=", "_getProjectViewStateContext", "(", ")", ";", "projectBaseUrl", "=", "model", ".", "setBaseUrl", "(", "projectBaseUrl", ")", ";", "PreferencesManager", ".", "setViewState", "(", "\"project.baseUrl\"", ",", "projectBaseUrl", ",", "context", ")", ";", "}" ]
Sets the encoded Base URL of the currently loaded project. @param {String}
[ "Sets", "the", "encoded", "Base", "URL", "of", "the", "currently", "loaded", "project", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L514-L520
2,476
adobe/brackets
src/project/ProjectManager.js
addWelcomeProjectPath
function addWelcomeProjectPath(path) { var welcomeProjects = ProjectModel._addWelcomeProjectPath(path, PreferencesManager.getViewState("welcomeProjects")); PreferencesManager.setViewState("welcomeProjects", welcomeProjects); }
javascript
function addWelcomeProjectPath(path) { var welcomeProjects = ProjectModel._addWelcomeProjectPath(path, PreferencesManager.getViewState("welcomeProjects")); PreferencesManager.setViewState("welcomeProjects", welcomeProjects); }
[ "function", "addWelcomeProjectPath", "(", "path", ")", "{", "var", "welcomeProjects", "=", "ProjectModel", ".", "_addWelcomeProjectPath", "(", "path", ",", "PreferencesManager", ".", "getViewState", "(", "\"welcomeProjects\"", ")", ")", ";", "PreferencesManager", ".", "setViewState", "(", "\"welcomeProjects\"", ",", "welcomeProjects", ")", ";", "}" ]
Adds the path to the list of welcome projects we've ever seen, if not on the list already. @param {string} path Path to possibly add
[ "Adds", "the", "path", "to", "the", "list", "of", "welcome", "projects", "we", "ve", "ever", "seen", "if", "not", "on", "the", "list", "already", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L700-L704
2,477
adobe/brackets
src/project/ProjectManager.js
_getFallbackProjectPath
function _getFallbackProjectPath() { var fallbackPaths = [], recentProjects = PreferencesManager.getViewState("recentProjects") || [], deferred = new $.Deferred(); // Build ordered fallback path array if (recentProjects.length > 1) { // *Most* recent project is the one that just failed to load, so use second most recent fallbackPaths.push(recentProjects[1]); } // Next is Getting Started project fallbackPaths.push(_getWelcomeProjectPath()); // Helper func for Async.firstSequentially() function processItem(path) { var deferred = new $.Deferred(), fileEntry = FileSystem.getDirectoryForPath(path); fileEntry.exists(function (err, exists) { if (!err && exists) { deferred.resolve(); } else { deferred.reject(); } }); return deferred.promise(); } // Find first path that exists Async.firstSequentially(fallbackPaths, processItem) .done(function (fallbackPath) { deferred.resolve(fallbackPath); }) .fail(function () { // Last resort is Brackets source folder which is guaranteed to exist deferred.resolve(FileUtils.getNativeBracketsDirectoryPath()); }); return deferred.promise(); }
javascript
function _getFallbackProjectPath() { var fallbackPaths = [], recentProjects = PreferencesManager.getViewState("recentProjects") || [], deferred = new $.Deferred(); // Build ordered fallback path array if (recentProjects.length > 1) { // *Most* recent project is the one that just failed to load, so use second most recent fallbackPaths.push(recentProjects[1]); } // Next is Getting Started project fallbackPaths.push(_getWelcomeProjectPath()); // Helper func for Async.firstSequentially() function processItem(path) { var deferred = new $.Deferred(), fileEntry = FileSystem.getDirectoryForPath(path); fileEntry.exists(function (err, exists) { if (!err && exists) { deferred.resolve(); } else { deferred.reject(); } }); return deferred.promise(); } // Find first path that exists Async.firstSequentially(fallbackPaths, processItem) .done(function (fallbackPath) { deferred.resolve(fallbackPath); }) .fail(function () { // Last resort is Brackets source folder which is guaranteed to exist deferred.resolve(FileUtils.getNativeBracketsDirectoryPath()); }); return deferred.promise(); }
[ "function", "_getFallbackProjectPath", "(", ")", "{", "var", "fallbackPaths", "=", "[", "]", ",", "recentProjects", "=", "PreferencesManager", ".", "getViewState", "(", "\"recentProjects\"", ")", "||", "[", "]", ",", "deferred", "=", "new", "$", ".", "Deferred", "(", ")", ";", "// Build ordered fallback path array", "if", "(", "recentProjects", ".", "length", ">", "1", ")", "{", "// *Most* recent project is the one that just failed to load, so use second most recent", "fallbackPaths", ".", "push", "(", "recentProjects", "[", "1", "]", ")", ";", "}", "// Next is Getting Started project", "fallbackPaths", ".", "push", "(", "_getWelcomeProjectPath", "(", ")", ")", ";", "// Helper func for Async.firstSequentially()", "function", "processItem", "(", "path", ")", "{", "var", "deferred", "=", "new", "$", ".", "Deferred", "(", ")", ",", "fileEntry", "=", "FileSystem", ".", "getDirectoryForPath", "(", "path", ")", ";", "fileEntry", ".", "exists", "(", "function", "(", "err", ",", "exists", ")", "{", "if", "(", "!", "err", "&&", "exists", ")", "{", "deferred", ".", "resolve", "(", ")", ";", "}", "else", "{", "deferred", ".", "reject", "(", ")", ";", "}", "}", ")", ";", "return", "deferred", ".", "promise", "(", ")", ";", "}", "// Find first path that exists", "Async", ".", "firstSequentially", "(", "fallbackPaths", ",", "processItem", ")", ".", "done", "(", "function", "(", "fallbackPath", ")", "{", "deferred", ".", "resolve", "(", "fallbackPath", ")", ";", "}", ")", ".", "fail", "(", "function", "(", ")", "{", "// Last resort is Brackets source folder which is guaranteed to exist", "deferred", ".", "resolve", "(", "FileUtils", ".", "getNativeBracketsDirectoryPath", "(", ")", ")", ";", "}", ")", ";", "return", "deferred", ".", "promise", "(", ")", ";", "}" ]
After failing to load a project, this function determines which project path to fallback to. @return {$.Promise} Promise that resolves to a project path {string}
[ "After", "failing", "to", "load", "a", "project", "this", "function", "determines", "which", "project", "path", "to", "fallback", "to", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L733-L774
2,478
adobe/brackets
src/project/ProjectManager.js
openProject
function openProject(path) { var result = new $.Deferred(); // 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 () { if (path) { // use specified path _loadProject(path, false).then(result.resolve, result.reject); } else { // Pop up a folder browse dialog FileSystem.showOpenDialog(false, true, Strings.CHOOSE_FOLDER, model.projectRoot.fullPath, null, function (err, files) { if (!err) { // If length == 0, user canceled the dialog; length should never be > 1 if (files.length > 0) { // Load the new project into the folder tree _loadProject(files[0]).then(result.resolve, result.reject); } else { result.reject(); } } else { _showErrorDialog(ERR_TYPE_OPEN_DIALOG, null, err); result.reject(); } }); } }) .fail(function () { result.reject(); }); // if fail, don't open new project: user canceled (or we failed to save its unsaved changes) return result.promise(); }
javascript
function openProject(path) { var result = new $.Deferred(); // 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 () { if (path) { // use specified path _loadProject(path, false).then(result.resolve, result.reject); } else { // Pop up a folder browse dialog FileSystem.showOpenDialog(false, true, Strings.CHOOSE_FOLDER, model.projectRoot.fullPath, null, function (err, files) { if (!err) { // If length == 0, user canceled the dialog; length should never be > 1 if (files.length > 0) { // Load the new project into the folder tree _loadProject(files[0]).then(result.resolve, result.reject); } else { result.reject(); } } else { _showErrorDialog(ERR_TYPE_OPEN_DIALOG, null, err); result.reject(); } }); } }) .fail(function () { result.reject(); }); // if fail, don't open new project: user canceled (or we failed to save its unsaved changes) return result.promise(); }
[ "function", "openProject", "(", "path", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ";", "// 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", "(", ")", "{", "if", "(", "path", ")", "{", "// use specified path", "_loadProject", "(", "path", ",", "false", ")", ".", "then", "(", "result", ".", "resolve", ",", "result", ".", "reject", ")", ";", "}", "else", "{", "// Pop up a folder browse dialog", "FileSystem", ".", "showOpenDialog", "(", "false", ",", "true", ",", "Strings", ".", "CHOOSE_FOLDER", ",", "model", ".", "projectRoot", ".", "fullPath", ",", "null", ",", "function", "(", "err", ",", "files", ")", "{", "if", "(", "!", "err", ")", "{", "// If length == 0, user canceled the dialog; length should never be > 1", "if", "(", "files", ".", "length", ">", "0", ")", "{", "// Load the new project into the folder tree", "_loadProject", "(", "files", "[", "0", "]", ")", ".", "then", "(", "result", ".", "resolve", ",", "result", ".", "reject", ")", ";", "}", "else", "{", "result", ".", "reject", "(", ")", ";", "}", "}", "else", "{", "_showErrorDialog", "(", "ERR_TYPE_OPEN_DIALOG", ",", "null", ",", "err", ")", ";", "result", ".", "reject", "(", ")", ";", "}", "}", ")", ";", "}", "}", ")", ".", "fail", "(", "function", "(", ")", "{", "result", ".", "reject", "(", ")", ";", "}", ")", ";", "// if fail, don't open new project: user canceled (or we failed to save its unsaved changes)", "return", "result", ".", "promise", "(", ")", ";", "}" ]
Open a new project. Currently, Brackets must always have a project open, so this method handles both closing the current project and opening a new project. @param {string=} path Optional absolute path to the root folder of the project. If path is undefined or null, displays a dialog where the user can choose a folder to load. If the user cancels the dialog, nothing more happens. @return {$.Promise} A promise object that will be resolved when the project is loaded and tree is rendered, or rejected if the project path fails to load.
[ "Open", "a", "new", "project", ".", "Currently", "Brackets", "must", "always", "have", "a", "project", "open", "so", "this", "method", "handles", "both", "closing", "the", "current", "project", "and", "opening", "a", "new", "project", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L1056-L1092
2,479
adobe/brackets
src/project/ProjectManager.js
createNewItem
function createNewItem(baseDir, initialName, skipRename, isFolder) { baseDir = model.getDirectoryInProject(baseDir); if (skipRename) { if(isFolder) { return model.createAtPath(baseDir + initialName + "/"); } return model.createAtPath(baseDir + initialName); } return actionCreator.startCreating(baseDir, initialName, isFolder); }
javascript
function createNewItem(baseDir, initialName, skipRename, isFolder) { baseDir = model.getDirectoryInProject(baseDir); if (skipRename) { if(isFolder) { return model.createAtPath(baseDir + initialName + "/"); } return model.createAtPath(baseDir + initialName); } return actionCreator.startCreating(baseDir, initialName, isFolder); }
[ "function", "createNewItem", "(", "baseDir", ",", "initialName", ",", "skipRename", ",", "isFolder", ")", "{", "baseDir", "=", "model", ".", "getDirectoryInProject", "(", "baseDir", ")", ";", "if", "(", "skipRename", ")", "{", "if", "(", "isFolder", ")", "{", "return", "model", ".", "createAtPath", "(", "baseDir", "+", "initialName", "+", "\"/\"", ")", ";", "}", "return", "model", ".", "createAtPath", "(", "baseDir", "+", "initialName", ")", ";", "}", "return", "actionCreator", ".", "startCreating", "(", "baseDir", ",", "initialName", ",", "isFolder", ")", ";", "}" ]
Create a new item in the current project. @param baseDir {string|Directory} Full path of the directory where the item should go. Defaults to the project root if the entry is not valid or not within the project. @param initialName {string} Initial name for the item @param skipRename {boolean} If true, don't allow the user to rename the item @param isFolder {boolean} If true, create a folder instead of a file @return {$.Promise} A promise object that will be resolved with the File of the created object, or rejected if the user cancelled or entered an illegal filename.
[ "Create", "a", "new", "item", "in", "the", "current", "project", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L1114-L1124
2,480
adobe/brackets
src/project/ProjectManager.js
deleteItem
function deleteItem(entry) { var result = new $.Deferred(); entry.moveToTrash(function (err) { if (!err) { DocumentManager.notifyPathDeleted(entry.fullPath); result.resolve(); } else { _showErrorDialog(ERR_TYPE_DELETE, entry.isDirectory, FileUtils.getFileErrorString(err), entry.fullPath); result.reject(err); } }); return result.promise(); }
javascript
function deleteItem(entry) { var result = new $.Deferred(); entry.moveToTrash(function (err) { if (!err) { DocumentManager.notifyPathDeleted(entry.fullPath); result.resolve(); } else { _showErrorDialog(ERR_TYPE_DELETE, entry.isDirectory, FileUtils.getFileErrorString(err), entry.fullPath); result.reject(err); } }); return result.promise(); }
[ "function", "deleteItem", "(", "entry", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ";", "entry", ".", "moveToTrash", "(", "function", "(", "err", ")", "{", "if", "(", "!", "err", ")", "{", "DocumentManager", ".", "notifyPathDeleted", "(", "entry", ".", "fullPath", ")", ";", "result", ".", "resolve", "(", ")", ";", "}", "else", "{", "_showErrorDialog", "(", "ERR_TYPE_DELETE", ",", "entry", ".", "isDirectory", ",", "FileUtils", ".", "getFileErrorString", "(", "err", ")", ",", "entry", ".", "fullPath", ")", ";", "result", ".", "reject", "(", "err", ")", ";", "}", "}", ")", ";", "return", "result", ".", "promise", "(", ")", ";", "}" ]
Delete file or directore from project @param {!(File|Directory)} entry File or Directory to delete
[ "Delete", "file", "or", "directore", "from", "project" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L1130-L1145
2,481
adobe/brackets
src/editor/EditorStatusBar.js
_formatCountable
function _formatCountable(number, singularStr, pluralStr) { return StringUtils.format(number > 1 ? pluralStr : singularStr, number); }
javascript
function _formatCountable(number, singularStr, pluralStr) { return StringUtils.format(number > 1 ? pluralStr : singularStr, number); }
[ "function", "_formatCountable", "(", "number", ",", "singularStr", ",", "pluralStr", ")", "{", "return", "StringUtils", ".", "format", "(", "number", ">", "1", "?", "pluralStr", ":", "singularStr", ",", "number", ")", ";", "}" ]
Determine string based on count @param {number} number Count @param {string} singularStr Singular string @param {string} pluralStr Plural string @return {string} Proper string to use for count
[ "Determine", "string", "based", "on", "count" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L80-L82
2,482
adobe/brackets
src/editor/EditorStatusBar.js
_updateLanguageInfo
function _updateLanguageInfo(editor) { var doc = editor.document, lang = doc.getLanguage(); // Show the current language as button title languageSelect.$button.text(lang.getName()); }
javascript
function _updateLanguageInfo(editor) { var doc = editor.document, lang = doc.getLanguage(); // Show the current language as button title languageSelect.$button.text(lang.getName()); }
[ "function", "_updateLanguageInfo", "(", "editor", ")", "{", "var", "doc", "=", "editor", ".", "document", ",", "lang", "=", "doc", ".", "getLanguage", "(", ")", ";", "// Show the current language as button title", "languageSelect", ".", "$button", ".", "text", "(", "lang", ".", "getName", "(", ")", ")", ";", "}" ]
Update file mode @param {Editor} editor Current editor
[ "Update", "file", "mode" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L88-L94
2,483
adobe/brackets
src/editor/EditorStatusBar.js
_updateFileInfo
function _updateFileInfo(editor) { var lines = editor.lineCount(); $fileInfo.text(_formatCountable(lines, Strings.STATUSBAR_LINE_COUNT_SINGULAR, Strings.STATUSBAR_LINE_COUNT_PLURAL)); }
javascript
function _updateFileInfo(editor) { var lines = editor.lineCount(); $fileInfo.text(_formatCountable(lines, Strings.STATUSBAR_LINE_COUNT_SINGULAR, Strings.STATUSBAR_LINE_COUNT_PLURAL)); }
[ "function", "_updateFileInfo", "(", "editor", ")", "{", "var", "lines", "=", "editor", ".", "lineCount", "(", ")", ";", "$fileInfo", ".", "text", "(", "_formatCountable", "(", "lines", ",", "Strings", ".", "STATUSBAR_LINE_COUNT_SINGULAR", ",", "Strings", ".", "STATUSBAR_LINE_COUNT_PLURAL", ")", ")", ";", "}" ]
Update file information @param {Editor} editor Current editor
[ "Update", "file", "information" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L114-L117
2,484
adobe/brackets
src/editor/EditorStatusBar.js
_updateIndentType
function _updateIndentType(fullPath) { var indentWithTabs = Editor.getUseTabChar(fullPath); $indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES); $indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS); $indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES); }
javascript
function _updateIndentType(fullPath) { var indentWithTabs = Editor.getUseTabChar(fullPath); $indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES); $indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS); $indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES); }
[ "function", "_updateIndentType", "(", "fullPath", ")", "{", "var", "indentWithTabs", "=", "Editor", ".", "getUseTabChar", "(", "fullPath", ")", ";", "$indentType", ".", "text", "(", "indentWithTabs", "?", "Strings", ".", "STATUSBAR_TAB_SIZE", ":", "Strings", ".", "STATUSBAR_SPACES", ")", ";", "$indentType", ".", "attr", "(", "\"title\"", ",", "indentWithTabs", "?", "Strings", ".", "STATUSBAR_INDENT_TOOLTIP_SPACES", ":", "Strings", ".", "STATUSBAR_INDENT_TOOLTIP_TABS", ")", ";", "$indentWidthLabel", ".", "attr", "(", "\"title\"", ",", "indentWithTabs", "?", "Strings", ".", "STATUSBAR_INDENT_SIZE_TOOLTIP_TABS", ":", "Strings", ".", "STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES", ")", ";", "}" ]
Update indent type and size @param {string} fullPath Path to file in current editor
[ "Update", "indent", "type", "and", "size" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L123-L128
2,485
adobe/brackets
src/editor/EditorStatusBar.js
_toggleIndentType
function _toggleIndentType() { var current = EditorManager.getActiveEditor(), fullPath = current && current.document.file.fullPath; Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath); _updateIndentType(fullPath); _updateIndentSize(fullPath); }
javascript
function _toggleIndentType() { var current = EditorManager.getActiveEditor(), fullPath = current && current.document.file.fullPath; Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath); _updateIndentType(fullPath); _updateIndentSize(fullPath); }
[ "function", "_toggleIndentType", "(", ")", "{", "var", "current", "=", "EditorManager", ".", "getActiveEditor", "(", ")", ",", "fullPath", "=", "current", "&&", "current", ".", "document", ".", "file", ".", "fullPath", ";", "Editor", ".", "setUseTabChar", "(", "!", "Editor", ".", "getUseTabChar", "(", "fullPath", ")", ",", "fullPath", ")", ";", "_updateIndentType", "(", "fullPath", ")", ";", "_updateIndentSize", "(", "fullPath", ")", ";", "}" ]
Toggle indent type
[ "Toggle", "indent", "type" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L152-L159
2,486
adobe/brackets
src/editor/EditorStatusBar.js
_changeIndentWidth
function _changeIndentWidth(fullPath, value) { $indentWidthLabel.removeClass("hidden"); $indentWidthInput.addClass("hidden"); // remove all event handlers from the input field $indentWidthInput.off("blur keyup"); // restore focus to the editor MainViewManager.focusActivePane(); var valInt = parseInt(value, 10); if (Editor.getUseTabChar(fullPath)) { if (!Editor.setTabSize(valInt, fullPath)) { return; // validation failed } } else { if (!Editor.setSpaceUnits(valInt, fullPath)) { return; // validation failed } } // update indicator _updateIndentSize(fullPath); // column position may change when tab size changes _updateCursorInfo(); }
javascript
function _changeIndentWidth(fullPath, value) { $indentWidthLabel.removeClass("hidden"); $indentWidthInput.addClass("hidden"); // remove all event handlers from the input field $indentWidthInput.off("blur keyup"); // restore focus to the editor MainViewManager.focusActivePane(); var valInt = parseInt(value, 10); if (Editor.getUseTabChar(fullPath)) { if (!Editor.setTabSize(valInt, fullPath)) { return; // validation failed } } else { if (!Editor.setSpaceUnits(valInt, fullPath)) { return; // validation failed } } // update indicator _updateIndentSize(fullPath); // column position may change when tab size changes _updateCursorInfo(); }
[ "function", "_changeIndentWidth", "(", "fullPath", ",", "value", ")", "{", "$indentWidthLabel", ".", "removeClass", "(", "\"hidden\"", ")", ";", "$indentWidthInput", ".", "addClass", "(", "\"hidden\"", ")", ";", "// remove all event handlers from the input field", "$indentWidthInput", ".", "off", "(", "\"blur keyup\"", ")", ";", "// restore focus to the editor", "MainViewManager", ".", "focusActivePane", "(", ")", ";", "var", "valInt", "=", "parseInt", "(", "value", ",", "10", ")", ";", "if", "(", "Editor", ".", "getUseTabChar", "(", "fullPath", ")", ")", "{", "if", "(", "!", "Editor", ".", "setTabSize", "(", "valInt", ",", "fullPath", ")", ")", "{", "return", ";", "// validation failed", "}", "}", "else", "{", "if", "(", "!", "Editor", ".", "setSpaceUnits", "(", "valInt", ",", "fullPath", ")", ")", "{", "return", ";", "// validation failed", "}", "}", "// update indicator", "_updateIndentSize", "(", "fullPath", ")", ";", "// column position may change when tab size changes", "_updateCursorInfo", "(", ")", ";", "}" ]
Change indent size @param {string} fullPath Path to file in current editor @param {string} value Size entered into status bar
[ "Change", "indent", "size" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L207-L233
2,487
adobe/brackets
src/editor/EditorStatusBar.js
_onActiveEditorChange
function _onActiveEditorChange(event, current, previous) { if (previous) { previous.off(".statusbar"); previous.document.off(".statusbar"); previous.document.releaseRef(); } if (!current) { StatusBar.hideAllPanes(); } else { var fullPath = current.document.file.fullPath; StatusBar.showAllPanes(); current.on("cursorActivity.statusbar", _updateCursorInfo); current.on("optionChange.statusbar", function () { _updateIndentType(fullPath); _updateIndentSize(fullPath); }); current.on("change.statusbar", function () { // async update to keep typing speed smooth window.setTimeout(function () { _updateFileInfo(current); }, 0); }); current.on("overwriteToggle.statusbar", _updateOverwriteLabel); current.document.addRef(); current.document.on("languageChanged.statusbar", function () { _updateLanguageInfo(current); }); _updateCursorInfo(null, current); _updateLanguageInfo(current); _updateEncodingInfo(current); _updateFileInfo(current); _initOverwriteMode(current); _updateIndentType(fullPath); _updateIndentSize(fullPath); } }
javascript
function _onActiveEditorChange(event, current, previous) { if (previous) { previous.off(".statusbar"); previous.document.off(".statusbar"); previous.document.releaseRef(); } if (!current) { StatusBar.hideAllPanes(); } else { var fullPath = current.document.file.fullPath; StatusBar.showAllPanes(); current.on("cursorActivity.statusbar", _updateCursorInfo); current.on("optionChange.statusbar", function () { _updateIndentType(fullPath); _updateIndentSize(fullPath); }); current.on("change.statusbar", function () { // async update to keep typing speed smooth window.setTimeout(function () { _updateFileInfo(current); }, 0); }); current.on("overwriteToggle.statusbar", _updateOverwriteLabel); current.document.addRef(); current.document.on("languageChanged.statusbar", function () { _updateLanguageInfo(current); }); _updateCursorInfo(null, current); _updateLanguageInfo(current); _updateEncodingInfo(current); _updateFileInfo(current); _initOverwriteMode(current); _updateIndentType(fullPath); _updateIndentSize(fullPath); } }
[ "function", "_onActiveEditorChange", "(", "event", ",", "current", ",", "previous", ")", "{", "if", "(", "previous", ")", "{", "previous", ".", "off", "(", "\".statusbar\"", ")", ";", "previous", ".", "document", ".", "off", "(", "\".statusbar\"", ")", ";", "previous", ".", "document", ".", "releaseRef", "(", ")", ";", "}", "if", "(", "!", "current", ")", "{", "StatusBar", ".", "hideAllPanes", "(", ")", ";", "}", "else", "{", "var", "fullPath", "=", "current", ".", "document", ".", "file", ".", "fullPath", ";", "StatusBar", ".", "showAllPanes", "(", ")", ";", "current", ".", "on", "(", "\"cursorActivity.statusbar\"", ",", "_updateCursorInfo", ")", ";", "current", ".", "on", "(", "\"optionChange.statusbar\"", ",", "function", "(", ")", "{", "_updateIndentType", "(", "fullPath", ")", ";", "_updateIndentSize", "(", "fullPath", ")", ";", "}", ")", ";", "current", ".", "on", "(", "\"change.statusbar\"", ",", "function", "(", ")", "{", "// async update to keep typing speed smooth", "window", ".", "setTimeout", "(", "function", "(", ")", "{", "_updateFileInfo", "(", "current", ")", ";", "}", ",", "0", ")", ";", "}", ")", ";", "current", ".", "on", "(", "\"overwriteToggle.statusbar\"", ",", "_updateOverwriteLabel", ")", ";", "current", ".", "document", ".", "addRef", "(", ")", ";", "current", ".", "document", ".", "on", "(", "\"languageChanged.statusbar\"", ",", "function", "(", ")", "{", "_updateLanguageInfo", "(", "current", ")", ";", "}", ")", ";", "_updateCursorInfo", "(", "null", ",", "current", ")", ";", "_updateLanguageInfo", "(", "current", ")", ";", "_updateEncodingInfo", "(", "current", ")", ";", "_updateFileInfo", "(", "current", ")", ";", "_initOverwriteMode", "(", "current", ")", ";", "_updateIndentType", "(", "fullPath", ")", ";", "_updateIndentSize", "(", "fullPath", ")", ";", "}", "}" ]
Handle active editor change event @param {Event} event (unused) @param {Editor} current Current editor @param {Editor} previous Previous editor
[ "Handle", "active", "editor", "change", "event" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L283-L320
2,488
adobe/brackets
src/editor/EditorStatusBar.js
_populateLanguageDropdown
function _populateLanguageDropdown() { // Get all non-binary languages var languages = _.values(LanguageManager.getLanguages()).filter(function (language) { return !language.isBinary(); }); // sort dropdown alphabetically languages.sort(function (a, b) { return a.getName().toLowerCase().localeCompare(b.getName().toLowerCase()); }); languageSelect.items = languages; // Add option to top of menu for persisting the override languageSelect.items.unshift("---"); languageSelect.items.unshift(LANGUAGE_SET_AS_DEFAULT); }
javascript
function _populateLanguageDropdown() { // Get all non-binary languages var languages = _.values(LanguageManager.getLanguages()).filter(function (language) { return !language.isBinary(); }); // sort dropdown alphabetically languages.sort(function (a, b) { return a.getName().toLowerCase().localeCompare(b.getName().toLowerCase()); }); languageSelect.items = languages; // Add option to top of menu for persisting the override languageSelect.items.unshift("---"); languageSelect.items.unshift(LANGUAGE_SET_AS_DEFAULT); }
[ "function", "_populateLanguageDropdown", "(", ")", "{", "// Get all non-binary languages", "var", "languages", "=", "_", ".", "values", "(", "LanguageManager", ".", "getLanguages", "(", ")", ")", ".", "filter", "(", "function", "(", "language", ")", "{", "return", "!", "language", ".", "isBinary", "(", ")", ";", "}", ")", ";", "// sort dropdown alphabetically", "languages", ".", "sort", "(", "function", "(", "a", ",", "b", ")", "{", "return", "a", ".", "getName", "(", ")", ".", "toLowerCase", "(", ")", ".", "localeCompare", "(", "b", ".", "getName", "(", ")", ".", "toLowerCase", "(", ")", ")", ";", "}", ")", ";", "languageSelect", ".", "items", "=", "languages", ";", "// Add option to top of menu for persisting the override", "languageSelect", ".", "items", ".", "unshift", "(", "\"---\"", ")", ";", "languageSelect", ".", "items", ".", "unshift", "(", "LANGUAGE_SET_AS_DEFAULT", ")", ";", "}" ]
Populate the languageSelect DropdownButton's menu with all registered Languages
[ "Populate", "the", "languageSelect", "DropdownButton", "s", "menu", "with", "all", "registered", "Languages" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L325-L341
2,489
adobe/brackets
src/editor/EditorStatusBar.js
_changeEncodingAndReloadDoc
function _changeEncodingAndReloadDoc(document) { var promise = document.reload(); promise.done(function (text, readTimestamp) { encodingSelect.$button.text(document.file._encoding); // Store the preferred encoding in the state var projectRoot = ProjectManager.getProjectRoot(), context = { location : { scope: "user", layer: "project", layerID: projectRoot.fullPath } }; var encoding = PreferencesManager.getViewState("encoding", context); encoding[document.file.fullPath] = document.file._encoding; PreferencesManager.setViewState("encoding", encoding, context); }); promise.fail(function (error) { console.log("Error reloading contents of " + document.file.fullPath, error); }); }
javascript
function _changeEncodingAndReloadDoc(document) { var promise = document.reload(); promise.done(function (text, readTimestamp) { encodingSelect.$button.text(document.file._encoding); // Store the preferred encoding in the state var projectRoot = ProjectManager.getProjectRoot(), context = { location : { scope: "user", layer: "project", layerID: projectRoot.fullPath } }; var encoding = PreferencesManager.getViewState("encoding", context); encoding[document.file.fullPath] = document.file._encoding; PreferencesManager.setViewState("encoding", encoding, context); }); promise.fail(function (error) { console.log("Error reloading contents of " + document.file.fullPath, error); }); }
[ "function", "_changeEncodingAndReloadDoc", "(", "document", ")", "{", "var", "promise", "=", "document", ".", "reload", "(", ")", ";", "promise", ".", "done", "(", "function", "(", "text", ",", "readTimestamp", ")", "{", "encodingSelect", ".", "$button", ".", "text", "(", "document", ".", "file", ".", "_encoding", ")", ";", "// Store the preferred encoding in the state", "var", "projectRoot", "=", "ProjectManager", ".", "getProjectRoot", "(", ")", ",", "context", "=", "{", "location", ":", "{", "scope", ":", "\"user\"", ",", "layer", ":", "\"project\"", ",", "layerID", ":", "projectRoot", ".", "fullPath", "}", "}", ";", "var", "encoding", "=", "PreferencesManager", ".", "getViewState", "(", "\"encoding\"", ",", "context", ")", ";", "encoding", "[", "document", ".", "file", ".", "fullPath", "]", "=", "document", ".", "file", ".", "_encoding", ";", "PreferencesManager", ".", "setViewState", "(", "\"encoding\"", ",", "encoding", ",", "context", ")", ";", "}", ")", ";", "promise", ".", "fail", "(", "function", "(", "error", ")", "{", "console", ".", "log", "(", "\"Error reloading contents of \"", "+", "document", ".", "file", ".", "fullPath", ",", "error", ")", ";", "}", ")", ";", "}" ]
Change the encoding and reload the current document. If passed then save the preferred encoding in state.
[ "Change", "the", "encoding", "and", "reload", "the", "current", "document", ".", "If", "passed", "then", "save", "the", "preferred", "encoding", "in", "state", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L347-L367
2,490
adobe/brackets
src/extensions/default/QuickOpenJavaScript/main.js
createFunctionList
function createFunctionList() { var doc = DocumentManager.getCurrentDocument(); if (!doc) { return; } var functionList = []; var docText = doc.getText(); var lines = docText.split("\n"); var functions = JSUtils.findAllMatchingFunctionsInText(docText, "*"); functions.forEach(function (funcEntry) { functionList.push(new FileLocation(null, funcEntry.nameLineStart, funcEntry.columnStart, funcEntry.columnEnd, funcEntry.label || funcEntry.name)); }); return functionList; }
javascript
function createFunctionList() { var doc = DocumentManager.getCurrentDocument(); if (!doc) { return; } var functionList = []; var docText = doc.getText(); var lines = docText.split("\n"); var functions = JSUtils.findAllMatchingFunctionsInText(docText, "*"); functions.forEach(function (funcEntry) { functionList.push(new FileLocation(null, funcEntry.nameLineStart, funcEntry.columnStart, funcEntry.columnEnd, funcEntry.label || funcEntry.name)); }); return functionList; }
[ "function", "createFunctionList", "(", ")", "{", "var", "doc", "=", "DocumentManager", ".", "getCurrentDocument", "(", ")", ";", "if", "(", "!", "doc", ")", "{", "return", ";", "}", "var", "functionList", "=", "[", "]", ";", "var", "docText", "=", "doc", ".", "getText", "(", ")", ";", "var", "lines", "=", "docText", ".", "split", "(", "\"\\n\"", ")", ";", "var", "functions", "=", "JSUtils", ".", "findAllMatchingFunctionsInText", "(", "docText", ",", "\"*\"", ")", ";", "functions", ".", "forEach", "(", "function", "(", "funcEntry", ")", "{", "functionList", ".", "push", "(", "new", "FileLocation", "(", "null", ",", "funcEntry", ".", "nameLineStart", ",", "funcEntry", ".", "columnStart", ",", "funcEntry", ".", "columnEnd", ",", "funcEntry", ".", "label", "||", "funcEntry", ".", "name", ")", ")", ";", "}", ")", ";", "return", "functionList", ";", "}" ]
Contains a list of information about functions for a single document. @return {?Array.<FileLocation>}
[ "Contains", "a", "list", "of", "information", "about", "functions", "for", "a", "single", "document", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/QuickOpenJavaScript/main.js#L57-L71
2,491
adobe/brackets
src/extensions/default/CodeFolding/main.js
rangeEqualsSelection
function rangeEqualsSelection(range, selection) { return range.from.line === selection.start.line && range.from.ch === selection.start.ch && range.to.line === selection.end.line && range.to.ch === selection.end.ch; }
javascript
function rangeEqualsSelection(range, selection) { return range.from.line === selection.start.line && range.from.ch === selection.start.ch && range.to.line === selection.end.line && range.to.ch === selection.end.ch; }
[ "function", "rangeEqualsSelection", "(", "range", ",", "selection", ")", "{", "return", "range", ".", "from", ".", "line", "===", "selection", ".", "start", ".", "line", "&&", "range", ".", "from", ".", "ch", "===", "selection", ".", "start", ".", "ch", "&&", "range", ".", "to", ".", "line", "===", "selection", ".", "end", ".", "line", "&&", "range", ".", "to", ".", "ch", "===", "selection", ".", "end", ".", "ch", ";", "}" ]
Checks if the range from and to Pos is the same as the selection start and end Pos @param {Object} range {from, to} where from and to are CodeMirror.Pos objects @param {Object} selection {start, end} where start and end are CodeMirror.Pos objects @returns {Boolean} true if the range and selection span the same region and false otherwise
[ "Checks", "if", "the", "range", "from", "and", "to", "Pos", "is", "the", "same", "as", "the", "selection", "start", "and", "end", "Pos" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L98-L101
2,492
adobe/brackets
src/extensions/default/CodeFolding/main.js
isInViewStateSelection
function isInViewStateSelection(range, viewState) { if (!viewState || !viewState.selections) { return false; } return viewState.selections.some(function (selection) { return rangeEqualsSelection(range, selection); }); }
javascript
function isInViewStateSelection(range, viewState) { if (!viewState || !viewState.selections) { return false; } return viewState.selections.some(function (selection) { return rangeEqualsSelection(range, selection); }); }
[ "function", "isInViewStateSelection", "(", "range", ",", "viewState", ")", "{", "if", "(", "!", "viewState", "||", "!", "viewState", ".", "selections", ")", "{", "return", "false", ";", "}", "return", "viewState", ".", "selections", ".", "some", "(", "function", "(", "selection", ")", "{", "return", "rangeEqualsSelection", "(", "range", ",", "selection", ")", ";", "}", ")", ";", "}" ]
Checks if the range is equal to one of the selections in the viewState @param {Object} range {from, to} where from and to are CodeMirror.Pos objects. @param {Object} viewState The current editor's ViewState object @returns {Boolean} true if the range is found in the list of selections or false if not.
[ "Checks", "if", "the", "range", "is", "equal", "to", "one", "of", "the", "selections", "in", "the", "viewState" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L109-L117
2,493
adobe/brackets
src/extensions/default/CodeFolding/main.js
saveLineFolds
function saveLineFolds(editor) { var saveFolds = prefs.getSetting("saveFoldStates"); if (!editor || !saveFolds) { return; } var folds = editor._codeMirror._lineFolds || {}; var path = editor.document.file.fullPath; if (Object.keys(folds).length) { prefs.setFolds(path, folds); } else { prefs.setFolds(path, undefined); } }
javascript
function saveLineFolds(editor) { var saveFolds = prefs.getSetting("saveFoldStates"); if (!editor || !saveFolds) { return; } var folds = editor._codeMirror._lineFolds || {}; var path = editor.document.file.fullPath; if (Object.keys(folds).length) { prefs.setFolds(path, folds); } else { prefs.setFolds(path, undefined); } }
[ "function", "saveLineFolds", "(", "editor", ")", "{", "var", "saveFolds", "=", "prefs", ".", "getSetting", "(", "\"saveFoldStates\"", ")", ";", "if", "(", "!", "editor", "||", "!", "saveFolds", ")", "{", "return", ";", "}", "var", "folds", "=", "editor", ".", "_codeMirror", ".", "_lineFolds", "||", "{", "}", ";", "var", "path", "=", "editor", ".", "document", ".", "file", ".", "fullPath", ";", "if", "(", "Object", ".", "keys", "(", "folds", ")", ".", "length", ")", "{", "prefs", ".", "setFolds", "(", "path", ",", "folds", ")", ";", "}", "else", "{", "prefs", ".", "setFolds", "(", "path", ",", "undefined", ")", ";", "}", "}" ]
Saves the line folds in the editor using the preference storage @param {Editor} editor the editor whose line folds should be saved
[ "Saves", "the", "line", "folds", "in", "the", "editor", "using", "the", "preference", "storage" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L159-L171
2,494
adobe/brackets
src/extensions/default/CodeFolding/main.js
collapseCurrent
function collapseCurrent() { var editor = EditorManager.getFocusedEditor(); if (!editor) { return; } var cm = editor._codeMirror; var cursor = editor.getCursorPos(), i; // Move cursor up until a collapsible line is found for (i = cursor.line; i >= 0; i--) { if (cm.foldCode(i)) { editor.setCursorPos(i); return; } } }
javascript
function collapseCurrent() { var editor = EditorManager.getFocusedEditor(); if (!editor) { return; } var cm = editor._codeMirror; var cursor = editor.getCursorPos(), i; // Move cursor up until a collapsible line is found for (i = cursor.line; i >= 0; i--) { if (cm.foldCode(i)) { editor.setCursorPos(i); return; } } }
[ "function", "collapseCurrent", "(", ")", "{", "var", "editor", "=", "EditorManager", ".", "getFocusedEditor", "(", ")", ";", "if", "(", "!", "editor", ")", "{", "return", ";", "}", "var", "cm", "=", "editor", ".", "_codeMirror", ";", "var", "cursor", "=", "editor", ".", "getCursorPos", "(", ")", ",", "i", ";", "// Move cursor up until a collapsible line is found", "for", "(", "i", "=", "cursor", ".", "line", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "if", "(", "cm", ".", "foldCode", "(", "i", ")", ")", "{", "editor", ".", "setCursorPos", "(", "i", ")", ";", "return", ";", "}", "}", "}" ]
Collapses the code region nearest the current cursor position. Nearest is found by searching from the current line and moving up the document until an opening code-folding region is found.
[ "Collapses", "the", "code", "region", "nearest", "the", "current", "cursor", "position", ".", "Nearest", "is", "found", "by", "searching", "from", "the", "current", "line", "and", "moving", "up", "the", "document", "until", "an", "opening", "code", "-", "folding", "region", "is", "found", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L211-L225
2,495
adobe/brackets
src/extensions/default/CodeFolding/main.js
expandCurrent
function expandCurrent() { var editor = EditorManager.getFocusedEditor(); if (editor) { var cursor = editor.getCursorPos(), cm = editor._codeMirror; cm.unfoldCode(cursor.line); } }
javascript
function expandCurrent() { var editor = EditorManager.getFocusedEditor(); if (editor) { var cursor = editor.getCursorPos(), cm = editor._codeMirror; cm.unfoldCode(cursor.line); } }
[ "function", "expandCurrent", "(", ")", "{", "var", "editor", "=", "EditorManager", ".", "getFocusedEditor", "(", ")", ";", "if", "(", "editor", ")", "{", "var", "cursor", "=", "editor", ".", "getCursorPos", "(", ")", ",", "cm", "=", "editor", ".", "_codeMirror", ";", "cm", ".", "unfoldCode", "(", "cursor", ".", "line", ")", ";", "}", "}" ]
Expands the code region at the current cursor position.
[ "Expands", "the", "code", "region", "at", "the", "current", "cursor", "position", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L230-L236
2,496
adobe/brackets
src/extensions/default/CodeFolding/main.js
expandAll
function expandAll() { var editor = EditorManager.getFocusedEditor(); if (editor) { var cm = editor._codeMirror; CodeMirror.commands.unfoldAll(cm); } }
javascript
function expandAll() { var editor = EditorManager.getFocusedEditor(); if (editor) { var cm = editor._codeMirror; CodeMirror.commands.unfoldAll(cm); } }
[ "function", "expandAll", "(", ")", "{", "var", "editor", "=", "EditorManager", ".", "getFocusedEditor", "(", ")", ";", "if", "(", "editor", ")", "{", "var", "cm", "=", "editor", ".", "_codeMirror", ";", "CodeMirror", ".", "commands", ".", "unfoldAll", "(", "cm", ")", ";", "}", "}" ]
Expands all folded regions in the current document
[ "Expands", "all", "folded", "regions", "in", "the", "current", "document" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L262-L268
2,497
adobe/brackets
src/extensions/default/CodeFolding/main.js
setupGutterEventListeners
function setupGutterEventListeners(editor) { var cm = editor._codeMirror; $(editor.getRootElement()).addClass("folding-enabled"); cm.setOption("foldGutter", {onGutterClick: onGutterClick}); $(cm.getGutterElement()).on({ mouseenter: function () { if (prefs.getSetting("hideUntilMouseover")) { foldGutter.updateInViewport(cm); } else { $(editor.getRootElement()).addClass("over-gutter"); } }, mouseleave: function () { if (prefs.getSetting("hideUntilMouseover")) { clearGutter(editor); } else { $(editor.getRootElement()).removeClass("over-gutter"); } } }); }
javascript
function setupGutterEventListeners(editor) { var cm = editor._codeMirror; $(editor.getRootElement()).addClass("folding-enabled"); cm.setOption("foldGutter", {onGutterClick: onGutterClick}); $(cm.getGutterElement()).on({ mouseenter: function () { if (prefs.getSetting("hideUntilMouseover")) { foldGutter.updateInViewport(cm); } else { $(editor.getRootElement()).addClass("over-gutter"); } }, mouseleave: function () { if (prefs.getSetting("hideUntilMouseover")) { clearGutter(editor); } else { $(editor.getRootElement()).removeClass("over-gutter"); } } }); }
[ "function", "setupGutterEventListeners", "(", "editor", ")", "{", "var", "cm", "=", "editor", ".", "_codeMirror", ";", "$", "(", "editor", ".", "getRootElement", "(", ")", ")", ".", "addClass", "(", "\"folding-enabled\"", ")", ";", "cm", ".", "setOption", "(", "\"foldGutter\"", ",", "{", "onGutterClick", ":", "onGutterClick", "}", ")", ";", "$", "(", "cm", ".", "getGutterElement", "(", ")", ")", ".", "on", "(", "{", "mouseenter", ":", "function", "(", ")", "{", "if", "(", "prefs", ".", "getSetting", "(", "\"hideUntilMouseover\"", ")", ")", "{", "foldGutter", ".", "updateInViewport", "(", "cm", ")", ";", "}", "else", "{", "$", "(", "editor", ".", "getRootElement", "(", ")", ")", ".", "addClass", "(", "\"over-gutter\"", ")", ";", "}", "}", ",", "mouseleave", ":", "function", "(", ")", "{", "if", "(", "prefs", ".", "getSetting", "(", "\"hideUntilMouseover\"", ")", ")", "{", "clearGutter", "(", "editor", ")", ";", "}", "else", "{", "$", "(", "editor", ".", "getRootElement", "(", ")", ")", ".", "removeClass", "(", "\"over-gutter\"", ")", ";", "}", "}", "}", ")", ";", "}" ]
Renders and sets up event listeners the code-folding gutter. @param {Editor} editor the editor on which to initialise the fold gutter
[ "Renders", "and", "sets", "up", "event", "listeners", "the", "code", "-", "folding", "gutter", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L288-L309
2,498
adobe/brackets
src/extensions/default/CodeFolding/main.js
removeGutters
function removeGutters(editor) { Editor.unregisterGutter(GUTTER_NAME); $(editor.getRootElement()).removeClass("folding-enabled"); CodeMirror.defineOption("foldGutter", false, null); }
javascript
function removeGutters(editor) { Editor.unregisterGutter(GUTTER_NAME); $(editor.getRootElement()).removeClass("folding-enabled"); CodeMirror.defineOption("foldGutter", false, null); }
[ "function", "removeGutters", "(", "editor", ")", "{", "Editor", ".", "unregisterGutter", "(", "GUTTER_NAME", ")", ";", "$", "(", "editor", ".", "getRootElement", "(", ")", ")", ".", "removeClass", "(", "\"folding-enabled\"", ")", ";", "CodeMirror", ".", "defineOption", "(", "\"foldGutter\"", ",", "false", ",", "null", ")", ";", "}" ]
Remove the fold gutter for a given CodeMirror instance. @param {Editor} editor the editor instance whose gutter should be removed
[ "Remove", "the", "fold", "gutter", "for", "a", "given", "CodeMirror", "instance", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L315-L319
2,499
adobe/brackets
src/extensions/default/CodeFolding/main.js
onActiveEditorChanged
function onActiveEditorChanged(event, current, previous) { if (current && !current._codeMirror._lineFolds) { enableFoldingInEditor(current); } if (previous) { saveLineFolds(previous); } }
javascript
function onActiveEditorChanged(event, current, previous) { if (current && !current._codeMirror._lineFolds) { enableFoldingInEditor(current); } if (previous) { saveLineFolds(previous); } }
[ "function", "onActiveEditorChanged", "(", "event", ",", "current", ",", "previous", ")", "{", "if", "(", "current", "&&", "!", "current", ".", "_codeMirror", ".", "_lineFolds", ")", "{", "enableFoldingInEditor", "(", "current", ")", ";", "}", "if", "(", "previous", ")", "{", "saveLineFolds", "(", "previous", ")", ";", "}", "}" ]
When a brand new editor is seen, initialise fold-gutter and restore line folds in it. Save line folds in departing editor in case it's getting closed. @param {object} event the event object @param {Editor} current the current editor @param {Editor} previous the previous editor
[ "When", "a", "brand", "new", "editor", "is", "seen", "initialise", "fold", "-", "gutter", "and", "restore", "line", "folds", "in", "it", ".", "Save", "line", "folds", "in", "departing", "editor", "in", "case", "it", "s", "getting", "closed", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L338-L345