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
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
partition
stringclasses
1 value
adobe/brackets
src/preferences/PreferencesBase.js
function (context) { context = context || {}; var layerCounter, layers = this._layers, layer, data = this.data; var keySets = [_.difference(_.keys(data), this._exclusions)]; for (layerCounter = 0; layerCounter < layers.length; layerCounter++) { layer = layers[layerCounter]; keySets.push(layer.getKeys(data[layer.key], context)); } return _.union.apply(null, keySets); }
javascript
function (context) { context = context || {}; var layerCounter, layers = this._layers, layer, data = this.data; var keySets = [_.difference(_.keys(data), this._exclusions)]; for (layerCounter = 0; layerCounter < layers.length; layerCounter++) { layer = layers[layerCounter]; keySets.push(layer.getKeys(data[layer.key], context)); } return _.union.apply(null, keySets); }
[ "function", "(", "context", ")", "{", "context", "=", "context", "||", "{", "}", ";", "var", "layerCounter", ",", "layers", "=", "this", ".", "_layers", ",", "layer", ",", "data", "=", "this", ".", "data", ";", "var", "keySets", "=", "[", "_", ".", "difference", "(", "_", ".", "keys", "(", "data", ")", ",", "this", ".", "_exclusions", ")", "]", ";", "for", "(", "layerCounter", "=", "0", ";", "layerCounter", "<", "layers", ".", "length", ";", "layerCounter", "++", ")", "{", "layer", "=", "layers", "[", "layerCounter", "]", ";", "keySets", ".", "push", "(", "layer", ".", "getKeys", "(", "data", "[", "layer", ".", "key", "]", ",", "context", ")", ")", ";", "}", "return", "_", ".", "union", ".", "apply", "(", "null", ",", "keySets", ")", ";", "}" ]
Get the preference IDs that are set in this Scope. All layers are added in. If context is not provided, the set of all keys in the Scope including all keys in each layer will be returned. @param {?Object} context Optional additional information for looking up the keys @return {Array.<string>} Set of preferences set by this Scope
[ "Get", "the", "preference", "IDs", "that", "are", "set", "in", "this", "Scope", ".", "All", "layers", "are", "added", "in", ".", "If", "context", "is", "not", "provided", "the", "set", "of", "all", "keys", "in", "the", "Scope", "including", "all", "keys", "in", "each", "layer", "will", "be", "returned", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L486-L501
train
adobe/brackets
src/preferences/PreferencesBase.js
function (layer) { this._layers.push(layer); this._layerMap[layer.key] = layer; this._exclusions.push(layer.key); this.trigger(PREFERENCE_CHANGE, { ids: layer.getKeys(this.data[layer.key], {}) }); }
javascript
function (layer) { this._layers.push(layer); this._layerMap[layer.key] = layer; this._exclusions.push(layer.key); this.trigger(PREFERENCE_CHANGE, { ids: layer.getKeys(this.data[layer.key], {}) }); }
[ "function", "(", "layer", ")", "{", "this", ".", "_layers", ".", "push", "(", "layer", ")", ";", "this", ".", "_layerMap", "[", "layer", ".", "key", "]", "=", "layer", ";", "this", ".", "_exclusions", ".", "push", "(", "layer", ".", "key", ")", ";", "this", ".", "trigger", "(", "PREFERENCE_CHANGE", ",", "{", "ids", ":", "layer", ".", "getKeys", "(", "this", ".", "data", "[", "layer", ".", "key", "]", ",", "{", "}", ")", "}", ")", ";", "}" ]
Adds a Layer to this Scope. The Layer object should define a `key`, which represents the subset of the preference data that the Layer works with. Layers should also define `get` and `getKeys` operations that are like their counterparts in Scope but take "data" as the first argument. Listeners are notified of potential changes in preferences with the addition of this layer. @param {Layer} layer Layer object to add to this Scope
[ "Adds", "a", "Layer", "to", "this", "Scope", ".", "The", "Layer", "object", "should", "define", "a", "key", "which", "represents", "the", "subset", "of", "the", "preference", "data", "that", "the", "Layer", "works", "with", ".", "Layers", "should", "also", "define", "get", "and", "getKeys", "operations", "that", "are", "like", "their", "counterparts", "in", "Scope", "but", "take", "data", "as", "the", "first", "argument", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L514-L521
train
adobe/brackets
src/preferences/PreferencesBase.js
function (oldContext, newContext) { var changes = [], data = this.data; _.each(this._layers, function (layer) { if (data[layer.key] && oldContext[layer.key] !== newContext[layer.key]) { var changesInLayer = layer.contextChanged(data[layer.key], oldContext, newContext); if (changesInLayer) { changes.push(changesInLayer); } } }); return _.union.apply(null, changes); }
javascript
function (oldContext, newContext) { var changes = [], data = this.data; _.each(this._layers, function (layer) { if (data[layer.key] && oldContext[layer.key] !== newContext[layer.key]) { var changesInLayer = layer.contextChanged(data[layer.key], oldContext, newContext); if (changesInLayer) { changes.push(changesInLayer); } } }); return _.union.apply(null, changes); }
[ "function", "(", "oldContext", ",", "newContext", ")", "{", "var", "changes", "=", "[", "]", ",", "data", "=", "this", ".", "data", ";", "_", ".", "each", "(", "this", ".", "_layers", ",", "function", "(", "layer", ")", "{", "if", "(", "data", "[", "layer", ".", "key", "]", "&&", "oldContext", "[", "layer", ".", "key", "]", "!==", "newContext", "[", "layer", ".", "key", "]", ")", "{", "var", "changesInLayer", "=", "layer", ".", "contextChanged", "(", "data", "[", "layer", ".", "key", "]", ",", "oldContext", ",", "newContext", ")", ";", "if", "(", "changesInLayer", ")", "{", "changes", ".", "push", "(", "changesInLayer", ")", ";", "}", "}", "}", ")", ";", "return", "_", ".", "union", ".", "apply", "(", "null", ",", "changes", ")", ";", "}" ]
Determines if there are likely to be any changes based on the change of context. @param {{path: string, language: string}} oldContext Old context @param {{path: string, language: string}} newContext New context @return {Array.<string>} List of changed IDs
[ "Determines", "if", "there", "are", "likely", "to", "be", "any", "changes", "based", "on", "the", "change", "of", "context", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L541-L556
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, id) { if (!data || !this.projectPath) { return; } if (data[this.projectPath] && (data[this.projectPath][id] !== undefined)) { return data[this.projectPath][id]; } return; }
javascript
function (data, id) { if (!data || !this.projectPath) { return; } if (data[this.projectPath] && (data[this.projectPath][id] !== undefined)) { return data[this.projectPath][id]; } return; }
[ "function", "(", "data", ",", "id", ")", "{", "if", "(", "!", "data", "||", "!", "this", ".", "projectPath", ")", "{", "return", ";", "}", "if", "(", "data", "[", "this", ".", "projectPath", "]", "&&", "(", "data", "[", "this", ".", "projectPath", "]", "[", "id", "]", "!==", "undefined", ")", ")", "{", "return", "data", "[", "this", ".", "projectPath", "]", "[", "id", "]", ";", "}", "return", ";", "}" ]
Retrieve the current value based on the current project path in the layer. @param {Object} data the preference data from the Scope @param {string} id preference ID to look up
[ "Retrieve", "the", "current", "value", "based", "on", "the", "current", "project", "path", "in", "the", "layer", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L610-L619
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data) { if (!data) { return; } return _.union.apply(null, _.map(_.values(data), _.keys)); }
javascript
function (data) { if (!data) { return; } return _.union.apply(null, _.map(_.values(data), _.keys)); }
[ "function", "(", "data", ")", "{", "if", "(", "!", "data", ")", "{", "return", ";", "}", "return", "_", ".", "union", ".", "apply", "(", "null", ",", "_", ".", "map", "(", "_", ".", "values", "(", "data", ")", ",", "_", ".", "keys", ")", ")", ";", "}" ]
Retrieves the keys provided by this layer object. @param {Object} data the preference data from the Scope
[ "Retrieves", "the", "keys", "provided", "by", "this", "layer", "object", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L684-L690
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, id, context) { if (!data || !context.language) { return; } if (data[context.language] && (data[context.language][id] !== undefined)) { return data[context.language][id]; } return; }
javascript
function (data, id, context) { if (!data || !context.language) { return; } if (data[context.language] && (data[context.language][id] !== undefined)) { return data[context.language][id]; } return; }
[ "function", "(", "data", ",", "id", ",", "context", ")", "{", "if", "(", "!", "data", "||", "!", "context", ".", "language", ")", "{", "return", ";", "}", "if", "(", "data", "[", "context", ".", "language", "]", "&&", "(", "data", "[", "context", ".", "language", "]", "[", "id", "]", "!==", "undefined", ")", ")", "{", "return", "data", "[", "context", ".", "language", "]", "[", "id", "]", ";", "}", "return", ";", "}" ]
Retrieve the current value based on the specified context. If the context does contain language field, undefined is returned. @param {Object} data the preference data from the Scope @param {string} id preference ID to look up @param {{language: string}} context Context to operate with @return {*|undefined} property value
[ "Retrieve", "the", "current", "value", "based", "on", "the", "specified", "context", ".", "If", "the", "context", "does", "contain", "language", "field", "undefined", "is", "returned", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L725-L734
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, oldContext, newContext) { // this function is called only if the language has changed if (newContext.language === undefined) { return _.keys(data[oldContext.language]); } if (oldContext.language === undefined) { return _.keys(data[newContext.language]); } return _.union(_.keys(data[newContext.language]), _.keys(data[oldContext.language])); }
javascript
function (data, oldContext, newContext) { // this function is called only if the language has changed if (newContext.language === undefined) { return _.keys(data[oldContext.language]); } if (oldContext.language === undefined) { return _.keys(data[newContext.language]); } return _.union(_.keys(data[newContext.language]), _.keys(data[oldContext.language])); }
[ "function", "(", "data", ",", "oldContext", ",", "newContext", ")", "{", "if", "(", "newContext", ".", "language", "===", "undefined", ")", "{", "return", "_", ".", "keys", "(", "data", "[", "oldContext", ".", "language", "]", ")", ";", "}", "if", "(", "oldContext", ".", "language", "===", "undefined", ")", "{", "return", "_", ".", "keys", "(", "data", "[", "newContext", ".", "language", "]", ")", ";", "}", "return", "_", ".", "union", "(", "_", ".", "keys", "(", "data", "[", "newContext", ".", "language", "]", ")", ",", "_", ".", "keys", "(", "data", "[", "oldContext", ".", "language", "]", ")", ")", ";", "}" ]
Determines if there are preference IDs that could change as a result of the context change. This implementation considers only changes in language. @param {Object} data Data in the Scope @param {{language: string}} oldContext Old context @param {{language: string}} newContext New context @return {Array.<string>|undefined} list of preference IDs that could have changed
[ "Determines", "if", "there", "are", "preference", "IDs", "that", "could", "change", "as", "a", "result", "of", "the", "context", "change", ".", "This", "implementation", "considers", "only", "changes", "in", "language", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L834-L844
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, id, context) { var glob = this.getPreferenceLocation(data, id, context); if (!glob) { return; } return data[glob][id]; }
javascript
function (data, id, context) { var glob = this.getPreferenceLocation(data, id, context); if (!glob) { return; } return data[glob][id]; }
[ "function", "(", "data", ",", "id", ",", "context", ")", "{", "var", "glob", "=", "this", ".", "getPreferenceLocation", "(", "data", ",", "id", ",", "context", ")", ";", "if", "(", "!", "glob", ")", "{", "return", ";", "}", "return", "data", "[", "glob", "]", "[", "id", "]", ";", "}" ]
Retrieve the current value based on the filename in the context object, comparing globs relative to the prefFilePath that this PathLayer was set up with. @param {Object} data the preference data from the Scope @param {string} id preference ID to look up @param {Object} context Object with filename that will be compared to the globs
[ "Retrieve", "the", "current", "value", "based", "on", "the", "filename", "in", "the", "context", "object", "comparing", "globs", "relative", "to", "the", "prefFilePath", "that", "this", "PathLayer", "was", "set", "up", "with", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L882-L890
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, id, context) { if (!data) { return; } var relativeFilename = FileUtils.getRelativeFilename(this.prefFilePath, context[this.key]); if (!relativeFilename) { return; } return _findMatchingGlob(data, relativeFilename); }
javascript
function (data, id, context) { if (!data) { return; } var relativeFilename = FileUtils.getRelativeFilename(this.prefFilePath, context[this.key]); if (!relativeFilename) { return; } return _findMatchingGlob(data, relativeFilename); }
[ "function", "(", "data", ",", "id", ",", "context", ")", "{", "if", "(", "!", "data", ")", "{", "return", ";", "}", "var", "relativeFilename", "=", "FileUtils", ".", "getRelativeFilename", "(", "this", ".", "prefFilePath", ",", "context", "[", "this", ".", "key", "]", ")", ";", "if", "(", "!", "relativeFilename", ")", "{", "return", ";", "}", "return", "_findMatchingGlob", "(", "data", ",", "relativeFilename", ")", ";", "}" ]
Gets the location in which the given pref was set, if it was set within this path layer for the current path. @param {Object} data the preference data from the Scope @param {string} id preference ID to look up @param {Object} context Object with filename that will be compared to the globs @return {string} the Layer ID, in this case the glob that matched
[ "Gets", "the", "location", "in", "which", "the", "given", "pref", "was", "set", "if", "it", "was", "set", "within", "this", "path", "layer", "for", "the", "current", "path", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L901-L912
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, id, value, context, layerID) { if (!layerID) { layerID = this.getPreferenceLocation(data, id, context); } if (!layerID) { return false; } var section = data[layerID]; if (!section) { data[layerID] = section = {}; } if (!_.isEqual(section[id], value)) { if (value === undefined) { delete section[id]; } else { section[id] = _.cloneDeep(value); } return true; } return false; }
javascript
function (data, id, value, context, layerID) { if (!layerID) { layerID = this.getPreferenceLocation(data, id, context); } if (!layerID) { return false; } var section = data[layerID]; if (!section) { data[layerID] = section = {}; } if (!_.isEqual(section[id], value)) { if (value === undefined) { delete section[id]; } else { section[id] = _.cloneDeep(value); } return true; } return false; }
[ "function", "(", "data", ",", "id", ",", "value", ",", "context", ",", "layerID", ")", "{", "if", "(", "!", "layerID", ")", "{", "layerID", "=", "this", ".", "getPreferenceLocation", "(", "data", ",", "id", ",", "context", ")", ";", "}", "if", "(", "!", "layerID", ")", "{", "return", "false", ";", "}", "var", "section", "=", "data", "[", "layerID", "]", ";", "if", "(", "!", "section", ")", "{", "data", "[", "layerID", "]", "=", "section", "=", "{", "}", ";", "}", "if", "(", "!", "_", ".", "isEqual", "(", "section", "[", "id", "]", ",", "value", ")", ")", "{", "if", "(", "value", "===", "undefined", ")", "{", "delete", "section", "[", "id", "]", ";", "}", "else", "{", "section", "[", "id", "]", "=", "_", ".", "cloneDeep", "(", "value", ")", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Sets the preference value in the given data structure for the layerID provided. If no layerID is provided, then the current layer is used. If a layerID is provided and it does not exist, it will be created. This function returns whether or not a value was set. @param {Object} data the preference data from the Scope @param {string} id preference ID to look up @param {Object} value new value to assign to the preference @param {Object} context Object with filename that will be compared to the globs @param {string=} layerID Optional: glob pattern for a specific section to set the value in @return {boolean} true if the value was set
[ "Sets", "the", "preference", "value", "in", "the", "given", "data", "structure", "for", "the", "layerID", "provided", ".", "If", "no", "layerID", "is", "provided", "then", "the", "current", "layer", "is", "used", ".", "If", "a", "layerID", "is", "provided", "and", "it", "does", "not", "exist", "it", "will", "be", "created", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L928-L950
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, context) { if (!data) { return; } var relativeFilename = FileUtils.getRelativeFilename(this.prefFilePath, context[this.key]); if (relativeFilename) { var glob = _findMatchingGlob(data, relativeFilename); if (glob) { return _.keys(data[glob]); } else { return []; } } return _.union.apply(null, _.map(_.values(data), _.keys)); }
javascript
function (data, context) { if (!data) { return; } var relativeFilename = FileUtils.getRelativeFilename(this.prefFilePath, context[this.key]); if (relativeFilename) { var glob = _findMatchingGlob(data, relativeFilename); if (glob) { return _.keys(data[glob]); } else { return []; } } return _.union.apply(null, _.map(_.values(data), _.keys)); }
[ "function", "(", "data", ",", "context", ")", "{", "if", "(", "!", "data", ")", "{", "return", ";", "}", "var", "relativeFilename", "=", "FileUtils", ".", "getRelativeFilename", "(", "this", ".", "prefFilePath", ",", "context", "[", "this", ".", "key", "]", ")", ";", "if", "(", "relativeFilename", ")", "{", "var", "glob", "=", "_findMatchingGlob", "(", "data", ",", "relativeFilename", ")", ";", "if", "(", "glob", ")", "{", "return", "_", ".", "keys", "(", "data", "[", "glob", "]", ")", ";", "}", "else", "{", "return", "[", "]", ";", "}", "}", "return", "_", ".", "union", ".", "apply", "(", "null", ",", "_", ".", "map", "(", "_", ".", "values", "(", "data", ")", ",", "_", ".", "keys", ")", ")", ";", "}" ]
Retrieves the keys provided by this layer object. If context with a filename is provided, only the keys for the matching file glob are given. Otherwise, all keys for all globs are provided. @param {Object} data the preference data from the Scope @param {?Object} context Additional context data (filename in particular is important)
[ "Retrieves", "the", "keys", "provided", "by", "this", "layer", "object", ".", "If", "context", "with", "a", "filename", "is", "provided", "only", "the", "keys", "for", "the", "matching", "file", "glob", "are", "given", ".", "Otherwise", "all", "keys", "for", "all", "globs", "are", "provided", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L960-L976
train
adobe/brackets
src/preferences/PreferencesBase.js
function (data, oldContext, newContext) { var newGlob = _findMatchingGlob(data, FileUtils.getRelativeFilename(this.prefFilePath, newContext[this.key])), oldGlob = _findMatchingGlob(data, FileUtils.getRelativeFilename(this.prefFilePath, oldContext[this.key])); if (newGlob === oldGlob) { return; } if (newGlob === undefined) { return _.keys(data[oldGlob]); } if (oldGlob === undefined) { return _.keys(data[newGlob]); } return _.union(_.keys(data[oldGlob]), _.keys(data[newGlob])); }
javascript
function (data, oldContext, newContext) { var newGlob = _findMatchingGlob(data, FileUtils.getRelativeFilename(this.prefFilePath, newContext[this.key])), oldGlob = _findMatchingGlob(data, FileUtils.getRelativeFilename(this.prefFilePath, oldContext[this.key])); if (newGlob === oldGlob) { return; } if (newGlob === undefined) { return _.keys(data[oldGlob]); } if (oldGlob === undefined) { return _.keys(data[newGlob]); } return _.union(_.keys(data[oldGlob]), _.keys(data[newGlob])); }
[ "function", "(", "data", ",", "oldContext", ",", "newContext", ")", "{", "var", "newGlob", "=", "_findMatchingGlob", "(", "data", ",", "FileUtils", ".", "getRelativeFilename", "(", "this", ".", "prefFilePath", ",", "newContext", "[", "this", ".", "key", "]", ")", ")", ",", "oldGlob", "=", "_findMatchingGlob", "(", "data", ",", "FileUtils", ".", "getRelativeFilename", "(", "this", ".", "prefFilePath", ",", "oldContext", "[", "this", ".", "key", "]", ")", ")", ";", "if", "(", "newGlob", "===", "oldGlob", ")", "{", "return", ";", "}", "if", "(", "newGlob", "===", "undefined", ")", "{", "return", "_", ".", "keys", "(", "data", "[", "oldGlob", "]", ")", ";", "}", "if", "(", "oldGlob", "===", "undefined", ")", "{", "return", "_", ".", "keys", "(", "data", "[", "newGlob", "]", ")", ";", "}", "return", "_", ".", "union", "(", "_", ".", "keys", "(", "data", "[", "oldGlob", "]", ")", ",", "_", ".", "keys", "(", "data", "[", "newGlob", "]", ")", ")", ";", "}" ]
Determines if there are preference IDs that could change as a result of a change in the context. This implementation considers only the path portion of the context and looks up matching globes if any. @param {Object} data Data in the Scope @param {{path: string}} oldContext Old context @param {{path: string}} newContext New context @return {Array.<string>} list of preference IDs that could have changed
[ "Determines", "if", "there", "are", "preference", "IDs", "that", "could", "change", "as", "a", "result", "of", "a", "change", "in", "the", "context", ".", "This", "implementation", "considers", "only", "the", "path", "portion", "of", "the", "context", "and", "looks", "up", "matching", "globes", "if", "any", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1001-L1018
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, context) { context = context || {}; return this.base.get(this.prefix + id, this.base._getContext(context)); }
javascript
function (id, context) { context = context || {}; return this.base.get(this.prefix + id, this.base._getContext(context)); }
[ "function", "(", "id", ",", "context", ")", "{", "context", "=", "context", "||", "{", "}", ";", "return", "this", ".", "base", ".", "get", "(", "this", ".", "prefix", "+", "id", ",", "this", ".", "base", ".", "_getContext", "(", "context", ")", ")", ";", "}" ]
Gets the prefixed preference @param {string} id Name of the preference for which the value should be retrieved @param {Object=} context Optional context object to change the preference lookup
[ "Gets", "the", "prefixed", "preference" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1099-L1102
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, value, options, doNotSave) { return this.base.set(this.prefix + id, value, options, doNotSave); }
javascript
function (id, value, options, doNotSave) { return this.base.set(this.prefix + id, value, options, doNotSave); }
[ "function", "(", "id", ",", "value", ",", "options", ",", "doNotSave", ")", "{", "return", "this", ".", "base", ".", "set", "(", "this", ".", "prefix", "+", "id", ",", "value", ",", "options", ",", "doNotSave", ")", ";", "}" ]
Sets the prefixed preference @param {string} id Identifier of the preference to set @param {Object} value New value for the preference @param {{location: ?Object, context: ?Object}=} options Specific location in which to set the value or the context to use when setting the value @param {boolean=} doNotSave True if the preference change should not be saved automatically. @return {valid: {boolean}, true if no validator specified or if value is valid stored: {boolean}} true if a value was stored
[ "Sets", "the", "prefixed", "preference" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1125-L1127
train
adobe/brackets
src/preferences/PreferencesBase.js
function (event, preferenceID, handler) { if (typeof preferenceID === "function") { handler = preferenceID; preferenceID = null; } if (preferenceID) { var pref = this.getPreference(preferenceID); pref.on(event, handler); } else { this._installListener(); this._on_internal(event, handler); } }
javascript
function (event, preferenceID, handler) { if (typeof preferenceID === "function") { handler = preferenceID; preferenceID = null; } if (preferenceID) { var pref = this.getPreference(preferenceID); pref.on(event, handler); } else { this._installListener(); this._on_internal(event, handler); } }
[ "function", "(", "event", ",", "preferenceID", ",", "handler", ")", "{", "if", "(", "typeof", "preferenceID", "===", "\"function\"", ")", "{", "handler", "=", "preferenceID", ";", "preferenceID", "=", "null", ";", "}", "if", "(", "preferenceID", ")", "{", "var", "pref", "=", "this", ".", "getPreference", "(", "preferenceID", ")", ";", "pref", ".", "on", "(", "event", ",", "handler", ")", ";", "}", "else", "{", "this", ".", "_installListener", "(", ")", ";", "this", ".", "_on_internal", "(", "event", ",", "handler", ")", ";", "}", "}" ]
Sets up a listener for events for this PrefixedPreferencesSystem. Only prefixed events will notify. Optionally, you can set up a listener for a specific preference. @param {string} event Name of the event to listen for @param {string|Function} preferenceID Name of a specific preference or the handler function @param {?Function} handler Handler for the event
[ "Sets", "up", "a", "listener", "for", "events", "for", "this", "PrefixedPreferencesSystem", ".", "Only", "prefixed", "events", "will", "notify", ".", "Optionally", "you", "can", "set", "up", "a", "listener", "for", "a", "specific", "preference", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1174-L1187
train
adobe/brackets
src/preferences/PreferencesBase.js
function (event, preferenceID, handler) { if (typeof preferenceID === "function") { handler = preferenceID; preferenceID = null; } if (preferenceID) { var pref = this.getPreference(preferenceID); pref.off(event, handler); } else { this._off_internal(event, handler); } }
javascript
function (event, preferenceID, handler) { if (typeof preferenceID === "function") { handler = preferenceID; preferenceID = null; } if (preferenceID) { var pref = this.getPreference(preferenceID); pref.off(event, handler); } else { this._off_internal(event, handler); } }
[ "function", "(", "event", ",", "preferenceID", ",", "handler", ")", "{", "if", "(", "typeof", "preferenceID", "===", "\"function\"", ")", "{", "handler", "=", "preferenceID", ";", "preferenceID", "=", "null", ";", "}", "if", "(", "preferenceID", ")", "{", "var", "pref", "=", "this", ".", "getPreference", "(", "preferenceID", ")", ";", "pref", ".", "off", "(", "event", ",", "handler", ")", ";", "}", "else", "{", "this", ".", "_off_internal", "(", "event", ",", "handler", ")", ";", "}", "}" ]
Turns off the event handlers for a given event, optionally for a specific preference or a specific handler function. @param {string} event Name of the event for which to turn off listening @param {string|Function} preferenceID Name of a specific preference or the handler function @param {?Function} handler Specific handler which should stop being notified
[ "Turns", "off", "the", "event", "handlers", "for", "a", "given", "event", "optionally", "for", "a", "specific", "preference", "or", "a", "specific", "handler", "function", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1197-L1209
train
adobe/brackets
src/preferences/PreferencesBase.js
PreferencesSystem
function PreferencesSystem(contextBuilder) { this.contextBuilder = contextBuilder; this._knownPrefs = {}; this._scopes = { "default": new Scope(new MemoryStorage()) }; this._scopes["default"].load(); this._defaults = { scopeOrder: ["default"], _shadowScopeOrder: [{ id: "default", scope: this._scopes["default"], promise: (new $.Deferred()).resolve().promise() }] }; this._pendingScopes = {}; this._saveInProgress = false; this._nextSaveDeferred = null; // The objects that define the different kinds of path-based Scope handlers. // Examples could include the handler for .brackets.json files or an .editorconfig // handler. this._pathScopeDefinitions = {}; // Names of the files that contain path scopes this._pathScopeFilenames = []; // Keeps track of cached path scope objects. this._pathScopes = {}; // Keeps track of change events that need to be sent when change events are resumed this._changeEventQueue = null; var notifyPrefChange = function (id) { var pref = this._knownPrefs[id]; if (pref) { pref.trigger(PREFERENCE_CHANGE); } }.bind(this); // When we signal a general change message on this manager, we also signal a change // on the individual preference object. this.on(PREFERENCE_CHANGE, function (e, data) { data.ids.forEach(notifyPrefChange); }.bind(this)); }
javascript
function PreferencesSystem(contextBuilder) { this.contextBuilder = contextBuilder; this._knownPrefs = {}; this._scopes = { "default": new Scope(new MemoryStorage()) }; this._scopes["default"].load(); this._defaults = { scopeOrder: ["default"], _shadowScopeOrder: [{ id: "default", scope: this._scopes["default"], promise: (new $.Deferred()).resolve().promise() }] }; this._pendingScopes = {}; this._saveInProgress = false; this._nextSaveDeferred = null; // The objects that define the different kinds of path-based Scope handlers. // Examples could include the handler for .brackets.json files or an .editorconfig // handler. this._pathScopeDefinitions = {}; // Names of the files that contain path scopes this._pathScopeFilenames = []; // Keeps track of cached path scope objects. this._pathScopes = {}; // Keeps track of change events that need to be sent when change events are resumed this._changeEventQueue = null; var notifyPrefChange = function (id) { var pref = this._knownPrefs[id]; if (pref) { pref.trigger(PREFERENCE_CHANGE); } }.bind(this); // When we signal a general change message on this manager, we also signal a change // on the individual preference object. this.on(PREFERENCE_CHANGE, function (e, data) { data.ids.forEach(notifyPrefChange); }.bind(this)); }
[ "function", "PreferencesSystem", "(", "contextBuilder", ")", "{", "this", ".", "contextBuilder", "=", "contextBuilder", ";", "this", ".", "_knownPrefs", "=", "{", "}", ";", "this", ".", "_scopes", "=", "{", "\"default\"", ":", "new", "Scope", "(", "new", "MemoryStorage", "(", ")", ")", "}", ";", "this", ".", "_scopes", "[", "\"default\"", "]", ".", "load", "(", ")", ";", "this", ".", "_defaults", "=", "{", "scopeOrder", ":", "[", "\"default\"", "]", ",", "_shadowScopeOrder", ":", "[", "{", "id", ":", "\"default\"", ",", "scope", ":", "this", ".", "_scopes", "[", "\"default\"", "]", ",", "promise", ":", "(", "new", "$", ".", "Deferred", "(", ")", ")", ".", "resolve", "(", ")", ".", "promise", "(", ")", "}", "]", "}", ";", "this", ".", "_pendingScopes", "=", "{", "}", ";", "this", ".", "_saveInProgress", "=", "false", ";", "this", ".", "_nextSaveDeferred", "=", "null", ";", "this", ".", "_pathScopeDefinitions", "=", "{", "}", ";", "this", ".", "_pathScopeFilenames", "=", "[", "]", ";", "this", ".", "_pathScopes", "=", "{", "}", ";", "this", ".", "_changeEventQueue", "=", "null", ";", "var", "notifyPrefChange", "=", "function", "(", "id", ")", "{", "var", "pref", "=", "this", ".", "_knownPrefs", "[", "id", "]", ";", "if", "(", "pref", ")", "{", "pref", ".", "trigger", "(", "PREFERENCE_CHANGE", ")", ";", "}", "}", ".", "bind", "(", "this", ")", ";", "this", ".", "on", "(", "PREFERENCE_CHANGE", ",", "function", "(", "e", ",", "data", ")", "{", "data", ".", "ids", ".", "forEach", "(", "notifyPrefChange", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "}" ]
PreferencesSystem ties everything together to provide a simple interface for managing the whole prefs system. It keeps track of multiple Scope levels and also manages path-based Scopes. It also provides the ability to register preferences, which gives a fine-grained means for listening for changes and will ultimately allow for automatic UI generation. The contextBuilder is used to construct get/set contexts based on the needs of individual context systems. It can be passed in at construction time or set later. @constructor @param {function=} contextNormalizer function that is passed the context used for get or set to adjust for specific PreferencesSystem behavior
[ "PreferencesSystem", "ties", "everything", "together", "to", "provide", "a", "simple", "interface", "for", "managing", "the", "whole", "prefs", "system", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1240-L1290
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, type, initial, options) { options = options || {}; if (this._knownPrefs.hasOwnProperty(id)) { throw new Error("Preference " + id + " was redefined"); } var pref = this._knownPrefs[id] = new Preference({ type: type, initial: initial, name: options.name, description: options.description, validator: options.validator, excludeFromHints: options.excludeFromHints, keys: options.keys, values: options.values, valueType: options.valueType }); this.set(id, initial, { location: { scope: "default" } }); return pref; }
javascript
function (id, type, initial, options) { options = options || {}; if (this._knownPrefs.hasOwnProperty(id)) { throw new Error("Preference " + id + " was redefined"); } var pref = this._knownPrefs[id] = new Preference({ type: type, initial: initial, name: options.name, description: options.description, validator: options.validator, excludeFromHints: options.excludeFromHints, keys: options.keys, values: options.values, valueType: options.valueType }); this.set(id, initial, { location: { scope: "default" } }); return pref; }
[ "function", "(", "id", ",", "type", ",", "initial", ",", "options", ")", "{", "options", "=", "options", "||", "{", "}", ";", "if", "(", "this", ".", "_knownPrefs", ".", "hasOwnProperty", "(", "id", ")", ")", "{", "throw", "new", "Error", "(", "\"Preference \"", "+", "id", "+", "\" was redefined\"", ")", ";", "}", "var", "pref", "=", "this", ".", "_knownPrefs", "[", "id", "]", "=", "new", "Preference", "(", "{", "type", ":", "type", ",", "initial", ":", "initial", ",", "name", ":", "options", ".", "name", ",", "description", ":", "options", ".", "description", ",", "validator", ":", "options", ".", "validator", ",", "excludeFromHints", ":", "options", ".", "excludeFromHints", ",", "keys", ":", "options", ".", "keys", ",", "values", ":", "options", ".", "values", ",", "valueType", ":", "options", ".", "valueType", "}", ")", ";", "this", ".", "set", "(", "id", ",", "initial", ",", "{", "location", ":", "{", "scope", ":", "\"default\"", "}", "}", ")", ";", "return", "pref", ";", "}" ]
Defines a new preference. @param {string} id identifier of the preference. Generally a dotted name. @param {string} type Data type for the preference (generally, string, boolean, number) @param {Object} initial Default value for the preference @param {?{name: string=, description: string=, validator: function=, excludeFromHints: boolean=, keys: object=, values: array=, valueType: string=}} options Additional options for the pref. - `options.name` Name of the preference that can be used in the UI. - `options.description` A description of the preference. - `options.validator` A function to validate the value of a preference. - `options.excludeFromHints` True if you want to exclude a preference from code hints. - `options.keys` An object that will hold the child preferences in case the preference type is `object` - `options.values` An array of possible values of a preference. It will show up in code hints. - `options.valueType` In case the preference type is `array`, `valueType` should hold data type of its elements. @return {Object} The preference object.
[ "Defines", "a", "new", "preference", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1311-L1333
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, addBefore) { var shadowScopeOrder = this._defaults._shadowScopeOrder, index = _.findIndex(shadowScopeOrder, function (entry) { return entry.id === id; }), entry; if (index > -1) { entry = shadowScopeOrder[index]; this._addToScopeOrder(entry.id, entry.scope, entry.promise, addBefore); } }
javascript
function (id, addBefore) { var shadowScopeOrder = this._defaults._shadowScopeOrder, index = _.findIndex(shadowScopeOrder, function (entry) { return entry.id === id; }), entry; if (index > -1) { entry = shadowScopeOrder[index]; this._addToScopeOrder(entry.id, entry.scope, entry.promise, addBefore); } }
[ "function", "(", "id", ",", "addBefore", ")", "{", "var", "shadowScopeOrder", "=", "this", ".", "_defaults", ".", "_shadowScopeOrder", ",", "index", "=", "_", ".", "findIndex", "(", "shadowScopeOrder", ",", "function", "(", "entry", ")", "{", "return", "entry", ".", "id", "===", "id", ";", "}", ")", ",", "entry", ";", "if", "(", "index", ">", "-", "1", ")", "{", "entry", "=", "shadowScopeOrder", "[", "index", "]", ";", "this", ".", "_addToScopeOrder", "(", "entry", ".", "id", ",", "entry", ".", "scope", ",", "entry", ".", "promise", ",", "addBefore", ")", ";", "}", "}" ]
Adds scope to the scope order by its id. The scope should be previously added to the preference system. @param {string} id the scope id @param {string} before the id of the scope to add before
[ "Adds", "scope", "to", "the", "scope", "order", "by", "its", "id", ".", "The", "scope", "should", "be", "previously", "added", "to", "the", "preference", "system", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1516-L1526
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id) { var scope = this._scopes[id]; if (scope) { _.pull(this._defaults.scopeOrder, id); scope.off(".prefsys"); this.trigger(SCOPEORDER_CHANGE, { id: id, action: "removed" }); this._triggerChange({ ids: scope.getKeys() }); } }
javascript
function (id) { var scope = this._scopes[id]; if (scope) { _.pull(this._defaults.scopeOrder, id); scope.off(".prefsys"); this.trigger(SCOPEORDER_CHANGE, { id: id, action: "removed" }); this._triggerChange({ ids: scope.getKeys() }); } }
[ "function", "(", "id", ")", "{", "var", "scope", "=", "this", ".", "_scopes", "[", "id", "]", ";", "if", "(", "scope", ")", "{", "_", ".", "pull", "(", "this", ".", "_defaults", ".", "scopeOrder", ",", "id", ")", ";", "scope", ".", "off", "(", "\".prefsys\"", ")", ";", "this", ".", "trigger", "(", "SCOPEORDER_CHANGE", ",", "{", "id", ":", "id", ",", "action", ":", "\"removed\"", "}", ")", ";", "this", ".", "_triggerChange", "(", "{", "ids", ":", "scope", ".", "getKeys", "(", ")", "}", ")", ";", "}", "}" ]
Removes a scope from the default scope order. @param {string} id Name of the Scope to remove from the default scope order.
[ "Removes", "a", "scope", "from", "the", "default", "scope", "order", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1533-L1546
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, scope, options) { var promise; options = options || {}; if (this._scopes[id]) { throw new Error("Attempt to redefine preferences scope: " + id); } // Check to see if scope is a Storage that needs to be wrapped if (!scope.get) { scope = new Scope(scope); } promise = scope.load(); this._addToScopeOrder(id, scope, promise, options.before); promise .fail(function (err) { // With preferences, it is valid for there to be no file. // It is not valid to have an unparseable file. if (err instanceof ParsingError) { console.error(err); } }); return promise; }
javascript
function (id, scope, options) { var promise; options = options || {}; if (this._scopes[id]) { throw new Error("Attempt to redefine preferences scope: " + id); } // Check to see if scope is a Storage that needs to be wrapped if (!scope.get) { scope = new Scope(scope); } promise = scope.load(); this._addToScopeOrder(id, scope, promise, options.before); promise .fail(function (err) { // With preferences, it is valid for there to be no file. // It is not valid to have an unparseable file. if (err instanceof ParsingError) { console.error(err); } }); return promise; }
[ "function", "(", "id", ",", "scope", ",", "options", ")", "{", "var", "promise", ";", "options", "=", "options", "||", "{", "}", ";", "if", "(", "this", ".", "_scopes", "[", "id", "]", ")", "{", "throw", "new", "Error", "(", "\"Attempt to redefine preferences scope: \"", "+", "id", ")", ";", "}", "if", "(", "!", "scope", ".", "get", ")", "{", "scope", "=", "new", "Scope", "(", "scope", ")", ";", "}", "promise", "=", "scope", ".", "load", "(", ")", ";", "this", ".", "_addToScopeOrder", "(", "id", ",", "scope", ",", "promise", ",", "options", ".", "before", ")", ";", "promise", ".", "fail", "(", "function", "(", "err", ")", "{", "if", "(", "err", "instanceof", "ParsingError", ")", "{", "console", ".", "error", "(", "err", ")", ";", "}", "}", ")", ";", "return", "promise", ";", "}" ]
Adds a new Scope. New Scopes are added at the highest precedence, unless the "before" option is given. The new Scope is automatically loaded. @param {string} id Name of the Scope @param {Scope|Storage} scope the Scope object itself. Optionally, can be given a Storage directly for convenience. @param {{before: string}} options optional behavior when adding (e.g. setting which scope this comes before) @return {Promise} Promise that is resolved when the Scope is loaded. It is resolved with id and scope.
[ "Adds", "a", "new", "Scope", ".", "New", "Scopes", "are", "added", "at", "the", "highest", "precedence", "unless", "the", "before", "option", "is", "given", ".", "The", "new", "Scope", "is", "automatically", "loaded", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1582-L1609
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id) { var scope = this._scopes[id], shadowIndex; if (!scope) { return; } this.removeFromScopeOrder(id); shadowIndex = _.findIndex(this._defaults._shadowScopeOrder, function (entry) { return entry.id === id; }); this._defaults._shadowScopeOrder.splice(shadowIndex, 1); delete this._scopes[id]; }
javascript
function (id) { var scope = this._scopes[id], shadowIndex; if (!scope) { return; } this.removeFromScopeOrder(id); shadowIndex = _.findIndex(this._defaults._shadowScopeOrder, function (entry) { return entry.id === id; }); this._defaults._shadowScopeOrder.splice(shadowIndex, 1); delete this._scopes[id]; }
[ "function", "(", "id", ")", "{", "var", "scope", "=", "this", ".", "_scopes", "[", "id", "]", ",", "shadowIndex", ";", "if", "(", "!", "scope", ")", "{", "return", ";", "}", "this", ".", "removeFromScopeOrder", "(", "id", ")", ";", "shadowIndex", "=", "_", ".", "findIndex", "(", "this", ".", "_defaults", ".", "_shadowScopeOrder", ",", "function", "(", "entry", ")", "{", "return", "entry", ".", "id", "===", "id", ";", "}", ")", ";", "this", ".", "_defaults", ".", "_shadowScopeOrder", ".", "splice", "(", "shadowIndex", ",", "1", ")", ";", "delete", "this", ".", "_scopes", "[", "id", "]", ";", "}" ]
Removes a Scope from this PreferencesSystem. Returns without doing anything if the Scope does not exist. Notifies listeners of preferences that may have changed. @param {string} id Name of the Scope to remove
[ "Removes", "a", "Scope", "from", "this", "PreferencesSystem", ".", "Returns", "without", "doing", "anything", "if", "the", "Scope", "does", "not", "exist", ".", "Notifies", "listeners", "of", "preferences", "that", "may", "have", "changed", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1618-L1631
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, context) { var scopeCounter; context = this._getContext(context); var scopeOrder = this._getScopeOrder(context); for (scopeCounter = 0; scopeCounter < scopeOrder.length; scopeCounter++) { var scope = this._scopes[scopeOrder[scopeCounter]]; if (scope) { var result = scope.get(id, context); if (result !== undefined) { var pref = this.getPreference(id), validator = pref && pref.validator; if (!validator || validator(result)) { if (pref && pref.type === "object") { result = _.extend({}, pref.initial, result); } return _.cloneDeep(result); } } } } }
javascript
function (id, context) { var scopeCounter; context = this._getContext(context); var scopeOrder = this._getScopeOrder(context); for (scopeCounter = 0; scopeCounter < scopeOrder.length; scopeCounter++) { var scope = this._scopes[scopeOrder[scopeCounter]]; if (scope) { var result = scope.get(id, context); if (result !== undefined) { var pref = this.getPreference(id), validator = pref && pref.validator; if (!validator || validator(result)) { if (pref && pref.type === "object") { result = _.extend({}, pref.initial, result); } return _.cloneDeep(result); } } } } }
[ "function", "(", "id", ",", "context", ")", "{", "var", "scopeCounter", ";", "context", "=", "this", ".", "_getContext", "(", "context", ")", ";", "var", "scopeOrder", "=", "this", ".", "_getScopeOrder", "(", "context", ")", ";", "for", "(", "scopeCounter", "=", "0", ";", "scopeCounter", "<", "scopeOrder", ".", "length", ";", "scopeCounter", "++", ")", "{", "var", "scope", "=", "this", ".", "_scopes", "[", "scopeOrder", "[", "scopeCounter", "]", "]", ";", "if", "(", "scope", ")", "{", "var", "result", "=", "scope", ".", "get", "(", "id", ",", "context", ")", ";", "if", "(", "result", "!==", "undefined", ")", "{", "var", "pref", "=", "this", ".", "getPreference", "(", "id", ")", ",", "validator", "=", "pref", "&&", "pref", ".", "validator", ";", "if", "(", "!", "validator", "||", "validator", "(", "result", ")", ")", "{", "if", "(", "pref", "&&", "pref", ".", "type", "===", "\"object\"", ")", "{", "result", "=", "_", ".", "extend", "(", "{", "}", ",", "pref", ".", "initial", ",", "result", ")", ";", "}", "return", "_", ".", "cloneDeep", "(", "result", ")", ";", "}", "}", "}", "}", "}" ]
Get the current value of a preference. The optional context provides a way to change scope ordering or the reference filename for path-based scopes. @param {string} id Name of the preference for which the value should be retrieved @param {Object|string=} context Optional context object or name of context to change the preference lookup
[ "Get", "the", "current", "value", "of", "a", "preference", ".", "The", "optional", "context", "provides", "a", "way", "to", "change", "scope", "ordering", "or", "the", "reference", "filename", "for", "path", "-", "based", "scopes", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1654-L1677
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, context) { var scopeCounter, scopeName; context = this._getContext(context); var scopeOrder = this._getScopeOrder(context); for (scopeCounter = 0; scopeCounter < scopeOrder.length; scopeCounter++) { scopeName = scopeOrder[scopeCounter]; var scope = this._scopes[scopeName]; if (scope) { var result = scope.getPreferenceLocation(id, context); if (result !== undefined) { result.scope = scopeName; return result; } } } }
javascript
function (id, context) { var scopeCounter, scopeName; context = this._getContext(context); var scopeOrder = this._getScopeOrder(context); for (scopeCounter = 0; scopeCounter < scopeOrder.length; scopeCounter++) { scopeName = scopeOrder[scopeCounter]; var scope = this._scopes[scopeName]; if (scope) { var result = scope.getPreferenceLocation(id, context); if (result !== undefined) { result.scope = scopeName; return result; } } } }
[ "function", "(", "id", ",", "context", ")", "{", "var", "scopeCounter", ",", "scopeName", ";", "context", "=", "this", ".", "_getContext", "(", "context", ")", ";", "var", "scopeOrder", "=", "this", ".", "_getScopeOrder", "(", "context", ")", ";", "for", "(", "scopeCounter", "=", "0", ";", "scopeCounter", "<", "scopeOrder", ".", "length", ";", "scopeCounter", "++", ")", "{", "scopeName", "=", "scopeOrder", "[", "scopeCounter", "]", ";", "var", "scope", "=", "this", ".", "_scopes", "[", "scopeName", "]", ";", "if", "(", "scope", ")", "{", "var", "result", "=", "scope", ".", "getPreferenceLocation", "(", "id", ",", "context", ")", ";", "if", "(", "result", "!==", "undefined", ")", "{", "result", ".", "scope", "=", "scopeName", ";", "return", "result", ";", "}", "}", "}", "}" ]
Gets the location in which the value of a preference has been set. @param {string} id Name of the preference for which the value should be retrieved @param {Object=} context Optional context object to change the preference lookup @return {{scope: string, layer: ?string, layerID: ?object}} Object describing where the preferences came from
[ "Gets", "the", "location", "in", "which", "the", "value", "of", "a", "preference", "has", "been", "set", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1686-L1705
train
adobe/brackets
src/preferences/PreferencesBase.js
function (id, value, options, doNotSave) { options = options || {}; var context = this._getContext(options.context), // The case where the "default" scope was chosen specifically is special. // Usually "default" would come up only when a preference did not have any // user-set value, in which case we'd want to set the value in a different scope. forceDefault = options.location && options.location.scope === "default" ? true : false, location = options.location || this.getPreferenceLocation(id, context); if (!location || (location.scope === "default" && !forceDefault)) { var scopeOrder = this._getScopeOrder(context); // The default scope for setting a preference is the lowest priority // scope after "default". if (scopeOrder.length > 1) { location = { scope: scopeOrder[scopeOrder.length - 2] }; } else { return { valid: true, stored: false }; } } var scope = this._scopes[location.scope]; if (!scope) { return { valid: true, stored: false }; } var pref = this.getPreference(id), validator = pref && pref.validator; if (validator && !validator(value)) { return { valid: false, stored: false }; } var wasSet = scope.set(id, value, context, location); if (wasSet) { if (!doNotSave) { this.save(); } this._triggerChange({ ids: [id] }); } return { valid: true, stored: wasSet }; }
javascript
function (id, value, options, doNotSave) { options = options || {}; var context = this._getContext(options.context), // The case where the "default" scope was chosen specifically is special. // Usually "default" would come up only when a preference did not have any // user-set value, in which case we'd want to set the value in a different scope. forceDefault = options.location && options.location.scope === "default" ? true : false, location = options.location || this.getPreferenceLocation(id, context); if (!location || (location.scope === "default" && !forceDefault)) { var scopeOrder = this._getScopeOrder(context); // The default scope for setting a preference is the lowest priority // scope after "default". if (scopeOrder.length > 1) { location = { scope: scopeOrder[scopeOrder.length - 2] }; } else { return { valid: true, stored: false }; } } var scope = this._scopes[location.scope]; if (!scope) { return { valid: true, stored: false }; } var pref = this.getPreference(id), validator = pref && pref.validator; if (validator && !validator(value)) { return { valid: false, stored: false }; } var wasSet = scope.set(id, value, context, location); if (wasSet) { if (!doNotSave) { this.save(); } this._triggerChange({ ids: [id] }); } return { valid: true, stored: wasSet }; }
[ "function", "(", "id", ",", "value", ",", "options", ",", "doNotSave", ")", "{", "options", "=", "options", "||", "{", "}", ";", "var", "context", "=", "this", ".", "_getContext", "(", "options", ".", "context", ")", ",", "forceDefault", "=", "options", ".", "location", "&&", "options", ".", "location", ".", "scope", "===", "\"default\"", "?", "true", ":", "false", ",", "location", "=", "options", ".", "location", "||", "this", ".", "getPreferenceLocation", "(", "id", ",", "context", ")", ";", "if", "(", "!", "location", "||", "(", "location", ".", "scope", "===", "\"default\"", "&&", "!", "forceDefault", ")", ")", "{", "var", "scopeOrder", "=", "this", ".", "_getScopeOrder", "(", "context", ")", ";", "if", "(", "scopeOrder", ".", "length", ">", "1", ")", "{", "location", "=", "{", "scope", ":", "scopeOrder", "[", "scopeOrder", ".", "length", "-", "2", "]", "}", ";", "}", "else", "{", "return", "{", "valid", ":", "true", ",", "stored", ":", "false", "}", ";", "}", "}", "var", "scope", "=", "this", ".", "_scopes", "[", "location", ".", "scope", "]", ";", "if", "(", "!", "scope", ")", "{", "return", "{", "valid", ":", "true", ",", "stored", ":", "false", "}", ";", "}", "var", "pref", "=", "this", ".", "getPreference", "(", "id", ")", ",", "validator", "=", "pref", "&&", "pref", ".", "validator", ";", "if", "(", "validator", "&&", "!", "validator", "(", "value", ")", ")", "{", "return", "{", "valid", ":", "false", ",", "stored", ":", "false", "}", ";", "}", "var", "wasSet", "=", "scope", ".", "set", "(", "id", ",", "value", ",", "context", ",", "location", ")", ";", "if", "(", "wasSet", ")", "{", "if", "(", "!", "doNotSave", ")", "{", "this", ".", "save", "(", ")", ";", "}", "this", ".", "_triggerChange", "(", "{", "ids", ":", "[", "id", "]", "}", ")", ";", "}", "return", "{", "valid", ":", "true", ",", "stored", ":", "wasSet", "}", ";", "}" ]
Sets a preference and notifies listeners that there may have been a change. By default, the preference is set in the same location in which it was defined except for the "default" scope. If the current value of the preference comes from the "default" scope, the new value will be set at the level just above default. @param {string} id Identifier of the preference to set @param {Object} value New value for the preference @param {{location: ?Object, context: ?Object}=} options Specific location in which to set the value or the context to use when setting the value @param {boolean=} doNotSave True if the preference change should not be saved automatically. @return {valid: {boolean}, true if no validator specified or if value is valid stored: {boolean}} true if a value was stored
[ "Sets", "a", "preference", "and", "notifies", "listeners", "that", "there", "may", "have", "been", "a", "change", ".", "By", "default", "the", "preference", "is", "set", "in", "the", "same", "location", "in", "which", "it", "was", "defined", "except", "for", "the", "default", "scope", ".", "If", "the", "current", "value", "of", "the", "preference", "comes", "from", "the", "default", "scope", "the", "new", "value", "will", "be", "set", "at", "the", "level", "just", "above", "default", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1721-L1766
train
adobe/brackets
src/preferences/PreferencesBase.js
function () { if (this._saveInProgress) { if (!this._nextSaveDeferred) { this._nextSaveDeferred = new $.Deferred(); } return this._nextSaveDeferred.promise(); } var deferred = this._nextSaveDeferred || (new $.Deferred()); this._saveInProgress = true; this._nextSaveDeferred = null; Async.doInParallel(_.values(this._scopes), function (scope) { if (scope) { return scope.save(); } else { return (new $.Deferred()).resolve().promise(); } }.bind(this)) .then(function () { this._saveInProgress = false; if (this._nextSaveDeferred) { this.save(); } deferred.resolve(); }.bind(this)) .fail(function (err) { deferred.reject(err); }); return deferred.promise(); }
javascript
function () { if (this._saveInProgress) { if (!this._nextSaveDeferred) { this._nextSaveDeferred = new $.Deferred(); } return this._nextSaveDeferred.promise(); } var deferred = this._nextSaveDeferred || (new $.Deferred()); this._saveInProgress = true; this._nextSaveDeferred = null; Async.doInParallel(_.values(this._scopes), function (scope) { if (scope) { return scope.save(); } else { return (new $.Deferred()).resolve().promise(); } }.bind(this)) .then(function () { this._saveInProgress = false; if (this._nextSaveDeferred) { this.save(); } deferred.resolve(); }.bind(this)) .fail(function (err) { deferred.reject(err); }); return deferred.promise(); }
[ "function", "(", ")", "{", "if", "(", "this", ".", "_saveInProgress", ")", "{", "if", "(", "!", "this", ".", "_nextSaveDeferred", ")", "{", "this", ".", "_nextSaveDeferred", "=", "new", "$", ".", "Deferred", "(", ")", ";", "}", "return", "this", ".", "_nextSaveDeferred", ".", "promise", "(", ")", ";", "}", "var", "deferred", "=", "this", ".", "_nextSaveDeferred", "||", "(", "new", "$", ".", "Deferred", "(", ")", ")", ";", "this", ".", "_saveInProgress", "=", "true", ";", "this", ".", "_nextSaveDeferred", "=", "null", ";", "Async", ".", "doInParallel", "(", "_", ".", "values", "(", "this", ".", "_scopes", ")", ",", "function", "(", "scope", ")", "{", "if", "(", "scope", ")", "{", "return", "scope", ".", "save", "(", ")", ";", "}", "else", "{", "return", "(", "new", "$", ".", "Deferred", "(", ")", ")", ".", "resolve", "(", ")", ".", "promise", "(", ")", ";", "}", "}", ".", "bind", "(", "this", ")", ")", ".", "then", "(", "function", "(", ")", "{", "this", ".", "_saveInProgress", "=", "false", ";", "if", "(", "this", ".", "_nextSaveDeferred", ")", "{", "this", ".", "save", "(", ")", ";", "}", "deferred", ".", "resolve", "(", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ".", "fail", "(", "function", "(", "err", ")", "{", "deferred", ".", "reject", "(", "err", ")", ";", "}", ")", ";", "return", "deferred", ".", "promise", "(", ")", ";", "}" ]
Saves the preferences. If a save is already in progress, a Promise is returned for that save operation. @return {Promise} Resolved when the preferences are done saving.
[ "Saves", "the", "preferences", ".", "If", "a", "save", "is", "already", "in", "progress", "a", "Promise", "is", "returned", "for", "that", "save", "operation", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1774-L1805
train
adobe/brackets
src/preferences/PreferencesBase.js
function (oldContext, newContext) { var changes = []; _.each(this._scopes, function (scope) { var changedInScope = scope.contextChanged(oldContext, newContext); if (changedInScope) { changes.push(changedInScope); } }); changes = _.union.apply(null, changes); if (changes.length > 0) { this._triggerChange({ ids: changes }); } }
javascript
function (oldContext, newContext) { var changes = []; _.each(this._scopes, function (scope) { var changedInScope = scope.contextChanged(oldContext, newContext); if (changedInScope) { changes.push(changedInScope); } }); changes = _.union.apply(null, changes); if (changes.length > 0) { this._triggerChange({ ids: changes }); } }
[ "function", "(", "oldContext", ",", "newContext", ")", "{", "var", "changes", "=", "[", "]", ";", "_", ".", "each", "(", "this", ".", "_scopes", ",", "function", "(", "scope", ")", "{", "var", "changedInScope", "=", "scope", ".", "contextChanged", "(", "oldContext", ",", "newContext", ")", ";", "if", "(", "changedInScope", ")", "{", "changes", ".", "push", "(", "changedInScope", ")", ";", "}", "}", ")", ";", "changes", "=", "_", ".", "union", ".", "apply", "(", "null", ",", "changes", ")", ";", "if", "(", "changes", ".", "length", ">", "0", ")", "{", "this", ".", "_triggerChange", "(", "{", "ids", ":", "changes", "}", ")", ";", "}", "}" ]
Signals the context change to all the scopes within the preferences layer. PreferencesManager is in charge of computing the context and signaling the changes to PreferencesSystem. @param {{path: string, language: string}} oldContext Old context @param {{path: string, language: string}} newContext New context
[ "Signals", "the", "context", "change", "to", "all", "the", "scopes", "within", "the", "preferences", "layer", ".", "PreferencesManager", "is", "in", "charge", "of", "computing", "the", "context", "and", "signaling", "the", "changes", "to", "PreferencesSystem", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/preferences/PreferencesBase.js#L1815-L1831
train
adobe/brackets
src/project/SidebarView.js
_updateWorkingSetState
function _updateWorkingSetState() { if (MainViewManager.getPaneCount() === 1 && MainViewManager.getWorkingSetSize(MainViewManager.ACTIVE_PANE) === 0) { $workingSetViewsContainer.hide(); $gearMenu.hide(); } else { $workingSetViewsContainer.show(); $gearMenu.show(); } }
javascript
function _updateWorkingSetState() { if (MainViewManager.getPaneCount() === 1 && MainViewManager.getWorkingSetSize(MainViewManager.ACTIVE_PANE) === 0) { $workingSetViewsContainer.hide(); $gearMenu.hide(); } else { $workingSetViewsContainer.show(); $gearMenu.show(); } }
[ "function", "_updateWorkingSetState", "(", ")", "{", "if", "(", "MainViewManager", ".", "getPaneCount", "(", ")", "===", "1", "&&", "MainViewManager", ".", "getWorkingSetSize", "(", "MainViewManager", ".", "ACTIVE_PANE", ")", "===", "0", ")", "{", "$workingSetViewsContainer", ".", "hide", "(", ")", ";", "$gearMenu", ".", "hide", "(", ")", ";", "}", "else", "{", "$workingSetViewsContainer", ".", "show", "(", ")", ";", "$gearMenu", ".", "show", "(", ")", ";", "}", "}" ]
Update state of working set @private
[ "Update", "state", "of", "working", "set" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/SidebarView.js#L115-L124
train
adobe/brackets
src/project/SidebarView.js
_updateUIStates
function _updateUIStates() { var spriteIndex, ICON_CLASSES = ["splitview-icon-none", "splitview-icon-vertical", "splitview-icon-horizontal"], layoutScheme = MainViewManager.getLayoutScheme(); if (layoutScheme.columns > 1) { spriteIndex = 1; } else if (layoutScheme.rows > 1) { spriteIndex = 2; } else { spriteIndex = 0; } // SplitView Icon $splitViewMenu.removeClass(ICON_CLASSES.join(" ")) .addClass(ICON_CLASSES[spriteIndex]); // SplitView Menu _cmdSplitNone.setChecked(spriteIndex === 0); _cmdSplitVertical.setChecked(spriteIndex === 1); _cmdSplitHorizontal.setChecked(spriteIndex === 2); // Options icon _updateWorkingSetState(); }
javascript
function _updateUIStates() { var spriteIndex, ICON_CLASSES = ["splitview-icon-none", "splitview-icon-vertical", "splitview-icon-horizontal"], layoutScheme = MainViewManager.getLayoutScheme(); if (layoutScheme.columns > 1) { spriteIndex = 1; } else if (layoutScheme.rows > 1) { spriteIndex = 2; } else { spriteIndex = 0; } // SplitView Icon $splitViewMenu.removeClass(ICON_CLASSES.join(" ")) .addClass(ICON_CLASSES[spriteIndex]); // SplitView Menu _cmdSplitNone.setChecked(spriteIndex === 0); _cmdSplitVertical.setChecked(spriteIndex === 1); _cmdSplitHorizontal.setChecked(spriteIndex === 2); // Options icon _updateWorkingSetState(); }
[ "function", "_updateUIStates", "(", ")", "{", "var", "spriteIndex", ",", "ICON_CLASSES", "=", "[", "\"splitview-icon-none\"", ",", "\"splitview-icon-vertical\"", ",", "\"splitview-icon-horizontal\"", "]", ",", "layoutScheme", "=", "MainViewManager", ".", "getLayoutScheme", "(", ")", ";", "if", "(", "layoutScheme", ".", "columns", ">", "1", ")", "{", "spriteIndex", "=", "1", ";", "}", "else", "if", "(", "layoutScheme", ".", "rows", ">", "1", ")", "{", "spriteIndex", "=", "2", ";", "}", "else", "{", "spriteIndex", "=", "0", ";", "}", "$splitViewMenu", ".", "removeClass", "(", "ICON_CLASSES", ".", "join", "(", "\" \"", ")", ")", ".", "addClass", "(", "ICON_CLASSES", "[", "spriteIndex", "]", ")", ";", "_cmdSplitNone", ".", "setChecked", "(", "spriteIndex", "===", "0", ")", ";", "_cmdSplitVertical", ".", "setChecked", "(", "spriteIndex", "===", "1", ")", ";", "_cmdSplitHorizontal", ".", "setChecked", "(", "spriteIndex", "===", "2", ")", ";", "_updateWorkingSetState", "(", ")", ";", "}" ]
Update state of splitview and option elements @private
[ "Update", "state", "of", "splitview", "and", "option", "elements" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/SidebarView.js#L130-L154
train
adobe/brackets
src/extensions/default/CommandLineTool/main.js
addCommand
function addCommand() { var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU), INSTALL_COMMAND_SCRIPT = "file.installCommandScript"; CommandManager.register(Strings.CMD_LAUNCH_SCRIPT_MAC, INSTALL_COMMAND_SCRIPT, handleInstallCommand); menu.addMenuDivider(); menu.addMenuItem(INSTALL_COMMAND_SCRIPT); }
javascript
function addCommand() { var menu = Menus.getMenu(Menus.AppMenuBar.FILE_MENU), INSTALL_COMMAND_SCRIPT = "file.installCommandScript"; CommandManager.register(Strings.CMD_LAUNCH_SCRIPT_MAC, INSTALL_COMMAND_SCRIPT, handleInstallCommand); menu.addMenuDivider(); menu.addMenuItem(INSTALL_COMMAND_SCRIPT); }
[ "function", "addCommand", "(", ")", "{", "var", "menu", "=", "Menus", ".", "getMenu", "(", "Menus", ".", "AppMenuBar", ".", "FILE_MENU", ")", ",", "INSTALL_COMMAND_SCRIPT", "=", "\"file.installCommandScript\"", ";", "CommandManager", ".", "register", "(", "Strings", ".", "CMD_LAUNCH_SCRIPT_MAC", ",", "INSTALL_COMMAND_SCRIPT", ",", "handleInstallCommand", ")", ";", "menu", ".", "addMenuDivider", "(", ")", ";", "menu", ".", "addMenuItem", "(", "INSTALL_COMMAND_SCRIPT", ")", ";", "}" ]
Register the command and add the menu to file menu.
[ "Register", "the", "command", "and", "add", "the", "menu", "to", "file", "menu", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CommandLineTool/main.js#L97-L105
train
adobe/brackets
src/JSUtils/Session.js
Session
function Session(editor) { this.editor = editor; this.path = editor.document.file.fullPath; this.ternHints = []; this.ternGuesses = null; this.fnType = null; this.builtins = null; }
javascript
function Session(editor) { this.editor = editor; this.path = editor.document.file.fullPath; this.ternHints = []; this.ternGuesses = null; this.fnType = null; this.builtins = null; }
[ "function", "Session", "(", "editor", ")", "{", "this", ".", "editor", "=", "editor", ";", "this", ".", "path", "=", "editor", ".", "document", ".", "file", ".", "fullPath", ";", "this", ".", "ternHints", "=", "[", "]", ";", "this", ".", "ternGuesses", "=", "null", ";", "this", ".", "fnType", "=", "null", ";", "this", ".", "builtins", "=", "null", ";", "}" ]
Session objects encapsulate state associated with a hinting session and provide methods for updating and querying the session. @constructor @param {Editor} editor - the editor context for the session
[ "Session", "objects", "encapsulate", "state", "associated", "with", "a", "hinting", "session", "and", "provide", "methods", "for", "updating", "and", "querying", "the", "session", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/Session.js#L45-L52
train
adobe/brackets
src/JSUtils/Session.js
isOnFunctionIdentifier
function isOnFunctionIdentifier() { // Check if we might be on function identifier of the function call. var type = token.type, nextToken, localLexical, localCursor = {line: cursor.line, ch: token.end}; if (type === "variable-2" || type === "variable" || type === "property") { nextToken = self.getNextToken(localCursor, true); if (nextToken && nextToken.string === "(") { localLexical = getLexicalState(nextToken); return localLexical; } } return null; }
javascript
function isOnFunctionIdentifier() { // Check if we might be on function identifier of the function call. var type = token.type, nextToken, localLexical, localCursor = {line: cursor.line, ch: token.end}; if (type === "variable-2" || type === "variable" || type === "property") { nextToken = self.getNextToken(localCursor, true); if (nextToken && nextToken.string === "(") { localLexical = getLexicalState(nextToken); return localLexical; } } return null; }
[ "function", "isOnFunctionIdentifier", "(", ")", "{", "var", "type", "=", "token", ".", "type", ",", "nextToken", ",", "localLexical", ",", "localCursor", "=", "{", "line", ":", "cursor", ".", "line", ",", "ch", ":", "token", ".", "end", "}", ";", "if", "(", "type", "===", "\"variable-2\"", "||", "type", "===", "\"variable\"", "||", "type", "===", "\"property\"", ")", "{", "nextToken", "=", "self", ".", "getNextToken", "(", "localCursor", ",", "true", ")", ";", "if", "(", "nextToken", "&&", "nextToken", ".", "string", "===", "\"(\"", ")", "{", "localLexical", "=", "getLexicalState", "(", "nextToken", ")", ";", "return", "localLexical", ";", "}", "}", "return", "null", ";", "}" ]
Test if the cursor is on a function identifier @return {Object} - lexical state if on a function identifier, null otherwise.
[ "Test", "if", "the", "cursor", "is", "on", "a", "function", "identifier" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/Session.js#L364-L381
train
adobe/brackets
src/JSUtils/Session.js
isInFunctionalCall
function isInFunctionalCall(lex) { // in a call, or inside array or object brackets that are inside a function. return (lex && (lex.info === "call" || (lex.info === undefined && (lex.type === "]" || lex.type === "}") && lex.prev.info === "call"))); }
javascript
function isInFunctionalCall(lex) { // in a call, or inside array or object brackets that are inside a function. return (lex && (lex.info === "call" || (lex.info === undefined && (lex.type === "]" || lex.type === "}") && lex.prev.info === "call"))); }
[ "function", "isInFunctionalCall", "(", "lex", ")", "{", "return", "(", "lex", "&&", "(", "lex", ".", "info", "===", "\"call\"", "||", "(", "lex", ".", "info", "===", "undefined", "&&", "(", "lex", ".", "type", "===", "\"]\"", "||", "lex", ".", "type", "===", "\"}\"", ")", "&&", "lex", ".", "prev", ".", "info", "===", "\"call\"", ")", ")", ")", ";", "}" ]
Test is a lexical state is in a function call. @param {Object} lex - lexical state. @return {Object | boolean}
[ "Test", "is", "a", "lexical", "state", "is", "in", "a", "function", "call", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/Session.js#L390-L395
train
adobe/brackets
src/JSUtils/Session.js
penalizeUnderscoreValueCompare
function penalizeUnderscoreValueCompare(a, b) { var aName = a.value.toLowerCase(), bName = b.value.toLowerCase(); // this sort function will cause _ to sort lower than lower case // alphabetical letters if (aName[0] === "_" && bName[0] !== "_") { return 1; } else if (bName[0] === "_" && aName[0] !== "_") { return -1; } if (aName < bName) { return -1; } else if (aName > bName) { return 1; } return 0; }
javascript
function penalizeUnderscoreValueCompare(a, b) { var aName = a.value.toLowerCase(), bName = b.value.toLowerCase(); // this sort function will cause _ to sort lower than lower case // alphabetical letters if (aName[0] === "_" && bName[0] !== "_") { return 1; } else if (bName[0] === "_" && aName[0] !== "_") { return -1; } if (aName < bName) { return -1; } else if (aName > bName) { return 1; } return 0; }
[ "function", "penalizeUnderscoreValueCompare", "(", "a", ",", "b", ")", "{", "var", "aName", "=", "a", ".", "value", ".", "toLowerCase", "(", ")", ",", "bName", "=", "b", ".", "value", ".", "toLowerCase", "(", ")", ";", "if", "(", "aName", "[", "0", "]", "===", "\"_\"", "&&", "bName", "[", "0", "]", "!==", "\"_\"", ")", "{", "return", "1", ";", "}", "else", "if", "(", "bName", "[", "0", "]", "===", "\"_\"", "&&", "aName", "[", "0", "]", "!==", "\"_\"", ")", "{", "return", "-", "1", ";", "}", "if", "(", "aName", "<", "bName", ")", "{", "return", "-", "1", ";", "}", "else", "if", "(", "aName", ">", "bName", ")", "{", "return", "1", ";", "}", "return", "0", ";", "}" ]
Comparison function used for sorting that does a case-insensitive string comparison on the "value" field of both objects. Unlike a normal string comparison, however, this sorts leading "_" to the bottom, given that a leading "_" usually denotes a private value.
[ "Comparison", "function", "used", "for", "sorting", "that", "does", "a", "case", "-", "insensitive", "string", "comparison", "on", "the", "value", "field", "of", "both", "objects", ".", "Unlike", "a", "normal", "string", "comparison", "however", "this", "sorts", "leading", "_", "to", "the", "bottom", "given", "that", "a", "leading", "_", "usually", "denotes", "a", "private", "value", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/Session.js#L491-L506
train
adobe/brackets
src/JSUtils/Session.js
filterWithQueryAndMatcher
function filterWithQueryAndMatcher(hints, matcher) { var matchResults = $.map(hints, function (hint) { var searchResult = matcher.match(hint.value, query); if (searchResult) { searchResult.value = hint.value; searchResult.guess = hint.guess; searchResult.type = hint.type; if (hint.keyword !== undefined) { searchResult.keyword = hint.keyword; } if (hint.literal !== undefined) { searchResult.literal = hint.literal; } if (hint.depth !== undefined) { searchResult.depth = hint.depth; } if (hint.doc) { searchResult.doc = hint.doc; } if (hint.url) { searchResult.url = hint.url; } if (!type.property && !type.showFunctionType && hint.origin && isBuiltin(hint.origin)) { searchResult.builtin = 1; } else { searchResult.builtin = 0; } } return searchResult; }); return matchResults; }
javascript
function filterWithQueryAndMatcher(hints, matcher) { var matchResults = $.map(hints, function (hint) { var searchResult = matcher.match(hint.value, query); if (searchResult) { searchResult.value = hint.value; searchResult.guess = hint.guess; searchResult.type = hint.type; if (hint.keyword !== undefined) { searchResult.keyword = hint.keyword; } if (hint.literal !== undefined) { searchResult.literal = hint.literal; } if (hint.depth !== undefined) { searchResult.depth = hint.depth; } if (hint.doc) { searchResult.doc = hint.doc; } if (hint.url) { searchResult.url = hint.url; } if (!type.property && !type.showFunctionType && hint.origin && isBuiltin(hint.origin)) { searchResult.builtin = 1; } else { searchResult.builtin = 0; } } return searchResult; }); return matchResults; }
[ "function", "filterWithQueryAndMatcher", "(", "hints", ",", "matcher", ")", "{", "var", "matchResults", "=", "$", ".", "map", "(", "hints", ",", "function", "(", "hint", ")", "{", "var", "searchResult", "=", "matcher", ".", "match", "(", "hint", ".", "value", ",", "query", ")", ";", "if", "(", "searchResult", ")", "{", "searchResult", ".", "value", "=", "hint", ".", "value", ";", "searchResult", ".", "guess", "=", "hint", ".", "guess", ";", "searchResult", ".", "type", "=", "hint", ".", "type", ";", "if", "(", "hint", ".", "keyword", "!==", "undefined", ")", "{", "searchResult", ".", "keyword", "=", "hint", ".", "keyword", ";", "}", "if", "(", "hint", ".", "literal", "!==", "undefined", ")", "{", "searchResult", ".", "literal", "=", "hint", ".", "literal", ";", "}", "if", "(", "hint", ".", "depth", "!==", "undefined", ")", "{", "searchResult", ".", "depth", "=", "hint", ".", "depth", ";", "}", "if", "(", "hint", ".", "doc", ")", "{", "searchResult", ".", "doc", "=", "hint", ".", "doc", ";", "}", "if", "(", "hint", ".", "url", ")", "{", "searchResult", ".", "url", "=", "hint", ".", "url", ";", "}", "if", "(", "!", "type", ".", "property", "&&", "!", "type", ".", "showFunctionType", "&&", "hint", ".", "origin", "&&", "isBuiltin", "(", "hint", ".", "origin", ")", ")", "{", "searchResult", ".", "builtin", "=", "1", ";", "}", "else", "{", "searchResult", ".", "builtin", "=", "0", ";", "}", "}", "return", "searchResult", ";", "}", ")", ";", "return", "matchResults", ";", "}" ]
Filter an array hints using a given query and matcher. The hints are returned in the format of the matcher. The matcher returns the value in the "label" property, the match score in "matchGoodness" property. @param {Array} hints - array of hints @param {StringMatcher} matcher @return {Array} - array of matching hints.
[ "Filter", "an", "array", "hints", "using", "a", "given", "query", "and", "matcher", ".", "The", "hints", "are", "returned", "in", "the", "format", "of", "the", "matcher", ".", "The", "matcher", "returns", "the", "value", "in", "the", "label", "property", "the", "match", "score", "in", "matchGoodness", "property", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/Session.js#L549-L589
train
adobe/brackets
src/extensibility/Package.js
install
function install(path, nameHint, _doUpdate) { return _extensionManagerCall(function (extensionManager) { var d = new $.Deferred(), destinationDirectory = ExtensionLoader.getUserExtensionPath(), disabledDirectory = destinationDirectory.replace(/\/user$/, "/disabled"), systemDirectory = FileUtils.getNativeBracketsDirectoryPath() + "/extensions/default/"; var operation = _doUpdate ? "update" : "install"; extensionManager[operation](path, destinationDirectory, { disabledDirectory: disabledDirectory, systemExtensionDirectory: systemDirectory, apiVersion: brackets.metadata.apiVersion, nameHint: nameHint, proxy: PreferencesManager.get("proxy") }) .done(function (result) { result.keepFile = false; if (result.installationStatus !== InstallationStatuses.INSTALLED || _doUpdate) { d.resolve(result); } else { // This was a new extension and everything looked fine. // We load it into Brackets right away. ExtensionLoader.loadExtension(result.name, { // On Windows, it looks like Node converts Unix-y paths to backslashy paths. // We need to convert them back. baseUrl: FileUtils.convertWindowsPathToUnixPath(result.installedTo) }, "main").then(function () { d.resolve(result); }, function () { d.reject(Errors.ERROR_LOADING); }); } }) .fail(function (error) { d.reject(error); }); return d.promise(); }); }
javascript
function install(path, nameHint, _doUpdate) { return _extensionManagerCall(function (extensionManager) { var d = new $.Deferred(), destinationDirectory = ExtensionLoader.getUserExtensionPath(), disabledDirectory = destinationDirectory.replace(/\/user$/, "/disabled"), systemDirectory = FileUtils.getNativeBracketsDirectoryPath() + "/extensions/default/"; var operation = _doUpdate ? "update" : "install"; extensionManager[operation](path, destinationDirectory, { disabledDirectory: disabledDirectory, systemExtensionDirectory: systemDirectory, apiVersion: brackets.metadata.apiVersion, nameHint: nameHint, proxy: PreferencesManager.get("proxy") }) .done(function (result) { result.keepFile = false; if (result.installationStatus !== InstallationStatuses.INSTALLED || _doUpdate) { d.resolve(result); } else { // This was a new extension and everything looked fine. // We load it into Brackets right away. ExtensionLoader.loadExtension(result.name, { // On Windows, it looks like Node converts Unix-y paths to backslashy paths. // We need to convert them back. baseUrl: FileUtils.convertWindowsPathToUnixPath(result.installedTo) }, "main").then(function () { d.resolve(result); }, function () { d.reject(Errors.ERROR_LOADING); }); } }) .fail(function (error) { d.reject(error); }); return d.promise(); }); }
[ "function", "install", "(", "path", ",", "nameHint", ",", "_doUpdate", ")", "{", "return", "_extensionManagerCall", "(", "function", "(", "extensionManager", ")", "{", "var", "d", "=", "new", "$", ".", "Deferred", "(", ")", ",", "destinationDirectory", "=", "ExtensionLoader", ".", "getUserExtensionPath", "(", ")", ",", "disabledDirectory", "=", "destinationDirectory", ".", "replace", "(", "/", "\\/user$", "/", ",", "\"/disabled\"", ")", ",", "systemDirectory", "=", "FileUtils", ".", "getNativeBracketsDirectoryPath", "(", ")", "+", "\"/extensions/default/\"", ";", "var", "operation", "=", "_doUpdate", "?", "\"update\"", ":", "\"install\"", ";", "extensionManager", "[", "operation", "]", "(", "path", ",", "destinationDirectory", ",", "{", "disabledDirectory", ":", "disabledDirectory", ",", "systemExtensionDirectory", ":", "systemDirectory", ",", "apiVersion", ":", "brackets", ".", "metadata", ".", "apiVersion", ",", "nameHint", ":", "nameHint", ",", "proxy", ":", "PreferencesManager", ".", "get", "(", "\"proxy\"", ")", "}", ")", ".", "done", "(", "function", "(", "result", ")", "{", "result", ".", "keepFile", "=", "false", ";", "if", "(", "result", ".", "installationStatus", "!==", "InstallationStatuses", ".", "INSTALLED", "||", "_doUpdate", ")", "{", "d", ".", "resolve", "(", "result", ")", ";", "}", "else", "{", "ExtensionLoader", ".", "loadExtension", "(", "result", ".", "name", ",", "{", "baseUrl", ":", "FileUtils", ".", "convertWindowsPathToUnixPath", "(", "result", ".", "installedTo", ")", "}", ",", "\"main\"", ")", ".", "then", "(", "function", "(", ")", "{", "d", ".", "resolve", "(", "result", ")", ";", "}", ",", "function", "(", ")", "{", "d", ".", "reject", "(", "Errors", ".", "ERROR_LOADING", ")", ";", "}", ")", ";", "}", "}", ")", ".", "fail", "(", "function", "(", "error", ")", "{", "d", ".", "reject", "(", "error", ")", ";", "}", ")", ";", "return", "d", ".", "promise", "(", ")", ";", "}", ")", ";", "}" ]
Validates and installs the package at the given path. Validation and installation is handled by the Node process. The extension will be installed into the user's extensions directory. If the user already has the extension installed, it will instead go into their disabled extensions directory. The promise is resolved with an object: { errors: Array.<{string}>, metadata: { name:string, version:string, ... }, disabledReason:string, installedTo:string, commonPrefix:string } metadata is pulled straight from package.json and is likely to be undefined if there are errors. It is null if there was no package.json. disabledReason is either null or the reason the extension was installed disabled. @param {string} path Absolute path to the package zip file @param {?string} nameHint Hint for the extension folder's name (used in favor of path's filename if present, and if no package metadata present). @param {?boolean} _doUpdate private argument used to signal an update @return {$.Promise} A promise that is resolved with information about the package (which may include errors, in which case the extension was disabled), or rejected with an error object.
[ "Validates", "and", "installs", "the", "package", "at", "the", "given", "path", ".", "Validation", "and", "installation", "is", "handled", "by", "the", "Node", "process", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/Package.js#L158-L198
train
adobe/brackets
src/extensibility/Package.js
toggleDefaultExtension
function toggleDefaultExtension(path, enabled) { var arr = PreferencesManager.get(PREF_EXTENSIONS_DEFAULT_DISABLED); if (!Array.isArray(arr)) { arr = []; } var io = arr.indexOf(path); if (enabled === true && io !== -1) { arr.splice(io, 1); } else if (enabled === false && io === -1) { arr.push(path); } PreferencesManager.set(PREF_EXTENSIONS_DEFAULT_DISABLED, arr); }
javascript
function toggleDefaultExtension(path, enabled) { var arr = PreferencesManager.get(PREF_EXTENSIONS_DEFAULT_DISABLED); if (!Array.isArray(arr)) { arr = []; } var io = arr.indexOf(path); if (enabled === true && io !== -1) { arr.splice(io, 1); } else if (enabled === false && io === -1) { arr.push(path); } PreferencesManager.set(PREF_EXTENSIONS_DEFAULT_DISABLED, arr); }
[ "function", "toggleDefaultExtension", "(", "path", ",", "enabled", ")", "{", "var", "arr", "=", "PreferencesManager", ".", "get", "(", "PREF_EXTENSIONS_DEFAULT_DISABLED", ")", ";", "if", "(", "!", "Array", ".", "isArray", "(", "arr", ")", ")", "{", "arr", "=", "[", "]", ";", "}", "var", "io", "=", "arr", ".", "indexOf", "(", "path", ")", ";", "if", "(", "enabled", "===", "true", "&&", "io", "!==", "-", "1", ")", "{", "arr", ".", "splice", "(", "io", ",", "1", ")", ";", "}", "else", "if", "(", "enabled", "===", "false", "&&", "io", "===", "-", "1", ")", "{", "arr", ".", "push", "(", "path", ")", ";", "}", "PreferencesManager", ".", "set", "(", "PREF_EXTENSIONS_DEFAULT_DISABLED", ",", "arr", ")", ";", "}" ]
This function manages the PREF_EXTENSIONS_DEFAULT_DISABLED preference holding an array of default extension paths that should not be loaded on Brackets startup
[ "This", "function", "manages", "the", "PREF_EXTENSIONS_DEFAULT_DISABLED", "preference", "holding", "an", "array", "of", "default", "extension", "paths", "that", "should", "not", "be", "loaded", "on", "Brackets", "startup" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/Package.js#L449-L459
train
adobe/brackets
src/extensibility/Package.js
disable
function disable(path) { var result = new $.Deferred(), file = FileSystem.getFileForPath(path + "/.disabled"); var defaultExtensionPath = ExtensionLoader.getDefaultExtensionPath(); if (file.fullPath.indexOf(defaultExtensionPath) === 0) { toggleDefaultExtension(path, false); result.resolve(); return result.promise(); } file.write("", function (err) { if (err) { return result.reject(err); } result.resolve(); }); return result.promise(); }
javascript
function disable(path) { var result = new $.Deferred(), file = FileSystem.getFileForPath(path + "/.disabled"); var defaultExtensionPath = ExtensionLoader.getDefaultExtensionPath(); if (file.fullPath.indexOf(defaultExtensionPath) === 0) { toggleDefaultExtension(path, false); result.resolve(); return result.promise(); } file.write("", function (err) { if (err) { return result.reject(err); } result.resolve(); }); return result.promise(); }
[ "function", "disable", "(", "path", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ",", "file", "=", "FileSystem", ".", "getFileForPath", "(", "path", "+", "\"/.disabled\"", ")", ";", "var", "defaultExtensionPath", "=", "ExtensionLoader", ".", "getDefaultExtensionPath", "(", ")", ";", "if", "(", "file", ".", "fullPath", ".", "indexOf", "(", "defaultExtensionPath", ")", "===", "0", ")", "{", "toggleDefaultExtension", "(", "path", ",", "false", ")", ";", "result", ".", "resolve", "(", ")", ";", "return", "result", ".", "promise", "(", ")", ";", "}", "file", ".", "write", "(", "\"\"", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "return", "result", ".", "reject", "(", "err", ")", ";", "}", "result", ".", "resolve", "(", ")", ";", "}", ")", ";", "return", "result", ".", "promise", "(", ")", ";", "}" ]
Disables the extension at the given path. @param {string} path The absolute path to the extension to disable. @return {$.Promise} A promise that's resolved when the extenion is disabled, or rejected if there was an error.
[ "Disables", "the", "extension", "at", "the", "given", "path", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/Package.js#L468-L486
train
adobe/brackets
src/extensibility/Package.js
enable
function enable(path) { var result = new $.Deferred(), file = FileSystem.getFileForPath(path + "/.disabled"); function afterEnable() { ExtensionLoader.loadExtension(FileUtils.getBaseName(path), { baseUrl: path }, "main") .done(result.resolve) .fail(result.reject); } var defaultExtensionPath = ExtensionLoader.getDefaultExtensionPath(); if (file.fullPath.indexOf(defaultExtensionPath) === 0) { toggleDefaultExtension(path, true); afterEnable(); return result.promise(); } file.unlink(function (err) { if (err) { return result.reject(err); } afterEnable(); }); return result.promise(); }
javascript
function enable(path) { var result = new $.Deferred(), file = FileSystem.getFileForPath(path + "/.disabled"); function afterEnable() { ExtensionLoader.loadExtension(FileUtils.getBaseName(path), { baseUrl: path }, "main") .done(result.resolve) .fail(result.reject); } var defaultExtensionPath = ExtensionLoader.getDefaultExtensionPath(); if (file.fullPath.indexOf(defaultExtensionPath) === 0) { toggleDefaultExtension(path, true); afterEnable(); return result.promise(); } file.unlink(function (err) { if (err) { return result.reject(err); } afterEnable(); }); return result.promise(); }
[ "function", "enable", "(", "path", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ",", "file", "=", "FileSystem", ".", "getFileForPath", "(", "path", "+", "\"/.disabled\"", ")", ";", "function", "afterEnable", "(", ")", "{", "ExtensionLoader", ".", "loadExtension", "(", "FileUtils", ".", "getBaseName", "(", "path", ")", ",", "{", "baseUrl", ":", "path", "}", ",", "\"main\"", ")", ".", "done", "(", "result", ".", "resolve", ")", ".", "fail", "(", "result", ".", "reject", ")", ";", "}", "var", "defaultExtensionPath", "=", "ExtensionLoader", ".", "getDefaultExtensionPath", "(", ")", ";", "if", "(", "file", ".", "fullPath", ".", "indexOf", "(", "defaultExtensionPath", ")", "===", "0", ")", "{", "toggleDefaultExtension", "(", "path", ",", "true", ")", ";", "afterEnable", "(", ")", ";", "return", "result", ".", "promise", "(", ")", ";", "}", "file", ".", "unlink", "(", "function", "(", "err", ")", "{", "if", "(", "err", ")", "{", "return", "result", ".", "reject", "(", "err", ")", ";", "}", "afterEnable", "(", ")", ";", "}", ")", ";", "return", "result", ".", "promise", "(", ")", ";", "}" ]
Enables the extension at the given path. @param {string} path The absolute path to the extension to enable. @return {$.Promise} A promise that's resolved when the extenion is enable, or rejected if there was an error.
[ "Enables", "the", "extension", "at", "the", "given", "path", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/Package.js#L495-L519
train
adobe/brackets
src/extensibility/Package.js
installUpdate
function installUpdate(path, nameHint) { var d = new $.Deferred(); install(path, nameHint, true) .done(function (result) { if (result.installationStatus !== InstallationStatuses.INSTALLED) { d.reject(result.errors); } else { d.resolve(result); } }) .fail(function (error) { d.reject(error); }); return d.promise(); }
javascript
function installUpdate(path, nameHint) { var d = new $.Deferred(); install(path, nameHint, true) .done(function (result) { if (result.installationStatus !== InstallationStatuses.INSTALLED) { d.reject(result.errors); } else { d.resolve(result); } }) .fail(function (error) { d.reject(error); }); return d.promise(); }
[ "function", "installUpdate", "(", "path", ",", "nameHint", ")", "{", "var", "d", "=", "new", "$", ".", "Deferred", "(", ")", ";", "install", "(", "path", ",", "nameHint", ",", "true", ")", ".", "done", "(", "function", "(", "result", ")", "{", "if", "(", "result", ".", "installationStatus", "!==", "InstallationStatuses", ".", "INSTALLED", ")", "{", "d", ".", "reject", "(", "result", ".", "errors", ")", ";", "}", "else", "{", "d", ".", "resolve", "(", "result", ")", ";", "}", "}", ")", ".", "fail", "(", "function", "(", "error", ")", "{", "d", ".", "reject", "(", "error", ")", ";", "}", ")", ";", "return", "d", ".", "promise", "(", ")", ";", "}" ]
Install an extension update located at path. This assumes that the installation was previously attempted and an installationStatus of "ALREADY_INSTALLED", "NEEDS_UPDATE", "SAME_VERSION", or "OLDER_VERSION" was the result. This workflow ensures that there should not generally be validation errors because the first pass at installation the extension looked at the metadata and installed packages. @param {string} path to package file @param {?string} nameHint Hint for the extension folder's name (used in favor of path's filename if present, and if no package metadata present). @return {$.Promise} A promise that is resolved when the extension is successfully installed or rejected if there is a problem.
[ "Install", "an", "extension", "update", "located", "at", "path", ".", "This", "assumes", "that", "the", "installation", "was", "previously", "attempted", "and", "an", "installationStatus", "of", "ALREADY_INSTALLED", "NEEDS_UPDATE", "SAME_VERSION", "or", "OLDER_VERSION", "was", "the", "result", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/Package.js#L537-L551
train
adobe/brackets
src/LiveDevelopment/MultiBrowserImpl/transports/node/NodeSocketTransportDomain.js
_cmdSend
function _cmdSend(idOrArray, msgStr) { if (!Array.isArray(idOrArray)) { idOrArray = [idOrArray]; } idOrArray.forEach(function (id) { var client = _clients[id]; if (!client) { console.error("nodeSocketTransport: Couldn't find client ID: " + id); } else { client.socket.send(msgStr); } }); }
javascript
function _cmdSend(idOrArray, msgStr) { if (!Array.isArray(idOrArray)) { idOrArray = [idOrArray]; } idOrArray.forEach(function (id) { var client = _clients[id]; if (!client) { console.error("nodeSocketTransport: Couldn't find client ID: " + id); } else { client.socket.send(msgStr); } }); }
[ "function", "_cmdSend", "(", "idOrArray", ",", "msgStr", ")", "{", "if", "(", "!", "Array", ".", "isArray", "(", "idOrArray", ")", ")", "{", "idOrArray", "=", "[", "idOrArray", "]", ";", "}", "idOrArray", ".", "forEach", "(", "function", "(", "id", ")", "{", "var", "client", "=", "_clients", "[", "id", "]", ";", "if", "(", "!", "client", ")", "{", "console", ".", "error", "(", "\"nodeSocketTransport: Couldn't find client ID: \"", "+", "id", ")", ";", "}", "else", "{", "client", ".", "socket", ".", "send", "(", "msgStr", ")", ";", "}", "}", ")", ";", "}" ]
Sends a transport-layer message over the socket. @param {number|Array.<number>} idOrArray A client ID or array of client IDs to send the message to. @param {string} msgStr The message to send as a JSON string.
[ "Sends", "a", "transport", "-", "layer", "message", "over", "the", "socket", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/transports/node/NodeSocketTransportDomain.js#L153-L165
train
adobe/brackets
src/LiveDevelopment/MultiBrowserImpl/transports/node/NodeSocketTransportDomain.js
_cmdClose
function _cmdClose(clientId) { var client = _clients[clientId]; if (client) { client.socket.close(); delete _clients[clientId]; } }
javascript
function _cmdClose(clientId) { var client = _clients[clientId]; if (client) { client.socket.close(); delete _clients[clientId]; } }
[ "function", "_cmdClose", "(", "clientId", ")", "{", "var", "client", "=", "_clients", "[", "clientId", "]", ";", "if", "(", "client", ")", "{", "client", ".", "socket", ".", "close", "(", ")", ";", "delete", "_clients", "[", "clientId", "]", ";", "}", "}" ]
Closes the connection for a given client ID. @param {number} clientId
[ "Closes", "the", "connection", "for", "a", "given", "client", "ID", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/transports/node/NodeSocketTransportDomain.js#L171-L177
train
adobe/brackets
src/language/JSUtils.js
nextLine
function nextLine() { if (stream) { curOffset++; // account for \n if (curOffset >= length) { return false; } } lineStart = curOffset; var lineEnd = text.indexOf("\n", lineStart); if (lineEnd === -1) { lineEnd = length; } stream = new CodeMirror.StringStream(text.slice(curOffset, lineEnd)); return true; }
javascript
function nextLine() { if (stream) { curOffset++; // account for \n if (curOffset >= length) { return false; } } lineStart = curOffset; var lineEnd = text.indexOf("\n", lineStart); if (lineEnd === -1) { lineEnd = length; } stream = new CodeMirror.StringStream(text.slice(curOffset, lineEnd)); return true; }
[ "function", "nextLine", "(", ")", "{", "if", "(", "stream", ")", "{", "curOffset", "++", ";", "if", "(", "curOffset", ">=", "length", ")", "{", "return", "false", ";", "}", "}", "lineStart", "=", "curOffset", ";", "var", "lineEnd", "=", "text", ".", "indexOf", "(", "\"\\n\"", ",", "\\n", ")", ";", "lineStart", "if", "(", "lineEnd", "===", "-", "1", ")", "{", "lineEnd", "=", "length", ";", "}", "stream", "=", "new", "CodeMirror", ".", "StringStream", "(", "text", ".", "slice", "(", "curOffset", ",", "lineEnd", ")", ")", ";", "}" ]
Get a stream for the next line, and update curOffset and lineStart to point to the beginning of that next line. Returns false if we're at the end of the text.
[ "Get", "a", "stream", "for", "the", "next", "line", "and", "update", "curOffset", "and", "lineStart", "to", "point", "to", "the", "beginning", "of", "that", "next", "line", ".", "Returns", "false", "if", "we", "re", "at", "the", "end", "of", "the", "text", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/JSUtils.js#L182-L196
train
adobe/brackets
src/language/JSUtils.js
_shouldGetFromCache
function _shouldGetFromCache(fileInfo) { var result = new $.Deferred(), isChanged = _changedDocumentTracker.isPathChanged(fileInfo.fullPath); if (isChanged && fileInfo.JSUtils) { // See if it's dirty and in the working set first var doc = DocumentManager.getOpenDocumentForPath(fileInfo.fullPath); if (doc && doc.isDirty) { result.resolve(false); } else { // If a cache exists, check the timestamp on disk var file = FileSystem.getFileForPath(fileInfo.fullPath); file.stat(function (err, stat) { if (!err) { result.resolve(fileInfo.JSUtils.timestamp.getTime() === stat.mtime.getTime()); } else { result.reject(err); } }); } } else { // Use the cache if the file did not change and the cache exists result.resolve(!isChanged && fileInfo.JSUtils); } return result.promise(); }
javascript
function _shouldGetFromCache(fileInfo) { var result = new $.Deferred(), isChanged = _changedDocumentTracker.isPathChanged(fileInfo.fullPath); if (isChanged && fileInfo.JSUtils) { // See if it's dirty and in the working set first var doc = DocumentManager.getOpenDocumentForPath(fileInfo.fullPath); if (doc && doc.isDirty) { result.resolve(false); } else { // If a cache exists, check the timestamp on disk var file = FileSystem.getFileForPath(fileInfo.fullPath); file.stat(function (err, stat) { if (!err) { result.resolve(fileInfo.JSUtils.timestamp.getTime() === stat.mtime.getTime()); } else { result.reject(err); } }); } } else { // Use the cache if the file did not change and the cache exists result.resolve(!isChanged && fileInfo.JSUtils); } return result.promise(); }
[ "function", "_shouldGetFromCache", "(", "fileInfo", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ",", "isChanged", "=", "_changedDocumentTracker", ".", "isPathChanged", "(", "fileInfo", ".", "fullPath", ")", ";", "if", "(", "isChanged", "&&", "fileInfo", ".", "JSUtils", ")", "{", "var", "doc", "=", "DocumentManager", ".", "getOpenDocumentForPath", "(", "fileInfo", ".", "fullPath", ")", ";", "if", "(", "doc", "&&", "doc", ".", "isDirty", ")", "{", "result", ".", "resolve", "(", "false", ")", ";", "}", "else", "{", "var", "file", "=", "FileSystem", ".", "getFileForPath", "(", "fileInfo", ".", "fullPath", ")", ";", "file", ".", "stat", "(", "function", "(", "err", ",", "stat", ")", "{", "if", "(", "!", "err", ")", "{", "result", ".", "resolve", "(", "fileInfo", ".", "JSUtils", ".", "timestamp", ".", "getTime", "(", ")", "===", "stat", ".", "mtime", ".", "getTime", "(", ")", ")", ";", "}", "else", "{", "result", ".", "reject", "(", "err", ")", ";", "}", "}", ")", ";", "}", "}", "else", "{", "result", ".", "resolve", "(", "!", "isChanged", "&&", "fileInfo", ".", "JSUtils", ")", ";", "}", "return", "result", ".", "promise", "(", ")", ";", "}" ]
Determines if the document function cache is up to date. @param {FileInfo} fileInfo @return {$.Promise} A promise resolved with true with true when a function cache is available for the document. Resolves with false when there is no cache or the cache is stale.
[ "Determines", "if", "the", "document", "function", "cache", "is", "up", "to", "date", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/JSUtils.js#L302-L330
train
adobe/brackets
src/language/JSUtils.js
_getFunctionsForFile
function _getFunctionsForFile(fileInfo) { var result = new $.Deferred(); _shouldGetFromCache(fileInfo) .done(function (useCache) { if (useCache) { // Return cached data. doc property is undefined since we hit the cache. // _getOffsets() will fetch the Document if necessary. result.resolve({/*doc: undefined,*/fileInfo: fileInfo, functions: fileInfo.JSUtils.functions}); } else { _readFile(fileInfo, result); } }).fail(function (err) { result.reject(err); }); return result.promise(); }
javascript
function _getFunctionsForFile(fileInfo) { var result = new $.Deferred(); _shouldGetFromCache(fileInfo) .done(function (useCache) { if (useCache) { // Return cached data. doc property is undefined since we hit the cache. // _getOffsets() will fetch the Document if necessary. result.resolve({/*doc: undefined,*/fileInfo: fileInfo, functions: fileInfo.JSUtils.functions}); } else { _readFile(fileInfo, result); } }).fail(function (err) { result.reject(err); }); return result.promise(); }
[ "function", "_getFunctionsForFile", "(", "fileInfo", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ";", "_shouldGetFromCache", "(", "fileInfo", ")", ".", "done", "(", "function", "(", "useCache", ")", "{", "if", "(", "useCache", ")", "{", "result", ".", "resolve", "(", "{", "fileInfo", ":", "fileInfo", ",", "functions", ":", "fileInfo", ".", "JSUtils", ".", "functions", "}", ")", ";", "}", "else", "{", "_readFile", "(", "fileInfo", ",", "result", ")", ";", "}", "}", ")", ".", "fail", "(", "function", "(", "err", ")", "{", "result", ".", "reject", "(", "err", ")", ";", "}", ")", ";", "return", "result", ".", "promise", "(", ")", ";", "}" ]
Resolves with a record containing the Document or FileInfo and an Array of all function names with offsets for the specified file. Results may be cached. @param {FileInfo} fileInfo @return {$.Promise} A promise resolved with a document info object that contains a map of all function names from the document and each function's start offset.
[ "Resolves", "with", "a", "record", "containing", "the", "Document", "or", "FileInfo", "and", "an", "Array", "of", "all", "function", "names", "with", "offsets", "for", "the", "specified", "file", ".", "Results", "may", "be", "cached", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/JSUtils.js#L389-L406
train
adobe/brackets
src/language/JSUtils.js
findMatchingFunctions
function findMatchingFunctions(functionName, fileInfos, keepAllFiles) { var result = new $.Deferred(), jsFiles = []; if (!keepAllFiles) { // Filter fileInfos for .js files jsFiles = fileInfos.filter(function (fileInfo) { return FileUtils.getFileExtension(fileInfo.fullPath).toLowerCase() === "js"; }); } else { jsFiles = fileInfos; } // RegExp search (or cache lookup) for all functions in the project _getFunctionsInFiles(jsFiles).done(function (docEntries) { // Compute offsets for all matched functions _getOffsetsForFunction(docEntries, functionName).done(function (rangeResults) { result.resolve(rangeResults); }); }); return result.promise(); }
javascript
function findMatchingFunctions(functionName, fileInfos, keepAllFiles) { var result = new $.Deferred(), jsFiles = []; if (!keepAllFiles) { // Filter fileInfos for .js files jsFiles = fileInfos.filter(function (fileInfo) { return FileUtils.getFileExtension(fileInfo.fullPath).toLowerCase() === "js"; }); } else { jsFiles = fileInfos; } // RegExp search (or cache lookup) for all functions in the project _getFunctionsInFiles(jsFiles).done(function (docEntries) { // Compute offsets for all matched functions _getOffsetsForFunction(docEntries, functionName).done(function (rangeResults) { result.resolve(rangeResults); }); }); return result.promise(); }
[ "function", "findMatchingFunctions", "(", "functionName", ",", "fileInfos", ",", "keepAllFiles", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ",", "jsFiles", "=", "[", "]", ";", "if", "(", "!", "keepAllFiles", ")", "{", "jsFiles", "=", "fileInfos", ".", "filter", "(", "function", "(", "fileInfo", ")", "{", "return", "FileUtils", ".", "getFileExtension", "(", "fileInfo", ".", "fullPath", ")", ".", "toLowerCase", "(", ")", "===", "\"js\"", ";", "}", ")", ";", "}", "else", "{", "jsFiles", "=", "fileInfos", ";", "}", "_getFunctionsInFiles", "(", "jsFiles", ")", ".", "done", "(", "function", "(", "docEntries", ")", "{", "_getOffsetsForFunction", "(", "docEntries", ",", "functionName", ")", ".", "done", "(", "function", "(", "rangeResults", ")", "{", "result", ".", "resolve", "(", "rangeResults", ")", ";", "}", ")", ";", "}", ")", ";", "return", "result", ".", "promise", "(", ")", ";", "}" ]
Return all functions that have the specified name, searching across all the given files. @param {!String} functionName The name to match. @param {!Array.<File>} fileInfos The array of files to search. @param {boolean=} keepAllFiles If true, don't ignore non-javascript files. @return {$.Promise} that will be resolved with an Array of objects containing the source document, start line, and end line (0-based, inclusive range) for each matching function list. Does not addRef() the documents returned in the array.
[ "Return", "all", "functions", "that", "have", "the", "specified", "name", "searching", "across", "all", "the", "given", "files", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/JSUtils.js#L455-L477
train
adobe/brackets
src/language/JSUtils.js
findAllMatchingFunctionsInText
function findAllMatchingFunctionsInText(text, searchName) { var allFunctions = _findAllFunctionsInText(text); var result = []; var lines = text.split("\n"); _.forEach(allFunctions, function (functions, functionName) { if (functionName === searchName || searchName === "*") { functions.forEach(function (funcEntry) { var endOffset = _getFunctionEndOffset(text, funcEntry.offsetStart); result.push({ name: functionName, label: funcEntry.label, lineStart: StringUtils.offsetToLineNum(lines, funcEntry.offsetStart), lineEnd: StringUtils.offsetToLineNum(lines, endOffset), nameLineStart: funcEntry.location.start.line - 1, nameLineEnd: funcEntry.location.end.line - 1, columnStart: funcEntry.location.start.column, columnEnd: funcEntry.location.end.column }); }); } }); return result; }
javascript
function findAllMatchingFunctionsInText(text, searchName) { var allFunctions = _findAllFunctionsInText(text); var result = []; var lines = text.split("\n"); _.forEach(allFunctions, function (functions, functionName) { if (functionName === searchName || searchName === "*") { functions.forEach(function (funcEntry) { var endOffset = _getFunctionEndOffset(text, funcEntry.offsetStart); result.push({ name: functionName, label: funcEntry.label, lineStart: StringUtils.offsetToLineNum(lines, funcEntry.offsetStart), lineEnd: StringUtils.offsetToLineNum(lines, endOffset), nameLineStart: funcEntry.location.start.line - 1, nameLineEnd: funcEntry.location.end.line - 1, columnStart: funcEntry.location.start.column, columnEnd: funcEntry.location.end.column }); }); } }); return result; }
[ "function", "findAllMatchingFunctionsInText", "(", "text", ",", "searchName", ")", "{", "var", "allFunctions", "=", "_findAllFunctionsInText", "(", "text", ")", ";", "var", "result", "=", "[", "]", ";", "var", "lines", "=", "text", ".", "split", "(", "\"\\n\"", ")", ";", "\\n", "_", ".", "forEach", "(", "allFunctions", ",", "function", "(", "functions", ",", "functionName", ")", "{", "if", "(", "functionName", "===", "searchName", "||", "searchName", "===", "\"*\"", ")", "{", "functions", ".", "forEach", "(", "function", "(", "funcEntry", ")", "{", "var", "endOffset", "=", "_getFunctionEndOffset", "(", "text", ",", "funcEntry", ".", "offsetStart", ")", ";", "result", ".", "push", "(", "{", "name", ":", "functionName", ",", "label", ":", "funcEntry", ".", "label", ",", "lineStart", ":", "StringUtils", ".", "offsetToLineNum", "(", "lines", ",", "funcEntry", ".", "offsetStart", ")", ",", "lineEnd", ":", "StringUtils", ".", "offsetToLineNum", "(", "lines", ",", "endOffset", ")", ",", "nameLineStart", ":", "funcEntry", ".", "location", ".", "start", ".", "line", "-", "1", ",", "nameLineEnd", ":", "funcEntry", ".", "location", ".", "end", ".", "line", "-", "1", ",", "columnStart", ":", "funcEntry", ".", "location", ".", "start", ".", "column", ",", "columnEnd", ":", "funcEntry", ".", "location", ".", "end", ".", "column", "}", ")", ";", "}", ")", ";", "}", "}", ")", ";", "}" ]
Finds all instances of the specified searchName in "text". Returns an Array of Objects with start and end properties. @param text {!String} JS text to search @param searchName {!String} function name to search for @return {Array.<{offset:number, functionName:string}>} Array of objects containing the start offset for each matched function name.
[ "Finds", "all", "instances", "of", "the", "specified", "searchName", "in", "text", ".", "Returns", "an", "Array", "of", "Objects", "with", "start", "and", "end", "properties", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/JSUtils.js#L488-L512
train
adobe/brackets
src/view/ThemeManager.js
refresh
function refresh(force) { if (force) { currentTheme = null; } $.when(force && loadCurrentTheme()).done(function () { var editor = EditorManager.getActiveEditor(); if (!editor || !editor._codeMirror) { return; } var cm = editor._codeMirror; ThemeView.updateThemes(cm); // currentTheme can be undefined, so watch out cm.setOption("addModeClass", !!(currentTheme && currentTheme.addModeClass)); }); }
javascript
function refresh(force) { if (force) { currentTheme = null; } $.when(force && loadCurrentTheme()).done(function () { var editor = EditorManager.getActiveEditor(); if (!editor || !editor._codeMirror) { return; } var cm = editor._codeMirror; ThemeView.updateThemes(cm); // currentTheme can be undefined, so watch out cm.setOption("addModeClass", !!(currentTheme && currentTheme.addModeClass)); }); }
[ "function", "refresh", "(", "force", ")", "{", "if", "(", "force", ")", "{", "currentTheme", "=", "null", ";", "}", "$", ".", "when", "(", "force", "&&", "loadCurrentTheme", "(", ")", ")", ".", "done", "(", "function", "(", ")", "{", "var", "editor", "=", "EditorManager", ".", "getActiveEditor", "(", ")", ";", "if", "(", "!", "editor", "||", "!", "editor", ".", "_codeMirror", ")", "{", "return", ";", "}", "var", "cm", "=", "editor", ".", "_codeMirror", ";", "ThemeView", ".", "updateThemes", "(", "cm", ")", ";", "cm", ".", "setOption", "(", "\"addModeClass\"", ",", "!", "!", "(", "currentTheme", "&&", "currentTheme", ".", "addModeClass", ")", ")", ";", "}", ")", ";", "}" ]
Refresh current theme in the editor @param {boolean} force Forces a reload of the current theme. It reloads the theme file.
[ "Refresh", "current", "theme", "in", "the", "editor" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ThemeManager.js#L254-L271
train
adobe/brackets
src/view/ThemeManager.js
loadFile
function loadFile(fileName, options) { var deferred = new $.Deferred(), file = FileSystem.getFileForPath(fileName), currentThemeName = prefs.get("theme"); file.exists(function (err, exists) { var theme; if (exists) { theme = new Theme(file, options); loadedThemes[theme.name] = theme; ThemeSettings._setThemes(loadedThemes); // For themes that are loaded after ThemeManager has been loaded, // we should check if it's the current theme. If it is, then we just // load it. if (currentThemeName === theme.name) { refresh(true); } deferred.resolve(theme); } else if (err || !exists) { deferred.reject(err); } }); return deferred.promise(); }
javascript
function loadFile(fileName, options) { var deferred = new $.Deferred(), file = FileSystem.getFileForPath(fileName), currentThemeName = prefs.get("theme"); file.exists(function (err, exists) { var theme; if (exists) { theme = new Theme(file, options); loadedThemes[theme.name] = theme; ThemeSettings._setThemes(loadedThemes); // For themes that are loaded after ThemeManager has been loaded, // we should check if it's the current theme. If it is, then we just // load it. if (currentThemeName === theme.name) { refresh(true); } deferred.resolve(theme); } else if (err || !exists) { deferred.reject(err); } }); return deferred.promise(); }
[ "function", "loadFile", "(", "fileName", ",", "options", ")", "{", "var", "deferred", "=", "new", "$", ".", "Deferred", "(", ")", ",", "file", "=", "FileSystem", ".", "getFileForPath", "(", "fileName", ")", ",", "currentThemeName", "=", "prefs", ".", "get", "(", "\"theme\"", ")", ";", "file", ".", "exists", "(", "function", "(", "err", ",", "exists", ")", "{", "var", "theme", ";", "if", "(", "exists", ")", "{", "theme", "=", "new", "Theme", "(", "file", ",", "options", ")", ";", "loadedThemes", "[", "theme", ".", "name", "]", "=", "theme", ";", "ThemeSettings", ".", "_setThemes", "(", "loadedThemes", ")", ";", "if", "(", "currentThemeName", "===", "theme", ".", "name", ")", "{", "refresh", "(", "true", ")", ";", "}", "deferred", ".", "resolve", "(", "theme", ")", ";", "}", "else", "if", "(", "err", "||", "!", "exists", ")", "{", "deferred", ".", "reject", "(", "err", ")", ";", "}", "}", ")", ";", "return", "deferred", ".", "promise", "(", ")", ";", "}" ]
Loads a theme from a file. @param {string} fileName is the full path to the file to be opened @param {Object} options is an optional parameter to specify metadata for the theme. @return {$.Promise} promise object resolved with the theme to be loaded from fileName
[ "Loads", "a", "theme", "from", "a", "file", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ThemeManager.js#L282-L309
train
adobe/brackets
src/view/ThemeManager.js
loadPackage
function loadPackage(themePackage) { var fileName = themePackage.path + "/" + themePackage.metadata.theme.file; return loadFile(fileName, themePackage.metadata); }
javascript
function loadPackage(themePackage) { var fileName = themePackage.path + "/" + themePackage.metadata.theme.file; return loadFile(fileName, themePackage.metadata); }
[ "function", "loadPackage", "(", "themePackage", ")", "{", "var", "fileName", "=", "themePackage", ".", "path", "+", "\"/\"", "+", "themePackage", ".", "metadata", ".", "theme", ".", "file", ";", "return", "loadFile", "(", "fileName", ",", "themePackage", ".", "metadata", ")", ";", "}" ]
Loads a theme from an extension package. @param {Object} themePackage is a package from the extension manager for the theme to be loaded. @return {$.Promise} promise object resolved with the theme to be loaded from the pacakge
[ "Loads", "a", "theme", "from", "an", "extension", "package", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ThemeManager.js#L318-L321
train
adobe/brackets
src/utils/AnimationUtils.js
animateUsingClass
function animateUsingClass(target, animClass, timeoutDuration) { var result = new $.Deferred(), $target = $(target); timeoutDuration = timeoutDuration || 400; function finish(e) { if (e.target === target) { result.resolve(); } } function cleanup() { $target .removeClass(animClass) .off(_transitionEvent, finish); } if ($target.is(":hidden")) { // Don't do anything if the element is hidden because transitionEnd wouldn't fire result.resolve(); } else { // Note that we can't just use $.one() here because we only want to remove // the handler when we get the transition end event for the correct target (not // a child). $target .addClass(animClass) .on(_transitionEvent, finish); } // Use timeout in case transition end event is not sent return Async.withTimeout(result.promise(), timeoutDuration, true) .done(cleanup); }
javascript
function animateUsingClass(target, animClass, timeoutDuration) { var result = new $.Deferred(), $target = $(target); timeoutDuration = timeoutDuration || 400; function finish(e) { if (e.target === target) { result.resolve(); } } function cleanup() { $target .removeClass(animClass) .off(_transitionEvent, finish); } if ($target.is(":hidden")) { // Don't do anything if the element is hidden because transitionEnd wouldn't fire result.resolve(); } else { // Note that we can't just use $.one() here because we only want to remove // the handler when we get the transition end event for the correct target (not // a child). $target .addClass(animClass) .on(_transitionEvent, finish); } // Use timeout in case transition end event is not sent return Async.withTimeout(result.promise(), timeoutDuration, true) .done(cleanup); }
[ "function", "animateUsingClass", "(", "target", ",", "animClass", ",", "timeoutDuration", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ",", "$target", "=", "$", "(", "target", ")", ";", "timeoutDuration", "=", "timeoutDuration", "||", "400", ";", "function", "finish", "(", "e", ")", "{", "if", "(", "e", ".", "target", "===", "target", ")", "{", "result", ".", "resolve", "(", ")", ";", "}", "}", "function", "cleanup", "(", ")", "{", "$target", ".", "removeClass", "(", "animClass", ")", ".", "off", "(", "_transitionEvent", ",", "finish", ")", ";", "}", "if", "(", "$target", ".", "is", "(", "\":hidden\"", ")", ")", "{", "result", ".", "resolve", "(", ")", ";", "}", "else", "{", "$target", ".", "addClass", "(", "animClass", ")", ".", "on", "(", "_transitionEvent", ",", "finish", ")", ";", "}", "return", "Async", ".", "withTimeout", "(", "result", ".", "promise", "(", ")", ",", "timeoutDuration", ",", "true", ")", ".", "done", "(", "cleanup", ")", ";", "}" ]
Start an animation by adding the given class to the given target. When the animation is complete, removes the class, clears the event handler we attach to watch for the animation to finish, and resolves the returned promise. @param {Element} target The DOM node to animate. @param {string} animClass The class that applies the animation/transition to the target. @param {number=} timeoutDuration Time to wait in ms before rejecting promise. Default is 400. @return {$.Promise} A promise that is resolved when the animation completes. Never rejected.
[ "Start", "an", "animation", "by", "adding", "the", "given", "class", "to", "the", "given", "target", ".", "When", "the", "animation", "is", "complete", "removes", "the", "class", "clears", "the", "event", "handler", "we", "attach", "to", "watch", "for", "the", "animation", "to", "finish", "and", "resolves", "the", "returned", "promise", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/AnimationUtils.js#L68-L101
train
adobe/brackets
src/project/FileTreeView.js
function () { var result = this.props.parentPath + this.props.name; // Add trailing slash for directories if (!FileTreeViewModel.isFile(this.props.entry) && _.last(result) !== "/") { result += "/"; } return result; }
javascript
function () { var result = this.props.parentPath + this.props.name; // Add trailing slash for directories if (!FileTreeViewModel.isFile(this.props.entry) && _.last(result) !== "/") { result += "/"; } return result; }
[ "function", "(", ")", "{", "var", "result", "=", "this", ".", "props", ".", "parentPath", "+", "this", ".", "props", ".", "name", ";", "if", "(", "!", "FileTreeViewModel", ".", "isFile", "(", "this", ".", "props", ".", "entry", ")", "&&", "_", ".", "last", "(", "result", ")", "!==", "\"/\"", ")", "{", "result", "+=", "\"/\"", ";", "}", "return", "result", ";", "}" ]
Computes the full path of the file represented by this input.
[ "Computes", "the", "full", "path", "of", "the", "file", "represented", "by", "this", "input", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L93-L102
train
adobe/brackets
src/project/FileTreeView.js
function (e) { if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) { this.props.actions.cancelRename(); } else if (e.keyCode === KeyEvent.DOM_VK_RETURN) { this.props.actions.performRename(); } }
javascript
function (e) { if (e.keyCode === KeyEvent.DOM_VK_ESCAPE) { this.props.actions.cancelRename(); } else if (e.keyCode === KeyEvent.DOM_VK_RETURN) { this.props.actions.performRename(); } }
[ "function", "(", "e", ")", "{", "if", "(", "e", ".", "keyCode", "===", "KeyEvent", ".", "DOM_VK_ESCAPE", ")", "{", "this", ".", "props", ".", "actions", ".", "cancelRename", "(", ")", ";", "}", "else", "if", "(", "e", ".", "keyCode", "===", "KeyEvent", ".", "DOM_VK_RETURN", ")", "{", "this", ".", "props", ".", "actions", ".", "performRename", "(", ")", ";", "}", "}" ]
If the user presses enter or escape, we either successfully complete or cancel, respectively, the rename or create operation that is underway.
[ "If", "the", "user", "presses", "enter", "or", "escape", "we", "either", "successfully", "complete", "or", "cancel", "respectively", "the", "rename", "or", "create", "operation", "that", "is", "underway", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L175-L181
train
adobe/brackets
src/project/FileTreeView.js
function (e) { this.props.actions.setRenameValue(this.props.parentPath + this.refs.name.value.trim()); if (e.keyCode !== KeyEvent.DOM_VK_LEFT && e.keyCode !== KeyEvent.DOM_VK_RIGHT) { // update the width of the input field var node = this.refs.name, newWidth = _measureText(node.value); $(node).width(newWidth); } }
javascript
function (e) { this.props.actions.setRenameValue(this.props.parentPath + this.refs.name.value.trim()); if (e.keyCode !== KeyEvent.DOM_VK_LEFT && e.keyCode !== KeyEvent.DOM_VK_RIGHT) { // update the width of the input field var node = this.refs.name, newWidth = _measureText(node.value); $(node).width(newWidth); } }
[ "function", "(", "e", ")", "{", "this", ".", "props", ".", "actions", ".", "setRenameValue", "(", "this", ".", "props", ".", "parentPath", "+", "this", ".", "refs", ".", "name", ".", "value", ".", "trim", "(", ")", ")", ";", "if", "(", "e", ".", "keyCode", "!==", "KeyEvent", ".", "DOM_VK_LEFT", "&&", "e", ".", "keyCode", "!==", "KeyEvent", ".", "DOM_VK_RIGHT", ")", "{", "var", "node", "=", "this", ".", "refs", ".", "name", ",", "newWidth", "=", "_measureText", "(", "node", ".", "value", ")", ";", "$", "(", "node", ")", ".", "width", "(", "newWidth", ")", ";", "}", "}" ]
The rename or create operation can be completed or canceled by actions outside of this component, so we keep the model up to date by sending every update via an action.
[ "The", "rename", "or", "create", "operation", "can", "be", "completed", "or", "canceled", "by", "actions", "outside", "of", "this", "component", "so", "we", "keep", "the", "model", "up", "to", "date", "by", "sending", "every", "update", "via", "an", "action", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L187-L197
train
adobe/brackets
src/project/FileTreeView.js
function () { var fullname = this.props.name, extension = LanguageManager.getCompoundFileExtension(fullname); var node = this.refs.name; node.setSelectionRange(0, _getName(fullname, extension).length); node.focus(); // set focus on the rename input ViewUtils.scrollElementIntoView($("#project-files-container"), $(node), true); }
javascript
function () { var fullname = this.props.name, extension = LanguageManager.getCompoundFileExtension(fullname); var node = this.refs.name; node.setSelectionRange(0, _getName(fullname, extension).length); node.focus(); // set focus on the rename input ViewUtils.scrollElementIntoView($("#project-files-container"), $(node), true); }
[ "function", "(", ")", "{", "var", "fullname", "=", "this", ".", "props", ".", "name", ",", "extension", "=", "LanguageManager", ".", "getCompoundFileExtension", "(", "fullname", ")", ";", "var", "node", "=", "this", ".", "refs", ".", "name", ";", "node", ".", "setSelectionRange", "(", "0", ",", "_getName", "(", "fullname", ",", "extension", ")", ".", "length", ")", ";", "node", ".", "focus", "(", ")", ";", "ViewUtils", ".", "scrollElementIntoView", "(", "$", "(", "\"#project-files-container\"", ")", ",", "$", "(", "node", ")", ",", "true", ")", ";", "}" ]
When this component is displayed, we scroll it into view and select the portion of the filename that excludes the extension.
[ "When", "this", "component", "is", "displayed", "we", "scroll", "it", "into", "view", "and", "select", "the", "portion", "of", "the", "filename", "that", "excludes", "the", "extension", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L327-L335
train
adobe/brackets
src/project/FileTreeView.js
function (e) { e.stopPropagation(); if (e.button === RIGHT_MOUSE_BUTTON || (this.props.platform === "mac" && e.button === LEFT_MOUSE_BUTTON && e.ctrlKey)) { this.props.actions.setContext(this.myPath()); e.preventDefault(); return; } // Return true only for mouse down in rename mode. if (this.props.entry.get("rename")) { return; } }
javascript
function (e) { e.stopPropagation(); if (e.button === RIGHT_MOUSE_BUTTON || (this.props.platform === "mac" && e.button === LEFT_MOUSE_BUTTON && e.ctrlKey)) { this.props.actions.setContext(this.myPath()); e.preventDefault(); return; } // Return true only for mouse down in rename mode. if (this.props.entry.get("rename")) { return; } }
[ "function", "(", "e", ")", "{", "e", ".", "stopPropagation", "(", ")", ";", "if", "(", "e", ".", "button", "===", "RIGHT_MOUSE_BUTTON", "||", "(", "this", ".", "props", ".", "platform", "===", "\"mac\"", "&&", "e", ".", "button", "===", "LEFT_MOUSE_BUTTON", "&&", "e", ".", "ctrlKey", ")", ")", "{", "this", ".", "props", ".", "actions", ".", "setContext", "(", "this", ".", "myPath", "(", ")", ")", ";", "e", ".", "preventDefault", "(", ")", ";", "return", ";", "}", "if", "(", "this", ".", "props", ".", "entry", ".", "get", "(", "\"rename\"", ")", ")", "{", "return", ";", "}", "}" ]
Send matching mouseDown events to the action creator as a setContext action.
[ "Send", "matching", "mouseDown", "events", "to", "the", "action", "creator", "as", "a", "setContext", "action", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L368-L380
train
adobe/brackets
src/project/FileTreeView.js
function (nextProps, nextState) { return nextProps.forceRender || this.props.entry !== nextProps.entry || this.props.extensions !== nextProps.extensions; }
javascript
function (nextProps, nextState) { return nextProps.forceRender || this.props.entry !== nextProps.entry || this.props.extensions !== nextProps.extensions; }
[ "function", "(", "nextProps", ",", "nextState", ")", "{", "return", "nextProps", ".", "forceRender", "||", "this", ".", "props", ".", "entry", "!==", "nextProps", ".", "entry", "||", "this", ".", "props", ".", "extensions", "!==", "nextProps", ".", "extensions", ";", "}" ]
Thanks to immutable objects, we can just do a start object identity check to know whether or not we need to re-render.
[ "Thanks", "to", "immutable", "objects", "we", "can", "just", "do", "a", "start", "object", "identity", "check", "to", "know", "whether", "or", "not", "we", "need", "to", "re", "-", "render", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L492-L496
train
adobe/brackets
src/project/FileTreeView.js
function (prevProps, prevState) { var wasSelected = prevProps.entry.get("selected"), isSelected = this.props.entry.get("selected"); if (isSelected && !wasSelected) { // TODO: This shouldn't really know about project-files-container // directly. It is probably the case that our Preact tree should actually // start with project-files-container instead of just the interior of // project-files-container and then the file tree will be one self-contained // functional unit. ViewUtils.scrollElementIntoView($("#project-files-container"), $(Preact.findDOMNode(this)), true); } else if (!isSelected && wasSelected && this.state.clickTimer !== null) { this.clearTimer(); } }
javascript
function (prevProps, prevState) { var wasSelected = prevProps.entry.get("selected"), isSelected = this.props.entry.get("selected"); if (isSelected && !wasSelected) { // TODO: This shouldn't really know about project-files-container // directly. It is probably the case that our Preact tree should actually // start with project-files-container instead of just the interior of // project-files-container and then the file tree will be one self-contained // functional unit. ViewUtils.scrollElementIntoView($("#project-files-container"), $(Preact.findDOMNode(this)), true); } else if (!isSelected && wasSelected && this.state.clickTimer !== null) { this.clearTimer(); } }
[ "function", "(", "prevProps", ",", "prevState", ")", "{", "var", "wasSelected", "=", "prevProps", ".", "entry", ".", "get", "(", "\"selected\"", ")", ",", "isSelected", "=", "this", ".", "props", ".", "entry", ".", "get", "(", "\"selected\"", ")", ";", "if", "(", "isSelected", "&&", "!", "wasSelected", ")", "{", "ViewUtils", ".", "scrollElementIntoView", "(", "$", "(", "\"#project-files-container\"", ")", ",", "$", "(", "Preact", ".", "findDOMNode", "(", "this", ")", ")", ",", "true", ")", ";", "}", "else", "if", "(", "!", "isSelected", "&&", "wasSelected", "&&", "this", ".", "state", ".", "clickTimer", "!==", "null", ")", "{", "this", ".", "clearTimer", "(", ")", ";", "}", "}" ]
If this node is newly selected, scroll it into view. Also, move the selection or context boxes as appropriate.
[ "If", "this", "node", "is", "newly", "selected", "scroll", "it", "into", "view", ".", "Also", "move", "the", "selection", "or", "context", "boxes", "as", "appropriate", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L502-L516
train
adobe/brackets
src/project/FileTreeView.js
function (e) { // If we're renaming, allow the click to go through to the rename input. if (this.props.entry.get("rename")) { e.stopPropagation(); return; } if (e.button !== LEFT_MOUSE_BUTTON) { return; } if (this.props.entry.get("selected") && !e.ctrlKey) { if (this.state.clickTimer === null && !this.props.entry.get("rename")) { var timer = window.setTimeout(this.startRename, CLICK_RENAME_MINIMUM); this.setState({ clickTimer: timer }); } } else { this.props.actions.setSelected(this.myPath()); } e.stopPropagation(); e.preventDefault(); }
javascript
function (e) { // If we're renaming, allow the click to go through to the rename input. if (this.props.entry.get("rename")) { e.stopPropagation(); return; } if (e.button !== LEFT_MOUSE_BUTTON) { return; } if (this.props.entry.get("selected") && !e.ctrlKey) { if (this.state.clickTimer === null && !this.props.entry.get("rename")) { var timer = window.setTimeout(this.startRename, CLICK_RENAME_MINIMUM); this.setState({ clickTimer: timer }); } } else { this.props.actions.setSelected(this.myPath()); } e.stopPropagation(); e.preventDefault(); }
[ "function", "(", "e", ")", "{", "if", "(", "this", ".", "props", ".", "entry", ".", "get", "(", "\"rename\"", ")", ")", "{", "e", ".", "stopPropagation", "(", ")", ";", "return", ";", "}", "if", "(", "e", ".", "button", "!==", "LEFT_MOUSE_BUTTON", ")", "{", "return", ";", "}", "if", "(", "this", ".", "props", ".", "entry", ".", "get", "(", "\"selected\"", ")", "&&", "!", "e", ".", "ctrlKey", ")", "{", "if", "(", "this", ".", "state", ".", "clickTimer", "===", "null", "&&", "!", "this", ".", "props", ".", "entry", ".", "get", "(", "\"rename\"", ")", ")", "{", "var", "timer", "=", "window", ".", "setTimeout", "(", "this", ".", "startRename", ",", "CLICK_RENAME_MINIMUM", ")", ";", "this", ".", "setState", "(", "{", "clickTimer", ":", "timer", "}", ")", ";", "}", "}", "else", "{", "this", ".", "props", ".", "actions", ".", "setSelected", "(", "this", ".", "myPath", "(", ")", ")", ";", "}", "e", ".", "stopPropagation", "(", ")", ";", "e", ".", "preventDefault", "(", ")", ";", "}" ]
When the user clicks on the node, we'll either select it or, if they've clicked twice with a bit of delay in between, we'll invoke the `startRename` action.
[ "When", "the", "user", "clicks", "on", "the", "node", "we", "ll", "either", "select", "it", "or", "if", "they", "ve", "clicked", "twice", "with", "a", "bit", "of", "delay", "in", "between", "we", "ll", "invoke", "the", "startRename", "action", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L538-L561
train
adobe/brackets
src/project/FileTreeView.js
function () { var fullname = this.props.name; var node = this.refs.name; node.setSelectionRange(0, fullname.length); node.focus(); // set focus on the rename input ViewUtils.scrollElementIntoView($("#project-files-container"), $(node), true); }
javascript
function () { var fullname = this.props.name; var node = this.refs.name; node.setSelectionRange(0, fullname.length); node.focus(); // set focus on the rename input ViewUtils.scrollElementIntoView($("#project-files-container"), $(node), true); }
[ "function", "(", ")", "{", "var", "fullname", "=", "this", ".", "props", ".", "name", ";", "var", "node", "=", "this", ".", "refs", ".", "name", ";", "node", ".", "setSelectionRange", "(", "0", ",", "fullname", ".", "length", ")", ";", "node", ".", "focus", "(", ")", ";", "ViewUtils", ".", "scrollElementIntoView", "(", "$", "(", "\"#project-files-container\"", ")", ",", "$", "(", "node", ")", ",", "true", ")", ";", "}" ]
When this component is displayed, we scroll it into view and select the folder name.
[ "When", "this", "component", "is", "displayed", "we", "scroll", "it", "into", "view", "and", "select", "the", "folder", "name", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L717-L724
train
adobe/brackets
src/project/FileTreeView.js
function (nextProps, nextState) { return nextProps.forceRender || this.props.entry !== nextProps.entry || this.props.sortDirectoriesFirst !== nextProps.sortDirectoriesFirst || this.props.extensions !== nextProps.extensions || (nextState !== undefined && this.state.draggedOver !== nextState.draggedOver); }
javascript
function (nextProps, nextState) { return nextProps.forceRender || this.props.entry !== nextProps.entry || this.props.sortDirectoriesFirst !== nextProps.sortDirectoriesFirst || this.props.extensions !== nextProps.extensions || (nextState !== undefined && this.state.draggedOver !== nextState.draggedOver); }
[ "function", "(", "nextProps", ",", "nextState", ")", "{", "return", "nextProps", ".", "forceRender", "||", "this", ".", "props", ".", "entry", "!==", "nextProps", ".", "entry", "||", "this", ".", "props", ".", "sortDirectoriesFirst", "!==", "nextProps", ".", "sortDirectoriesFirst", "||", "this", ".", "props", ".", "extensions", "!==", "nextProps", ".", "extensions", "||", "(", "nextState", "!==", "undefined", "&&", "this", ".", "state", ".", "draggedOver", "!==", "nextState", ".", "draggedOver", ")", ";", "}" ]
We need to update this component if the sort order changes or our entry object changes. Thanks to immutability, if any of the directory contents change, our entry object will change.
[ "We", "need", "to", "update", "this", "component", "if", "the", "sort", "order", "changes", "or", "our", "entry", "object", "changes", ".", "Thanks", "to", "immutability", "if", "any", "of", "the", "directory", "contents", "change", "our", "entry", "object", "will", "change", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L774-L780
train
adobe/brackets
src/project/FileTreeView.js
function (event) { if (this.props.entry.get("rename")) { event.stopPropagation(); return; } if (event.button !== LEFT_MOUSE_BUTTON) { return; } var isOpen = this.props.entry.get("open"), setOpen = isOpen ? false : true; if (event.metaKey || event.ctrlKey) { // ctrl-alt-click toggles this directory and its children if (event.altKey) { if (setOpen) { // when opening, we only open the immediate children because // opening a whole subtree could be really slow (consider // a `node_modules` directory, for example). this.props.actions.toggleSubdirectories(this.myPath(), setOpen); this.props.actions.setDirectoryOpen(this.myPath(), setOpen); } else { // When closing, we recursively close the whole subtree. this.props.actions.closeSubtree(this.myPath()); } } else { // ctrl-click toggles the sibling directories this.props.actions.toggleSubdirectories(this.props.parentPath, setOpen); } } else { // directory toggle with no modifier this.props.actions.setDirectoryOpen(this.myPath(), setOpen); } event.stopPropagation(); event.preventDefault(); }
javascript
function (event) { if (this.props.entry.get("rename")) { event.stopPropagation(); return; } if (event.button !== LEFT_MOUSE_BUTTON) { return; } var isOpen = this.props.entry.get("open"), setOpen = isOpen ? false : true; if (event.metaKey || event.ctrlKey) { // ctrl-alt-click toggles this directory and its children if (event.altKey) { if (setOpen) { // when opening, we only open the immediate children because // opening a whole subtree could be really slow (consider // a `node_modules` directory, for example). this.props.actions.toggleSubdirectories(this.myPath(), setOpen); this.props.actions.setDirectoryOpen(this.myPath(), setOpen); } else { // When closing, we recursively close the whole subtree. this.props.actions.closeSubtree(this.myPath()); } } else { // ctrl-click toggles the sibling directories this.props.actions.toggleSubdirectories(this.props.parentPath, setOpen); } } else { // directory toggle with no modifier this.props.actions.setDirectoryOpen(this.myPath(), setOpen); } event.stopPropagation(); event.preventDefault(); }
[ "function", "(", "event", ")", "{", "if", "(", "this", ".", "props", ".", "entry", ".", "get", "(", "\"rename\"", ")", ")", "{", "event", ".", "stopPropagation", "(", ")", ";", "return", ";", "}", "if", "(", "event", ".", "button", "!==", "LEFT_MOUSE_BUTTON", ")", "{", "return", ";", "}", "var", "isOpen", "=", "this", ".", "props", ".", "entry", ".", "get", "(", "\"open\"", ")", ",", "setOpen", "=", "isOpen", "?", "false", ":", "true", ";", "if", "(", "event", ".", "metaKey", "||", "event", ".", "ctrlKey", ")", "{", "if", "(", "event", ".", "altKey", ")", "{", "if", "(", "setOpen", ")", "{", "this", ".", "props", ".", "actions", ".", "toggleSubdirectories", "(", "this", ".", "myPath", "(", ")", ",", "setOpen", ")", ";", "this", ".", "props", ".", "actions", ".", "setDirectoryOpen", "(", "this", ".", "myPath", "(", ")", ",", "setOpen", ")", ";", "}", "else", "{", "this", ".", "props", ".", "actions", ".", "closeSubtree", "(", "this", ".", "myPath", "(", ")", ")", ";", "}", "}", "else", "{", "this", ".", "props", ".", "actions", ".", "toggleSubdirectories", "(", "this", ".", "props", ".", "parentPath", ",", "setOpen", ")", ";", "}", "}", "else", "{", "this", ".", "props", ".", "actions", ".", "setDirectoryOpen", "(", "this", ".", "myPath", "(", ")", ",", "setOpen", ")", ";", "}", "event", ".", "stopPropagation", "(", ")", ";", "event", ".", "preventDefault", "(", ")", ";", "}" ]
If you click on a directory, it will toggle between open and closed.
[ "If", "you", "click", "on", "a", "directory", "it", "will", "toggle", "between", "open", "and", "closed", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L785-L821
train
adobe/brackets
src/project/FileTreeView.js
function (nextProps, nextState) { return nextProps.forceRender || this.props.contents !== nextProps.contents || this.props.sortDirectoriesFirst !== nextProps.sortDirectoriesFirst || this.props.extensions !== nextProps.extensions; }
javascript
function (nextProps, nextState) { return nextProps.forceRender || this.props.contents !== nextProps.contents || this.props.sortDirectoriesFirst !== nextProps.sortDirectoriesFirst || this.props.extensions !== nextProps.extensions; }
[ "function", "(", "nextProps", ",", "nextState", ")", "{", "return", "nextProps", ".", "forceRender", "||", "this", ".", "props", ".", "contents", "!==", "nextProps", ".", "contents", "||", "this", ".", "props", ".", "sortDirectoriesFirst", "!==", "nextProps", ".", "sortDirectoriesFirst", "||", "this", ".", "props", ".", "extensions", "!==", "nextProps", ".", "extensions", ";", "}" ]
Need to re-render if the sort order or the contents change.
[ "Need", "to", "re", "-", "render", "if", "the", "sort", "order", "or", "the", "contents", "change", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L937-L942
train
adobe/brackets
src/project/FileTreeView.js
function (nextProps, nextState) { return nextProps.forceRender || this.props.treeData !== nextProps.treeData || this.props.sortDirectoriesFirst !== nextProps.sortDirectoriesFirst || this.props.extensions !== nextProps.extensions || this.props.selectionViewInfo !== nextProps.selectionViewInfo; }
javascript
function (nextProps, nextState) { return nextProps.forceRender || this.props.treeData !== nextProps.treeData || this.props.sortDirectoriesFirst !== nextProps.sortDirectoriesFirst || this.props.extensions !== nextProps.extensions || this.props.selectionViewInfo !== nextProps.selectionViewInfo; }
[ "function", "(", "nextProps", ",", "nextState", ")", "{", "return", "nextProps", ".", "forceRender", "||", "this", ".", "props", ".", "treeData", "!==", "nextProps", ".", "treeData", "||", "this", ".", "props", ".", "sortDirectoriesFirst", "!==", "nextProps", ".", "sortDirectoriesFirst", "||", "this", ".", "props", ".", "extensions", "!==", "nextProps", ".", "extensions", "||", "this", ".", "props", ".", "selectionViewInfo", "!==", "nextProps", ".", "selectionViewInfo", ";", "}" ]
Update for any change in the tree data or directory sorting preference.
[ "Update", "for", "any", "change", "in", "the", "tree", "data", "or", "directory", "sorting", "preference", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L1127-L1133
train
adobe/brackets
src/project/FileTreeView.js
render
function render(element, viewModel, projectRoot, actions, forceRender, platform) { if (!projectRoot) { return; } Preact.render(fileTreeView({ treeData: viewModel.treeData, selectionViewInfo: viewModel.selectionViewInfo, sortDirectoriesFirst: viewModel.sortDirectoriesFirst, parentPath: projectRoot.fullPath, actions: actions, extensions: _extensions, platform: platform, forceRender: forceRender }), element); }
javascript
function render(element, viewModel, projectRoot, actions, forceRender, platform) { if (!projectRoot) { return; } Preact.render(fileTreeView({ treeData: viewModel.treeData, selectionViewInfo: viewModel.selectionViewInfo, sortDirectoriesFirst: viewModel.sortDirectoriesFirst, parentPath: projectRoot.fullPath, actions: actions, extensions: _extensions, platform: platform, forceRender: forceRender }), element); }
[ "function", "render", "(", "element", ",", "viewModel", ",", "projectRoot", ",", "actions", ",", "forceRender", ",", "platform", ")", "{", "if", "(", "!", "projectRoot", ")", "{", "return", ";", "}", "Preact", ".", "render", "(", "fileTreeView", "(", "{", "treeData", ":", "viewModel", ".", "treeData", ",", "selectionViewInfo", ":", "viewModel", ".", "selectionViewInfo", ",", "sortDirectoriesFirst", ":", "viewModel", ".", "sortDirectoriesFirst", ",", "parentPath", ":", "projectRoot", ".", "fullPath", ",", "actions", ":", "actions", ",", "extensions", ":", "_extensions", ",", "platform", ":", "platform", ",", "forceRender", ":", "forceRender", "}", ")", ",", "element", ")", ";", "}" ]
Renders the file tree to the given element. @param {DOMNode|jQuery} element Element in which to render this file tree @param {FileTreeViewModel} viewModel the data container @param {Directory} projectRoot Directory object from which the fullPath of the project root is extracted @param {ActionCreator} actions object with methods used to communicate events that originate from the user @param {boolean} forceRender Run render on the entire tree (useful if an extension has new data that it needs rendered) @param {string} platform mac, win, linux
[ "Renders", "the", "file", "tree", "to", "the", "given", "element", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileTreeView.js#L1217-L1233
train
adobe/brackets
src/languageTools/ClientLoader.js
sendLanguageClientInfo
function sendLanguageClientInfo() { //Init node with Information required by Language Client clientInfoLoadedPromise = clientInfoDomain.exec("initialize", _bracketsPath, ToolingInfo); function logInitializationError() { console.error("Failed to Initialize LanguageClient Module Information."); } //Attach success and failure function for the clientInfoLoadedPromise clientInfoLoadedPromise.then(function (success) { if (!success) { logInitializationError(); return; } if (Array.isArray(pendingClientsToBeLoaded)) { pendingClientsToBeLoaded.forEach(function (pendingClient) { pendingClient.load(); }); } else { exports.trigger("languageClientModuleInitialized"); } pendingClientsToBeLoaded = null; }, function () { logInitializationError(); }); }
javascript
function sendLanguageClientInfo() { //Init node with Information required by Language Client clientInfoLoadedPromise = clientInfoDomain.exec("initialize", _bracketsPath, ToolingInfo); function logInitializationError() { console.error("Failed to Initialize LanguageClient Module Information."); } //Attach success and failure function for the clientInfoLoadedPromise clientInfoLoadedPromise.then(function (success) { if (!success) { logInitializationError(); return; } if (Array.isArray(pendingClientsToBeLoaded)) { pendingClientsToBeLoaded.forEach(function (pendingClient) { pendingClient.load(); }); } else { exports.trigger("languageClientModuleInitialized"); } pendingClientsToBeLoaded = null; }, function () { logInitializationError(); }); }
[ "function", "sendLanguageClientInfo", "(", ")", "{", "clientInfoLoadedPromise", "=", "clientInfoDomain", ".", "exec", "(", "\"initialize\"", ",", "_bracketsPath", ",", "ToolingInfo", ")", ";", "function", "logInitializationError", "(", ")", "{", "console", ".", "error", "(", "\"Failed to Initialize LanguageClient Module Information.\"", ")", ";", "}", "clientInfoLoadedPromise", ".", "then", "(", "function", "(", "success", ")", "{", "if", "(", "!", "success", ")", "{", "logInitializationError", "(", ")", ";", "return", ";", "}", "if", "(", "Array", ".", "isArray", "(", "pendingClientsToBeLoaded", ")", ")", "{", "pendingClientsToBeLoaded", ".", "forEach", "(", "function", "(", "pendingClient", ")", "{", "pendingClient", ".", "load", "(", ")", ";", "}", ")", ";", "}", "else", "{", "exports", ".", "trigger", "(", "\"languageClientModuleInitialized\"", ")", ";", "}", "pendingClientsToBeLoaded", "=", "null", ";", "}", ",", "function", "(", ")", "{", "logInitializationError", "(", ")", ";", "}", ")", ";", "}" ]
This function passes Brackets's native directory path as well as the tooling commands required by the LanguageClient node module. This information is then maintained in memory in the node process server for succesfully loading and functioning of all language clients since it is a direct dependency.
[ "This", "function", "passes", "Brackets", "s", "native", "directory", "path", "as", "well", "as", "the", "tooling", "commands", "required", "by", "the", "LanguageClient", "node", "module", ".", "This", "information", "is", "then", "maintained", "in", "memory", "in", "the", "node", "process", "server", "for", "succesfully", "loading", "and", "functioning", "of", "all", "language", "clients", "since", "it", "is", "a", "direct", "dependency", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/languageTools/ClientLoader.js#L124-L150
train
adobe/brackets
src/languageTools/ClientLoader.js
initDomainAndHandleNodeCrash
function initDomainAndHandleNodeCrash() { clientInfoDomain = new NodeDomain("LanguageClientInfo", _domainPath); //Initialize LanguageClientInfo once the domain has successfully loaded. clientInfoDomain.promise().done(function () { sendLanguageClientInfo(); //This is to handle the node failure. If the node process dies, we get an on close //event on the websocket connection object. Brackets then spawns another process and //restablishes the connection. Once the connection is restablished we send reinitialize //the LanguageClient info. clientInfoDomain.connection.on("close", function (event, reconnectedPromise) { reconnectedPromise.done(sendLanguageClientInfo); }); }).fail(function (err) { console.error("ClientInfo domain could not be loaded: ", err); }); }
javascript
function initDomainAndHandleNodeCrash() { clientInfoDomain = new NodeDomain("LanguageClientInfo", _domainPath); //Initialize LanguageClientInfo once the domain has successfully loaded. clientInfoDomain.promise().done(function () { sendLanguageClientInfo(); //This is to handle the node failure. If the node process dies, we get an on close //event on the websocket connection object. Brackets then spawns another process and //restablishes the connection. Once the connection is restablished we send reinitialize //the LanguageClient info. clientInfoDomain.connection.on("close", function (event, reconnectedPromise) { reconnectedPromise.done(sendLanguageClientInfo); }); }).fail(function (err) { console.error("ClientInfo domain could not be loaded: ", err); }); }
[ "function", "initDomainAndHandleNodeCrash", "(", ")", "{", "clientInfoDomain", "=", "new", "NodeDomain", "(", "\"LanguageClientInfo\"", ",", "_domainPath", ")", ";", "clientInfoDomain", ".", "promise", "(", ")", ".", "done", "(", "function", "(", ")", "{", "sendLanguageClientInfo", "(", ")", ";", "clientInfoDomain", ".", "connection", ".", "on", "(", "\"close\"", ",", "function", "(", "event", ",", "reconnectedPromise", ")", "{", "reconnectedPromise", ".", "done", "(", "sendLanguageClientInfo", ")", ";", "}", ")", ";", "}", ")", ".", "fail", "(", "function", "(", "err", ")", "{", "console", ".", "error", "(", "\"ClientInfo domain could not be loaded: \"", ",", "err", ")", ";", "}", ")", ";", "}" ]
This function starts a domain which initializes the LanguageClient node module required by the Language Server Protocol framework in Brackets. All the LSP clients can only be successfully initiated once this domain has been successfully loaded and the LanguageClient info initialized. Refer to sendLanguageClientInfo for more.
[ "This", "function", "starts", "a", "domain", "which", "initializes", "the", "LanguageClient", "node", "module", "required", "by", "the", "Language", "Server", "Protocol", "framework", "in", "Brackets", ".", "All", "the", "LSP", "clients", "can", "only", "be", "successfully", "initiated", "once", "this", "domain", "has", "been", "successfully", "loaded", "and", "the", "LanguageClient", "info", "initialized", ".", "Refer", "to", "sendLanguageClientInfo", "for", "more", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/languageTools/ClientLoader.js#L158-L173
train
adobe/brackets
src/extensions/default/RemoteFileAdapter/RemoteFile.js
_getStats
function _getStats(uri) { return new FileSystemStats({ isFile: true, mtime: SESSION_START_TIME.toISOString(), size: 0, realPath: uri, hash: uri }); }
javascript
function _getStats(uri) { return new FileSystemStats({ isFile: true, mtime: SESSION_START_TIME.toISOString(), size: 0, realPath: uri, hash: uri }); }
[ "function", "_getStats", "(", "uri", ")", "{", "return", "new", "FileSystemStats", "(", "{", "isFile", ":", "true", ",", "mtime", ":", "SESSION_START_TIME", ".", "toISOString", "(", ")", ",", "size", ":", "0", ",", "realPath", ":", "uri", ",", "hash", ":", "uri", "}", ")", ";", "}" ]
Create a new file stat. See the FileSystemStats class for more details. @param {!string} fullPath The full path for this File. @return {FileSystemStats} stats.
[ "Create", "a", "new", "file", "stat", ".", "See", "the", "FileSystemStats", "class", "for", "more", "details", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RemoteFileAdapter/RemoteFile.js#L38-L46
train
adobe/brackets
src/extensions/default/RemoteFileAdapter/RemoteFile.js
RemoteFile
function RemoteFile(protocol, fullPath, fileSystem) { this._isFile = true; this._isDirectory = false; this.readOnly = true; this._path = fullPath; this._stat = _getStats(fullPath); this._id = fullPath; this._name = _getFileName(fullPath); this._fileSystem = fileSystem; this.donotWatch = true; this.protocol = protocol; this.encodedPath = fullPath; }
javascript
function RemoteFile(protocol, fullPath, fileSystem) { this._isFile = true; this._isDirectory = false; this.readOnly = true; this._path = fullPath; this._stat = _getStats(fullPath); this._id = fullPath; this._name = _getFileName(fullPath); this._fileSystem = fileSystem; this.donotWatch = true; this.protocol = protocol; this.encodedPath = fullPath; }
[ "function", "RemoteFile", "(", "protocol", ",", "fullPath", ",", "fileSystem", ")", "{", "this", ".", "_isFile", "=", "true", ";", "this", ".", "_isDirectory", "=", "false", ";", "this", ".", "readOnly", "=", "true", ";", "this", ".", "_path", "=", "fullPath", ";", "this", ".", "_stat", "=", "_getStats", "(", "fullPath", ")", ";", "this", ".", "_id", "=", "fullPath", ";", "this", ".", "_name", "=", "_getFileName", "(", "fullPath", ")", ";", "this", ".", "_fileSystem", "=", "fileSystem", ";", "this", ".", "donotWatch", "=", "true", ";", "this", ".", "protocol", "=", "protocol", ";", "this", ".", "encodedPath", "=", "fullPath", ";", "}" ]
Model for a RemoteFile. This class should *not* be instantiated directly. Use FileSystem.getFileForPath See the FileSystem class for more details. @constructor @param {!string} fullPath The full path for this File. @param {!FileSystem} fileSystem The file system associated with this File.
[ "Model", "for", "a", "RemoteFile", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RemoteFileAdapter/RemoteFile.js#L70-L82
train
adobe/brackets
src/extensions/default/JavaScriptCodeHints/HintUtils2.js
formatParameterHint
function formatParameterHint(params, appendSeparators, appendParameter, typesOnly) { var result = "", pendingOptional = false; params.forEach(function (value, i) { var param = value.type, separators = ""; if (value.isOptional) { // if an optional param is following by an optional parameter, then // terminate the bracket. Otherwise enclose a required parameter // in the same bracket. if (pendingOptional) { separators += "]"; } pendingOptional = true; } if (i > 0) { separators += ", "; } if (value.isOptional) { separators += "["; } if (appendSeparators) { appendSeparators(separators); } result += separators; if (!typesOnly) { param += " " + value.name; } if (appendParameter) { appendParameter(param, i); } result += param; }); if (pendingOptional) { if (appendSeparators) { appendSeparators("]"); } result += "]"; } return result; }
javascript
function formatParameterHint(params, appendSeparators, appendParameter, typesOnly) { var result = "", pendingOptional = false; params.forEach(function (value, i) { var param = value.type, separators = ""; if (value.isOptional) { // if an optional param is following by an optional parameter, then // terminate the bracket. Otherwise enclose a required parameter // in the same bracket. if (pendingOptional) { separators += "]"; } pendingOptional = true; } if (i > 0) { separators += ", "; } if (value.isOptional) { separators += "["; } if (appendSeparators) { appendSeparators(separators); } result += separators; if (!typesOnly) { param += " " + value.name; } if (appendParameter) { appendParameter(param, i); } result += param; }); if (pendingOptional) { if (appendSeparators) { appendSeparators("]"); } result += "]"; } return result; }
[ "function", "formatParameterHint", "(", "params", ",", "appendSeparators", ",", "appendParameter", ",", "typesOnly", ")", "{", "var", "result", "=", "\"\"", ",", "pendingOptional", "=", "false", ";", "params", ".", "forEach", "(", "function", "(", "value", ",", "i", ")", "{", "var", "param", "=", "value", ".", "type", ",", "separators", "=", "\"\"", ";", "if", "(", "value", ".", "isOptional", ")", "{", "if", "(", "pendingOptional", ")", "{", "separators", "+=", "\"]\"", ";", "}", "pendingOptional", "=", "true", ";", "}", "if", "(", "i", ">", "0", ")", "{", "separators", "+=", "\", \"", ";", "}", "if", "(", "value", ".", "isOptional", ")", "{", "separators", "+=", "\"[\"", ";", "}", "if", "(", "appendSeparators", ")", "{", "appendSeparators", "(", "separators", ")", ";", "}", "result", "+=", "separators", ";", "if", "(", "!", "typesOnly", ")", "{", "param", "+=", "\" \"", "+", "value", ".", "name", ";", "}", "if", "(", "appendParameter", ")", "{", "appendParameter", "(", "param", ",", "i", ")", ";", "}", "result", "+=", "param", ";", "}", ")", ";", "if", "(", "pendingOptional", ")", "{", "if", "(", "appendSeparators", ")", "{", "appendSeparators", "(", "\"]\"", ")", ";", "}", "result", "+=", "\"]\"", ";", "}", "return", "result", ";", "}" ]
Format the given parameter array. Handles separators between parameters, syntax for optional parameters, and the order of the parameter type and parameter name. @param {!Array.<{name: string, type: string, isOptional: boolean}>} params - array of parameter descriptors @param {function(string)=} appendSeparators - callback function to append separators. The separator is passed to the callback. @param {function(string, number)=} appendParameter - callback function to append parameter. The formatted parameter type and name is passed to the callback along with the current index of the parameter. @param {boolean=} typesOnly - only show parameter types. The default behavior is to include both parameter names and types. @return {string} - formatted parameter hint
[ "Format", "the", "given", "parameter", "array", ".", "Handles", "separators", "between", "parameters", "syntax", "for", "optional", "parameters", "and", "the", "order", "of", "the", "parameter", "type", "and", "parameter", "name", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptCodeHints/HintUtils2.js#L49-L103
train
adobe/brackets
src/utils/NodeConnection.js
setDeferredTimeout
function setDeferredTimeout(deferred, delay) { var timer = setTimeout(function () { deferred.reject("timeout"); }, delay); deferred.always(function () { clearTimeout(timer); }); }
javascript
function setDeferredTimeout(deferred, delay) { var timer = setTimeout(function () { deferred.reject("timeout"); }, delay); deferred.always(function () { clearTimeout(timer); }); }
[ "function", "setDeferredTimeout", "(", "deferred", ",", "delay", ")", "{", "var", "timer", "=", "setTimeout", "(", "function", "(", ")", "{", "deferred", ".", "reject", "(", "\"timeout\"", ")", ";", "}", ",", "delay", ")", ";", "deferred", ".", "always", "(", "function", "(", ")", "{", "clearTimeout", "(", "timer", ")", ";", "}", ")", ";", "}" ]
2^32 - 1 @private Helper function to auto-reject a deferred after a given amount of time. If the deferred is resolved/rejected manually, then the timeout is automatically cleared.
[ "2^32", "-", "1" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/NodeConnection.js#L64-L69
train
adobe/brackets
src/utils/NodeConnection.js
registerHandlersAndDomains
function registerHandlersAndDomains(ws, port) { // Called if we succeed at the final setup function success() { self._ws.onclose = function () { if (self._autoReconnect) { var $promise = self.connect(true); self.trigger("close", $promise); } else { self._cleanup(); self.trigger("close"); } }; deferred.resolve(); } // Called if we fail at the final setup function fail(err) { self._cleanup(); deferred.reject(err); } self._ws = ws; self._port = port; self._ws.onmessage = self._receive.bind(self); // refresh the current domains, then re-register any // "autoregister" modules self._refreshInterface().then( function () { if (self._registeredModules.length > 0) { self.loadDomains(self._registeredModules, false).then( success, fail ); } else { success(); } }, fail ); }
javascript
function registerHandlersAndDomains(ws, port) { // Called if we succeed at the final setup function success() { self._ws.onclose = function () { if (self._autoReconnect) { var $promise = self.connect(true); self.trigger("close", $promise); } else { self._cleanup(); self.trigger("close"); } }; deferred.resolve(); } // Called if we fail at the final setup function fail(err) { self._cleanup(); deferred.reject(err); } self._ws = ws; self._port = port; self._ws.onmessage = self._receive.bind(self); // refresh the current domains, then re-register any // "autoregister" modules self._refreshInterface().then( function () { if (self._registeredModules.length > 0) { self.loadDomains(self._registeredModules, false).then( success, fail ); } else { success(); } }, fail ); }
[ "function", "registerHandlersAndDomains", "(", "ws", ",", "port", ")", "{", "function", "success", "(", ")", "{", "self", ".", "_ws", ".", "onclose", "=", "function", "(", ")", "{", "if", "(", "self", ".", "_autoReconnect", ")", "{", "var", "$promise", "=", "self", ".", "connect", "(", "true", ")", ";", "self", ".", "trigger", "(", "\"close\"", ",", "$promise", ")", ";", "}", "else", "{", "self", ".", "_cleanup", "(", ")", ";", "self", ".", "trigger", "(", "\"close\"", ")", ";", "}", "}", ";", "deferred", ".", "resolve", "(", ")", ";", "}", "function", "fail", "(", "err", ")", "{", "self", ".", "_cleanup", "(", ")", ";", "deferred", ".", "reject", "(", "err", ")", ";", "}", "self", ".", "_ws", "=", "ws", ";", "self", ".", "_port", "=", "port", ";", "self", ".", "_ws", ".", "onmessage", "=", "self", ".", "_receive", ".", "bind", "(", "self", ")", ";", "self", ".", "_refreshInterface", "(", ")", ".", "then", "(", "function", "(", ")", "{", "if", "(", "self", ".", "_registeredModules", ".", "length", ">", "0", ")", "{", "self", ".", "loadDomains", "(", "self", ".", "_registeredModules", ",", "false", ")", ".", "then", "(", "success", ",", "fail", ")", ";", "}", "else", "{", "success", "(", ")", ";", "}", "}", ",", "fail", ")", ";", "}" ]
Called after a successful connection to do final setup steps
[ "Called", "after", "a", "successful", "connection", "to", "do", "final", "setup", "steps" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/NodeConnection.js#L256-L295
train
adobe/brackets
src/utils/NodeConnection.js
success
function success() { self._ws.onclose = function () { if (self._autoReconnect) { var $promise = self.connect(true); self.trigger("close", $promise); } else { self._cleanup(); self.trigger("close"); } }; deferred.resolve(); }
javascript
function success() { self._ws.onclose = function () { if (self._autoReconnect) { var $promise = self.connect(true); self.trigger("close", $promise); } else { self._cleanup(); self.trigger("close"); } }; deferred.resolve(); }
[ "function", "success", "(", ")", "{", "self", ".", "_ws", ".", "onclose", "=", "function", "(", ")", "{", "if", "(", "self", ".", "_autoReconnect", ")", "{", "var", "$promise", "=", "self", ".", "connect", "(", "true", ")", ";", "self", ".", "trigger", "(", "\"close\"", ",", "$promise", ")", ";", "}", "else", "{", "self", ".", "_cleanup", "(", ")", ";", "self", ".", "trigger", "(", "\"close\"", ")", ";", "}", "}", ";", "deferred", ".", "resolve", "(", ")", ";", "}" ]
Called if we succeed at the final setup
[ "Called", "if", "we", "succeed", "at", "the", "final", "setup" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/NodeConnection.js#L258-L269
train
adobe/brackets
src/utils/NodeConnection.js
doConnect
function doConnect() { attemptCount++; attemptTimestamp = new Date(); attemptSingleConnect().then( registerHandlersAndDomains, // succeded function () { // failed this attempt, possibly try again if (attemptCount < CONNECTION_ATTEMPTS) { //try again // Calculate how long we should wait before trying again var now = new Date(); var delay = Math.max( RETRY_DELAY - (now - attemptTimestamp), 1 ); setTimeout(doConnect, delay); } else { // too many attempts, give up deferred.reject("Max connection attempts reached"); } } ); }
javascript
function doConnect() { attemptCount++; attemptTimestamp = new Date(); attemptSingleConnect().then( registerHandlersAndDomains, // succeded function () { // failed this attempt, possibly try again if (attemptCount < CONNECTION_ATTEMPTS) { //try again // Calculate how long we should wait before trying again var now = new Date(); var delay = Math.max( RETRY_DELAY - (now - attemptTimestamp), 1 ); setTimeout(doConnect, delay); } else { // too many attempts, give up deferred.reject("Max connection attempts reached"); } } ); }
[ "function", "doConnect", "(", ")", "{", "attemptCount", "++", ";", "attemptTimestamp", "=", "new", "Date", "(", ")", ";", "attemptSingleConnect", "(", ")", ".", "then", "(", "registerHandlersAndDomains", ",", "function", "(", ")", "{", "if", "(", "attemptCount", "<", "CONNECTION_ATTEMPTS", ")", "{", "var", "now", "=", "new", "Date", "(", ")", ";", "var", "delay", "=", "Math", ".", "max", "(", "RETRY_DELAY", "-", "(", "now", "-", "attemptTimestamp", ")", ",", "1", ")", ";", "setTimeout", "(", "doConnect", ",", "delay", ")", ";", "}", "else", "{", "deferred", ".", "reject", "(", "\"Max connection attempts reached\"", ")", ";", "}", "}", ")", ";", "}" ]
Repeatedly tries to connect until we succeed or until we've failed CONNECTION_ATTEMPT times. After each attempt, waits at least RETRY_DELAY before trying again.
[ "Repeatedly", "tries", "to", "connect", "until", "we", "succeed", "or", "until", "we", "ve", "failed", "CONNECTION_ATTEMPT", "times", ".", "After", "each", "attempt", "waits", "at", "least", "RETRY_DELAY", "before", "trying", "again", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/NodeConnection.js#L300-L319
train
adobe/brackets
src/extensions/default/JavaScriptRefactoring/WrapSelection.js
_wrapSelectedStatements
function _wrapSelectedStatements (wrapperName, err) { var editor = EditorManager.getActiveEditor(); if (!editor) { return; } initializeRefactoringSession(editor); var startIndex = current.startIndex, endIndex = current.endIndex, selectedText = current.selectedText, pos; if (selectedText.length === 0) { var statementNode = RefactoringUtils.findSurroundASTNode(current.ast, {start: startIndex}, ["Statement"]); if (!statementNode) { current.editor.displayErrorMessageAtCursor(err); return; } selectedText = current.text.substr(statementNode.start, statementNode.end - statementNode.start); startIndex = statementNode.start; endIndex = statementNode.end; } else { var selectionDetails = RefactoringUtils.normalizeText(selectedText, startIndex, endIndex); selectedText = selectionDetails.text; startIndex = selectionDetails.start; endIndex = selectionDetails.end; } if (!RefactoringUtils.checkStatement(current.ast, startIndex, endIndex, selectedText)) { current.editor.displayErrorMessageAtCursor(err); return; } pos = { "start": current.cm.posFromIndex(startIndex), "end": current.cm.posFromIndex(endIndex) }; current.document.batchOperation(function() { current.replaceTextFromTemplate(wrapperName, {body: selectedText}, pos); }); if (wrapperName === TRY_CATCH) { var cursorLine = current.editor.getSelection().end.line - 1, startCursorCh = current.document.getLine(cursorLine).indexOf("\/\/"), endCursorCh = current.document.getLine(cursorLine).length; current.editor.setSelection({"line": cursorLine, "ch": startCursorCh}, {"line": cursorLine, "ch": endCursorCh}); } else if (wrapperName === WRAP_IN_CONDITION) { current.editor.setSelection({"line": pos.start.line, "ch": pos.start.ch + 4}, {"line": pos.start.line, "ch": pos.start.ch + 13}); } }
javascript
function _wrapSelectedStatements (wrapperName, err) { var editor = EditorManager.getActiveEditor(); if (!editor) { return; } initializeRefactoringSession(editor); var startIndex = current.startIndex, endIndex = current.endIndex, selectedText = current.selectedText, pos; if (selectedText.length === 0) { var statementNode = RefactoringUtils.findSurroundASTNode(current.ast, {start: startIndex}, ["Statement"]); if (!statementNode) { current.editor.displayErrorMessageAtCursor(err); return; } selectedText = current.text.substr(statementNode.start, statementNode.end - statementNode.start); startIndex = statementNode.start; endIndex = statementNode.end; } else { var selectionDetails = RefactoringUtils.normalizeText(selectedText, startIndex, endIndex); selectedText = selectionDetails.text; startIndex = selectionDetails.start; endIndex = selectionDetails.end; } if (!RefactoringUtils.checkStatement(current.ast, startIndex, endIndex, selectedText)) { current.editor.displayErrorMessageAtCursor(err); return; } pos = { "start": current.cm.posFromIndex(startIndex), "end": current.cm.posFromIndex(endIndex) }; current.document.batchOperation(function() { current.replaceTextFromTemplate(wrapperName, {body: selectedText}, pos); }); if (wrapperName === TRY_CATCH) { var cursorLine = current.editor.getSelection().end.line - 1, startCursorCh = current.document.getLine(cursorLine).indexOf("\/\/"), endCursorCh = current.document.getLine(cursorLine).length; current.editor.setSelection({"line": cursorLine, "ch": startCursorCh}, {"line": cursorLine, "ch": endCursorCh}); } else if (wrapperName === WRAP_IN_CONDITION) { current.editor.setSelection({"line": pos.start.line, "ch": pos.start.ch + 4}, {"line": pos.start.line, "ch": pos.start.ch + 13}); } }
[ "function", "_wrapSelectedStatements", "(", "wrapperName", ",", "err", ")", "{", "var", "editor", "=", "EditorManager", ".", "getActiveEditor", "(", ")", ";", "if", "(", "!", "editor", ")", "{", "return", ";", "}", "initializeRefactoringSession", "(", "editor", ")", ";", "var", "startIndex", "=", "current", ".", "startIndex", ",", "endIndex", "=", "current", ".", "endIndex", ",", "selectedText", "=", "current", ".", "selectedText", ",", "pos", ";", "if", "(", "selectedText", ".", "length", "===", "0", ")", "{", "var", "statementNode", "=", "RefactoringUtils", ".", "findSurroundASTNode", "(", "current", ".", "ast", ",", "{", "start", ":", "startIndex", "}", ",", "[", "\"Statement\"", "]", ")", ";", "if", "(", "!", "statementNode", ")", "{", "current", ".", "editor", ".", "displayErrorMessageAtCursor", "(", "err", ")", ";", "return", ";", "}", "selectedText", "=", "current", ".", "text", ".", "substr", "(", "statementNode", ".", "start", ",", "statementNode", ".", "end", "-", "statementNode", ".", "start", ")", ";", "startIndex", "=", "statementNode", ".", "start", ";", "endIndex", "=", "statementNode", ".", "end", ";", "}", "else", "{", "var", "selectionDetails", "=", "RefactoringUtils", ".", "normalizeText", "(", "selectedText", ",", "startIndex", ",", "endIndex", ")", ";", "selectedText", "=", "selectionDetails", ".", "text", ";", "startIndex", "=", "selectionDetails", ".", "start", ";", "endIndex", "=", "selectionDetails", ".", "end", ";", "}", "if", "(", "!", "RefactoringUtils", ".", "checkStatement", "(", "current", ".", "ast", ",", "startIndex", ",", "endIndex", ",", "selectedText", ")", ")", "{", "current", ".", "editor", ".", "displayErrorMessageAtCursor", "(", "err", ")", ";", "return", ";", "}", "pos", "=", "{", "\"start\"", ":", "current", ".", "cm", ".", "posFromIndex", "(", "startIndex", ")", ",", "\"end\"", ":", "current", ".", "cm", ".", "posFromIndex", "(", "endIndex", ")", "}", ";", "current", ".", "document", ".", "batchOperation", "(", "function", "(", ")", "{", "current", ".", "replaceTextFromTemplate", "(", "wrapperName", ",", "{", "body", ":", "selectedText", "}", ",", "pos", ")", ";", "}", ")", ";", "if", "(", "wrapperName", "===", "TRY_CATCH", ")", "{", "var", "cursorLine", "=", "current", ".", "editor", ".", "getSelection", "(", ")", ".", "end", ".", "line", "-", "1", ",", "startCursorCh", "=", "current", ".", "document", ".", "getLine", "(", "cursorLine", ")", ".", "indexOf", "(", "\"\\/\\/\"", ")", ",", "\\/", ";", "\\/", "}", "else", "endCursorCh", "=", "current", ".", "document", ".", "getLine", "(", "cursorLine", ")", ".", "length", "}" ]
Wrap selected statements @param {string} wrapperName - template name where we want wrap selected statements @param {string} err- error message if we can't wrap selected code
[ "Wrap", "selected", "statements" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/WrapSelection.js#L57-L108
train
adobe/brackets
src/extensions/default/JavaScriptRefactoring/WrapSelection.js
createGettersAndSetters
function createGettersAndSetters() { var editor = EditorManager.getActiveEditor(); if (!editor) { return; } initializeRefactoringSession(editor); var startIndex = current.startIndex, endIndex = current.endIndex, selectedText = current.selectedText; if (selectedText.length >= 1) { var selectionDetails = RefactoringUtils.normalizeText(selectedText, startIndex, endIndex); selectedText = selectionDetails.text; startIndex = selectionDetails.start; endIndex = selectionDetails.end; } var token = TokenUtils.getTokenAt(current.cm, current.cm.posFromIndex(endIndex)), commaString = ",", isLastNode, templateParams, parentNode, propertyEndPos; //Create getters and setters only if selected reference is a property if (token.type !== "property") { current.editor.displayErrorMessageAtCursor(Strings.ERROR_GETTERS_SETTERS); return; } parentNode = current.getParentNode(current.ast, endIndex); // Check if selected propery is child of a object expression if (!parentNode || !parentNode.properties) { current.editor.displayErrorMessageAtCursor(Strings.ERROR_GETTERS_SETTERS); return; } var propertyNodeArray = parentNode.properties; // Find the last Propery Node before endIndex var properyNodeIndex = propertyNodeArray.findIndex(function (element) { return (endIndex >= element.start && endIndex < element.end); }); var propertyNode = propertyNodeArray[properyNodeIndex]; //Get Current Selected Property End Index; propertyEndPos = editor.posFromIndex(propertyNode.end); //We have to add ',' so we need to find position of current property selected isLastNode = current.isLastNodeInScope(current.ast, endIndex); var nextPropertNode, nextPropertyStartPos; if(!isLastNode && properyNodeIndex + 1 <= propertyNodeArray.length - 1) { nextPropertNode = propertyNodeArray[properyNodeIndex + 1]; nextPropertyStartPos = editor.posFromIndex(nextPropertNode.start); if(propertyEndPos.line !== nextPropertyStartPos.line) { propertyEndPos = current.lineEndPosition(current.startPos.line); } else { propertyEndPos = nextPropertyStartPos; commaString = ", "; } } var getSetPos; if (isLastNode) { getSetPos = current.document.adjustPosForChange(propertyEndPos, commaString.split("\n"), propertyEndPos, propertyEndPos); } else { getSetPos = propertyEndPos; } templateParams = { "getName": token.string, "setName": token.string, "tokenName": token.string }; // Replace, setSelection, IndentLine // We need to call batchOperation as indentLine don't have option to add origin as like replaceRange current.document.batchOperation(function() { if (isLastNode) { //Add ',' in the end of current line current.document.replaceRange(commaString, propertyEndPos, propertyEndPos); } current.editor.setSelection(getSetPos); //Selection on line end // Add getters and setters for given token using template at current cursor position current.replaceTextFromTemplate(GETTERS_SETTERS, templateParams); if (!isLastNode) { // Add ',' at the end setter current.document.replaceRange(commaString, current.editor.getSelection().start, current.editor.getSelection().start); } }); }
javascript
function createGettersAndSetters() { var editor = EditorManager.getActiveEditor(); if (!editor) { return; } initializeRefactoringSession(editor); var startIndex = current.startIndex, endIndex = current.endIndex, selectedText = current.selectedText; if (selectedText.length >= 1) { var selectionDetails = RefactoringUtils.normalizeText(selectedText, startIndex, endIndex); selectedText = selectionDetails.text; startIndex = selectionDetails.start; endIndex = selectionDetails.end; } var token = TokenUtils.getTokenAt(current.cm, current.cm.posFromIndex(endIndex)), commaString = ",", isLastNode, templateParams, parentNode, propertyEndPos; //Create getters and setters only if selected reference is a property if (token.type !== "property") { current.editor.displayErrorMessageAtCursor(Strings.ERROR_GETTERS_SETTERS); return; } parentNode = current.getParentNode(current.ast, endIndex); // Check if selected propery is child of a object expression if (!parentNode || !parentNode.properties) { current.editor.displayErrorMessageAtCursor(Strings.ERROR_GETTERS_SETTERS); return; } var propertyNodeArray = parentNode.properties; // Find the last Propery Node before endIndex var properyNodeIndex = propertyNodeArray.findIndex(function (element) { return (endIndex >= element.start && endIndex < element.end); }); var propertyNode = propertyNodeArray[properyNodeIndex]; //Get Current Selected Property End Index; propertyEndPos = editor.posFromIndex(propertyNode.end); //We have to add ',' so we need to find position of current property selected isLastNode = current.isLastNodeInScope(current.ast, endIndex); var nextPropertNode, nextPropertyStartPos; if(!isLastNode && properyNodeIndex + 1 <= propertyNodeArray.length - 1) { nextPropertNode = propertyNodeArray[properyNodeIndex + 1]; nextPropertyStartPos = editor.posFromIndex(nextPropertNode.start); if(propertyEndPos.line !== nextPropertyStartPos.line) { propertyEndPos = current.lineEndPosition(current.startPos.line); } else { propertyEndPos = nextPropertyStartPos; commaString = ", "; } } var getSetPos; if (isLastNode) { getSetPos = current.document.adjustPosForChange(propertyEndPos, commaString.split("\n"), propertyEndPos, propertyEndPos); } else { getSetPos = propertyEndPos; } templateParams = { "getName": token.string, "setName": token.string, "tokenName": token.string }; // Replace, setSelection, IndentLine // We need to call batchOperation as indentLine don't have option to add origin as like replaceRange current.document.batchOperation(function() { if (isLastNode) { //Add ',' in the end of current line current.document.replaceRange(commaString, propertyEndPos, propertyEndPos); } current.editor.setSelection(getSetPos); //Selection on line end // Add getters and setters for given token using template at current cursor position current.replaceTextFromTemplate(GETTERS_SETTERS, templateParams); if (!isLastNode) { // Add ',' at the end setter current.document.replaceRange(commaString, current.editor.getSelection().start, current.editor.getSelection().start); } }); }
[ "function", "createGettersAndSetters", "(", ")", "{", "var", "editor", "=", "EditorManager", ".", "getActiveEditor", "(", ")", ";", "if", "(", "!", "editor", ")", "{", "return", ";", "}", "initializeRefactoringSession", "(", "editor", ")", ";", "var", "startIndex", "=", "current", ".", "startIndex", ",", "endIndex", "=", "current", ".", "endIndex", ",", "selectedText", "=", "current", ".", "selectedText", ";", "if", "(", "selectedText", ".", "length", ">=", "1", ")", "{", "var", "selectionDetails", "=", "RefactoringUtils", ".", "normalizeText", "(", "selectedText", ",", "startIndex", ",", "endIndex", ")", ";", "selectedText", "=", "selectionDetails", ".", "text", ";", "startIndex", "=", "selectionDetails", ".", "start", ";", "endIndex", "=", "selectionDetails", ".", "end", ";", "}", "var", "token", "=", "TokenUtils", ".", "getTokenAt", "(", "current", ".", "cm", ",", "current", ".", "cm", ".", "posFromIndex", "(", "endIndex", ")", ")", ",", "commaString", "=", "\",\"", ",", "isLastNode", ",", "templateParams", ",", "parentNode", ",", "propertyEndPos", ";", "if", "(", "token", ".", "type", "!==", "\"property\"", ")", "{", "current", ".", "editor", ".", "displayErrorMessageAtCursor", "(", "Strings", ".", "ERROR_GETTERS_SETTERS", ")", ";", "return", ";", "}", "parentNode", "=", "current", ".", "getParentNode", "(", "current", ".", "ast", ",", "endIndex", ")", ";", "if", "(", "!", "parentNode", "||", "!", "parentNode", ".", "properties", ")", "{", "current", ".", "editor", ".", "displayErrorMessageAtCursor", "(", "Strings", ".", "ERROR_GETTERS_SETTERS", ")", ";", "return", ";", "}", "var", "propertyNodeArray", "=", "parentNode", ".", "properties", ";", "var", "properyNodeIndex", "=", "propertyNodeArray", ".", "findIndex", "(", "function", "(", "element", ")", "{", "return", "(", "endIndex", ">=", "element", ".", "start", "&&", "endIndex", "<", "element", ".", "end", ")", ";", "}", ")", ";", "var", "propertyNode", "=", "propertyNodeArray", "[", "properyNodeIndex", "]", ";", "propertyEndPos", "=", "editor", ".", "posFromIndex", "(", "propertyNode", ".", "end", ")", ";", "isLastNode", "=", "current", ".", "isLastNodeInScope", "(", "current", ".", "ast", ",", "endIndex", ")", ";", "var", "nextPropertNode", ",", "nextPropertyStartPos", ";", "if", "(", "!", "isLastNode", "&&", "properyNodeIndex", "+", "1", "<=", "propertyNodeArray", ".", "length", "-", "1", ")", "{", "nextPropertNode", "=", "propertyNodeArray", "[", "properyNodeIndex", "+", "1", "]", ";", "nextPropertyStartPos", "=", "editor", ".", "posFromIndex", "(", "nextPropertNode", ".", "start", ")", ";", "if", "(", "propertyEndPos", ".", "line", "!==", "nextPropertyStartPos", ".", "line", ")", "{", "propertyEndPos", "=", "current", ".", "lineEndPosition", "(", "current", ".", "startPos", ".", "line", ")", ";", "}", "else", "{", "propertyEndPos", "=", "nextPropertyStartPos", ";", "commaString", "=", "\", \"", ";", "}", "}", "var", "getSetPos", ";", "if", "(", "isLastNode", ")", "{", "getSetPos", "=", "current", ".", "document", ".", "adjustPosForChange", "(", "propertyEndPos", ",", "commaString", ".", "split", "(", "\"\\n\"", ")", ",", "\\n", ",", "propertyEndPos", ")", ";", "}", "else", "propertyEndPos", "{", "getSetPos", "=", "propertyEndPos", ";", "}", "templateParams", "=", "{", "\"getName\"", ":", "token", ".", "string", ",", "\"setName\"", ":", "token", ".", "string", ",", "\"tokenName\"", ":", "token", ".", "string", "}", ";", "}" ]
Create gtteres and setters for a property
[ "Create", "gtteres", "and", "setters", "for", "a", "property" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/JavaScriptRefactoring/WrapSelection.js#L230-L327
train
adobe/brackets
src/utils/Async.js
doSequentiallyInBackground
function doSequentiallyInBackground(items, fnProcessItem, maxBlockingTime, idleTime) { maxBlockingTime = maxBlockingTime || 15; idleTime = idleTime || 30; var sliceStartTime = (new Date()).getTime(); return doSequentially(items, function (item, i) { var result = new $.Deferred(); // process the next item fnProcessItem(item, i); // if we've exhausted our maxBlockingTime if ((new Date()).getTime() - sliceStartTime >= maxBlockingTime) { //yield window.setTimeout(function () { sliceStartTime = (new Date()).getTime(); result.resolve(); }, idleTime); } else { //continue processing result.resolve(); } return result; }, false); }
javascript
function doSequentiallyInBackground(items, fnProcessItem, maxBlockingTime, idleTime) { maxBlockingTime = maxBlockingTime || 15; idleTime = idleTime || 30; var sliceStartTime = (new Date()).getTime(); return doSequentially(items, function (item, i) { var result = new $.Deferred(); // process the next item fnProcessItem(item, i); // if we've exhausted our maxBlockingTime if ((new Date()).getTime() - sliceStartTime >= maxBlockingTime) { //yield window.setTimeout(function () { sliceStartTime = (new Date()).getTime(); result.resolve(); }, idleTime); } else { //continue processing result.resolve(); } return result; }, false); }
[ "function", "doSequentiallyInBackground", "(", "items", ",", "fnProcessItem", ",", "maxBlockingTime", ",", "idleTime", ")", "{", "maxBlockingTime", "=", "maxBlockingTime", "||", "15", ";", "idleTime", "=", "idleTime", "||", "30", ";", "var", "sliceStartTime", "=", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", ";", "return", "doSequentially", "(", "items", ",", "function", "(", "item", ",", "i", ")", "{", "var", "result", "=", "new", "$", ".", "Deferred", "(", ")", ";", "fnProcessItem", "(", "item", ",", "i", ")", ";", "if", "(", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", "-", "sliceStartTime", ">=", "maxBlockingTime", ")", "{", "window", ".", "setTimeout", "(", "function", "(", ")", "{", "sliceStartTime", "=", "(", "new", "Date", "(", ")", ")", ".", "getTime", "(", ")", ";", "result", ".", "resolve", "(", ")", ";", "}", ",", "idleTime", ")", ";", "}", "else", "{", "result", ".", "resolve", "(", ")", ";", "}", "return", "result", ";", "}", ",", "false", ")", ";", "}" ]
Executes a series of synchronous tasks sequentially spread over time-slices less than maxBlockingTime. Processing yields by idleTime between time-slices. @param {!Array.<*>} items @param {!function(*, number)} fnProcessItem Function that synchronously processes one item @param {number=} maxBlockingTime @param {number=} idleTime @return {$.Promise}
[ "Executes", "a", "series", "of", "synchronous", "tasks", "sequentially", "spread", "over", "time", "-", "slices", "less", "than", "maxBlockingTime", ".", "Processing", "yields", "by", "idleTime", "between", "time", "-", "slices", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/Async.js#L208-L235
train
adobe/brackets
src/language/CodeInspection.js
setGotoEnabled
function setGotoEnabled(gotoEnabled) { CommandManager.get(Commands.NAVIGATE_GOTO_FIRST_PROBLEM).setEnabled(gotoEnabled); _gotoEnabled = gotoEnabled; }
javascript
function setGotoEnabled(gotoEnabled) { CommandManager.get(Commands.NAVIGATE_GOTO_FIRST_PROBLEM).setEnabled(gotoEnabled); _gotoEnabled = gotoEnabled; }
[ "function", "setGotoEnabled", "(", "gotoEnabled", ")", "{", "CommandManager", ".", "get", "(", "Commands", ".", "NAVIGATE_GOTO_FIRST_PROBLEM", ")", ".", "setEnabled", "(", "gotoEnabled", ")", ";", "_gotoEnabled", "=", "gotoEnabled", ";", "}" ]
Enable or disable the "Go to First Error" command @param {boolean} gotoEnabled Whether it is enabled.
[ "Enable", "or", "disable", "the", "Go", "to", "First", "Error", "command" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CodeInspection.js#L141-L144
train
adobe/brackets
src/language/CodeInspection.js
getProvidersForPath
function getProvidersForPath(filePath) { var language = LanguageManager.getLanguageForPath(filePath).getId(), context = PreferencesManager._buildContext(filePath, language), installedProviders = getProvidersForLanguageId(language), preferredProviders, prefPreferredProviderNames = prefs.get(PREF_PREFER_PROVIDERS, context), prefPreferredOnly = prefs.get(PREF_PREFERRED_ONLY, context), providers; if (prefPreferredProviderNames && prefPreferredProviderNames.length) { if (typeof prefPreferredProviderNames === "string") { prefPreferredProviderNames = [prefPreferredProviderNames]; } preferredProviders = prefPreferredProviderNames.reduce(function (result, key) { var provider = _.find(installedProviders, {name: key}); if (provider) { result.push(provider); } return result; }, []); if (prefPreferredOnly) { providers = preferredProviders; } else { providers = _.union(preferredProviders, installedProviders); } } else { providers = installedProviders; } return providers; }
javascript
function getProvidersForPath(filePath) { var language = LanguageManager.getLanguageForPath(filePath).getId(), context = PreferencesManager._buildContext(filePath, language), installedProviders = getProvidersForLanguageId(language), preferredProviders, prefPreferredProviderNames = prefs.get(PREF_PREFER_PROVIDERS, context), prefPreferredOnly = prefs.get(PREF_PREFERRED_ONLY, context), providers; if (prefPreferredProviderNames && prefPreferredProviderNames.length) { if (typeof prefPreferredProviderNames === "string") { prefPreferredProviderNames = [prefPreferredProviderNames]; } preferredProviders = prefPreferredProviderNames.reduce(function (result, key) { var provider = _.find(installedProviders, {name: key}); if (provider) { result.push(provider); } return result; }, []); if (prefPreferredOnly) { providers = preferredProviders; } else { providers = _.union(preferredProviders, installedProviders); } } else { providers = installedProviders; } return providers; }
[ "function", "getProvidersForPath", "(", "filePath", ")", "{", "var", "language", "=", "LanguageManager", ".", "getLanguageForPath", "(", "filePath", ")", ".", "getId", "(", ")", ",", "context", "=", "PreferencesManager", ".", "_buildContext", "(", "filePath", ",", "language", ")", ",", "installedProviders", "=", "getProvidersForLanguageId", "(", "language", ")", ",", "preferredProviders", ",", "prefPreferredProviderNames", "=", "prefs", ".", "get", "(", "PREF_PREFER_PROVIDERS", ",", "context", ")", ",", "prefPreferredOnly", "=", "prefs", ".", "get", "(", "PREF_PREFERRED_ONLY", ",", "context", ")", ",", "providers", ";", "if", "(", "prefPreferredProviderNames", "&&", "prefPreferredProviderNames", ".", "length", ")", "{", "if", "(", "typeof", "prefPreferredProviderNames", "===", "\"string\"", ")", "{", "prefPreferredProviderNames", "=", "[", "prefPreferredProviderNames", "]", ";", "}", "preferredProviders", "=", "prefPreferredProviderNames", ".", "reduce", "(", "function", "(", "result", ",", "key", ")", "{", "var", "provider", "=", "_", ".", "find", "(", "installedProviders", ",", "{", "name", ":", "key", "}", ")", ";", "if", "(", "provider", ")", "{", "result", ".", "push", "(", "provider", ")", ";", "}", "return", "result", ";", "}", ",", "[", "]", ")", ";", "if", "(", "prefPreferredOnly", ")", "{", "providers", "=", "preferredProviders", ";", "}", "else", "{", "providers", "=", "_", ".", "union", "(", "preferredProviders", ",", "installedProviders", ")", ";", "}", "}", "else", "{", "providers", "=", "installedProviders", ";", "}", "return", "providers", ";", "}" ]
Returns a list of provider for given file path, if available. Decision is made depending on the file extension. @param {!string} filePath @return {Array.<{name:string, scanFileAsync:?function(string, string):!{$.Promise}, scanFile:?function(string, string):?{errors:!Array, aborted:boolean}}>}
[ "Returns", "a", "list", "of", "provider", "for", "given", "file", "path", "if", "available", ".", "Decision", "is", "made", "depending", "on", "the", "file", "extension", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CodeInspection.js#L157-L188
train
adobe/brackets
src/language/CodeInspection.js
getProviderIDsForLanguage
function getProviderIDsForLanguage(languageId) { if (!_providers[languageId]) { return []; } return _providers[languageId].map(function (provider) { return provider.name; }); }
javascript
function getProviderIDsForLanguage(languageId) { if (!_providers[languageId]) { return []; } return _providers[languageId].map(function (provider) { return provider.name; }); }
[ "function", "getProviderIDsForLanguage", "(", "languageId", ")", "{", "if", "(", "!", "_providers", "[", "languageId", "]", ")", "{", "return", "[", "]", ";", "}", "return", "_providers", "[", "languageId", "]", ".", "map", "(", "function", "(", "provider", ")", "{", "return", "provider", ".", "name", ";", "}", ")", ";", "}" ]
Returns an array of the IDs of providers registered for a specific language @param {!string} languageId @return {Array.<string>} Names of registered providers.
[ "Returns", "an", "array", "of", "the", "IDs", "of", "providers", "registered", "for", "a", "specific", "language" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CodeInspection.js#L196-L203
train
adobe/brackets
src/language/CodeInspection.js
updatePanelTitleAndStatusBar
function updatePanelTitleAndStatusBar(numProblems, providersReportingProblems, aborted) { var message, tooltip; if (providersReportingProblems.length === 1) { // don't show a header if there is only one provider available for this file type $problemsPanelTable.find(".inspector-section").hide(); $problemsPanelTable.find("tr").removeClass("forced-hidden"); if (numProblems === 1 && !aborted) { message = StringUtils.format(Strings.SINGLE_ERROR, providersReportingProblems[0].name); } else { if (aborted) { numProblems += "+"; } message = StringUtils.format(Strings.MULTIPLE_ERRORS, providersReportingProblems[0].name, numProblems); } } else if (providersReportingProblems.length > 1) { $problemsPanelTable.find(".inspector-section").show(); if (aborted) { numProblems += "+"; } message = StringUtils.format(Strings.ERRORS_PANEL_TITLE_MULTIPLE, numProblems); } else { return; } $problemsPanel.find(".title").text(message); tooltip = StringUtils.format(Strings.STATUSBAR_CODE_INSPECTION_TOOLTIP, message); StatusBar.updateIndicator(INDICATOR_ID, true, "inspection-errors", tooltip); }
javascript
function updatePanelTitleAndStatusBar(numProblems, providersReportingProblems, aborted) { var message, tooltip; if (providersReportingProblems.length === 1) { // don't show a header if there is only one provider available for this file type $problemsPanelTable.find(".inspector-section").hide(); $problemsPanelTable.find("tr").removeClass("forced-hidden"); if (numProblems === 1 && !aborted) { message = StringUtils.format(Strings.SINGLE_ERROR, providersReportingProblems[0].name); } else { if (aborted) { numProblems += "+"; } message = StringUtils.format(Strings.MULTIPLE_ERRORS, providersReportingProblems[0].name, numProblems); } } else if (providersReportingProblems.length > 1) { $problemsPanelTable.find(".inspector-section").show(); if (aborted) { numProblems += "+"; } message = StringUtils.format(Strings.ERRORS_PANEL_TITLE_MULTIPLE, numProblems); } else { return; } $problemsPanel.find(".title").text(message); tooltip = StringUtils.format(Strings.STATUSBAR_CODE_INSPECTION_TOOLTIP, message); StatusBar.updateIndicator(INDICATOR_ID, true, "inspection-errors", tooltip); }
[ "function", "updatePanelTitleAndStatusBar", "(", "numProblems", ",", "providersReportingProblems", ",", "aborted", ")", "{", "var", "message", ",", "tooltip", ";", "if", "(", "providersReportingProblems", ".", "length", "===", "1", ")", "{", "$problemsPanelTable", ".", "find", "(", "\".inspector-section\"", ")", ".", "hide", "(", ")", ";", "$problemsPanelTable", ".", "find", "(", "\"tr\"", ")", ".", "removeClass", "(", "\"forced-hidden\"", ")", ";", "if", "(", "numProblems", "===", "1", "&&", "!", "aborted", ")", "{", "message", "=", "StringUtils", ".", "format", "(", "Strings", ".", "SINGLE_ERROR", ",", "providersReportingProblems", "[", "0", "]", ".", "name", ")", ";", "}", "else", "{", "if", "(", "aborted", ")", "{", "numProblems", "+=", "\"+\"", ";", "}", "message", "=", "StringUtils", ".", "format", "(", "Strings", ".", "MULTIPLE_ERRORS", ",", "providersReportingProblems", "[", "0", "]", ".", "name", ",", "numProblems", ")", ";", "}", "}", "else", "if", "(", "providersReportingProblems", ".", "length", ">", "1", ")", "{", "$problemsPanelTable", ".", "find", "(", "\".inspector-section\"", ")", ".", "show", "(", ")", ";", "if", "(", "aborted", ")", "{", "numProblems", "+=", "\"+\"", ";", "}", "message", "=", "StringUtils", ".", "format", "(", "Strings", ".", "ERRORS_PANEL_TITLE_MULTIPLE", ",", "numProblems", ")", ";", "}", "else", "{", "return", ";", "}", "$problemsPanel", ".", "find", "(", "\".title\"", ")", ".", "text", "(", "message", ")", ";", "tooltip", "=", "StringUtils", ".", "format", "(", "Strings", ".", "STATUSBAR_CODE_INSPECTION_TOOLTIP", ",", "message", ")", ";", "StatusBar", ".", "updateIndicator", "(", "INDICATOR_ID", ",", "true", ",", "\"inspection-errors\"", ",", "tooltip", ")", ";", "}" ]
Update the title of the problem panel and the tooltip of the status bar icon. The title and the tooltip will change based on the number of problems reported and how many provider reported problems. @param {Number} numProblems - total number of problems across all providers @param {Array.<{name:string, scanFileAsync:?function(string, string):!{$.Promise}, scanFile:?function(string, string):Object}>} providersReportingProblems - providers that reported problems @param {boolean} aborted - true if any provider returned a result with the 'aborted' flag set
[ "Update", "the", "title", "of", "the", "problem", "panel", "and", "the", "tooltip", "of", "the", "status", "bar", "icon", ".", "The", "title", "and", "the", "tooltip", "will", "change", "based", "on", "the", "number", "of", "problems", "reported", "and", "how", "many", "provider", "reported", "problems", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CodeInspection.js#L315-L347
train
adobe/brackets
src/language/CodeInspection.js
getProvidersForLanguageId
function getProvidersForLanguageId(languageId) { var result = []; if (_providers[languageId]) { result = result.concat(_providers[languageId]); } if (_providers['*']) { result = result.concat(_providers['*']); } return result; }
javascript
function getProvidersForLanguageId(languageId) { var result = []; if (_providers[languageId]) { result = result.concat(_providers[languageId]); } if (_providers['*']) { result = result.concat(_providers['*']); } return result; }
[ "function", "getProvidersForLanguageId", "(", "languageId", ")", "{", "var", "result", "=", "[", "]", ";", "if", "(", "_providers", "[", "languageId", "]", ")", "{", "result", "=", "result", ".", "concat", "(", "_providers", "[", "languageId", "]", ")", ";", "}", "if", "(", "_providers", "[", "'*'", "]", ")", "{", "result", "=", "result", ".", "concat", "(", "_providers", "[", "'*'", "]", ")", ";", "}", "return", "result", ";", "}" ]
Returns a list of providers registered for given languageId through register function
[ "Returns", "a", "list", "of", "providers", "registered", "for", "given", "languageId", "through", "register", "function" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CodeInspection.js#L519-L528
train
adobe/brackets
src/language/CodeInspection.js
updateListeners
function updateListeners() { if (_enabled) { // register our event listeners MainViewManager .on("currentFileChange.codeInspection", function () { run(); }); DocumentManager .on("currentDocumentLanguageChanged.codeInspection", function () { run(); }) .on("documentSaved.codeInspection documentRefreshed.codeInspection", function (event, document) { if (document === DocumentManager.getCurrentDocument()) { run(); } }); } else { DocumentManager.off(".codeInspection"); MainViewManager.off(".codeInspection"); } }
javascript
function updateListeners() { if (_enabled) { // register our event listeners MainViewManager .on("currentFileChange.codeInspection", function () { run(); }); DocumentManager .on("currentDocumentLanguageChanged.codeInspection", function () { run(); }) .on("documentSaved.codeInspection documentRefreshed.codeInspection", function (event, document) { if (document === DocumentManager.getCurrentDocument()) { run(); } }); } else { DocumentManager.off(".codeInspection"); MainViewManager.off(".codeInspection"); } }
[ "function", "updateListeners", "(", ")", "{", "if", "(", "_enabled", ")", "{", "MainViewManager", ".", "on", "(", "\"currentFileChange.codeInspection\"", ",", "function", "(", ")", "{", "run", "(", ")", ";", "}", ")", ";", "DocumentManager", ".", "on", "(", "\"currentDocumentLanguageChanged.codeInspection\"", ",", "function", "(", ")", "{", "run", "(", ")", ";", "}", ")", ".", "on", "(", "\"documentSaved.codeInspection documentRefreshed.codeInspection\"", ",", "function", "(", "event", ",", "document", ")", "{", "if", "(", "document", "===", "DocumentManager", ".", "getCurrentDocument", "(", ")", ")", "{", "run", "(", ")", ";", "}", "}", ")", ";", "}", "else", "{", "DocumentManager", ".", "off", "(", "\".codeInspection\"", ")", ";", "MainViewManager", ".", "off", "(", "\".codeInspection\"", ")", ";", "}", "}" ]
Update DocumentManager listeners.
[ "Update", "DocumentManager", "listeners", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CodeInspection.js#L533-L553
train
adobe/brackets
src/language/CodeInspection.js
toggleEnabled
function toggleEnabled(enabled, doNotSave) { if (enabled === undefined) { enabled = !_enabled; } // Take no action when there is no change. if (enabled === _enabled) { return; } _enabled = enabled; CommandManager.get(Commands.VIEW_TOGGLE_INSPECTION).setChecked(_enabled); updateListeners(); if (!doNotSave) { prefs.set(PREF_ENABLED, _enabled); prefs.save(); } // run immediately run(); }
javascript
function toggleEnabled(enabled, doNotSave) { if (enabled === undefined) { enabled = !_enabled; } // Take no action when there is no change. if (enabled === _enabled) { return; } _enabled = enabled; CommandManager.get(Commands.VIEW_TOGGLE_INSPECTION).setChecked(_enabled); updateListeners(); if (!doNotSave) { prefs.set(PREF_ENABLED, _enabled); prefs.save(); } // run immediately run(); }
[ "function", "toggleEnabled", "(", "enabled", ",", "doNotSave", ")", "{", "if", "(", "enabled", "===", "undefined", ")", "{", "enabled", "=", "!", "_enabled", ";", "}", "if", "(", "enabled", "===", "_enabled", ")", "{", "return", ";", "}", "_enabled", "=", "enabled", ";", "CommandManager", ".", "get", "(", "Commands", ".", "VIEW_TOGGLE_INSPECTION", ")", ".", "setChecked", "(", "_enabled", ")", ";", "updateListeners", "(", ")", ";", "if", "(", "!", "doNotSave", ")", "{", "prefs", ".", "set", "(", "PREF_ENABLED", ",", "_enabled", ")", ";", "prefs", ".", "save", "(", ")", ";", "}", "run", "(", ")", ";", "}" ]
Enable or disable all inspection. @param {?boolean} enabled Enabled state. If omitted, the state is toggled. @param {?boolean} doNotSave true if the preference should not be saved to user settings. This is generally for events triggered by project-level settings.
[ "Enable", "or", "disable", "all", "inspection", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/CodeInspection.js#L560-L581
train
adobe/brackets
src/editor/EditorCommandHandlers.js
_firstNotWs
function _firstNotWs(doc, lineNum) { var text = doc.getLine(lineNum); if (text === null || text === undefined) { return 0; } return text.search(/\S|$/); }
javascript
function _firstNotWs(doc, lineNum) { var text = doc.getLine(lineNum); if (text === null || text === undefined) { return 0; } return text.search(/\S|$/); }
[ "function", "_firstNotWs", "(", "doc", ",", "lineNum", ")", "{", "var", "text", "=", "doc", ".", "getLine", "(", "lineNum", ")", ";", "if", "(", "text", "===", "null", "||", "text", "===", "undefined", ")", "{", "return", "0", ";", "}", "return", "text", ".", "search", "(", "/", "\\S|$", "/", ")", ";", "}" ]
Return the column of the first non whitespace char in the given line. @private @param {!Document} doc @param {number} lineNum @returns {number} the column index or null
[ "Return", "the", "column", "of", "the", "first", "non", "whitespace", "char", "in", "the", "given", "line", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorCommandHandlers.js#L308-L315
train
adobe/brackets
src/extensions/default/InlineTimingFunctionEditor/main.js
prepareEditorForProvider
function prepareEditorForProvider(hostEditor, pos) { var cursorLine, sel, startPos, endPos, startBookmark, endBookmark, currentMatch, cm = hostEditor._codeMirror; sel = hostEditor.getSelection(); if (sel.start.line !== sel.end.line) { return {timingFunction: null, reason: null}; } cursorLine = hostEditor.document.getLine(pos.line); // code runs several matches complicated patterns, multiple times, so // first do a quick, simple check to see make sure we may have a match if (!cursorLine.match(/cubic-bezier|linear|ease|step/)) { return {timingFunction: null, reason: null}; } currentMatch = TimingFunctionUtils.timingFunctionMatch(cursorLine, false); if (!currentMatch) { return {timingFunction: null, reason: Strings.ERROR_TIMINGQUICKEDIT_INVALIDSYNTAX}; } // check for subsequent matches, and use first match after pos var lineOffset = 0, matchLength = ((currentMatch.originalString && currentMatch.originalString.length) || currentMatch[0].length); while (pos.ch > (currentMatch.index + matchLength + lineOffset)) { var restOfLine = cursorLine.substring(currentMatch.index + matchLength + lineOffset), newMatch = TimingFunctionUtils.timingFunctionMatch(restOfLine, false); if (newMatch) { lineOffset += (currentMatch.index + matchLength); currentMatch = $.extend(true, [], newMatch); } else { break; } } currentMatch.lineOffset = lineOffset; startPos = {line: pos.line, ch: lineOffset + currentMatch.index}; endPos = {line: pos.line, ch: lineOffset + currentMatch.index + matchLength}; startBookmark = cm.setBookmark(startPos); endBookmark = cm.setBookmark(endPos); // Adjust selection to the match so that the inline editor won't // get dismissed while we're updating the timing function. hostEditor.setSelection(startPos, endPos); return { timingFunction: currentMatch, start: startBookmark, end: endBookmark }; }
javascript
function prepareEditorForProvider(hostEditor, pos) { var cursorLine, sel, startPos, endPos, startBookmark, endBookmark, currentMatch, cm = hostEditor._codeMirror; sel = hostEditor.getSelection(); if (sel.start.line !== sel.end.line) { return {timingFunction: null, reason: null}; } cursorLine = hostEditor.document.getLine(pos.line); // code runs several matches complicated patterns, multiple times, so // first do a quick, simple check to see make sure we may have a match if (!cursorLine.match(/cubic-bezier|linear|ease|step/)) { return {timingFunction: null, reason: null}; } currentMatch = TimingFunctionUtils.timingFunctionMatch(cursorLine, false); if (!currentMatch) { return {timingFunction: null, reason: Strings.ERROR_TIMINGQUICKEDIT_INVALIDSYNTAX}; } // check for subsequent matches, and use first match after pos var lineOffset = 0, matchLength = ((currentMatch.originalString && currentMatch.originalString.length) || currentMatch[0].length); while (pos.ch > (currentMatch.index + matchLength + lineOffset)) { var restOfLine = cursorLine.substring(currentMatch.index + matchLength + lineOffset), newMatch = TimingFunctionUtils.timingFunctionMatch(restOfLine, false); if (newMatch) { lineOffset += (currentMatch.index + matchLength); currentMatch = $.extend(true, [], newMatch); } else { break; } } currentMatch.lineOffset = lineOffset; startPos = {line: pos.line, ch: lineOffset + currentMatch.index}; endPos = {line: pos.line, ch: lineOffset + currentMatch.index + matchLength}; startBookmark = cm.setBookmark(startPos); endBookmark = cm.setBookmark(endPos); // Adjust selection to the match so that the inline editor won't // get dismissed while we're updating the timing function. hostEditor.setSelection(startPos, endPos); return { timingFunction: currentMatch, start: startBookmark, end: endBookmark }; }
[ "function", "prepareEditorForProvider", "(", "hostEditor", ",", "pos", ")", "{", "var", "cursorLine", ",", "sel", ",", "startPos", ",", "endPos", ",", "startBookmark", ",", "endBookmark", ",", "currentMatch", ",", "cm", "=", "hostEditor", ".", "_codeMirror", ";", "sel", "=", "hostEditor", ".", "getSelection", "(", ")", ";", "if", "(", "sel", ".", "start", ".", "line", "!==", "sel", ".", "end", ".", "line", ")", "{", "return", "{", "timingFunction", ":", "null", ",", "reason", ":", "null", "}", ";", "}", "cursorLine", "=", "hostEditor", ".", "document", ".", "getLine", "(", "pos", ".", "line", ")", ";", "if", "(", "!", "cursorLine", ".", "match", "(", "/", "cubic-bezier|linear|ease|step", "/", ")", ")", "{", "return", "{", "timingFunction", ":", "null", ",", "reason", ":", "null", "}", ";", "}", "currentMatch", "=", "TimingFunctionUtils", ".", "timingFunctionMatch", "(", "cursorLine", ",", "false", ")", ";", "if", "(", "!", "currentMatch", ")", "{", "return", "{", "timingFunction", ":", "null", ",", "reason", ":", "Strings", ".", "ERROR_TIMINGQUICKEDIT_INVALIDSYNTAX", "}", ";", "}", "var", "lineOffset", "=", "0", ",", "matchLength", "=", "(", "(", "currentMatch", ".", "originalString", "&&", "currentMatch", ".", "originalString", ".", "length", ")", "||", "currentMatch", "[", "0", "]", ".", "length", ")", ";", "while", "(", "pos", ".", "ch", ">", "(", "currentMatch", ".", "index", "+", "matchLength", "+", "lineOffset", ")", ")", "{", "var", "restOfLine", "=", "cursorLine", ".", "substring", "(", "currentMatch", ".", "index", "+", "matchLength", "+", "lineOffset", ")", ",", "newMatch", "=", "TimingFunctionUtils", ".", "timingFunctionMatch", "(", "restOfLine", ",", "false", ")", ";", "if", "(", "newMatch", ")", "{", "lineOffset", "+=", "(", "currentMatch", ".", "index", "+", "matchLength", ")", ";", "currentMatch", "=", "$", ".", "extend", "(", "true", ",", "[", "]", ",", "newMatch", ")", ";", "}", "else", "{", "break", ";", "}", "}", "currentMatch", ".", "lineOffset", "=", "lineOffset", ";", "startPos", "=", "{", "line", ":", "pos", ".", "line", ",", "ch", ":", "lineOffset", "+", "currentMatch", ".", "index", "}", ";", "endPos", "=", "{", "line", ":", "pos", ".", "line", ",", "ch", ":", "lineOffset", "+", "currentMatch", ".", "index", "+", "matchLength", "}", ";", "startBookmark", "=", "cm", ".", "setBookmark", "(", "startPos", ")", ";", "endBookmark", "=", "cm", ".", "setBookmark", "(", "endPos", ")", ";", "hostEditor", ".", "setSelection", "(", "startPos", ",", "endPos", ")", ";", "return", "{", "timingFunction", ":", "currentMatch", ",", "start", ":", "startBookmark", ",", "end", ":", "endBookmark", "}", ";", "}" ]
Functions Prepare hostEditor for an InlineTimingFunctionEditor at pos if possible. Return editor context if so; otherwise null. @param {Editor} hostEditor @param {{line:Number, ch:Number}} pos @return {timingFunction:{?string}, reason:{?string}, start:{?TextMarker}, end:{?TextMarker}}
[ "Functions", "Prepare", "hostEditor", "for", "an", "InlineTimingFunctionEditor", "at", "pos", "if", "possible", ".", "Return", "editor", "context", "if", "so", ";", "otherwise", "null", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InlineTimingFunctionEditor/main.js#L68-L122
train
adobe/brackets
src/project/WorkingSetView.js
refresh
function refresh(rebuild) { _.forEach(_views, function (view) { var top = view.$openFilesContainer.scrollTop(); if (rebuild) { view._rebuildViewList(true); } else { view._redraw(); } view.$openFilesContainer.scrollTop(top); }); }
javascript
function refresh(rebuild) { _.forEach(_views, function (view) { var top = view.$openFilesContainer.scrollTop(); if (rebuild) { view._rebuildViewList(true); } else { view._redraw(); } view.$openFilesContainer.scrollTop(top); }); }
[ "function", "refresh", "(", "rebuild", ")", "{", "_", ".", "forEach", "(", "_views", ",", "function", "(", "view", ")", "{", "var", "top", "=", "view", ".", "$openFilesContainer", ".", "scrollTop", "(", ")", ";", "if", "(", "rebuild", ")", "{", "view", ".", "_rebuildViewList", "(", "true", ")", ";", "}", "else", "{", "view", ".", "_redraw", "(", ")", ";", "}", "view", ".", "$openFilesContainer", ".", "scrollTop", "(", "top", ")", ";", "}", ")", ";", "}" ]
Refreshes all Pane View List Views
[ "Refreshes", "all", "Pane", "View", "List", "Views" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L120-L130
train
adobe/brackets
src/project/WorkingSetView.js
_updateListItemSelection
function _updateListItemSelection(listItem, selectedFile) { var shouldBeSelected = (selectedFile && $(listItem).data(_FILE_KEY).fullPath === selectedFile.fullPath); ViewUtils.toggleClass($(listItem), "selected", shouldBeSelected); }
javascript
function _updateListItemSelection(listItem, selectedFile) { var shouldBeSelected = (selectedFile && $(listItem).data(_FILE_KEY).fullPath === selectedFile.fullPath); ViewUtils.toggleClass($(listItem), "selected", shouldBeSelected); }
[ "function", "_updateListItemSelection", "(", "listItem", ",", "selectedFile", ")", "{", "var", "shouldBeSelected", "=", "(", "selectedFile", "&&", "$", "(", "listItem", ")", ".", "data", "(", "_FILE_KEY", ")", ".", "fullPath", "===", "selectedFile", ".", "fullPath", ")", ";", "ViewUtils", ".", "toggleClass", "(", "$", "(", "listItem", ")", ",", "\"selected\"", ",", "shouldBeSelected", ")", ";", "}" ]
Updates the appearance of the list element based on the parameters provided. @private @param {!HTMLLIElement} listElement @param {?File} selectedFile
[ "Updates", "the", "appearance", "of", "the", "list", "element", "based", "on", "the", "parameters", "provided", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L147-L150
train
adobe/brackets
src/project/WorkingSetView.js
_isOpenAndDirty
function _isOpenAndDirty(file) { // working set item might never have been opened; if so, then it's definitely not dirty var docIfOpen = DocumentManager.getOpenDocumentForPath(file.fullPath); return (docIfOpen && docIfOpen.isDirty); }
javascript
function _isOpenAndDirty(file) { // working set item might never have been opened; if so, then it's definitely not dirty var docIfOpen = DocumentManager.getOpenDocumentForPath(file.fullPath); return (docIfOpen && docIfOpen.isDirty); }
[ "function", "_isOpenAndDirty", "(", "file", ")", "{", "var", "docIfOpen", "=", "DocumentManager", ".", "getOpenDocumentForPath", "(", "file", ".", "fullPath", ")", ";", "return", "(", "docIfOpen", "&&", "docIfOpen", ".", "isDirty", ")", ";", "}" ]
Determines if a file is dirty @private @param {!File} file - file to test @return {boolean} true if the file is dirty, false otherwise
[ "Determines", "if", "a", "file", "is", "dirty" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L158-L162
train
adobe/brackets
src/project/WorkingSetView.js
_suppressScrollShadowsOnAllViews
function _suppressScrollShadowsOnAllViews(disable) { _.forEach(_views, function (view) { if (disable) { ViewUtils.removeScrollerShadow(view.$openFilesContainer[0], null); } else if (view.$openFilesContainer[0].scrollHeight > view.$openFilesContainer[0].clientHeight) { ViewUtils.addScrollerShadow(view.$openFilesContainer[0], null, true); } }); }
javascript
function _suppressScrollShadowsOnAllViews(disable) { _.forEach(_views, function (view) { if (disable) { ViewUtils.removeScrollerShadow(view.$openFilesContainer[0], null); } else if (view.$openFilesContainer[0].scrollHeight > view.$openFilesContainer[0].clientHeight) { ViewUtils.addScrollerShadow(view.$openFilesContainer[0], null, true); } }); }
[ "function", "_suppressScrollShadowsOnAllViews", "(", "disable", ")", "{", "_", ".", "forEach", "(", "_views", ",", "function", "(", "view", ")", "{", "if", "(", "disable", ")", "{", "ViewUtils", ".", "removeScrollerShadow", "(", "view", ".", "$openFilesContainer", "[", "0", "]", ",", "null", ")", ";", "}", "else", "if", "(", "view", ".", "$openFilesContainer", "[", "0", "]", ".", "scrollHeight", ">", "view", ".", "$openFilesContainer", "[", "0", "]", ".", "clientHeight", ")", "{", "ViewUtils", ".", "addScrollerShadow", "(", "view", ".", "$openFilesContainer", "[", "0", "]", ",", "null", ",", "true", ")", ";", "}", "}", ")", ";", "}" ]
turns off the scroll shadow on view containers so they don't interfere with dragging @private @param {Boolean} disable - true to disable, false to enable
[ "turns", "off", "the", "scroll", "shadow", "on", "view", "containers", "so", "they", "don", "t", "interfere", "with", "dragging" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L188-L196
train
adobe/brackets
src/project/WorkingSetView.js
_deactivateAllViews
function _deactivateAllViews(deactivate) { _.forEach(_views, function (view) { if (deactivate) { if (view.$el.hasClass("active")) { view.$el.removeClass("active").addClass("reactivate"); view.$openFilesList.trigger("selectionHide"); } } else { if (view.$el.hasClass("reactivate")) { view.$el.removeClass("reactivate").addClass("active"); } // don't update the scroll pos view._fireSelectionChanged(false); } }); }
javascript
function _deactivateAllViews(deactivate) { _.forEach(_views, function (view) { if (deactivate) { if (view.$el.hasClass("active")) { view.$el.removeClass("active").addClass("reactivate"); view.$openFilesList.trigger("selectionHide"); } } else { if (view.$el.hasClass("reactivate")) { view.$el.removeClass("reactivate").addClass("active"); } // don't update the scroll pos view._fireSelectionChanged(false); } }); }
[ "function", "_deactivateAllViews", "(", "deactivate", ")", "{", "_", ".", "forEach", "(", "_views", ",", "function", "(", "view", ")", "{", "if", "(", "deactivate", ")", "{", "if", "(", "view", ".", "$el", ".", "hasClass", "(", "\"active\"", ")", ")", "{", "view", ".", "$el", ".", "removeClass", "(", "\"active\"", ")", ".", "addClass", "(", "\"reactivate\"", ")", ";", "view", ".", "$openFilesList", ".", "trigger", "(", "\"selectionHide\"", ")", ";", "}", "}", "else", "{", "if", "(", "view", ".", "$el", ".", "hasClass", "(", "\"reactivate\"", ")", ")", "{", "view", ".", "$el", ".", "removeClass", "(", "\"reactivate\"", ")", ".", "addClass", "(", "\"active\"", ")", ";", "}", "view", ".", "_fireSelectionChanged", "(", "false", ")", ";", "}", "}", ")", ";", "}" ]
Deactivates all views so the selection marker does not show @private @param {Boolean} deactivate - true to deactivate, false to reactivate
[ "Deactivates", "all", "views", "so", "the", "selection", "marker", "does", "not", "show" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L203-L218
train
adobe/brackets
src/project/WorkingSetView.js
_viewFromEl
function _viewFromEl($el) { if (!$el.hasClass("working-set-view")) { $el = $el.parents(".working-set-view"); } var id = $el.attr("id").match(/working\-set\-list\-([\w]+[\w\d\-\.\:\_]*)/).pop(); return _views[id]; }
javascript
function _viewFromEl($el) { if (!$el.hasClass("working-set-view")) { $el = $el.parents(".working-set-view"); } var id = $el.attr("id").match(/working\-set\-list\-([\w]+[\w\d\-\.\:\_]*)/).pop(); return _views[id]; }
[ "function", "_viewFromEl", "(", "$el", ")", "{", "if", "(", "!", "$el", ".", "hasClass", "(", "\"working-set-view\"", ")", ")", "{", "$el", "=", "$el", ".", "parents", "(", "\".working-set-view\"", ")", ";", "}", "var", "id", "=", "$el", ".", "attr", "(", "\"id\"", ")", ".", "match", "(", "/", "working\\-set\\-list\\-([\\w]+[\\w\\d\\-\\.\\:\\_]*)", "/", ")", ".", "pop", "(", ")", ";", "return", "_views", "[", "id", "]", ";", "}" ]
Finds the WorkingSetView object for the specified element @private @param {jQuery} $el - the element to find the view for @return {View} view object
[ "Finds", "the", "WorkingSetView", "object", "for", "the", "specified", "element" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L226-L233
train
adobe/brackets
src/project/WorkingSetView.js
scroll
function scroll($container, $el, dir, callback) { var container = $container[0], maxScroll = container.scrollHeight - container.clientHeight; if (maxScroll && dir && !interval) { // Scroll view if the mouse is over the first or last pixels of the container interval = window.setInterval(function () { var scrollTop = $container.scrollTop(); if ((dir === -1 && scrollTop <= 0) || (dir === 1 && scrollTop >= maxScroll)) { endScroll($el); } else { $container.scrollTop(scrollTop + 7 * dir); callback($el); } }, 50); } }
javascript
function scroll($container, $el, dir, callback) { var container = $container[0], maxScroll = container.scrollHeight - container.clientHeight; if (maxScroll && dir && !interval) { // Scroll view if the mouse is over the first or last pixels of the container interval = window.setInterval(function () { var scrollTop = $container.scrollTop(); if ((dir === -1 && scrollTop <= 0) || (dir === 1 && scrollTop >= maxScroll)) { endScroll($el); } else { $container.scrollTop(scrollTop + 7 * dir); callback($el); } }, 50); } }
[ "function", "scroll", "(", "$container", ",", "$el", ",", "dir", ",", "callback", ")", "{", "var", "container", "=", "$container", "[", "0", "]", ",", "maxScroll", "=", "container", ".", "scrollHeight", "-", "container", ".", "clientHeight", ";", "if", "(", "maxScroll", "&&", "dir", "&&", "!", "interval", ")", "{", "interval", "=", "window", ".", "setInterval", "(", "function", "(", ")", "{", "var", "scrollTop", "=", "$container", ".", "scrollTop", "(", ")", ";", "if", "(", "(", "dir", "===", "-", "1", "&&", "scrollTop", "<=", "0", ")", "||", "(", "dir", "===", "1", "&&", "scrollTop", ">=", "maxScroll", ")", ")", "{", "endScroll", "(", "$el", ")", ";", "}", "else", "{", "$container", ".", "scrollTop", "(", "scrollTop", "+", "7", "*", "dir", ")", ";", "callback", "(", "$el", ")", ";", "}", "}", ",", "50", ")", ";", "}", "}" ]
We scroll the list while hovering over the first or last visible list element in the working set, so that positioning a working set item before or after one that has been scrolled out of view can be performed. This function will call the drag interface repeatedly on an interval to allow the item to be dragged while scrolling the list until the mouse is moved off the first or last item or endScroll is called
[ "We", "scroll", "the", "list", "while", "hovering", "over", "the", "first", "or", "last", "visible", "list", "element", "in", "the", "working", "set", "so", "that", "positioning", "a", "working", "set", "item", "before", "or", "after", "one", "that", "has", "been", "scrolled", "out", "of", "view", "can", "be", "performed", ".", "This", "function", "will", "call", "the", "drag", "interface", "repeatedly", "on", "an", "interval", "to", "allow", "the", "item", "to", "be", "dragged", "while", "scrolling", "the", "list", "until", "the", "mouse", "is", "moved", "off", "the", "first", "or", "last", "item", "or", "endScroll", "is", "called" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L259-L274
train
adobe/brackets
src/project/WorkingSetView.js
preDropCleanup
function preDropCleanup() { window.onmousewheel = window.document.onmousewheel = null; $(window).off(".wsvdragging"); if (dragged) { $workingFilesContainer.removeClass("dragging"); $workingFilesContainer.find(".drag-show-as-selected").removeClass("drag-show-as-selected"); endScroll($el); // re-activate the views (adds the "active" class to the view that was previously active) _deactivateAllViews(false); // turn scroll wheel back on $ghost.remove(); $el.css("opacity", ""); if ($el.next().length === 0) { scrollCurrentViewToBottom(); } } }
javascript
function preDropCleanup() { window.onmousewheel = window.document.onmousewheel = null; $(window).off(".wsvdragging"); if (dragged) { $workingFilesContainer.removeClass("dragging"); $workingFilesContainer.find(".drag-show-as-selected").removeClass("drag-show-as-selected"); endScroll($el); // re-activate the views (adds the "active" class to the view that was previously active) _deactivateAllViews(false); // turn scroll wheel back on $ghost.remove(); $el.css("opacity", ""); if ($el.next().length === 0) { scrollCurrentViewToBottom(); } } }
[ "function", "preDropCleanup", "(", ")", "{", "window", ".", "onmousewheel", "=", "window", ".", "document", ".", "onmousewheel", "=", "null", ";", "$", "(", "window", ")", ".", "off", "(", "\".wsvdragging\"", ")", ";", "if", "(", "dragged", ")", "{", "$workingFilesContainer", ".", "removeClass", "(", "\"dragging\"", ")", ";", "$workingFilesContainer", ".", "find", "(", "\".drag-show-as-selected\"", ")", ".", "removeClass", "(", "\"drag-show-as-selected\"", ")", ";", "endScroll", "(", "$el", ")", ";", "_deactivateAllViews", "(", "false", ")", ";", "$ghost", ".", "remove", "(", ")", ";", "$el", ".", "css", "(", "\"opacity\"", ",", "\"\"", ")", ";", "if", "(", "$el", ".", "next", "(", ")", ".", "length", "===", "0", ")", "{", "scrollCurrentViewToBottom", "(", ")", ";", "}", "}", "}" ]
Close down the drag operation
[ "Close", "down", "the", "drag", "operation" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L722-L739
train
adobe/brackets
src/project/WorkingSetView.js
createWorkingSetViewForPane
function createWorkingSetViewForPane($container, paneId) { var view = _views[paneId]; if (!view) { view = new WorkingSetView($container, paneId); _views[view.paneId] = view; } }
javascript
function createWorkingSetViewForPane($container, paneId) { var view = _views[paneId]; if (!view) { view = new WorkingSetView($container, paneId); _views[view.paneId] = view; } }
[ "function", "createWorkingSetViewForPane", "(", "$container", ",", "paneId", ")", "{", "var", "view", "=", "_views", "[", "paneId", "]", ";", "if", "(", "!", "view", ")", "{", "view", "=", "new", "WorkingSetView", "(", "$container", ",", "paneId", ")", ";", "_views", "[", "view", ".", "paneId", "]", "=", "view", ";", "}", "}" ]
Creates a new WorkingSetView object for the specified pane @param {!jQuery} $container - the WorkingSetView's DOM parent node @param {!string} paneId - the id of the pane the view is being created for
[ "Creates", "a", "new", "WorkingSetView", "object", "for", "the", "specified", "pane" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetView.js#L1427-L1433
train
adobe/brackets
src/search/QuickOpen.js
_getPluginsForCurrentContext
function _getPluginsForCurrentContext() { var curDoc = DocumentManager.getCurrentDocument(); if (curDoc) { var languageId = curDoc.getLanguage().getId(); return _providerRegistrationHandler.getProvidersForLanguageId(languageId); } return _providerRegistrationHandler.getProvidersForLanguageId(); //plugins registered for all }
javascript
function _getPluginsForCurrentContext() { var curDoc = DocumentManager.getCurrentDocument(); if (curDoc) { var languageId = curDoc.getLanguage().getId(); return _providerRegistrationHandler.getProvidersForLanguageId(languageId); } return _providerRegistrationHandler.getProvidersForLanguageId(); //plugins registered for all }
[ "function", "_getPluginsForCurrentContext", "(", ")", "{", "var", "curDoc", "=", "DocumentManager", ".", "getCurrentDocument", "(", ")", ";", "if", "(", "curDoc", ")", "{", "var", "languageId", "=", "curDoc", ".", "getLanguage", "(", ")", ".", "getId", "(", ")", ";", "return", "_providerRegistrationHandler", ".", "getProvidersForLanguageId", "(", "languageId", ")", ";", "}", "return", "_providerRegistrationHandler", ".", "getProvidersForLanguageId", "(", ")", ";", "}" ]
Helper function to get the plugins based on the type of the current document. @private @returns {Array} Returns the plugings based on the languageId of the current document.
[ "Helper", "function", "to", "get", "the", "plugins", "based", "on", "the", "type", "of", "the", "current", "document", "." ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/QuickOpen.js#L111-L120
train
adobe/brackets
src/search/QuickOpen.js
QuickOpenPlugin
function QuickOpenPlugin(name, languageIds, done, search, match, itemFocus, itemSelect, resultsFormatter, matcherOptions, label) { this.name = name; this.languageIds = languageIds; this.done = done; this.search = search; this.match = match; this.itemFocus = itemFocus; this.itemSelect = itemSelect; this.resultsFormatter = resultsFormatter; this.matcherOptions = matcherOptions; this.label = label; }
javascript
function QuickOpenPlugin(name, languageIds, done, search, match, itemFocus, itemSelect, resultsFormatter, matcherOptions, label) { this.name = name; this.languageIds = languageIds; this.done = done; this.search = search; this.match = match; this.itemFocus = itemFocus; this.itemSelect = itemSelect; this.resultsFormatter = resultsFormatter; this.matcherOptions = matcherOptions; this.label = label; }
[ "function", "QuickOpenPlugin", "(", "name", ",", "languageIds", ",", "done", ",", "search", ",", "match", ",", "itemFocus", ",", "itemSelect", ",", "resultsFormatter", ",", "matcherOptions", ",", "label", ")", "{", "this", ".", "name", "=", "name", ";", "this", ".", "languageIds", "=", "languageIds", ";", "this", ".", "done", "=", "done", ";", "this", ".", "search", "=", "search", ";", "this", ".", "match", "=", "match", ";", "this", ".", "itemFocus", "=", "itemFocus", ";", "this", ".", "itemSelect", "=", "itemSelect", ";", "this", ".", "resultsFormatter", "=", "resultsFormatter", ";", "this", ".", "matcherOptions", "=", "matcherOptions", ";", "this", ".", "label", "=", "label", ";", "}" ]
Defines API for new QuickOpen plug-ins
[ "Defines", "API", "for", "new", "QuickOpen", "plug", "-", "ins" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/QuickOpen.js#L125-L136
train
adobe/brackets
src/search/QuickOpen.js
addQuickOpenPlugin
function addQuickOpenPlugin(pluginDef) { var quickOpenProvider = new QuickOpenPlugin( pluginDef.name, pluginDef.languageIds, pluginDef.done, pluginDef.search, pluginDef.match, pluginDef.itemFocus, pluginDef.itemSelect, pluginDef.resultsFormatter, pluginDef.matcherOptions, pluginDef.label ), providerLanguageIds = pluginDef.languageIds.length ? pluginDef.languageIds : ["all"], providerPriority = pluginDef.priority || 0; _registerQuickOpenProvider(quickOpenProvider, providerLanguageIds, providerPriority); }
javascript
function addQuickOpenPlugin(pluginDef) { var quickOpenProvider = new QuickOpenPlugin( pluginDef.name, pluginDef.languageIds, pluginDef.done, pluginDef.search, pluginDef.match, pluginDef.itemFocus, pluginDef.itemSelect, pluginDef.resultsFormatter, pluginDef.matcherOptions, pluginDef.label ), providerLanguageIds = pluginDef.languageIds.length ? pluginDef.languageIds : ["all"], providerPriority = pluginDef.priority || 0; _registerQuickOpenProvider(quickOpenProvider, providerLanguageIds, providerPriority); }
[ "function", "addQuickOpenPlugin", "(", "pluginDef", ")", "{", "var", "quickOpenProvider", "=", "new", "QuickOpenPlugin", "(", "pluginDef", ".", "name", ",", "pluginDef", ".", "languageIds", ",", "pluginDef", ".", "done", ",", "pluginDef", ".", "search", ",", "pluginDef", ".", "match", ",", "pluginDef", ".", "itemFocus", ",", "pluginDef", ".", "itemSelect", ",", "pluginDef", ".", "resultsFormatter", ",", "pluginDef", ".", "matcherOptions", ",", "pluginDef", ".", "label", ")", ",", "providerLanguageIds", "=", "pluginDef", ".", "languageIds", ".", "length", "?", "pluginDef", ".", "languageIds", ":", "[", "\"all\"", "]", ",", "providerPriority", "=", "pluginDef", ".", "priority", "||", "0", ";", "_registerQuickOpenProvider", "(", "quickOpenProvider", ",", "providerLanguageIds", ",", "providerPriority", ")", ";", "}" ]
Creates and registers a new QuickOpenPlugin @param { name: string, languageIds: !Array.<string>, done: ?function(), search: function(string, !StringMatch.StringMatcher):(!Array.<SearchResult|string>|$.Promise), match: function(string):boolean, itemFocus: ?function(?SearchResult|string, string, boolean), itemSelect: function(?SearchResult|string, string), resultsFormatter: ?function(SearchResult|string, string):string, matcherOptions: ?Object, label: ?string } pluginDef Parameter Documentation: name - plug-in name, **must be unique** languageIds - language Ids array. Example: ["javascript", "css", "html"]. To allow any language, pass []. Required. done - called when quick open is complete. Plug-in should clear its internal state. Optional. search - takes a query string and a StringMatcher (the use of which is optional but can speed up your searches) and returns an array of strings or result objects that match the query; or a Promise that resolves to such an array. Required. match - takes a query string and returns true if this plug-in wants to provide results for this query. Required. itemFocus - performs an action when a result has been highlighted (via arrow keys, or by becoming top of the list). Passed the highlighted search result item (as returned by search()), the current query string, and a flag that is true if the item was highlighted explicitly (arrow keys), not implicitly (at top of list after last search()). Optional. itemSelect - performs an action when a result is chosen. Passed the highlighted search result item (as returned by search()), and the current query string. Required. resultsFormatter - takes a query string and an item string and returns a <LI> item to insert into the displayed search results. Optional. matcherOptions - options to pass along to the StringMatcher (see StringMatch.StringMatcher for available options). Optional. label - if provided, the label to show before the query field. Optional. If itemFocus() makes changes to the current document or cursor/scroll position and then the user cancels Quick Open (via Esc), those changes are automatically reverted.
[ "Creates", "and", "registers", "a", "new", "QuickOpenPlugin" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/QuickOpen.js#L176-L193
train
adobe/brackets
src/search/QuickOpen.js
_filter
function _filter(file) { return !LanguageManager.getLanguageForPath(file.fullPath).isBinary() || MainViewFactory.findSuitableFactoryForPath(file.fullPath); }
javascript
function _filter(file) { return !LanguageManager.getLanguageForPath(file.fullPath).isBinary() || MainViewFactory.findSuitableFactoryForPath(file.fullPath); }
[ "function", "_filter", "(", "file", ")", "{", "return", "!", "LanguageManager", ".", "getLanguageForPath", "(", "file", ".", "fullPath", ")", ".", "isBinary", "(", ")", "||", "MainViewFactory", ".", "findSuitableFactoryForPath", "(", "file", ".", "fullPath", ")", ";", "}" ]
Return files that are non-binary, or binary files that have a custom viewer
[ "Return", "files", "that", "are", "non", "-", "binary", "or", "binary", "files", "that", "have", "a", "custom", "viewer" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/search/QuickOpen.js#L708-L711
train
adobe/brackets
src/JSUtils/node/TernNodeDomain.js
handleGetFile
function handleGetFile(file, text) { var next = fileCallBacks[file]; if (next) { try { next(null, text); } catch (e) { _reportError(e, file); } } delete fileCallBacks[file]; }
javascript
function handleGetFile(file, text) { var next = fileCallBacks[file]; if (next) { try { next(null, text); } catch (e) { _reportError(e, file); } } delete fileCallBacks[file]; }
[ "function", "handleGetFile", "(", "file", ",", "text", ")", "{", "var", "next", "=", "fileCallBacks", "[", "file", "]", ";", "if", "(", "next", ")", "{", "try", "{", "next", "(", "null", ",", "text", ")", ";", "}", "catch", "(", "e", ")", "{", "_reportError", "(", "e", ",", "file", ")", ";", "}", "}", "delete", "fileCallBacks", "[", "file", "]", ";", "}" ]
Handle a response from the main thread providing the contents of a file @param {string} file - the name of the file @param {string} text - the contents of the file
[ "Handle", "a", "response", "from", "the", "main", "thread", "providing", "the", "contents", "of", "a", "file" ]
d5d00d43602c438266d32b8eda8f8a3ca937b524
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L90-L100
train