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/JSUtils/node/TernNodeDomain.js
|
getFile
|
function getFile(name, next) {
// save the callback
fileCallBacks[name] = next;
setImmediate(function () {
try {
ExtractContent.extractContent(name, handleGetFile, _requestFileContent);
} catch (error) {
console.log(error);
}
});
}
|
javascript
|
function getFile(name, next) {
// save the callback
fileCallBacks[name] = next;
setImmediate(function () {
try {
ExtractContent.extractContent(name, handleGetFile, _requestFileContent);
} catch (error) {
console.log(error);
}
});
}
|
[
"function",
"getFile",
"(",
"name",
",",
"next",
")",
"{",
"fileCallBacks",
"[",
"name",
"]",
"=",
"next",
";",
"setImmediate",
"(",
"function",
"(",
")",
"{",
"try",
"{",
"ExtractContent",
".",
"extractContent",
"(",
"name",
",",
"handleGetFile",
",",
"_requestFileContent",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"error",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Provide the contents of the requested file to tern
@param {string} name - the name of the file
@param {Function} next - the function to call with the text of the file
once it has been read in.
|
[
"Provide",
"the",
"contents",
"of",
"the",
"requested",
"file",
"to",
"tern"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L133-L144
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
resetTernServer
|
function resetTernServer() {
// If a server is already created just reset the analysis data
if (ternServer) {
ternServer.reset();
Infer.resetGuessing();
// tell the main thread we're ready to start processing again
self.postMessage({type: MessageIds.TERN_WORKER_READY});
}
}
|
javascript
|
function resetTernServer() {
// If a server is already created just reset the analysis data
if (ternServer) {
ternServer.reset();
Infer.resetGuessing();
// tell the main thread we're ready to start processing again
self.postMessage({type: MessageIds.TERN_WORKER_READY});
}
}
|
[
"function",
"resetTernServer",
"(",
")",
"{",
"if",
"(",
"ternServer",
")",
"{",
"ternServer",
".",
"reset",
"(",
")",
";",
"Infer",
".",
"resetGuessing",
"(",
")",
";",
"self",
".",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_WORKER_READY",
"}",
")",
";",
"}",
"}"
] |
Resets an existing tern server.
|
[
"Resets",
"an",
"existing",
"tern",
"server",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L179-L187
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
buildRequest
|
function buildRequest(fileInfo, query, offset) {
query = {type: query};
query.start = offset;
query.end = offset;
query.file = (fileInfo.type === MessageIds.TERN_FILE_INFO_TYPE_PART) ? "#0" : fileInfo.name;
query.filter = false;
query.sort = false;
query.depths = true;
query.guess = true;
query.origins = true;
query.types = true;
query.expandWordForward = false;
query.lineCharPositions = true;
query.docs = true;
query.urls = true;
var request = {query: query, files: [], offset: offset, timeout: inferenceTimeout};
if (fileInfo.type !== MessageIds.TERN_FILE_INFO_TYPE_EMPTY) {
// Create a copy to mutate ahead
var fileInfoCopy = JSON.parse(JSON.stringify(fileInfo));
request.files.push(fileInfoCopy);
}
return request;
}
|
javascript
|
function buildRequest(fileInfo, query, offset) {
query = {type: query};
query.start = offset;
query.end = offset;
query.file = (fileInfo.type === MessageIds.TERN_FILE_INFO_TYPE_PART) ? "#0" : fileInfo.name;
query.filter = false;
query.sort = false;
query.depths = true;
query.guess = true;
query.origins = true;
query.types = true;
query.expandWordForward = false;
query.lineCharPositions = true;
query.docs = true;
query.urls = true;
var request = {query: query, files: [], offset: offset, timeout: inferenceTimeout};
if (fileInfo.type !== MessageIds.TERN_FILE_INFO_TYPE_EMPTY) {
// Create a copy to mutate ahead
var fileInfoCopy = JSON.parse(JSON.stringify(fileInfo));
request.files.push(fileInfoCopy);
}
return request;
}
|
[
"function",
"buildRequest",
"(",
"fileInfo",
",",
"query",
",",
"offset",
")",
"{",
"query",
"=",
"{",
"type",
":",
"query",
"}",
";",
"query",
".",
"start",
"=",
"offset",
";",
"query",
".",
"end",
"=",
"offset",
";",
"query",
".",
"file",
"=",
"(",
"fileInfo",
".",
"type",
"===",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_PART",
")",
"?",
"\"#0\"",
":",
"fileInfo",
".",
"name",
";",
"query",
".",
"filter",
"=",
"false",
";",
"query",
".",
"sort",
"=",
"false",
";",
"query",
".",
"depths",
"=",
"true",
";",
"query",
".",
"guess",
"=",
"true",
";",
"query",
".",
"origins",
"=",
"true",
";",
"query",
".",
"types",
"=",
"true",
";",
"query",
".",
"expandWordForward",
"=",
"false",
";",
"query",
".",
"lineCharPositions",
"=",
"true",
";",
"query",
".",
"docs",
"=",
"true",
";",
"query",
".",
"urls",
"=",
"true",
";",
"var",
"request",
"=",
"{",
"query",
":",
"query",
",",
"files",
":",
"[",
"]",
",",
"offset",
":",
"offset",
",",
"timeout",
":",
"inferenceTimeout",
"}",
";",
"if",
"(",
"fileInfo",
".",
"type",
"!==",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_EMPTY",
")",
"{",
"var",
"fileInfoCopy",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"fileInfo",
")",
")",
";",
"request",
".",
"files",
".",
"push",
"(",
"fileInfoCopy",
")",
";",
"}",
"return",
"request",
";",
"}"
] |
Build an object that can be used as a request to tern.
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {string} query - the type of request being made
@param {{line: number, ch: number}} offset -
|
[
"Build",
"an",
"object",
"that",
"can",
"be",
"used",
"as",
"a",
"request",
"to",
"tern",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L215-L239
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
getRefs
|
function getRefs(fileInfo, offset) {
var request = buildRequest(fileInfo, "refs", offset);
try {
ternServer.request(request, function (error, data) {
if (error) {
_log("Error returned from Tern 'refs' request: " + error);
var response = {
type: MessageIds.TERN_REFS,
error: error.message
};
self.postMessage(response);
return;
}
var response = {
type: MessageIds.TERN_REFS,
file: fileInfo.name,
offset: offset,
references: data
};
// Post a message back to the main thread with the results
self.postMessage(response);
});
} catch (e) {
_reportError(e, fileInfo.name);
}
}
|
javascript
|
function getRefs(fileInfo, offset) {
var request = buildRequest(fileInfo, "refs", offset);
try {
ternServer.request(request, function (error, data) {
if (error) {
_log("Error returned from Tern 'refs' request: " + error);
var response = {
type: MessageIds.TERN_REFS,
error: error.message
};
self.postMessage(response);
return;
}
var response = {
type: MessageIds.TERN_REFS,
file: fileInfo.name,
offset: offset,
references: data
};
// Post a message back to the main thread with the results
self.postMessage(response);
});
} catch (e) {
_reportError(e, fileInfo.name);
}
}
|
[
"function",
"getRefs",
"(",
"fileInfo",
",",
"offset",
")",
"{",
"var",
"request",
"=",
"buildRequest",
"(",
"fileInfo",
",",
"\"refs\"",
",",
"offset",
")",
";",
"try",
"{",
"ternServer",
".",
"request",
"(",
"request",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"if",
"(",
"error",
")",
"{",
"_log",
"(",
"\"Error returned from Tern 'refs' request: \"",
"+",
"error",
")",
";",
"var",
"response",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_REFS",
",",
"error",
":",
"error",
".",
"message",
"}",
";",
"self",
".",
"postMessage",
"(",
"response",
")",
";",
"return",
";",
"}",
"var",
"response",
"=",
"{",
"type",
":",
"MessageIds",
".",
"TERN_REFS",
",",
"file",
":",
"fileInfo",
".",
"name",
",",
"offset",
":",
"offset",
",",
"references",
":",
"data",
"}",
";",
"self",
".",
"postMessage",
"(",
"response",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"_reportError",
"(",
"e",
",",
"fileInfo",
".",
"name",
")",
";",
"}",
"}"
] |
Get all References location
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}} offset - the offset into the
file for cursor
|
[
"Get",
"all",
"References",
"location"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L252-L277
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
getScopeData
|
function getScopeData(fileInfo, offset) {
// Create a new tern Server
// Existing tern server resolves all the required modules which might take time
// We only need to analyze single file for getting the scope
ternOptions.plugins = {};
var ternServer = new Tern.Server(ternOptions);
ternServer.addFile(fileInfo.name, fileInfo.text);
var error;
var request = buildRequest(fileInfo, "completions", offset); // for primepump
try {
// primepump
ternServer.request(request, function (ternError, data) {
if (ternError) {
_log("Error for Tern request: \n" + JSON.stringify(request) + "\n" + ternError);
error = ternError.toString();
} else {
var file = ternServer.findFile(fileInfo.name);
var scope = Infer.scopeAt(file.ast, Tern.resolvePos(file, offset), file.scope);
if (scope) {
// Remove unwanted properties to remove cycles in the object
scope = JSON.parse(JSON.stringify(scope, function(key, value) {
if (["proto", "propertyOf", "onNewProp", "sourceFile", "maybeProps"].includes(key)) {
return undefined;
}
else if (key === "fnType") {
return value.name || "FunctionExpression";
}
else if (key === "props") {
for (var key in value) {
value[key] = value[key].propertyName;
}
return value;
} else if (key === "originNode") {
return value && {
start: value.start,
end: value.end,
type: value.type,
body: {
start: value.body.start,
end: value.body.end
}
};
}
return value;
}));
}
self.postMessage({
type: MessageIds.TERN_SCOPEDATA_MSG,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
scope: scope
});
}
});
} catch (e) {
_reportError(e, fileInfo.name);
} finally {
ternServer.reset();
Infer.resetGuessing();
}
}
|
javascript
|
function getScopeData(fileInfo, offset) {
// Create a new tern Server
// Existing tern server resolves all the required modules which might take time
// We only need to analyze single file for getting the scope
ternOptions.plugins = {};
var ternServer = new Tern.Server(ternOptions);
ternServer.addFile(fileInfo.name, fileInfo.text);
var error;
var request = buildRequest(fileInfo, "completions", offset); // for primepump
try {
// primepump
ternServer.request(request, function (ternError, data) {
if (ternError) {
_log("Error for Tern request: \n" + JSON.stringify(request) + "\n" + ternError);
error = ternError.toString();
} else {
var file = ternServer.findFile(fileInfo.name);
var scope = Infer.scopeAt(file.ast, Tern.resolvePos(file, offset), file.scope);
if (scope) {
// Remove unwanted properties to remove cycles in the object
scope = JSON.parse(JSON.stringify(scope, function(key, value) {
if (["proto", "propertyOf", "onNewProp", "sourceFile", "maybeProps"].includes(key)) {
return undefined;
}
else if (key === "fnType") {
return value.name || "FunctionExpression";
}
else if (key === "props") {
for (var key in value) {
value[key] = value[key].propertyName;
}
return value;
} else if (key === "originNode") {
return value && {
start: value.start,
end: value.end,
type: value.type,
body: {
start: value.body.start,
end: value.body.end
}
};
}
return value;
}));
}
self.postMessage({
type: MessageIds.TERN_SCOPEDATA_MSG,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
scope: scope
});
}
});
} catch (e) {
_reportError(e, fileInfo.name);
} finally {
ternServer.reset();
Infer.resetGuessing();
}
}
|
[
"function",
"getScopeData",
"(",
"fileInfo",
",",
"offset",
")",
"{",
"ternOptions",
".",
"plugins",
"=",
"{",
"}",
";",
"var",
"ternServer",
"=",
"new",
"Tern",
".",
"Server",
"(",
"ternOptions",
")",
";",
"ternServer",
".",
"addFile",
"(",
"fileInfo",
".",
"name",
",",
"fileInfo",
".",
"text",
")",
";",
"var",
"error",
";",
"var",
"request",
"=",
"buildRequest",
"(",
"fileInfo",
",",
"\"completions\"",
",",
"offset",
")",
";",
"try",
"{",
"ternServer",
".",
"request",
"(",
"request",
",",
"function",
"(",
"ternError",
",",
"data",
")",
"{",
"if",
"(",
"ternError",
")",
"{",
"_log",
"(",
"\"Error for Tern request: \\n\"",
"+",
"\\n",
"+",
"JSON",
".",
"stringify",
"(",
"request",
")",
"+",
"\"\\n\"",
")",
";",
"\\n",
"}",
"else",
"ternError",
"}",
")",
";",
"}",
"error",
"=",
"ternError",
".",
"toString",
"(",
")",
";",
"{",
"var",
"file",
"=",
"ternServer",
".",
"findFile",
"(",
"fileInfo",
".",
"name",
")",
";",
"var",
"scope",
"=",
"Infer",
".",
"scopeAt",
"(",
"file",
".",
"ast",
",",
"Tern",
".",
"resolvePos",
"(",
"file",
",",
"offset",
")",
",",
"file",
".",
"scope",
")",
";",
"if",
"(",
"scope",
")",
"{",
"scope",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"scope",
",",
"function",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"[",
"\"proto\"",
",",
"\"propertyOf\"",
",",
"\"onNewProp\"",
",",
"\"sourceFile\"",
",",
"\"maybeProps\"",
"]",
".",
"includes",
"(",
"key",
")",
")",
"{",
"return",
"undefined",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"\"fnType\"",
")",
"{",
"return",
"value",
".",
"name",
"||",
"\"FunctionExpression\"",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"\"props\"",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"value",
")",
"{",
"value",
"[",
"key",
"]",
"=",
"value",
"[",
"key",
"]",
".",
"propertyName",
";",
"}",
"return",
"value",
";",
"}",
"else",
"if",
"(",
"key",
"===",
"\"originNode\"",
")",
"{",
"return",
"value",
"&&",
"{",
"start",
":",
"value",
".",
"start",
",",
"end",
":",
"value",
".",
"end",
",",
"type",
":",
"value",
".",
"type",
",",
"body",
":",
"{",
"start",
":",
"value",
".",
"body",
".",
"start",
",",
"end",
":",
"value",
".",
"body",
".",
"end",
"}",
"}",
";",
"}",
"return",
"value",
";",
"}",
")",
")",
";",
"}",
"self",
".",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_SCOPEDATA_MSG",
",",
"file",
":",
"_getNormalizedFilename",
"(",
"fileInfo",
".",
"name",
")",
",",
"offset",
":",
"offset",
",",
"scope",
":",
"scope",
"}",
")",
";",
"}",
"}"
] |
Get scope at the offset in the file
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}} offset - the offset into the
file for cursor
|
[
"Get",
"scope",
"at",
"the",
"offset",
"in",
"the",
"file"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L289-L354
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
getTernProperties
|
function getTernProperties(fileInfo, offset, type) {
var request = buildRequest(fileInfo, "properties", offset),
i;
//_log("tern properties: request " + request.type + dir + " " + file);
try {
ternServer.request(request, function (error, data) {
var properties = [];
if (error) {
_log("Error returned from Tern 'properties' request: " + error);
} else {
//_log("tern properties: completions = " + data.completions.length);
properties = data.completions.map(function (completion) {
return {value: completion, type: completion.type, guess: true};
});
}
// Post a message back to the main thread with the completions
self.postMessage({type: type,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
properties: properties
});
});
} catch (e) {
_reportError(e, fileInfo.name);
}
}
|
javascript
|
function getTernProperties(fileInfo, offset, type) {
var request = buildRequest(fileInfo, "properties", offset),
i;
//_log("tern properties: request " + request.type + dir + " " + file);
try {
ternServer.request(request, function (error, data) {
var properties = [];
if (error) {
_log("Error returned from Tern 'properties' request: " + error);
} else {
//_log("tern properties: completions = " + data.completions.length);
properties = data.completions.map(function (completion) {
return {value: completion, type: completion.type, guess: true};
});
}
// Post a message back to the main thread with the completions
self.postMessage({type: type,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
properties: properties
});
});
} catch (e) {
_reportError(e, fileInfo.name);
}
}
|
[
"function",
"getTernProperties",
"(",
"fileInfo",
",",
"offset",
",",
"type",
")",
"{",
"var",
"request",
"=",
"buildRequest",
"(",
"fileInfo",
",",
"\"properties\"",
",",
"offset",
")",
",",
"i",
";",
"try",
"{",
"ternServer",
".",
"request",
"(",
"request",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"var",
"properties",
"=",
"[",
"]",
";",
"if",
"(",
"error",
")",
"{",
"_log",
"(",
"\"Error returned from Tern 'properties' request: \"",
"+",
"error",
")",
";",
"}",
"else",
"{",
"properties",
"=",
"data",
".",
"completions",
".",
"map",
"(",
"function",
"(",
"completion",
")",
"{",
"return",
"{",
"value",
":",
"completion",
",",
"type",
":",
"completion",
".",
"type",
",",
"guess",
":",
"true",
"}",
";",
"}",
")",
";",
"}",
"self",
".",
"postMessage",
"(",
"{",
"type",
":",
"type",
",",
"file",
":",
"_getNormalizedFilename",
"(",
"fileInfo",
".",
"name",
")",
",",
"offset",
":",
"offset",
",",
"properties",
":",
"properties",
"}",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"_reportError",
"(",
"e",
",",
"fileInfo",
".",
"name",
")",
";",
"}",
"}"
] |
Get all the known properties for guessing.
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}} offset -
the offset into the file where we want completions for
@param {string} type - the type of the message to reply with.
|
[
"Get",
"all",
"the",
"known",
"properties",
"for",
"guessing",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L416-L442
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
getTernHints
|
function getTernHints(fileInfo, offset, isProperty) {
var request = buildRequest(fileInfo, "completions", offset),
i;
//_log("request " + dir + " " + file + " " + offset /*+ " " + text */);
try {
ternServer.request(request, function (error, data) {
var completions = [];
if (error) {
_log("Error returned from Tern 'completions' request: " + error);
} else {
//_log("found " + data.completions + " for " + file + "@" + offset);
completions = data.completions.map(function (completion) {
return {value: completion.name, type: completion.type, depth: completion.depth,
guess: completion.guess, origin: completion.origin, doc: completion.doc, url: completion.url};
});
}
if (completions.length > 0 || !isProperty) {
// Post a message back to the main thread with the completions
self.postMessage({type: MessageIds.TERN_COMPLETIONS_MSG,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
completions: completions
});
} else {
// if there are no completions, then get all the properties
getTernProperties(fileInfo, offset, MessageIds.TERN_COMPLETIONS_MSG);
}
});
} catch (e) {
_reportError(e, fileInfo.name);
}
}
|
javascript
|
function getTernHints(fileInfo, offset, isProperty) {
var request = buildRequest(fileInfo, "completions", offset),
i;
//_log("request " + dir + " " + file + " " + offset /*+ " " + text */);
try {
ternServer.request(request, function (error, data) {
var completions = [];
if (error) {
_log("Error returned from Tern 'completions' request: " + error);
} else {
//_log("found " + data.completions + " for " + file + "@" + offset);
completions = data.completions.map(function (completion) {
return {value: completion.name, type: completion.type, depth: completion.depth,
guess: completion.guess, origin: completion.origin, doc: completion.doc, url: completion.url};
});
}
if (completions.length > 0 || !isProperty) {
// Post a message back to the main thread with the completions
self.postMessage({type: MessageIds.TERN_COMPLETIONS_MSG,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
completions: completions
});
} else {
// if there are no completions, then get all the properties
getTernProperties(fileInfo, offset, MessageIds.TERN_COMPLETIONS_MSG);
}
});
} catch (e) {
_reportError(e, fileInfo.name);
}
}
|
[
"function",
"getTernHints",
"(",
"fileInfo",
",",
"offset",
",",
"isProperty",
")",
"{",
"var",
"request",
"=",
"buildRequest",
"(",
"fileInfo",
",",
"\"completions\"",
",",
"offset",
")",
",",
"i",
";",
"try",
"{",
"ternServer",
".",
"request",
"(",
"request",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"var",
"completions",
"=",
"[",
"]",
";",
"if",
"(",
"error",
")",
"{",
"_log",
"(",
"\"Error returned from Tern 'completions' request: \"",
"+",
"error",
")",
";",
"}",
"else",
"{",
"completions",
"=",
"data",
".",
"completions",
".",
"map",
"(",
"function",
"(",
"completion",
")",
"{",
"return",
"{",
"value",
":",
"completion",
".",
"name",
",",
"type",
":",
"completion",
".",
"type",
",",
"depth",
":",
"completion",
".",
"depth",
",",
"guess",
":",
"completion",
".",
"guess",
",",
"origin",
":",
"completion",
".",
"origin",
",",
"doc",
":",
"completion",
".",
"doc",
",",
"url",
":",
"completion",
".",
"url",
"}",
";",
"}",
")",
";",
"}",
"if",
"(",
"completions",
".",
"length",
">",
"0",
"||",
"!",
"isProperty",
")",
"{",
"self",
".",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_COMPLETIONS_MSG",
",",
"file",
":",
"_getNormalizedFilename",
"(",
"fileInfo",
".",
"name",
")",
",",
"offset",
":",
"offset",
",",
"completions",
":",
"completions",
"}",
")",
";",
"}",
"else",
"{",
"getTernProperties",
"(",
"fileInfo",
",",
"offset",
",",
"MessageIds",
".",
"TERN_COMPLETIONS_MSG",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"_reportError",
"(",
"e",
",",
"fileInfo",
".",
"name",
")",
";",
"}",
"}"
] |
Get the completions for the given offset
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}} offset -
the offset into the file where we want completions for
@param {boolean} isProperty - true if getting a property hint,
otherwise getting an identifier hint.
|
[
"Get",
"the",
"completions",
"for",
"the",
"given",
"offset"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L457-L489
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
inferArrTypeToString
|
function inferArrTypeToString(inferArrType) {
var result = "Array.<";
result += inferArrType.props["<i>"].types.map(inferTypeToString).join(", ");
// workaround case where types is zero length
if (inferArrType.props["<i>"].types.length === 0) {
result += "Object";
}
result += ">";
return result;
}
|
javascript
|
function inferArrTypeToString(inferArrType) {
var result = "Array.<";
result += inferArrType.props["<i>"].types.map(inferTypeToString).join(", ");
// workaround case where types is zero length
if (inferArrType.props["<i>"].types.length === 0) {
result += "Object";
}
result += ">";
return result;
}
|
[
"function",
"inferArrTypeToString",
"(",
"inferArrType",
")",
"{",
"var",
"result",
"=",
"\"Array.<\"",
";",
"result",
"+=",
"inferArrType",
".",
"props",
"[",
"\"<i>\"",
"]",
".",
"types",
".",
"map",
"(",
"inferTypeToString",
")",
".",
"join",
"(",
"\", \"",
")",
";",
"if",
"(",
"inferArrType",
".",
"props",
"[",
"\"<i>\"",
"]",
".",
"types",
".",
"length",
"===",
"0",
")",
"{",
"result",
"+=",
"\"Object\"",
";",
"}",
"result",
"+=",
"\">\"",
";",
"return",
"result",
";",
"}"
] |
Convert an infer array type to a string.
Formatted using google closure style. For example:
"Array.<string, number>"
@param {Infer.Arr} inferArrType
@return {string} - array formatted in google closure style.
|
[
"Convert",
"an",
"infer",
"array",
"type",
"to",
"a",
"string",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L515-L527
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
handleFunctionType
|
function handleFunctionType(fileInfo, offset) {
var request = buildRequest(fileInfo, "type", offset),
error;
request.query.preferFunction = true;
var fnType = "";
try {
ternServer.request(request, function (ternError, data) {
if (ternError) {
_log("Error for Tern request: \n" + JSON.stringify(request) + "\n" + ternError);
error = ternError.toString();
} else {
var file = ternServer.findFile(fileInfo.name);
// convert query from partial to full offsets
var newOffset = offset;
if (fileInfo.type === MessageIds.TERN_FILE_INFO_TYPE_PART) {
newOffset = {line: offset.line + fileInfo.offsetLines, ch: offset.ch};
}
request = buildRequest(createEmptyUpdate(fileInfo.name), "type", newOffset);
var expr = Tern.findQueryExpr(file, request.query);
Infer.resetGuessing();
var type = Infer.expressionType(expr);
type = type.getFunctionType() || type.getType();
if (type) {
fnType = getParameters(type);
} else {
ternError = "No parameter type found";
_log(ternError);
}
}
});
} catch (e) {
_reportError(e, fileInfo.name);
}
// Post a message back to the main thread with the completions
self.postMessage({type: MessageIds.TERN_CALLED_FUNC_TYPE_MSG,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
fnType: fnType,
error: error
});
}
|
javascript
|
function handleFunctionType(fileInfo, offset) {
var request = buildRequest(fileInfo, "type", offset),
error;
request.query.preferFunction = true;
var fnType = "";
try {
ternServer.request(request, function (ternError, data) {
if (ternError) {
_log("Error for Tern request: \n" + JSON.stringify(request) + "\n" + ternError);
error = ternError.toString();
} else {
var file = ternServer.findFile(fileInfo.name);
// convert query from partial to full offsets
var newOffset = offset;
if (fileInfo.type === MessageIds.TERN_FILE_INFO_TYPE_PART) {
newOffset = {line: offset.line + fileInfo.offsetLines, ch: offset.ch};
}
request = buildRequest(createEmptyUpdate(fileInfo.name), "type", newOffset);
var expr = Tern.findQueryExpr(file, request.query);
Infer.resetGuessing();
var type = Infer.expressionType(expr);
type = type.getFunctionType() || type.getType();
if (type) {
fnType = getParameters(type);
} else {
ternError = "No parameter type found";
_log(ternError);
}
}
});
} catch (e) {
_reportError(e, fileInfo.name);
}
// Post a message back to the main thread with the completions
self.postMessage({type: MessageIds.TERN_CALLED_FUNC_TYPE_MSG,
file: _getNormalizedFilename(fileInfo.name),
offset: offset,
fnType: fnType,
error: error
});
}
|
[
"function",
"handleFunctionType",
"(",
"fileInfo",
",",
"offset",
")",
"{",
"var",
"request",
"=",
"buildRequest",
"(",
"fileInfo",
",",
"\"type\"",
",",
"offset",
")",
",",
"error",
";",
"request",
".",
"query",
".",
"preferFunction",
"=",
"true",
";",
"var",
"fnType",
"=",
"\"\"",
";",
"try",
"{",
"ternServer",
".",
"request",
"(",
"request",
",",
"function",
"(",
"ternError",
",",
"data",
")",
"{",
"if",
"(",
"ternError",
")",
"{",
"_log",
"(",
"\"Error for Tern request: \\n\"",
"+",
"\\n",
"+",
"JSON",
".",
"stringify",
"(",
"request",
")",
"+",
"\"\\n\"",
")",
";",
"\\n",
"}",
"else",
"ternError",
"}",
")",
";",
"}",
"error",
"=",
"ternError",
".",
"toString",
"(",
")",
";",
"{",
"var",
"file",
"=",
"ternServer",
".",
"findFile",
"(",
"fileInfo",
".",
"name",
")",
";",
"var",
"newOffset",
"=",
"offset",
";",
"if",
"(",
"fileInfo",
".",
"type",
"===",
"MessageIds",
".",
"TERN_FILE_INFO_TYPE_PART",
")",
"{",
"newOffset",
"=",
"{",
"line",
":",
"offset",
".",
"line",
"+",
"fileInfo",
".",
"offsetLines",
",",
"ch",
":",
"offset",
".",
"ch",
"}",
";",
"}",
"request",
"=",
"buildRequest",
"(",
"createEmptyUpdate",
"(",
"fileInfo",
".",
"name",
")",
",",
"\"type\"",
",",
"newOffset",
")",
";",
"var",
"expr",
"=",
"Tern",
".",
"findQueryExpr",
"(",
"file",
",",
"request",
".",
"query",
")",
";",
"Infer",
".",
"resetGuessing",
"(",
")",
";",
"var",
"type",
"=",
"Infer",
".",
"expressionType",
"(",
"expr",
")",
";",
"type",
"=",
"type",
".",
"getFunctionType",
"(",
")",
"||",
"type",
".",
"getType",
"(",
")",
";",
"if",
"(",
"type",
")",
"{",
"fnType",
"=",
"getParameters",
"(",
"type",
")",
";",
"}",
"else",
"{",
"ternError",
"=",
"\"No parameter type found\"",
";",
"_log",
"(",
"ternError",
")",
";",
"}",
"}",
"}"
] |
Get the function type for the given offset
@param {{type: string, name: string, offsetLines: number, text: string}} fileInfo
- type of update, name of file, and the text of the update.
For "full" updates, the whole text of the file is present. For "part" updates,
the changed portion of the text. For "empty" updates, the file has not been modified
and the text is empty.
@param {{line: number, ch: number}} offset -
the offset into the file where we want completions for
|
[
"Get",
"the",
"function",
"type",
"for",
"the",
"given",
"offset"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L728-L776
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
handleUpdateFile
|
function handleUpdateFile(path, text) {
ternServer.addFile(path, text);
self.postMessage({type: MessageIds.TERN_UPDATE_FILE_MSG,
path: path
});
// reset to get the best hints with the updated file.
ternServer.reset();
Infer.resetGuessing();
}
|
javascript
|
function handleUpdateFile(path, text) {
ternServer.addFile(path, text);
self.postMessage({type: MessageIds.TERN_UPDATE_FILE_MSG,
path: path
});
// reset to get the best hints with the updated file.
ternServer.reset();
Infer.resetGuessing();
}
|
[
"function",
"handleUpdateFile",
"(",
"path",
",",
"text",
")",
"{",
"ternServer",
".",
"addFile",
"(",
"path",
",",
"text",
")",
";",
"self",
".",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_UPDATE_FILE_MSG",
",",
"path",
":",
"path",
"}",
")",
";",
"ternServer",
".",
"reset",
"(",
")",
";",
"Infer",
".",
"resetGuessing",
"(",
")",
";",
"}"
] |
Update the context of a file in tern.
@param {string} path - full path of file.
@param {string} text - content of the file.
|
[
"Update",
"the",
"context",
"of",
"a",
"file",
"in",
"tern",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L796-L807
|
train
|
adobe/brackets
|
src/JSUtils/node/TernNodeDomain.js
|
handlePrimePump
|
function handlePrimePump(path) {
var fileName = _getDenormalizedFilename(path);
var fileInfo = createEmptyUpdate(fileName),
request = buildRequest(fileInfo, "completions", {line: 0, ch: 0});
try {
ternServer.request(request, function (error, data) {
// Post a message back to the main thread
self.postMessage({type: MessageIds.TERN_PRIME_PUMP_MSG,
path: _getNormalizedFilename(path)
});
});
} catch (e) {
_reportError(e, path);
}
}
|
javascript
|
function handlePrimePump(path) {
var fileName = _getDenormalizedFilename(path);
var fileInfo = createEmptyUpdate(fileName),
request = buildRequest(fileInfo, "completions", {line: 0, ch: 0});
try {
ternServer.request(request, function (error, data) {
// Post a message back to the main thread
self.postMessage({type: MessageIds.TERN_PRIME_PUMP_MSG,
path: _getNormalizedFilename(path)
});
});
} catch (e) {
_reportError(e, path);
}
}
|
[
"function",
"handlePrimePump",
"(",
"path",
")",
"{",
"var",
"fileName",
"=",
"_getDenormalizedFilename",
"(",
"path",
")",
";",
"var",
"fileInfo",
"=",
"createEmptyUpdate",
"(",
"fileName",
")",
",",
"request",
"=",
"buildRequest",
"(",
"fileInfo",
",",
"\"completions\"",
",",
"{",
"line",
":",
"0",
",",
"ch",
":",
"0",
"}",
")",
";",
"try",
"{",
"ternServer",
".",
"request",
"(",
"request",
",",
"function",
"(",
"error",
",",
"data",
")",
"{",
"self",
".",
"postMessage",
"(",
"{",
"type",
":",
"MessageIds",
".",
"TERN_PRIME_PUMP_MSG",
",",
"path",
":",
"_getNormalizedFilename",
"(",
"path",
")",
"}",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"_reportError",
"(",
"e",
",",
"path",
")",
";",
"}",
"}"
] |
Make a completions request to tern to force tern to resolve files
and create a fast first lookup for the user.
@param {string} path - the path of the file
|
[
"Make",
"a",
"completions",
"request",
"to",
"tern",
"to",
"force",
"tern",
"to",
"resolve",
"files",
"and",
"create",
"a",
"fast",
"first",
"lookup",
"for",
"the",
"user",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/TernNodeDomain.js#L814-L829
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
_updateScrollerShadow
|
function _updateScrollerShadow($displayElement, $scrollElement, $shadowTop, $shadowBottom, isPositionFixed) {
var offsetTop = 0,
scrollElement = $scrollElement.get(0),
scrollTop = scrollElement.scrollTop,
topShadowOffset = Math.min(scrollTop - SCROLL_SHADOW_HEIGHT, 0),
displayElementWidth = $displayElement.width();
if ($shadowTop) {
$shadowTop.css("background-position", "0px " + topShadowOffset + "px");
if (isPositionFixed) {
offsetTop = $displayElement.offset().top;
$shadowTop.css("top", offsetTop);
}
if (isPositionFixed) {
$shadowTop.css("width", displayElementWidth);
}
}
if ($shadowBottom) {
var clientHeight = scrollElement.clientHeight,
outerHeight = $displayElement.outerHeight(),
scrollHeight = scrollElement.scrollHeight,
bottomShadowOffset = SCROLL_SHADOW_HEIGHT; // outside of shadow div viewport
if (scrollHeight > clientHeight) {
bottomShadowOffset -= Math.min(SCROLL_SHADOW_HEIGHT, (scrollHeight - (scrollTop + clientHeight)));
}
$shadowBottom.css("background-position", "0px " + bottomShadowOffset + "px");
$shadowBottom.css("top", offsetTop + outerHeight - SCROLL_SHADOW_HEIGHT);
$shadowBottom.css("width", displayElementWidth);
}
}
|
javascript
|
function _updateScrollerShadow($displayElement, $scrollElement, $shadowTop, $shadowBottom, isPositionFixed) {
var offsetTop = 0,
scrollElement = $scrollElement.get(0),
scrollTop = scrollElement.scrollTop,
topShadowOffset = Math.min(scrollTop - SCROLL_SHADOW_HEIGHT, 0),
displayElementWidth = $displayElement.width();
if ($shadowTop) {
$shadowTop.css("background-position", "0px " + topShadowOffset + "px");
if (isPositionFixed) {
offsetTop = $displayElement.offset().top;
$shadowTop.css("top", offsetTop);
}
if (isPositionFixed) {
$shadowTop.css("width", displayElementWidth);
}
}
if ($shadowBottom) {
var clientHeight = scrollElement.clientHeight,
outerHeight = $displayElement.outerHeight(),
scrollHeight = scrollElement.scrollHeight,
bottomShadowOffset = SCROLL_SHADOW_HEIGHT; // outside of shadow div viewport
if (scrollHeight > clientHeight) {
bottomShadowOffset -= Math.min(SCROLL_SHADOW_HEIGHT, (scrollHeight - (scrollTop + clientHeight)));
}
$shadowBottom.css("background-position", "0px " + bottomShadowOffset + "px");
$shadowBottom.css("top", offsetTop + outerHeight - SCROLL_SHADOW_HEIGHT);
$shadowBottom.css("width", displayElementWidth);
}
}
|
[
"function",
"_updateScrollerShadow",
"(",
"$displayElement",
",",
"$scrollElement",
",",
"$shadowTop",
",",
"$shadowBottom",
",",
"isPositionFixed",
")",
"{",
"var",
"offsetTop",
"=",
"0",
",",
"scrollElement",
"=",
"$scrollElement",
".",
"get",
"(",
"0",
")",
",",
"scrollTop",
"=",
"scrollElement",
".",
"scrollTop",
",",
"topShadowOffset",
"=",
"Math",
".",
"min",
"(",
"scrollTop",
"-",
"SCROLL_SHADOW_HEIGHT",
",",
"0",
")",
",",
"displayElementWidth",
"=",
"$displayElement",
".",
"width",
"(",
")",
";",
"if",
"(",
"$shadowTop",
")",
"{",
"$shadowTop",
".",
"css",
"(",
"\"background-position\"",
",",
"\"0px \"",
"+",
"topShadowOffset",
"+",
"\"px\"",
")",
";",
"if",
"(",
"isPositionFixed",
")",
"{",
"offsetTop",
"=",
"$displayElement",
".",
"offset",
"(",
")",
".",
"top",
";",
"$shadowTop",
".",
"css",
"(",
"\"top\"",
",",
"offsetTop",
")",
";",
"}",
"if",
"(",
"isPositionFixed",
")",
"{",
"$shadowTop",
".",
"css",
"(",
"\"width\"",
",",
"displayElementWidth",
")",
";",
"}",
"}",
"if",
"(",
"$shadowBottom",
")",
"{",
"var",
"clientHeight",
"=",
"scrollElement",
".",
"clientHeight",
",",
"outerHeight",
"=",
"$displayElement",
".",
"outerHeight",
"(",
")",
",",
"scrollHeight",
"=",
"scrollElement",
".",
"scrollHeight",
",",
"bottomShadowOffset",
"=",
"SCROLL_SHADOW_HEIGHT",
";",
"if",
"(",
"scrollHeight",
">",
"clientHeight",
")",
"{",
"bottomShadowOffset",
"-=",
"Math",
".",
"min",
"(",
"SCROLL_SHADOW_HEIGHT",
",",
"(",
"scrollHeight",
"-",
"(",
"scrollTop",
"+",
"clientHeight",
")",
")",
")",
";",
"}",
"$shadowBottom",
".",
"css",
"(",
"\"background-position\"",
",",
"\"0px \"",
"+",
"bottomShadowOffset",
"+",
"\"px\"",
")",
";",
"$shadowBottom",
".",
"css",
"(",
"\"top\"",
",",
"offsetTop",
"+",
"outerHeight",
"-",
"SCROLL_SHADOW_HEIGHT",
")",
";",
"$shadowBottom",
".",
"css",
"(",
"\"width\"",
",",
"displayElementWidth",
")",
";",
"}",
"}"
] |
Positions shadow background elements to indicate vertical scrolling.
@param {!DOMElement} $displayElement the DOMElement that displays the shadow
@param {!Object} $scrollElement the object that is scrolled
@param {!DOMElement} $shadowTop div .scroller-shadow.top
@param {!DOMElement} $shadowBottom div .scroller-shadow.bottom
@param {boolean} isPositionFixed When using absolute position, top remains at 0.
|
[
"Positions",
"shadow",
"background",
"elements",
"to",
"indicate",
"vertical",
"scrolling",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L45-L79
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
addScrollerShadow
|
function addScrollerShadow(displayElement, scrollElement, showBottom) {
// use fixed positioning when the display and scroll elements are the same
var isPositionFixed = false;
if (!scrollElement) {
scrollElement = displayElement;
isPositionFixed = true;
}
// update shadows when the scrolling element is scrolled
var $displayElement = $(displayElement),
$scrollElement = $(scrollElement);
var $shadowTop = getOrCreateShadow($displayElement, "top", isPositionFixed);
var $shadowBottom = (showBottom) ? getOrCreateShadow($displayElement, "bottom", isPositionFixed) : null;
var doUpdate = function () {
_updateScrollerShadow($displayElement, $scrollElement, $shadowTop, $shadowBottom, isPositionFixed);
};
// remove any previously installed listeners on this node
$scrollElement.off("scroll.scroller-shadow");
$displayElement.off("contentChanged.scroller-shadow");
// add new ones
$scrollElement.on("scroll.scroller-shadow", doUpdate);
$displayElement.on("contentChanged.scroller-shadow", doUpdate);
// update immediately
doUpdate();
}
|
javascript
|
function addScrollerShadow(displayElement, scrollElement, showBottom) {
// use fixed positioning when the display and scroll elements are the same
var isPositionFixed = false;
if (!scrollElement) {
scrollElement = displayElement;
isPositionFixed = true;
}
// update shadows when the scrolling element is scrolled
var $displayElement = $(displayElement),
$scrollElement = $(scrollElement);
var $shadowTop = getOrCreateShadow($displayElement, "top", isPositionFixed);
var $shadowBottom = (showBottom) ? getOrCreateShadow($displayElement, "bottom", isPositionFixed) : null;
var doUpdate = function () {
_updateScrollerShadow($displayElement, $scrollElement, $shadowTop, $shadowBottom, isPositionFixed);
};
// remove any previously installed listeners on this node
$scrollElement.off("scroll.scroller-shadow");
$displayElement.off("contentChanged.scroller-shadow");
// add new ones
$scrollElement.on("scroll.scroller-shadow", doUpdate);
$displayElement.on("contentChanged.scroller-shadow", doUpdate);
// update immediately
doUpdate();
}
|
[
"function",
"addScrollerShadow",
"(",
"displayElement",
",",
"scrollElement",
",",
"showBottom",
")",
"{",
"var",
"isPositionFixed",
"=",
"false",
";",
"if",
"(",
"!",
"scrollElement",
")",
"{",
"scrollElement",
"=",
"displayElement",
";",
"isPositionFixed",
"=",
"true",
";",
"}",
"var",
"$displayElement",
"=",
"$",
"(",
"displayElement",
")",
",",
"$scrollElement",
"=",
"$",
"(",
"scrollElement",
")",
";",
"var",
"$shadowTop",
"=",
"getOrCreateShadow",
"(",
"$displayElement",
",",
"\"top\"",
",",
"isPositionFixed",
")",
";",
"var",
"$shadowBottom",
"=",
"(",
"showBottom",
")",
"?",
"getOrCreateShadow",
"(",
"$displayElement",
",",
"\"bottom\"",
",",
"isPositionFixed",
")",
":",
"null",
";",
"var",
"doUpdate",
"=",
"function",
"(",
")",
"{",
"_updateScrollerShadow",
"(",
"$displayElement",
",",
"$scrollElement",
",",
"$shadowTop",
",",
"$shadowBottom",
",",
"isPositionFixed",
")",
";",
"}",
";",
"$scrollElement",
".",
"off",
"(",
"\"scroll.scroller-shadow\"",
")",
";",
"$displayElement",
".",
"off",
"(",
"\"contentChanged.scroller-shadow\"",
")",
";",
"$scrollElement",
".",
"on",
"(",
"\"scroll.scroller-shadow\"",
",",
"doUpdate",
")",
";",
"$displayElement",
".",
"on",
"(",
"\"contentChanged.scroller-shadow\"",
",",
"doUpdate",
")",
";",
"doUpdate",
"(",
")",
";",
"}"
] |
Installs event handlers for updatng shadow background elements to indicate vertical scrolling.
@param {!DOMElement} displayElement the DOMElement that displays the shadow. Must fire
"contentChanged" events when the element is resized or repositioned.
@param {?Object} scrollElement the object that is scrolled. Must fire "scroll" events
when the element is scrolled. If null, the displayElement is used.
@param {?boolean} showBottom optionally show the bottom shadow
|
[
"Installs",
"event",
"handlers",
"for",
"updatng",
"shadow",
"background",
"elements",
"to",
"indicate",
"vertical",
"scrolling",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L106-L136
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
removeScrollerShadow
|
function removeScrollerShadow(displayElement, scrollElement) {
if (!scrollElement) {
scrollElement = displayElement;
}
var $displayElement = $(displayElement),
$scrollElement = $(scrollElement);
// remove scrollerShadow elements from DOM
$displayElement.find(".scroller-shadow.top").remove();
$displayElement.find(".scroller-shadow.bottom").remove();
// remove event handlers
$scrollElement.off("scroll.scroller-shadow");
$displayElement.off("contentChanged.scroller-shadow");
}
|
javascript
|
function removeScrollerShadow(displayElement, scrollElement) {
if (!scrollElement) {
scrollElement = displayElement;
}
var $displayElement = $(displayElement),
$scrollElement = $(scrollElement);
// remove scrollerShadow elements from DOM
$displayElement.find(".scroller-shadow.top").remove();
$displayElement.find(".scroller-shadow.bottom").remove();
// remove event handlers
$scrollElement.off("scroll.scroller-shadow");
$displayElement.off("contentChanged.scroller-shadow");
}
|
[
"function",
"removeScrollerShadow",
"(",
"displayElement",
",",
"scrollElement",
")",
"{",
"if",
"(",
"!",
"scrollElement",
")",
"{",
"scrollElement",
"=",
"displayElement",
";",
"}",
"var",
"$displayElement",
"=",
"$",
"(",
"displayElement",
")",
",",
"$scrollElement",
"=",
"$",
"(",
"scrollElement",
")",
";",
"$displayElement",
".",
"find",
"(",
"\".scroller-shadow.top\"",
")",
".",
"remove",
"(",
")",
";",
"$displayElement",
".",
"find",
"(",
"\".scroller-shadow.bottom\"",
")",
".",
"remove",
"(",
")",
";",
"$scrollElement",
".",
"off",
"(",
"\"scroll.scroller-shadow\"",
")",
";",
"$displayElement",
".",
"off",
"(",
"\"contentChanged.scroller-shadow\"",
")",
";",
"}"
] |
Remove scroller-shadow effect.
@param {!DOMElement} displayElement the DOMElement that displays the shadow
@param {?Object} scrollElement the object that is scrolled
|
[
"Remove",
"scroller",
"-",
"shadow",
"effect",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L143-L158
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
getElementClipSize
|
function getElementClipSize($view, elementRect) {
var delta,
clip = { top: 0, right: 0, bottom: 0, left: 0 },
viewOffset = $view.offset() || { top: 0, left: 0};
// Check if element extends below viewport
delta = (elementRect.top + elementRect.height) - (viewOffset.top + $view.height());
if (delta > 0) {
clip.bottom = delta;
}
// Check if element extends above viewport
delta = viewOffset.top - elementRect.top;
if (delta > 0) {
clip.top = delta;
}
// Check if element extends to the left of viewport
delta = viewOffset.left - elementRect.left;
if (delta > 0) {
clip.left = delta;
}
// Check if element extends to the right of viewport
delta = (elementRect.left + elementRect.width) - (viewOffset.left + $view.width());
if (delta > 0) {
clip.right = delta;
}
return clip;
}
|
javascript
|
function getElementClipSize($view, elementRect) {
var delta,
clip = { top: 0, right: 0, bottom: 0, left: 0 },
viewOffset = $view.offset() || { top: 0, left: 0};
// Check if element extends below viewport
delta = (elementRect.top + elementRect.height) - (viewOffset.top + $view.height());
if (delta > 0) {
clip.bottom = delta;
}
// Check if element extends above viewport
delta = viewOffset.top - elementRect.top;
if (delta > 0) {
clip.top = delta;
}
// Check if element extends to the left of viewport
delta = viewOffset.left - elementRect.left;
if (delta > 0) {
clip.left = delta;
}
// Check if element extends to the right of viewport
delta = (elementRect.left + elementRect.width) - (viewOffset.left + $view.width());
if (delta > 0) {
clip.right = delta;
}
return clip;
}
|
[
"function",
"getElementClipSize",
"(",
"$view",
",",
"elementRect",
")",
"{",
"var",
"delta",
",",
"clip",
"=",
"{",
"top",
":",
"0",
",",
"right",
":",
"0",
",",
"bottom",
":",
"0",
",",
"left",
":",
"0",
"}",
",",
"viewOffset",
"=",
"$view",
".",
"offset",
"(",
")",
"||",
"{",
"top",
":",
"0",
",",
"left",
":",
"0",
"}",
";",
"delta",
"=",
"(",
"elementRect",
".",
"top",
"+",
"elementRect",
".",
"height",
")",
"-",
"(",
"viewOffset",
".",
"top",
"+",
"$view",
".",
"height",
"(",
")",
")",
";",
"if",
"(",
"delta",
">",
"0",
")",
"{",
"clip",
".",
"bottom",
"=",
"delta",
";",
"}",
"delta",
"=",
"viewOffset",
".",
"top",
"-",
"elementRect",
".",
"top",
";",
"if",
"(",
"delta",
">",
"0",
")",
"{",
"clip",
".",
"top",
"=",
"delta",
";",
"}",
"delta",
"=",
"viewOffset",
".",
"left",
"-",
"elementRect",
".",
"left",
";",
"if",
"(",
"delta",
">",
"0",
")",
"{",
"clip",
".",
"left",
"=",
"delta",
";",
"}",
"delta",
"=",
"(",
"elementRect",
".",
"left",
"+",
"elementRect",
".",
"width",
")",
"-",
"(",
"viewOffset",
".",
"left",
"+",
"$view",
".",
"width",
"(",
")",
")",
";",
"if",
"(",
"delta",
">",
"0",
")",
"{",
"clip",
".",
"right",
"=",
"delta",
";",
"}",
"return",
"clip",
";",
"}"
] |
Determine how much of an element rect is clipped in view.
@param {!DOMElement} $view - A jQuery scrolling container
@param {!{top: number, left: number, height: number, width: number}}
elementRect - rectangle of element's default position/size
@return {{top: number, right: number, bottom: number, left: number}}
amount element rect is clipped in each direction
|
[
"Determine",
"how",
"much",
"of",
"an",
"element",
"rect",
"is",
"clipped",
"in",
"view",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L313-L343
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
scrollElementIntoView
|
function scrollElementIntoView($view, $element, scrollHorizontal) {
var elementOffset = $element.offset();
// scroll minimum amount
var elementRect = {
top: elementOffset.top,
left: elementOffset.left,
height: $element.height(),
width: $element.width()
},
clip = getElementClipSize($view, elementRect);
if (clip.bottom > 0) {
// below viewport
$view.scrollTop($view.scrollTop() + clip.bottom);
} else if (clip.top > 0) {
// above viewport
$view.scrollTop($view.scrollTop() - clip.top);
}
if (scrollHorizontal) {
if (clip.left > 0) {
$view.scrollLeft($view.scrollLeft() - clip.left);
} else if (clip.right > 0) {
$view.scrollLeft($view.scrollLeft() + clip.right);
}
}
}
|
javascript
|
function scrollElementIntoView($view, $element, scrollHorizontal) {
var elementOffset = $element.offset();
// scroll minimum amount
var elementRect = {
top: elementOffset.top,
left: elementOffset.left,
height: $element.height(),
width: $element.width()
},
clip = getElementClipSize($view, elementRect);
if (clip.bottom > 0) {
// below viewport
$view.scrollTop($view.scrollTop() + clip.bottom);
} else if (clip.top > 0) {
// above viewport
$view.scrollTop($view.scrollTop() - clip.top);
}
if (scrollHorizontal) {
if (clip.left > 0) {
$view.scrollLeft($view.scrollLeft() - clip.left);
} else if (clip.right > 0) {
$view.scrollLeft($view.scrollLeft() + clip.right);
}
}
}
|
[
"function",
"scrollElementIntoView",
"(",
"$view",
",",
"$element",
",",
"scrollHorizontal",
")",
"{",
"var",
"elementOffset",
"=",
"$element",
".",
"offset",
"(",
")",
";",
"var",
"elementRect",
"=",
"{",
"top",
":",
"elementOffset",
".",
"top",
",",
"left",
":",
"elementOffset",
".",
"left",
",",
"height",
":",
"$element",
".",
"height",
"(",
")",
",",
"width",
":",
"$element",
".",
"width",
"(",
")",
"}",
",",
"clip",
"=",
"getElementClipSize",
"(",
"$view",
",",
"elementRect",
")",
";",
"if",
"(",
"clip",
".",
"bottom",
">",
"0",
")",
"{",
"$view",
".",
"scrollTop",
"(",
"$view",
".",
"scrollTop",
"(",
")",
"+",
"clip",
".",
"bottom",
")",
";",
"}",
"else",
"if",
"(",
"clip",
".",
"top",
">",
"0",
")",
"{",
"$view",
".",
"scrollTop",
"(",
"$view",
".",
"scrollTop",
"(",
")",
"-",
"clip",
".",
"top",
")",
";",
"}",
"if",
"(",
"scrollHorizontal",
")",
"{",
"if",
"(",
"clip",
".",
"left",
">",
"0",
")",
"{",
"$view",
".",
"scrollLeft",
"(",
"$view",
".",
"scrollLeft",
"(",
")",
"-",
"clip",
".",
"left",
")",
";",
"}",
"else",
"if",
"(",
"clip",
".",
"right",
">",
"0",
")",
"{",
"$view",
".",
"scrollLeft",
"(",
"$view",
".",
"scrollLeft",
"(",
")",
"+",
"clip",
".",
"right",
")",
";",
"}",
"}",
"}"
] |
Within a scrolling DOMElement, if necessary, scroll element into viewport.
To Perform the minimum amount of scrolling necessary, cases should be handled as follows:
- element already completely in view : no scrolling
- element above viewport : scroll view so element is at top
- element left of viewport : scroll view so element is at left
- element below viewport : scroll view so element is at bottom
- element right of viewport : scroll view so element is at right
Assumptions:
- $view is a scrolling container
@param {!DOMElement} $view - A jQuery scrolling container
@param {!DOMElement} $element - A jQuery element
@param {?boolean} scrollHorizontal - whether to also scroll horizontally
|
[
"Within",
"a",
"scrolling",
"DOMElement",
"if",
"necessary",
"scroll",
"element",
"into",
"viewport",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L362-L389
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
getFileEntryDisplay
|
function getFileEntryDisplay(entry) {
var name = entry.name,
ext = LanguageManager.getCompoundFileExtension(name),
i = name.lastIndexOf("." + ext);
if (i > 0) {
// Escape all HTML-sensitive characters in filename.
name = _.escape(name.substring(0, i)) + "<span class='extension'>" + _.escape(name.substring(i)) + "</span>";
} else {
name = _.escape(name);
}
return name;
}
|
javascript
|
function getFileEntryDisplay(entry) {
var name = entry.name,
ext = LanguageManager.getCompoundFileExtension(name),
i = name.lastIndexOf("." + ext);
if (i > 0) {
// Escape all HTML-sensitive characters in filename.
name = _.escape(name.substring(0, i)) + "<span class='extension'>" + _.escape(name.substring(i)) + "</span>";
} else {
name = _.escape(name);
}
return name;
}
|
[
"function",
"getFileEntryDisplay",
"(",
"entry",
")",
"{",
"var",
"name",
"=",
"entry",
".",
"name",
",",
"ext",
"=",
"LanguageManager",
".",
"getCompoundFileExtension",
"(",
"name",
")",
",",
"i",
"=",
"name",
".",
"lastIndexOf",
"(",
"\".\"",
"+",
"ext",
")",
";",
"if",
"(",
"i",
">",
"0",
")",
"{",
"name",
"=",
"_",
".",
"escape",
"(",
"name",
".",
"substring",
"(",
"0",
",",
"i",
")",
")",
"+",
"\"<span class='extension'>\"",
"+",
"_",
".",
"escape",
"(",
"name",
".",
"substring",
"(",
"i",
")",
")",
"+",
"\"</span>\"",
";",
"}",
"else",
"{",
"name",
"=",
"_",
".",
"escape",
"(",
"name",
")",
";",
"}",
"return",
"name",
";",
"}"
] |
HTML formats a file entry name for display in the sidebar.
@param {!File} entry File entry to display
@return {string} HTML formatted string
|
[
"HTML",
"formats",
"a",
"file",
"entry",
"name",
"for",
"display",
"in",
"the",
"sidebar",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L396-L409
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
getDirNamesForDuplicateFiles
|
function getDirNamesForDuplicateFiles(files) {
// Must have at least two files in list for this to make sense
if (files.length <= 1) {
return [];
}
// First collect paths from the list of files and fill map with them
var map = {}, filePaths = [], displayPaths = [];
files.forEach(function (file, index) {
var fp = file.fullPath.split("/");
fp.pop(); // Remove the filename itself
displayPaths[index] = fp.pop();
filePaths[index] = fp;
if (!map[displayPaths[index]]) {
map[displayPaths[index]] = [index];
} else {
map[displayPaths[index]].push(index);
}
});
// This function is used to loop through map and resolve duplicate names
var processMap = function (map) {
var didSomething = false;
_.forEach(map, function (arr, key) {
// length > 1 means we have duplicates that need to be resolved
if (arr.length > 1) {
arr.forEach(function (index) {
if (filePaths[index].length !== 0) {
displayPaths[index] = filePaths[index].pop() + "/" + displayPaths[index];
didSomething = true;
if (!map[displayPaths[index]]) {
map[displayPaths[index]] = [index];
} else {
map[displayPaths[index]].push(index);
}
}
});
}
delete map[key];
});
return didSomething;
};
var repeat;
do {
repeat = processMap(map);
} while (repeat);
return displayPaths;
}
|
javascript
|
function getDirNamesForDuplicateFiles(files) {
// Must have at least two files in list for this to make sense
if (files.length <= 1) {
return [];
}
// First collect paths from the list of files and fill map with them
var map = {}, filePaths = [], displayPaths = [];
files.forEach(function (file, index) {
var fp = file.fullPath.split("/");
fp.pop(); // Remove the filename itself
displayPaths[index] = fp.pop();
filePaths[index] = fp;
if (!map[displayPaths[index]]) {
map[displayPaths[index]] = [index];
} else {
map[displayPaths[index]].push(index);
}
});
// This function is used to loop through map and resolve duplicate names
var processMap = function (map) {
var didSomething = false;
_.forEach(map, function (arr, key) {
// length > 1 means we have duplicates that need to be resolved
if (arr.length > 1) {
arr.forEach(function (index) {
if (filePaths[index].length !== 0) {
displayPaths[index] = filePaths[index].pop() + "/" + displayPaths[index];
didSomething = true;
if (!map[displayPaths[index]]) {
map[displayPaths[index]] = [index];
} else {
map[displayPaths[index]].push(index);
}
}
});
}
delete map[key];
});
return didSomething;
};
var repeat;
do {
repeat = processMap(map);
} while (repeat);
return displayPaths;
}
|
[
"function",
"getDirNamesForDuplicateFiles",
"(",
"files",
")",
"{",
"if",
"(",
"files",
".",
"length",
"<=",
"1",
")",
"{",
"return",
"[",
"]",
";",
"}",
"var",
"map",
"=",
"{",
"}",
",",
"filePaths",
"=",
"[",
"]",
",",
"displayPaths",
"=",
"[",
"]",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
",",
"index",
")",
"{",
"var",
"fp",
"=",
"file",
".",
"fullPath",
".",
"split",
"(",
"\"/\"",
")",
";",
"fp",
".",
"pop",
"(",
")",
";",
"displayPaths",
"[",
"index",
"]",
"=",
"fp",
".",
"pop",
"(",
")",
";",
"filePaths",
"[",
"index",
"]",
"=",
"fp",
";",
"if",
"(",
"!",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
")",
"{",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
"=",
"[",
"index",
"]",
";",
"}",
"else",
"{",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
".",
"push",
"(",
"index",
")",
";",
"}",
"}",
")",
";",
"var",
"processMap",
"=",
"function",
"(",
"map",
")",
"{",
"var",
"didSomething",
"=",
"false",
";",
"_",
".",
"forEach",
"(",
"map",
",",
"function",
"(",
"arr",
",",
"key",
")",
"{",
"if",
"(",
"arr",
".",
"length",
">",
"1",
")",
"{",
"arr",
".",
"forEach",
"(",
"function",
"(",
"index",
")",
"{",
"if",
"(",
"filePaths",
"[",
"index",
"]",
".",
"length",
"!==",
"0",
")",
"{",
"displayPaths",
"[",
"index",
"]",
"=",
"filePaths",
"[",
"index",
"]",
".",
"pop",
"(",
")",
"+",
"\"/\"",
"+",
"displayPaths",
"[",
"index",
"]",
";",
"didSomething",
"=",
"true",
";",
"if",
"(",
"!",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
")",
"{",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
"=",
"[",
"index",
"]",
";",
"}",
"else",
"{",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
".",
"push",
"(",
"index",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"delete",
"map",
"[",
"key",
"]",
";",
"}",
")",
";",
"return",
"didSomething",
";",
"}",
";",
"var",
"repeat",
";",
"do",
"{",
"repeat",
"=",
"processMap",
"(",
"map",
")",
";",
"}",
"while",
"(",
"repeat",
")",
";",
"return",
"displayPaths",
";",
"}"
] |
Determine the minimum directory path to distinguish duplicate file names
for each file in list.
@param {Array.<File>} files - list of Files with the same filename
@return {Array.<string>} directory paths to match list of files
|
[
"Determine",
"the",
"minimum",
"directory",
"path",
"to",
"distinguish",
"duplicate",
"file",
"names",
"for",
"each",
"file",
"in",
"list",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L418-L469
|
train
|
adobe/brackets
|
src/utils/ViewUtils.js
|
function (map) {
var didSomething = false;
_.forEach(map, function (arr, key) {
// length > 1 means we have duplicates that need to be resolved
if (arr.length > 1) {
arr.forEach(function (index) {
if (filePaths[index].length !== 0) {
displayPaths[index] = filePaths[index].pop() + "/" + displayPaths[index];
didSomething = true;
if (!map[displayPaths[index]]) {
map[displayPaths[index]] = [index];
} else {
map[displayPaths[index]].push(index);
}
}
});
}
delete map[key];
});
return didSomething;
}
|
javascript
|
function (map) {
var didSomething = false;
_.forEach(map, function (arr, key) {
// length > 1 means we have duplicates that need to be resolved
if (arr.length > 1) {
arr.forEach(function (index) {
if (filePaths[index].length !== 0) {
displayPaths[index] = filePaths[index].pop() + "/" + displayPaths[index];
didSomething = true;
if (!map[displayPaths[index]]) {
map[displayPaths[index]] = [index];
} else {
map[displayPaths[index]].push(index);
}
}
});
}
delete map[key];
});
return didSomething;
}
|
[
"function",
"(",
"map",
")",
"{",
"var",
"didSomething",
"=",
"false",
";",
"_",
".",
"forEach",
"(",
"map",
",",
"function",
"(",
"arr",
",",
"key",
")",
"{",
"if",
"(",
"arr",
".",
"length",
">",
"1",
")",
"{",
"arr",
".",
"forEach",
"(",
"function",
"(",
"index",
")",
"{",
"if",
"(",
"filePaths",
"[",
"index",
"]",
".",
"length",
"!==",
"0",
")",
"{",
"displayPaths",
"[",
"index",
"]",
"=",
"filePaths",
"[",
"index",
"]",
".",
"pop",
"(",
")",
"+",
"\"/\"",
"+",
"displayPaths",
"[",
"index",
"]",
";",
"didSomething",
"=",
"true",
";",
"if",
"(",
"!",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
")",
"{",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
"=",
"[",
"index",
"]",
";",
"}",
"else",
"{",
"map",
"[",
"displayPaths",
"[",
"index",
"]",
"]",
".",
"push",
"(",
"index",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"delete",
"map",
"[",
"key",
"]",
";",
"}",
")",
";",
"return",
"didSomething",
";",
"}"
] |
This function is used to loop through map and resolve duplicate names
|
[
"This",
"function",
"is",
"used",
"to",
"loop",
"through",
"map",
"and",
"resolve",
"duplicate",
"names"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ViewUtils.js#L440-L461
|
train
|
|
adobe/brackets
|
src/extensibility/ExtensionManagerViewModel.js
|
filterForKeyword
|
function filterForKeyword(extensionList, word) {
var filteredList = [];
extensionList.forEach(function (id) {
var entry = self._getEntry(id);
if (entry && self._entryMatchesQuery(entry, word)) {
filteredList.push(id);
}
});
return filteredList;
}
|
javascript
|
function filterForKeyword(extensionList, word) {
var filteredList = [];
extensionList.forEach(function (id) {
var entry = self._getEntry(id);
if (entry && self._entryMatchesQuery(entry, word)) {
filteredList.push(id);
}
});
return filteredList;
}
|
[
"function",
"filterForKeyword",
"(",
"extensionList",
",",
"word",
")",
"{",
"var",
"filteredList",
"=",
"[",
"]",
";",
"extensionList",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"var",
"entry",
"=",
"self",
".",
"_getEntry",
"(",
"id",
")",
";",
"if",
"(",
"entry",
"&&",
"self",
".",
"_entryMatchesQuery",
"(",
"entry",
",",
"word",
")",
")",
"{",
"filteredList",
".",
"push",
"(",
"id",
")",
";",
"}",
"}",
")",
";",
"return",
"filteredList",
";",
"}"
] |
Takes 'extensionList' and returns a version filtered to only those that match 'keyword'
|
[
"Takes",
"extensionList",
"and",
"returns",
"a",
"version",
"filtered",
"to",
"only",
"those",
"that",
"match",
"keyword"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/ExtensionManagerViewModel.js#L214-L223
|
train
|
adobe/brackets
|
src/utils/ExtensionLoader.js
|
loadExtensionModule
|
function loadExtensionModule(name, config, entryPoint) {
var extensionConfig = {
context: name,
baseUrl: config.baseUrl,
paths: globalPaths,
locale: brackets.getLocale()
};
// Read optional requirejs-config.json
var promise = _mergeConfig(extensionConfig).then(function (mergedConfig) {
// Create new RequireJS context and load extension entry point
var extensionRequire = brackets.libRequire.config(mergedConfig),
extensionRequireDeferred = new $.Deferred();
contexts[name] = extensionRequire;
extensionRequire([entryPoint], extensionRequireDeferred.resolve, extensionRequireDeferred.reject);
return extensionRequireDeferred.promise();
}).then(function (module) {
// Extension loaded normally
var initPromise;
_extensions[name] = module;
// Optional sync/async initExtension
if (module && module.initExtension && (typeof module.initExtension === "function")) {
// optional async extension init
try {
initPromise = Async.withTimeout(module.initExtension(), _getInitExtensionTimeout());
} catch (err) {
// Synchronous error while initializing extension
console.error("[Extension] Error -- error thrown during initExtension for " + name + ": " + err);
return new $.Deferred().reject(err).promise();
}
// initExtension may be synchronous and may not return a promise
if (initPromise) {
// WARNING: These calls to initPromise.fail() and initPromise.then(),
// could also result in a runtime error if initPromise is not a valid
// promise. Currently, the promise is wrapped via Async.withTimeout(),
// so the call is safe as-is.
initPromise.fail(function (err) {
if (err === Async.ERROR_TIMEOUT) {
console.error("[Extension] Error -- timeout during initExtension for " + name);
} else {
console.error("[Extension] Error -- failed initExtension for " + name + (err ? ": " + err : ""));
}
});
return initPromise;
}
}
}, function errback(err) {
// Extension failed to load during the initial require() call
var additionalInfo = String(err);
if (err.requireType === "scripterror" && err.originalError) {
// This type has a misleading error message - replace it with something clearer (URL of require() call that got a 404 result)
additionalInfo = "Module does not exist: " + err.originalError.target.src;
}
console.error("[Extension] failed to load " + config.baseUrl + " - " + additionalInfo);
if (err.requireType === "define") {
// This type has a useful stack (exception thrown by ext code or info on bad getModule() call)
console.log(err.stack);
}
});
return promise;
}
|
javascript
|
function loadExtensionModule(name, config, entryPoint) {
var extensionConfig = {
context: name,
baseUrl: config.baseUrl,
paths: globalPaths,
locale: brackets.getLocale()
};
// Read optional requirejs-config.json
var promise = _mergeConfig(extensionConfig).then(function (mergedConfig) {
// Create new RequireJS context and load extension entry point
var extensionRequire = brackets.libRequire.config(mergedConfig),
extensionRequireDeferred = new $.Deferred();
contexts[name] = extensionRequire;
extensionRequire([entryPoint], extensionRequireDeferred.resolve, extensionRequireDeferred.reject);
return extensionRequireDeferred.promise();
}).then(function (module) {
// Extension loaded normally
var initPromise;
_extensions[name] = module;
// Optional sync/async initExtension
if (module && module.initExtension && (typeof module.initExtension === "function")) {
// optional async extension init
try {
initPromise = Async.withTimeout(module.initExtension(), _getInitExtensionTimeout());
} catch (err) {
// Synchronous error while initializing extension
console.error("[Extension] Error -- error thrown during initExtension for " + name + ": " + err);
return new $.Deferred().reject(err).promise();
}
// initExtension may be synchronous and may not return a promise
if (initPromise) {
// WARNING: These calls to initPromise.fail() and initPromise.then(),
// could also result in a runtime error if initPromise is not a valid
// promise. Currently, the promise is wrapped via Async.withTimeout(),
// so the call is safe as-is.
initPromise.fail(function (err) {
if (err === Async.ERROR_TIMEOUT) {
console.error("[Extension] Error -- timeout during initExtension for " + name);
} else {
console.error("[Extension] Error -- failed initExtension for " + name + (err ? ": " + err : ""));
}
});
return initPromise;
}
}
}, function errback(err) {
// Extension failed to load during the initial require() call
var additionalInfo = String(err);
if (err.requireType === "scripterror" && err.originalError) {
// This type has a misleading error message - replace it with something clearer (URL of require() call that got a 404 result)
additionalInfo = "Module does not exist: " + err.originalError.target.src;
}
console.error("[Extension] failed to load " + config.baseUrl + " - " + additionalInfo);
if (err.requireType === "define") {
// This type has a useful stack (exception thrown by ext code or info on bad getModule() call)
console.log(err.stack);
}
});
return promise;
}
|
[
"function",
"loadExtensionModule",
"(",
"name",
",",
"config",
",",
"entryPoint",
")",
"{",
"var",
"extensionConfig",
"=",
"{",
"context",
":",
"name",
",",
"baseUrl",
":",
"config",
".",
"baseUrl",
",",
"paths",
":",
"globalPaths",
",",
"locale",
":",
"brackets",
".",
"getLocale",
"(",
")",
"}",
";",
"var",
"promise",
"=",
"_mergeConfig",
"(",
"extensionConfig",
")",
".",
"then",
"(",
"function",
"(",
"mergedConfig",
")",
"{",
"var",
"extensionRequire",
"=",
"brackets",
".",
"libRequire",
".",
"config",
"(",
"mergedConfig",
")",
",",
"extensionRequireDeferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"contexts",
"[",
"name",
"]",
"=",
"extensionRequire",
";",
"extensionRequire",
"(",
"[",
"entryPoint",
"]",
",",
"extensionRequireDeferred",
".",
"resolve",
",",
"extensionRequireDeferred",
".",
"reject",
")",
";",
"return",
"extensionRequireDeferred",
".",
"promise",
"(",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"module",
")",
"{",
"var",
"initPromise",
";",
"_extensions",
"[",
"name",
"]",
"=",
"module",
";",
"if",
"(",
"module",
"&&",
"module",
".",
"initExtension",
"&&",
"(",
"typeof",
"module",
".",
"initExtension",
"===",
"\"function\"",
")",
")",
"{",
"try",
"{",
"initPromise",
"=",
"Async",
".",
"withTimeout",
"(",
"module",
".",
"initExtension",
"(",
")",
",",
"_getInitExtensionTimeout",
"(",
")",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"\"[Extension] Error -- error thrown during initExtension for \"",
"+",
"name",
"+",
"\": \"",
"+",
"err",
")",
";",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"reject",
"(",
"err",
")",
".",
"promise",
"(",
")",
";",
"}",
"if",
"(",
"initPromise",
")",
"{",
"initPromise",
".",
"fail",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"===",
"Async",
".",
"ERROR_TIMEOUT",
")",
"{",
"console",
".",
"error",
"(",
"\"[Extension] Error -- timeout during initExtension for \"",
"+",
"name",
")",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"[Extension] Error -- failed initExtension for \"",
"+",
"name",
"+",
"(",
"err",
"?",
"\": \"",
"+",
"err",
":",
"\"\"",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"initPromise",
";",
"}",
"}",
"}",
",",
"function",
"errback",
"(",
"err",
")",
"{",
"var",
"additionalInfo",
"=",
"String",
"(",
"err",
")",
";",
"if",
"(",
"err",
".",
"requireType",
"===",
"\"scripterror\"",
"&&",
"err",
".",
"originalError",
")",
"{",
"additionalInfo",
"=",
"\"Module does not exist: \"",
"+",
"err",
".",
"originalError",
".",
"target",
".",
"src",
";",
"}",
"console",
".",
"error",
"(",
"\"[Extension] failed to load \"",
"+",
"config",
".",
"baseUrl",
"+",
"\" - \"",
"+",
"additionalInfo",
")",
";",
"if",
"(",
"err",
".",
"requireType",
"===",
"\"define\"",
")",
"{",
"console",
".",
"log",
"(",
"err",
".",
"stack",
")",
";",
"}",
"}",
")",
";",
"return",
"promise",
";",
"}"
] |
Loads the extension module that lives at baseUrl into its own Require.js context
@param {!string} name, used to identify the extension
@param {!{baseUrl: string}} config object with baseUrl property containing absolute path of extension
@param {!string} entryPoint, name of the main js file to load
@return {!$.Promise} A promise object that is resolved when the extension is loaded, or rejected
if the extension fails to load or throws an exception immediately when loaded.
(Note: if extension contains a JS syntax error, promise is resolved not rejected).
|
[
"Loads",
"the",
"extension",
"module",
"that",
"lives",
"at",
"baseUrl",
"into",
"its",
"own",
"Require",
".",
"js",
"context"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionLoader.js#L168-L236
|
train
|
adobe/brackets
|
src/utils/ExtensionLoader.js
|
loadExtension
|
function loadExtension(name, config, entryPoint) {
var promise = new $.Deferred();
// Try to load the package.json to figure out if we are loading a theme.
ExtensionUtils.loadMetadata(config.baseUrl).always(promise.resolve);
return promise
.then(function (metadata) {
// No special handling for themes... Let the promise propagate into the ExtensionManager
if (metadata && metadata.theme) {
return;
}
if (!metadata.disabled) {
return loadExtensionModule(name, config, entryPoint);
} else {
return new $.Deferred().reject("disabled").promise();
}
})
.then(function () {
exports.trigger("load", config.baseUrl);
}, function (err) {
if (err === "disabled") {
exports.trigger("disabled", config.baseUrl);
} else {
exports.trigger("loadFailed", config.baseUrl);
}
});
}
|
javascript
|
function loadExtension(name, config, entryPoint) {
var promise = new $.Deferred();
// Try to load the package.json to figure out if we are loading a theme.
ExtensionUtils.loadMetadata(config.baseUrl).always(promise.resolve);
return promise
.then(function (metadata) {
// No special handling for themes... Let the promise propagate into the ExtensionManager
if (metadata && metadata.theme) {
return;
}
if (!metadata.disabled) {
return loadExtensionModule(name, config, entryPoint);
} else {
return new $.Deferred().reject("disabled").promise();
}
})
.then(function () {
exports.trigger("load", config.baseUrl);
}, function (err) {
if (err === "disabled") {
exports.trigger("disabled", config.baseUrl);
} else {
exports.trigger("loadFailed", config.baseUrl);
}
});
}
|
[
"function",
"loadExtension",
"(",
"name",
",",
"config",
",",
"entryPoint",
")",
"{",
"var",
"promise",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"ExtensionUtils",
".",
"loadMetadata",
"(",
"config",
".",
"baseUrl",
")",
".",
"always",
"(",
"promise",
".",
"resolve",
")",
";",
"return",
"promise",
".",
"then",
"(",
"function",
"(",
"metadata",
")",
"{",
"if",
"(",
"metadata",
"&&",
"metadata",
".",
"theme",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"metadata",
".",
"disabled",
")",
"{",
"return",
"loadExtensionModule",
"(",
"name",
",",
"config",
",",
"entryPoint",
")",
";",
"}",
"else",
"{",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"reject",
"(",
"\"disabled\"",
")",
".",
"promise",
"(",
")",
";",
"}",
"}",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"exports",
".",
"trigger",
"(",
"\"load\"",
",",
"config",
".",
"baseUrl",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"===",
"\"disabled\"",
")",
"{",
"exports",
".",
"trigger",
"(",
"\"disabled\"",
",",
"config",
".",
"baseUrl",
")",
";",
"}",
"else",
"{",
"exports",
".",
"trigger",
"(",
"\"loadFailed\"",
",",
"config",
".",
"baseUrl",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Loads the extension that lives at baseUrl into its own Require.js context
@param {!string} name, used to identify the extension
@param {!{baseUrl: string}} config object with baseUrl property containing absolute path of extension
@param {!string} entryPoint, name of the main js file to load
@return {!$.Promise} A promise object that is resolved when the extension is loaded, or rejected
if the extension fails to load or throws an exception immediately when loaded.
(Note: if extension contains a JS syntax error, promise is resolved not rejected).
|
[
"Loads",
"the",
"extension",
"that",
"lives",
"at",
"baseUrl",
"into",
"its",
"own",
"Require",
".",
"js",
"context"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionLoader.js#L248-L276
|
train
|
adobe/brackets
|
src/utils/ExtensionLoader.js
|
init
|
function init(paths) {
var params = new UrlParams();
if (_init) {
// Only init once. Return a resolved promise.
return new $.Deferred().resolve().promise();
}
if (!paths) {
params.parse();
if (params.get("reloadWithoutUserExts") === "true") {
paths = ["default"];
} else {
paths = [
getDefaultExtensionPath(),
"dev",
getUserExtensionPath()
];
}
}
// Load extensions before restoring the project
// Get a Directory for the user extension directory and create it if it doesn't exist.
// Note that this is an async call and there are no success or failure functions passed
// in. If the directory *doesn't* exist, it will be created. Extension loading may happen
// before the directory is finished being created, but that is okay, since the extension
// loading will work correctly without this directory.
// If the directory *does* exist, nothing else needs to be done. It will be scanned normally
// during extension loading.
var extensionPath = getUserExtensionPath();
FileSystem.getDirectoryForPath(extensionPath).create();
// Create the extensions/disabled directory, too.
var disabledExtensionPath = extensionPath.replace(/\/user$/, "/disabled");
FileSystem.getDirectoryForPath(disabledExtensionPath).create();
var promise = Async.doSequentially(paths, function (item) {
var extensionPath = item;
// If the item has "/" in it, assume it is a full path. Otherwise, load
// from our source path + "/extensions/".
if (item.indexOf("/") === -1) {
extensionPath = FileUtils.getNativeBracketsDirectoryPath() + "/extensions/" + item;
}
return loadAllExtensionsInNativeDirectory(extensionPath);
}, false);
promise.always(function () {
_init = true;
});
return promise;
}
|
javascript
|
function init(paths) {
var params = new UrlParams();
if (_init) {
// Only init once. Return a resolved promise.
return new $.Deferred().resolve().promise();
}
if (!paths) {
params.parse();
if (params.get("reloadWithoutUserExts") === "true") {
paths = ["default"];
} else {
paths = [
getDefaultExtensionPath(),
"dev",
getUserExtensionPath()
];
}
}
// Load extensions before restoring the project
// Get a Directory for the user extension directory and create it if it doesn't exist.
// Note that this is an async call and there are no success or failure functions passed
// in. If the directory *doesn't* exist, it will be created. Extension loading may happen
// before the directory is finished being created, but that is okay, since the extension
// loading will work correctly without this directory.
// If the directory *does* exist, nothing else needs to be done. It will be scanned normally
// during extension loading.
var extensionPath = getUserExtensionPath();
FileSystem.getDirectoryForPath(extensionPath).create();
// Create the extensions/disabled directory, too.
var disabledExtensionPath = extensionPath.replace(/\/user$/, "/disabled");
FileSystem.getDirectoryForPath(disabledExtensionPath).create();
var promise = Async.doSequentially(paths, function (item) {
var extensionPath = item;
// If the item has "/" in it, assume it is a full path. Otherwise, load
// from our source path + "/extensions/".
if (item.indexOf("/") === -1) {
extensionPath = FileUtils.getNativeBracketsDirectoryPath() + "/extensions/" + item;
}
return loadAllExtensionsInNativeDirectory(extensionPath);
}, false);
promise.always(function () {
_init = true;
});
return promise;
}
|
[
"function",
"init",
"(",
"paths",
")",
"{",
"var",
"params",
"=",
"new",
"UrlParams",
"(",
")",
";",
"if",
"(",
"_init",
")",
"{",
"return",
"new",
"$",
".",
"Deferred",
"(",
")",
".",
"resolve",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"if",
"(",
"!",
"paths",
")",
"{",
"params",
".",
"parse",
"(",
")",
";",
"if",
"(",
"params",
".",
"get",
"(",
"\"reloadWithoutUserExts\"",
")",
"===",
"\"true\"",
")",
"{",
"paths",
"=",
"[",
"\"default\"",
"]",
";",
"}",
"else",
"{",
"paths",
"=",
"[",
"getDefaultExtensionPath",
"(",
")",
",",
"\"dev\"",
",",
"getUserExtensionPath",
"(",
")",
"]",
";",
"}",
"}",
"var",
"extensionPath",
"=",
"getUserExtensionPath",
"(",
")",
";",
"FileSystem",
".",
"getDirectoryForPath",
"(",
"extensionPath",
")",
".",
"create",
"(",
")",
";",
"var",
"disabledExtensionPath",
"=",
"extensionPath",
".",
"replace",
"(",
"/",
"\\/user$",
"/",
",",
"\"/disabled\"",
")",
";",
"FileSystem",
".",
"getDirectoryForPath",
"(",
"disabledExtensionPath",
")",
".",
"create",
"(",
")",
";",
"var",
"promise",
"=",
"Async",
".",
"doSequentially",
"(",
"paths",
",",
"function",
"(",
"item",
")",
"{",
"var",
"extensionPath",
"=",
"item",
";",
"if",
"(",
"item",
".",
"indexOf",
"(",
"\"/\"",
")",
"===",
"-",
"1",
")",
"{",
"extensionPath",
"=",
"FileUtils",
".",
"getNativeBracketsDirectoryPath",
"(",
")",
"+",
"\"/extensions/\"",
"+",
"item",
";",
"}",
"return",
"loadAllExtensionsInNativeDirectory",
"(",
"extensionPath",
")",
";",
"}",
",",
"false",
")",
";",
"promise",
".",
"always",
"(",
"function",
"(",
")",
"{",
"_init",
"=",
"true",
";",
"}",
")",
";",
"return",
"promise",
";",
"}"
] |
Load extensions.
@param {?Array.<string>} A list containing references to extension source
location. A source location may be either (a) a folder name inside
src/extensions or (b) an absolute path.
@return {!$.Promise} A promise object that is resolved when all extensions complete loading.
|
[
"Load",
"extensions",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/ExtensionLoader.js#L401-L456
|
train
|
adobe/brackets
|
src/filesystem/Directory.js
|
_applyAllCallbacks
|
function _applyAllCallbacks(callbacks, args) {
if (callbacks.length > 0) {
var callback = callbacks.pop();
try {
callback.apply(undefined, args);
} finally {
_applyAllCallbacks(callbacks, args);
}
}
}
|
javascript
|
function _applyAllCallbacks(callbacks, args) {
if (callbacks.length > 0) {
var callback = callbacks.pop();
try {
callback.apply(undefined, args);
} finally {
_applyAllCallbacks(callbacks, args);
}
}
}
|
[
"function",
"_applyAllCallbacks",
"(",
"callbacks",
",",
"args",
")",
"{",
"if",
"(",
"callbacks",
".",
"length",
">",
"0",
")",
"{",
"var",
"callback",
"=",
"callbacks",
".",
"pop",
"(",
")",
";",
"try",
"{",
"callback",
".",
"apply",
"(",
"undefined",
",",
"args",
")",
";",
"}",
"finally",
"{",
"_applyAllCallbacks",
"(",
"callbacks",
",",
"args",
")",
";",
"}",
"}",
"}"
] |
Apply each callback in a list to the provided arguments. Callbacks
can throw without preventing other callbacks from being applied.
@private
@param {Array.<function>} callbacks The callbacks to apply
@param {Array} args The arguments to which each callback is applied
|
[
"Apply",
"each",
"callback",
"in",
"a",
"list",
"to",
"the",
"provided",
"arguments",
".",
"Callbacks",
"can",
"throw",
"without",
"preventing",
"other",
"callbacks",
"from",
"being",
"applied",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/Directory.js#L114-L123
|
train
|
adobe/brackets
|
src/project/ProjectModel.js
|
doCreate
|
function doCreate(path, isFolder) {
var d = new $.Deferred();
var filename = FileUtils.getBaseName(path);
// Check if filename
if (!isValidFilename(filename)){
return d.reject(ERROR_INVALID_FILENAME).promise();
}
// Check if fullpath with filename is valid
// This check is used to circumvent directory jumps (Like ../..)
if (!isValidPath(path)) {
return d.reject(ERROR_INVALID_FILENAME).promise();
}
FileSystem.resolve(path, function (err) {
if (!err) {
// Item already exists, fail with error
d.reject(FileSystemError.ALREADY_EXISTS);
} else {
if (isFolder) {
var directory = FileSystem.getDirectoryForPath(path);
directory.create(function (err) {
if (err) {
d.reject(err);
} else {
d.resolve(directory);
}
});
} else {
// Create an empty file
var file = FileSystem.getFileForPath(path);
FileUtils.writeText(file, "").then(function () {
d.resolve(file);
}, d.reject);
}
}
});
return d.promise();
}
|
javascript
|
function doCreate(path, isFolder) {
var d = new $.Deferred();
var filename = FileUtils.getBaseName(path);
// Check if filename
if (!isValidFilename(filename)){
return d.reject(ERROR_INVALID_FILENAME).promise();
}
// Check if fullpath with filename is valid
// This check is used to circumvent directory jumps (Like ../..)
if (!isValidPath(path)) {
return d.reject(ERROR_INVALID_FILENAME).promise();
}
FileSystem.resolve(path, function (err) {
if (!err) {
// Item already exists, fail with error
d.reject(FileSystemError.ALREADY_EXISTS);
} else {
if (isFolder) {
var directory = FileSystem.getDirectoryForPath(path);
directory.create(function (err) {
if (err) {
d.reject(err);
} else {
d.resolve(directory);
}
});
} else {
// Create an empty file
var file = FileSystem.getFileForPath(path);
FileUtils.writeText(file, "").then(function () {
d.resolve(file);
}, d.reject);
}
}
});
return d.promise();
}
|
[
"function",
"doCreate",
"(",
"path",
",",
"isFolder",
")",
"{",
"var",
"d",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"filename",
"=",
"FileUtils",
".",
"getBaseName",
"(",
"path",
")",
";",
"if",
"(",
"!",
"isValidFilename",
"(",
"filename",
")",
")",
"{",
"return",
"d",
".",
"reject",
"(",
"ERROR_INVALID_FILENAME",
")",
".",
"promise",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isValidPath",
"(",
"path",
")",
")",
"{",
"return",
"d",
".",
"reject",
"(",
"ERROR_INVALID_FILENAME",
")",
".",
"promise",
"(",
")",
";",
"}",
"FileSystem",
".",
"resolve",
"(",
"path",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"d",
".",
"reject",
"(",
"FileSystemError",
".",
"ALREADY_EXISTS",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isFolder",
")",
"{",
"var",
"directory",
"=",
"FileSystem",
".",
"getDirectoryForPath",
"(",
"path",
")",
";",
"directory",
".",
"create",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"d",
".",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"d",
".",
"resolve",
"(",
"directory",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"var",
"file",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"path",
")",
";",
"FileUtils",
".",
"writeText",
"(",
"file",
",",
"\"\"",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"d",
".",
"resolve",
"(",
"file",
")",
";",
"}",
",",
"d",
".",
"reject",
")",
";",
"}",
"}",
"}",
")",
";",
"return",
"d",
".",
"promise",
"(",
")",
";",
"}"
] |
Creates a new file or folder at the given path. The returned promise is rejected if the filename
is invalid, the new path already exists or some other filesystem error comes up.
@param {string} path path to create
@param {boolean} isFolder true if the new entry is a folder
@return {$.Promise} resolved when the file or directory has been created.
|
[
"Creates",
"a",
"new",
"file",
"or",
"folder",
"at",
"the",
"given",
"path",
".",
"The",
"returned",
"promise",
"is",
"rejected",
"if",
"the",
"filename",
"is",
"invalid",
"the",
"new",
"path",
"already",
"exists",
"or",
"some",
"other",
"filesystem",
"error",
"comes",
"up",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectModel.js#L188-L230
|
train
|
adobe/brackets
|
src/project/ProjectModel.js
|
_isWelcomeProjectPath
|
function _isWelcomeProjectPath(path, welcomeProjectPath, welcomeProjects) {
if (path === welcomeProjectPath) {
return true;
}
// No match on the current path, and it's not a match if there are no previously known projects
if (!welcomeProjects) {
return false;
}
var pathNoSlash = FileUtils.stripTrailingSlash(path); // "welcomeProjects" pref has standardized on no trailing "/"
return welcomeProjects.indexOf(pathNoSlash) !== -1;
}
|
javascript
|
function _isWelcomeProjectPath(path, welcomeProjectPath, welcomeProjects) {
if (path === welcomeProjectPath) {
return true;
}
// No match on the current path, and it's not a match if there are no previously known projects
if (!welcomeProjects) {
return false;
}
var pathNoSlash = FileUtils.stripTrailingSlash(path); // "welcomeProjects" pref has standardized on no trailing "/"
return welcomeProjects.indexOf(pathNoSlash) !== -1;
}
|
[
"function",
"_isWelcomeProjectPath",
"(",
"path",
",",
"welcomeProjectPath",
",",
"welcomeProjects",
")",
"{",
"if",
"(",
"path",
"===",
"welcomeProjectPath",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"welcomeProjects",
")",
"{",
"return",
"false",
";",
"}",
"var",
"pathNoSlash",
"=",
"FileUtils",
".",
"stripTrailingSlash",
"(",
"path",
")",
";",
"return",
"welcomeProjects",
".",
"indexOf",
"(",
"pathNoSlash",
")",
"!==",
"-",
"1",
";",
"}"
] |
Returns true if the given path is the same as one of the welcome projects we've previously opened,
or the one for the current build.
@param {string} path Path to check to see if it's a welcome project
@param {string} welcomeProjectPath Current welcome project path
@param {Array.<string>=} welcomeProjects All known welcome projects
|
[
"Returns",
"true",
"if",
"the",
"given",
"path",
"is",
"the",
"same",
"as",
"one",
"of",
"the",
"welcome",
"projects",
"we",
"ve",
"previously",
"opened",
"or",
"the",
"one",
"for",
"the",
"current",
"build",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectModel.js#L1351-L1363
|
train
|
adobe/brackets
|
src/extensions/default/InAppNotifications/main.js
|
_getVersionInfoUrl
|
function _getVersionInfoUrl(localeParam) {
var locale = localeParam || brackets.getLocale();
if (locale.length > 2) {
locale = locale.substring(0, 2);
}
return brackets.config.notification_info_url.replace("<locale>", locale);
}
|
javascript
|
function _getVersionInfoUrl(localeParam) {
var locale = localeParam || brackets.getLocale();
if (locale.length > 2) {
locale = locale.substring(0, 2);
}
return brackets.config.notification_info_url.replace("<locale>", locale);
}
|
[
"function",
"_getVersionInfoUrl",
"(",
"localeParam",
")",
"{",
"var",
"locale",
"=",
"localeParam",
"||",
"brackets",
".",
"getLocale",
"(",
")",
";",
"if",
"(",
"locale",
".",
"length",
">",
"2",
")",
"{",
"locale",
"=",
"locale",
".",
"substring",
"(",
"0",
",",
"2",
")",
";",
"}",
"return",
"brackets",
".",
"config",
".",
"notification_info_url",
".",
"replace",
"(",
"\"<locale>\"",
",",
"locale",
")",
";",
"}"
] |
Constructs notification info URL for XHR
@param {string=} localeParam - optional locale, defaults to 'brackets.getLocale()' when omitted.
@returns {string} the new notification info url
|
[
"Constructs",
"notification",
"info",
"URL",
"for",
"XHR"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InAppNotifications/main.js#L55-L64
|
train
|
adobe/brackets
|
src/extensions/default/InAppNotifications/main.js
|
_getNotificationInformation
|
function _getNotificationInformation(_notificationInfoUrl) {
// Last time the versionInfoURL was fetched
var lastInfoURLFetchTime = PreferencesManager.getViewState("lastNotificationURLFetchTime");
var result = new $.Deferred();
var fetchData = false;
var data;
// If we don't have data saved in prefs, fetch
data = PreferencesManager.getViewState("notificationInfo");
if (!data) {
fetchData = true;
}
// If more than 24 hours have passed since our last fetch, fetch again
if (Date.now() > lastInfoURLFetchTime + ONE_DAY) {
fetchData = true;
}
if (fetchData) {
var lookupPromise = new $.Deferred(),
localNotificationInfoUrl;
// If the current locale isn't "en" or "en-US", check whether we actually have a
// locale-specific notification target, and fall back to "en" if not.
var locale = brackets.getLocale().toLowerCase();
if (locale !== "en" && locale !== "en-us") {
localNotificationInfoUrl = _notificationInfoUrl || _getVersionInfoUrl();
// Check if we can reach a locale specific notifications source
$.ajax({
url: localNotificationInfoUrl,
cache: false,
type: "HEAD"
}).fail(function (jqXHR, status, error) {
// Fallback to "en" locale
localNotificationInfoUrl = _getVersionInfoUrl("en");
}).always(function (jqXHR, status, error) {
lookupPromise.resolve();
});
} else {
localNotificationInfoUrl = _notificationInfoUrl || _getVersionInfoUrl("en");
lookupPromise.resolve();
}
lookupPromise.done(function () {
$.ajax({
url: localNotificationInfoUrl,
dataType: "json",
cache: false
}).done(function (notificationInfo, textStatus, jqXHR) {
lastInfoURLFetchTime = (new Date()).getTime();
PreferencesManager.setViewState("lastNotificationURLFetchTime", lastInfoURLFetchTime);
PreferencesManager.setViewState("notificationInfo", notificationInfo);
result.resolve(notificationInfo);
}).fail(function (jqXHR, status, error) {
// When loading data for unit tests, the error handler is
// called but the responseText is valid. Try to use it here,
// but *don't* save the results in prefs.
if (!jqXHR.responseText) {
// Text is NULL or empty string, reject().
result.reject();
return;
}
try {
data = JSON.parse(jqXHR.responseText);
result.resolve(data);
} catch (e) {
result.reject();
}
});
});
} else {
result.resolve(data);
}
return result.promise();
}
|
javascript
|
function _getNotificationInformation(_notificationInfoUrl) {
// Last time the versionInfoURL was fetched
var lastInfoURLFetchTime = PreferencesManager.getViewState("lastNotificationURLFetchTime");
var result = new $.Deferred();
var fetchData = false;
var data;
// If we don't have data saved in prefs, fetch
data = PreferencesManager.getViewState("notificationInfo");
if (!data) {
fetchData = true;
}
// If more than 24 hours have passed since our last fetch, fetch again
if (Date.now() > lastInfoURLFetchTime + ONE_DAY) {
fetchData = true;
}
if (fetchData) {
var lookupPromise = new $.Deferred(),
localNotificationInfoUrl;
// If the current locale isn't "en" or "en-US", check whether we actually have a
// locale-specific notification target, and fall back to "en" if not.
var locale = brackets.getLocale().toLowerCase();
if (locale !== "en" && locale !== "en-us") {
localNotificationInfoUrl = _notificationInfoUrl || _getVersionInfoUrl();
// Check if we can reach a locale specific notifications source
$.ajax({
url: localNotificationInfoUrl,
cache: false,
type: "HEAD"
}).fail(function (jqXHR, status, error) {
// Fallback to "en" locale
localNotificationInfoUrl = _getVersionInfoUrl("en");
}).always(function (jqXHR, status, error) {
lookupPromise.resolve();
});
} else {
localNotificationInfoUrl = _notificationInfoUrl || _getVersionInfoUrl("en");
lookupPromise.resolve();
}
lookupPromise.done(function () {
$.ajax({
url: localNotificationInfoUrl,
dataType: "json",
cache: false
}).done(function (notificationInfo, textStatus, jqXHR) {
lastInfoURLFetchTime = (new Date()).getTime();
PreferencesManager.setViewState("lastNotificationURLFetchTime", lastInfoURLFetchTime);
PreferencesManager.setViewState("notificationInfo", notificationInfo);
result.resolve(notificationInfo);
}).fail(function (jqXHR, status, error) {
// When loading data for unit tests, the error handler is
// called but the responseText is valid. Try to use it here,
// but *don't* save the results in prefs.
if (!jqXHR.responseText) {
// Text is NULL or empty string, reject().
result.reject();
return;
}
try {
data = JSON.parse(jqXHR.responseText);
result.resolve(data);
} catch (e) {
result.reject();
}
});
});
} else {
result.resolve(data);
}
return result.promise();
}
|
[
"function",
"_getNotificationInformation",
"(",
"_notificationInfoUrl",
")",
"{",
"var",
"lastInfoURLFetchTime",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"lastNotificationURLFetchTime\"",
")",
";",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"var",
"fetchData",
"=",
"false",
";",
"var",
"data",
";",
"data",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"notificationInfo\"",
")",
";",
"if",
"(",
"!",
"data",
")",
"{",
"fetchData",
"=",
"true",
";",
"}",
"if",
"(",
"Date",
".",
"now",
"(",
")",
">",
"lastInfoURLFetchTime",
"+",
"ONE_DAY",
")",
"{",
"fetchData",
"=",
"true",
";",
"}",
"if",
"(",
"fetchData",
")",
"{",
"var",
"lookupPromise",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"localNotificationInfoUrl",
";",
"var",
"locale",
"=",
"brackets",
".",
"getLocale",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"locale",
"!==",
"\"en\"",
"&&",
"locale",
"!==",
"\"en-us\"",
")",
"{",
"localNotificationInfoUrl",
"=",
"_notificationInfoUrl",
"||",
"_getVersionInfoUrl",
"(",
")",
";",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"localNotificationInfoUrl",
",",
"cache",
":",
"false",
",",
"type",
":",
"\"HEAD\"",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"localNotificationInfoUrl",
"=",
"_getVersionInfoUrl",
"(",
"\"en\"",
")",
";",
"}",
")",
".",
"always",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"lookupPromise",
".",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"localNotificationInfoUrl",
"=",
"_notificationInfoUrl",
"||",
"_getVersionInfoUrl",
"(",
"\"en\"",
")",
";",
"lookupPromise",
".",
"resolve",
"(",
")",
";",
"}",
"lookupPromise",
".",
"done",
"(",
"function",
"(",
")",
"{",
"$",
".",
"ajax",
"(",
"{",
"url",
":",
"localNotificationInfoUrl",
",",
"dataType",
":",
"\"json\"",
",",
"cache",
":",
"false",
"}",
")",
".",
"done",
"(",
"function",
"(",
"notificationInfo",
",",
"textStatus",
",",
"jqXHR",
")",
"{",
"lastInfoURLFetchTime",
"=",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"lastNotificationURLFetchTime\"",
",",
"lastInfoURLFetchTime",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"notificationInfo\"",
",",
"notificationInfo",
")",
";",
"result",
".",
"resolve",
"(",
"notificationInfo",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"jqXHR",
",",
"status",
",",
"error",
")",
"{",
"if",
"(",
"!",
"jqXHR",
".",
"responseText",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"return",
";",
"}",
"try",
"{",
"data",
"=",
"JSON",
".",
"parse",
"(",
"jqXHR",
".",
"responseText",
")",
";",
"result",
".",
"resolve",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"resolve",
"(",
"data",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Get a data structure that has information for all Brackets targeted notifications.
_notificationInfoUrl is used for unit testing.
|
[
"Get",
"a",
"data",
"structure",
"that",
"has",
"information",
"for",
"all",
"Brackets",
"targeted",
"notifications",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InAppNotifications/main.js#L71-L149
|
train
|
adobe/brackets
|
src/extensions/default/InAppNotifications/main.js
|
checkForNotification
|
function checkForNotification(versionInfoUrl) {
var result = new $.Deferred();
_getNotificationInformation(versionInfoUrl)
.done(function (notificationInfo) {
// Get all available notifications
var notifications = notificationInfo.notifications;
if (notifications && notifications.length > 0) {
// Iterate through notifications and act only on the most recent
// applicable notification
notifications.every(function(notificationObj) {
// Only show the notification overlay if the user hasn't been
// alerted of this notification
if (_checkNotificationValidity(notificationObj)) {
if (notificationObj.silent) {
// silent notifications, to gather user validity based on filters
HealthLogger.sendAnalyticsData("notification", notificationObj.sequence, "handled");
} else {
showNotification(notificationObj);
}
// Break, we have acted on one notification already
return false;
}
// Continue, we haven't yet got a notification to act on
return true;
});
}
result.resolve();
})
.fail(function () {
// Error fetching the update data. If this is a forced check, alert the user
result.reject();
});
return result.promise();
}
|
javascript
|
function checkForNotification(versionInfoUrl) {
var result = new $.Deferred();
_getNotificationInformation(versionInfoUrl)
.done(function (notificationInfo) {
// Get all available notifications
var notifications = notificationInfo.notifications;
if (notifications && notifications.length > 0) {
// Iterate through notifications and act only on the most recent
// applicable notification
notifications.every(function(notificationObj) {
// Only show the notification overlay if the user hasn't been
// alerted of this notification
if (_checkNotificationValidity(notificationObj)) {
if (notificationObj.silent) {
// silent notifications, to gather user validity based on filters
HealthLogger.sendAnalyticsData("notification", notificationObj.sequence, "handled");
} else {
showNotification(notificationObj);
}
// Break, we have acted on one notification already
return false;
}
// Continue, we haven't yet got a notification to act on
return true;
});
}
result.resolve();
})
.fail(function () {
// Error fetching the update data. If this is a forced check, alert the user
result.reject();
});
return result.promise();
}
|
[
"function",
"checkForNotification",
"(",
"versionInfoUrl",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"_getNotificationInformation",
"(",
"versionInfoUrl",
")",
".",
"done",
"(",
"function",
"(",
"notificationInfo",
")",
"{",
"var",
"notifications",
"=",
"notificationInfo",
".",
"notifications",
";",
"if",
"(",
"notifications",
"&&",
"notifications",
".",
"length",
">",
"0",
")",
"{",
"notifications",
".",
"every",
"(",
"function",
"(",
"notificationObj",
")",
"{",
"if",
"(",
"_checkNotificationValidity",
"(",
"notificationObj",
")",
")",
"{",
"if",
"(",
"notificationObj",
".",
"silent",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"\"notification\"",
",",
"notificationObj",
".",
"sequence",
",",
"\"handled\"",
")",
";",
"}",
"else",
"{",
"showNotification",
"(",
"notificationObj",
")",
";",
"}",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"}",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Check for notifications, notification overlays are always displayed
@return {$.Promise} jQuery Promise object that is resolved or rejected after the notification check is complete.
|
[
"Check",
"for",
"notifications",
"notification",
"overlays",
"are",
"always",
"displayed"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/InAppNotifications/main.js#L157-L192
|
train
|
adobe/brackets
|
src/utils/EventDispatcher.js
|
splitNs
|
function splitNs(eventStr) {
var dot = eventStr.indexOf(".");
if (dot === -1) {
return { eventName: eventStr };
} else {
return { eventName: eventStr.substring(0, dot), ns: eventStr.substring(dot) };
}
}
|
javascript
|
function splitNs(eventStr) {
var dot = eventStr.indexOf(".");
if (dot === -1) {
return { eventName: eventStr };
} else {
return { eventName: eventStr.substring(0, dot), ns: eventStr.substring(dot) };
}
}
|
[
"function",
"splitNs",
"(",
"eventStr",
")",
"{",
"var",
"dot",
"=",
"eventStr",
".",
"indexOf",
"(",
"\".\"",
")",
";",
"if",
"(",
"dot",
"===",
"-",
"1",
")",
"{",
"return",
"{",
"eventName",
":",
"eventStr",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"eventName",
":",
"eventStr",
".",
"substring",
"(",
"0",
",",
"dot",
")",
",",
"ns",
":",
"eventStr",
".",
"substring",
"(",
"dot",
")",
"}",
";",
"}",
"}"
] |
Split "event.namespace" string into its two parts; both parts are optional.
@param {string} eventName Event name and/or trailing ".namespace"
@return {!{event:string, ns:string}} Uses "" for missing parts.
|
[
"Split",
"event",
".",
"namespace",
"string",
"into",
"its",
"two",
"parts",
";",
"both",
"parts",
"are",
"optional",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/EventDispatcher.js#L66-L73
|
train
|
adobe/brackets
|
src/extensions/default/NoDistractions/main.js
|
_hidePanelsIfRequired
|
function _hidePanelsIfRequired() {
var panelIDs = WorkspaceManager.getAllPanelIDs();
_previouslyOpenPanelIDs = [];
panelIDs.forEach(function (panelID) {
var panel = WorkspaceManager.getPanelForID(panelID);
if (panel && panel.isVisible()) {
panel.hide();
_previouslyOpenPanelIDs.push(panelID);
}
});
}
|
javascript
|
function _hidePanelsIfRequired() {
var panelIDs = WorkspaceManager.getAllPanelIDs();
_previouslyOpenPanelIDs = [];
panelIDs.forEach(function (panelID) {
var panel = WorkspaceManager.getPanelForID(panelID);
if (panel && panel.isVisible()) {
panel.hide();
_previouslyOpenPanelIDs.push(panelID);
}
});
}
|
[
"function",
"_hidePanelsIfRequired",
"(",
")",
"{",
"var",
"panelIDs",
"=",
"WorkspaceManager",
".",
"getAllPanelIDs",
"(",
")",
";",
"_previouslyOpenPanelIDs",
"=",
"[",
"]",
";",
"panelIDs",
".",
"forEach",
"(",
"function",
"(",
"panelID",
")",
"{",
"var",
"panel",
"=",
"WorkspaceManager",
".",
"getPanelForID",
"(",
"panelID",
")",
";",
"if",
"(",
"panel",
"&&",
"panel",
".",
"isVisible",
"(",
")",
")",
"{",
"panel",
".",
"hide",
"(",
")",
";",
"_previouslyOpenPanelIDs",
".",
"push",
"(",
"panelID",
")",
";",
"}",
"}",
")",
";",
"}"
] |
hide all open panels
|
[
"hide",
"all",
"open",
"panels"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NoDistractions/main.js#L77-L87
|
train
|
adobe/brackets
|
src/extensions/default/NoDistractions/main.js
|
initializeCommands
|
function initializeCommands() {
CommandManager.register(Strings.CMD_TOGGLE_PURE_CODE, CMD_TOGGLE_PURE_CODE, _togglePureCode);
CommandManager.register(Strings.CMD_TOGGLE_PANELS, CMD_TOGGLE_PANELS, _togglePanels);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(CMD_TOGGLE_PANELS, "", Menus.AFTER, Commands.VIEW_HIDE_SIDEBAR);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(CMD_TOGGLE_PURE_CODE, "", Menus.AFTER, CMD_TOGGLE_PANELS);
KeyBindingManager.addBinding(CMD_TOGGLE_PURE_CODE, [ {key: togglePureCodeKey}, {key: togglePureCodeKeyMac, platform: "mac"} ]);
//default toggle panel shortcut was ctrl+shift+` as it is present in one vertical line in the keyboard. However, we later learnt
//from IQE team than non-English keyboards does not have the ` char. So added one more shortcut ctrl+shift+1 which will be preferred
KeyBindingManager.addBinding(CMD_TOGGLE_PANELS, [ {key: togglePanelsKey}, {key: togglePanelsKeyMac, platform: "mac"} ]);
KeyBindingManager.addBinding(CMD_TOGGLE_PANELS, [ {key: togglePanelsKey_EN}, {key: togglePanelsKeyMac_EN, platform: "mac"} ]);
}
|
javascript
|
function initializeCommands() {
CommandManager.register(Strings.CMD_TOGGLE_PURE_CODE, CMD_TOGGLE_PURE_CODE, _togglePureCode);
CommandManager.register(Strings.CMD_TOGGLE_PANELS, CMD_TOGGLE_PANELS, _togglePanels);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(CMD_TOGGLE_PANELS, "", Menus.AFTER, Commands.VIEW_HIDE_SIDEBAR);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(CMD_TOGGLE_PURE_CODE, "", Menus.AFTER, CMD_TOGGLE_PANELS);
KeyBindingManager.addBinding(CMD_TOGGLE_PURE_CODE, [ {key: togglePureCodeKey}, {key: togglePureCodeKeyMac, platform: "mac"} ]);
//default toggle panel shortcut was ctrl+shift+` as it is present in one vertical line in the keyboard. However, we later learnt
//from IQE team than non-English keyboards does not have the ` char. So added one more shortcut ctrl+shift+1 which will be preferred
KeyBindingManager.addBinding(CMD_TOGGLE_PANELS, [ {key: togglePanelsKey}, {key: togglePanelsKeyMac, platform: "mac"} ]);
KeyBindingManager.addBinding(CMD_TOGGLE_PANELS, [ {key: togglePanelsKey_EN}, {key: togglePanelsKeyMac_EN, platform: "mac"} ]);
}
|
[
"function",
"initializeCommands",
"(",
")",
"{",
"CommandManager",
".",
"register",
"(",
"Strings",
".",
"CMD_TOGGLE_PURE_CODE",
",",
"CMD_TOGGLE_PURE_CODE",
",",
"_togglePureCode",
")",
";",
"CommandManager",
".",
"register",
"(",
"Strings",
".",
"CMD_TOGGLE_PANELS",
",",
"CMD_TOGGLE_PANELS",
",",
"_togglePanels",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"addMenuItem",
"(",
"CMD_TOGGLE_PANELS",
",",
"\"\"",
",",
"Menus",
".",
"AFTER",
",",
"Commands",
".",
"VIEW_HIDE_SIDEBAR",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"addMenuItem",
"(",
"CMD_TOGGLE_PURE_CODE",
",",
"\"\"",
",",
"Menus",
".",
"AFTER",
",",
"CMD_TOGGLE_PANELS",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"CMD_TOGGLE_PURE_CODE",
",",
"[",
"{",
"key",
":",
"togglePureCodeKey",
"}",
",",
"{",
"key",
":",
"togglePureCodeKeyMac",
",",
"platform",
":",
"\"mac\"",
"}",
"]",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"CMD_TOGGLE_PANELS",
",",
"[",
"{",
"key",
":",
"togglePanelsKey",
"}",
",",
"{",
"key",
":",
"togglePanelsKeyMac",
",",
"platform",
":",
"\"mac\"",
"}",
"]",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"CMD_TOGGLE_PANELS",
",",
"[",
"{",
"key",
":",
"togglePanelsKey_EN",
"}",
",",
"{",
"key",
":",
"togglePanelsKeyMac_EN",
",",
"platform",
":",
"\"mac\"",
"}",
"]",
")",
";",
"}"
] |
Register the Commands , add the Menu Items and key bindings
|
[
"Register",
"the",
"Commands",
"add",
"the",
"Menu",
"Items",
"and",
"key",
"bindings"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NoDistractions/main.js#L154-L167
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/EditAgent.js
|
_findChangedCharacters
|
function _findChangedCharacters(oldValue, value) {
if (oldValue === value) {
return undefined;
}
var length = oldValue.length;
var index = 0;
// find the first character that changed
var i;
for (i = 0; i < length; i++) {
if (value[i] !== oldValue[i]) {
break;
}
}
index += i;
value = value.substr(i);
length -= i;
// find the last character that changed
for (i = 0; i < length; i++) {
if (value[value.length - 1 - i] !== oldValue[oldValue.length - 1 - i]) {
break;
}
}
length -= i;
value = value.substr(0, value.length - i);
return { from: index, to: index + length, text: value };
}
|
javascript
|
function _findChangedCharacters(oldValue, value) {
if (oldValue === value) {
return undefined;
}
var length = oldValue.length;
var index = 0;
// find the first character that changed
var i;
for (i = 0; i < length; i++) {
if (value[i] !== oldValue[i]) {
break;
}
}
index += i;
value = value.substr(i);
length -= i;
// find the last character that changed
for (i = 0; i < length; i++) {
if (value[value.length - 1 - i] !== oldValue[oldValue.length - 1 - i]) {
break;
}
}
length -= i;
value = value.substr(0, value.length - i);
return { from: index, to: index + length, text: value };
}
|
[
"function",
"_findChangedCharacters",
"(",
"oldValue",
",",
"value",
")",
"{",
"if",
"(",
"oldValue",
"===",
"value",
")",
"{",
"return",
"undefined",
";",
"}",
"var",
"length",
"=",
"oldValue",
".",
"length",
";",
"var",
"index",
"=",
"0",
";",
"var",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"value",
"[",
"i",
"]",
"!==",
"oldValue",
"[",
"i",
"]",
")",
"{",
"break",
";",
"}",
"}",
"index",
"+=",
"i",
";",
"value",
"=",
"value",
".",
"substr",
"(",
"i",
")",
";",
"length",
"-=",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"value",
"[",
"value",
".",
"length",
"-",
"1",
"-",
"i",
"]",
"!==",
"oldValue",
"[",
"oldValue",
".",
"length",
"-",
"1",
"-",
"i",
"]",
")",
"{",
"break",
";",
"}",
"}",
"length",
"-=",
"i",
";",
"value",
"=",
"value",
".",
"substr",
"(",
"0",
",",
"value",
".",
"length",
"-",
"i",
")",
";",
"return",
"{",
"from",
":",
"index",
",",
"to",
":",
"index",
"+",
"length",
",",
"text",
":",
"value",
"}",
";",
"}"
] |
Find changed characters
@param {string} old value
@param {string} changed value
@return {from, to, text}
|
[
"Find",
"changed",
"characters"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/EditAgent.js#L45-L73
|
train
|
adobe/brackets
|
src/view/WorkspaceManager.js
|
updateResizeLimits
|
function updateResizeLimits() {
var editorAreaHeight = $editorHolder.height();
$editorHolder.siblings().each(function (i, elem) {
var $elem = $(elem);
if ($elem.css("display") === "none") {
$elem.data("maxsize", editorAreaHeight);
} else {
$elem.data("maxsize", editorAreaHeight + $elem.outerHeight());
}
});
}
|
javascript
|
function updateResizeLimits() {
var editorAreaHeight = $editorHolder.height();
$editorHolder.siblings().each(function (i, elem) {
var $elem = $(elem);
if ($elem.css("display") === "none") {
$elem.data("maxsize", editorAreaHeight);
} else {
$elem.data("maxsize", editorAreaHeight + $elem.outerHeight());
}
});
}
|
[
"function",
"updateResizeLimits",
"(",
")",
"{",
"var",
"editorAreaHeight",
"=",
"$editorHolder",
".",
"height",
"(",
")",
";",
"$editorHolder",
".",
"siblings",
"(",
")",
".",
"each",
"(",
"function",
"(",
"i",
",",
"elem",
")",
"{",
"var",
"$elem",
"=",
"$",
"(",
"elem",
")",
";",
"if",
"(",
"$elem",
".",
"css",
"(",
"\"display\"",
")",
"===",
"\"none\"",
")",
"{",
"$elem",
".",
"data",
"(",
"\"maxsize\"",
",",
"editorAreaHeight",
")",
";",
"}",
"else",
"{",
"$elem",
".",
"data",
"(",
"\"maxsize\"",
",",
"editorAreaHeight",
"+",
"$elem",
".",
"outerHeight",
"(",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Updates panel resize limits to disallow making panels big enough to shrink editor area below 0
|
[
"Updates",
"panel",
"resize",
"limits",
"to",
"disallow",
"making",
"panels",
"big",
"enough",
"to",
"shrink",
"editor",
"area",
"below",
"0"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/WorkspaceManager.js#L91-L102
|
train
|
adobe/brackets
|
src/view/WorkspaceManager.js
|
handleWindowResize
|
function handleWindowResize() {
// These are not initialized in Jasmine Spec Runner window until a test
// is run that creates a mock document.
if (!$windowContent || !$editorHolder) {
return;
}
// FIXME (issue #4564) Workaround https://github.com/codemirror/CodeMirror/issues/1787
triggerUpdateLayout();
if (!windowResizing) {
windowResizing = true;
// We don't need any fancy debouncing here - we just need to react before the user can start
// resizing any panels at the new window size. So just listen for first mousemove once the
// window resize releases mouse capture.
$(window.document).one("mousemove", function () {
windowResizing = false;
updateResizeLimits();
});
}
}
|
javascript
|
function handleWindowResize() {
// These are not initialized in Jasmine Spec Runner window until a test
// is run that creates a mock document.
if (!$windowContent || !$editorHolder) {
return;
}
// FIXME (issue #4564) Workaround https://github.com/codemirror/CodeMirror/issues/1787
triggerUpdateLayout();
if (!windowResizing) {
windowResizing = true;
// We don't need any fancy debouncing here - we just need to react before the user can start
// resizing any panels at the new window size. So just listen for first mousemove once the
// window resize releases mouse capture.
$(window.document).one("mousemove", function () {
windowResizing = false;
updateResizeLimits();
});
}
}
|
[
"function",
"handleWindowResize",
"(",
")",
"{",
"if",
"(",
"!",
"$windowContent",
"||",
"!",
"$editorHolder",
")",
"{",
"return",
";",
"}",
"triggerUpdateLayout",
"(",
")",
";",
"if",
"(",
"!",
"windowResizing",
")",
"{",
"windowResizing",
"=",
"true",
";",
"$",
"(",
"window",
".",
"document",
")",
".",
"one",
"(",
"\"mousemove\"",
",",
"function",
"(",
")",
"{",
"windowResizing",
"=",
"false",
";",
"updateResizeLimits",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Trigger editor area resize whenever the window is resized
|
[
"Trigger",
"editor",
"area",
"resize",
"whenever",
"the",
"window",
"is",
"resized"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/WorkspaceManager.js#L123-L144
|
train
|
adobe/brackets
|
src/view/WorkspaceManager.js
|
createBottomPanel
|
function createBottomPanel(id, $panel, minSize) {
$panel.insertBefore("#status-bar");
$panel.hide();
updateResizeLimits(); // initialize panel's max size
panelIDMap[id] = new Panel($panel, minSize);
panelIDMap[id].panelID = id;
return panelIDMap[id];
}
|
javascript
|
function createBottomPanel(id, $panel, minSize) {
$panel.insertBefore("#status-bar");
$panel.hide();
updateResizeLimits(); // initialize panel's max size
panelIDMap[id] = new Panel($panel, minSize);
panelIDMap[id].panelID = id;
return panelIDMap[id];
}
|
[
"function",
"createBottomPanel",
"(",
"id",
",",
"$panel",
",",
"minSize",
")",
"{",
"$panel",
".",
"insertBefore",
"(",
"\"#status-bar\"",
")",
";",
"$panel",
".",
"hide",
"(",
")",
";",
"updateResizeLimits",
"(",
")",
";",
"panelIDMap",
"[",
"id",
"]",
"=",
"new",
"Panel",
"(",
"$panel",
",",
"minSize",
")",
";",
"panelIDMap",
"[",
"id",
"]",
".",
"panelID",
"=",
"id",
";",
"return",
"panelIDMap",
"[",
"id",
"]",
";",
"}"
] |
Creates a new resizable panel beneath the editor area and above the status bar footer. Panel is initially invisible.
The panel's size & visibility are automatically saved & restored as a view-state preference.
@param {!string} id Unique id for this panel. Use package-style naming, e.g. "myextension.feature.panelname"
@param {!jQueryObject} $panel DOM content to use as the panel. Need not be in the document yet. Must have an id
attribute, for use as a preferences key.
@param {number=} minSize Minimum height of panel in px.
@return {!Panel}
|
[
"Creates",
"a",
"new",
"resizable",
"panel",
"beneath",
"the",
"editor",
"area",
"and",
"above",
"the",
"status",
"bar",
"footer",
".",
"Panel",
"is",
"initially",
"invisible",
".",
"The",
"panel",
"s",
"size",
"&",
"visibility",
"are",
"automatically",
"saved",
"&",
"restored",
"as",
"a",
"view",
"-",
"state",
"preference",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/WorkspaceManager.js#L227-L236
|
train
|
adobe/brackets
|
src/view/WorkspaceManager.js
|
getAllPanelIDs
|
function getAllPanelIDs() {
var property, panelIDs = [];
for (property in panelIDMap) {
if (panelIDMap.hasOwnProperty(property)) {
panelIDs.push(property);
}
}
return panelIDs;
}
|
javascript
|
function getAllPanelIDs() {
var property, panelIDs = [];
for (property in panelIDMap) {
if (panelIDMap.hasOwnProperty(property)) {
panelIDs.push(property);
}
}
return panelIDs;
}
|
[
"function",
"getAllPanelIDs",
"(",
")",
"{",
"var",
"property",
",",
"panelIDs",
"=",
"[",
"]",
";",
"for",
"(",
"property",
"in",
"panelIDMap",
")",
"{",
"if",
"(",
"panelIDMap",
".",
"hasOwnProperty",
"(",
"property",
")",
")",
"{",
"panelIDs",
".",
"push",
"(",
"property",
")",
";",
"}",
"}",
"return",
"panelIDs",
";",
"}"
] |
Returns an array of all panel ID's
@returns {Array} List of ID's of all bottom panels
|
[
"Returns",
"an",
"array",
"of",
"all",
"panel",
"ID",
"s"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/WorkspaceManager.js#L242-L250
|
train
|
adobe/brackets
|
src/utils/HealthLogger.js
|
getAggregatedHealthData
|
function getAggregatedHealthData() {
var healthData = getStoredHealthData();
$.extend(healthData, PerfUtils.getHealthReport());
$.extend(healthData, FindUtils.getHealthReport());
return healthData;
}
|
javascript
|
function getAggregatedHealthData() {
var healthData = getStoredHealthData();
$.extend(healthData, PerfUtils.getHealthReport());
$.extend(healthData, FindUtils.getHealthReport());
return healthData;
}
|
[
"function",
"getAggregatedHealthData",
"(",
")",
"{",
"var",
"healthData",
"=",
"getStoredHealthData",
"(",
")",
";",
"$",
".",
"extend",
"(",
"healthData",
",",
"PerfUtils",
".",
"getHealthReport",
"(",
")",
")",
";",
"$",
".",
"extend",
"(",
"healthData",
",",
"FindUtils",
".",
"getHealthReport",
"(",
")",
")",
";",
"return",
"healthData",
";",
"}"
] |
Return the aggregate of all health data logged till now from all sources
@return {Object} Health Data aggregated till now
|
[
"Return",
"the",
"aggregate",
"of",
"all",
"health",
"data",
"logged",
"till",
"now",
"from",
"all",
"sources"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/HealthLogger.js#L85-L90
|
train
|
adobe/brackets
|
src/utils/HealthLogger.js
|
setHealthDataLog
|
function setHealthDataLog(key, dataObject) {
var healthData = getStoredHealthData();
healthData[key] = dataObject;
setHealthData(healthData);
}
|
javascript
|
function setHealthDataLog(key, dataObject) {
var healthData = getStoredHealthData();
healthData[key] = dataObject;
setHealthData(healthData);
}
|
[
"function",
"setHealthDataLog",
"(",
"key",
",",
"dataObject",
")",
"{",
"var",
"healthData",
"=",
"getStoredHealthData",
"(",
")",
";",
"healthData",
"[",
"key",
"]",
"=",
"dataObject",
";",
"setHealthData",
"(",
"healthData",
")",
";",
"}"
] |
Sets the health data for the given key
@param {Object} dataObject The object to be stored as health data for the key
|
[
"Sets",
"the",
"health",
"data",
"for",
"the",
"given",
"key"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/HealthLogger.js#L116-L120
|
train
|
adobe/brackets
|
src/utils/HealthLogger.js
|
fileOpened
|
function fileOpened(filePath, addedToWorkingSet, encoding) {
if (!shouldLogHealthData()) {
return;
}
var fileExtension = FileUtils.getFileExtension(filePath),
language = LanguageManager.getLanguageForPath(filePath),
healthData = getStoredHealthData(),
fileExtCountMap = [];
healthData.fileStats = healthData.fileStats || {
openedFileExt : {},
workingSetFileExt : {},
openedFileEncoding: {}
};
if (language.getId() !== "unknown") {
fileExtCountMap = addedToWorkingSet ? healthData.fileStats.workingSetFileExt : healthData.fileStats.openedFileExt;
if (!fileExtCountMap[fileExtension]) {
fileExtCountMap[fileExtension] = 0;
}
fileExtCountMap[fileExtension]++;
setHealthData(healthData);
}
if (encoding) {
var fileEncCountMap = healthData.fileStats.openedFileEncoding;
if (!fileEncCountMap) {
healthData.fileStats.openedFileEncoding = {};
fileEncCountMap = healthData.fileStats.openedFileEncoding;
}
if (!fileEncCountMap[encoding]) {
fileEncCountMap[encoding] = 0;
}
fileEncCountMap[encoding]++;
setHealthData(healthData);
}
sendAnalyticsData(commonStrings.USAGE + commonStrings.FILE_OPEN + language._name,
commonStrings.USAGE,
commonStrings.FILE_OPEN,
language._name.toLowerCase()
);
}
|
javascript
|
function fileOpened(filePath, addedToWorkingSet, encoding) {
if (!shouldLogHealthData()) {
return;
}
var fileExtension = FileUtils.getFileExtension(filePath),
language = LanguageManager.getLanguageForPath(filePath),
healthData = getStoredHealthData(),
fileExtCountMap = [];
healthData.fileStats = healthData.fileStats || {
openedFileExt : {},
workingSetFileExt : {},
openedFileEncoding: {}
};
if (language.getId() !== "unknown") {
fileExtCountMap = addedToWorkingSet ? healthData.fileStats.workingSetFileExt : healthData.fileStats.openedFileExt;
if (!fileExtCountMap[fileExtension]) {
fileExtCountMap[fileExtension] = 0;
}
fileExtCountMap[fileExtension]++;
setHealthData(healthData);
}
if (encoding) {
var fileEncCountMap = healthData.fileStats.openedFileEncoding;
if (!fileEncCountMap) {
healthData.fileStats.openedFileEncoding = {};
fileEncCountMap = healthData.fileStats.openedFileEncoding;
}
if (!fileEncCountMap[encoding]) {
fileEncCountMap[encoding] = 0;
}
fileEncCountMap[encoding]++;
setHealthData(healthData);
}
sendAnalyticsData(commonStrings.USAGE + commonStrings.FILE_OPEN + language._name,
commonStrings.USAGE,
commonStrings.FILE_OPEN,
language._name.toLowerCase()
);
}
|
[
"function",
"fileOpened",
"(",
"filePath",
",",
"addedToWorkingSet",
",",
"encoding",
")",
"{",
"if",
"(",
"!",
"shouldLogHealthData",
"(",
")",
")",
"{",
"return",
";",
"}",
"var",
"fileExtension",
"=",
"FileUtils",
".",
"getFileExtension",
"(",
"filePath",
")",
",",
"language",
"=",
"LanguageManager",
".",
"getLanguageForPath",
"(",
"filePath",
")",
",",
"healthData",
"=",
"getStoredHealthData",
"(",
")",
",",
"fileExtCountMap",
"=",
"[",
"]",
";",
"healthData",
".",
"fileStats",
"=",
"healthData",
".",
"fileStats",
"||",
"{",
"openedFileExt",
":",
"{",
"}",
",",
"workingSetFileExt",
":",
"{",
"}",
",",
"openedFileEncoding",
":",
"{",
"}",
"}",
";",
"if",
"(",
"language",
".",
"getId",
"(",
")",
"!==",
"\"unknown\"",
")",
"{",
"fileExtCountMap",
"=",
"addedToWorkingSet",
"?",
"healthData",
".",
"fileStats",
".",
"workingSetFileExt",
":",
"healthData",
".",
"fileStats",
".",
"openedFileExt",
";",
"if",
"(",
"!",
"fileExtCountMap",
"[",
"fileExtension",
"]",
")",
"{",
"fileExtCountMap",
"[",
"fileExtension",
"]",
"=",
"0",
";",
"}",
"fileExtCountMap",
"[",
"fileExtension",
"]",
"++",
";",
"setHealthData",
"(",
"healthData",
")",
";",
"}",
"if",
"(",
"encoding",
")",
"{",
"var",
"fileEncCountMap",
"=",
"healthData",
".",
"fileStats",
".",
"openedFileEncoding",
";",
"if",
"(",
"!",
"fileEncCountMap",
")",
"{",
"healthData",
".",
"fileStats",
".",
"openedFileEncoding",
"=",
"{",
"}",
";",
"fileEncCountMap",
"=",
"healthData",
".",
"fileStats",
".",
"openedFileEncoding",
";",
"}",
"if",
"(",
"!",
"fileEncCountMap",
"[",
"encoding",
"]",
")",
"{",
"fileEncCountMap",
"[",
"encoding",
"]",
"=",
"0",
";",
"}",
"fileEncCountMap",
"[",
"encoding",
"]",
"++",
";",
"setHealthData",
"(",
"healthData",
")",
";",
"}",
"sendAnalyticsData",
"(",
"commonStrings",
".",
"USAGE",
"+",
"commonStrings",
".",
"FILE_OPEN",
"+",
"language",
".",
"_name",
",",
"commonStrings",
".",
"USAGE",
",",
"commonStrings",
".",
"FILE_OPEN",
",",
"language",
".",
"_name",
".",
"toLowerCase",
"(",
")",
")",
";",
"}"
] |
Whenever a file is opened call this function. The function will record the number of times
the standard file types have been opened. We only log the standard filetypes
@param {String} filePath The path of the file to be registered
@param {boolean} addedToWorkingSet set to true if extensions of files added to the
working set needs to be logged
|
[
"Whenever",
"a",
"file",
"is",
"opened",
"call",
"this",
"function",
".",
"The",
"function",
"will",
"record",
"the",
"number",
"of",
"times",
"the",
"standard",
"file",
"types",
"have",
"been",
"opened",
".",
"We",
"only",
"log",
"the",
"standard",
"filetypes"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/HealthLogger.js#L149-L190
|
train
|
adobe/brackets
|
src/utils/HealthLogger.js
|
fileSaved
|
function fileSaved(docToSave) {
if (!docToSave) {
return;
}
var fileType = docToSave.language ? docToSave.language._name : "";
sendAnalyticsData(commonStrings.USAGE + commonStrings.FILE_SAVE + fileType,
commonStrings.USAGE,
commonStrings.FILE_SAVE,
fileType.toLowerCase()
);
}
|
javascript
|
function fileSaved(docToSave) {
if (!docToSave) {
return;
}
var fileType = docToSave.language ? docToSave.language._name : "";
sendAnalyticsData(commonStrings.USAGE + commonStrings.FILE_SAVE + fileType,
commonStrings.USAGE,
commonStrings.FILE_SAVE,
fileType.toLowerCase()
);
}
|
[
"function",
"fileSaved",
"(",
"docToSave",
")",
"{",
"if",
"(",
"!",
"docToSave",
")",
"{",
"return",
";",
"}",
"var",
"fileType",
"=",
"docToSave",
".",
"language",
"?",
"docToSave",
".",
"language",
".",
"_name",
":",
"\"\"",
";",
"sendAnalyticsData",
"(",
"commonStrings",
".",
"USAGE",
"+",
"commonStrings",
".",
"FILE_SAVE",
"+",
"fileType",
",",
"commonStrings",
".",
"USAGE",
",",
"commonStrings",
".",
"FILE_SAVE",
",",
"fileType",
".",
"toLowerCase",
"(",
")",
")",
";",
"}"
] |
Whenever a file is saved call this function.
The function will send the analytics Data
We only log the standard filetypes and fileSize
@param {String} filePath The path of the file to be registered
|
[
"Whenever",
"a",
"file",
"is",
"saved",
"call",
"this",
"function",
".",
"The",
"function",
"will",
"send",
"the",
"analytics",
"Data",
"We",
"only",
"log",
"the",
"standard",
"filetypes",
"and",
"fileSize"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/HealthLogger.js#L198-L208
|
train
|
adobe/brackets
|
src/utils/HealthLogger.js
|
fileClosed
|
function fileClosed(file) {
if (!file) {
return;
}
var language = LanguageManager.getLanguageForPath(file._path),
size = -1;
function _sendData(fileSize) {
var subType = "";
if(fileSize/1024 <= 1) {
if(fileSize < 0) {
subType = "";
}
if(fileSize <= 10) {
subType = "Size_0_10KB";
} else if (fileSize <= 50) {
subType = "Size_10_50KB";
} else if (fileSize <= 100) {
subType = "Size_50_100KB";
} else if (fileSize <= 500) {
subType = "Size_100_500KB";
} else {
subType = "Size_500KB_1MB";
}
} else {
fileSize = fileSize/1024;
if(fileSize <= 2) {
subType = "Size_1_2MB";
} else if(fileSize <= 5) {
subType = "Size_2_5MB";
} else {
subType = "Size_Above_5MB";
}
}
sendAnalyticsData(commonStrings.USAGE + commonStrings.FILE_CLOSE + language._name + subType,
commonStrings.USAGE,
commonStrings.FILE_CLOSE,
language._name.toLowerCase(),
subType
);
}
file.stat(function(err, fileStat) {
if(!err) {
size = fileStat.size.valueOf()/1024;
}
_sendData(size);
});
}
|
javascript
|
function fileClosed(file) {
if (!file) {
return;
}
var language = LanguageManager.getLanguageForPath(file._path),
size = -1;
function _sendData(fileSize) {
var subType = "";
if(fileSize/1024 <= 1) {
if(fileSize < 0) {
subType = "";
}
if(fileSize <= 10) {
subType = "Size_0_10KB";
} else if (fileSize <= 50) {
subType = "Size_10_50KB";
} else if (fileSize <= 100) {
subType = "Size_50_100KB";
} else if (fileSize <= 500) {
subType = "Size_100_500KB";
} else {
subType = "Size_500KB_1MB";
}
} else {
fileSize = fileSize/1024;
if(fileSize <= 2) {
subType = "Size_1_2MB";
} else if(fileSize <= 5) {
subType = "Size_2_5MB";
} else {
subType = "Size_Above_5MB";
}
}
sendAnalyticsData(commonStrings.USAGE + commonStrings.FILE_CLOSE + language._name + subType,
commonStrings.USAGE,
commonStrings.FILE_CLOSE,
language._name.toLowerCase(),
subType
);
}
file.stat(function(err, fileStat) {
if(!err) {
size = fileStat.size.valueOf()/1024;
}
_sendData(size);
});
}
|
[
"function",
"fileClosed",
"(",
"file",
")",
"{",
"if",
"(",
"!",
"file",
")",
"{",
"return",
";",
"}",
"var",
"language",
"=",
"LanguageManager",
".",
"getLanguageForPath",
"(",
"file",
".",
"_path",
")",
",",
"size",
"=",
"-",
"1",
";",
"function",
"_sendData",
"(",
"fileSize",
")",
"{",
"var",
"subType",
"=",
"\"\"",
";",
"if",
"(",
"fileSize",
"/",
"1024",
"<=",
"1",
")",
"{",
"if",
"(",
"fileSize",
"<",
"0",
")",
"{",
"subType",
"=",
"\"\"",
";",
"}",
"if",
"(",
"fileSize",
"<=",
"10",
")",
"{",
"subType",
"=",
"\"Size_0_10KB\"",
";",
"}",
"else",
"if",
"(",
"fileSize",
"<=",
"50",
")",
"{",
"subType",
"=",
"\"Size_10_50KB\"",
";",
"}",
"else",
"if",
"(",
"fileSize",
"<=",
"100",
")",
"{",
"subType",
"=",
"\"Size_50_100KB\"",
";",
"}",
"else",
"if",
"(",
"fileSize",
"<=",
"500",
")",
"{",
"subType",
"=",
"\"Size_100_500KB\"",
";",
"}",
"else",
"{",
"subType",
"=",
"\"Size_500KB_1MB\"",
";",
"}",
"}",
"else",
"{",
"fileSize",
"=",
"fileSize",
"/",
"1024",
";",
"if",
"(",
"fileSize",
"<=",
"2",
")",
"{",
"subType",
"=",
"\"Size_1_2MB\"",
";",
"}",
"else",
"if",
"(",
"fileSize",
"<=",
"5",
")",
"{",
"subType",
"=",
"\"Size_2_5MB\"",
";",
"}",
"else",
"{",
"subType",
"=",
"\"Size_Above_5MB\"",
";",
"}",
"}",
"sendAnalyticsData",
"(",
"commonStrings",
".",
"USAGE",
"+",
"commonStrings",
".",
"FILE_CLOSE",
"+",
"language",
".",
"_name",
"+",
"subType",
",",
"commonStrings",
".",
"USAGE",
",",
"commonStrings",
".",
"FILE_CLOSE",
",",
"language",
".",
"_name",
".",
"toLowerCase",
"(",
")",
",",
"subType",
")",
";",
"}",
"file",
".",
"stat",
"(",
"function",
"(",
"err",
",",
"fileStat",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"size",
"=",
"fileStat",
".",
"size",
".",
"valueOf",
"(",
")",
"/",
"1024",
";",
"}",
"_sendData",
"(",
"size",
")",
";",
"}",
")",
";",
"}"
] |
Whenever a file is closed call this function.
The function will send the analytics Data.
We only log the standard filetypes and fileSize
@param {String} filePath The path of the file to be registered
|
[
"Whenever",
"a",
"file",
"is",
"closed",
"call",
"this",
"function",
".",
"The",
"function",
"will",
"send",
"the",
"analytics",
"Data",
".",
"We",
"only",
"log",
"the",
"standard",
"filetypes",
"and",
"fileSize"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/HealthLogger.js#L216-L268
|
train
|
adobe/brackets
|
src/utils/HealthLogger.js
|
searchDone
|
function searchDone(searchType) {
var searchDetails = getHealthDataLog("searchDetails");
if (!searchDetails) {
searchDetails = {};
}
if (!searchDetails[searchType]) {
searchDetails[searchType] = 0;
}
searchDetails[searchType]++;
setHealthDataLog("searchDetails", searchDetails);
}
|
javascript
|
function searchDone(searchType) {
var searchDetails = getHealthDataLog("searchDetails");
if (!searchDetails) {
searchDetails = {};
}
if (!searchDetails[searchType]) {
searchDetails[searchType] = 0;
}
searchDetails[searchType]++;
setHealthDataLog("searchDetails", searchDetails);
}
|
[
"function",
"searchDone",
"(",
"searchType",
")",
"{",
"var",
"searchDetails",
"=",
"getHealthDataLog",
"(",
"\"searchDetails\"",
")",
";",
"if",
"(",
"!",
"searchDetails",
")",
"{",
"searchDetails",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"searchDetails",
"[",
"searchType",
"]",
")",
"{",
"searchDetails",
"[",
"searchType",
"]",
"=",
"0",
";",
"}",
"searchDetails",
"[",
"searchType",
"]",
"++",
";",
"setHealthDataLog",
"(",
"\"searchDetails\"",
",",
"searchDetails",
")",
";",
"}"
] |
Increments health log count for a particular kind of search done
@param {string} searchType The kind of search type that needs to be logged- should be a js var compatible string
|
[
"Increments",
"health",
"log",
"count",
"for",
"a",
"particular",
"kind",
"of",
"search",
"done"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/HealthLogger.js#L294-L304
|
train
|
adobe/brackets
|
src/utils/HealthLogger.js
|
sendAnalyticsData
|
function sendAnalyticsData(eventName, eventCategory, eventSubCategory, eventType, eventSubType) {
var isEventDataAlreadySent = analyticsEventMap.get(eventName),
isHDTracking = PreferencesManager.getExtensionPrefs("healthData").get("healthDataTracking"),
eventParams = {};
if (isHDTracking && !isEventDataAlreadySent && eventName && eventCategory) {
eventParams = {
eventName: eventName,
eventCategory: eventCategory,
eventSubCategory: eventSubCategory || "",
eventType: eventType || "",
eventSubType: eventSubType || ""
};
notifyHealthManagerToSendData(eventParams);
}
}
|
javascript
|
function sendAnalyticsData(eventName, eventCategory, eventSubCategory, eventType, eventSubType) {
var isEventDataAlreadySent = analyticsEventMap.get(eventName),
isHDTracking = PreferencesManager.getExtensionPrefs("healthData").get("healthDataTracking"),
eventParams = {};
if (isHDTracking && !isEventDataAlreadySent && eventName && eventCategory) {
eventParams = {
eventName: eventName,
eventCategory: eventCategory,
eventSubCategory: eventSubCategory || "",
eventType: eventType || "",
eventSubType: eventSubType || ""
};
notifyHealthManagerToSendData(eventParams);
}
}
|
[
"function",
"sendAnalyticsData",
"(",
"eventName",
",",
"eventCategory",
",",
"eventSubCategory",
",",
"eventType",
",",
"eventSubType",
")",
"{",
"var",
"isEventDataAlreadySent",
"=",
"analyticsEventMap",
".",
"get",
"(",
"eventName",
")",
",",
"isHDTracking",
"=",
"PreferencesManager",
".",
"getExtensionPrefs",
"(",
"\"healthData\"",
")",
".",
"get",
"(",
"\"healthDataTracking\"",
")",
",",
"eventParams",
"=",
"{",
"}",
";",
"if",
"(",
"isHDTracking",
"&&",
"!",
"isEventDataAlreadySent",
"&&",
"eventName",
"&&",
"eventCategory",
")",
"{",
"eventParams",
"=",
"{",
"eventName",
":",
"eventName",
",",
"eventCategory",
":",
"eventCategory",
",",
"eventSubCategory",
":",
"eventSubCategory",
"||",
"\"\"",
",",
"eventType",
":",
"eventType",
"||",
"\"\"",
",",
"eventSubType",
":",
"eventSubType",
"||",
"\"\"",
"}",
";",
"notifyHealthManagerToSendData",
"(",
"eventParams",
")",
";",
"}",
"}"
] |
Send Analytics Data
@param {string} eventCategory The kind of Event Category that
needs to be logged- should be a js var compatible string
@param {string} eventSubCategory The kind of Event Sub Category that
needs to be logged- should be a js var compatible string
@param {string} eventType The kind of Event Type that needs to be logged- should be a js var compatible string
@param {string} eventSubType The kind of Event Sub Type that
needs to be logged- should be a js var compatible string
|
[
"Send",
"Analytics",
"Data"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/HealthLogger.js#L324-L339
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevelopmentUtils.js
|
isStaticHtmlFileExt
|
function isStaticHtmlFileExt(filePath) {
if (!filePath) {
return false;
}
return (_staticHtmlFileExts.indexOf(LanguageManager.getLanguageForPath(filePath).getId()) !== -1);
}
|
javascript
|
function isStaticHtmlFileExt(filePath) {
if (!filePath) {
return false;
}
return (_staticHtmlFileExts.indexOf(LanguageManager.getLanguageForPath(filePath).getId()) !== -1);
}
|
[
"function",
"isStaticHtmlFileExt",
"(",
"filePath",
")",
"{",
"if",
"(",
"!",
"filePath",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"_staticHtmlFileExts",
".",
"indexOf",
"(",
"LanguageManager",
".",
"getLanguageForPath",
"(",
"filePath",
")",
".",
"getId",
"(",
")",
")",
"!==",
"-",
"1",
")",
";",
"}"
] |
Determine if file extension is a static html file extension.
@param {string} filePath could be a path, a file name or just a file extension
@return {boolean} Returns true if fileExt is in the list
|
[
"Determine",
"if",
"file",
"extension",
"is",
"a",
"static",
"html",
"file",
"extension",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevelopmentUtils.js#L45-L51
|
train
|
adobe/brackets
|
src/LiveDevelopment/LiveDevelopmentUtils.js
|
isServerHtmlFileExt
|
function isServerHtmlFileExt(filePath) {
if (!filePath) {
return false;
}
return (_serverHtmlFileExts.indexOf(LanguageManager.getLanguageForPath(filePath).getId()) !== -1);
}
|
javascript
|
function isServerHtmlFileExt(filePath) {
if (!filePath) {
return false;
}
return (_serverHtmlFileExts.indexOf(LanguageManager.getLanguageForPath(filePath).getId()) !== -1);
}
|
[
"function",
"isServerHtmlFileExt",
"(",
"filePath",
")",
"{",
"if",
"(",
"!",
"filePath",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"_serverHtmlFileExts",
".",
"indexOf",
"(",
"LanguageManager",
".",
"getLanguageForPath",
"(",
"filePath",
")",
".",
"getId",
"(",
")",
")",
"!==",
"-",
"1",
")",
";",
"}"
] |
Determine if file extension is a server html file extension.
@param {string} filePath could be a path, a file name or just a file extension
@return {boolean} Returns true if fileExt is in the list
|
[
"Determine",
"if",
"file",
"extension",
"is",
"a",
"server",
"html",
"file",
"extension",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/LiveDevelopmentUtils.js#L58-L64
|
train
|
adobe/brackets
|
src/JSUtils/node/ExtractFileContent.js
|
updateDirtyFilesCache
|
function updateDirtyFilesCache(name, action) {
if (action) {
_dirtyFilesCache[name] = true;
} else {
if (_dirtyFilesCache[name]) {
delete _dirtyFilesCache[name];
}
}
}
|
javascript
|
function updateDirtyFilesCache(name, action) {
if (action) {
_dirtyFilesCache[name] = true;
} else {
if (_dirtyFilesCache[name]) {
delete _dirtyFilesCache[name];
}
}
}
|
[
"function",
"updateDirtyFilesCache",
"(",
"name",
",",
"action",
")",
"{",
"if",
"(",
"action",
")",
"{",
"_dirtyFilesCache",
"[",
"name",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"_dirtyFilesCache",
"[",
"name",
"]",
")",
"{",
"delete",
"_dirtyFilesCache",
"[",
"name",
"]",
";",
"}",
"}",
"}"
] |
Updates the files cache with fullpath when dirty flag changes for a document
If the doc is being marked as dirty then an entry is created in the cache
If the doc is being marked as clean then the corresponsing entry gets cleared from cache
@param {String} name - fullpath of the document
@param {boolean} action - whether the document is dirty
|
[
"Updates",
"the",
"files",
"cache",
"with",
"fullpath",
"when",
"dirty",
"flag",
"changes",
"for",
"a",
"document",
"If",
"the",
"doc",
"is",
"being",
"marked",
"as",
"dirty",
"then",
"an",
"entry",
"is",
"created",
"in",
"the",
"cache",
"If",
"the",
"doc",
"is",
"being",
"marked",
"as",
"clean",
"then",
"the",
"corresponsing",
"entry",
"gets",
"cleared",
"from",
"cache"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/JSUtils/node/ExtractFileContent.js#L47-L55
|
train
|
adobe/brackets
|
src/extensibility/InstallExtensionDialog.js
|
InstallExtensionDialog
|
function InstallExtensionDialog(installer, _isUpdate) {
this._installer = installer;
this._state = STATE_CLOSED;
this._installResult = null;
this._isUpdate = _isUpdate;
// Timeout before we allow user to leave STATE_INSTALL_CANCELING without waiting for a resolution
// (per-instance so we can poke it for unit testing)
this._cancelTimeout = 10 * 1000;
}
|
javascript
|
function InstallExtensionDialog(installer, _isUpdate) {
this._installer = installer;
this._state = STATE_CLOSED;
this._installResult = null;
this._isUpdate = _isUpdate;
// Timeout before we allow user to leave STATE_INSTALL_CANCELING without waiting for a resolution
// (per-instance so we can poke it for unit testing)
this._cancelTimeout = 10 * 1000;
}
|
[
"function",
"InstallExtensionDialog",
"(",
"installer",
",",
"_isUpdate",
")",
"{",
"this",
".",
"_installer",
"=",
"installer",
";",
"this",
".",
"_state",
"=",
"STATE_CLOSED",
";",
"this",
".",
"_installResult",
"=",
"null",
";",
"this",
".",
"_isUpdate",
"=",
"_isUpdate",
";",
"this",
".",
"_cancelTimeout",
"=",
"10",
"*",
"1000",
";",
"}"
] |
Creates a new extension installer dialog.
@constructor
@param {{install: function(url), cancel: function()}} installer The installer backend to use.
|
[
"Creates",
"a",
"new",
"extension",
"installer",
"dialog",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/InstallExtensionDialog.js#L58-L67
|
train
|
adobe/brackets
|
src/project/WorkingSetSort.js
|
get
|
function get(command) {
var commandID;
if (!command) {
console.error("Attempting to get a Sort method with a missing required parameter: command");
return;
}
if (typeof command === "string") {
commandID = command;
} else {
commandID = command.getID();
}
return _sorts[commandID];
}
|
javascript
|
function get(command) {
var commandID;
if (!command) {
console.error("Attempting to get a Sort method with a missing required parameter: command");
return;
}
if (typeof command === "string") {
commandID = command;
} else {
commandID = command.getID();
}
return _sorts[commandID];
}
|
[
"function",
"get",
"(",
"command",
")",
"{",
"var",
"commandID",
";",
"if",
"(",
"!",
"command",
")",
"{",
"console",
".",
"error",
"(",
"\"Attempting to get a Sort method with a missing required parameter: command\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"command",
"===",
"\"string\"",
")",
"{",
"commandID",
"=",
"command",
";",
"}",
"else",
"{",
"commandID",
"=",
"command",
".",
"getID",
"(",
")",
";",
"}",
"return",
"_sorts",
"[",
"commandID",
"]",
";",
"}"
] |
Retrieves a Sort object by id
@param {(string|Command)} command A command ID or a command object.
@return {?Sort}
|
[
"Retrieves",
"a",
"Sort",
"object",
"by",
"id"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetSort.js#L98-L111
|
train
|
adobe/brackets
|
src/project/WorkingSetSort.js
|
_convertSortPref
|
function _convertSortPref(sortMethod) {
if (!sortMethod) {
return null;
}
if (_sortPrefConversionMap.hasOwnProperty(sortMethod)) {
sortMethod = _sortPrefConversionMap[sortMethod];
PreferencesManager.setViewState(_WORKING_SET_SORT_PREF, sortMethod);
} else {
sortMethod = null;
}
return sortMethod;
}
|
javascript
|
function _convertSortPref(sortMethod) {
if (!sortMethod) {
return null;
}
if (_sortPrefConversionMap.hasOwnProperty(sortMethod)) {
sortMethod = _sortPrefConversionMap[sortMethod];
PreferencesManager.setViewState(_WORKING_SET_SORT_PREF, sortMethod);
} else {
sortMethod = null;
}
return sortMethod;
}
|
[
"function",
"_convertSortPref",
"(",
"sortMethod",
")",
"{",
"if",
"(",
"!",
"sortMethod",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"_sortPrefConversionMap",
".",
"hasOwnProperty",
"(",
"sortMethod",
")",
")",
"{",
"sortMethod",
"=",
"_sortPrefConversionMap",
"[",
"sortMethod",
"]",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"_WORKING_SET_SORT_PREF",
",",
"sortMethod",
")",
";",
"}",
"else",
"{",
"sortMethod",
"=",
"null",
";",
"}",
"return",
"sortMethod",
";",
"}"
] |
Converts the old brackets working set sort preference into the modern paneview sort preference
@private
@param {!string} sortMethod - sort preference to convert
@return {?string} new sort preference string or undefined if an sortMethod is not found
|
[
"Converts",
"the",
"old",
"brackets",
"working",
"set",
"sort",
"preference",
"into",
"the",
"modern",
"paneview",
"sort",
"preference"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetSort.js#L119-L132
|
train
|
adobe/brackets
|
src/project/WorkingSetSort.js
|
_addListeners
|
function _addListeners() {
if (_automaticSort && _currentSort && _currentSort.getEvents()) {
MainViewManager
.on(_currentSort.getEvents(), function () {
_currentSort.sort();
})
.on("_workingSetDisableAutoSort.sort", function () {
setAutomatic(false);
});
}
}
|
javascript
|
function _addListeners() {
if (_automaticSort && _currentSort && _currentSort.getEvents()) {
MainViewManager
.on(_currentSort.getEvents(), function () {
_currentSort.sort();
})
.on("_workingSetDisableAutoSort.sort", function () {
setAutomatic(false);
});
}
}
|
[
"function",
"_addListeners",
"(",
")",
"{",
"if",
"(",
"_automaticSort",
"&&",
"_currentSort",
"&&",
"_currentSort",
".",
"getEvents",
"(",
")",
")",
"{",
"MainViewManager",
".",
"on",
"(",
"_currentSort",
".",
"getEvents",
"(",
")",
",",
"function",
"(",
")",
"{",
"_currentSort",
".",
"sort",
"(",
")",
";",
"}",
")",
".",
"on",
"(",
"\"_workingSetDisableAutoSort.sort\"",
",",
"function",
"(",
")",
"{",
"setAutomatic",
"(",
"false",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Adds the current sort MainViewManager listeners.
@private
|
[
"Adds",
"the",
"current",
"sort",
"MainViewManager",
"listeners",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetSort.js#L170-L180
|
train
|
adobe/brackets
|
src/project/WorkingSetSort.js
|
_setCurrentSort
|
function _setCurrentSort(newSort) {
if (_currentSort !== newSort) {
if (_currentSort !== null) {
_currentSort.setChecked(false);
}
if (_automaticSort) {
newSort.setChecked(true);
}
CommandManager.get(Commands.CMD_WORKING_SORT_TOGGLE_AUTO).setEnabled(!!newSort.getEvents());
PreferencesManager.setViewState(_WORKING_SET_SORT_PREF, newSort.getCommandID());
_currentSort = newSort;
}
}
|
javascript
|
function _setCurrentSort(newSort) {
if (_currentSort !== newSort) {
if (_currentSort !== null) {
_currentSort.setChecked(false);
}
if (_automaticSort) {
newSort.setChecked(true);
}
CommandManager.get(Commands.CMD_WORKING_SORT_TOGGLE_AUTO).setEnabled(!!newSort.getEvents());
PreferencesManager.setViewState(_WORKING_SET_SORT_PREF, newSort.getCommandID());
_currentSort = newSort;
}
}
|
[
"function",
"_setCurrentSort",
"(",
"newSort",
")",
"{",
"if",
"(",
"_currentSort",
"!==",
"newSort",
")",
"{",
"if",
"(",
"_currentSort",
"!==",
"null",
")",
"{",
"_currentSort",
".",
"setChecked",
"(",
"false",
")",
";",
"}",
"if",
"(",
"_automaticSort",
")",
"{",
"newSort",
".",
"setChecked",
"(",
"true",
")",
";",
"}",
"CommandManager",
".",
"get",
"(",
"Commands",
".",
"CMD_WORKING_SORT_TOGGLE_AUTO",
")",
".",
"setEnabled",
"(",
"!",
"!",
"newSort",
".",
"getEvents",
"(",
")",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"_WORKING_SET_SORT_PREF",
",",
"newSort",
".",
"getCommandID",
"(",
")",
")",
";",
"_currentSort",
"=",
"newSort",
";",
"}",
"}"
] |
Sets the current sort method and checks it on the context menu.
@private
@param {Sort} newSort
|
[
"Sets",
"the",
"current",
"sort",
"method",
"and",
"checks",
"it",
"on",
"the",
"context",
"menu",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetSort.js#L188-L201
|
train
|
adobe/brackets
|
src/project/WorkingSetSort.js
|
register
|
function register(command, compareFn, events) {
var commandID = "";
if (!command || !compareFn) {
console.log("Attempting to register a Sort method with a missing required parameter: command or compare function");
return;
}
if (typeof command === "string") {
commandID = command;
} else {
commandID = command.getID();
}
if (_sorts[commandID]) {
console.log("Attempting to register an already-registered Sort method: " + command);
return;
}
// Adds ".sort" to the end of each event to make them specific for the automatic sort.
if (events) {
events = events.split(" ");
events.forEach(function (event, index) {
events[index] = events[index].trim() + ".sort";
});
events = events.join(" ");
}
var sort = new Sort(commandID, compareFn, events);
_sorts[commandID] = sort;
return sort;
}
|
javascript
|
function register(command, compareFn, events) {
var commandID = "";
if (!command || !compareFn) {
console.log("Attempting to register a Sort method with a missing required parameter: command or compare function");
return;
}
if (typeof command === "string") {
commandID = command;
} else {
commandID = command.getID();
}
if (_sorts[commandID]) {
console.log("Attempting to register an already-registered Sort method: " + command);
return;
}
// Adds ".sort" to the end of each event to make them specific for the automatic sort.
if (events) {
events = events.split(" ");
events.forEach(function (event, index) {
events[index] = events[index].trim() + ".sort";
});
events = events.join(" ");
}
var sort = new Sort(commandID, compareFn, events);
_sorts[commandID] = sort;
return sort;
}
|
[
"function",
"register",
"(",
"command",
",",
"compareFn",
",",
"events",
")",
"{",
"var",
"commandID",
"=",
"\"\"",
";",
"if",
"(",
"!",
"command",
"||",
"!",
"compareFn",
")",
"{",
"console",
".",
"log",
"(",
"\"Attempting to register a Sort method with a missing required parameter: command or compare function\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"command",
"===",
"\"string\"",
")",
"{",
"commandID",
"=",
"command",
";",
"}",
"else",
"{",
"commandID",
"=",
"command",
".",
"getID",
"(",
")",
";",
"}",
"if",
"(",
"_sorts",
"[",
"commandID",
"]",
")",
"{",
"console",
".",
"log",
"(",
"\"Attempting to register an already-registered Sort method: \"",
"+",
"command",
")",
";",
"return",
";",
"}",
"if",
"(",
"events",
")",
"{",
"events",
"=",
"events",
".",
"split",
"(",
"\" \"",
")",
";",
"events",
".",
"forEach",
"(",
"function",
"(",
"event",
",",
"index",
")",
"{",
"events",
"[",
"index",
"]",
"=",
"events",
"[",
"index",
"]",
".",
"trim",
"(",
")",
"+",
"\".sort\"",
";",
"}",
")",
";",
"events",
"=",
"events",
".",
"join",
"(",
"\" \"",
")",
";",
"}",
"var",
"sort",
"=",
"new",
"Sort",
"(",
"commandID",
",",
"compareFn",
",",
"events",
")",
";",
"_sorts",
"[",
"commandID",
"]",
"=",
"sort",
";",
"return",
"sort",
";",
"}"
] |
Registers a working set sort method.
@param {(string|Command)} command A command ID or a command object
@param {function(File, File): number} compareFn The function that
will be used inside JavaScript's sort function. The return a value
should be >0 (sort a to a lower index than b), =0 (leaves a and b
unchanged with respect to each other) or <0 (sort b to a lower index
than a) and must always returns the same value when given a specific
pair of elements a and b as its two arguments. Documentation at:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort
@param {?string} events One or more space-separated event types that
DocumentManger uses. Each event passed will trigger the automatic
sort. If no events are passed, the automatic sort will be disabled
for that sort method.
@return {?Sort}
|
[
"Registers",
"a",
"working",
"set",
"sort",
"method",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/WorkingSetSort.js#L289-L319
|
train
|
adobe/brackets
|
src/LiveDevelopment/MultiBrowserImpl/language/HTMLSimpleDOM.js
|
function () {
var attributeString = JSON.stringify(this.attributes);
this.attributeSignature = MurmurHash3.hashString(attributeString, attributeString.length, seed);
}
|
javascript
|
function () {
var attributeString = JSON.stringify(this.attributes);
this.attributeSignature = MurmurHash3.hashString(attributeString, attributeString.length, seed);
}
|
[
"function",
"(",
")",
"{",
"var",
"attributeString",
"=",
"JSON",
".",
"stringify",
"(",
"this",
".",
"attributes",
")",
";",
"this",
".",
"attributeSignature",
"=",
"MurmurHash3",
".",
"hashString",
"(",
"attributeString",
",",
"attributeString",
".",
"length",
",",
"seed",
")",
";",
"}"
] |
Updates the signature of this node's attributes. Call this after making attribute changes.
|
[
"Updates",
"the",
"signature",
"of",
"this",
"node",
"s",
"attributes",
".",
"Call",
"this",
"after",
"making",
"attribute",
"changes",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/MultiBrowserImpl/language/HTMLSimpleDOM.js#L165-L168
|
train
|
|
adobe/brackets
|
src/LiveDevelopment/Agents/DOMAgent.js
|
allNodesAtLocation
|
function allNodesAtLocation(location) {
var nodes = [];
exports.root.each(function each(n) {
if (n.type === DOMNode.TYPE_ELEMENT && n.isAtLocation(location)) {
nodes.push(n);
}
});
return nodes;
}
|
javascript
|
function allNodesAtLocation(location) {
var nodes = [];
exports.root.each(function each(n) {
if (n.type === DOMNode.TYPE_ELEMENT && n.isAtLocation(location)) {
nodes.push(n);
}
});
return nodes;
}
|
[
"function",
"allNodesAtLocation",
"(",
"location",
")",
"{",
"var",
"nodes",
"=",
"[",
"]",
";",
"exports",
".",
"root",
".",
"each",
"(",
"function",
"each",
"(",
"n",
")",
"{",
"if",
"(",
"n",
".",
"type",
"===",
"DOMNode",
".",
"TYPE_ELEMENT",
"&&",
"n",
".",
"isAtLocation",
"(",
"location",
")",
")",
"{",
"nodes",
".",
"push",
"(",
"n",
")",
";",
"}",
"}",
")",
";",
"return",
"nodes",
";",
"}"
] |
Get the element node that encloses the given location
@param {location}
|
[
"Get",
"the",
"element",
"node",
"that",
"encloses",
"the",
"given",
"location"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/DOMAgent.js#L66-L74
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/DOMAgent.js
|
nodeAtLocation
|
function nodeAtLocation(location) {
return exports.root.find(function each(n) {
return n.isAtLocation(location, false);
});
}
|
javascript
|
function nodeAtLocation(location) {
return exports.root.find(function each(n) {
return n.isAtLocation(location, false);
});
}
|
[
"function",
"nodeAtLocation",
"(",
"location",
")",
"{",
"return",
"exports",
".",
"root",
".",
"find",
"(",
"function",
"each",
"(",
"n",
")",
"{",
"return",
"n",
".",
"isAtLocation",
"(",
"location",
",",
"false",
")",
";",
"}",
")",
";",
"}"
] |
Get the node at the given location
@param {location}
|
[
"Get",
"the",
"node",
"at",
"the",
"given",
"location"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/DOMAgent.js#L79-L83
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/DOMAgent.js
|
_cleanURL
|
function _cleanURL(url) {
var index = url.search(/[#\?]/);
if (index >= 0) {
url = url.substr(0, index);
}
return url;
}
|
javascript
|
function _cleanURL(url) {
var index = url.search(/[#\?]/);
if (index >= 0) {
url = url.substr(0, index);
}
return url;
}
|
[
"function",
"_cleanURL",
"(",
"url",
")",
"{",
"var",
"index",
"=",
"url",
".",
"search",
"(",
"/",
"[#\\?]",
"/",
")",
";",
"if",
"(",
"index",
">=",
"0",
")",
"{",
"url",
"=",
"url",
".",
"substr",
"(",
"0",
",",
"index",
")",
";",
"}",
"return",
"url",
";",
"}"
] |
Eliminate the query string from a URL
@param {string} URL
|
[
"Eliminate",
"the",
"query",
"string",
"from",
"a",
"URL"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/DOMAgent.js#L123-L129
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/DOMAgent.js
|
_mapDocumentToSource
|
function _mapDocumentToSource(source) {
var node = exports.root;
DOMHelpers.eachNode(source, function each(payload) {
if (!node) {
return true;
}
if (payload.closing) {
var parent = node.findParentForNextNodeMatchingPayload(payload);
if (!parent) {
return console.warn("Matching Parent not at " + payload.sourceOffset + " (" + payload.nodeName + ")");
}
parent.closeLocation = payload.sourceOffset;
parent.closeLength = payload.sourceLength;
} else {
var next = node.findNextNodeMatchingPayload(payload);
if (!next) {
return console.warn("Skipping Source Node at " + payload.sourceOffset);
}
node = next;
node.location = payload.sourceOffset;
node.length = payload.sourceLength;
if (payload.closed) {
node.closed = payload.closed;
}
}
});
}
|
javascript
|
function _mapDocumentToSource(source) {
var node = exports.root;
DOMHelpers.eachNode(source, function each(payload) {
if (!node) {
return true;
}
if (payload.closing) {
var parent = node.findParentForNextNodeMatchingPayload(payload);
if (!parent) {
return console.warn("Matching Parent not at " + payload.sourceOffset + " (" + payload.nodeName + ")");
}
parent.closeLocation = payload.sourceOffset;
parent.closeLength = payload.sourceLength;
} else {
var next = node.findNextNodeMatchingPayload(payload);
if (!next) {
return console.warn("Skipping Source Node at " + payload.sourceOffset);
}
node = next;
node.location = payload.sourceOffset;
node.length = payload.sourceLength;
if (payload.closed) {
node.closed = payload.closed;
}
}
});
}
|
[
"function",
"_mapDocumentToSource",
"(",
"source",
")",
"{",
"var",
"node",
"=",
"exports",
".",
"root",
";",
"DOMHelpers",
".",
"eachNode",
"(",
"source",
",",
"function",
"each",
"(",
"payload",
")",
"{",
"if",
"(",
"!",
"node",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"payload",
".",
"closing",
")",
"{",
"var",
"parent",
"=",
"node",
".",
"findParentForNextNodeMatchingPayload",
"(",
"payload",
")",
";",
"if",
"(",
"!",
"parent",
")",
"{",
"return",
"console",
".",
"warn",
"(",
"\"Matching Parent not at \"",
"+",
"payload",
".",
"sourceOffset",
"+",
"\" (\"",
"+",
"payload",
".",
"nodeName",
"+",
"\")\"",
")",
";",
"}",
"parent",
".",
"closeLocation",
"=",
"payload",
".",
"sourceOffset",
";",
"parent",
".",
"closeLength",
"=",
"payload",
".",
"sourceLength",
";",
"}",
"else",
"{",
"var",
"next",
"=",
"node",
".",
"findNextNodeMatchingPayload",
"(",
"payload",
")",
";",
"if",
"(",
"!",
"next",
")",
"{",
"return",
"console",
".",
"warn",
"(",
"\"Skipping Source Node at \"",
"+",
"payload",
".",
"sourceOffset",
")",
";",
"}",
"node",
"=",
"next",
";",
"node",
".",
"location",
"=",
"payload",
".",
"sourceOffset",
";",
"node",
".",
"length",
"=",
"payload",
".",
"sourceLength",
";",
"if",
"(",
"payload",
".",
"closed",
")",
"{",
"node",
".",
"closed",
"=",
"payload",
".",
"closed",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Map the DOM document to the source text
@param {string} source
|
[
"Map",
"the",
"DOM",
"document",
"to",
"the",
"source",
"text"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/DOMAgent.js#L134-L160
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/DOMAgent.js
|
_onFinishedLoadingDOM
|
function _onFinishedLoadingDOM() {
var request = new XMLHttpRequest();
request.open("GET", exports.url);
request.onload = function onLoad() {
if ((request.status >= 200 && request.status < 300) ||
request.status === 304 || request.status === 0) {
_mapDocumentToSource(request.response);
_load.resolve();
} else {
var msg = "Received status " + request.status + " from XMLHttpRequest while attempting to load source file at " + exports.url;
_load.reject(msg, { message: msg });
}
};
request.onerror = function onError() {
var msg = "Could not load source file at " + exports.url;
_load.reject(msg, { message: msg });
};
request.send(null);
}
|
javascript
|
function _onFinishedLoadingDOM() {
var request = new XMLHttpRequest();
request.open("GET", exports.url);
request.onload = function onLoad() {
if ((request.status >= 200 && request.status < 300) ||
request.status === 304 || request.status === 0) {
_mapDocumentToSource(request.response);
_load.resolve();
} else {
var msg = "Received status " + request.status + " from XMLHttpRequest while attempting to load source file at " + exports.url;
_load.reject(msg, { message: msg });
}
};
request.onerror = function onError() {
var msg = "Could not load source file at " + exports.url;
_load.reject(msg, { message: msg });
};
request.send(null);
}
|
[
"function",
"_onFinishedLoadingDOM",
"(",
")",
"{",
"var",
"request",
"=",
"new",
"XMLHttpRequest",
"(",
")",
";",
"request",
".",
"open",
"(",
"\"GET\"",
",",
"exports",
".",
"url",
")",
";",
"request",
".",
"onload",
"=",
"function",
"onLoad",
"(",
")",
"{",
"if",
"(",
"(",
"request",
".",
"status",
">=",
"200",
"&&",
"request",
".",
"status",
"<",
"300",
")",
"||",
"request",
".",
"status",
"===",
"304",
"||",
"request",
".",
"status",
"===",
"0",
")",
"{",
"_mapDocumentToSource",
"(",
"request",
".",
"response",
")",
";",
"_load",
".",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"var",
"msg",
"=",
"\"Received status \"",
"+",
"request",
".",
"status",
"+",
"\" from XMLHttpRequest while attempting to load source file at \"",
"+",
"exports",
".",
"url",
";",
"_load",
".",
"reject",
"(",
"msg",
",",
"{",
"message",
":",
"msg",
"}",
")",
";",
"}",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"onError",
"(",
")",
"{",
"var",
"msg",
"=",
"\"Could not load source file at \"",
"+",
"exports",
".",
"url",
";",
"_load",
".",
"reject",
"(",
"msg",
",",
"{",
"message",
":",
"msg",
"}",
")",
";",
"}",
";",
"request",
".",
"send",
"(",
"null",
")",
";",
"}"
] |
Load the source document and match it with the DOM tree
|
[
"Load",
"the",
"source",
"document",
"and",
"match",
"it",
"with",
"the",
"DOM",
"tree"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/DOMAgent.js#L163-L181
|
train
|
adobe/brackets
|
src/LiveDevelopment/Agents/DOMAgent.js
|
applyChange
|
function applyChange(from, to, text) {
var delta = from - to + text.length;
var node = nodeAtLocation(from);
// insert a text node
if (!node) {
if (!(/^\s*$/).test(text)) {
console.warn("Inserting nodes not supported.");
node = nodeBeforeLocation(from);
}
} else if (node.type === 3) {
// update a text node
var value = node.value.substr(0, from - node.location);
value += text;
value += node.value.substr(to - node.location);
node.value = value;
if (!EditAgent.isEditing) {
// only update the DOM if the change was not caused by the edit agent
Inspector.DOM.setNodeValue(node.nodeId, node.value);
}
} else {
console.warn("Changing non-text nodes not supported.");
}
// adjust the location of all nodes after the change
if (node) {
node.length += delta;
exports.root.each(function each(n) {
if (n.location > node.location) {
n.location += delta;
}
if (n.closeLocation !== undefined && n.closeLocation > node.location) {
n.closeLocation += delta;
}
});
}
}
|
javascript
|
function applyChange(from, to, text) {
var delta = from - to + text.length;
var node = nodeAtLocation(from);
// insert a text node
if (!node) {
if (!(/^\s*$/).test(text)) {
console.warn("Inserting nodes not supported.");
node = nodeBeforeLocation(from);
}
} else if (node.type === 3) {
// update a text node
var value = node.value.substr(0, from - node.location);
value += text;
value += node.value.substr(to - node.location);
node.value = value;
if (!EditAgent.isEditing) {
// only update the DOM if the change was not caused by the edit agent
Inspector.DOM.setNodeValue(node.nodeId, node.value);
}
} else {
console.warn("Changing non-text nodes not supported.");
}
// adjust the location of all nodes after the change
if (node) {
node.length += delta;
exports.root.each(function each(n) {
if (n.location > node.location) {
n.location += delta;
}
if (n.closeLocation !== undefined && n.closeLocation > node.location) {
n.closeLocation += delta;
}
});
}
}
|
[
"function",
"applyChange",
"(",
"from",
",",
"to",
",",
"text",
")",
"{",
"var",
"delta",
"=",
"from",
"-",
"to",
"+",
"text",
".",
"length",
";",
"var",
"node",
"=",
"nodeAtLocation",
"(",
"from",
")",
";",
"if",
"(",
"!",
"node",
")",
"{",
"if",
"(",
"!",
"(",
"/",
"^\\s*$",
"/",
")",
".",
"test",
"(",
"text",
")",
")",
"{",
"console",
".",
"warn",
"(",
"\"Inserting nodes not supported.\"",
")",
";",
"node",
"=",
"nodeBeforeLocation",
"(",
"from",
")",
";",
"}",
"}",
"else",
"if",
"(",
"node",
".",
"type",
"===",
"3",
")",
"{",
"var",
"value",
"=",
"node",
".",
"value",
".",
"substr",
"(",
"0",
",",
"from",
"-",
"node",
".",
"location",
")",
";",
"value",
"+=",
"text",
";",
"value",
"+=",
"node",
".",
"value",
".",
"substr",
"(",
"to",
"-",
"node",
".",
"location",
")",
";",
"node",
".",
"value",
"=",
"value",
";",
"if",
"(",
"!",
"EditAgent",
".",
"isEditing",
")",
"{",
"Inspector",
".",
"DOM",
".",
"setNodeValue",
"(",
"node",
".",
"nodeId",
",",
"node",
".",
"value",
")",
";",
"}",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"\"Changing non-text nodes not supported.\"",
")",
";",
"}",
"if",
"(",
"node",
")",
"{",
"node",
".",
"length",
"+=",
"delta",
";",
"exports",
".",
"root",
".",
"each",
"(",
"function",
"each",
"(",
"n",
")",
"{",
"if",
"(",
"n",
".",
"location",
">",
"node",
".",
"location",
")",
"{",
"n",
".",
"location",
"+=",
"delta",
";",
"}",
"if",
"(",
"n",
".",
"closeLocation",
"!==",
"undefined",
"&&",
"n",
".",
"closeLocation",
">",
"node",
".",
"location",
")",
"{",
"n",
".",
"closeLocation",
"+=",
"delta",
";",
"}",
"}",
")",
";",
"}",
"}"
] |
Apply a change
@param {integer} start offset of the change
@param {integer} end offset of the change
@param {string} change text
|
[
"Apply",
"a",
"change"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Agents/DOMAgent.js#L251-L287
|
train
|
adobe/brackets
|
src/language/LanguageManager.js
|
_validateNonEmptyString
|
function _validateNonEmptyString(value, description, deferred) {
var reportError = deferred ? deferred.reject : console.error;
// http://stackoverflow.com/questions/1303646/check-whether-variable-is-number-or-string-in-javascript
if (Object.prototype.toString.call(value) !== "[object String]") {
reportError(description + " must be a string");
return false;
}
if (value === "") {
reportError(description + " must not be empty");
return false;
}
return true;
}
|
javascript
|
function _validateNonEmptyString(value, description, deferred) {
var reportError = deferred ? deferred.reject : console.error;
// http://stackoverflow.com/questions/1303646/check-whether-variable-is-number-or-string-in-javascript
if (Object.prototype.toString.call(value) !== "[object String]") {
reportError(description + " must be a string");
return false;
}
if (value === "") {
reportError(description + " must not be empty");
return false;
}
return true;
}
|
[
"function",
"_validateNonEmptyString",
"(",
"value",
",",
"description",
",",
"deferred",
")",
"{",
"var",
"reportError",
"=",
"deferred",
"?",
"deferred",
".",
"reject",
":",
"console",
".",
"error",
";",
"if",
"(",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"value",
")",
"!==",
"\"[object String]\"",
")",
"{",
"reportError",
"(",
"description",
"+",
"\" must be a string\"",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"value",
"===",
"\"\"",
")",
"{",
"reportError",
"(",
"description",
"+",
"\" must not be empty\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Helper functions
Checks whether value is a non-empty string. Reports an error otherwise.
If no deferred is passed, console.error is called.
Otherwise the deferred is rejected with the error message.
@param {*} value The value to validate
@param {!string} description A helpful identifier for value
@param {?jQuery.Deferred} deferred A deferred to reject with the error message in case of an error
@return {boolean} True if the value is a non-empty string, false otherwise
|
[
"Helper",
"functions",
"Checks",
"whether",
"value",
"is",
"a",
"non",
"-",
"empty",
"string",
".",
"Reports",
"an",
"error",
"otherwise",
".",
"If",
"no",
"deferred",
"is",
"passed",
"console",
".",
"error",
"is",
"called",
".",
"Otherwise",
"the",
"deferred",
"is",
"rejected",
"with",
"the",
"error",
"message",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/LanguageManager.js#L189-L202
|
train
|
adobe/brackets
|
src/language/LanguageManager.js
|
_patchCodeMirror
|
function _patchCodeMirror() {
var _original_CodeMirror_defineMode = CodeMirror.defineMode;
function _wrapped_CodeMirror_defineMode(name) {
if (CodeMirror.modes[name]) {
console.error("There already is a CodeMirror mode with the name \"" + name + "\"");
return;
}
_original_CodeMirror_defineMode.apply(CodeMirror, arguments);
}
CodeMirror.defineMode = _wrapped_CodeMirror_defineMode;
}
|
javascript
|
function _patchCodeMirror() {
var _original_CodeMirror_defineMode = CodeMirror.defineMode;
function _wrapped_CodeMirror_defineMode(name) {
if (CodeMirror.modes[name]) {
console.error("There already is a CodeMirror mode with the name \"" + name + "\"");
return;
}
_original_CodeMirror_defineMode.apply(CodeMirror, arguments);
}
CodeMirror.defineMode = _wrapped_CodeMirror_defineMode;
}
|
[
"function",
"_patchCodeMirror",
"(",
")",
"{",
"var",
"_original_CodeMirror_defineMode",
"=",
"CodeMirror",
".",
"defineMode",
";",
"function",
"_wrapped_CodeMirror_defineMode",
"(",
"name",
")",
"{",
"if",
"(",
"CodeMirror",
".",
"modes",
"[",
"name",
"]",
")",
"{",
"console",
".",
"error",
"(",
"\"There already is a CodeMirror mode with the name \\\"\"",
"+",
"\\\"",
"+",
"name",
")",
";",
"\"\\\"\"",
"}",
"\\\"",
"}",
"return",
";",
"}"
] |
Monkey-patch CodeMirror to prevent modes from being overwritten by extensions.
We may rely on the tokens provided by some of these modes.
|
[
"Monkey",
"-",
"patch",
"CodeMirror",
"to",
"prevent",
"modes",
"from",
"being",
"overwritten",
"by",
"extensions",
".",
"We",
"may",
"rely",
"on",
"the",
"tokens",
"provided",
"by",
"some",
"of",
"these",
"modes",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/LanguageManager.js#L208-L218
|
train
|
adobe/brackets
|
src/language/LanguageManager.js
|
_setLanguageForMode
|
function _setLanguageForMode(mode, language) {
if (_modeToLanguageMap[mode]) {
console.warn("CodeMirror mode \"" + mode + "\" is already used by language " + _modeToLanguageMap[mode]._name + " - cannot fully register language " + language._name +
" using the same mode. Some features will treat all content with this mode as language " + _modeToLanguageMap[mode]._name);
return;
}
_modeToLanguageMap[mode] = language;
}
|
javascript
|
function _setLanguageForMode(mode, language) {
if (_modeToLanguageMap[mode]) {
console.warn("CodeMirror mode \"" + mode + "\" is already used by language " + _modeToLanguageMap[mode]._name + " - cannot fully register language " + language._name +
" using the same mode. Some features will treat all content with this mode as language " + _modeToLanguageMap[mode]._name);
return;
}
_modeToLanguageMap[mode] = language;
}
|
[
"function",
"_setLanguageForMode",
"(",
"mode",
",",
"language",
")",
"{",
"if",
"(",
"_modeToLanguageMap",
"[",
"mode",
"]",
")",
"{",
"console",
".",
"warn",
"(",
"\"CodeMirror mode \\\"\"",
"+",
"\\\"",
"+",
"mode",
"+",
"\"\\\" is already used by language \"",
"+",
"\\\"",
"+",
"_modeToLanguageMap",
"[",
"mode",
"]",
".",
"_name",
"+",
"\" - cannot fully register language \"",
"+",
"language",
".",
"_name",
")",
";",
"\" using the same mode. Some features will treat all content with this mode as language \"",
"}",
"_modeToLanguageMap",
"[",
"mode",
"]",
".",
"_name",
"}"
] |
Adds a global mode-to-language association.
@param {!string} mode The mode to associate the language with
@param {!Language} language The language to associate with the mode
|
[
"Adds",
"a",
"global",
"mode",
"-",
"to",
"-",
"language",
"association",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/LanguageManager.js#L225-L233
|
train
|
adobe/brackets
|
src/language/LanguageManager.js
|
_getLanguageForMode
|
function _getLanguageForMode(mode) {
var language = _modeToLanguageMap[mode];
if (language) {
return language;
}
// In case of unsupported languages
console.log("Called LanguageManager._getLanguageForMode with a mode for which no language has been registered:", mode);
return _fallbackLanguage;
}
|
javascript
|
function _getLanguageForMode(mode) {
var language = _modeToLanguageMap[mode];
if (language) {
return language;
}
// In case of unsupported languages
console.log("Called LanguageManager._getLanguageForMode with a mode for which no language has been registered:", mode);
return _fallbackLanguage;
}
|
[
"function",
"_getLanguageForMode",
"(",
"mode",
")",
"{",
"var",
"language",
"=",
"_modeToLanguageMap",
"[",
"mode",
"]",
";",
"if",
"(",
"language",
")",
"{",
"return",
"language",
";",
"}",
"console",
".",
"log",
"(",
"\"Called LanguageManager._getLanguageForMode with a mode for which no language has been registered:\"",
",",
"mode",
")",
";",
"return",
"_fallbackLanguage",
";",
"}"
] |
Resolves a CodeMirror mode to a Language object.
@param {!string} mode CodeMirror mode
@return {Language} The language for the provided mode or the fallback language
|
[
"Resolves",
"a",
"CodeMirror",
"mode",
"to",
"a",
"Language",
"object",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/LanguageManager.js#L340-L349
|
train
|
adobe/brackets
|
src/language/LanguageManager.js
|
defineLanguage
|
function defineLanguage(id, definition) {
var result = new $.Deferred();
if (_pendingLanguages[id]) {
result.reject("Language \"" + id + "\" is waiting to be resolved.");
return result.promise();
}
if (_languages[id]) {
result.reject("Language \"" + id + "\" is already defined");
return result.promise();
}
var language = new Language(),
name = definition.name,
fileExtensions = definition.fileExtensions,
fileNames = definition.fileNames,
blockComment = definition.blockComment,
lineComment = definition.lineComment,
i,
l;
function _finishRegisteringLanguage() {
if (fileExtensions) {
for (i = 0, l = fileExtensions.length; i < l; i++) {
language.addFileExtension(fileExtensions[i]);
}
}
// register language file names after mode has loaded
if (fileNames) {
for (i = 0, l = fileNames.length; i < l; i++) {
language.addFileName(fileNames[i]);
}
}
language._setBinary(!!definition.isBinary);
// store language to language map
_languages[language.getId()] = language;
// restore any preferences for non-default languages
if(PreferencesManager) {
_updateFromPrefs(_EXTENSION_MAP_PREF);
_updateFromPrefs(_NAME_MAP_PREF);
}
}
if (!language._setId(id) || !language._setName(name) ||
(blockComment && !language.setBlockCommentSyntax(blockComment[0], blockComment[1])) ||
(lineComment && !language.setLineCommentSyntax(lineComment))) {
result.reject();
return result.promise();
}
if (definition.isBinary) {
// add file extensions and store language to language map
_finishRegisteringLanguage();
result.resolve(language);
// Not notifying DocumentManager via event LanguageAdded, because DocumentManager
// does not care about binary files.
} else {
// track languages that are currently loading
_pendingLanguages[id] = language;
language._loadAndSetMode(definition.mode).done(function () {
// globally associate mode to language
_setLanguageForMode(language.getMode(), language);
// add file extensions and store language to language map
_finishRegisteringLanguage();
// fire an event to notify DocumentManager of the new language
_triggerLanguageAdded(language);
result.resolve(language);
}).fail(function (error) {
console.error(error);
result.reject(error);
}).always(function () {
// delete from pending languages after success and failure
delete _pendingLanguages[id];
});
}
return result.promise();
}
|
javascript
|
function defineLanguage(id, definition) {
var result = new $.Deferred();
if (_pendingLanguages[id]) {
result.reject("Language \"" + id + "\" is waiting to be resolved.");
return result.promise();
}
if (_languages[id]) {
result.reject("Language \"" + id + "\" is already defined");
return result.promise();
}
var language = new Language(),
name = definition.name,
fileExtensions = definition.fileExtensions,
fileNames = definition.fileNames,
blockComment = definition.blockComment,
lineComment = definition.lineComment,
i,
l;
function _finishRegisteringLanguage() {
if (fileExtensions) {
for (i = 0, l = fileExtensions.length; i < l; i++) {
language.addFileExtension(fileExtensions[i]);
}
}
// register language file names after mode has loaded
if (fileNames) {
for (i = 0, l = fileNames.length; i < l; i++) {
language.addFileName(fileNames[i]);
}
}
language._setBinary(!!definition.isBinary);
// store language to language map
_languages[language.getId()] = language;
// restore any preferences for non-default languages
if(PreferencesManager) {
_updateFromPrefs(_EXTENSION_MAP_PREF);
_updateFromPrefs(_NAME_MAP_PREF);
}
}
if (!language._setId(id) || !language._setName(name) ||
(blockComment && !language.setBlockCommentSyntax(blockComment[0], blockComment[1])) ||
(lineComment && !language.setLineCommentSyntax(lineComment))) {
result.reject();
return result.promise();
}
if (definition.isBinary) {
// add file extensions and store language to language map
_finishRegisteringLanguage();
result.resolve(language);
// Not notifying DocumentManager via event LanguageAdded, because DocumentManager
// does not care about binary files.
} else {
// track languages that are currently loading
_pendingLanguages[id] = language;
language._loadAndSetMode(definition.mode).done(function () {
// globally associate mode to language
_setLanguageForMode(language.getMode(), language);
// add file extensions and store language to language map
_finishRegisteringLanguage();
// fire an event to notify DocumentManager of the new language
_triggerLanguageAdded(language);
result.resolve(language);
}).fail(function (error) {
console.error(error);
result.reject(error);
}).always(function () {
// delete from pending languages after success and failure
delete _pendingLanguages[id];
});
}
return result.promise();
}
|
[
"function",
"defineLanguage",
"(",
"id",
",",
"definition",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"_pendingLanguages",
"[",
"id",
"]",
")",
"{",
"result",
".",
"reject",
"(",
"\"Language \\\"\"",
"+",
"\\\"",
"+",
"id",
")",
";",
"\"\\\" is waiting to be resolved.\"",
"}",
"\\\"",
"return",
"result",
".",
"promise",
"(",
")",
";",
"if",
"(",
"_languages",
"[",
"id",
"]",
")",
"{",
"result",
".",
"reject",
"(",
"\"Language \\\"\"",
"+",
"\\\"",
"+",
"id",
")",
";",
"\"\\\" is already defined\"",
"}",
"\\\"",
"return",
"result",
".",
"promise",
"(",
")",
";",
"var",
"language",
"=",
"new",
"Language",
"(",
")",
",",
"name",
"=",
"definition",
".",
"name",
",",
"fileExtensions",
"=",
"definition",
".",
"fileExtensions",
",",
"fileNames",
"=",
"definition",
".",
"fileNames",
",",
"blockComment",
"=",
"definition",
".",
"blockComment",
",",
"lineComment",
"=",
"definition",
".",
"lineComment",
",",
"i",
",",
"l",
";",
"}"
] |
Defines a language.
@param {!string} id Unique identifier for this language: lowercase letters, digits, and _ separators (e.g. "cpp", "foo_bar", "c99")
@param {!Object} definition An object describing the language
@param {!string} definition.name Human-readable name of the language, as it's commonly referred to (e.g. "C++")
@param {Array.<string>} definition.fileExtensions List of file extensions used by this language (e.g. ["php", "php3"] or ["coffee.md"] - may contain dots)
@param {Array.<string>} definition.fileNames List of exact file names (e.g. ["Makefile"] or ["package.json]). Higher precedence than file extension.
@param {Array.<string>} definition.blockComment Array with two entries defining the block comment prefix and suffix (e.g. ["<!--", "-->"])
@param {(string|Array.<string>)} definition.lineComment Line comment prefixes (e.g. "//" or ["//", "#"])
@param {(string|Array.<string>)} definition.mode CodeMirror mode (e.g. "htmlmixed"), optionally with a MIME mode defined by that mode ["clike", "text/x-c++src"]
Unless the mode is located in thirdparty/CodeMirror/mode/<name>/<name>.js, you need to first load it yourself.
@return {$.Promise} A promise object that will be resolved with a Language object
|
[
"Defines",
"a",
"language",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/LanguageManager.js#L926-L1013
|
train
|
adobe/brackets
|
src/widgets/PopUpManager.js
|
addPopUp
|
function addPopUp($popUp, removeHandler, autoRemove) {
autoRemove = autoRemove || false;
_popUps.push($popUp[0]);
$popUp.data("PopUpManager-autoRemove", autoRemove);
$popUp.data("PopUpManager-removeHandler", removeHandler);
}
|
javascript
|
function addPopUp($popUp, removeHandler, autoRemove) {
autoRemove = autoRemove || false;
_popUps.push($popUp[0]);
$popUp.data("PopUpManager-autoRemove", autoRemove);
$popUp.data("PopUpManager-removeHandler", removeHandler);
}
|
[
"function",
"addPopUp",
"(",
"$popUp",
",",
"removeHandler",
",",
"autoRemove",
")",
"{",
"autoRemove",
"=",
"autoRemove",
"||",
"false",
";",
"_popUps",
".",
"push",
"(",
"$popUp",
"[",
"0",
"]",
")",
";",
"$popUp",
".",
"data",
"(",
"\"PopUpManager-autoRemove\"",
",",
"autoRemove",
")",
";",
"$popUp",
".",
"data",
"(",
"\"PopUpManager-removeHandler\"",
",",
"removeHandler",
")",
";",
"}"
] |
Add Esc key handling for a popup DOM element.
@param {!jQuery} $popUp jQuery object for the DOM element pop-up
@param {function} removeHandler Pop-up specific remove (e.g. display:none or DOM removal)
@param {?Boolean} autoRemove - Specify true to indicate the PopUpManager should
remove the popup from the _popUps array when the popup is closed. Specify false
when the popup is always persistant in the _popUps array.
|
[
"Add",
"Esc",
"key",
"handling",
"for",
"a",
"popup",
"DOM",
"element",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/PopUpManager.js#L47-L53
|
train
|
adobe/brackets
|
src/xorigin.js
|
handleError
|
function handleError(message, url, line) {
// Ignore this error if it does not look like the rather vague cross origin error in Chrome
// Chrome will print it to the console anyway
if (!testCrossOriginError(message, url, line)) {
if (previousErrorHandler) {
return previousErrorHandler(message, url, line);
}
return;
}
// Show an error message
window.alert("Oops! This application doesn't run in browsers yet.\n\nIt is built in HTML, but right now it runs as a desktop app so you can use it to edit local files. Please use the application shell in the following repo to run this application:\n\ngithub.com/adobe/brackets-shell");
// Restore the original handler for later errors
window.onerror = previousErrorHandler;
}
|
javascript
|
function handleError(message, url, line) {
// Ignore this error if it does not look like the rather vague cross origin error in Chrome
// Chrome will print it to the console anyway
if (!testCrossOriginError(message, url, line)) {
if (previousErrorHandler) {
return previousErrorHandler(message, url, line);
}
return;
}
// Show an error message
window.alert("Oops! This application doesn't run in browsers yet.\n\nIt is built in HTML, but right now it runs as a desktop app so you can use it to edit local files. Please use the application shell in the following repo to run this application:\n\ngithub.com/adobe/brackets-shell");
// Restore the original handler for later errors
window.onerror = previousErrorHandler;
}
|
[
"function",
"handleError",
"(",
"message",
",",
"url",
",",
"line",
")",
"{",
"if",
"(",
"!",
"testCrossOriginError",
"(",
"message",
",",
"url",
",",
"line",
")",
")",
"{",
"if",
"(",
"previousErrorHandler",
")",
"{",
"return",
"previousErrorHandler",
"(",
"message",
",",
"url",
",",
"line",
")",
";",
"}",
"return",
";",
"}",
"window",
".",
"alert",
"(",
"\"Oops! This application doesn't run in browsers yet.\\n\\nIt is built in HTML, but right now it runs as a desktop app so you can use it to edit local files. Please use the application shell in the following repo to run this application:\\n\\ngithub.com/adobe/brackets-shell\"",
")",
";",
"\\n",
"}"
] |
Our error handler
|
[
"Our",
"error",
"handler"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/xorigin.js#L55-L70
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_loadStyles
|
function _loadStyles() {
var lessText = require("text!LiveDevelopment/main.less");
less.render(lessText, function onParse(err, tree) {
console.assert(!err, err);
ExtensionUtils.addEmbeddedStyleSheet(tree.css);
});
}
|
javascript
|
function _loadStyles() {
var lessText = require("text!LiveDevelopment/main.less");
less.render(lessText, function onParse(err, tree) {
console.assert(!err, err);
ExtensionUtils.addEmbeddedStyleSheet(tree.css);
});
}
|
[
"function",
"_loadStyles",
"(",
")",
"{",
"var",
"lessText",
"=",
"require",
"(",
"\"text!LiveDevelopment/main.less\"",
")",
";",
"less",
".",
"render",
"(",
"lessText",
",",
"function",
"onParse",
"(",
"err",
",",
"tree",
")",
"{",
"console",
".",
"assert",
"(",
"!",
"err",
",",
"err",
")",
";",
"ExtensionUtils",
".",
"addEmbeddedStyleSheet",
"(",
"tree",
".",
"css",
")",
";",
"}",
")",
";",
"}"
] |
Load Live Development LESS Style
|
[
"Load",
"Live",
"Development",
"LESS",
"Style"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L137-L144
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_setLabel
|
function _setLabel($btn, text, style, tooltip) {
// Clear text/styles from previous status
$("span", $btn).remove();
$btn.removeClass(_allStatusStyles);
// Set text/styles for new status
if (text && text.length > 0) {
$("<span class=\"label\">")
.addClass(style)
.text(text)
.appendTo($btn);
} else {
$btn.addClass(style);
}
if (tooltip) {
$btn.attr("title", tooltip);
}
}
|
javascript
|
function _setLabel($btn, text, style, tooltip) {
// Clear text/styles from previous status
$("span", $btn).remove();
$btn.removeClass(_allStatusStyles);
// Set text/styles for new status
if (text && text.length > 0) {
$("<span class=\"label\">")
.addClass(style)
.text(text)
.appendTo($btn);
} else {
$btn.addClass(style);
}
if (tooltip) {
$btn.attr("title", tooltip);
}
}
|
[
"function",
"_setLabel",
"(",
"$btn",
",",
"text",
",",
"style",
",",
"tooltip",
")",
"{",
"$",
"(",
"\"span\"",
",",
"$btn",
")",
".",
"remove",
"(",
")",
";",
"$btn",
".",
"removeClass",
"(",
"_allStatusStyles",
")",
";",
"if",
"(",
"text",
"&&",
"text",
".",
"length",
">",
"0",
")",
"{",
"$",
"(",
"\"<span class=\\\"label\\\">\"",
")",
".",
"\\\"",
"\\\"",
".",
"addClass",
"(",
"style",
")",
".",
"text",
"(",
"text",
")",
";",
"}",
"else",
"appendTo",
"(",
"$btn",
")",
"}"
] |
Change the appearance of a button. Omit text to remove any extra text; omit style to return to default styling;
omit tooltip to leave tooltip unchanged.
|
[
"Change",
"the",
"appearance",
"of",
"a",
"button",
".",
"Omit",
"text",
"to",
"remove",
"any",
"extra",
"text",
";",
"omit",
"style",
"to",
"return",
"to",
"default",
"styling",
";",
"omit",
"tooltip",
"to",
"leave",
"tooltip",
"unchanged",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L150-L168
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_handleGoLiveCommand
|
function _handleGoLiveCommand() {
if (LiveDevImpl.status >= LiveDevImpl.STATUS_ACTIVE) {
LiveDevImpl.close();
} else if (LiveDevImpl.status <= LiveDevImpl.STATUS_INACTIVE) {
if (!params.get("skipLiveDevelopmentInfo") && !PreferencesManager.getViewState("livedev.afterFirstLaunch")) {
PreferencesManager.setViewState("livedev.afterFirstLaunch", "true");
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_INFO,
Strings.LIVE_DEVELOPMENT_INFO_TITLE,
Strings.LIVE_DEVELOPMENT_INFO_MESSAGE
).done(function (id) {
LiveDevImpl.open();
});
} else {
LiveDevImpl.open();
}
}
}
|
javascript
|
function _handleGoLiveCommand() {
if (LiveDevImpl.status >= LiveDevImpl.STATUS_ACTIVE) {
LiveDevImpl.close();
} else if (LiveDevImpl.status <= LiveDevImpl.STATUS_INACTIVE) {
if (!params.get("skipLiveDevelopmentInfo") && !PreferencesManager.getViewState("livedev.afterFirstLaunch")) {
PreferencesManager.setViewState("livedev.afterFirstLaunch", "true");
Dialogs.showModalDialog(
DefaultDialogs.DIALOG_ID_INFO,
Strings.LIVE_DEVELOPMENT_INFO_TITLE,
Strings.LIVE_DEVELOPMENT_INFO_MESSAGE
).done(function (id) {
LiveDevImpl.open();
});
} else {
LiveDevImpl.open();
}
}
}
|
[
"function",
"_handleGoLiveCommand",
"(",
")",
"{",
"if",
"(",
"LiveDevImpl",
".",
"status",
">=",
"LiveDevImpl",
".",
"STATUS_ACTIVE",
")",
"{",
"LiveDevImpl",
".",
"close",
"(",
")",
";",
"}",
"else",
"if",
"(",
"LiveDevImpl",
".",
"status",
"<=",
"LiveDevImpl",
".",
"STATUS_INACTIVE",
")",
"{",
"if",
"(",
"!",
"params",
".",
"get",
"(",
"\"skipLiveDevelopmentInfo\"",
")",
"&&",
"!",
"PreferencesManager",
".",
"getViewState",
"(",
"\"livedev.afterFirstLaunch\"",
")",
")",
"{",
"PreferencesManager",
".",
"setViewState",
"(",
"\"livedev.afterFirstLaunch\"",
",",
"\"true\"",
")",
";",
"Dialogs",
".",
"showModalDialog",
"(",
"DefaultDialogs",
".",
"DIALOG_ID_INFO",
",",
"Strings",
".",
"LIVE_DEVELOPMENT_INFO_TITLE",
",",
"Strings",
".",
"LIVE_DEVELOPMENT_INFO_MESSAGE",
")",
".",
"done",
"(",
"function",
"(",
"id",
")",
"{",
"LiveDevImpl",
".",
"open",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"LiveDevImpl",
".",
"open",
"(",
")",
";",
"}",
"}",
"}"
] |
Toggles LiveDevelopment and synchronizes the state of UI elements that reports LiveDevelopment status
Stop Live Dev when in an active state (ACTIVE, OUT_OF_SYNC, SYNC_ERROR).
Start Live Dev when in an inactive state (ERROR, INACTIVE).
Do nothing when in a connecting state (CONNECTING, LOADING_AGENTS).
|
[
"Toggles",
"LiveDevelopment",
"and",
"synchronizes",
"the",
"state",
"of",
"UI",
"elements",
"that",
"reports",
"LiveDevelopment",
"status"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L177-L194
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_showStatusChangeReason
|
function _showStatusChangeReason(reason) {
// Destroy the previous twipsy (options are not updated otherwise)
_$btnGoLive.twipsy("hide").removeData("twipsy");
// If there was no reason or the action was an explicit request by the user, don't show a twipsy
if (!reason || reason === "explicit_close") {
return;
}
// Translate the reason
var translatedReason = Strings["LIVE_DEV_" + reason.toUpperCase()];
if (!translatedReason) {
translatedReason = StringUtils.format(Strings.LIVE_DEV_CLOSED_UNKNOWN_REASON, reason);
}
// Configure the twipsy
var options = {
placement: "left",
trigger: "manual",
autoHideDelay: 5000,
title: function () {
return translatedReason;
}
};
// Show the twipsy with the explanation
_$btnGoLive.twipsy(options).twipsy("show");
}
|
javascript
|
function _showStatusChangeReason(reason) {
// Destroy the previous twipsy (options are not updated otherwise)
_$btnGoLive.twipsy("hide").removeData("twipsy");
// If there was no reason or the action was an explicit request by the user, don't show a twipsy
if (!reason || reason === "explicit_close") {
return;
}
// Translate the reason
var translatedReason = Strings["LIVE_DEV_" + reason.toUpperCase()];
if (!translatedReason) {
translatedReason = StringUtils.format(Strings.LIVE_DEV_CLOSED_UNKNOWN_REASON, reason);
}
// Configure the twipsy
var options = {
placement: "left",
trigger: "manual",
autoHideDelay: 5000,
title: function () {
return translatedReason;
}
};
// Show the twipsy with the explanation
_$btnGoLive.twipsy(options).twipsy("show");
}
|
[
"function",
"_showStatusChangeReason",
"(",
"reason",
")",
"{",
"_$btnGoLive",
".",
"twipsy",
"(",
"\"hide\"",
")",
".",
"removeData",
"(",
"\"twipsy\"",
")",
";",
"if",
"(",
"!",
"reason",
"||",
"reason",
"===",
"\"explicit_close\"",
")",
"{",
"return",
";",
"}",
"var",
"translatedReason",
"=",
"Strings",
"[",
"\"LIVE_DEV_\"",
"+",
"reason",
".",
"toUpperCase",
"(",
")",
"]",
";",
"if",
"(",
"!",
"translatedReason",
")",
"{",
"translatedReason",
"=",
"StringUtils",
".",
"format",
"(",
"Strings",
".",
"LIVE_DEV_CLOSED_UNKNOWN_REASON",
",",
"reason",
")",
";",
"}",
"var",
"options",
"=",
"{",
"placement",
":",
"\"left\"",
",",
"trigger",
":",
"\"manual\"",
",",
"autoHideDelay",
":",
"5000",
",",
"title",
":",
"function",
"(",
")",
"{",
"return",
"translatedReason",
";",
"}",
"}",
";",
"_$btnGoLive",
".",
"twipsy",
"(",
"options",
")",
".",
"twipsy",
"(",
"\"show\"",
")",
";",
"}"
] |
Called on status change
|
[
"Called",
"on",
"status",
"change"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L197-L224
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_setupGoLiveButton
|
function _setupGoLiveButton() {
if (!_$btnGoLive) {
_$btnGoLive = $("#toolbar-go-live");
_$btnGoLive.click(function onGoLive() {
_handleGoLiveCommand();
});
}
LiveDevImpl.on("statusChange", function statusChange(event, status, reason) {
// status starts at -1 (error), so add one when looking up name and style
// See the comments at the top of LiveDevelopment.js for details on the
// various status codes.
_setLabel(_$btnGoLive, null, _status[status + 1].style, _status[status + 1].tooltip);
_showStatusChangeReason(reason);
if (config.autoconnect) {
window.sessionStorage.setItem("live.enabled", status === 3);
}
});
// Initialize tooltip for 'not connected' state
_setLabel(_$btnGoLive, null, _status[1].style, _status[1].tooltip);
}
|
javascript
|
function _setupGoLiveButton() {
if (!_$btnGoLive) {
_$btnGoLive = $("#toolbar-go-live");
_$btnGoLive.click(function onGoLive() {
_handleGoLiveCommand();
});
}
LiveDevImpl.on("statusChange", function statusChange(event, status, reason) {
// status starts at -1 (error), so add one when looking up name and style
// See the comments at the top of LiveDevelopment.js for details on the
// various status codes.
_setLabel(_$btnGoLive, null, _status[status + 1].style, _status[status + 1].tooltip);
_showStatusChangeReason(reason);
if (config.autoconnect) {
window.sessionStorage.setItem("live.enabled", status === 3);
}
});
// Initialize tooltip for 'not connected' state
_setLabel(_$btnGoLive, null, _status[1].style, _status[1].tooltip);
}
|
[
"function",
"_setupGoLiveButton",
"(",
")",
"{",
"if",
"(",
"!",
"_$btnGoLive",
")",
"{",
"_$btnGoLive",
"=",
"$",
"(",
"\"#toolbar-go-live\"",
")",
";",
"_$btnGoLive",
".",
"click",
"(",
"function",
"onGoLive",
"(",
")",
"{",
"_handleGoLiveCommand",
"(",
")",
";",
"}",
")",
";",
"}",
"LiveDevImpl",
".",
"on",
"(",
"\"statusChange\"",
",",
"function",
"statusChange",
"(",
"event",
",",
"status",
",",
"reason",
")",
"{",
"_setLabel",
"(",
"_$btnGoLive",
",",
"null",
",",
"_status",
"[",
"status",
"+",
"1",
"]",
".",
"style",
",",
"_status",
"[",
"status",
"+",
"1",
"]",
".",
"tooltip",
")",
";",
"_showStatusChangeReason",
"(",
"reason",
")",
";",
"if",
"(",
"config",
".",
"autoconnect",
")",
"{",
"window",
".",
"sessionStorage",
".",
"setItem",
"(",
"\"live.enabled\"",
",",
"status",
"===",
"3",
")",
";",
"}",
"}",
")",
";",
"_setLabel",
"(",
"_$btnGoLive",
",",
"null",
",",
"_status",
"[",
"1",
"]",
".",
"style",
",",
"_status",
"[",
"1",
"]",
".",
"tooltip",
")",
";",
"}"
] |
Create the menu item "Go Live"
|
[
"Create",
"the",
"menu",
"item",
"Go",
"Live"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L227-L247
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_setupGoLiveMenu
|
function _setupGoLiveMenu() {
LiveDevImpl.on("statusChange", function statusChange(event, status) {
// Update the checkmark next to 'Live Preview' menu item
// Add checkmark when status is STATUS_ACTIVE; otherwise remove it
CommandManager.get(Commands.FILE_LIVE_FILE_PREVIEW).setChecked(status === LiveDevImpl.STATUS_ACTIVE);
CommandManager.get(Commands.FILE_LIVE_HIGHLIGHT).setEnabled(status === LiveDevImpl.STATUS_ACTIVE);
});
}
|
javascript
|
function _setupGoLiveMenu() {
LiveDevImpl.on("statusChange", function statusChange(event, status) {
// Update the checkmark next to 'Live Preview' menu item
// Add checkmark when status is STATUS_ACTIVE; otherwise remove it
CommandManager.get(Commands.FILE_LIVE_FILE_PREVIEW).setChecked(status === LiveDevImpl.STATUS_ACTIVE);
CommandManager.get(Commands.FILE_LIVE_HIGHLIGHT).setEnabled(status === LiveDevImpl.STATUS_ACTIVE);
});
}
|
[
"function",
"_setupGoLiveMenu",
"(",
")",
"{",
"LiveDevImpl",
".",
"on",
"(",
"\"statusChange\"",
",",
"function",
"statusChange",
"(",
"event",
",",
"status",
")",
"{",
"CommandManager",
".",
"get",
"(",
"Commands",
".",
"FILE_LIVE_FILE_PREVIEW",
")",
".",
"setChecked",
"(",
"status",
"===",
"LiveDevImpl",
".",
"STATUS_ACTIVE",
")",
";",
"CommandManager",
".",
"get",
"(",
"Commands",
".",
"FILE_LIVE_HIGHLIGHT",
")",
".",
"setEnabled",
"(",
"status",
"===",
"LiveDevImpl",
".",
"STATUS_ACTIVE",
")",
";",
"}",
")",
";",
"}"
] |
Maintains state of the Live Preview menu item
|
[
"Maintains",
"state",
"of",
"the",
"Live",
"Preview",
"menu",
"item"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L250-L257
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_setImplementation
|
function _setImplementation(multibrowser) {
if (multibrowser) {
// set implemenation
LiveDevImpl = MultiBrowserLiveDev;
// update styles for UI status
_status = [
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "warning" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_CONNECTED, style: "success" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_OUT_OF_SYNC, style: "out-of-sync" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_SYNC_ERROR, style: "sync-error" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" }
];
} else {
LiveDevImpl = LiveDevelopment;
_status = [
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "warning" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS2, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_CONNECTED, style: "success" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_OUT_OF_SYNC, style: "out-of-sync" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_SYNC_ERROR, style: "sync-error" }
];
}
// setup status changes listeners for new implementation
_setupGoLiveButton();
_setupGoLiveMenu();
// toggle the menu
_toggleLivePreviewMultiBrowser(multibrowser);
}
|
javascript
|
function _setImplementation(multibrowser) {
if (multibrowser) {
// set implemenation
LiveDevImpl = MultiBrowserLiveDev;
// update styles for UI status
_status = [
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "warning" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_CONNECTED, style: "success" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_OUT_OF_SYNC, style: "out-of-sync" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_SYNC_ERROR, style: "sync-error" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" }
];
} else {
LiveDevImpl = LiveDevelopment;
_status = [
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "warning" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_NOT_CONNECTED, style: "" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS1, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_PROGRESS2, style: "info" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_CONNECTED, style: "success" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_OUT_OF_SYNC, style: "out-of-sync" },
{ tooltip: Strings.LIVE_DEV_STATUS_TIP_SYNC_ERROR, style: "sync-error" }
];
}
// setup status changes listeners for new implementation
_setupGoLiveButton();
_setupGoLiveMenu();
// toggle the menu
_toggleLivePreviewMultiBrowser(multibrowser);
}
|
[
"function",
"_setImplementation",
"(",
"multibrowser",
")",
"{",
"if",
"(",
"multibrowser",
")",
"{",
"LiveDevImpl",
"=",
"MultiBrowserLiveDev",
";",
"_status",
"=",
"[",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_NOT_CONNECTED",
",",
"style",
":",
"\"warning\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_NOT_CONNECTED",
",",
"style",
":",
"\"\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_PROGRESS1",
",",
"style",
":",
"\"info\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_CONNECTED",
",",
"style",
":",
"\"success\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_OUT_OF_SYNC",
",",
"style",
":",
"\"out-of-sync\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_SYNC_ERROR",
",",
"style",
":",
"\"sync-error\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_PROGRESS1",
",",
"style",
":",
"\"info\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_PROGRESS1",
",",
"style",
":",
"\"info\"",
"}",
"]",
";",
"}",
"else",
"{",
"LiveDevImpl",
"=",
"LiveDevelopment",
";",
"_status",
"=",
"[",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_NOT_CONNECTED",
",",
"style",
":",
"\"warning\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_NOT_CONNECTED",
",",
"style",
":",
"\"\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_PROGRESS1",
",",
"style",
":",
"\"info\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_PROGRESS2",
",",
"style",
":",
"\"info\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_CONNECTED",
",",
"style",
":",
"\"success\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_OUT_OF_SYNC",
",",
"style",
":",
"\"out-of-sync\"",
"}",
",",
"{",
"tooltip",
":",
"Strings",
".",
"LIVE_DEV_STATUS_TIP_SYNC_ERROR",
",",
"style",
":",
"\"sync-error\"",
"}",
"]",
";",
"}",
"_setupGoLiveButton",
"(",
")",
";",
"_setupGoLiveMenu",
"(",
")",
";",
"_toggleLivePreviewMultiBrowser",
"(",
"multibrowser",
")",
";",
"}"
] |
Sets the MultiBrowserLiveDev implementation if multibrowser is truthy,
keeps default LiveDevelopment implementation based on CDT otherwise.
It also resets the listeners and UI elements.
|
[
"Sets",
"the",
"MultiBrowserLiveDev",
"implementation",
"if",
"multibrowser",
"is",
"truthy",
"keeps",
"default",
"LiveDevelopment",
"implementation",
"based",
"on",
"CDT",
"otherwise",
".",
"It",
"also",
"resets",
"the",
"listeners",
"and",
"UI",
"elements",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L279-L311
|
train
|
adobe/brackets
|
src/LiveDevelopment/main.js
|
_setupDebugHelpers
|
function _setupDebugHelpers() {
window.ld = LiveDevelopment;
window.i = Inspector;
window.report = function report(params) { window.params = params; console.info(params); };
}
|
javascript
|
function _setupDebugHelpers() {
window.ld = LiveDevelopment;
window.i = Inspector;
window.report = function report(params) { window.params = params; console.info(params); };
}
|
[
"function",
"_setupDebugHelpers",
"(",
")",
"{",
"window",
".",
"ld",
"=",
"LiveDevelopment",
";",
"window",
".",
"i",
"=",
"Inspector",
";",
"window",
".",
"report",
"=",
"function",
"report",
"(",
"params",
")",
"{",
"window",
".",
"params",
"=",
"params",
";",
"console",
".",
"info",
"(",
"params",
")",
";",
"}",
";",
"}"
] |
Setup window references to useful LiveDevelopment modules
|
[
"Setup",
"window",
"references",
"to",
"useful",
"LiveDevelopment",
"modules"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/main.js#L314-L318
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
checkIfAnotherSessionInProgress
|
function checkIfAnotherSessionInProgress() {
var result = $.Deferred();
if(updateJsonHandler) {
var state = updateJsonHandler.state;
updateJsonHandler.refresh()
.done(function() {
var val = updateJsonHandler.get(updateProgressKey);
if(val !== null) {
result.resolve(val);
} else {
result.reject();
}
})
.fail(function() {
updateJsonHandler.state = state;
result.reject();
});
}
return result.promise();
}
|
javascript
|
function checkIfAnotherSessionInProgress() {
var result = $.Deferred();
if(updateJsonHandler) {
var state = updateJsonHandler.state;
updateJsonHandler.refresh()
.done(function() {
var val = updateJsonHandler.get(updateProgressKey);
if(val !== null) {
result.resolve(val);
} else {
result.reject();
}
})
.fail(function() {
updateJsonHandler.state = state;
result.reject();
});
}
return result.promise();
}
|
[
"function",
"checkIfAnotherSessionInProgress",
"(",
")",
"{",
"var",
"result",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"updateJsonHandler",
")",
"{",
"var",
"state",
"=",
"updateJsonHandler",
".",
"state",
";",
"updateJsonHandler",
".",
"refresh",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"var",
"val",
"=",
"updateJsonHandler",
".",
"get",
"(",
"updateProgressKey",
")",
";",
"if",
"(",
"val",
"!==",
"null",
")",
"{",
"result",
".",
"resolve",
"(",
"val",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"updateJsonHandler",
".",
"state",
"=",
"state",
";",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Checks if an auto update session is currently in progress
@returns {boolean} - true if an auto update session is currently in progress, false otherwise
|
[
"Checks",
"if",
"an",
"auto",
"update",
"session",
"is",
"currently",
"in",
"progress"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L102-L122
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
receiveMessageFromNode
|
function receiveMessageFromNode(event, msgObj) {
if (functionMap[msgObj.fn]) {
if(domainID === msgObj.requester) {
functionMap[msgObj.fn].apply(null, msgObj.args);
}
}
}
|
javascript
|
function receiveMessageFromNode(event, msgObj) {
if (functionMap[msgObj.fn]) {
if(domainID === msgObj.requester) {
functionMap[msgObj.fn].apply(null, msgObj.args);
}
}
}
|
[
"function",
"receiveMessageFromNode",
"(",
"event",
",",
"msgObj",
")",
"{",
"if",
"(",
"functionMap",
"[",
"msgObj",
".",
"fn",
"]",
")",
"{",
"if",
"(",
"domainID",
"===",
"msgObj",
".",
"requester",
")",
"{",
"functionMap",
"[",
"msgObj",
".",
"fn",
"]",
".",
"apply",
"(",
"null",
",",
"msgObj",
".",
"args",
")",
";",
"}",
"}",
"}"
] |
Receives messages from node
@param {object} event - event received from node
@param {object} msgObj - json containing - {
fn - function to execute on Brackets side
args - arguments to the above function
requester - ID of the current requester domain
|
[
"Receives",
"messages",
"from",
"node"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L141-L147
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
postMessageToNode
|
function postMessageToNode(messageId) {
var msg = {
fn: messageId,
args: getFunctionArgs(arguments),
requester: domainID
};
updateDomain.exec('data', msg);
}
|
javascript
|
function postMessageToNode(messageId) {
var msg = {
fn: messageId,
args: getFunctionArgs(arguments),
requester: domainID
};
updateDomain.exec('data', msg);
}
|
[
"function",
"postMessageToNode",
"(",
"messageId",
")",
"{",
"var",
"msg",
"=",
"{",
"fn",
":",
"messageId",
",",
"args",
":",
"getFunctionArgs",
"(",
"arguments",
")",
",",
"requester",
":",
"domainID",
"}",
";",
"updateDomain",
".",
"exec",
"(",
"'data'",
",",
"msg",
")",
";",
"}"
] |
Posts messages to node
@param {string} messageId - Message to be passed
|
[
"Posts",
"messages",
"to",
"node"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L185-L192
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
checkInstallationStatus
|
function checkInstallationStatus() {
var searchParams = {
"updateDir": updateDir,
"installErrorStr": ["ERROR:"],
"bracketsErrorStr": ["ERROR:"],
"encoding": "utf8"
},
// Below are the possible Windows Installer error strings, which will be searched for in the installer logs to track failures.
winInstallErrorStrArr = [
"Installation success or error status",
"Reconfiguration success or error status"
];
if (brackets.platform === "win") {
searchParams.installErrorStr = winInstallErrorStrArr;
searchParams.encoding = "utf16le";
}
postMessageToNode(MessageIds.CHECK_INSTALLER_STATUS, searchParams);
}
|
javascript
|
function checkInstallationStatus() {
var searchParams = {
"updateDir": updateDir,
"installErrorStr": ["ERROR:"],
"bracketsErrorStr": ["ERROR:"],
"encoding": "utf8"
},
// Below are the possible Windows Installer error strings, which will be searched for in the installer logs to track failures.
winInstallErrorStrArr = [
"Installation success or error status",
"Reconfiguration success or error status"
];
if (brackets.platform === "win") {
searchParams.installErrorStr = winInstallErrorStrArr;
searchParams.encoding = "utf16le";
}
postMessageToNode(MessageIds.CHECK_INSTALLER_STATUS, searchParams);
}
|
[
"function",
"checkInstallationStatus",
"(",
")",
"{",
"var",
"searchParams",
"=",
"{",
"\"updateDir\"",
":",
"updateDir",
",",
"\"installErrorStr\"",
":",
"[",
"\"ERROR:\"",
"]",
",",
"\"bracketsErrorStr\"",
":",
"[",
"\"ERROR:\"",
"]",
",",
"\"encoding\"",
":",
"\"utf8\"",
"}",
",",
"winInstallErrorStrArr",
"=",
"[",
"\"Installation success or error status\"",
",",
"\"Reconfiguration success or error status\"",
"]",
";",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"win\"",
")",
"{",
"searchParams",
".",
"installErrorStr",
"=",
"winInstallErrorStrArr",
";",
"searchParams",
".",
"encoding",
"=",
"\"utf16le\"",
";",
"}",
"postMessageToNode",
"(",
"MessageIds",
".",
"CHECK_INSTALLER_STATUS",
",",
"searchParams",
")",
";",
"}"
] |
Checks Install failure scenarios
|
[
"Checks",
"Install",
"failure",
"scenarios"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L197-L214
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
checkUpdateStatus
|
function checkUpdateStatus() {
var filesToCache = ['.logs'],
downloadCompleted = updateJsonHandler.get("downloadCompleted"),
updateInitiatedInPrevSession = updateJsonHandler.get("updateInitiatedInPrevSession");
if (downloadCompleted && updateInitiatedInPrevSession) {
var isNewVersion = checkIfVersionUpdated();
updateJsonHandler.reset();
if (isNewVersion) {
// We get here if the update was successful
UpdateInfoBar.showUpdateBar({
type: "success",
title: Strings.UPDATE_SUCCESSFUL,
description: ""
});
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_INSTALLATION_SUCCESS,
"autoUpdate",
"install",
"complete",
""
);
} else {
// We get here if the update started but failed
checkInstallationStatus();
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.UPDATE_FAILED,
description: Strings.GO_TO_SITE
});
}
} else if (downloadCompleted && !updateInitiatedInPrevSession) {
// We get here if the download was complete and user selected UpdateLater
if (brackets.platform === "mac") {
filesToCache = ['.dmg', '.json'];
} else if (brackets.platform === "win") {
filesToCache = ['.msi', '.json'];
}
}
postMessageToNode(MessageIds.PERFORM_CLEANUP, filesToCache);
}
|
javascript
|
function checkUpdateStatus() {
var filesToCache = ['.logs'],
downloadCompleted = updateJsonHandler.get("downloadCompleted"),
updateInitiatedInPrevSession = updateJsonHandler.get("updateInitiatedInPrevSession");
if (downloadCompleted && updateInitiatedInPrevSession) {
var isNewVersion = checkIfVersionUpdated();
updateJsonHandler.reset();
if (isNewVersion) {
// We get here if the update was successful
UpdateInfoBar.showUpdateBar({
type: "success",
title: Strings.UPDATE_SUCCESSFUL,
description: ""
});
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_INSTALLATION_SUCCESS,
"autoUpdate",
"install",
"complete",
""
);
} else {
// We get here if the update started but failed
checkInstallationStatus();
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.UPDATE_FAILED,
description: Strings.GO_TO_SITE
});
}
} else if (downloadCompleted && !updateInitiatedInPrevSession) {
// We get here if the download was complete and user selected UpdateLater
if (brackets.platform === "mac") {
filesToCache = ['.dmg', '.json'];
} else if (brackets.platform === "win") {
filesToCache = ['.msi', '.json'];
}
}
postMessageToNode(MessageIds.PERFORM_CLEANUP, filesToCache);
}
|
[
"function",
"checkUpdateStatus",
"(",
")",
"{",
"var",
"filesToCache",
"=",
"[",
"'.logs'",
"]",
",",
"downloadCompleted",
"=",
"updateJsonHandler",
".",
"get",
"(",
"\"downloadCompleted\"",
")",
",",
"updateInitiatedInPrevSession",
"=",
"updateJsonHandler",
".",
"get",
"(",
"\"updateInitiatedInPrevSession\"",
")",
";",
"if",
"(",
"downloadCompleted",
"&&",
"updateInitiatedInPrevSession",
")",
"{",
"var",
"isNewVersion",
"=",
"checkIfVersionUpdated",
"(",
")",
";",
"updateJsonHandler",
".",
"reset",
"(",
")",
";",
"if",
"(",
"isNewVersion",
")",
"{",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"type",
":",
"\"success\"",
",",
"title",
":",
"Strings",
".",
"UPDATE_SUCCESSFUL",
",",
"description",
":",
"\"\"",
"}",
")",
";",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_INSTALLATION_SUCCESS",
",",
"\"autoUpdate\"",
",",
"\"install\"",
",",
"\"complete\"",
",",
"\"\"",
")",
";",
"}",
"else",
"{",
"checkInstallationStatus",
"(",
")",
";",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"type",
":",
"\"error\"",
",",
"title",
":",
"Strings",
".",
"UPDATE_FAILED",
",",
"description",
":",
"Strings",
".",
"GO_TO_SITE",
"}",
")",
";",
"}",
"}",
"else",
"if",
"(",
"downloadCompleted",
"&&",
"!",
"updateInitiatedInPrevSession",
")",
"{",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"filesToCache",
"=",
"[",
"'.dmg'",
",",
"'.json'",
"]",
";",
"}",
"else",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"win\"",
")",
"{",
"filesToCache",
"=",
"[",
"'.msi'",
",",
"'.json'",
"]",
";",
"}",
"}",
"postMessageToNode",
"(",
"MessageIds",
".",
"PERFORM_CLEANUP",
",",
"filesToCache",
")",
";",
"}"
] |
Checks and handles the update success and failure scenarios
|
[
"Checks",
"and",
"handles",
"the",
"update",
"success",
"and",
"failure",
"scenarios"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L219-L260
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
handleInstallationStatus
|
function handleInstallationStatus(statusObj) {
var errorCode = "",
errorline = statusObj.installError;
if (errorline) {
errorCode = errorline.substr(errorline.lastIndexOf(':') + 2, errorline.length);
}
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_INSTALLATION_FAILED,
"autoUpdate",
"install",
"fail",
errorCode
);
}
|
javascript
|
function handleInstallationStatus(statusObj) {
var errorCode = "",
errorline = statusObj.installError;
if (errorline) {
errorCode = errorline.substr(errorline.lastIndexOf(':') + 2, errorline.length);
}
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_INSTALLATION_FAILED,
"autoUpdate",
"install",
"fail",
errorCode
);
}
|
[
"function",
"handleInstallationStatus",
"(",
"statusObj",
")",
"{",
"var",
"errorCode",
"=",
"\"\"",
",",
"errorline",
"=",
"statusObj",
".",
"installError",
";",
"if",
"(",
"errorline",
")",
"{",
"errorCode",
"=",
"errorline",
".",
"substr",
"(",
"errorline",
".",
"lastIndexOf",
"(",
"':'",
")",
"+",
"2",
",",
"errorline",
".",
"length",
")",
";",
"}",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_INSTALLATION_FAILED",
",",
"\"autoUpdate\"",
",",
"\"install\"",
",",
"\"fail\"",
",",
"errorCode",
")",
";",
"}"
] |
Send Installer Error Code to Analytics Server
|
[
"Send",
"Installer",
"Error",
"Code",
"to",
"Analytics",
"Server"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L266-L279
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
initState
|
function initState() {
var result = $.Deferred();
updateJsonHandler.parse()
.done(function() {
result.resolve();
})
.fail(function (code) {
var logMsg;
switch (code) {
case StateHandlerMessages.FILE_NOT_FOUND:
logMsg = "AutoUpdate : updateHelper.json cannot be parsed, does not exist";
break;
case StateHandlerMessages.FILE_NOT_READ:
logMsg = "AutoUpdate : updateHelper.json could not be read";
break;
case StateHandlerMessages.FILE_PARSE_EXCEPTION:
logMsg = "AutoUpdate : updateHelper.json could not be parsed, exception encountered";
break;
case StateHandlerMessages.FILE_READ_FAIL:
logMsg = "AutoUpdate : updateHelper.json could not be parsed";
break;
}
console.log(logMsg);
result.reject();
});
return result.promise();
}
|
javascript
|
function initState() {
var result = $.Deferred();
updateJsonHandler.parse()
.done(function() {
result.resolve();
})
.fail(function (code) {
var logMsg;
switch (code) {
case StateHandlerMessages.FILE_NOT_FOUND:
logMsg = "AutoUpdate : updateHelper.json cannot be parsed, does not exist";
break;
case StateHandlerMessages.FILE_NOT_READ:
logMsg = "AutoUpdate : updateHelper.json could not be read";
break;
case StateHandlerMessages.FILE_PARSE_EXCEPTION:
logMsg = "AutoUpdate : updateHelper.json could not be parsed, exception encountered";
break;
case StateHandlerMessages.FILE_READ_FAIL:
logMsg = "AutoUpdate : updateHelper.json could not be parsed";
break;
}
console.log(logMsg);
result.reject();
});
return result.promise();
}
|
[
"function",
"initState",
"(",
")",
"{",
"var",
"result",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"updateJsonHandler",
".",
"parse",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"code",
")",
"{",
"var",
"logMsg",
";",
"switch",
"(",
"code",
")",
"{",
"case",
"StateHandlerMessages",
".",
"FILE_NOT_FOUND",
":",
"logMsg",
"=",
"\"AutoUpdate : updateHelper.json cannot be parsed, does not exist\"",
";",
"break",
";",
"case",
"StateHandlerMessages",
".",
"FILE_NOT_READ",
":",
"logMsg",
"=",
"\"AutoUpdate : updateHelper.json could not be read\"",
";",
"break",
";",
"case",
"StateHandlerMessages",
".",
"FILE_PARSE_EXCEPTION",
":",
"logMsg",
"=",
"\"AutoUpdate : updateHelper.json could not be parsed, exception encountered\"",
";",
"break",
";",
"case",
"StateHandlerMessages",
".",
"FILE_READ_FAIL",
":",
"logMsg",
"=",
"\"AutoUpdate : updateHelper.json could not be parsed\"",
";",
"break",
";",
"}",
"console",
".",
"log",
"(",
"logMsg",
")",
";",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Initializes the state of parsed content from updateHelper.json
returns Promise Object Which is resolved when parsing is success
and rejected if parsing is failed.
|
[
"Initializes",
"the",
"state",
"of",
"parsed",
"content",
"from",
"updateHelper",
".",
"json",
"returns",
"Promise",
"Object",
"Which",
"is",
"resolved",
"when",
"parsing",
"is",
"success",
"and",
"rejected",
"if",
"parsing",
"is",
"failed",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L287-L313
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
setupAutoUpdate
|
function setupAutoUpdate() {
updateJsonHandler = new StateHandler(updateJsonPath);
updateDomain.on('data', receiveMessageFromNode);
updateDomain.exec('initNode', {
messageIds: MessageIds,
updateDir: updateDir,
requester: domainID
});
}
|
javascript
|
function setupAutoUpdate() {
updateJsonHandler = new StateHandler(updateJsonPath);
updateDomain.on('data', receiveMessageFromNode);
updateDomain.exec('initNode', {
messageIds: MessageIds,
updateDir: updateDir,
requester: domainID
});
}
|
[
"function",
"setupAutoUpdate",
"(",
")",
"{",
"updateJsonHandler",
"=",
"new",
"StateHandler",
"(",
"updateJsonPath",
")",
";",
"updateDomain",
".",
"on",
"(",
"'data'",
",",
"receiveMessageFromNode",
")",
";",
"updateDomain",
".",
"exec",
"(",
"'initNode'",
",",
"{",
"messageIds",
":",
"MessageIds",
",",
"updateDir",
":",
"updateDir",
",",
"requester",
":",
"domainID",
"}",
")",
";",
"}"
] |
Sets up the Auto Update environment
|
[
"Sets",
"up",
"the",
"Auto",
"Update",
"environment"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L320-L329
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
initializeState
|
function initializeState() {
var result = $.Deferred();
FileSystem.resolve(updateDir, function (err) {
if (!err) {
result.resolve();
} else {
var directory = FileSystem.getDirectoryForPath(updateDir);
directory.create(function (error) {
if (error) {
console.error('AutoUpdate : Error in creating update directory in Appdata');
result.reject();
} else {
result.resolve();
}
});
}
});
return result.promise();
}
|
javascript
|
function initializeState() {
var result = $.Deferred();
FileSystem.resolve(updateDir, function (err) {
if (!err) {
result.resolve();
} else {
var directory = FileSystem.getDirectoryForPath(updateDir);
directory.create(function (error) {
if (error) {
console.error('AutoUpdate : Error in creating update directory in Appdata');
result.reject();
} else {
result.resolve();
}
});
}
});
return result.promise();
}
|
[
"function",
"initializeState",
"(",
")",
"{",
"var",
"result",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"FileSystem",
".",
"resolve",
"(",
"updateDir",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"var",
"directory",
"=",
"FileSystem",
".",
"getDirectoryForPath",
"(",
"updateDir",
")",
";",
"directory",
".",
"create",
"(",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"'AutoUpdate : Error in creating update directory in Appdata'",
")",
";",
"result",
".",
"reject",
"(",
")",
";",
"}",
"else",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Initializes the state for AutoUpdate process
@returns {$.Deferred} - a jquery promise,
that is resolved with success or failure
of state initialization
|
[
"Initializes",
"the",
"state",
"for",
"AutoUpdate",
"process"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L338-L358
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
initiateAutoUpdate
|
function initiateAutoUpdate(updateParams) {
_updateParams = updateParams;
downloadAttemptsRemaining = MAX_DOWNLOAD_ATTEMPTS;
initializeState()
.done(function () {
var setUpdateInProgress = function() {
var initNodeFn = function () {
isAutoUpdateInitiated = true;
postMessageToNode(MessageIds.INITIALIZE_STATE, _updateParams);
};
if (updateJsonHandler.get('latestBuildNumber') !== _updateParams.latestBuildNumber) {
setUpdateStateInJSON('latestBuildNumber', _updateParams.latestBuildNumber)
.done(initNodeFn);
} else {
initNodeFn();
}
};
checkIfAnotherSessionInProgress()
.done(function(inProgress) {
if(inProgress) {
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.AUTOUPDATE_ERROR,
description: Strings.AUTOUPDATE_IN_PROGRESS
});
} else {
setUpdateStateInJSON("autoUpdateInProgress", true)
.done(setUpdateInProgress);
}
})
.fail(function() {
setUpdateStateInJSON("autoUpdateInProgress", true)
.done(setUpdateInProgress);
});
})
.fail(function () {
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.INITIALISATION_FAILED,
description: ""
});
});
}
|
javascript
|
function initiateAutoUpdate(updateParams) {
_updateParams = updateParams;
downloadAttemptsRemaining = MAX_DOWNLOAD_ATTEMPTS;
initializeState()
.done(function () {
var setUpdateInProgress = function() {
var initNodeFn = function () {
isAutoUpdateInitiated = true;
postMessageToNode(MessageIds.INITIALIZE_STATE, _updateParams);
};
if (updateJsonHandler.get('latestBuildNumber') !== _updateParams.latestBuildNumber) {
setUpdateStateInJSON('latestBuildNumber', _updateParams.latestBuildNumber)
.done(initNodeFn);
} else {
initNodeFn();
}
};
checkIfAnotherSessionInProgress()
.done(function(inProgress) {
if(inProgress) {
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.AUTOUPDATE_ERROR,
description: Strings.AUTOUPDATE_IN_PROGRESS
});
} else {
setUpdateStateInJSON("autoUpdateInProgress", true)
.done(setUpdateInProgress);
}
})
.fail(function() {
setUpdateStateInJSON("autoUpdateInProgress", true)
.done(setUpdateInProgress);
});
})
.fail(function () {
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.INITIALISATION_FAILED,
description: ""
});
});
}
|
[
"function",
"initiateAutoUpdate",
"(",
"updateParams",
")",
"{",
"_updateParams",
"=",
"updateParams",
";",
"downloadAttemptsRemaining",
"=",
"MAX_DOWNLOAD_ATTEMPTS",
";",
"initializeState",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"var",
"setUpdateInProgress",
"=",
"function",
"(",
")",
"{",
"var",
"initNodeFn",
"=",
"function",
"(",
")",
"{",
"isAutoUpdateInitiated",
"=",
"true",
";",
"postMessageToNode",
"(",
"MessageIds",
".",
"INITIALIZE_STATE",
",",
"_updateParams",
")",
";",
"}",
";",
"if",
"(",
"updateJsonHandler",
".",
"get",
"(",
"'latestBuildNumber'",
")",
"!==",
"_updateParams",
".",
"latestBuildNumber",
")",
"{",
"setUpdateStateInJSON",
"(",
"'latestBuildNumber'",
",",
"_updateParams",
".",
"latestBuildNumber",
")",
".",
"done",
"(",
"initNodeFn",
")",
";",
"}",
"else",
"{",
"initNodeFn",
"(",
")",
";",
"}",
"}",
";",
"checkIfAnotherSessionInProgress",
"(",
")",
".",
"done",
"(",
"function",
"(",
"inProgress",
")",
"{",
"if",
"(",
"inProgress",
")",
"{",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"type",
":",
"\"error\"",
",",
"title",
":",
"Strings",
".",
"AUTOUPDATE_ERROR",
",",
"description",
":",
"Strings",
".",
"AUTOUPDATE_IN_PROGRESS",
"}",
")",
";",
"}",
"else",
"{",
"setUpdateStateInJSON",
"(",
"\"autoUpdateInProgress\"",
",",
"true",
")",
".",
"done",
"(",
"setUpdateInProgress",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"setUpdateStateInJSON",
"(",
"\"autoUpdateInProgress\"",
",",
"true",
")",
".",
"done",
"(",
"setUpdateInProgress",
")",
";",
"}",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"type",
":",
"\"error\"",
",",
"title",
":",
"Strings",
".",
"INITIALISATION_FAILED",
",",
"description",
":",
"\"\"",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Handles the auto update event, which is triggered when user clicks GetItNow in UpdateNotification dialog
@param {object} updateParams - json object containing update information {
installerName - name of the installer
downloadURL - download URL
latestBuildNumber - build number
checksum - checksum }
|
[
"Handles",
"the",
"auto",
"update",
"event",
"which",
"is",
"triggered",
"when",
"user",
"clicks",
"GetItNow",
"in",
"UpdateNotification",
"dialog"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L370-L419
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
resetStateInFailure
|
function resetStateInFailure(message) {
updateJsonHandler.reset();
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.UPDATE_FAILED,
description: ""
});
enableCheckForUpdateEntry(true);
console.error(message);
}
|
javascript
|
function resetStateInFailure(message) {
updateJsonHandler.reset();
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.UPDATE_FAILED,
description: ""
});
enableCheckForUpdateEntry(true);
console.error(message);
}
|
[
"function",
"resetStateInFailure",
"(",
"message",
")",
"{",
"updateJsonHandler",
".",
"reset",
"(",
")",
";",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"type",
":",
"\"error\"",
",",
"title",
":",
"Strings",
".",
"UPDATE_FAILED",
",",
"description",
":",
"\"\"",
"}",
")",
";",
"enableCheckForUpdateEntry",
"(",
"true",
")",
";",
"console",
".",
"error",
"(",
"message",
")",
";",
"}"
] |
Resets the update state in updatehelper.json in case of failure,
and logs an error with the message
@param {string} message - the message to be logged onto console
|
[
"Resets",
"the",
"update",
"state",
"in",
"updatehelper",
".",
"json",
"in",
"case",
"of",
"failure",
"and",
"logs",
"an",
"error",
"with",
"the",
"message"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L611-L623
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
setUpdateStateInJSON
|
function setUpdateStateInJSON(key, value) {
var result = $.Deferred();
updateJsonHandler.set(key, value)
.done(function () {
result.resolve();
})
.fail(function () {
resetStateInFailure("AutoUpdate : Could not modify updatehelper.json");
result.reject();
});
return result.promise();
}
|
javascript
|
function setUpdateStateInJSON(key, value) {
var result = $.Deferred();
updateJsonHandler.set(key, value)
.done(function () {
result.resolve();
})
.fail(function () {
resetStateInFailure("AutoUpdate : Could not modify updatehelper.json");
result.reject();
});
return result.promise();
}
|
[
"function",
"setUpdateStateInJSON",
"(",
"key",
",",
"value",
")",
"{",
"var",
"result",
"=",
"$",
".",
"Deferred",
"(",
")",
";",
"updateJsonHandler",
".",
"set",
"(",
"key",
",",
"value",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"resetStateInFailure",
"(",
"\"AutoUpdate : Could not modify updatehelper.json\"",
")",
";",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Sets the update state in updateHelper.json in Appdata
@param {string} key - key to be set
@param {string} value - value to be set
@returns {$.Deferred} - a jquery promise, that is resolved with
success or failure of state update in json file
|
[
"Sets",
"the",
"update",
"state",
"in",
"updateHelper",
".",
"json",
"in",
"Appdata"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L632-L644
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
handleSafeToDownload
|
function handleSafeToDownload() {
var downloadFn = function () {
if (isFirstIterationDownload()) {
// For the first iteration of download, show download
//status info in Status bar, and pass download to node
UpdateStatus.showUpdateStatus("initial-download");
postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, true);
} else {
/* For the retry iterations of download, modify the
download status info in Status bar, and pass download to node */
var attempt = (MAX_DOWNLOAD_ATTEMPTS - downloadAttemptsRemaining);
if (attempt > 1) {
var info = attempt.toString() + "/5";
var status = {
target: "retry-download",
spans: [{
id: "attempt",
val: info
}]
};
UpdateStatus.modifyUpdateStatus(status);
} else {
UpdateStatus.showUpdateStatus("retry-download");
}
postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, false);
}
--downloadAttemptsRemaining;
};
if(!isAutoUpdateInitiated) {
isAutoUpdateInitiated = true;
updateJsonHandler.refresh()
.done(function() {
setUpdateStateInJSON('downloadCompleted', false)
.done(downloadFn);
});
} else {
setUpdateStateInJSON('downloadCompleted', false)
.done(downloadFn);
}
}
|
javascript
|
function handleSafeToDownload() {
var downloadFn = function () {
if (isFirstIterationDownload()) {
// For the first iteration of download, show download
//status info in Status bar, and pass download to node
UpdateStatus.showUpdateStatus("initial-download");
postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, true);
} else {
/* For the retry iterations of download, modify the
download status info in Status bar, and pass download to node */
var attempt = (MAX_DOWNLOAD_ATTEMPTS - downloadAttemptsRemaining);
if (attempt > 1) {
var info = attempt.toString() + "/5";
var status = {
target: "retry-download",
spans: [{
id: "attempt",
val: info
}]
};
UpdateStatus.modifyUpdateStatus(status);
} else {
UpdateStatus.showUpdateStatus("retry-download");
}
postMessageToNode(MessageIds.DOWNLOAD_INSTALLER, false);
}
--downloadAttemptsRemaining;
};
if(!isAutoUpdateInitiated) {
isAutoUpdateInitiated = true;
updateJsonHandler.refresh()
.done(function() {
setUpdateStateInJSON('downloadCompleted', false)
.done(downloadFn);
});
} else {
setUpdateStateInJSON('downloadCompleted', false)
.done(downloadFn);
}
}
|
[
"function",
"handleSafeToDownload",
"(",
")",
"{",
"var",
"downloadFn",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"isFirstIterationDownload",
"(",
")",
")",
"{",
"UpdateStatus",
".",
"showUpdateStatus",
"(",
"\"initial-download\"",
")",
";",
"postMessageToNode",
"(",
"MessageIds",
".",
"DOWNLOAD_INSTALLER",
",",
"true",
")",
";",
"}",
"else",
"{",
"var",
"attempt",
"=",
"(",
"MAX_DOWNLOAD_ATTEMPTS",
"-",
"downloadAttemptsRemaining",
")",
";",
"if",
"(",
"attempt",
">",
"1",
")",
"{",
"var",
"info",
"=",
"attempt",
".",
"toString",
"(",
")",
"+",
"\"/5\"",
";",
"var",
"status",
"=",
"{",
"target",
":",
"\"retry-download\"",
",",
"spans",
":",
"[",
"{",
"id",
":",
"\"attempt\"",
",",
"val",
":",
"info",
"}",
"]",
"}",
";",
"UpdateStatus",
".",
"modifyUpdateStatus",
"(",
"status",
")",
";",
"}",
"else",
"{",
"UpdateStatus",
".",
"showUpdateStatus",
"(",
"\"retry-download\"",
")",
";",
"}",
"postMessageToNode",
"(",
"MessageIds",
".",
"DOWNLOAD_INSTALLER",
",",
"false",
")",
";",
"}",
"--",
"downloadAttemptsRemaining",
";",
"}",
";",
"if",
"(",
"!",
"isAutoUpdateInitiated",
")",
"{",
"isAutoUpdateInitiated",
"=",
"true",
";",
"updateJsonHandler",
".",
"refresh",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"setUpdateStateInJSON",
"(",
"'downloadCompleted'",
",",
"false",
")",
".",
"done",
"(",
"downloadFn",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"setUpdateStateInJSON",
"(",
"'downloadCompleted'",
",",
"false",
")",
".",
"done",
"(",
"downloadFn",
")",
";",
"}",
"}"
] |
Handles a safe download of the latest installer,
safety is ensured by cleaning up any pre-existing installers
from update directory before beginning a fresh download
|
[
"Handles",
"a",
"safe",
"download",
"of",
"the",
"latest",
"installer",
"safety",
"is",
"ensured",
"by",
"cleaning",
"up",
"any",
"pre",
"-",
"existing",
"installers",
"from",
"update",
"directory",
"before",
"beginning",
"a",
"fresh",
"download"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L651-L692
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
attemptToDownload
|
function attemptToDownload() {
if (checkIfOnline()) {
postMessageToNode(MessageIds.PERFORM_CLEANUP, ['.json'], true);
} else {
enableCheckForUpdateEntry(true);
UpdateStatus.cleanUpdateStatus();
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_FAILED,
"autoUpdate",
"download",
"fail",
"No Internet connection available."
);
UpdateInfoBar.showUpdateBar({
type: "warning",
title: Strings.DOWNLOAD_FAILED,
description: Strings.INTERNET_UNAVAILABLE
});
setUpdateStateInJSON("autoUpdateInProgress", false);
}
}
|
javascript
|
function attemptToDownload() {
if (checkIfOnline()) {
postMessageToNode(MessageIds.PERFORM_CLEANUP, ['.json'], true);
} else {
enableCheckForUpdateEntry(true);
UpdateStatus.cleanUpdateStatus();
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_FAILED,
"autoUpdate",
"download",
"fail",
"No Internet connection available."
);
UpdateInfoBar.showUpdateBar({
type: "warning",
title: Strings.DOWNLOAD_FAILED,
description: Strings.INTERNET_UNAVAILABLE
});
setUpdateStateInJSON("autoUpdateInProgress", false);
}
}
|
[
"function",
"attemptToDownload",
"(",
")",
"{",
"if",
"(",
"checkIfOnline",
"(",
")",
")",
"{",
"postMessageToNode",
"(",
"MessageIds",
".",
"PERFORM_CLEANUP",
",",
"[",
"'.json'",
"]",
",",
"true",
")",
";",
"}",
"else",
"{",
"enableCheckForUpdateEntry",
"(",
"true",
")",
";",
"UpdateStatus",
".",
"cleanUpdateStatus",
"(",
")",
";",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_FAILED",
",",
"\"autoUpdate\"",
",",
"\"download\"",
",",
"\"fail\"",
",",
"\"No Internet connection available.\"",
")",
";",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"type",
":",
"\"warning\"",
",",
"title",
":",
"Strings",
".",
"DOWNLOAD_FAILED",
",",
"description",
":",
"Strings",
".",
"INTERNET_UNAVAILABLE",
"}",
")",
";",
"setUpdateStateInJSON",
"(",
"\"autoUpdateInProgress\"",
",",
"false",
")",
";",
"}",
"}"
] |
Attempts a download of the latest installer, while cleaning up any existing downloaded installers
|
[
"Attempts",
"a",
"download",
"of",
"the",
"latest",
"installer",
"while",
"cleaning",
"up",
"any",
"existing",
"downloaded",
"installers"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L705-L726
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
showStatusInfo
|
function showStatusInfo(statusObj) {
if (statusObj.target === "initial-download") {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_START,
"autoUpdate",
"download",
"started",
""
);
UpdateStatus.modifyUpdateStatus(statusObj);
}
UpdateStatus.displayProgress(statusObj);
}
|
javascript
|
function showStatusInfo(statusObj) {
if (statusObj.target === "initial-download") {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_START,
"autoUpdate",
"download",
"started",
""
);
UpdateStatus.modifyUpdateStatus(statusObj);
}
UpdateStatus.displayProgress(statusObj);
}
|
[
"function",
"showStatusInfo",
"(",
"statusObj",
")",
"{",
"if",
"(",
"statusObj",
".",
"target",
"===",
"\"initial-download\"",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_START",
",",
"\"autoUpdate\"",
",",
"\"download\"",
",",
"\"started\"",
",",
"\"\"",
")",
";",
"UpdateStatus",
".",
"modifyUpdateStatus",
"(",
"statusObj",
")",
";",
"}",
"UpdateStatus",
".",
"displayProgress",
"(",
"statusObj",
")",
";",
"}"
] |
Handles the show status information callback from Node.
It modifies the info displayed on Status bar.
@param {object} statusObj - json containing status info {
target - id of string to display,
spans - Array containing json objects of type - {
id - span id,
val - string to fill the span element with }
}
|
[
"Handles",
"the",
"show",
"status",
"information",
"callback",
"from",
"Node",
".",
"It",
"modifies",
"the",
"info",
"displayed",
"on",
"Status",
"bar",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L760-L772
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
showErrorMessage
|
function showErrorMessage(message) {
var analyticsDescriptionMessage = "";
switch (message) {
case _nodeErrorMessages.UPDATEDIR_READ_FAILED:
analyticsDescriptionMessage = "Update directory could not be read.";
break;
case _nodeErrorMessages.UPDATEDIR_CLEAN_FAILED:
analyticsDescriptionMessage = "Update directory could not be cleaned.";
break;
}
console.log("AutoUpdate : Clean-up failed! Reason : " + analyticsDescriptionMessage + ".\n");
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_CLEANUP_FAILED,
"autoUpdate",
"cleanUp",
"fail",
analyticsDescriptionMessage
);
}
|
javascript
|
function showErrorMessage(message) {
var analyticsDescriptionMessage = "";
switch (message) {
case _nodeErrorMessages.UPDATEDIR_READ_FAILED:
analyticsDescriptionMessage = "Update directory could not be read.";
break;
case _nodeErrorMessages.UPDATEDIR_CLEAN_FAILED:
analyticsDescriptionMessage = "Update directory could not be cleaned.";
break;
}
console.log("AutoUpdate : Clean-up failed! Reason : " + analyticsDescriptionMessage + ".\n");
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_CLEANUP_FAILED,
"autoUpdate",
"cleanUp",
"fail",
analyticsDescriptionMessage
);
}
|
[
"function",
"showErrorMessage",
"(",
"message",
")",
"{",
"var",
"analyticsDescriptionMessage",
"=",
"\"\"",
";",
"switch",
"(",
"message",
")",
"{",
"case",
"_nodeErrorMessages",
".",
"UPDATEDIR_READ_FAILED",
":",
"analyticsDescriptionMessage",
"=",
"\"Update directory could not be read.\"",
";",
"break",
";",
"case",
"_nodeErrorMessages",
".",
"UPDATEDIR_CLEAN_FAILED",
":",
"analyticsDescriptionMessage",
"=",
"\"Update directory could not be cleaned.\"",
";",
"break",
";",
"}",
"console",
".",
"log",
"(",
"\"AutoUpdate : Clean-up failed! Reason : \"",
"+",
"analyticsDescriptionMessage",
"+",
"\".\\n\"",
")",
";",
"\\n",
"}"
] |
Handles the error messages from Node, in a popup displayed to the user.
@param {string} message - error string
|
[
"Handles",
"the",
"error",
"messages",
"from",
"Node",
"in",
"a",
"popup",
"displayed",
"to",
"the",
"user",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L778-L797
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
initiateUpdateProcess
|
function initiateUpdateProcess(formattedInstallerPath, formattedLogFilePath, installStatusFilePath) {
// Get additional update parameters on Mac : installDir, appName, and updateDir
function getAdditionalParams() {
var retval = {};
var installDir = FileUtils.getNativeBracketsDirectoryPath();
if (installDir) {
var appPath = installDir.split("/Contents/www")[0];
installDir = appPath.substr(0, appPath.lastIndexOf('/'));
var appName = appPath.substr(appPath.lastIndexOf('/') + 1);
retval = {
installDir: installDir,
appName: appName,
updateDir: updateDir
};
}
return retval;
}
// Update function, to carry out app update
var updateFn = function () {
var infoObj = {
installerPath: formattedInstallerPath,
logFilePath: formattedLogFilePath,
installStatusFilePath: installStatusFilePath
};
if (brackets.platform === "mac") {
var additionalParams = getAdditionalParams(),
key;
for (key in additionalParams) {
if (additionalParams.hasOwnProperty(key)) {
infoObj[key] = additionalParams[key];
}
}
}
// Set update parameters for app update
if (brackets.app.setUpdateParams) {
brackets.app.setUpdateParams(JSON.stringify(infoObj), function (err) {
if (err) {
resetStateInFailure("AutoUpdate : Update parameters could not be set for the installer. Error encountered: " + err);
} else {
setAppQuitHandler();
CommandManager.execute(Commands.FILE_QUIT);
}
});
} else {
resetStateInFailure("AutoUpdate : setUpdateParams could not be found in shell");
}
};
setUpdateStateInJSON('updateInitiatedInPrevSession', true)
.done(updateFn);
}
|
javascript
|
function initiateUpdateProcess(formattedInstallerPath, formattedLogFilePath, installStatusFilePath) {
// Get additional update parameters on Mac : installDir, appName, and updateDir
function getAdditionalParams() {
var retval = {};
var installDir = FileUtils.getNativeBracketsDirectoryPath();
if (installDir) {
var appPath = installDir.split("/Contents/www")[0];
installDir = appPath.substr(0, appPath.lastIndexOf('/'));
var appName = appPath.substr(appPath.lastIndexOf('/') + 1);
retval = {
installDir: installDir,
appName: appName,
updateDir: updateDir
};
}
return retval;
}
// Update function, to carry out app update
var updateFn = function () {
var infoObj = {
installerPath: formattedInstallerPath,
logFilePath: formattedLogFilePath,
installStatusFilePath: installStatusFilePath
};
if (brackets.platform === "mac") {
var additionalParams = getAdditionalParams(),
key;
for (key in additionalParams) {
if (additionalParams.hasOwnProperty(key)) {
infoObj[key] = additionalParams[key];
}
}
}
// Set update parameters for app update
if (brackets.app.setUpdateParams) {
brackets.app.setUpdateParams(JSON.stringify(infoObj), function (err) {
if (err) {
resetStateInFailure("AutoUpdate : Update parameters could not be set for the installer. Error encountered: " + err);
} else {
setAppQuitHandler();
CommandManager.execute(Commands.FILE_QUIT);
}
});
} else {
resetStateInFailure("AutoUpdate : setUpdateParams could not be found in shell");
}
};
setUpdateStateInJSON('updateInitiatedInPrevSession', true)
.done(updateFn);
}
|
[
"function",
"initiateUpdateProcess",
"(",
"formattedInstallerPath",
",",
"formattedLogFilePath",
",",
"installStatusFilePath",
")",
"{",
"function",
"getAdditionalParams",
"(",
")",
"{",
"var",
"retval",
"=",
"{",
"}",
";",
"var",
"installDir",
"=",
"FileUtils",
".",
"getNativeBracketsDirectoryPath",
"(",
")",
";",
"if",
"(",
"installDir",
")",
"{",
"var",
"appPath",
"=",
"installDir",
".",
"split",
"(",
"\"/Contents/www\"",
")",
"[",
"0",
"]",
";",
"installDir",
"=",
"appPath",
".",
"substr",
"(",
"0",
",",
"appPath",
".",
"lastIndexOf",
"(",
"'/'",
")",
")",
";",
"var",
"appName",
"=",
"appPath",
".",
"substr",
"(",
"appPath",
".",
"lastIndexOf",
"(",
"'/'",
")",
"+",
"1",
")",
";",
"retval",
"=",
"{",
"installDir",
":",
"installDir",
",",
"appName",
":",
"appName",
",",
"updateDir",
":",
"updateDir",
"}",
";",
"}",
"return",
"retval",
";",
"}",
"var",
"updateFn",
"=",
"function",
"(",
")",
"{",
"var",
"infoObj",
"=",
"{",
"installerPath",
":",
"formattedInstallerPath",
",",
"logFilePath",
":",
"formattedLogFilePath",
",",
"installStatusFilePath",
":",
"installStatusFilePath",
"}",
";",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"var",
"additionalParams",
"=",
"getAdditionalParams",
"(",
")",
",",
"key",
";",
"for",
"(",
"key",
"in",
"additionalParams",
")",
"{",
"if",
"(",
"additionalParams",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"infoObj",
"[",
"key",
"]",
"=",
"additionalParams",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"brackets",
".",
"app",
".",
"setUpdateParams",
")",
"{",
"brackets",
".",
"app",
".",
"setUpdateParams",
"(",
"JSON",
".",
"stringify",
"(",
"infoObj",
")",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"resetStateInFailure",
"(",
"\"AutoUpdate : Update parameters could not be set for the installer. Error encountered: \"",
"+",
"err",
")",
";",
"}",
"else",
"{",
"setAppQuitHandler",
"(",
")",
";",
"CommandManager",
".",
"execute",
"(",
"Commands",
".",
"FILE_QUIT",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"resetStateInFailure",
"(",
"\"AutoUpdate : setUpdateParams could not be found in shell\"",
")",
";",
"}",
"}",
";",
"setUpdateStateInJSON",
"(",
"'updateInitiatedInPrevSession'",
",",
"true",
")",
".",
"done",
"(",
"updateFn",
")",
";",
"}"
] |
Initiates the update process, when user clicks UpdateNow in the update popup
@param {string} formattedInstallerPath - formatted path to the latest installer
@param {string} formattedLogFilePath - formatted path to the installer log file
@param {string} installStatusFilePath - path to the install status log file
|
[
"Initiates",
"the",
"update",
"process",
"when",
"user",
"clicks",
"UpdateNow",
"in",
"the",
"update",
"popup"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L829-L885
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
function () {
var infoObj = {
installerPath: formattedInstallerPath,
logFilePath: formattedLogFilePath,
installStatusFilePath: installStatusFilePath
};
if (brackets.platform === "mac") {
var additionalParams = getAdditionalParams(),
key;
for (key in additionalParams) {
if (additionalParams.hasOwnProperty(key)) {
infoObj[key] = additionalParams[key];
}
}
}
// Set update parameters for app update
if (brackets.app.setUpdateParams) {
brackets.app.setUpdateParams(JSON.stringify(infoObj), function (err) {
if (err) {
resetStateInFailure("AutoUpdate : Update parameters could not be set for the installer. Error encountered: " + err);
} else {
setAppQuitHandler();
CommandManager.execute(Commands.FILE_QUIT);
}
});
} else {
resetStateInFailure("AutoUpdate : setUpdateParams could not be found in shell");
}
}
|
javascript
|
function () {
var infoObj = {
installerPath: formattedInstallerPath,
logFilePath: formattedLogFilePath,
installStatusFilePath: installStatusFilePath
};
if (brackets.platform === "mac") {
var additionalParams = getAdditionalParams(),
key;
for (key in additionalParams) {
if (additionalParams.hasOwnProperty(key)) {
infoObj[key] = additionalParams[key];
}
}
}
// Set update parameters for app update
if (brackets.app.setUpdateParams) {
brackets.app.setUpdateParams(JSON.stringify(infoObj), function (err) {
if (err) {
resetStateInFailure("AutoUpdate : Update parameters could not be set for the installer. Error encountered: " + err);
} else {
setAppQuitHandler();
CommandManager.execute(Commands.FILE_QUIT);
}
});
} else {
resetStateInFailure("AutoUpdate : setUpdateParams could not be found in shell");
}
}
|
[
"function",
"(",
")",
"{",
"var",
"infoObj",
"=",
"{",
"installerPath",
":",
"formattedInstallerPath",
",",
"logFilePath",
":",
"formattedLogFilePath",
",",
"installStatusFilePath",
":",
"installStatusFilePath",
"}",
";",
"if",
"(",
"brackets",
".",
"platform",
"===",
"\"mac\"",
")",
"{",
"var",
"additionalParams",
"=",
"getAdditionalParams",
"(",
")",
",",
"key",
";",
"for",
"(",
"key",
"in",
"additionalParams",
")",
"{",
"if",
"(",
"additionalParams",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"infoObj",
"[",
"key",
"]",
"=",
"additionalParams",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"brackets",
".",
"app",
".",
"setUpdateParams",
")",
"{",
"brackets",
".",
"app",
".",
"setUpdateParams",
"(",
"JSON",
".",
"stringify",
"(",
"infoObj",
")",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"resetStateInFailure",
"(",
"\"AutoUpdate : Update parameters could not be set for the installer. Error encountered: \"",
"+",
"err",
")",
";",
"}",
"else",
"{",
"setAppQuitHandler",
"(",
")",
";",
"CommandManager",
".",
"execute",
"(",
"Commands",
".",
"FILE_QUIT",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"resetStateInFailure",
"(",
"\"AutoUpdate : setUpdateParams could not be found in shell\"",
")",
";",
"}",
"}"
] |
Update function, to carry out app update
|
[
"Update",
"function",
"to",
"carry",
"out",
"app",
"update"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L851-L882
|
train
|
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
handleValidationStatus
|
function handleValidationStatus(statusObj) {
enableCheckForUpdateEntry(true);
UpdateStatus.cleanUpdateStatus();
if (statusObj.valid) {
// Installer is validated successfully
var statusValidFn = function () {
// Restart button click handler
var restartBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART,
"autoUpdate",
"installNotification",
"installNow ",
"click"
);
detachUpdateBarBtnHandlers();
initiateUpdateProcess(statusObj.installerPath, statusObj.logFilePath, statusObj.installStatusFilePath);
};
// Later button click handler
var laterBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_LATER,
"autoUpdate",
"installNotification",
"cancel",
"click"
);
detachUpdateBarBtnHandlers();
setUpdateStateInJSON('updateInitiatedInPrevSession', false);
};
//attaching UpdateBar handlers
UpdateInfoBar.on(UpdateInfoBar.RESTART_BTN_CLICKED, restartBtnClicked);
UpdateInfoBar.on(UpdateInfoBar.LATER_BTN_CLICKED, laterBtnClicked);
UpdateInfoBar.showUpdateBar({
title: Strings.DOWNLOAD_COMPLETE,
description: Strings.CLICK_RESTART_TO_UPDATE,
needButtons: true
});
setUpdateStateInJSON("autoUpdateInProgress", false);
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOADCOMPLETE_UPDATE_BAR_RENDERED,
"autoUpdate",
"installNotification",
"render",
""
);
};
if(!isAutoUpdateInitiated) {
isAutoUpdateInitiated = true;
updateJsonHandler.refresh()
.done(function() {
setUpdateStateInJSON('downloadCompleted', true)
.done(statusValidFn);
});
} else {
setUpdateStateInJSON('downloadCompleted', true)
.done(statusValidFn);
}
} else {
// Installer validation failed
if (updateJsonHandler.get("downloadCompleted")) {
// If this was a cached download, retry downloading
updateJsonHandler.reset();
var statusInvalidFn = function () {
downloadAttemptsRemaining = MAX_DOWNLOAD_ATTEMPTS;
getLatestInstaller();
};
setUpdateStateInJSON('downloadCompleted', false)
.done(statusInvalidFn);
} else {
// If this is a new download, prompt the message on update bar
var descriptionMessage = "",
analyticsDescriptionMessage = "";
switch (statusObj.err) {
case _nodeErrorMessages.CHECKSUM_DID_NOT_MATCH:
descriptionMessage = Strings.CHECKSUM_DID_NOT_MATCH;
analyticsDescriptionMessage = "Checksum didn't match.";
break;
case _nodeErrorMessages.INSTALLER_NOT_FOUND:
descriptionMessage = Strings.INSTALLER_NOT_FOUND;
analyticsDescriptionMessage = "Installer not found.";
break;
}
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_FAILED,
"autoUpdate",
"download",
"fail",
analyticsDescriptionMessage
);
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.VALIDATION_FAILED,
description: descriptionMessage
});
setUpdateStateInJSON("autoUpdateInProgress", false);
}
}
}
|
javascript
|
function handleValidationStatus(statusObj) {
enableCheckForUpdateEntry(true);
UpdateStatus.cleanUpdateStatus();
if (statusObj.valid) {
// Installer is validated successfully
var statusValidFn = function () {
// Restart button click handler
var restartBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART,
"autoUpdate",
"installNotification",
"installNow ",
"click"
);
detachUpdateBarBtnHandlers();
initiateUpdateProcess(statusObj.installerPath, statusObj.logFilePath, statusObj.installStatusFilePath);
};
// Later button click handler
var laterBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_LATER,
"autoUpdate",
"installNotification",
"cancel",
"click"
);
detachUpdateBarBtnHandlers();
setUpdateStateInJSON('updateInitiatedInPrevSession', false);
};
//attaching UpdateBar handlers
UpdateInfoBar.on(UpdateInfoBar.RESTART_BTN_CLICKED, restartBtnClicked);
UpdateInfoBar.on(UpdateInfoBar.LATER_BTN_CLICKED, laterBtnClicked);
UpdateInfoBar.showUpdateBar({
title: Strings.DOWNLOAD_COMPLETE,
description: Strings.CLICK_RESTART_TO_UPDATE,
needButtons: true
});
setUpdateStateInJSON("autoUpdateInProgress", false);
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOADCOMPLETE_UPDATE_BAR_RENDERED,
"autoUpdate",
"installNotification",
"render",
""
);
};
if(!isAutoUpdateInitiated) {
isAutoUpdateInitiated = true;
updateJsonHandler.refresh()
.done(function() {
setUpdateStateInJSON('downloadCompleted', true)
.done(statusValidFn);
});
} else {
setUpdateStateInJSON('downloadCompleted', true)
.done(statusValidFn);
}
} else {
// Installer validation failed
if (updateJsonHandler.get("downloadCompleted")) {
// If this was a cached download, retry downloading
updateJsonHandler.reset();
var statusInvalidFn = function () {
downloadAttemptsRemaining = MAX_DOWNLOAD_ATTEMPTS;
getLatestInstaller();
};
setUpdateStateInJSON('downloadCompleted', false)
.done(statusInvalidFn);
} else {
// If this is a new download, prompt the message on update bar
var descriptionMessage = "",
analyticsDescriptionMessage = "";
switch (statusObj.err) {
case _nodeErrorMessages.CHECKSUM_DID_NOT_MATCH:
descriptionMessage = Strings.CHECKSUM_DID_NOT_MATCH;
analyticsDescriptionMessage = "Checksum didn't match.";
break;
case _nodeErrorMessages.INSTALLER_NOT_FOUND:
descriptionMessage = Strings.INSTALLER_NOT_FOUND;
analyticsDescriptionMessage = "Installer not found.";
break;
}
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_FAILED,
"autoUpdate",
"download",
"fail",
analyticsDescriptionMessage
);
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.VALIDATION_FAILED,
description: descriptionMessage
});
setUpdateStateInJSON("autoUpdateInProgress", false);
}
}
}
|
[
"function",
"handleValidationStatus",
"(",
"statusObj",
")",
"{",
"enableCheckForUpdateEntry",
"(",
"true",
")",
";",
"UpdateStatus",
".",
"cleanUpdateStatus",
"(",
")",
";",
"if",
"(",
"statusObj",
".",
"valid",
")",
"{",
"var",
"statusValidFn",
"=",
"function",
"(",
")",
"{",
"var",
"restartBtnClicked",
"=",
"function",
"(",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART",
",",
"\"autoUpdate\"",
",",
"\"installNotification\"",
",",
"\"installNow \"",
",",
"\"click\"",
")",
";",
"detachUpdateBarBtnHandlers",
"(",
")",
";",
"initiateUpdateProcess",
"(",
"statusObj",
".",
"installerPath",
",",
"statusObj",
".",
"logFilePath",
",",
"statusObj",
".",
"installStatusFilePath",
")",
";",
"}",
";",
"var",
"laterBtnClicked",
"=",
"function",
"(",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_LATER",
",",
"\"autoUpdate\"",
",",
"\"installNotification\"",
",",
"\"cancel\"",
",",
"\"click\"",
")",
";",
"detachUpdateBarBtnHandlers",
"(",
")",
";",
"setUpdateStateInJSON",
"(",
"'updateInitiatedInPrevSession'",
",",
"false",
")",
";",
"}",
";",
"UpdateInfoBar",
".",
"on",
"(",
"UpdateInfoBar",
".",
"RESTART_BTN_CLICKED",
",",
"restartBtnClicked",
")",
";",
"UpdateInfoBar",
".",
"on",
"(",
"UpdateInfoBar",
".",
"LATER_BTN_CLICKED",
",",
"laterBtnClicked",
")",
";",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"title",
":",
"Strings",
".",
"DOWNLOAD_COMPLETE",
",",
"description",
":",
"Strings",
".",
"CLICK_RESTART_TO_UPDATE",
",",
"needButtons",
":",
"true",
"}",
")",
";",
"setUpdateStateInJSON",
"(",
"\"autoUpdateInProgress\"",
",",
"false",
")",
";",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOADCOMPLETE_UPDATE_BAR_RENDERED",
",",
"\"autoUpdate\"",
",",
"\"installNotification\"",
",",
"\"render\"",
",",
"\"\"",
")",
";",
"}",
";",
"if",
"(",
"!",
"isAutoUpdateInitiated",
")",
"{",
"isAutoUpdateInitiated",
"=",
"true",
";",
"updateJsonHandler",
".",
"refresh",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"setUpdateStateInJSON",
"(",
"'downloadCompleted'",
",",
"true",
")",
".",
"done",
"(",
"statusValidFn",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"setUpdateStateInJSON",
"(",
"'downloadCompleted'",
",",
"true",
")",
".",
"done",
"(",
"statusValidFn",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"updateJsonHandler",
".",
"get",
"(",
"\"downloadCompleted\"",
")",
")",
"{",
"updateJsonHandler",
".",
"reset",
"(",
")",
";",
"var",
"statusInvalidFn",
"=",
"function",
"(",
")",
"{",
"downloadAttemptsRemaining",
"=",
"MAX_DOWNLOAD_ATTEMPTS",
";",
"getLatestInstaller",
"(",
")",
";",
"}",
";",
"setUpdateStateInJSON",
"(",
"'downloadCompleted'",
",",
"false",
")",
".",
"done",
"(",
"statusInvalidFn",
")",
";",
"}",
"else",
"{",
"var",
"descriptionMessage",
"=",
"\"\"",
",",
"analyticsDescriptionMessage",
"=",
"\"\"",
";",
"switch",
"(",
"statusObj",
".",
"err",
")",
"{",
"case",
"_nodeErrorMessages",
".",
"CHECKSUM_DID_NOT_MATCH",
":",
"descriptionMessage",
"=",
"Strings",
".",
"CHECKSUM_DID_NOT_MATCH",
";",
"analyticsDescriptionMessage",
"=",
"\"Checksum didn't match.\"",
";",
"break",
";",
"case",
"_nodeErrorMessages",
".",
"INSTALLER_NOT_FOUND",
":",
"descriptionMessage",
"=",
"Strings",
".",
"INSTALLER_NOT_FOUND",
";",
"analyticsDescriptionMessage",
"=",
"\"Installer not found.\"",
";",
"break",
";",
"}",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_FAILED",
",",
"\"autoUpdate\"",
",",
"\"download\"",
",",
"\"fail\"",
",",
"analyticsDescriptionMessage",
")",
";",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"type",
":",
"\"error\"",
",",
"title",
":",
"Strings",
".",
"VALIDATION_FAILED",
",",
"description",
":",
"descriptionMessage",
"}",
")",
";",
"setUpdateStateInJSON",
"(",
"\"autoUpdateInProgress\"",
",",
"false",
")",
";",
"}",
"}",
"}"
] |
Handles the installer validation callback from Node
@param {object} statusObj - json containing - {
valid - (boolean)true for a valid installer, false otherwise,
installerPath, logFilePath,
installStatusFilePath - for a valid installer,
err - for an invalid installer }
|
[
"Handles",
"the",
"installer",
"validation",
"callback",
"from",
"Node"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L904-L1018
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
function () {
// Restart button click handler
var restartBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART,
"autoUpdate",
"installNotification",
"installNow ",
"click"
);
detachUpdateBarBtnHandlers();
initiateUpdateProcess(statusObj.installerPath, statusObj.logFilePath, statusObj.installStatusFilePath);
};
// Later button click handler
var laterBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_LATER,
"autoUpdate",
"installNotification",
"cancel",
"click"
);
detachUpdateBarBtnHandlers();
setUpdateStateInJSON('updateInitiatedInPrevSession', false);
};
//attaching UpdateBar handlers
UpdateInfoBar.on(UpdateInfoBar.RESTART_BTN_CLICKED, restartBtnClicked);
UpdateInfoBar.on(UpdateInfoBar.LATER_BTN_CLICKED, laterBtnClicked);
UpdateInfoBar.showUpdateBar({
title: Strings.DOWNLOAD_COMPLETE,
description: Strings.CLICK_RESTART_TO_UPDATE,
needButtons: true
});
setUpdateStateInJSON("autoUpdateInProgress", false);
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOADCOMPLETE_UPDATE_BAR_RENDERED,
"autoUpdate",
"installNotification",
"render",
""
);
}
|
javascript
|
function () {
// Restart button click handler
var restartBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART,
"autoUpdate",
"installNotification",
"installNow ",
"click"
);
detachUpdateBarBtnHandlers();
initiateUpdateProcess(statusObj.installerPath, statusObj.logFilePath, statusObj.installStatusFilePath);
};
// Later button click handler
var laterBtnClicked = function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_LATER,
"autoUpdate",
"installNotification",
"cancel",
"click"
);
detachUpdateBarBtnHandlers();
setUpdateStateInJSON('updateInitiatedInPrevSession', false);
};
//attaching UpdateBar handlers
UpdateInfoBar.on(UpdateInfoBar.RESTART_BTN_CLICKED, restartBtnClicked);
UpdateInfoBar.on(UpdateInfoBar.LATER_BTN_CLICKED, laterBtnClicked);
UpdateInfoBar.showUpdateBar({
title: Strings.DOWNLOAD_COMPLETE,
description: Strings.CLICK_RESTART_TO_UPDATE,
needButtons: true
});
setUpdateStateInJSON("autoUpdateInProgress", false);
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOADCOMPLETE_UPDATE_BAR_RENDERED,
"autoUpdate",
"installNotification",
"render",
""
);
}
|
[
"function",
"(",
")",
"{",
"var",
"restartBtnClicked",
"=",
"function",
"(",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART",
",",
"\"autoUpdate\"",
",",
"\"installNotification\"",
",",
"\"installNow \"",
",",
"\"click\"",
")",
";",
"detachUpdateBarBtnHandlers",
"(",
")",
";",
"initiateUpdateProcess",
"(",
"statusObj",
".",
"installerPath",
",",
"statusObj",
".",
"logFilePath",
",",
"statusObj",
".",
"installStatusFilePath",
")",
";",
"}",
";",
"var",
"laterBtnClicked",
"=",
"function",
"(",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_LATER",
",",
"\"autoUpdate\"",
",",
"\"installNotification\"",
",",
"\"cancel\"",
",",
"\"click\"",
")",
";",
"detachUpdateBarBtnHandlers",
"(",
")",
";",
"setUpdateStateInJSON",
"(",
"'updateInitiatedInPrevSession'",
",",
"false",
")",
";",
"}",
";",
"UpdateInfoBar",
".",
"on",
"(",
"UpdateInfoBar",
".",
"RESTART_BTN_CLICKED",
",",
"restartBtnClicked",
")",
";",
"UpdateInfoBar",
".",
"on",
"(",
"UpdateInfoBar",
".",
"LATER_BTN_CLICKED",
",",
"laterBtnClicked",
")",
";",
"UpdateInfoBar",
".",
"showUpdateBar",
"(",
"{",
"title",
":",
"Strings",
".",
"DOWNLOAD_COMPLETE",
",",
"description",
":",
"Strings",
".",
"CLICK_RESTART_TO_UPDATE",
",",
"needButtons",
":",
"true",
"}",
")",
";",
"setUpdateStateInJSON",
"(",
"\"autoUpdateInProgress\"",
",",
"false",
")",
";",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOADCOMPLETE_UPDATE_BAR_RENDERED",
",",
"\"autoUpdate\"",
",",
"\"installNotification\"",
",",
"\"render\"",
",",
"\"\"",
")",
";",
"}"
] |
Installer is validated successfully
|
[
"Installer",
"is",
"validated",
"successfully"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L911-L957
|
train
|
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART,
"autoUpdate",
"installNotification",
"installNow ",
"click"
);
detachUpdateBarBtnHandlers();
initiateUpdateProcess(statusObj.installerPath, statusObj.logFilePath, statusObj.installStatusFilePath);
}
|
javascript
|
function () {
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART,
"autoUpdate",
"installNotification",
"installNow ",
"click"
);
detachUpdateBarBtnHandlers();
initiateUpdateProcess(statusObj.installerPath, statusObj.logFilePath, statusObj.installStatusFilePath);
}
|
[
"function",
"(",
")",
"{",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"autoUpdateEventNames",
".",
"AUTOUPDATE_DOWNLOAD_COMPLETE_USER_CLICK_RESTART",
",",
"\"autoUpdate\"",
",",
"\"installNotification\"",
",",
"\"installNow \"",
",",
"\"click\"",
")",
";",
"detachUpdateBarBtnHandlers",
"(",
")",
";",
"initiateUpdateProcess",
"(",
"statusObj",
".",
"installerPath",
",",
"statusObj",
".",
"logFilePath",
",",
"statusObj",
".",
"installStatusFilePath",
")",
";",
"}"
] |
Restart button click handler
|
[
"Restart",
"button",
"click",
"handler"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L914-L924
|
train
|
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
handleDownloadFailure
|
function handleDownloadFailure(message) {
console.log("AutoUpdate : Download of latest installer failed in Attempt " +
(MAX_DOWNLOAD_ATTEMPTS - downloadAttemptsRemaining) + ".\n Reason : " + message);
if (downloadAttemptsRemaining) {
// Retry the downloading
attemptToDownload();
} else {
// Download could not completed, all attempts exhausted
enableCheckForUpdateEntry(true);
UpdateStatus.cleanUpdateStatus();
var descriptionMessage = "",
analyticsDescriptionMessage = "";
if (message === _nodeErrorMessages.DOWNLOAD_ERROR) {
descriptionMessage = Strings.DOWNLOAD_ERROR;
analyticsDescriptionMessage = "Error occurred while downloading.";
} else if (message === _nodeErrorMessages.NETWORK_SLOW_OR_DISCONNECTED) {
descriptionMessage = Strings.NETWORK_SLOW_OR_DISCONNECTED;
analyticsDescriptionMessage = "Network is Disconnected or too slow.";
}
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_FAILED,
"autoUpdate",
"download",
"fail",
analyticsDescriptionMessage
);
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.DOWNLOAD_FAILED,
description: descriptionMessage
});
setUpdateStateInJSON("autoUpdateInProgress", false);
}
}
|
javascript
|
function handleDownloadFailure(message) {
console.log("AutoUpdate : Download of latest installer failed in Attempt " +
(MAX_DOWNLOAD_ATTEMPTS - downloadAttemptsRemaining) + ".\n Reason : " + message);
if (downloadAttemptsRemaining) {
// Retry the downloading
attemptToDownload();
} else {
// Download could not completed, all attempts exhausted
enableCheckForUpdateEntry(true);
UpdateStatus.cleanUpdateStatus();
var descriptionMessage = "",
analyticsDescriptionMessage = "";
if (message === _nodeErrorMessages.DOWNLOAD_ERROR) {
descriptionMessage = Strings.DOWNLOAD_ERROR;
analyticsDescriptionMessage = "Error occurred while downloading.";
} else if (message === _nodeErrorMessages.NETWORK_SLOW_OR_DISCONNECTED) {
descriptionMessage = Strings.NETWORK_SLOW_OR_DISCONNECTED;
analyticsDescriptionMessage = "Network is Disconnected or too slow.";
}
HealthLogger.sendAnalyticsData(
autoUpdateEventNames.AUTOUPDATE_DOWNLOAD_FAILED,
"autoUpdate",
"download",
"fail",
analyticsDescriptionMessage
);
UpdateInfoBar.showUpdateBar({
type: "error",
title: Strings.DOWNLOAD_FAILED,
description: descriptionMessage
});
setUpdateStateInJSON("autoUpdateInProgress", false);
}
}
|
[
"function",
"handleDownloadFailure",
"(",
"message",
")",
"{",
"console",
".",
"log",
"(",
"\"AutoUpdate : Download of latest installer failed in Attempt \"",
"+",
"(",
"MAX_DOWNLOAD_ATTEMPTS",
"-",
"downloadAttemptsRemaining",
")",
"+",
"\".\\n Reason : \"",
"+",
"\\n",
")",
";",
"message",
"}"
] |
Handles the download failure callback from Node
@param {string} message - reason of download failure
|
[
"Handles",
"the",
"download",
"failure",
"callback",
"from",
"Node"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L1024-L1063
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/main.js
|
registerBracketsFunctions
|
function registerBracketsFunctions() {
functionMap["brackets.notifyinitializationComplete"] = handleInitializationComplete;
functionMap["brackets.showStatusInfo"] = showStatusInfo;
functionMap["brackets.notifyDownloadSuccess"] = handleDownloadSuccess;
functionMap["brackets.showErrorMessage"] = showErrorMessage;
functionMap["brackets.notifyDownloadFailure"] = handleDownloadFailure;
functionMap["brackets.notifySafeToDownload"] = handleSafeToDownload;
functionMap["brackets.notifyvalidationStatus"] = handleValidationStatus;
functionMap["brackets.notifyInstallationStatus"] = handleInstallationStatus;
ProjectManager.on("beforeProjectClose beforeAppClose", _handleAppClose);
}
|
javascript
|
function registerBracketsFunctions() {
functionMap["brackets.notifyinitializationComplete"] = handleInitializationComplete;
functionMap["brackets.showStatusInfo"] = showStatusInfo;
functionMap["brackets.notifyDownloadSuccess"] = handleDownloadSuccess;
functionMap["brackets.showErrorMessage"] = showErrorMessage;
functionMap["brackets.notifyDownloadFailure"] = handleDownloadFailure;
functionMap["brackets.notifySafeToDownload"] = handleSafeToDownload;
functionMap["brackets.notifyvalidationStatus"] = handleValidationStatus;
functionMap["brackets.notifyInstallationStatus"] = handleInstallationStatus;
ProjectManager.on("beforeProjectClose beforeAppClose", _handleAppClose);
}
|
[
"function",
"registerBracketsFunctions",
"(",
")",
"{",
"functionMap",
"[",
"\"brackets.notifyinitializationComplete\"",
"]",
"=",
"handleInitializationComplete",
";",
"functionMap",
"[",
"\"brackets.showStatusInfo\"",
"]",
"=",
"showStatusInfo",
";",
"functionMap",
"[",
"\"brackets.notifyDownloadSuccess\"",
"]",
"=",
"handleDownloadSuccess",
";",
"functionMap",
"[",
"\"brackets.showErrorMessage\"",
"]",
"=",
"showErrorMessage",
";",
"functionMap",
"[",
"\"brackets.notifyDownloadFailure\"",
"]",
"=",
"handleDownloadFailure",
";",
"functionMap",
"[",
"\"brackets.notifySafeToDownload\"",
"]",
"=",
"handleSafeToDownload",
";",
"functionMap",
"[",
"\"brackets.notifyvalidationStatus\"",
"]",
"=",
"handleValidationStatus",
";",
"functionMap",
"[",
"\"brackets.notifyInstallationStatus\"",
"]",
"=",
"handleInstallationStatus",
";",
"ProjectManager",
".",
"on",
"(",
"\"beforeProjectClose beforeAppClose\"",
",",
"_handleAppClose",
")",
";",
"}"
] |
Generates a map for brackets side functions
|
[
"Generates",
"a",
"map",
"for",
"brackets",
"side",
"functions"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/main.js#L1098-L1109
|
train
|
adobe/brackets
|
src/extensions/default/MDNDocs/main.js
|
inlineProvider
|
function inlineProvider(hostEditor, pos) {
var jsonFile, propInfo,
propQueue = [], // priority queue of propNames to try
langId = hostEditor.getLanguageForSelection().getId(),
supportedLangs = {
"css": true,
"scss": true,
"less": true,
"html": true
},
isQuickDocAvailable = langId ? supportedLangs[langId] : -1; // fail if langId is falsy
// Only provide docs when cursor is in supported language
if (!isQuickDocAvailable) {
return null;
}
// Send analytics data for Quick Doc open
HealthLogger.sendAnalyticsData(
"cssQuickDoc",
"usage",
"quickDoc",
"open"
);
// Only provide docs if the selection is within a single line
var sel = hostEditor.getSelection();
if (sel.start.line !== sel.end.line) {
return null;
}
if (langId === "html") { // HTML
jsonFile = "html.json";
propInfo = HTMLUtils.getTagInfo(hostEditor, sel.start);
if (propInfo.position.tokenType === HTMLUtils.ATTR_NAME && propInfo.attr && propInfo.attr.name) {
// we're on an HTML attribute (and not on its value)
propQueue.push(propInfo.attr.name.toLowerCase());
}
if (propInfo.tagName) { // we're somehow on an HTML tag (no matter where exactly)
propInfo = propInfo.tagName.toLowerCase();
propQueue.push("<" + propInfo + ">");
}
} else { // CSS-like language
jsonFile = "css.json";
propInfo = CSSUtils.getInfoAtPos(hostEditor, sel.start);
if (propInfo.name) {
propQueue.push(propInfo.name);
// remove possible vendor prefixes
propQueue.push(propInfo.name.replace(/^-(?:webkit|moz|ms|o)-/, ""));
}
}
// Are we on a supported property? (no matter if info is available for the property)
if (propQueue.length) {
var result = new $.Deferred();
// Load JSON file if not done yet
getDocs(jsonFile)
.done(function (docs) {
// Construct inline widget (if we have docs for this property)
var displayName, propDetails,
propName = _.find(propQueue, function (propName) { // find the first property where info is available
return docs.hasOwnProperty(propName);
});
if (propName) {
propDetails = docs[propName];
displayName = propName.substr(propName.lastIndexOf("/") + 1);
}
if (propDetails) {
var inlineWidget = new InlineDocsViewer(displayName, propDetails);
inlineWidget.load(hostEditor);
result.resolve(inlineWidget);
} else {
result.reject();
}
})
.fail(function () {
result.reject();
});
return result.promise();
} else {
return null;
}
}
|
javascript
|
function inlineProvider(hostEditor, pos) {
var jsonFile, propInfo,
propQueue = [], // priority queue of propNames to try
langId = hostEditor.getLanguageForSelection().getId(),
supportedLangs = {
"css": true,
"scss": true,
"less": true,
"html": true
},
isQuickDocAvailable = langId ? supportedLangs[langId] : -1; // fail if langId is falsy
// Only provide docs when cursor is in supported language
if (!isQuickDocAvailable) {
return null;
}
// Send analytics data for Quick Doc open
HealthLogger.sendAnalyticsData(
"cssQuickDoc",
"usage",
"quickDoc",
"open"
);
// Only provide docs if the selection is within a single line
var sel = hostEditor.getSelection();
if (sel.start.line !== sel.end.line) {
return null;
}
if (langId === "html") { // HTML
jsonFile = "html.json";
propInfo = HTMLUtils.getTagInfo(hostEditor, sel.start);
if (propInfo.position.tokenType === HTMLUtils.ATTR_NAME && propInfo.attr && propInfo.attr.name) {
// we're on an HTML attribute (and not on its value)
propQueue.push(propInfo.attr.name.toLowerCase());
}
if (propInfo.tagName) { // we're somehow on an HTML tag (no matter where exactly)
propInfo = propInfo.tagName.toLowerCase();
propQueue.push("<" + propInfo + ">");
}
} else { // CSS-like language
jsonFile = "css.json";
propInfo = CSSUtils.getInfoAtPos(hostEditor, sel.start);
if (propInfo.name) {
propQueue.push(propInfo.name);
// remove possible vendor prefixes
propQueue.push(propInfo.name.replace(/^-(?:webkit|moz|ms|o)-/, ""));
}
}
// Are we on a supported property? (no matter if info is available for the property)
if (propQueue.length) {
var result = new $.Deferred();
// Load JSON file if not done yet
getDocs(jsonFile)
.done(function (docs) {
// Construct inline widget (if we have docs for this property)
var displayName, propDetails,
propName = _.find(propQueue, function (propName) { // find the first property where info is available
return docs.hasOwnProperty(propName);
});
if (propName) {
propDetails = docs[propName];
displayName = propName.substr(propName.lastIndexOf("/") + 1);
}
if (propDetails) {
var inlineWidget = new InlineDocsViewer(displayName, propDetails);
inlineWidget.load(hostEditor);
result.resolve(inlineWidget);
} else {
result.reject();
}
})
.fail(function () {
result.reject();
});
return result.promise();
} else {
return null;
}
}
|
[
"function",
"inlineProvider",
"(",
"hostEditor",
",",
"pos",
")",
"{",
"var",
"jsonFile",
",",
"propInfo",
",",
"propQueue",
"=",
"[",
"]",
",",
"langId",
"=",
"hostEditor",
".",
"getLanguageForSelection",
"(",
")",
".",
"getId",
"(",
")",
",",
"supportedLangs",
"=",
"{",
"\"css\"",
":",
"true",
",",
"\"scss\"",
":",
"true",
",",
"\"less\"",
":",
"true",
",",
"\"html\"",
":",
"true",
"}",
",",
"isQuickDocAvailable",
"=",
"langId",
"?",
"supportedLangs",
"[",
"langId",
"]",
":",
"-",
"1",
";",
"if",
"(",
"!",
"isQuickDocAvailable",
")",
"{",
"return",
"null",
";",
"}",
"HealthLogger",
".",
"sendAnalyticsData",
"(",
"\"cssQuickDoc\"",
",",
"\"usage\"",
",",
"\"quickDoc\"",
",",
"\"open\"",
")",
";",
"var",
"sel",
"=",
"hostEditor",
".",
"getSelection",
"(",
")",
";",
"if",
"(",
"sel",
".",
"start",
".",
"line",
"!==",
"sel",
".",
"end",
".",
"line",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"langId",
"===",
"\"html\"",
")",
"{",
"jsonFile",
"=",
"\"html.json\"",
";",
"propInfo",
"=",
"HTMLUtils",
".",
"getTagInfo",
"(",
"hostEditor",
",",
"sel",
".",
"start",
")",
";",
"if",
"(",
"propInfo",
".",
"position",
".",
"tokenType",
"===",
"HTMLUtils",
".",
"ATTR_NAME",
"&&",
"propInfo",
".",
"attr",
"&&",
"propInfo",
".",
"attr",
".",
"name",
")",
"{",
"propQueue",
".",
"push",
"(",
"propInfo",
".",
"attr",
".",
"name",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
"if",
"(",
"propInfo",
".",
"tagName",
")",
"{",
"propInfo",
"=",
"propInfo",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
";",
"propQueue",
".",
"push",
"(",
"\"<\"",
"+",
"propInfo",
"+",
"\">\"",
")",
";",
"}",
"}",
"else",
"{",
"jsonFile",
"=",
"\"css.json\"",
";",
"propInfo",
"=",
"CSSUtils",
".",
"getInfoAtPos",
"(",
"hostEditor",
",",
"sel",
".",
"start",
")",
";",
"if",
"(",
"propInfo",
".",
"name",
")",
"{",
"propQueue",
".",
"push",
"(",
"propInfo",
".",
"name",
")",
";",
"propQueue",
".",
"push",
"(",
"propInfo",
".",
"name",
".",
"replace",
"(",
"/",
"^-(?:webkit|moz|ms|o)-",
"/",
",",
"\"\"",
")",
")",
";",
"}",
"}",
"if",
"(",
"propQueue",
".",
"length",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"getDocs",
"(",
"jsonFile",
")",
".",
"done",
"(",
"function",
"(",
"docs",
")",
"{",
"var",
"displayName",
",",
"propDetails",
",",
"propName",
"=",
"_",
".",
"find",
"(",
"propQueue",
",",
"function",
"(",
"propName",
")",
"{",
"return",
"docs",
".",
"hasOwnProperty",
"(",
"propName",
")",
";",
"}",
")",
";",
"if",
"(",
"propName",
")",
"{",
"propDetails",
"=",
"docs",
"[",
"propName",
"]",
";",
"displayName",
"=",
"propName",
".",
"substr",
"(",
"propName",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
"+",
"1",
")",
";",
"}",
"if",
"(",
"propDetails",
")",
"{",
"var",
"inlineWidget",
"=",
"new",
"InlineDocsViewer",
"(",
"displayName",
",",
"propDetails",
")",
";",
"inlineWidget",
".",
"load",
"(",
"hostEditor",
")",
";",
"result",
".",
"resolve",
"(",
"inlineWidget",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Inline docs provider.
@param {!Editor} editor
@param {!{line:Number, ch:Number}} pos
@return {?$.Promise} resolved with an InlineWidget; null if we're not going to provide anything
|
[
"Inline",
"docs",
"provider",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/MDNDocs/main.js#L89-L176
|
train
|
adobe/brackets
|
src/extensions/default/HealthData/HealthDataManager.js
|
getHealthData
|
function getHealthData() {
var result = new $.Deferred(),
oneTimeHealthData = {};
oneTimeHealthData.snapshotTime = Date.now();
oneTimeHealthData.os = brackets.platform;
oneTimeHealthData.userAgent = window.navigator.userAgent;
oneTimeHealthData.osLanguage = brackets.app.language;
oneTimeHealthData.bracketsLanguage = brackets.getLocale();
oneTimeHealthData.bracketsVersion = brackets.metadata.version;
$.extend(oneTimeHealthData, HealthLogger.getAggregatedHealthData());
HealthDataUtils.getUserInstalledExtensions()
.done(function (userInstalledExtensions) {
oneTimeHealthData.installedExtensions = userInstalledExtensions;
})
.always(function () {
HealthDataUtils.getUserInstalledTheme()
.done(function (bracketsTheme) {
oneTimeHealthData.bracketsTheme = bracketsTheme;
})
.always(function () {
var userUuid = PreferencesManager.getViewState("UUID");
var olderUuid = PreferencesManager.getViewState("OlderUUID");
if (userUuid && olderUuid) {
oneTimeHealthData.uuid = userUuid;
oneTimeHealthData.olderuuid = olderUuid;
return result.resolve(oneTimeHealthData);
} else {
// So we are going to get the Machine hash in either of the cases.
if (appshell.app.getMachineHash) {
appshell.app.getMachineHash(function (err, macHash) {
var generatedUuid;
if (err) {
generatedUuid = uuid.v4();
} else {
generatedUuid = macHash;
}
if (!userUuid) {
// Could be a new user. In this case
// both will remain the same.
userUuid = olderUuid = generatedUuid;
} else {
// For existing user, we will still cache
// the older uuid, so that we can improve
// our reporting in terms of figuring out
// the new users accurately.
olderUuid = userUuid;
userUuid = generatedUuid;
}
PreferencesManager.setViewState("UUID", userUuid);
PreferencesManager.setViewState("OlderUUID", olderUuid);
oneTimeHealthData.uuid = userUuid;
oneTimeHealthData.olderuuid = olderUuid;
return result.resolve(oneTimeHealthData);
});
} else {
// Probably running on older shell, in which case we will
// assign the same uuid to olderuuid.
if (!userUuid) {
oneTimeHealthData.uuid = oneTimeHealthData.olderuuid = uuid.v4();
} else {
oneTimeHealthData.olderuuid = userUuid;
}
PreferencesManager.setViewState("UUID", oneTimeHealthData.uuid);
PreferencesManager.setViewState("OlderUUID", oneTimeHealthData.olderuuid);
return result.resolve(oneTimeHealthData);
}
}
});
});
return result.promise();
}
|
javascript
|
function getHealthData() {
var result = new $.Deferred(),
oneTimeHealthData = {};
oneTimeHealthData.snapshotTime = Date.now();
oneTimeHealthData.os = brackets.platform;
oneTimeHealthData.userAgent = window.navigator.userAgent;
oneTimeHealthData.osLanguage = brackets.app.language;
oneTimeHealthData.bracketsLanguage = brackets.getLocale();
oneTimeHealthData.bracketsVersion = brackets.metadata.version;
$.extend(oneTimeHealthData, HealthLogger.getAggregatedHealthData());
HealthDataUtils.getUserInstalledExtensions()
.done(function (userInstalledExtensions) {
oneTimeHealthData.installedExtensions = userInstalledExtensions;
})
.always(function () {
HealthDataUtils.getUserInstalledTheme()
.done(function (bracketsTheme) {
oneTimeHealthData.bracketsTheme = bracketsTheme;
})
.always(function () {
var userUuid = PreferencesManager.getViewState("UUID");
var olderUuid = PreferencesManager.getViewState("OlderUUID");
if (userUuid && olderUuid) {
oneTimeHealthData.uuid = userUuid;
oneTimeHealthData.olderuuid = olderUuid;
return result.resolve(oneTimeHealthData);
} else {
// So we are going to get the Machine hash in either of the cases.
if (appshell.app.getMachineHash) {
appshell.app.getMachineHash(function (err, macHash) {
var generatedUuid;
if (err) {
generatedUuid = uuid.v4();
} else {
generatedUuid = macHash;
}
if (!userUuid) {
// Could be a new user. In this case
// both will remain the same.
userUuid = olderUuid = generatedUuid;
} else {
// For existing user, we will still cache
// the older uuid, so that we can improve
// our reporting in terms of figuring out
// the new users accurately.
olderUuid = userUuid;
userUuid = generatedUuid;
}
PreferencesManager.setViewState("UUID", userUuid);
PreferencesManager.setViewState("OlderUUID", olderUuid);
oneTimeHealthData.uuid = userUuid;
oneTimeHealthData.olderuuid = olderUuid;
return result.resolve(oneTimeHealthData);
});
} else {
// Probably running on older shell, in which case we will
// assign the same uuid to olderuuid.
if (!userUuid) {
oneTimeHealthData.uuid = oneTimeHealthData.olderuuid = uuid.v4();
} else {
oneTimeHealthData.olderuuid = userUuid;
}
PreferencesManager.setViewState("UUID", oneTimeHealthData.uuid);
PreferencesManager.setViewState("OlderUUID", oneTimeHealthData.olderuuid);
return result.resolve(oneTimeHealthData);
}
}
});
});
return result.promise();
}
|
[
"function",
"getHealthData",
"(",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"oneTimeHealthData",
"=",
"{",
"}",
";",
"oneTimeHealthData",
".",
"snapshotTime",
"=",
"Date",
".",
"now",
"(",
")",
";",
"oneTimeHealthData",
".",
"os",
"=",
"brackets",
".",
"platform",
";",
"oneTimeHealthData",
".",
"userAgent",
"=",
"window",
".",
"navigator",
".",
"userAgent",
";",
"oneTimeHealthData",
".",
"osLanguage",
"=",
"brackets",
".",
"app",
".",
"language",
";",
"oneTimeHealthData",
".",
"bracketsLanguage",
"=",
"brackets",
".",
"getLocale",
"(",
")",
";",
"oneTimeHealthData",
".",
"bracketsVersion",
"=",
"brackets",
".",
"metadata",
".",
"version",
";",
"$",
".",
"extend",
"(",
"oneTimeHealthData",
",",
"HealthLogger",
".",
"getAggregatedHealthData",
"(",
")",
")",
";",
"HealthDataUtils",
".",
"getUserInstalledExtensions",
"(",
")",
".",
"done",
"(",
"function",
"(",
"userInstalledExtensions",
")",
"{",
"oneTimeHealthData",
".",
"installedExtensions",
"=",
"userInstalledExtensions",
";",
"}",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"HealthDataUtils",
".",
"getUserInstalledTheme",
"(",
")",
".",
"done",
"(",
"function",
"(",
"bracketsTheme",
")",
"{",
"oneTimeHealthData",
".",
"bracketsTheme",
"=",
"bracketsTheme",
";",
"}",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"var",
"userUuid",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"UUID\"",
")",
";",
"var",
"olderUuid",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"OlderUUID\"",
")",
";",
"if",
"(",
"userUuid",
"&&",
"olderUuid",
")",
"{",
"oneTimeHealthData",
".",
"uuid",
"=",
"userUuid",
";",
"oneTimeHealthData",
".",
"olderuuid",
"=",
"olderUuid",
";",
"return",
"result",
".",
"resolve",
"(",
"oneTimeHealthData",
")",
";",
"}",
"else",
"{",
"if",
"(",
"appshell",
".",
"app",
".",
"getMachineHash",
")",
"{",
"appshell",
".",
"app",
".",
"getMachineHash",
"(",
"function",
"(",
"err",
",",
"macHash",
")",
"{",
"var",
"generatedUuid",
";",
"if",
"(",
"err",
")",
"{",
"generatedUuid",
"=",
"uuid",
".",
"v4",
"(",
")",
";",
"}",
"else",
"{",
"generatedUuid",
"=",
"macHash",
";",
"}",
"if",
"(",
"!",
"userUuid",
")",
"{",
"userUuid",
"=",
"olderUuid",
"=",
"generatedUuid",
";",
"}",
"else",
"{",
"olderUuid",
"=",
"userUuid",
";",
"userUuid",
"=",
"generatedUuid",
";",
"}",
"PreferencesManager",
".",
"setViewState",
"(",
"\"UUID\"",
",",
"userUuid",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"OlderUUID\"",
",",
"olderUuid",
")",
";",
"oneTimeHealthData",
".",
"uuid",
"=",
"userUuid",
";",
"oneTimeHealthData",
".",
"olderuuid",
"=",
"olderUuid",
";",
"return",
"result",
".",
"resolve",
"(",
"oneTimeHealthData",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"userUuid",
")",
"{",
"oneTimeHealthData",
".",
"uuid",
"=",
"oneTimeHealthData",
".",
"olderuuid",
"=",
"uuid",
".",
"v4",
"(",
")",
";",
"}",
"else",
"{",
"oneTimeHealthData",
".",
"olderuuid",
"=",
"userUuid",
";",
"}",
"PreferencesManager",
".",
"setViewState",
"(",
"\"UUID\"",
",",
"oneTimeHealthData",
".",
"uuid",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"OlderUUID\"",
",",
"oneTimeHealthData",
".",
"olderuuid",
")",
";",
"return",
"result",
".",
"resolve",
"(",
"oneTimeHealthData",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Get the Health Data which will be sent to the server. Initially it is only one time data.
|
[
"Get",
"the",
"Health",
"Data",
"which",
"will",
"be",
"sent",
"to",
"the",
"server",
".",
"Initially",
"it",
"is",
"only",
"one",
"time",
"data",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/HealthData/HealthDataManager.js#L51-L130
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.