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/editor/CodeHintList.js
|
_itemsPerPage
|
function _itemsPerPage() {
var itemsPerPage = 1,
$items = self.$hintMenu.find("li"),
$view = self.$hintMenu.find("ul.dropdown-menu"),
itemHeight;
if ($items.length !== 0) {
itemHeight = $($items[0]).height();
if (itemHeight) {
// round down to integer value
itemsPerPage = Math.floor($view.height() / itemHeight);
itemsPerPage = Math.max(1, Math.min(itemsPerPage, $items.length));
}
}
return itemsPerPage;
}
|
javascript
|
function _itemsPerPage() {
var itemsPerPage = 1,
$items = self.$hintMenu.find("li"),
$view = self.$hintMenu.find("ul.dropdown-menu"),
itemHeight;
if ($items.length !== 0) {
itemHeight = $($items[0]).height();
if (itemHeight) {
// round down to integer value
itemsPerPage = Math.floor($view.height() / itemHeight);
itemsPerPage = Math.max(1, Math.min(itemsPerPage, $items.length));
}
}
return itemsPerPage;
}
|
[
"function",
"_itemsPerPage",
"(",
")",
"{",
"var",
"itemsPerPage",
"=",
"1",
",",
"$items",
"=",
"self",
".",
"$hintMenu",
".",
"find",
"(",
"\"li\"",
")",
",",
"$view",
"=",
"self",
".",
"$hintMenu",
".",
"find",
"(",
"\"ul.dropdown-menu\"",
")",
",",
"itemHeight",
";",
"if",
"(",
"$items",
".",
"length",
"!==",
"0",
")",
"{",
"itemHeight",
"=",
"$",
"(",
"$items",
"[",
"0",
"]",
")",
".",
"height",
"(",
")",
";",
"if",
"(",
"itemHeight",
")",
"{",
"itemsPerPage",
"=",
"Math",
".",
"floor",
"(",
"$view",
".",
"height",
"(",
")",
"/",
"itemHeight",
")",
";",
"itemsPerPage",
"=",
"Math",
".",
"max",
"(",
"1",
",",
"Math",
".",
"min",
"(",
"itemsPerPage",
",",
"$items",
".",
"length",
")",
")",
";",
"}",
"}",
"return",
"itemsPerPage",
";",
"}"
] |
Calculate the number of items per scroll page.
|
[
"Calculate",
"the",
"number",
"of",
"items",
"per",
"scroll",
"page",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/CodeHintList.js#L389-L405
|
train
|
adobe/brackets
|
src/language/JSONUtils.js
|
stripQuotes
|
function stripQuotes(string) {
if (string) {
if (/^['"]$/.test(string.charAt(0))) {
string = string.substr(1);
}
if (/^['"]$/.test(string.substr(-1, 1))) {
string = string.substr(0, string.length - 1);
}
}
return string;
}
|
javascript
|
function stripQuotes(string) {
if (string) {
if (/^['"]$/.test(string.charAt(0))) {
string = string.substr(1);
}
if (/^['"]$/.test(string.substr(-1, 1))) {
string = string.substr(0, string.length - 1);
}
}
return string;
}
|
[
"function",
"stripQuotes",
"(",
"string",
")",
"{",
"if",
"(",
"string",
")",
"{",
"if",
"(",
"/",
"^['\"]$",
"/",
".",
"test",
"(",
"string",
".",
"charAt",
"(",
"0",
")",
")",
")",
"{",
"string",
"=",
"string",
".",
"substr",
"(",
"1",
")",
";",
"}",
"if",
"(",
"/",
"^['\"]$",
"/",
".",
"test",
"(",
"string",
".",
"substr",
"(",
"-",
"1",
",",
"1",
")",
")",
")",
"{",
"string",
"=",
"string",
".",
"substr",
"(",
"0",
",",
"string",
".",
"length",
"-",
"1",
")",
";",
"}",
"}",
"return",
"string",
";",
"}"
] |
Removes the quotes around a string
@param {!String} string
@return {String}
|
[
"Removes",
"the",
"quotes",
"around",
"a",
"string"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/language/JSONUtils.js#L75-L85
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
add
|
function add() {
var root = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath),
recentProjects = getRecentProjects(),
index = recentProjects.indexOf(root);
if (index !== -1) {
recentProjects.splice(index, 1);
}
recentProjects.unshift(root);
if (recentProjects.length > MAX_PROJECTS) {
recentProjects = recentProjects.slice(0, MAX_PROJECTS);
}
PreferencesManager.setViewState("recentProjects", recentProjects);
}
|
javascript
|
function add() {
var root = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath),
recentProjects = getRecentProjects(),
index = recentProjects.indexOf(root);
if (index !== -1) {
recentProjects.splice(index, 1);
}
recentProjects.unshift(root);
if (recentProjects.length > MAX_PROJECTS) {
recentProjects = recentProjects.slice(0, MAX_PROJECTS);
}
PreferencesManager.setViewState("recentProjects", recentProjects);
}
|
[
"function",
"add",
"(",
")",
"{",
"var",
"root",
"=",
"FileUtils",
".",
"stripTrailingSlash",
"(",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
".",
"fullPath",
")",
",",
"recentProjects",
"=",
"getRecentProjects",
"(",
")",
",",
"index",
"=",
"recentProjects",
".",
"indexOf",
"(",
"root",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"recentProjects",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"recentProjects",
".",
"unshift",
"(",
"root",
")",
";",
"if",
"(",
"recentProjects",
".",
"length",
">",
"MAX_PROJECTS",
")",
"{",
"recentProjects",
"=",
"recentProjects",
".",
"slice",
"(",
"0",
",",
"MAX_PROJECTS",
")",
";",
"}",
"PreferencesManager",
".",
"setViewState",
"(",
"\"recentProjects\"",
",",
"recentProjects",
")",
";",
"}"
] |
Add a project to the stored list of recent projects, up to MAX_PROJECTS.
|
[
"Add",
"a",
"project",
"to",
"the",
"stored",
"list",
"of",
"recent",
"projects",
"up",
"to",
"MAX_PROJECTS",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L78-L91
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
checkHovers
|
function checkHovers(pageX, pageY) {
$dropdown.children().each(function () {
var offset = $(this).offset(),
width = $(this).outerWidth(),
height = $(this).outerHeight();
if (pageX >= offset.left && pageX <= offset.left + width &&
pageY >= offset.top && pageY <= offset.top + height) {
$(".recent-folder-link", this).triggerHandler("mouseenter");
}
});
}
|
javascript
|
function checkHovers(pageX, pageY) {
$dropdown.children().each(function () {
var offset = $(this).offset(),
width = $(this).outerWidth(),
height = $(this).outerHeight();
if (pageX >= offset.left && pageX <= offset.left + width &&
pageY >= offset.top && pageY <= offset.top + height) {
$(".recent-folder-link", this).triggerHandler("mouseenter");
}
});
}
|
[
"function",
"checkHovers",
"(",
"pageX",
",",
"pageY",
")",
"{",
"$dropdown",
".",
"children",
"(",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"offset",
"=",
"$",
"(",
"this",
")",
".",
"offset",
"(",
")",
",",
"width",
"=",
"$",
"(",
"this",
")",
".",
"outerWidth",
"(",
")",
",",
"height",
"=",
"$",
"(",
"this",
")",
".",
"outerHeight",
"(",
")",
";",
"if",
"(",
"pageX",
">=",
"offset",
".",
"left",
"&&",
"pageX",
"<=",
"offset",
".",
"left",
"+",
"width",
"&&",
"pageY",
">=",
"offset",
".",
"top",
"&&",
"pageY",
"<=",
"offset",
".",
"top",
"+",
"height",
")",
"{",
"$",
"(",
"\".recent-folder-link\"",
",",
"this",
")",
".",
"triggerHandler",
"(",
"\"mouseenter\"",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Check the list of items to see if any of them are hovered, and if so trigger a mouseenter.
Normally the mouseenter event handles this, but when a previous item is deleted and the next
item moves up to be underneath the mouse, we don't get a mouseenter event for that item.
|
[
"Check",
"the",
"list",
"of",
"items",
"to",
"see",
"if",
"any",
"of",
"them",
"are",
"hovered",
"and",
"if",
"so",
"trigger",
"a",
"mouseenter",
".",
"Normally",
"the",
"mouseenter",
"event",
"handles",
"this",
"but",
"when",
"a",
"previous",
"item",
"is",
"deleted",
"and",
"the",
"next",
"item",
"moves",
"up",
"to",
"be",
"underneath",
"the",
"mouse",
"we",
"don",
"t",
"get",
"a",
"mouseenter",
"event",
"for",
"that",
"item",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L98-L109
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
renderDelete
|
function renderDelete() {
return $("<div id='recent-folder-delete' class='trash-icon'>×</div>")
.mouseup(function (e) {
// Don't let the click bubble upward.
e.stopPropagation();
// Remove the project from the preferences.
var recentProjects = getRecentProjects(),
index = recentProjects.indexOf($(this).parent().data("path")),
newProjects = [],
i;
for (i = 0; i < recentProjects.length; i++) {
if (i !== index) {
newProjects.push(recentProjects[i]);
}
}
PreferencesManager.setViewState("recentProjects", newProjects);
$(this).closest("li").remove();
checkHovers(e.pageX, e.pageY);
if (newProjects.length === 1) {
$dropdown.find(".divider").remove();
}
});
}
|
javascript
|
function renderDelete() {
return $("<div id='recent-folder-delete' class='trash-icon'>×</div>")
.mouseup(function (e) {
// Don't let the click bubble upward.
e.stopPropagation();
// Remove the project from the preferences.
var recentProjects = getRecentProjects(),
index = recentProjects.indexOf($(this).parent().data("path")),
newProjects = [],
i;
for (i = 0; i < recentProjects.length; i++) {
if (i !== index) {
newProjects.push(recentProjects[i]);
}
}
PreferencesManager.setViewState("recentProjects", newProjects);
$(this).closest("li").remove();
checkHovers(e.pageX, e.pageY);
if (newProjects.length === 1) {
$dropdown.find(".divider").remove();
}
});
}
|
[
"function",
"renderDelete",
"(",
")",
"{",
"return",
"$",
"(",
"\"<div id='recent-folder-delete' class='trash-icon'>×</div>\"",
")",
".",
"mouseup",
"(",
"function",
"(",
"e",
")",
"{",
"e",
".",
"stopPropagation",
"(",
")",
";",
"var",
"recentProjects",
"=",
"getRecentProjects",
"(",
")",
",",
"index",
"=",
"recentProjects",
".",
"indexOf",
"(",
"$",
"(",
"this",
")",
".",
"parent",
"(",
")",
".",
"data",
"(",
"\"path\"",
")",
")",
",",
"newProjects",
"=",
"[",
"]",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"recentProjects",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"!==",
"index",
")",
"{",
"newProjects",
".",
"push",
"(",
"recentProjects",
"[",
"i",
"]",
")",
";",
"}",
"}",
"PreferencesManager",
".",
"setViewState",
"(",
"\"recentProjects\"",
",",
"newProjects",
")",
";",
"$",
"(",
"this",
")",
".",
"closest",
"(",
"\"li\"",
")",
".",
"remove",
"(",
")",
";",
"checkHovers",
"(",
"e",
".",
"pageX",
",",
"e",
".",
"pageY",
")",
";",
"if",
"(",
"newProjects",
".",
"length",
"===",
"1",
")",
"{",
"$dropdown",
".",
"find",
"(",
"\".divider\"",
")",
".",
"remove",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Create the "delete" button that shows up when you hover over a project.
|
[
"Create",
"the",
"delete",
"button",
"that",
"shows",
"up",
"when",
"you",
"hover",
"over",
"a",
"project",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L114-L138
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
selectNextItem
|
function selectNextItem(direction) {
var $links = $dropdown.find("a"),
index = $dropdownItem ? $links.index($dropdownItem) : (direction > 0 ? -1 : 0),
$newItem = $links.eq((index + direction) % $links.length);
if ($dropdownItem) {
$dropdownItem.removeClass("selected");
}
$newItem.addClass("selected");
$dropdownItem = $newItem;
removeDeleteButton();
}
|
javascript
|
function selectNextItem(direction) {
var $links = $dropdown.find("a"),
index = $dropdownItem ? $links.index($dropdownItem) : (direction > 0 ? -1 : 0),
$newItem = $links.eq((index + direction) % $links.length);
if ($dropdownItem) {
$dropdownItem.removeClass("selected");
}
$newItem.addClass("selected");
$dropdownItem = $newItem;
removeDeleteButton();
}
|
[
"function",
"selectNextItem",
"(",
"direction",
")",
"{",
"var",
"$links",
"=",
"$dropdown",
".",
"find",
"(",
"\"a\"",
")",
",",
"index",
"=",
"$dropdownItem",
"?",
"$links",
".",
"index",
"(",
"$dropdownItem",
")",
":",
"(",
"direction",
">",
"0",
"?",
"-",
"1",
":",
"0",
")",
",",
"$newItem",
"=",
"$links",
".",
"eq",
"(",
"(",
"index",
"+",
"direction",
")",
"%",
"$links",
".",
"length",
")",
";",
"if",
"(",
"$dropdownItem",
")",
"{",
"$dropdownItem",
".",
"removeClass",
"(",
"\"selected\"",
")",
";",
"}",
"$newItem",
".",
"addClass",
"(",
"\"selected\"",
")",
";",
"$dropdownItem",
"=",
"$newItem",
";",
"removeDeleteButton",
"(",
")",
";",
"}"
] |
Selects the next or previous item in the list
@param {number} direction +1 for next, -1 for prev
|
[
"Selects",
"the",
"next",
"or",
"previous",
"item",
"in",
"the",
"list"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L162-L174
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
removeSelectedItem
|
function removeSelectedItem(e) {
var recentProjects = getRecentProjects(),
$cacheItem = $dropdownItem,
index = recentProjects.indexOf($cacheItem.data("path"));
// When focus is not on project item
if (index === -1) {
return false;
}
// remove project
recentProjects.splice(index, 1);
PreferencesManager.setViewState("recentProjects", recentProjects);
checkHovers(e.pageX, e.pageY);
if (recentProjects.length === 1) {
$dropdown.find(".divider").remove();
}
selectNextItem(+1);
$cacheItem.closest("li").remove();
return true;
}
|
javascript
|
function removeSelectedItem(e) {
var recentProjects = getRecentProjects(),
$cacheItem = $dropdownItem,
index = recentProjects.indexOf($cacheItem.data("path"));
// When focus is not on project item
if (index === -1) {
return false;
}
// remove project
recentProjects.splice(index, 1);
PreferencesManager.setViewState("recentProjects", recentProjects);
checkHovers(e.pageX, e.pageY);
if (recentProjects.length === 1) {
$dropdown.find(".divider").remove();
}
selectNextItem(+1);
$cacheItem.closest("li").remove();
return true;
}
|
[
"function",
"removeSelectedItem",
"(",
"e",
")",
"{",
"var",
"recentProjects",
"=",
"getRecentProjects",
"(",
")",
",",
"$cacheItem",
"=",
"$dropdownItem",
",",
"index",
"=",
"recentProjects",
".",
"indexOf",
"(",
"$cacheItem",
".",
"data",
"(",
"\"path\"",
")",
")",
";",
"if",
"(",
"index",
"===",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"recentProjects",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"recentProjects\"",
",",
"recentProjects",
")",
";",
"checkHovers",
"(",
"e",
".",
"pageX",
",",
"e",
".",
"pageY",
")",
";",
"if",
"(",
"recentProjects",
".",
"length",
"===",
"1",
")",
"{",
"$dropdown",
".",
"find",
"(",
"\".divider\"",
")",
".",
"remove",
"(",
")",
";",
"}",
"selectNextItem",
"(",
"+",
"1",
")",
";",
"$cacheItem",
".",
"closest",
"(",
"\"li\"",
")",
".",
"remove",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Deletes the selected item and
move the focus to next item in list.
@return {boolean} TRUE if project is removed
|
[
"Deletes",
"the",
"selected",
"item",
"and",
"move",
"the",
"focus",
"to",
"next",
"item",
"in",
"list",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L182-L203
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
keydownHook
|
function keydownHook(event) {
var keyHandled = false;
switch (event.keyCode) {
case KeyEvent.DOM_VK_UP:
selectNextItem(-1);
keyHandled = true;
break;
case KeyEvent.DOM_VK_DOWN:
selectNextItem(+1);
keyHandled = true;
break;
case KeyEvent.DOM_VK_ENTER:
case KeyEvent.DOM_VK_RETURN:
if ($dropdownItem) {
$dropdownItem.trigger("click");
}
keyHandled = true;
break;
case KeyEvent.DOM_VK_BACK_SPACE:
case KeyEvent.DOM_VK_DELETE:
if ($dropdownItem) {
removeSelectedItem(event);
keyHandled = true;
}
break;
}
if (keyHandled) {
event.stopImmediatePropagation();
event.preventDefault();
}
return keyHandled;
}
|
javascript
|
function keydownHook(event) {
var keyHandled = false;
switch (event.keyCode) {
case KeyEvent.DOM_VK_UP:
selectNextItem(-1);
keyHandled = true;
break;
case KeyEvent.DOM_VK_DOWN:
selectNextItem(+1);
keyHandled = true;
break;
case KeyEvent.DOM_VK_ENTER:
case KeyEvent.DOM_VK_RETURN:
if ($dropdownItem) {
$dropdownItem.trigger("click");
}
keyHandled = true;
break;
case KeyEvent.DOM_VK_BACK_SPACE:
case KeyEvent.DOM_VK_DELETE:
if ($dropdownItem) {
removeSelectedItem(event);
keyHandled = true;
}
break;
}
if (keyHandled) {
event.stopImmediatePropagation();
event.preventDefault();
}
return keyHandled;
}
|
[
"function",
"keydownHook",
"(",
"event",
")",
"{",
"var",
"keyHandled",
"=",
"false",
";",
"switch",
"(",
"event",
".",
"keyCode",
")",
"{",
"case",
"KeyEvent",
".",
"DOM_VK_UP",
":",
"selectNextItem",
"(",
"-",
"1",
")",
";",
"keyHandled",
"=",
"true",
";",
"break",
";",
"case",
"KeyEvent",
".",
"DOM_VK_DOWN",
":",
"selectNextItem",
"(",
"+",
"1",
")",
";",
"keyHandled",
"=",
"true",
";",
"break",
";",
"case",
"KeyEvent",
".",
"DOM_VK_ENTER",
":",
"case",
"KeyEvent",
".",
"DOM_VK_RETURN",
":",
"if",
"(",
"$dropdownItem",
")",
"{",
"$dropdownItem",
".",
"trigger",
"(",
"\"click\"",
")",
";",
"}",
"keyHandled",
"=",
"true",
";",
"break",
";",
"case",
"KeyEvent",
".",
"DOM_VK_BACK_SPACE",
":",
"case",
"KeyEvent",
".",
"DOM_VK_DELETE",
":",
"if",
"(",
"$dropdownItem",
")",
"{",
"removeSelectedItem",
"(",
"event",
")",
";",
"keyHandled",
"=",
"true",
";",
"}",
"break",
";",
"}",
"if",
"(",
"keyHandled",
")",
"{",
"event",
".",
"stopImmediatePropagation",
"(",
")",
";",
"event",
".",
"preventDefault",
"(",
")",
";",
"}",
"return",
"keyHandled",
";",
"}"
] |
Handles the Key Down events
@param {KeyboardEvent} event
@return {boolean} True if the key was handled
|
[
"Handles",
"the",
"Key",
"Down",
"events"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L210-L243
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
cleanupDropdown
|
function cleanupDropdown() {
$("html").off("click", closeDropdown);
$("#project-files-container").off("scroll", closeDropdown);
$("#titlebar .nav").off("click", closeDropdown);
$dropdown = null;
MainViewManager.focusActivePane();
$(window).off("keydown", keydownHook);
}
|
javascript
|
function cleanupDropdown() {
$("html").off("click", closeDropdown);
$("#project-files-container").off("scroll", closeDropdown);
$("#titlebar .nav").off("click", closeDropdown);
$dropdown = null;
MainViewManager.focusActivePane();
$(window).off("keydown", keydownHook);
}
|
[
"function",
"cleanupDropdown",
"(",
")",
"{",
"$",
"(",
"\"html\"",
")",
".",
"off",
"(",
"\"click\"",
",",
"closeDropdown",
")",
";",
"$",
"(",
"\"#project-files-container\"",
")",
".",
"off",
"(",
"\"scroll\"",
",",
"closeDropdown",
")",
";",
"$",
"(",
"\"#titlebar .nav\"",
")",
".",
"off",
"(",
"\"click\"",
",",
"closeDropdown",
")",
";",
"$dropdown",
"=",
"null",
";",
"MainViewManager",
".",
"focusActivePane",
"(",
")",
";",
"$",
"(",
"window",
")",
".",
"off",
"(",
"\"keydown\"",
",",
"keydownHook",
")",
";",
"}"
] |
Remove the various event handlers that close the dropdown. This is called by the
PopUpManager when the dropdown is closed.
|
[
"Remove",
"the",
"various",
"event",
"handlers",
"that",
"close",
"the",
"dropdown",
".",
"This",
"is",
"called",
"by",
"the",
"PopUpManager",
"when",
"the",
"dropdown",
"is",
"closed",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L262-L271
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
parsePath
|
function parsePath(path) {
var lastSlash = path.lastIndexOf("/"), folder, rest;
if (lastSlash === path.length - 1) {
lastSlash = path.slice(0, path.length - 1).lastIndexOf("/");
}
if (lastSlash >= 0) {
rest = " - " + (lastSlash ? path.slice(0, lastSlash) : "/");
folder = path.slice(lastSlash + 1);
} else {
rest = "/";
folder = path;
}
return {path: path, folder: folder, rest: rest};
}
|
javascript
|
function parsePath(path) {
var lastSlash = path.lastIndexOf("/"), folder, rest;
if (lastSlash === path.length - 1) {
lastSlash = path.slice(0, path.length - 1).lastIndexOf("/");
}
if (lastSlash >= 0) {
rest = " - " + (lastSlash ? path.slice(0, lastSlash) : "/");
folder = path.slice(lastSlash + 1);
} else {
rest = "/";
folder = path;
}
return {path: path, folder: folder, rest: rest};
}
|
[
"function",
"parsePath",
"(",
"path",
")",
"{",
"var",
"lastSlash",
"=",
"path",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
",",
"folder",
",",
"rest",
";",
"if",
"(",
"lastSlash",
"===",
"path",
".",
"length",
"-",
"1",
")",
"{",
"lastSlash",
"=",
"path",
".",
"slice",
"(",
"0",
",",
"path",
".",
"length",
"-",
"1",
")",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
";",
"}",
"if",
"(",
"lastSlash",
">=",
"0",
")",
"{",
"rest",
"=",
"\" - \"",
"+",
"(",
"lastSlash",
"?",
"path",
".",
"slice",
"(",
"0",
",",
"lastSlash",
")",
":",
"\"/\"",
")",
";",
"folder",
"=",
"path",
".",
"slice",
"(",
"lastSlash",
"+",
"1",
")",
";",
"}",
"else",
"{",
"rest",
"=",
"\"/\"",
";",
"folder",
"=",
"path",
";",
"}",
"return",
"{",
"path",
":",
"path",
",",
"folder",
":",
"folder",
",",
"rest",
":",
"rest",
"}",
";",
"}"
] |
Parses the path and returns an object with the full path, the folder name and the path without the folder.
@param {string} path The full path to the folder.
@return {{path: string, folder: string, rest: string}}
|
[
"Parses",
"the",
"path",
"and",
"returns",
"an",
"object",
"with",
"the",
"full",
"path",
"the",
"folder",
"name",
"and",
"the",
"path",
"without",
"the",
"folder",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L334-L348
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
renderList
|
function renderList() {
var recentProjects = getRecentProjects(),
currentProject = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath),
templateVars = {
projectList : [],
Strings : Strings
};
recentProjects.forEach(function (root) {
if (root !== currentProject) {
templateVars.projectList.push(parsePath(root));
}
});
return Mustache.render(ProjectsMenuTemplate, templateVars);
}
|
javascript
|
function renderList() {
var recentProjects = getRecentProjects(),
currentProject = FileUtils.stripTrailingSlash(ProjectManager.getProjectRoot().fullPath),
templateVars = {
projectList : [],
Strings : Strings
};
recentProjects.forEach(function (root) {
if (root !== currentProject) {
templateVars.projectList.push(parsePath(root));
}
});
return Mustache.render(ProjectsMenuTemplate, templateVars);
}
|
[
"function",
"renderList",
"(",
")",
"{",
"var",
"recentProjects",
"=",
"getRecentProjects",
"(",
")",
",",
"currentProject",
"=",
"FileUtils",
".",
"stripTrailingSlash",
"(",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
".",
"fullPath",
")",
",",
"templateVars",
"=",
"{",
"projectList",
":",
"[",
"]",
",",
"Strings",
":",
"Strings",
"}",
";",
"recentProjects",
".",
"forEach",
"(",
"function",
"(",
"root",
")",
"{",
"if",
"(",
"root",
"!==",
"currentProject",
")",
"{",
"templateVars",
".",
"projectList",
".",
"push",
"(",
"parsePath",
"(",
"root",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"Mustache",
".",
"render",
"(",
"ProjectsMenuTemplate",
",",
"templateVars",
")",
";",
"}"
] |
Create the list of projects in the dropdown menu.
@return {string} The html content
|
[
"Create",
"the",
"list",
"of",
"projects",
"in",
"the",
"dropdown",
"menu",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L354-L369
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
showDropdown
|
function showDropdown(position) {
// If the dropdown is already visible, just return (so the root click handler on html
// will close it).
if ($dropdown) {
return;
}
Menus.closeAll();
$dropdown = $(renderList())
.css({
left: position.pageX,
top: position.pageY
})
.appendTo($("body"));
PopUpManager.addPopUp($dropdown, cleanupDropdown, true);
// TODO: should use capture, otherwise clicking on the menus doesn't close it. More fallout
// from the fact that we can't use the Boostrap (1.4) dropdowns.
$("html").on("click", closeDropdown);
// Hide the menu if the user scrolls in the project tree. Otherwise the Lion scrollbar
// overlaps it.
// TODO: This duplicates logic that's already in ProjectManager (which calls Menus.close()).
// We should fix this when the popup handling is centralized in PopupManager, as well
// as making Esc close the dropdown. See issue #1381.
$("#project-files-container").on("scroll", closeDropdown);
// Note: PopUpManager will automatically hide the sidebar in other cases, such as when a
// command is run, Esc is pressed, or the menu is focused.
// Hacky: if we detect a click in the menubar, close ourselves.
// TODO: again, we should have centralized popup management.
$("#titlebar .nav").on("click", closeDropdown);
_handleListEvents();
$(window).on("keydown", keydownHook);
}
|
javascript
|
function showDropdown(position) {
// If the dropdown is already visible, just return (so the root click handler on html
// will close it).
if ($dropdown) {
return;
}
Menus.closeAll();
$dropdown = $(renderList())
.css({
left: position.pageX,
top: position.pageY
})
.appendTo($("body"));
PopUpManager.addPopUp($dropdown, cleanupDropdown, true);
// TODO: should use capture, otherwise clicking on the menus doesn't close it. More fallout
// from the fact that we can't use the Boostrap (1.4) dropdowns.
$("html").on("click", closeDropdown);
// Hide the menu if the user scrolls in the project tree. Otherwise the Lion scrollbar
// overlaps it.
// TODO: This duplicates logic that's already in ProjectManager (which calls Menus.close()).
// We should fix this when the popup handling is centralized in PopupManager, as well
// as making Esc close the dropdown. See issue #1381.
$("#project-files-container").on("scroll", closeDropdown);
// Note: PopUpManager will automatically hide the sidebar in other cases, such as when a
// command is run, Esc is pressed, or the menu is focused.
// Hacky: if we detect a click in the menubar, close ourselves.
// TODO: again, we should have centralized popup management.
$("#titlebar .nav").on("click", closeDropdown);
_handleListEvents();
$(window).on("keydown", keydownHook);
}
|
[
"function",
"showDropdown",
"(",
"position",
")",
"{",
"if",
"(",
"$dropdown",
")",
"{",
"return",
";",
"}",
"Menus",
".",
"closeAll",
"(",
")",
";",
"$dropdown",
"=",
"$",
"(",
"renderList",
"(",
")",
")",
".",
"css",
"(",
"{",
"left",
":",
"position",
".",
"pageX",
",",
"top",
":",
"position",
".",
"pageY",
"}",
")",
".",
"appendTo",
"(",
"$",
"(",
"\"body\"",
")",
")",
";",
"PopUpManager",
".",
"addPopUp",
"(",
"$dropdown",
",",
"cleanupDropdown",
",",
"true",
")",
";",
"$",
"(",
"\"html\"",
")",
".",
"on",
"(",
"\"click\"",
",",
"closeDropdown",
")",
";",
"$",
"(",
"\"#project-files-container\"",
")",
".",
"on",
"(",
"\"scroll\"",
",",
"closeDropdown",
")",
";",
"$",
"(",
"\"#titlebar .nav\"",
")",
".",
"on",
"(",
"\"click\"",
",",
"closeDropdown",
")",
";",
"_handleListEvents",
"(",
")",
";",
"$",
"(",
"window",
")",
".",
"on",
"(",
"\"keydown\"",
",",
"keydownHook",
")",
";",
"}"
] |
Show or hide the recent projects dropdown.
@param {{pageX:number, pageY:number}} position - the absolute position where to open the dropdown
|
[
"Show",
"or",
"hide",
"the",
"recent",
"projects",
"dropdown",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L376-L414
|
train
|
adobe/brackets
|
src/extensions/default/RecentProjects/main.js
|
handleKeyEvent
|
function handleKeyEvent() {
if (!$dropdown) {
if (!SidebarView.isVisible()) {
SidebarView.show();
}
$("#project-dropdown-toggle").trigger("click");
$dropdown.focus();
$links = $dropdown.find("a");
// By default, select the most recent project (which is at the top of the list underneath Open Folder),
// but if there are none, select Open Folder instead.
$dropdownItem = $links.eq($links.length > 1 ? 1 : 0);
$dropdownItem.addClass("selected");
// If focusing the dropdown caused a modal bar to close, we need to refocus the dropdown
window.setTimeout(function () {
$dropdown.focus();
}, 0);
}
}
|
javascript
|
function handleKeyEvent() {
if (!$dropdown) {
if (!SidebarView.isVisible()) {
SidebarView.show();
}
$("#project-dropdown-toggle").trigger("click");
$dropdown.focus();
$links = $dropdown.find("a");
// By default, select the most recent project (which is at the top of the list underneath Open Folder),
// but if there are none, select Open Folder instead.
$dropdownItem = $links.eq($links.length > 1 ? 1 : 0);
$dropdownItem.addClass("selected");
// If focusing the dropdown caused a modal bar to close, we need to refocus the dropdown
window.setTimeout(function () {
$dropdown.focus();
}, 0);
}
}
|
[
"function",
"handleKeyEvent",
"(",
")",
"{",
"if",
"(",
"!",
"$dropdown",
")",
"{",
"if",
"(",
"!",
"SidebarView",
".",
"isVisible",
"(",
")",
")",
"{",
"SidebarView",
".",
"show",
"(",
")",
";",
"}",
"$",
"(",
"\"#project-dropdown-toggle\"",
")",
".",
"trigger",
"(",
"\"click\"",
")",
";",
"$dropdown",
".",
"focus",
"(",
")",
";",
"$links",
"=",
"$dropdown",
".",
"find",
"(",
"\"a\"",
")",
";",
"$dropdownItem",
"=",
"$links",
".",
"eq",
"(",
"$links",
".",
"length",
">",
"1",
"?",
"1",
":",
"0",
")",
";",
"$dropdownItem",
".",
"addClass",
"(",
"\"selected\"",
")",
";",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"$dropdown",
".",
"focus",
"(",
")",
";",
"}",
",",
"0",
")",
";",
"}",
"}"
] |
Show or hide the recent projects dropdown from the toogle command.
|
[
"Show",
"or",
"hide",
"the",
"recent",
"projects",
"dropdown",
"from",
"the",
"toogle",
"command",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/RecentProjects/main.js#L420-L440
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_validateFrame
|
function _validateFrame(entry) {
var deferred = new $.Deferred(),
fileEntry = FileSystem.getFileForPath(entry.filePath);
if (entry.inMem) {
var indexInWS = MainViewManager.findInWorkingSet(entry.paneId, entry.filePath);
// Remove entry if InMemoryFile is not found in Working set
if (indexInWS === -1) {
deferred.reject();
} else {
deferred.resolve();
}
} else {
fileEntry.exists(function (err, exists) {
if (!err && exists) {
// Additional check to handle external modification and mutation of the doc text affecting markers
if (fileEntry._hash !== entry._hash) {
deferred.reject();
} else if (!entry._validateMarkers()) {
deferred.reject();
} else {
deferred.resolve();
}
} else {
deferred.reject();
}
});
}
return deferred.promise();
}
|
javascript
|
function _validateFrame(entry) {
var deferred = new $.Deferred(),
fileEntry = FileSystem.getFileForPath(entry.filePath);
if (entry.inMem) {
var indexInWS = MainViewManager.findInWorkingSet(entry.paneId, entry.filePath);
// Remove entry if InMemoryFile is not found in Working set
if (indexInWS === -1) {
deferred.reject();
} else {
deferred.resolve();
}
} else {
fileEntry.exists(function (err, exists) {
if (!err && exists) {
// Additional check to handle external modification and mutation of the doc text affecting markers
if (fileEntry._hash !== entry._hash) {
deferred.reject();
} else if (!entry._validateMarkers()) {
deferred.reject();
} else {
deferred.resolve();
}
} else {
deferred.reject();
}
});
}
return deferred.promise();
}
|
[
"function",
"_validateFrame",
"(",
"entry",
")",
"{",
"var",
"deferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"fileEntry",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"entry",
".",
"filePath",
")",
";",
"if",
"(",
"entry",
".",
"inMem",
")",
"{",
"var",
"indexInWS",
"=",
"MainViewManager",
".",
"findInWorkingSet",
"(",
"entry",
".",
"paneId",
",",
"entry",
".",
"filePath",
")",
";",
"if",
"(",
"indexInWS",
"===",
"-",
"1",
")",
"{",
"deferred",
".",
"reject",
"(",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"resolve",
"(",
")",
";",
"}",
"}",
"else",
"{",
"fileEntry",
".",
"exists",
"(",
"function",
"(",
"err",
",",
"exists",
")",
"{",
"if",
"(",
"!",
"err",
"&&",
"exists",
")",
"{",
"if",
"(",
"fileEntry",
".",
"_hash",
"!==",
"entry",
".",
"_hash",
")",
"{",
"deferred",
".",
"reject",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"entry",
".",
"_validateMarkers",
"(",
")",
")",
"{",
"deferred",
".",
"reject",
"(",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"resolve",
"(",
")",
";",
"}",
"}",
"else",
"{",
"deferred",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"return",
"deferred",
".",
"promise",
"(",
")",
";",
"}"
] |
Function to check existence of a file entry, validity of markers
@private
|
[
"Function",
"to",
"check",
"existence",
"of",
"a",
"file",
"entry",
"validity",
"of",
"markers"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L98-L128
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_navigateBack
|
function _navigateBack() {
if (!jumpForwardStack.length) {
if (activePosNotSynced) {
currentEditPos = new NavigationFrame(EditorManager.getCurrentFullEditor(), {ranges: EditorManager.getCurrentFullEditor()._codeMirror.listSelections()});
jumpForwardStack.push(currentEditPos);
}
}
var navFrame = jumpBackwardStack.pop();
// Check if the poped frame is the current active frame or doesn't have any valid marker information
// if true, jump again
if (navFrame && navFrame === currentEditPos) {
jumpForwardStack.push(navFrame);
_validateNavigationCmds();
CommandManager.execute(NAVIGATION_JUMP_BACK);
return;
}
if (navFrame) {
// We will check for the file existence now, if it doesn't exist we will jump back again
// but discard the popped frame as invalid.
_validateFrame(navFrame).done(function () {
jumpForwardStack.push(navFrame);
navFrame.goTo();
currentEditPos = navFrame;
}).fail(function () {
CommandManager.execute(NAVIGATION_JUMP_BACK);
}).always(function () {
_validateNavigationCmds();
});
}
}
|
javascript
|
function _navigateBack() {
if (!jumpForwardStack.length) {
if (activePosNotSynced) {
currentEditPos = new NavigationFrame(EditorManager.getCurrentFullEditor(), {ranges: EditorManager.getCurrentFullEditor()._codeMirror.listSelections()});
jumpForwardStack.push(currentEditPos);
}
}
var navFrame = jumpBackwardStack.pop();
// Check if the poped frame is the current active frame or doesn't have any valid marker information
// if true, jump again
if (navFrame && navFrame === currentEditPos) {
jumpForwardStack.push(navFrame);
_validateNavigationCmds();
CommandManager.execute(NAVIGATION_JUMP_BACK);
return;
}
if (navFrame) {
// We will check for the file existence now, if it doesn't exist we will jump back again
// but discard the popped frame as invalid.
_validateFrame(navFrame).done(function () {
jumpForwardStack.push(navFrame);
navFrame.goTo();
currentEditPos = navFrame;
}).fail(function () {
CommandManager.execute(NAVIGATION_JUMP_BACK);
}).always(function () {
_validateNavigationCmds();
});
}
}
|
[
"function",
"_navigateBack",
"(",
")",
"{",
"if",
"(",
"!",
"jumpForwardStack",
".",
"length",
")",
"{",
"if",
"(",
"activePosNotSynced",
")",
"{",
"currentEditPos",
"=",
"new",
"NavigationFrame",
"(",
"EditorManager",
".",
"getCurrentFullEditor",
"(",
")",
",",
"{",
"ranges",
":",
"EditorManager",
".",
"getCurrentFullEditor",
"(",
")",
".",
"_codeMirror",
".",
"listSelections",
"(",
")",
"}",
")",
";",
"jumpForwardStack",
".",
"push",
"(",
"currentEditPos",
")",
";",
"}",
"}",
"var",
"navFrame",
"=",
"jumpBackwardStack",
".",
"pop",
"(",
")",
";",
"if",
"(",
"navFrame",
"&&",
"navFrame",
"===",
"currentEditPos",
")",
"{",
"jumpForwardStack",
".",
"push",
"(",
"navFrame",
")",
";",
"_validateNavigationCmds",
"(",
")",
";",
"CommandManager",
".",
"execute",
"(",
"NAVIGATION_JUMP_BACK",
")",
";",
"return",
";",
"}",
"if",
"(",
"navFrame",
")",
"{",
"_validateFrame",
"(",
"navFrame",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"jumpForwardStack",
".",
"push",
"(",
"navFrame",
")",
";",
"navFrame",
".",
"goTo",
"(",
")",
";",
"currentEditPos",
"=",
"navFrame",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"CommandManager",
".",
"execute",
"(",
"NAVIGATION_JUMP_BACK",
")",
";",
"}",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"_validateNavigationCmds",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Command handler to navigate backward
|
[
"Command",
"handler",
"to",
"navigate",
"backward"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L339-L371
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_navigateForward
|
function _navigateForward() {
var navFrame = jumpForwardStack.pop();
if (!navFrame) {
return;
}
// Check if the poped frame is the current active frame or doesn't have any valid marker information
// if true, jump again
if (navFrame === currentEditPos) {
jumpBackwardStack.push(navFrame);
_validateNavigationCmds();
CommandManager.execute(NAVIGATION_JUMP_FWD);
return;
}
// We will check for the file existence now, if it doesn't exist we will jump back again
// but discard the popped frame as invalid.
_validateFrame(navFrame).done(function () {
jumpBackwardStack.push(navFrame);
navFrame.goTo();
currentEditPos = navFrame;
}).fail(function () {
_validateNavigationCmds();
CommandManager.execute(NAVIGATION_JUMP_FWD);
}).always(function () {
_validateNavigationCmds();
});
}
|
javascript
|
function _navigateForward() {
var navFrame = jumpForwardStack.pop();
if (!navFrame) {
return;
}
// Check if the poped frame is the current active frame or doesn't have any valid marker information
// if true, jump again
if (navFrame === currentEditPos) {
jumpBackwardStack.push(navFrame);
_validateNavigationCmds();
CommandManager.execute(NAVIGATION_JUMP_FWD);
return;
}
// We will check for the file existence now, if it doesn't exist we will jump back again
// but discard the popped frame as invalid.
_validateFrame(navFrame).done(function () {
jumpBackwardStack.push(navFrame);
navFrame.goTo();
currentEditPos = navFrame;
}).fail(function () {
_validateNavigationCmds();
CommandManager.execute(NAVIGATION_JUMP_FWD);
}).always(function () {
_validateNavigationCmds();
});
}
|
[
"function",
"_navigateForward",
"(",
")",
"{",
"var",
"navFrame",
"=",
"jumpForwardStack",
".",
"pop",
"(",
")",
";",
"if",
"(",
"!",
"navFrame",
")",
"{",
"return",
";",
"}",
"if",
"(",
"navFrame",
"===",
"currentEditPos",
")",
"{",
"jumpBackwardStack",
".",
"push",
"(",
"navFrame",
")",
";",
"_validateNavigationCmds",
"(",
")",
";",
"CommandManager",
".",
"execute",
"(",
"NAVIGATION_JUMP_FWD",
")",
";",
"return",
";",
"}",
"_validateFrame",
"(",
"navFrame",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"jumpBackwardStack",
".",
"push",
"(",
"navFrame",
")",
";",
"navFrame",
".",
"goTo",
"(",
")",
";",
"currentEditPos",
"=",
"navFrame",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"_validateNavigationCmds",
"(",
")",
";",
"CommandManager",
".",
"execute",
"(",
"NAVIGATION_JUMP_FWD",
")",
";",
"}",
")",
".",
"always",
"(",
"function",
"(",
")",
"{",
"_validateNavigationCmds",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Command handler to navigate forward
|
[
"Command",
"handler",
"to",
"navigate",
"forward"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L376-L405
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_initNavigationMenuItems
|
function _initNavigationMenuItems() {
var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU);
menu.addMenuItem(NAVIGATION_JUMP_BACK, "", Menus.AFTER, Commands.NAVIGATE_PREV_DOC);
menu.addMenuItem(NAVIGATION_JUMP_FWD, "", Menus.AFTER, NAVIGATION_JUMP_BACK);
}
|
javascript
|
function _initNavigationMenuItems() {
var menu = Menus.getMenu(Menus.AppMenuBar.NAVIGATE_MENU);
menu.addMenuItem(NAVIGATION_JUMP_BACK, "", Menus.AFTER, Commands.NAVIGATE_PREV_DOC);
menu.addMenuItem(NAVIGATION_JUMP_FWD, "", Menus.AFTER, NAVIGATION_JUMP_BACK);
}
|
[
"function",
"_initNavigationMenuItems",
"(",
")",
"{",
"var",
"menu",
"=",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"NAVIGATE_MENU",
")",
";",
"menu",
".",
"addMenuItem",
"(",
"NAVIGATION_JUMP_BACK",
",",
"\"\"",
",",
"Menus",
".",
"AFTER",
",",
"Commands",
".",
"NAVIGATE_PREV_DOC",
")",
";",
"menu",
".",
"addMenuItem",
"(",
"NAVIGATION_JUMP_FWD",
",",
"\"\"",
",",
"Menus",
".",
"AFTER",
",",
"NAVIGATION_JUMP_BACK",
")",
";",
"}"
] |
Function to initialize navigation menu items.
@private
|
[
"Function",
"to",
"initialize",
"navigation",
"menu",
"items",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L411-L415
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_initNavigationCommands
|
function _initNavigationCommands() {
CommandManager.register(Strings.CMD_NAVIGATE_BACKWARD, NAVIGATION_JUMP_BACK, _navigateBack);
CommandManager.register(Strings.CMD_NAVIGATE_FORWARD, NAVIGATION_JUMP_FWD, _navigateForward);
commandJumpBack = CommandManager.get(NAVIGATION_JUMP_BACK);
commandJumpFwd = CommandManager.get(NAVIGATION_JUMP_FWD);
commandJumpBack.setEnabled(false);
commandJumpFwd.setEnabled(false);
KeyBindingManager.addBinding(NAVIGATION_JUMP_BACK, KeyboardPrefs[NAVIGATION_JUMP_BACK]);
KeyBindingManager.addBinding(NAVIGATION_JUMP_FWD, KeyboardPrefs[NAVIGATION_JUMP_FWD]);
_initNavigationMenuItems();
}
|
javascript
|
function _initNavigationCommands() {
CommandManager.register(Strings.CMD_NAVIGATE_BACKWARD, NAVIGATION_JUMP_BACK, _navigateBack);
CommandManager.register(Strings.CMD_NAVIGATE_FORWARD, NAVIGATION_JUMP_FWD, _navigateForward);
commandJumpBack = CommandManager.get(NAVIGATION_JUMP_BACK);
commandJumpFwd = CommandManager.get(NAVIGATION_JUMP_FWD);
commandJumpBack.setEnabled(false);
commandJumpFwd.setEnabled(false);
KeyBindingManager.addBinding(NAVIGATION_JUMP_BACK, KeyboardPrefs[NAVIGATION_JUMP_BACK]);
KeyBindingManager.addBinding(NAVIGATION_JUMP_FWD, KeyboardPrefs[NAVIGATION_JUMP_FWD]);
_initNavigationMenuItems();
}
|
[
"function",
"_initNavigationCommands",
"(",
")",
"{",
"CommandManager",
".",
"register",
"(",
"Strings",
".",
"CMD_NAVIGATE_BACKWARD",
",",
"NAVIGATION_JUMP_BACK",
",",
"_navigateBack",
")",
";",
"CommandManager",
".",
"register",
"(",
"Strings",
".",
"CMD_NAVIGATE_FORWARD",
",",
"NAVIGATION_JUMP_FWD",
",",
"_navigateForward",
")",
";",
"commandJumpBack",
"=",
"CommandManager",
".",
"get",
"(",
"NAVIGATION_JUMP_BACK",
")",
";",
"commandJumpFwd",
"=",
"CommandManager",
".",
"get",
"(",
"NAVIGATION_JUMP_FWD",
")",
";",
"commandJumpBack",
".",
"setEnabled",
"(",
"false",
")",
";",
"commandJumpFwd",
".",
"setEnabled",
"(",
"false",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"NAVIGATION_JUMP_BACK",
",",
"KeyboardPrefs",
"[",
"NAVIGATION_JUMP_BACK",
"]",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"NAVIGATION_JUMP_FWD",
",",
"KeyboardPrefs",
"[",
"NAVIGATION_JUMP_FWD",
"]",
")",
";",
"_initNavigationMenuItems",
"(",
")",
";",
"}"
] |
Function to initialize navigation commands and it's keyboard shortcuts.
@private
|
[
"Function",
"to",
"initialize",
"navigation",
"commands",
"and",
"it",
"s",
"keyboard",
"shortcuts",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L421-L431
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_captureFrame
|
function _captureFrame(editor) {
// Capture the active position now if it was not captured earlier
if ((activePosNotSynced || !jumpBackwardStack.length) && !jumpInProgress) {
jumpBackwardStack.push(new NavigationFrame(editor, {ranges: editor._codeMirror.listSelections()}));
}
}
|
javascript
|
function _captureFrame(editor) {
// Capture the active position now if it was not captured earlier
if ((activePosNotSynced || !jumpBackwardStack.length) && !jumpInProgress) {
jumpBackwardStack.push(new NavigationFrame(editor, {ranges: editor._codeMirror.listSelections()}));
}
}
|
[
"function",
"_captureFrame",
"(",
"editor",
")",
"{",
"if",
"(",
"(",
"activePosNotSynced",
"||",
"!",
"jumpBackwardStack",
".",
"length",
")",
"&&",
"!",
"jumpInProgress",
")",
"{",
"jumpBackwardStack",
".",
"push",
"(",
"new",
"NavigationFrame",
"(",
"editor",
",",
"{",
"ranges",
":",
"editor",
".",
"_codeMirror",
".",
"listSelections",
"(",
")",
"}",
")",
")",
";",
"}",
"}"
] |
Function to request a navigation frame creation explicitly.
@private
|
[
"Function",
"to",
"request",
"a",
"navigation",
"frame",
"creation",
"explicitly",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L437-L442
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_backupLiveMarkers
|
function _backupLiveMarkers(frames, editor) {
var index, frame;
for (index in frames) {
frame = frames[index];
if (frame.cm === editor._codeMirror) {
frame._handleEditorDestroy();
}
}
}
|
javascript
|
function _backupLiveMarkers(frames, editor) {
var index, frame;
for (index in frames) {
frame = frames[index];
if (frame.cm === editor._codeMirror) {
frame._handleEditorDestroy();
}
}
}
|
[
"function",
"_backupLiveMarkers",
"(",
"frames",
",",
"editor",
")",
"{",
"var",
"index",
",",
"frame",
";",
"for",
"(",
"index",
"in",
"frames",
")",
"{",
"frame",
"=",
"frames",
"[",
"index",
"]",
";",
"if",
"(",
"frame",
".",
"cm",
"===",
"editor",
".",
"_codeMirror",
")",
"{",
"frame",
".",
"_handleEditorDestroy",
"(",
")",
";",
"}",
"}",
"}"
] |
Create snapshot of last known live markers.
@private
|
[
"Create",
"snapshot",
"of",
"last",
"known",
"live",
"markers",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L448-L456
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_handleExternalChange
|
function _handleExternalChange(evt, doc) {
if (doc) {
_removeBackwardFramesForFile(doc.file);
_removeForwardFramesForFile(doc.file);
_validateNavigationCmds();
}
}
|
javascript
|
function _handleExternalChange(evt, doc) {
if (doc) {
_removeBackwardFramesForFile(doc.file);
_removeForwardFramesForFile(doc.file);
_validateNavigationCmds();
}
}
|
[
"function",
"_handleExternalChange",
"(",
"evt",
",",
"doc",
")",
"{",
"if",
"(",
"doc",
")",
"{",
"_removeBackwardFramesForFile",
"(",
"doc",
".",
"file",
")",
";",
"_removeForwardFramesForFile",
"(",
"doc",
".",
"file",
")",
";",
"_validateNavigationCmds",
"(",
")",
";",
"}",
"}"
] |
Handles explicit content reset for a document caused by external changes
@private
|
[
"Handles",
"explicit",
"content",
"reset",
"for",
"a",
"document",
"caused",
"by",
"external",
"changes"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L491-L497
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_reinstateMarkers
|
function _reinstateMarkers(editor, frames) {
var index, frame;
for (index in frames) {
frame = frames[index];
if (!frame.cm && frame.filePath === editor.document.file._path) {
frame._reinstateMarkers(editor);
}
}
}
|
javascript
|
function _reinstateMarkers(editor, frames) {
var index, frame;
for (index in frames) {
frame = frames[index];
if (!frame.cm && frame.filePath === editor.document.file._path) {
frame._reinstateMarkers(editor);
}
}
}
|
[
"function",
"_reinstateMarkers",
"(",
"editor",
",",
"frames",
")",
"{",
"var",
"index",
",",
"frame",
";",
"for",
"(",
"index",
"in",
"frames",
")",
"{",
"frame",
"=",
"frames",
"[",
"index",
"]",
";",
"if",
"(",
"!",
"frame",
".",
"cm",
"&&",
"frame",
".",
"filePath",
"===",
"editor",
".",
"document",
".",
"file",
".",
"_path",
")",
"{",
"frame",
".",
"_reinstateMarkers",
"(",
"editor",
")",
";",
"}",
"}",
"}"
] |
Required to make offline markers alive again to track document mutation
@private
|
[
"Required",
"to",
"make",
"offline",
"markers",
"alive",
"again",
"to",
"track",
"document",
"mutation"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L508-L516
|
train
|
adobe/brackets
|
src/extensions/default/NavigationAndHistory/NavigationProvider.js
|
_handleActiveEditorChange
|
function _handleActiveEditorChange(event, current, previous) {
if (previous && previous._paneId) { // Handle only full editors
previous.off("beforeSelectionChange", _recordJumpDef);
_captureFrame(previous);
_validateNavigationCmds();
}
if (current && current._paneId) { // Handle only full editors
activePosNotSynced = true;
current.off("beforeSelectionChange", _recordJumpDef);
current.on("beforeSelectionChange", _recordJumpDef);
current.off("beforeDestroy", _handleEditorCleanup);
current.on("beforeDestroy", _handleEditorCleanup);
}
}
|
javascript
|
function _handleActiveEditorChange(event, current, previous) {
if (previous && previous._paneId) { // Handle only full editors
previous.off("beforeSelectionChange", _recordJumpDef);
_captureFrame(previous);
_validateNavigationCmds();
}
if (current && current._paneId) { // Handle only full editors
activePosNotSynced = true;
current.off("beforeSelectionChange", _recordJumpDef);
current.on("beforeSelectionChange", _recordJumpDef);
current.off("beforeDestroy", _handleEditorCleanup);
current.on("beforeDestroy", _handleEditorCleanup);
}
}
|
[
"function",
"_handleActiveEditorChange",
"(",
"event",
",",
"current",
",",
"previous",
")",
"{",
"if",
"(",
"previous",
"&&",
"previous",
".",
"_paneId",
")",
"{",
"previous",
".",
"off",
"(",
"\"beforeSelectionChange\"",
",",
"_recordJumpDef",
")",
";",
"_captureFrame",
"(",
"previous",
")",
";",
"_validateNavigationCmds",
"(",
")",
";",
"}",
"if",
"(",
"current",
"&&",
"current",
".",
"_paneId",
")",
"{",
"activePosNotSynced",
"=",
"true",
";",
"current",
".",
"off",
"(",
"\"beforeSelectionChange\"",
",",
"_recordJumpDef",
")",
";",
"current",
".",
"on",
"(",
"\"beforeSelectionChange\"",
",",
"_recordJumpDef",
")",
";",
"current",
".",
"off",
"(",
"\"beforeDestroy\"",
",",
"_handleEditorCleanup",
")",
";",
"current",
".",
"on",
"(",
"\"beforeDestroy\"",
",",
"_handleEditorCleanup",
")",
";",
"}",
"}"
] |
Handle Active Editor change to update navigation information
@private
|
[
"Handle",
"Active",
"Editor",
"change",
"to",
"update",
"navigation",
"information"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/NavigationAndHistory/NavigationProvider.js#L522-L536
|
train
|
adobe/brackets
|
src/utils/Resizer.js
|
repositionResizer
|
function repositionResizer(elementSize) {
var resizerPosition = elementSize || 1;
if (position === POSITION_RIGHT || position === POSITION_BOTTOM) {
$resizer.css(resizerCSSPosition, resizerPosition);
}
}
|
javascript
|
function repositionResizer(elementSize) {
var resizerPosition = elementSize || 1;
if (position === POSITION_RIGHT || position === POSITION_BOTTOM) {
$resizer.css(resizerCSSPosition, resizerPosition);
}
}
|
[
"function",
"repositionResizer",
"(",
"elementSize",
")",
"{",
"var",
"resizerPosition",
"=",
"elementSize",
"||",
"1",
";",
"if",
"(",
"position",
"===",
"POSITION_RIGHT",
"||",
"position",
"===",
"POSITION_BOTTOM",
")",
"{",
"$resizer",
".",
"css",
"(",
"resizerCSSPosition",
",",
"resizerPosition",
")",
";",
"}",
"}"
] |
If the resizer is positioned right or bottom of the panel, we need to listen to reposition it if the element size changes externally
|
[
"If",
"the",
"resizer",
"is",
"positioned",
"right",
"or",
"bottom",
"of",
"the",
"panel",
"we",
"need",
"to",
"listen",
"to",
"reposition",
"it",
"if",
"the",
"element",
"size",
"changes",
"externally"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/utils/Resizer.js#L291-L296
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
_enqueueChange
|
function _enqueueChange(changedPath, stats) {
_pendingChanges[changedPath] = stats;
if (!_changeTimeout) {
_changeTimeout = window.setTimeout(function () {
if (_changeCallback) {
Object.keys(_pendingChanges).forEach(function (path) {
_changeCallback(path, _pendingChanges[path]);
});
}
_changeTimeout = null;
_pendingChanges = {};
}, FILE_WATCHER_BATCH_TIMEOUT);
}
}
|
javascript
|
function _enqueueChange(changedPath, stats) {
_pendingChanges[changedPath] = stats;
if (!_changeTimeout) {
_changeTimeout = window.setTimeout(function () {
if (_changeCallback) {
Object.keys(_pendingChanges).forEach(function (path) {
_changeCallback(path, _pendingChanges[path]);
});
}
_changeTimeout = null;
_pendingChanges = {};
}, FILE_WATCHER_BATCH_TIMEOUT);
}
}
|
[
"function",
"_enqueueChange",
"(",
"changedPath",
",",
"stats",
")",
"{",
"_pendingChanges",
"[",
"changedPath",
"]",
"=",
"stats",
";",
"if",
"(",
"!",
"_changeTimeout",
")",
"{",
"_changeTimeout",
"=",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"_changeCallback",
")",
"{",
"Object",
".",
"keys",
"(",
"_pendingChanges",
")",
".",
"forEach",
"(",
"function",
"(",
"path",
")",
"{",
"_changeCallback",
"(",
"path",
",",
"_pendingChanges",
"[",
"path",
"]",
")",
";",
"}",
")",
";",
"}",
"_changeTimeout",
"=",
"null",
";",
"_pendingChanges",
"=",
"{",
"}",
";",
"}",
",",
"FILE_WATCHER_BATCH_TIMEOUT",
")",
";",
"}",
"}"
] |
Enqueue a file change event for eventual reporting back to the FileSystem.
@param {string} changedPath The path that was changed
@param {object} stats Stats coming from the underlying watcher, if available
@private
|
[
"Enqueue",
"a",
"file",
"change",
"event",
"for",
"eventual",
"reporting",
"back",
"to",
"the",
"FileSystem",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L84-L98
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
_fileWatcherChange
|
function _fileWatcherChange(evt, event, parentDirPath, entryName, statsObj) {
var change;
switch (event) {
case "changed":
// an existing file/directory was modified; stats are passed if available
var fsStats;
if (statsObj) {
fsStats = new FileSystemStats(statsObj);
} else {
console.warn("FileWatcherDomain was expected to deliver stats for changed event!");
}
_enqueueChange(parentDirPath + entryName, fsStats);
break;
case "created":
case "deleted":
// file/directory was created/deleted; fire change on parent to reload contents
_enqueueChange(parentDirPath, null);
break;
default:
console.error("Unexpected 'change' event:", event);
}
}
|
javascript
|
function _fileWatcherChange(evt, event, parentDirPath, entryName, statsObj) {
var change;
switch (event) {
case "changed":
// an existing file/directory was modified; stats are passed if available
var fsStats;
if (statsObj) {
fsStats = new FileSystemStats(statsObj);
} else {
console.warn("FileWatcherDomain was expected to deliver stats for changed event!");
}
_enqueueChange(parentDirPath + entryName, fsStats);
break;
case "created":
case "deleted":
// file/directory was created/deleted; fire change on parent to reload contents
_enqueueChange(parentDirPath, null);
break;
default:
console.error("Unexpected 'change' event:", event);
}
}
|
[
"function",
"_fileWatcherChange",
"(",
"evt",
",",
"event",
",",
"parentDirPath",
",",
"entryName",
",",
"statsObj",
")",
"{",
"var",
"change",
";",
"switch",
"(",
"event",
")",
"{",
"case",
"\"changed\"",
":",
"var",
"fsStats",
";",
"if",
"(",
"statsObj",
")",
"{",
"fsStats",
"=",
"new",
"FileSystemStats",
"(",
"statsObj",
")",
";",
"}",
"else",
"{",
"console",
".",
"warn",
"(",
"\"FileWatcherDomain was expected to deliver stats for changed event!\"",
")",
";",
"}",
"_enqueueChange",
"(",
"parentDirPath",
"+",
"entryName",
",",
"fsStats",
")",
";",
"break",
";",
"case",
"\"created\"",
":",
"case",
"\"deleted\"",
":",
"_enqueueChange",
"(",
"parentDirPath",
",",
"null",
")",
";",
"break",
";",
"default",
":",
"console",
".",
"error",
"(",
"\"Unexpected 'change' event:\"",
",",
"event",
")",
";",
"}",
"}"
] |
Event handler for the Node fileWatcher domain's change event.
@param {jQuery.Event} The underlying change event
@param {string} event The type of the event: "changed", "created" or "deleted"
@param {string} parentDirPath The path to the directory holding entry that has changed
@param {string=} entryName The name of the file/directory that has changed
@param {object} statsObj Object that can be used to construct FileSystemStats
@private
|
[
"Event",
"handler",
"for",
"the",
"Node",
"fileWatcher",
"domain",
"s",
"change",
"event",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L110-L131
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
_mapError
|
function _mapError(err) {
if (!err) {
return null;
}
switch (err) {
case appshell.fs.ERR_INVALID_PARAMS:
return FileSystemError.INVALID_PARAMS;
case appshell.fs.ERR_NOT_FOUND:
return FileSystemError.NOT_FOUND;
case appshell.fs.ERR_CANT_READ:
return FileSystemError.NOT_READABLE;
case appshell.fs.ERR_CANT_WRITE:
return FileSystemError.NOT_WRITABLE;
case appshell.fs.ERR_UNSUPPORTED_ENCODING:
return FileSystemError.UNSUPPORTED_ENCODING;
case appshell.fs.ERR_OUT_OF_SPACE:
return FileSystemError.OUT_OF_SPACE;
case appshell.fs.ERR_FILE_EXISTS:
return FileSystemError.ALREADY_EXISTS;
case appshell.fs.ERR_ENCODE_FILE_FAILED:
return FileSystemError.ENCODE_FILE_FAILED;
case appshell.fs.ERR_DECODE_FILE_FAILED:
return FileSystemError.DECODE_FILE_FAILED;
case appshell.fs.ERR_UNSUPPORTED_UTF16_ENCODING:
return FileSystemError.UNSUPPORTED_UTF16_ENCODING;
}
return FileSystemError.UNKNOWN;
}
|
javascript
|
function _mapError(err) {
if (!err) {
return null;
}
switch (err) {
case appshell.fs.ERR_INVALID_PARAMS:
return FileSystemError.INVALID_PARAMS;
case appshell.fs.ERR_NOT_FOUND:
return FileSystemError.NOT_FOUND;
case appshell.fs.ERR_CANT_READ:
return FileSystemError.NOT_READABLE;
case appshell.fs.ERR_CANT_WRITE:
return FileSystemError.NOT_WRITABLE;
case appshell.fs.ERR_UNSUPPORTED_ENCODING:
return FileSystemError.UNSUPPORTED_ENCODING;
case appshell.fs.ERR_OUT_OF_SPACE:
return FileSystemError.OUT_OF_SPACE;
case appshell.fs.ERR_FILE_EXISTS:
return FileSystemError.ALREADY_EXISTS;
case appshell.fs.ERR_ENCODE_FILE_FAILED:
return FileSystemError.ENCODE_FILE_FAILED;
case appshell.fs.ERR_DECODE_FILE_FAILED:
return FileSystemError.DECODE_FILE_FAILED;
case appshell.fs.ERR_UNSUPPORTED_UTF16_ENCODING:
return FileSystemError.UNSUPPORTED_UTF16_ENCODING;
}
return FileSystemError.UNKNOWN;
}
|
[
"function",
"_mapError",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"return",
"null",
";",
"}",
"switch",
"(",
"err",
")",
"{",
"case",
"appshell",
".",
"fs",
".",
"ERR_INVALID_PARAMS",
":",
"return",
"FileSystemError",
".",
"INVALID_PARAMS",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_NOT_FOUND",
":",
"return",
"FileSystemError",
".",
"NOT_FOUND",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_CANT_READ",
":",
"return",
"FileSystemError",
".",
"NOT_READABLE",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_CANT_WRITE",
":",
"return",
"FileSystemError",
".",
"NOT_WRITABLE",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_UNSUPPORTED_ENCODING",
":",
"return",
"FileSystemError",
".",
"UNSUPPORTED_ENCODING",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_OUT_OF_SPACE",
":",
"return",
"FileSystemError",
".",
"OUT_OF_SPACE",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_FILE_EXISTS",
":",
"return",
"FileSystemError",
".",
"ALREADY_EXISTS",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_ENCODE_FILE_FAILED",
":",
"return",
"FileSystemError",
".",
"ENCODE_FILE_FAILED",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_DECODE_FILE_FAILED",
":",
"return",
"FileSystemError",
".",
"DECODE_FILE_FAILED",
";",
"case",
"appshell",
".",
"fs",
".",
"ERR_UNSUPPORTED_UTF16_ENCODING",
":",
"return",
"FileSystemError",
".",
"UNSUPPORTED_UTF16_ENCODING",
";",
"}",
"return",
"FileSystemError",
".",
"UNKNOWN",
";",
"}"
] |
Convert appshell error codes to FileSystemError values.
@param {?number} err An appshell error code
@return {?string} A FileSystemError string, or null if there was no error code.
@private
|
[
"Convert",
"appshell",
"error",
"codes",
"to",
"FileSystemError",
"values",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L143-L171
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
showOpenDialog
|
function showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, callback) {
appshell.fs.showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, _wrap(callback));
}
|
javascript
|
function showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, callback) {
appshell.fs.showOpenDialog(allowMultipleSelection, chooseDirectories, title, initialPath, fileTypes, _wrap(callback));
}
|
[
"function",
"showOpenDialog",
"(",
"allowMultipleSelection",
",",
"chooseDirectories",
",",
"title",
",",
"initialPath",
",",
"fileTypes",
",",
"callback",
")",
"{",
"appshell",
".",
"fs",
".",
"showOpenDialog",
"(",
"allowMultipleSelection",
",",
"chooseDirectories",
",",
"title",
",",
"initialPath",
",",
"fileTypes",
",",
"_wrap",
"(",
"callback",
")",
")",
";",
"}"
] |
Display an open-files dialog to the user and call back asynchronously with
either a FileSystmError string or an array of path strings, which indicate
the entry or entries selected.
@param {boolean} allowMultipleSelection
@param {boolean} chooseDirectories
@param {string} title
@param {string} initialPath
@param {Array.<string>=} fileTypes
@param {function(?string, Array.<string>=)} callback
|
[
"Display",
"an",
"open",
"-",
"files",
"dialog",
"to",
"the",
"user",
"and",
"call",
"back",
"asynchronously",
"with",
"either",
"a",
"FileSystmError",
"string",
"or",
"an",
"array",
"of",
"path",
"strings",
"which",
"indicate",
"the",
"entry",
"or",
"entries",
"selected",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L201-L203
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
showSaveDialog
|
function showSaveDialog(title, initialPath, proposedNewFilename, callback) {
appshell.fs.showSaveDialog(title, initialPath, proposedNewFilename, _wrap(callback));
}
|
javascript
|
function showSaveDialog(title, initialPath, proposedNewFilename, callback) {
appshell.fs.showSaveDialog(title, initialPath, proposedNewFilename, _wrap(callback));
}
|
[
"function",
"showSaveDialog",
"(",
"title",
",",
"initialPath",
",",
"proposedNewFilename",
",",
"callback",
")",
"{",
"appshell",
".",
"fs",
".",
"showSaveDialog",
"(",
"title",
",",
"initialPath",
",",
"proposedNewFilename",
",",
"_wrap",
"(",
"callback",
")",
")",
";",
"}"
] |
Display a save-file dialog and call back asynchronously with either a
FileSystemError string or the path to which the user has chosen to save
the file. If the dialog is cancelled, the path string will be empty.
@param {string} title
@param {string} initialPath
@param {string} proposedNewFilename
@param {function(?string, string=)} callback
|
[
"Display",
"a",
"save",
"-",
"file",
"dialog",
"and",
"call",
"back",
"asynchronously",
"with",
"either",
"a",
"FileSystemError",
"string",
"or",
"the",
"path",
"to",
"which",
"the",
"user",
"has",
"chosen",
"to",
"save",
"the",
"file",
".",
"If",
"the",
"dialog",
"is",
"cancelled",
"the",
"path",
"string",
"will",
"be",
"empty",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L215-L217
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
stat
|
function stat(path, callback) {
appshell.fs.stat(path, function (err, stats) {
if (err) {
callback(_mapError(err));
} else {
var options = {
isFile: stats.isFile(),
mtime: stats.mtime,
size: stats.size,
realPath: stats.realPath,
hash: stats.mtime.getTime()
};
var fsStats = new FileSystemStats(options);
callback(null, fsStats);
}
});
}
|
javascript
|
function stat(path, callback) {
appshell.fs.stat(path, function (err, stats) {
if (err) {
callback(_mapError(err));
} else {
var options = {
isFile: stats.isFile(),
mtime: stats.mtime,
size: stats.size,
realPath: stats.realPath,
hash: stats.mtime.getTime()
};
var fsStats = new FileSystemStats(options);
callback(null, fsStats);
}
});
}
|
[
"function",
"stat",
"(",
"path",
",",
"callback",
")",
"{",
"appshell",
".",
"fs",
".",
"stat",
"(",
"path",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"_mapError",
"(",
"err",
")",
")",
";",
"}",
"else",
"{",
"var",
"options",
"=",
"{",
"isFile",
":",
"stats",
".",
"isFile",
"(",
")",
",",
"mtime",
":",
"stats",
".",
"mtime",
",",
"size",
":",
"stats",
".",
"size",
",",
"realPath",
":",
"stats",
".",
"realPath",
",",
"hash",
":",
"stats",
".",
"mtime",
".",
"getTime",
"(",
")",
"}",
";",
"var",
"fsStats",
"=",
"new",
"FileSystemStats",
"(",
"options",
")",
";",
"callback",
"(",
"null",
",",
"fsStats",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Stat the file or directory at the given path, calling back
asynchronously with either a FileSystemError string or the entry's
associated FileSystemStats object.
@param {string} path
@param {function(?string, FileSystemStats=)} callback
|
[
"Stat",
"the",
"file",
"or",
"directory",
"at",
"the",
"given",
"path",
"calling",
"back",
"asynchronously",
"with",
"either",
"a",
"FileSystemError",
"string",
"or",
"the",
"entry",
"s",
"associated",
"FileSystemStats",
"object",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L227-L245
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
exists
|
function exists(path, callback) {
stat(path, function (err) {
if (err) {
if (err === FileSystemError.NOT_FOUND) {
callback(null, false);
} else {
callback(err);
}
return;
}
callback(null, true);
});
}
|
javascript
|
function exists(path, callback) {
stat(path, function (err) {
if (err) {
if (err === FileSystemError.NOT_FOUND) {
callback(null, false);
} else {
callback(err);
}
return;
}
callback(null, true);
});
}
|
[
"function",
"exists",
"(",
"path",
",",
"callback",
")",
"{",
"stat",
"(",
"path",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"if",
"(",
"err",
"===",
"FileSystemError",
".",
"NOT_FOUND",
")",
"{",
"callback",
"(",
"null",
",",
"false",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"return",
";",
"}",
"callback",
"(",
"null",
",",
"true",
")",
";",
"}",
")",
";",
"}"
] |
Determine whether a file or directory exists at the given path by calling
back asynchronously with either a FileSystemError string or a boolean,
which is true if the file exists and false otherwise. The error will never
be FileSystemError.NOT_FOUND; in that case, there will be no error and the
boolean parameter will be false.
@param {string} path
@param {function(?string, boolean)} callback
|
[
"Determine",
"whether",
"a",
"file",
"or",
"directory",
"exists",
"at",
"the",
"given",
"path",
"by",
"calling",
"back",
"asynchronously",
"with",
"either",
"a",
"FileSystemError",
"string",
"or",
"a",
"boolean",
"which",
"is",
"true",
"if",
"the",
"file",
"exists",
"and",
"false",
"otherwise",
".",
"The",
"error",
"will",
"never",
"be",
"FileSystemError",
".",
"NOT_FOUND",
";",
"in",
"that",
"case",
"there",
"will",
"be",
"no",
"error",
"and",
"the",
"boolean",
"parameter",
"will",
"be",
"false",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L257-L270
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
mkdir
|
function mkdir(path, mode, callback) {
if (typeof mode === "function") {
callback = mode;
mode = parseInt("0755", 8);
}
appshell.fs.makedir(path, mode, function (err) {
if (err) {
callback(_mapError(err));
} else {
stat(path, function (err, stat) {
callback(err, stat);
});
}
});
}
|
javascript
|
function mkdir(path, mode, callback) {
if (typeof mode === "function") {
callback = mode;
mode = parseInt("0755", 8);
}
appshell.fs.makedir(path, mode, function (err) {
if (err) {
callback(_mapError(err));
} else {
stat(path, function (err, stat) {
callback(err, stat);
});
}
});
}
|
[
"function",
"mkdir",
"(",
"path",
",",
"mode",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"mode",
"===",
"\"function\"",
")",
"{",
"callback",
"=",
"mode",
";",
"mode",
"=",
"parseInt",
"(",
"\"0755\"",
",",
"8",
")",
";",
"}",
"appshell",
".",
"fs",
".",
"makedir",
"(",
"path",
",",
"mode",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"_mapError",
"(",
"err",
")",
")",
";",
"}",
"else",
"{",
"stat",
"(",
"path",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"callback",
"(",
"err",
",",
"stat",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Create a directory at the given path, and call back asynchronously with
either a FileSystemError string or a stats object for the newly created
directory. The octal mode parameter is optional; if unspecified, the mode
of the created directory is implementation dependent.
@param {string} path
@param {number=} mode The base-eight mode of the newly created directory.
@param {function(?string, FileSystemStats=)=} callback
|
[
"Create",
"a",
"directory",
"at",
"the",
"given",
"path",
"and",
"call",
"back",
"asynchronously",
"with",
"either",
"a",
"FileSystemError",
"string",
"or",
"a",
"stats",
"object",
"for",
"the",
"newly",
"created",
"directory",
".",
"The",
"octal",
"mode",
"parameter",
"is",
"optional",
";",
"if",
"unspecified",
"the",
"mode",
"of",
"the",
"created",
"directory",
"is",
"implementation",
"dependent",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L319-L333
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
rename
|
function rename(oldPath, newPath, callback) {
appshell.fs.rename(oldPath, newPath, _wrap(callback));
}
|
javascript
|
function rename(oldPath, newPath, callback) {
appshell.fs.rename(oldPath, newPath, _wrap(callback));
}
|
[
"function",
"rename",
"(",
"oldPath",
",",
"newPath",
",",
"callback",
")",
"{",
"appshell",
".",
"fs",
".",
"rename",
"(",
"oldPath",
",",
"newPath",
",",
"_wrap",
"(",
"callback",
")",
")",
";",
"}"
] |
Rename the file or directory at oldPath to newPath, and call back
asynchronously with a possibly null FileSystemError string.
@param {string} oldPath
@param {string} newPath
@param {function(?string)=} callback
|
[
"Rename",
"the",
"file",
"or",
"directory",
"at",
"oldPath",
"to",
"newPath",
"and",
"call",
"back",
"asynchronously",
"with",
"a",
"possibly",
"null",
"FileSystemError",
"string",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L343-L345
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
doReadFile
|
function doReadFile(stat) {
if (stat.size > (FileUtils.MAX_FILE_SIZE)) {
callback(FileSystemError.EXCEEDS_MAX_FILE_SIZE);
} else {
appshell.fs.readFile(path, encoding, function (_err, _data, encoding, preserveBOM) {
if (_err) {
callback(_mapError(_err));
} else {
callback(null, _data, encoding, preserveBOM, stat);
}
});
}
}
|
javascript
|
function doReadFile(stat) {
if (stat.size > (FileUtils.MAX_FILE_SIZE)) {
callback(FileSystemError.EXCEEDS_MAX_FILE_SIZE);
} else {
appshell.fs.readFile(path, encoding, function (_err, _data, encoding, preserveBOM) {
if (_err) {
callback(_mapError(_err));
} else {
callback(null, _data, encoding, preserveBOM, stat);
}
});
}
}
|
[
"function",
"doReadFile",
"(",
"stat",
")",
"{",
"if",
"(",
"stat",
".",
"size",
">",
"(",
"FileUtils",
".",
"MAX_FILE_SIZE",
")",
")",
"{",
"callback",
"(",
"FileSystemError",
".",
"EXCEEDS_MAX_FILE_SIZE",
")",
";",
"}",
"else",
"{",
"appshell",
".",
"fs",
".",
"readFile",
"(",
"path",
",",
"encoding",
",",
"function",
"(",
"_err",
",",
"_data",
",",
"encoding",
",",
"preserveBOM",
")",
"{",
"if",
"(",
"_err",
")",
"{",
"callback",
"(",
"_mapError",
"(",
"_err",
")",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"_data",
",",
"encoding",
",",
"preserveBOM",
",",
"stat",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] |
callback to be executed when the call to stat completes or immediately if a stat object was passed as an argument
|
[
"callback",
"to",
"be",
"executed",
"when",
"the",
"call",
"to",
"stat",
"completes",
"or",
"immediately",
"if",
"a",
"stat",
"object",
"was",
"passed",
"as",
"an",
"argument"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L368-L380
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
moveToTrash
|
function moveToTrash(path, callback) {
appshell.fs.moveToTrash(path, function (err) {
callback(_mapError(err));
});
}
|
javascript
|
function moveToTrash(path, callback) {
appshell.fs.moveToTrash(path, function (err) {
callback(_mapError(err));
});
}
|
[
"function",
"moveToTrash",
"(",
"path",
",",
"callback",
")",
"{",
"appshell",
".",
"fs",
".",
"moveToTrash",
"(",
"path",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"_mapError",
"(",
"err",
")",
")",
";",
"}",
")",
";",
"}"
] |
Move the file or directory at the given path to a system dependent trash
location, calling back asynchronously with a possibly null FileSystemError
string. Directories will be moved even when non-empty.
@param {string} path
@param {function(string)=} callback
|
[
"Move",
"the",
"file",
"or",
"directory",
"at",
"the",
"given",
"path",
"to",
"a",
"system",
"dependent",
"trash",
"location",
"calling",
"back",
"asynchronously",
"with",
"a",
"possibly",
"null",
"FileSystemError",
"string",
".",
"Directories",
"will",
"be",
"moved",
"even",
"when",
"non",
"-",
"empty",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L484-L488
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
watchPath
|
function watchPath(path, ignored, callback) {
if (_isRunningOnWindowsXP) {
callback(FileSystemError.NOT_SUPPORTED);
return;
}
appshell.fs.isNetworkDrive(path, function (err, isNetworkDrive) {
if (err || isNetworkDrive) {
if (isNetworkDrive) {
callback(FileSystemError.NETWORK_DRIVE_NOT_SUPPORTED);
} else {
callback(FileSystemError.UNKNOWN);
}
return;
}
_nodeDomain.exec("watchPath", path, ignored)
.then(callback, callback);
});
}
|
javascript
|
function watchPath(path, ignored, callback) {
if (_isRunningOnWindowsXP) {
callback(FileSystemError.NOT_SUPPORTED);
return;
}
appshell.fs.isNetworkDrive(path, function (err, isNetworkDrive) {
if (err || isNetworkDrive) {
if (isNetworkDrive) {
callback(FileSystemError.NETWORK_DRIVE_NOT_SUPPORTED);
} else {
callback(FileSystemError.UNKNOWN);
}
return;
}
_nodeDomain.exec("watchPath", path, ignored)
.then(callback, callback);
});
}
|
[
"function",
"watchPath",
"(",
"path",
",",
"ignored",
",",
"callback",
")",
"{",
"if",
"(",
"_isRunningOnWindowsXP",
")",
"{",
"callback",
"(",
"FileSystemError",
".",
"NOT_SUPPORTED",
")",
";",
"return",
";",
"}",
"appshell",
".",
"fs",
".",
"isNetworkDrive",
"(",
"path",
",",
"function",
"(",
"err",
",",
"isNetworkDrive",
")",
"{",
"if",
"(",
"err",
"||",
"isNetworkDrive",
")",
"{",
"if",
"(",
"isNetworkDrive",
")",
"{",
"callback",
"(",
"FileSystemError",
".",
"NETWORK_DRIVE_NOT_SUPPORTED",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"FileSystemError",
".",
"UNKNOWN",
")",
";",
"}",
"return",
";",
"}",
"_nodeDomain",
".",
"exec",
"(",
"\"watchPath\"",
",",
"path",
",",
"ignored",
")",
".",
"then",
"(",
"callback",
",",
"callback",
")",
";",
"}",
")",
";",
"}"
] |
Start providing change notifications for the file or directory at the
given path, calling back asynchronously with a possibly null FileSystemError
string when the initialization is complete. Notifications are provided
using the changeCallback function provided by the initWatchers method.
Note that change notifications are only provided recursively for directories
when the recursiveWatch property of this module is true.
@param {string} path
@param {Array<string>} ignored
@param {function(?string)=} callback
|
[
"Start",
"providing",
"change",
"notifications",
"for",
"the",
"file",
"or",
"directory",
"at",
"the",
"given",
"path",
"calling",
"back",
"asynchronously",
"with",
"a",
"possibly",
"null",
"FileSystemError",
"string",
"when",
"the",
"initialization",
"is",
"complete",
".",
"Notifications",
"are",
"provided",
"using",
"the",
"changeCallback",
"function",
"provided",
"by",
"the",
"initWatchers",
"method",
".",
"Note",
"that",
"change",
"notifications",
"are",
"only",
"provided",
"recursively",
"for",
"directories",
"when",
"the",
"recursiveWatch",
"property",
"of",
"this",
"module",
"is",
"true",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L527-L544
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/AppshellFileSystem.js
|
unwatchPath
|
function unwatchPath(path, ignored, callback) {
_nodeDomain.exec("unwatchPath", path)
.then(callback, callback);
}
|
javascript
|
function unwatchPath(path, ignored, callback) {
_nodeDomain.exec("unwatchPath", path)
.then(callback, callback);
}
|
[
"function",
"unwatchPath",
"(",
"path",
",",
"ignored",
",",
"callback",
")",
"{",
"_nodeDomain",
".",
"exec",
"(",
"\"unwatchPath\"",
",",
"path",
")",
".",
"then",
"(",
"callback",
",",
"callback",
")",
";",
"}"
] |
Stop providing change notifications for the file or directory at the
given path, calling back asynchronously with a possibly null FileSystemError
string when the operation is complete.
This function needs to mirror the signature of watchPath
because of FileSystem.prototype._watchOrUnwatchEntry implementation.
@param {string} path
@param {Array<string>} ignored
@param {function(?string)=} callback
|
[
"Stop",
"providing",
"change",
"notifications",
"for",
"the",
"file",
"or",
"directory",
"at",
"the",
"given",
"path",
"calling",
"back",
"asynchronously",
"with",
"a",
"possibly",
"null",
"FileSystemError",
"string",
"when",
"the",
"operation",
"is",
"complete",
".",
"This",
"function",
"needs",
"to",
"mirror",
"the",
"signature",
"of",
"watchPath",
"because",
"of",
"FileSystem",
".",
"prototype",
".",
"_watchOrUnwatchEntry",
"implementation",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/AppshellFileSystem.js#L556-L559
|
train
|
adobe/brackets
|
src/project/FileSyncManager.js
|
reloadDoc
|
function reloadDoc(doc) {
var promise = FileUtils.readAsText(doc.file);
promise.done(function (text, readTimestamp) {
doc.refreshText(text, readTimestamp);
});
promise.fail(function (error) {
console.log("Error reloading contents of " + doc.file.fullPath, error);
});
return promise;
}
|
javascript
|
function reloadDoc(doc) {
var promise = FileUtils.readAsText(doc.file);
promise.done(function (text, readTimestamp) {
doc.refreshText(text, readTimestamp);
});
promise.fail(function (error) {
console.log("Error reloading contents of " + doc.file.fullPath, error);
});
return promise;
}
|
[
"function",
"reloadDoc",
"(",
"doc",
")",
"{",
"var",
"promise",
"=",
"FileUtils",
".",
"readAsText",
"(",
"doc",
".",
"file",
")",
";",
"promise",
".",
"done",
"(",
"function",
"(",
"text",
",",
"readTimestamp",
")",
"{",
"doc",
".",
"refreshText",
"(",
"text",
",",
"readTimestamp",
")",
";",
"}",
")",
";",
"promise",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"\"Error reloading contents of \"",
"+",
"doc",
".",
"file",
".",
"fullPath",
",",
"error",
")",
";",
"}",
")",
";",
"return",
"promise",
";",
"}"
] |
Reloads the Document's contents from disk, discarding any unsaved changes in the editor.
@param {!Document} doc
@return {$.Promise} Resolved after editor has been refreshed; rejected if unable to load the
file's new content. Errors are logged but no UI is shown.
|
[
"Reloads",
"the",
"Document",
"s",
"contents",
"from",
"disk",
"discarding",
"any",
"unsaved",
"changes",
"in",
"the",
"editor",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/FileSyncManager.js#L218-L229
|
train
|
adobe/brackets
|
src/extensibility/node/package-validator.js
|
parsePersonString
|
function parsePersonString(obj) {
if (typeof (obj) === "string") {
var parts = _personRegex.exec(obj);
// No regex match, so we just synthesize an object with an opaque name string
if (!parts) {
return {
name: obj
};
} else {
var result = {
name: parts[1]
};
if (parts[2]) {
result.email = parts[2];
}
if (parts[3]) {
result.url = parts[3];
}
return result;
}
} else {
// obj is not a string, so return as is
return obj;
}
}
|
javascript
|
function parsePersonString(obj) {
if (typeof (obj) === "string") {
var parts = _personRegex.exec(obj);
// No regex match, so we just synthesize an object with an opaque name string
if (!parts) {
return {
name: obj
};
} else {
var result = {
name: parts[1]
};
if (parts[2]) {
result.email = parts[2];
}
if (parts[3]) {
result.url = parts[3];
}
return result;
}
} else {
// obj is not a string, so return as is
return obj;
}
}
|
[
"function",
"parsePersonString",
"(",
"obj",
")",
"{",
"if",
"(",
"typeof",
"(",
"obj",
")",
"===",
"\"string\"",
")",
"{",
"var",
"parts",
"=",
"_personRegex",
".",
"exec",
"(",
"obj",
")",
";",
"if",
"(",
"!",
"parts",
")",
"{",
"return",
"{",
"name",
":",
"obj",
"}",
";",
"}",
"else",
"{",
"var",
"result",
"=",
"{",
"name",
":",
"parts",
"[",
"1",
"]",
"}",
";",
"if",
"(",
"parts",
"[",
"2",
"]",
")",
"{",
"result",
".",
"email",
"=",
"parts",
"[",
"2",
"]",
";",
"}",
"if",
"(",
"parts",
"[",
"3",
"]",
")",
"{",
"result",
".",
"url",
"=",
"parts",
"[",
"3",
"]",
";",
"}",
"return",
"result",
";",
"}",
"}",
"else",
"{",
"return",
"obj",
";",
"}",
"}"
] |
Normalizes person fields from package.json.
These fields can be an object with name, email and url properties or a
string of the form "name <email> <url>". This does a tolerant parsing of
the data to try to return an object with name and optional email and url.
If the string does not match the format, the string is returned as the
name on the resulting object.
If an object other than a string is passed in, it's returned as is.
@param <String|Object> obj to normalize
@return {Object} person object with name and optional email and url
|
[
"Normalizes",
"person",
"fields",
"from",
"package",
".",
"json",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L97-L122
|
train
|
adobe/brackets
|
src/extensibility/node/package-validator.js
|
containsWords
|
function containsWords(wordlist, str) {
var i;
var matches = [];
for (i = 0; i < wordlist.length; i++) {
var re = new RegExp("\\b" + wordlist[i] + "\\b", "i");
if (re.exec(str)) {
matches.push(wordlist[i]);
}
}
return matches;
}
|
javascript
|
function containsWords(wordlist, str) {
var i;
var matches = [];
for (i = 0; i < wordlist.length; i++) {
var re = new RegExp("\\b" + wordlist[i] + "\\b", "i");
if (re.exec(str)) {
matches.push(wordlist[i]);
}
}
return matches;
}
|
[
"function",
"containsWords",
"(",
"wordlist",
",",
"str",
")",
"{",
"var",
"i",
";",
"var",
"matches",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"wordlist",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"re",
"=",
"new",
"RegExp",
"(",
"\"\\\\b\"",
"+",
"\\\\",
"+",
"wordlist",
"[",
"i",
"]",
",",
"\"\\\\b\"",
")",
";",
"\\\\",
"}",
"\"i\"",
"}"
] |
Determines if any of the words in wordlist appear in str.
@param {String[]} wordlist list of words to check
@param {String} str to check for words
@return {String[]} words that matched
|
[
"Determines",
"if",
"any",
"of",
"the",
"words",
"in",
"wordlist",
"appear",
"in",
"str",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L131-L141
|
train
|
adobe/brackets
|
src/extensibility/node/package-validator.js
|
findCommonPrefix
|
function findCommonPrefix(extractDir, callback) {
fs.readdir(extractDir, function (err, files) {
ignoredFolders.forEach(function (folder) {
var index = files.indexOf(folder);
if (index !== -1) {
files.splice(index, 1);
}
});
if (err) {
callback(err);
} else if (files.length === 1) {
var name = files[0];
if (fs.statSync(path.join(extractDir, name)).isDirectory()) {
callback(null, name);
} else {
callback(null, "");
}
} else {
callback(null, "");
}
});
}
|
javascript
|
function findCommonPrefix(extractDir, callback) {
fs.readdir(extractDir, function (err, files) {
ignoredFolders.forEach(function (folder) {
var index = files.indexOf(folder);
if (index !== -1) {
files.splice(index, 1);
}
});
if (err) {
callback(err);
} else if (files.length === 1) {
var name = files[0];
if (fs.statSync(path.join(extractDir, name)).isDirectory()) {
callback(null, name);
} else {
callback(null, "");
}
} else {
callback(null, "");
}
});
}
|
[
"function",
"findCommonPrefix",
"(",
"extractDir",
",",
"callback",
")",
"{",
"fs",
".",
"readdir",
"(",
"extractDir",
",",
"function",
"(",
"err",
",",
"files",
")",
"{",
"ignoredFolders",
".",
"forEach",
"(",
"function",
"(",
"folder",
")",
"{",
"var",
"index",
"=",
"files",
".",
"indexOf",
"(",
"folder",
")",
";",
"if",
"(",
"index",
"!==",
"-",
"1",
")",
"{",
"files",
".",
"splice",
"(",
"index",
",",
"1",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"files",
".",
"length",
"===",
"1",
")",
"{",
"var",
"name",
"=",
"files",
"[",
"0",
"]",
";",
"if",
"(",
"fs",
".",
"statSync",
"(",
"path",
".",
"join",
"(",
"extractDir",
",",
"name",
")",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"callback",
"(",
"null",
",",
"name",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"\"\"",
")",
";",
"}",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"\"\"",
")",
";",
"}",
"}",
")",
";",
"}"
] |
Finds the common prefix, if any, for the files in a package file.
In some package files, all of the files are contained in a subdirectory, and this function
will identify that directory if it exists.
@param {string} extractDir directory into which the package was extracted
@param {function(Error, string)} callback function to accept err, commonPrefix (which will be "" if there is none)
|
[
"Finds",
"the",
"common",
"prefix",
"if",
"any",
"for",
"the",
"files",
"in",
"a",
"package",
"file",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L152-L173
|
train
|
adobe/brackets
|
src/extensibility/node/package-validator.js
|
validatePackageJSON
|
function validatePackageJSON(path, packageJSON, options, callback) {
var errors = [];
if (fs.existsSync(packageJSON)) {
fs.readFile(packageJSON, {
encoding: "utf8"
}, function (err, data) {
if (err) {
callback(err, null, null);
return;
}
var metadata;
try {
metadata = JSON.parse(data);
} catch (e) {
errors.push([Errors.INVALID_PACKAGE_JSON, e.toString(), path]);
callback(null, errors, undefined);
return;
}
// confirm required fields in the metadata
if (!metadata.name) {
errors.push([Errors.MISSING_PACKAGE_NAME, path]);
} else if (!validateName(metadata.name)) {
errors.push([Errors.BAD_PACKAGE_NAME, metadata.name]);
}
if (!metadata.version) {
errors.push([Errors.MISSING_PACKAGE_VERSION, path]);
} else if (!semver.valid(metadata.version)) {
errors.push([Errors.INVALID_VERSION_NUMBER, metadata.version, path]);
}
// normalize the author
if (metadata.author) {
metadata.author = parsePersonString(metadata.author);
}
// contributors should be an array of people.
// normalize each entry.
if (metadata.contributors) {
if (metadata.contributors.map) {
metadata.contributors = metadata.contributors.map(function (person) {
return parsePersonString(person);
});
} else {
metadata.contributors = [
parsePersonString(metadata.contributors)
];
}
}
if (metadata.engines && metadata.engines.brackets) {
var range = metadata.engines.brackets;
if (!semver.validRange(range)) {
errors.push([Errors.INVALID_BRACKETS_VERSION, range, path]);
}
}
if (options.disallowedWords) {
["title", "description", "name"].forEach(function (field) {
var words = containsWords(options.disallowedWords, metadata[field]);
if (words.length > 0) {
errors.push([Errors.DISALLOWED_WORDS, field, words.toString(), path]);
}
});
}
callback(null, errors, metadata);
});
} else {
if (options.requirePackageJSON) {
errors.push([Errors.MISSING_PACKAGE_JSON, path]);
}
callback(null, errors, null);
}
}
|
javascript
|
function validatePackageJSON(path, packageJSON, options, callback) {
var errors = [];
if (fs.existsSync(packageJSON)) {
fs.readFile(packageJSON, {
encoding: "utf8"
}, function (err, data) {
if (err) {
callback(err, null, null);
return;
}
var metadata;
try {
metadata = JSON.parse(data);
} catch (e) {
errors.push([Errors.INVALID_PACKAGE_JSON, e.toString(), path]);
callback(null, errors, undefined);
return;
}
// confirm required fields in the metadata
if (!metadata.name) {
errors.push([Errors.MISSING_PACKAGE_NAME, path]);
} else if (!validateName(metadata.name)) {
errors.push([Errors.BAD_PACKAGE_NAME, metadata.name]);
}
if (!metadata.version) {
errors.push([Errors.MISSING_PACKAGE_VERSION, path]);
} else if (!semver.valid(metadata.version)) {
errors.push([Errors.INVALID_VERSION_NUMBER, metadata.version, path]);
}
// normalize the author
if (metadata.author) {
metadata.author = parsePersonString(metadata.author);
}
// contributors should be an array of people.
// normalize each entry.
if (metadata.contributors) {
if (metadata.contributors.map) {
metadata.contributors = metadata.contributors.map(function (person) {
return parsePersonString(person);
});
} else {
metadata.contributors = [
parsePersonString(metadata.contributors)
];
}
}
if (metadata.engines && metadata.engines.brackets) {
var range = metadata.engines.brackets;
if (!semver.validRange(range)) {
errors.push([Errors.INVALID_BRACKETS_VERSION, range, path]);
}
}
if (options.disallowedWords) {
["title", "description", "name"].forEach(function (field) {
var words = containsWords(options.disallowedWords, metadata[field]);
if (words.length > 0) {
errors.push([Errors.DISALLOWED_WORDS, field, words.toString(), path]);
}
});
}
callback(null, errors, metadata);
});
} else {
if (options.requirePackageJSON) {
errors.push([Errors.MISSING_PACKAGE_JSON, path]);
}
callback(null, errors, null);
}
}
|
[
"function",
"validatePackageJSON",
"(",
"path",
",",
"packageJSON",
",",
"options",
",",
"callback",
")",
"{",
"var",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"packageJSON",
")",
")",
"{",
"fs",
".",
"readFile",
"(",
"packageJSON",
",",
"{",
"encoding",
":",
"\"utf8\"",
"}",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
",",
"null",
")",
";",
"return",
";",
"}",
"var",
"metadata",
";",
"try",
"{",
"metadata",
"=",
"JSON",
".",
"parse",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"INVALID_PACKAGE_JSON",
",",
"e",
".",
"toString",
"(",
")",
",",
"path",
"]",
")",
";",
"callback",
"(",
"null",
",",
"errors",
",",
"undefined",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"metadata",
".",
"name",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"MISSING_PACKAGE_NAME",
",",
"path",
"]",
")",
";",
"}",
"else",
"if",
"(",
"!",
"validateName",
"(",
"metadata",
".",
"name",
")",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"BAD_PACKAGE_NAME",
",",
"metadata",
".",
"name",
"]",
")",
";",
"}",
"if",
"(",
"!",
"metadata",
".",
"version",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"MISSING_PACKAGE_VERSION",
",",
"path",
"]",
")",
";",
"}",
"else",
"if",
"(",
"!",
"semver",
".",
"valid",
"(",
"metadata",
".",
"version",
")",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"INVALID_VERSION_NUMBER",
",",
"metadata",
".",
"version",
",",
"path",
"]",
")",
";",
"}",
"if",
"(",
"metadata",
".",
"author",
")",
"{",
"metadata",
".",
"author",
"=",
"parsePersonString",
"(",
"metadata",
".",
"author",
")",
";",
"}",
"if",
"(",
"metadata",
".",
"contributors",
")",
"{",
"if",
"(",
"metadata",
".",
"contributors",
".",
"map",
")",
"{",
"metadata",
".",
"contributors",
"=",
"metadata",
".",
"contributors",
".",
"map",
"(",
"function",
"(",
"person",
")",
"{",
"return",
"parsePersonString",
"(",
"person",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"metadata",
".",
"contributors",
"=",
"[",
"parsePersonString",
"(",
"metadata",
".",
"contributors",
")",
"]",
";",
"}",
"}",
"if",
"(",
"metadata",
".",
"engines",
"&&",
"metadata",
".",
"engines",
".",
"brackets",
")",
"{",
"var",
"range",
"=",
"metadata",
".",
"engines",
".",
"brackets",
";",
"if",
"(",
"!",
"semver",
".",
"validRange",
"(",
"range",
")",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"INVALID_BRACKETS_VERSION",
",",
"range",
",",
"path",
"]",
")",
";",
"}",
"}",
"if",
"(",
"options",
".",
"disallowedWords",
")",
"{",
"[",
"\"title\"",
",",
"\"description\"",
",",
"\"name\"",
"]",
".",
"forEach",
"(",
"function",
"(",
"field",
")",
"{",
"var",
"words",
"=",
"containsWords",
"(",
"options",
".",
"disallowedWords",
",",
"metadata",
"[",
"field",
"]",
")",
";",
"if",
"(",
"words",
".",
"length",
">",
"0",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"DISALLOWED_WORDS",
",",
"field",
",",
"words",
".",
"toString",
"(",
")",
",",
"path",
"]",
")",
";",
"}",
"}",
")",
";",
"}",
"callback",
"(",
"null",
",",
"errors",
",",
"metadata",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"options",
".",
"requirePackageJSON",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"MISSING_PACKAGE_JSON",
",",
"path",
"]",
")",
";",
"}",
"callback",
"(",
"null",
",",
"errors",
",",
"null",
")",
";",
"}",
"}"
] |
Validates the contents of package.json.
@param {string} path path to package file (used in error reporting)
@param {string} packageJSON path to the package.json file to check
@param {Object} options validation options passed to `validate()`
@param {function(Error, Array.<Array.<string, ...>>, Object)} callback function to call with array of errors and metadata
|
[
"Validates",
"the",
"contents",
"of",
"package",
".",
"json",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L183-L258
|
train
|
adobe/brackets
|
src/extensibility/node/package-validator.js
|
extractAndValidateFiles
|
function extractAndValidateFiles(zipPath, extractDir, options, callback) {
var unzipper = new DecompressZip(zipPath);
unzipper.on("error", function (err) {
// General error to report for problems reading the file
callback(null, {
errors: [[Errors.INVALID_ZIP_FILE, zipPath, err]]
});
return;
});
unzipper.on("extract", function (log) {
findCommonPrefix(extractDir, function (err, commonPrefix) {
if (err) {
callback(err, null);
return;
}
var packageJSON = path.join(extractDir, commonPrefix, "package.json");
validatePackageJSON(zipPath, packageJSON, options, function (err, errors, metadata) {
if (err) {
callback(err, null);
return;
}
var mainJS = path.join(extractDir, commonPrefix, "main.js"),
isTheme = metadata && metadata.theme;
// Throw missing main.js file only for non-theme extensions
if (!isTheme && !fs.existsSync(mainJS)) {
errors.push([Errors.MISSING_MAIN, zipPath, mainJS]);
}
var npmOptions = ['--production'];
if (options.proxy) {
npmOptions.push('--proxy ' + options.proxy);
}
if (process.platform.startsWith('win')) {
// On Windows force a 32 bit build until nodejs 64 bit is supported.
npmOptions.push('--arch=ia32');
npmOptions.push('--npm_config_arch=ia32');
npmOptions.push('--npm_config_target_arch=ia32');
}
performNpmInstallIfRequired(npmOptions, {
errors: errors,
metadata: metadata,
commonPrefix: commonPrefix,
extractDir: extractDir
}, callback);
});
});
});
unzipper.extract({
path: extractDir,
filter: function (file) {
return file.type !== "SymbolicLink";
}
});
}
|
javascript
|
function extractAndValidateFiles(zipPath, extractDir, options, callback) {
var unzipper = new DecompressZip(zipPath);
unzipper.on("error", function (err) {
// General error to report for problems reading the file
callback(null, {
errors: [[Errors.INVALID_ZIP_FILE, zipPath, err]]
});
return;
});
unzipper.on("extract", function (log) {
findCommonPrefix(extractDir, function (err, commonPrefix) {
if (err) {
callback(err, null);
return;
}
var packageJSON = path.join(extractDir, commonPrefix, "package.json");
validatePackageJSON(zipPath, packageJSON, options, function (err, errors, metadata) {
if (err) {
callback(err, null);
return;
}
var mainJS = path.join(extractDir, commonPrefix, "main.js"),
isTheme = metadata && metadata.theme;
// Throw missing main.js file only for non-theme extensions
if (!isTheme && !fs.existsSync(mainJS)) {
errors.push([Errors.MISSING_MAIN, zipPath, mainJS]);
}
var npmOptions = ['--production'];
if (options.proxy) {
npmOptions.push('--proxy ' + options.proxy);
}
if (process.platform.startsWith('win')) {
// On Windows force a 32 bit build until nodejs 64 bit is supported.
npmOptions.push('--arch=ia32');
npmOptions.push('--npm_config_arch=ia32');
npmOptions.push('--npm_config_target_arch=ia32');
}
performNpmInstallIfRequired(npmOptions, {
errors: errors,
metadata: metadata,
commonPrefix: commonPrefix,
extractDir: extractDir
}, callback);
});
});
});
unzipper.extract({
path: extractDir,
filter: function (file) {
return file.type !== "SymbolicLink";
}
});
}
|
[
"function",
"extractAndValidateFiles",
"(",
"zipPath",
",",
"extractDir",
",",
"options",
",",
"callback",
")",
"{",
"var",
"unzipper",
"=",
"new",
"DecompressZip",
"(",
"zipPath",
")",
";",
"unzipper",
".",
"on",
"(",
"\"error\"",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"null",
",",
"{",
"errors",
":",
"[",
"[",
"Errors",
".",
"INVALID_ZIP_FILE",
",",
"zipPath",
",",
"err",
"]",
"]",
"}",
")",
";",
"return",
";",
"}",
")",
";",
"unzipper",
".",
"on",
"(",
"\"extract\"",
",",
"function",
"(",
"log",
")",
"{",
"findCommonPrefix",
"(",
"extractDir",
",",
"function",
"(",
"err",
",",
"commonPrefix",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"return",
";",
"}",
"var",
"packageJSON",
"=",
"path",
".",
"join",
"(",
"extractDir",
",",
"commonPrefix",
",",
"\"package.json\"",
")",
";",
"validatePackageJSON",
"(",
"zipPath",
",",
"packageJSON",
",",
"options",
",",
"function",
"(",
"err",
",",
"errors",
",",
"metadata",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"return",
";",
"}",
"var",
"mainJS",
"=",
"path",
".",
"join",
"(",
"extractDir",
",",
"commonPrefix",
",",
"\"main.js\"",
")",
",",
"isTheme",
"=",
"metadata",
"&&",
"metadata",
".",
"theme",
";",
"if",
"(",
"!",
"isTheme",
"&&",
"!",
"fs",
".",
"existsSync",
"(",
"mainJS",
")",
")",
"{",
"errors",
".",
"push",
"(",
"[",
"Errors",
".",
"MISSING_MAIN",
",",
"zipPath",
",",
"mainJS",
"]",
")",
";",
"}",
"var",
"npmOptions",
"=",
"[",
"'--production'",
"]",
";",
"if",
"(",
"options",
".",
"proxy",
")",
"{",
"npmOptions",
".",
"push",
"(",
"'--proxy '",
"+",
"options",
".",
"proxy",
")",
";",
"}",
"if",
"(",
"process",
".",
"platform",
".",
"startsWith",
"(",
"'win'",
")",
")",
"{",
"npmOptions",
".",
"push",
"(",
"'--arch=ia32'",
")",
";",
"npmOptions",
".",
"push",
"(",
"'--npm_config_arch=ia32'",
")",
";",
"npmOptions",
".",
"push",
"(",
"'--npm_config_target_arch=ia32'",
")",
";",
"}",
"performNpmInstallIfRequired",
"(",
"npmOptions",
",",
"{",
"errors",
":",
"errors",
",",
"metadata",
":",
"metadata",
",",
"commonPrefix",
":",
"commonPrefix",
",",
"extractDir",
":",
"extractDir",
"}",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"unzipper",
".",
"extract",
"(",
"{",
"path",
":",
"extractDir",
",",
"filter",
":",
"function",
"(",
"file",
")",
"{",
"return",
"file",
".",
"type",
"!==",
"\"SymbolicLink\"",
";",
"}",
"}",
")",
";",
"}"
] |
Extracts the package into the given directory and then validates it.
@param {string} zipPath path to package zip file
@param {string} extractDir directory to extract package into
@param {Object} options validation options
@param {function(Error, {errors: Array, metadata: Object, commonPrefix: string, extractDir: string})} callback function to call with the result
|
[
"Extracts",
"the",
"package",
"into",
"the",
"given",
"directory",
"and",
"then",
"validates",
"it",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L268-L327
|
train
|
adobe/brackets
|
src/extensibility/node/package-validator.js
|
validate
|
function validate(path, options, callback) {
options = options || {};
fs.exists(path, function (doesExist) {
if (!doesExist) {
callback(null, {
errors: [[Errors.NOT_FOUND_ERR, path]]
});
return;
}
temp.mkdir("bracketsPackage_", function _tempDirCreated(err, extractDir) {
if (err) {
callback(err, null);
return;
}
extractAndValidateFiles(path, extractDir, options, callback);
});
});
}
|
javascript
|
function validate(path, options, callback) {
options = options || {};
fs.exists(path, function (doesExist) {
if (!doesExist) {
callback(null, {
errors: [[Errors.NOT_FOUND_ERR, path]]
});
return;
}
temp.mkdir("bracketsPackage_", function _tempDirCreated(err, extractDir) {
if (err) {
callback(err, null);
return;
}
extractAndValidateFiles(path, extractDir, options, callback);
});
});
}
|
[
"function",
"validate",
"(",
"path",
",",
"options",
",",
"callback",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"fs",
".",
"exists",
"(",
"path",
",",
"function",
"(",
"doesExist",
")",
"{",
"if",
"(",
"!",
"doesExist",
")",
"{",
"callback",
"(",
"null",
",",
"{",
"errors",
":",
"[",
"[",
"Errors",
".",
"NOT_FOUND_ERR",
",",
"path",
"]",
"]",
"}",
")",
";",
"return",
";",
"}",
"temp",
".",
"mkdir",
"(",
"\"bracketsPackage_\"",
",",
"function",
"_tempDirCreated",
"(",
"err",
",",
"extractDir",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"return",
";",
"}",
"extractAndValidateFiles",
"(",
"path",
",",
"extractDir",
",",
"options",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Implements the "validate" command in the "extensions" domain.
Validates the zipped package at path.
The "err" parameter of the callback is only set if there was an
unexpected error. Otherwise, errors are reported in the result.
The result object has an "errors" property. It is an array of
arrays of strings. Each array in the array is a set of parameters
that can be passed to StringUtils.format for internationalization.
The array will be empty if there are no errors.
The result will have a "metadata" property if the metadata was
read successfully from package.json in the zip file.
@param {string} path Absolute path to the package zip file
@param {{requirePackageJSON: ?boolean, disallowedWords: ?Array.<string>, proxy: ?<string>}} options for validation
@param {function} callback (err, result)
|
[
"Implements",
"the",
"validate",
"command",
"in",
"the",
"extensions",
"domain",
".",
"Validates",
"the",
"zipped",
"package",
"at",
"path",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensibility/node/package-validator.js#L348-L365
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/foldhelpers/foldSelected.js
|
SelectionFold
|
function SelectionFold(cm, start) {
if (!cm.somethingSelected()) {
return;
}
var from = cm.getCursor("from"),
to = cm.getCursor("to");
if (from.line === start.line) {
return {from: from, to: to};
}
}
|
javascript
|
function SelectionFold(cm, start) {
if (!cm.somethingSelected()) {
return;
}
var from = cm.getCursor("from"),
to = cm.getCursor("to");
if (from.line === start.line) {
return {from: from, to: to};
}
}
|
[
"function",
"SelectionFold",
"(",
"cm",
",",
"start",
")",
"{",
"if",
"(",
"!",
"cm",
".",
"somethingSelected",
"(",
")",
")",
"{",
"return",
";",
"}",
"var",
"from",
"=",
"cm",
".",
"getCursor",
"(",
"\"from\"",
")",
",",
"to",
"=",
"cm",
".",
"getCursor",
"(",
"\"to\"",
")",
";",
"if",
"(",
"from",
".",
"line",
"===",
"start",
".",
"line",
")",
"{",
"return",
"{",
"from",
":",
"from",
",",
"to",
":",
"to",
"}",
";",
"}",
"}"
] |
This helper returns the start and end range representing the current selection in the editor.
@param {Object} cm The Codemirror instance
@param {Object} start A Codemirror.Pos object {line, ch} representing the current line we are
checking for fold ranges
@returns {Object} The fold range, {from, to} representing the current selection.
|
[
"This",
"helper",
"returns",
"the",
"start",
"and",
"end",
"range",
"representing",
"the",
"current",
"selection",
"in",
"the",
"editor",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/foldhelpers/foldSelected.js#L17-L27
|
train
|
adobe/brackets
|
src/LiveDevelopment/Inspector/Inspector.js
|
_send
|
function _send(method, signature, varargs) {
if (!_socket) {
console.log("You must connect to the WebSocket before sending messages.");
// FUTURE: Our current implementation closes and re-opens an inspector connection whenever
// a new HTML file is selected. If done quickly enough, pending requests from the previous
// connection could come in before the new socket connection is established. For now we
// simply ignore this condition.
// This race condition will go away once we support multiple inspector connections and turn
// off auto re-opening when a new HTML file is selected.
return (new $.Deferred()).reject().promise();
}
var id, callback, args, i, params = {}, promise, msg;
// extract the parameters, the callback function, and the message id
args = Array.prototype.slice.call(arguments, 2);
if (typeof args[args.length - 1] === "function") {
callback = args.pop();
} else {
var deferred = new $.Deferred();
promise = deferred.promise();
callback = function (result, error) {
if (error) {
deferred.reject(error);
} else {
deferred.resolve(result);
}
};
}
id = _messageId++;
// verify the parameters against the method signature
// this also constructs the params object of type {name -> value}
if (signature) {
for (i in signature) {
if (_verifySignature(args[i], signature[i])) {
params[signature[i].name] = args[i];
}
}
}
// Store message callback and send message
msg = { method: method, id: id, params: params };
_messageCallbacks[id] = { callback: callback, message: msg };
_socket.send(JSON.stringify(msg));
return promise;
}
|
javascript
|
function _send(method, signature, varargs) {
if (!_socket) {
console.log("You must connect to the WebSocket before sending messages.");
// FUTURE: Our current implementation closes and re-opens an inspector connection whenever
// a new HTML file is selected. If done quickly enough, pending requests from the previous
// connection could come in before the new socket connection is established. For now we
// simply ignore this condition.
// This race condition will go away once we support multiple inspector connections and turn
// off auto re-opening when a new HTML file is selected.
return (new $.Deferred()).reject().promise();
}
var id, callback, args, i, params = {}, promise, msg;
// extract the parameters, the callback function, and the message id
args = Array.prototype.slice.call(arguments, 2);
if (typeof args[args.length - 1] === "function") {
callback = args.pop();
} else {
var deferred = new $.Deferred();
promise = deferred.promise();
callback = function (result, error) {
if (error) {
deferred.reject(error);
} else {
deferred.resolve(result);
}
};
}
id = _messageId++;
// verify the parameters against the method signature
// this also constructs the params object of type {name -> value}
if (signature) {
for (i in signature) {
if (_verifySignature(args[i], signature[i])) {
params[signature[i].name] = args[i];
}
}
}
// Store message callback and send message
msg = { method: method, id: id, params: params };
_messageCallbacks[id] = { callback: callback, message: msg };
_socket.send(JSON.stringify(msg));
return promise;
}
|
[
"function",
"_send",
"(",
"method",
",",
"signature",
",",
"varargs",
")",
"{",
"if",
"(",
"!",
"_socket",
")",
"{",
"console",
".",
"log",
"(",
"\"You must connect to the WebSocket before sending messages.\"",
")",
";",
"return",
"(",
"new",
"$",
".",
"Deferred",
"(",
")",
")",
".",
"reject",
"(",
")",
".",
"promise",
"(",
")",
";",
"}",
"var",
"id",
",",
"callback",
",",
"args",
",",
"i",
",",
"params",
"=",
"{",
"}",
",",
"promise",
",",
"msg",
";",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"2",
")",
";",
"if",
"(",
"typeof",
"args",
"[",
"args",
".",
"length",
"-",
"1",
"]",
"===",
"\"function\"",
")",
"{",
"callback",
"=",
"args",
".",
"pop",
"(",
")",
";",
"}",
"else",
"{",
"var",
"deferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"promise",
"=",
"deferred",
".",
"promise",
"(",
")",
";",
"callback",
"=",
"function",
"(",
"result",
",",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"deferred",
".",
"reject",
"(",
"error",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"resolve",
"(",
"result",
")",
";",
"}",
"}",
";",
"}",
"id",
"=",
"_messageId",
"++",
";",
"if",
"(",
"signature",
")",
"{",
"for",
"(",
"i",
"in",
"signature",
")",
"{",
"if",
"(",
"_verifySignature",
"(",
"args",
"[",
"i",
"]",
",",
"signature",
"[",
"i",
"]",
")",
")",
"{",
"params",
"[",
"signature",
"[",
"i",
"]",
".",
"name",
"]",
"=",
"args",
"[",
"i",
"]",
";",
"}",
"}",
"}",
"msg",
"=",
"{",
"method",
":",
"method",
",",
"id",
":",
"id",
",",
"params",
":",
"params",
"}",
";",
"_messageCallbacks",
"[",
"id",
"]",
"=",
"{",
"callback",
":",
"callback",
",",
"message",
":",
"msg",
"}",
";",
"_socket",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"msg",
")",
")",
";",
"return",
"promise",
";",
"}"
] |
Send a message to the remote debugger
All passed arguments after the signature are passed on as parameters.
If the last argument is a function, it is used as the callback function.
@param {string} remote method
@param {object} the method signature
|
[
"Send",
"a",
"message",
"to",
"the",
"remote",
"debugger",
"All",
"passed",
"arguments",
"after",
"the",
"signature",
"are",
"passed",
"on",
"as",
"parameters",
".",
"If",
"the",
"last",
"argument",
"is",
"a",
"function",
"it",
"is",
"used",
"as",
"the",
"callback",
"function",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L117-L166
|
train
|
adobe/brackets
|
src/LiveDevelopment/Inspector/Inspector.js
|
_onError
|
function _onError(error) {
if (_connectDeferred) {
_connectDeferred.reject();
_connectDeferred = null;
}
exports.trigger("error", error);
}
|
javascript
|
function _onError(error) {
if (_connectDeferred) {
_connectDeferred.reject();
_connectDeferred = null;
}
exports.trigger("error", error);
}
|
[
"function",
"_onError",
"(",
"error",
")",
"{",
"if",
"(",
"_connectDeferred",
")",
"{",
"_connectDeferred",
".",
"reject",
"(",
")",
";",
"_connectDeferred",
"=",
"null",
";",
"}",
"exports",
".",
"trigger",
"(",
"\"error\"",
",",
"error",
")",
";",
"}"
] |
WebSocket reported an error
|
[
"WebSocket",
"reported",
"an",
"error"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L186-L192
|
train
|
adobe/brackets
|
src/LiveDevelopment/Inspector/Inspector.js
|
disconnect
|
function disconnect() {
var deferred = new $.Deferred(),
promise = deferred.promise();
if (_socket && (_socket.readyState === WebSocket.OPEN)) {
_socket.onclose = function () {
// trigger disconnect event
_onDisconnect();
deferred.resolve();
};
promise = Async.withTimeout(promise, 5000);
_socket.close();
} else {
if (_socket) {
delete _socket.onmessage;
delete _socket.onopen;
delete _socket.onclose;
delete _socket.onerror;
_socket = undefined;
}
deferred.resolve();
}
return promise;
}
|
javascript
|
function disconnect() {
var deferred = new $.Deferred(),
promise = deferred.promise();
if (_socket && (_socket.readyState === WebSocket.OPEN)) {
_socket.onclose = function () {
// trigger disconnect event
_onDisconnect();
deferred.resolve();
};
promise = Async.withTimeout(promise, 5000);
_socket.close();
} else {
if (_socket) {
delete _socket.onmessage;
delete _socket.onopen;
delete _socket.onclose;
delete _socket.onerror;
_socket = undefined;
}
deferred.resolve();
}
return promise;
}
|
[
"function",
"disconnect",
"(",
")",
"{",
"var",
"deferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"promise",
"=",
"deferred",
".",
"promise",
"(",
")",
";",
"if",
"(",
"_socket",
"&&",
"(",
"_socket",
".",
"readyState",
"===",
"WebSocket",
".",
"OPEN",
")",
")",
"{",
"_socket",
".",
"onclose",
"=",
"function",
"(",
")",
"{",
"_onDisconnect",
"(",
")",
";",
"deferred",
".",
"resolve",
"(",
")",
";",
"}",
";",
"promise",
"=",
"Async",
".",
"withTimeout",
"(",
"promise",
",",
"5000",
")",
";",
"_socket",
".",
"close",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"_socket",
")",
"{",
"delete",
"_socket",
".",
"onmessage",
";",
"delete",
"_socket",
".",
"onopen",
";",
"delete",
"_socket",
".",
"onclose",
";",
"delete",
"_socket",
".",
"onerror",
";",
"_socket",
"=",
"undefined",
";",
"}",
"deferred",
".",
"resolve",
"(",
")",
";",
"}",
"return",
"promise",
";",
"}"
] |
Disconnect from the remote debugger WebSocket
@return {jQuery.Promise} Promise that is resolved immediately if not
currently connected or asynchronously when the socket is closed.
|
[
"Disconnect",
"from",
"the",
"remote",
"debugger",
"WebSocket"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L272-L301
|
train
|
adobe/brackets
|
src/LiveDevelopment/Inspector/Inspector.js
|
connect
|
function connect(socketURL) {
disconnect().done(function () {
_socket = new WebSocket(socketURL);
_socket.onmessage = _onMessage;
_socket.onopen = _onConnect;
_socket.onclose = _onDisconnect;
_socket.onerror = _onError;
});
}
|
javascript
|
function connect(socketURL) {
disconnect().done(function () {
_socket = new WebSocket(socketURL);
_socket.onmessage = _onMessage;
_socket.onopen = _onConnect;
_socket.onclose = _onDisconnect;
_socket.onerror = _onError;
});
}
|
[
"function",
"connect",
"(",
"socketURL",
")",
"{",
"disconnect",
"(",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"_socket",
"=",
"new",
"WebSocket",
"(",
"socketURL",
")",
";",
"_socket",
".",
"onmessage",
"=",
"_onMessage",
";",
"_socket",
".",
"onopen",
"=",
"_onConnect",
";",
"_socket",
".",
"onclose",
"=",
"_onDisconnect",
";",
"_socket",
".",
"onerror",
"=",
"_onError",
";",
"}",
")",
";",
"}"
] |
Connect to the remote debugger WebSocket at the given URL.
Clients must listen for the `connect` event.
@param {string} WebSocket URL
|
[
"Connect",
"to",
"the",
"remote",
"debugger",
"WebSocket",
"at",
"the",
"given",
"URL",
".",
"Clients",
"must",
"listen",
"for",
"the",
"connect",
"event",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L308-L316
|
train
|
adobe/brackets
|
src/LiveDevelopment/Inspector/Inspector.js
|
connectToURL
|
function connectToURL(url) {
if (_connectDeferred) {
// reject an existing connection attempt
_connectDeferred.reject("CANCEL");
}
var deferred = new $.Deferred();
_connectDeferred = deferred;
var promise = getDebuggableWindows();
promise.done(function onGetAvailableSockets(response) {
var i, page;
for (i in response) {
page = response[i];
if (page.webSocketDebuggerUrl && page.url.indexOf(url) === 0) {
connect(page.webSocketDebuggerUrl);
// _connectDeferred may be resolved by onConnect or rejected by onError
return;
}
}
deferred.reject(FileError.ERR_NOT_FOUND); // Reject with a "not found" error
});
promise.fail(function onFail(err) {
deferred.reject(err);
});
return deferred.promise();
}
|
javascript
|
function connectToURL(url) {
if (_connectDeferred) {
// reject an existing connection attempt
_connectDeferred.reject("CANCEL");
}
var deferred = new $.Deferred();
_connectDeferred = deferred;
var promise = getDebuggableWindows();
promise.done(function onGetAvailableSockets(response) {
var i, page;
for (i in response) {
page = response[i];
if (page.webSocketDebuggerUrl && page.url.indexOf(url) === 0) {
connect(page.webSocketDebuggerUrl);
// _connectDeferred may be resolved by onConnect or rejected by onError
return;
}
}
deferred.reject(FileError.ERR_NOT_FOUND); // Reject with a "not found" error
});
promise.fail(function onFail(err) {
deferred.reject(err);
});
return deferred.promise();
}
|
[
"function",
"connectToURL",
"(",
"url",
")",
"{",
"if",
"(",
"_connectDeferred",
")",
"{",
"_connectDeferred",
".",
"reject",
"(",
"\"CANCEL\"",
")",
";",
"}",
"var",
"deferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"_connectDeferred",
"=",
"deferred",
";",
"var",
"promise",
"=",
"getDebuggableWindows",
"(",
")",
";",
"promise",
".",
"done",
"(",
"function",
"onGetAvailableSockets",
"(",
"response",
")",
"{",
"var",
"i",
",",
"page",
";",
"for",
"(",
"i",
"in",
"response",
")",
"{",
"page",
"=",
"response",
"[",
"i",
"]",
";",
"if",
"(",
"page",
".",
"webSocketDebuggerUrl",
"&&",
"page",
".",
"url",
".",
"indexOf",
"(",
"url",
")",
"===",
"0",
")",
"{",
"connect",
"(",
"page",
".",
"webSocketDebuggerUrl",
")",
";",
"return",
";",
"}",
"}",
"deferred",
".",
"reject",
"(",
"FileError",
".",
"ERR_NOT_FOUND",
")",
";",
"}",
")",
";",
"promise",
".",
"fail",
"(",
"function",
"onFail",
"(",
"err",
")",
"{",
"deferred",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
"(",
")",
";",
"}"
] |
Connect to the remote debugger of the page that is at the given URL
@param {string} url
|
[
"Connect",
"to",
"the",
"remote",
"debugger",
"of",
"the",
"page",
"that",
"is",
"at",
"the",
"given",
"URL"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/LiveDevelopment/Inspector/Inspector.js#L321-L345
|
train
|
adobe/brackets
|
src/widgets/StatusBar.js
|
showBusyIndicator
|
function showBusyIndicator(updateCursor) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if (updateCursor) {
_busyCursor = true;
$("*").addClass("busyCursor");
}
$busyIndicator.addClass("spin");
}
|
javascript
|
function showBusyIndicator(updateCursor) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
if (updateCursor) {
_busyCursor = true;
$("*").addClass("busyCursor");
}
$busyIndicator.addClass("spin");
}
|
[
"function",
"showBusyIndicator",
"(",
"updateCursor",
")",
"{",
"if",
"(",
"!",
"_init",
")",
"{",
"console",
".",
"error",
"(",
"\"StatusBar API invoked before status bar created\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"updateCursor",
")",
"{",
"_busyCursor",
"=",
"true",
";",
"$",
"(",
"\"*\"",
")",
".",
"addClass",
"(",
"\"busyCursor\"",
")",
";",
"}",
"$busyIndicator",
".",
"addClass",
"(",
"\"spin\"",
")",
";",
"}"
] |
Shows the 'busy' indicator
@param {boolean} updateCursor Sets the cursor to "wait"
|
[
"Shows",
"the",
"busy",
"indicator"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/StatusBar.js#L58-L70
|
train
|
adobe/brackets
|
src/widgets/StatusBar.js
|
addIndicator
|
function addIndicator(id, indicator, visible, style, tooltip, insertBefore) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
indicator = indicator || window.document.createElement("div");
tooltip = tooltip || "";
style = style || "";
id = id.replace(_indicatorIDRegexp, "-") || "";
var $indicator = $(indicator);
$indicator.attr("id", id);
$indicator.attr("title", tooltip);
$indicator.addClass("indicator");
$indicator.addClass(style);
if (!visible) {
$indicator.hide();
}
// This code looks backwards because the DOM model is ordered
// top-to-bottom but the UI view is ordered right-to-left. The concept
// of "before" in the model is "after" in the view, and vice versa.
if (insertBefore && $("#" + insertBefore).length > 0) {
$indicator.insertAfter("#" + insertBefore);
} else {
// No positioning is provided, put on left end of indicators, but
// to right of "busy" indicator (which is usually hidden).
var $busyIndicator = $("#status-bar .spinner");
$indicator.insertBefore($busyIndicator);
}
}
|
javascript
|
function addIndicator(id, indicator, visible, style, tooltip, insertBefore) {
if (!_init) {
console.error("StatusBar API invoked before status bar created");
return;
}
indicator = indicator || window.document.createElement("div");
tooltip = tooltip || "";
style = style || "";
id = id.replace(_indicatorIDRegexp, "-") || "";
var $indicator = $(indicator);
$indicator.attr("id", id);
$indicator.attr("title", tooltip);
$indicator.addClass("indicator");
$indicator.addClass(style);
if (!visible) {
$indicator.hide();
}
// This code looks backwards because the DOM model is ordered
// top-to-bottom but the UI view is ordered right-to-left. The concept
// of "before" in the model is "after" in the view, and vice versa.
if (insertBefore && $("#" + insertBefore).length > 0) {
$indicator.insertAfter("#" + insertBefore);
} else {
// No positioning is provided, put on left end of indicators, but
// to right of "busy" indicator (which is usually hidden).
var $busyIndicator = $("#status-bar .spinner");
$indicator.insertBefore($busyIndicator);
}
}
|
[
"function",
"addIndicator",
"(",
"id",
",",
"indicator",
",",
"visible",
",",
"style",
",",
"tooltip",
",",
"insertBefore",
")",
"{",
"if",
"(",
"!",
"_init",
")",
"{",
"console",
".",
"error",
"(",
"\"StatusBar API invoked before status bar created\"",
")",
";",
"return",
";",
"}",
"indicator",
"=",
"indicator",
"||",
"window",
".",
"document",
".",
"createElement",
"(",
"\"div\"",
")",
";",
"tooltip",
"=",
"tooltip",
"||",
"\"\"",
";",
"style",
"=",
"style",
"||",
"\"\"",
";",
"id",
"=",
"id",
".",
"replace",
"(",
"_indicatorIDRegexp",
",",
"\"-\"",
")",
"||",
"\"\"",
";",
"var",
"$indicator",
"=",
"$",
"(",
"indicator",
")",
";",
"$indicator",
".",
"attr",
"(",
"\"id\"",
",",
"id",
")",
";",
"$indicator",
".",
"attr",
"(",
"\"title\"",
",",
"tooltip",
")",
";",
"$indicator",
".",
"addClass",
"(",
"\"indicator\"",
")",
";",
"$indicator",
".",
"addClass",
"(",
"style",
")",
";",
"if",
"(",
"!",
"visible",
")",
"{",
"$indicator",
".",
"hide",
"(",
")",
";",
"}",
"if",
"(",
"insertBefore",
"&&",
"$",
"(",
"\"#\"",
"+",
"insertBefore",
")",
".",
"length",
">",
"0",
")",
"{",
"$indicator",
".",
"insertAfter",
"(",
"\"#\"",
"+",
"insertBefore",
")",
";",
"}",
"else",
"{",
"var",
"$busyIndicator",
"=",
"$",
"(",
"\"#status-bar .spinner\"",
")",
";",
"$indicator",
".",
"insertBefore",
"(",
"$busyIndicator",
")",
";",
"}",
"}"
] |
Registers a new status indicator
@param {string} id Registration id of the indicator to be updated.
@param {(DOMNode|jQueryObject)=} indicator Optional DOMNode for the indicator
@param {boolean=} visible Shows or hides the indicator over the statusbar.
@param {string=} style Sets the attribute "class" of the indicator.
@param {string=} tooltip Sets the attribute "title" of the indicator.
@param {string=} insertBefore An id of an existing status bar indicator.
The new indicator will be inserted before (i.e. to the left of)
the indicator specified by this parameter.
|
[
"Registers",
"a",
"new",
"status",
"indicator"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/StatusBar.js#L102-L135
|
train
|
adobe/brackets
|
src/widgets/StatusBar.js
|
updateIndicator
|
function updateIndicator(id, visible, style, tooltip) {
if (!_init && !!brackets.test) {
console.error("StatusBar API invoked before status bar created");
return;
}
var $indicator = $("#" + id.replace(_indicatorIDRegexp, "-"));
if ($indicator) {
if (visible) {
$indicator.show();
} else {
$indicator.hide();
}
if (style) {
$indicator.removeClass();
$indicator.addClass(style);
} else {
$indicator.removeClass();
$indicator.addClass("indicator");
}
if (tooltip) {
$indicator.attr("title", tooltip);
}
}
}
|
javascript
|
function updateIndicator(id, visible, style, tooltip) {
if (!_init && !!brackets.test) {
console.error("StatusBar API invoked before status bar created");
return;
}
var $indicator = $("#" + id.replace(_indicatorIDRegexp, "-"));
if ($indicator) {
if (visible) {
$indicator.show();
} else {
$indicator.hide();
}
if (style) {
$indicator.removeClass();
$indicator.addClass(style);
} else {
$indicator.removeClass();
$indicator.addClass("indicator");
}
if (tooltip) {
$indicator.attr("title", tooltip);
}
}
}
|
[
"function",
"updateIndicator",
"(",
"id",
",",
"visible",
",",
"style",
",",
"tooltip",
")",
"{",
"if",
"(",
"!",
"_init",
"&&",
"!",
"!",
"brackets",
".",
"test",
")",
"{",
"console",
".",
"error",
"(",
"\"StatusBar API invoked before status bar created\"",
")",
";",
"return",
";",
"}",
"var",
"$indicator",
"=",
"$",
"(",
"\"#\"",
"+",
"id",
".",
"replace",
"(",
"_indicatorIDRegexp",
",",
"\"-\"",
")",
")",
";",
"if",
"(",
"$indicator",
")",
"{",
"if",
"(",
"visible",
")",
"{",
"$indicator",
".",
"show",
"(",
")",
";",
"}",
"else",
"{",
"$indicator",
".",
"hide",
"(",
")",
";",
"}",
"if",
"(",
"style",
")",
"{",
"$indicator",
".",
"removeClass",
"(",
")",
";",
"$indicator",
".",
"addClass",
"(",
"style",
")",
";",
"}",
"else",
"{",
"$indicator",
".",
"removeClass",
"(",
")",
";",
"$indicator",
".",
"addClass",
"(",
"\"indicator\"",
")",
";",
"}",
"if",
"(",
"tooltip",
")",
"{",
"$indicator",
".",
"attr",
"(",
"\"title\"",
",",
"tooltip",
")",
";",
"}",
"}",
"}"
] |
Updates a status indicator
@param {string} id Registration id of the indicator to be updated.
@param {boolean} visible Shows or hides the indicator over the statusbar.
@param {string=} style Sets the attribute "class" of the indicator.
@param {string=} tooltip Sets the attribute "title" of the indicator.
|
[
"Updates",
"a",
"status",
"indicator"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/widgets/StatusBar.js#L144-L172
|
train
|
adobe/brackets
|
src/view/ThemeView.js
|
updateScrollbars
|
function updateScrollbars(theme) {
theme = theme || {};
if (prefs.get("themeScrollbars")) {
var scrollbar = (theme.scrollbar || []).join(" ");
$scrollbars.text(scrollbar || "");
} else {
$scrollbars.text("");
}
}
|
javascript
|
function updateScrollbars(theme) {
theme = theme || {};
if (prefs.get("themeScrollbars")) {
var scrollbar = (theme.scrollbar || []).join(" ");
$scrollbars.text(scrollbar || "");
} else {
$scrollbars.text("");
}
}
|
[
"function",
"updateScrollbars",
"(",
"theme",
")",
"{",
"theme",
"=",
"theme",
"||",
"{",
"}",
";",
"if",
"(",
"prefs",
".",
"get",
"(",
"\"themeScrollbars\"",
")",
")",
"{",
"var",
"scrollbar",
"=",
"(",
"theme",
".",
"scrollbar",
"||",
"[",
"]",
")",
".",
"join",
"(",
"\" \"",
")",
";",
"$scrollbars",
".",
"text",
"(",
"scrollbar",
"||",
"\"\"",
")",
";",
"}",
"else",
"{",
"$scrollbars",
".",
"text",
"(",
"\"\"",
")",
";",
"}",
"}"
] |
Load scrollbar styling based on whether or not theme scrollbars are enabled.
@param {ThemeManager.Theme} theme Is the theme object with the corresponding scrollbar style
to be updated
|
[
"Load",
"scrollbar",
"styling",
"based",
"on",
"whether",
"or",
"not",
"theme",
"scrollbars",
"are",
"enabled",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ThemeView.js#L40-L48
|
train
|
adobe/brackets
|
src/view/ThemeView.js
|
updateThemes
|
function updateThemes(cm) {
var newTheme = prefs.get("theme"),
cmTheme = (cm.getOption("theme") || "").replace(/[\s]*/, ""); // Normalize themes string
// Check if the editor already has the theme applied...
if (cmTheme === newTheme) {
return;
}
// Setup current and further documents to get the new theme...
CodeMirror.defaults.theme = newTheme;
cm.setOption("theme", newTheme);
}
|
javascript
|
function updateThemes(cm) {
var newTheme = prefs.get("theme"),
cmTheme = (cm.getOption("theme") || "").replace(/[\s]*/, ""); // Normalize themes string
// Check if the editor already has the theme applied...
if (cmTheme === newTheme) {
return;
}
// Setup current and further documents to get the new theme...
CodeMirror.defaults.theme = newTheme;
cm.setOption("theme", newTheme);
}
|
[
"function",
"updateThemes",
"(",
"cm",
")",
"{",
"var",
"newTheme",
"=",
"prefs",
".",
"get",
"(",
"\"theme\"",
")",
",",
"cmTheme",
"=",
"(",
"cm",
".",
"getOption",
"(",
"\"theme\"",
")",
"||",
"\"\"",
")",
".",
"replace",
"(",
"/",
"[\\s]*",
"/",
",",
"\"\"",
")",
";",
"if",
"(",
"cmTheme",
"===",
"newTheme",
")",
"{",
"return",
";",
"}",
"CodeMirror",
".",
"defaults",
".",
"theme",
"=",
"newTheme",
";",
"cm",
".",
"setOption",
"(",
"\"theme\"",
",",
"newTheme",
")",
";",
"}"
] |
Handles updating codemirror with the current selection of themes.
@param {CodeMirror} cm is the CodeMirror instance currently loaded
|
[
"Handles",
"updating",
"codemirror",
"with",
"the",
"current",
"selection",
"of",
"themes",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/view/ThemeView.js#L56-L68
|
train
|
adobe/brackets
|
src/project/ProjectManager.js
|
getSelectedItem
|
function getSelectedItem() {
// Prefer file tree context, then file tree selection, else use working set
var selectedEntry = getFileTreeContext();
if (!selectedEntry) {
selectedEntry = model.getSelected();
}
if (!selectedEntry) {
selectedEntry = MainViewManager.getCurrentlyViewedFile();
}
return selectedEntry;
}
|
javascript
|
function getSelectedItem() {
// Prefer file tree context, then file tree selection, else use working set
var selectedEntry = getFileTreeContext();
if (!selectedEntry) {
selectedEntry = model.getSelected();
}
if (!selectedEntry) {
selectedEntry = MainViewManager.getCurrentlyViewedFile();
}
return selectedEntry;
}
|
[
"function",
"getSelectedItem",
"(",
")",
"{",
"var",
"selectedEntry",
"=",
"getFileTreeContext",
"(",
")",
";",
"if",
"(",
"!",
"selectedEntry",
")",
"{",
"selectedEntry",
"=",
"model",
".",
"getSelected",
"(",
")",
";",
"}",
"if",
"(",
"!",
"selectedEntry",
")",
"{",
"selectedEntry",
"=",
"MainViewManager",
".",
"getCurrentlyViewedFile",
"(",
")",
";",
"}",
"return",
"selectedEntry",
";",
"}"
] |
Returns the File or Directory corresponding to the item selected in the sidebar panel, whether in
the file tree OR in the working set; or null if no item is selected anywhere in the sidebar.
May NOT be identical to the current Document - a folder may be selected in the sidebar, or the sidebar may not
have the current document visible in the tree & working set.
@return {?(File|Directory)}
|
[
"Returns",
"the",
"File",
"or",
"Directory",
"corresponding",
"to",
"the",
"item",
"selected",
"in",
"the",
"sidebar",
"panel",
"whether",
"in",
"the",
"file",
"tree",
"OR",
"in",
"the",
"working",
"set",
";",
"or",
"null",
"if",
"no",
"item",
"is",
"selected",
"anywhere",
"in",
"the",
"sidebar",
".",
"May",
"NOT",
"be",
"identical",
"to",
"the",
"current",
"Document",
"-",
"a",
"folder",
"may",
"be",
"selected",
"in",
"the",
"sidebar",
"or",
"the",
"sidebar",
"may",
"not",
"have",
"the",
"current",
"document",
"visible",
"in",
"the",
"tree",
"&",
"working",
"set",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L441-L451
|
train
|
adobe/brackets
|
src/project/ProjectManager.js
|
setBaseUrl
|
function setBaseUrl(projectBaseUrl) {
var context = _getProjectViewStateContext();
projectBaseUrl = model.setBaseUrl(projectBaseUrl);
PreferencesManager.setViewState("project.baseUrl", projectBaseUrl, context);
}
|
javascript
|
function setBaseUrl(projectBaseUrl) {
var context = _getProjectViewStateContext();
projectBaseUrl = model.setBaseUrl(projectBaseUrl);
PreferencesManager.setViewState("project.baseUrl", projectBaseUrl, context);
}
|
[
"function",
"setBaseUrl",
"(",
"projectBaseUrl",
")",
"{",
"var",
"context",
"=",
"_getProjectViewStateContext",
"(",
")",
";",
"projectBaseUrl",
"=",
"model",
".",
"setBaseUrl",
"(",
"projectBaseUrl",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"project.baseUrl\"",
",",
"projectBaseUrl",
",",
"context",
")",
";",
"}"
] |
Sets the encoded Base URL of the currently loaded project.
@param {String}
|
[
"Sets",
"the",
"encoded",
"Base",
"URL",
"of",
"the",
"currently",
"loaded",
"project",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L514-L520
|
train
|
adobe/brackets
|
src/project/ProjectManager.js
|
addWelcomeProjectPath
|
function addWelcomeProjectPath(path) {
var welcomeProjects = ProjectModel._addWelcomeProjectPath(path,
PreferencesManager.getViewState("welcomeProjects"));
PreferencesManager.setViewState("welcomeProjects", welcomeProjects);
}
|
javascript
|
function addWelcomeProjectPath(path) {
var welcomeProjects = ProjectModel._addWelcomeProjectPath(path,
PreferencesManager.getViewState("welcomeProjects"));
PreferencesManager.setViewState("welcomeProjects", welcomeProjects);
}
|
[
"function",
"addWelcomeProjectPath",
"(",
"path",
")",
"{",
"var",
"welcomeProjects",
"=",
"ProjectModel",
".",
"_addWelcomeProjectPath",
"(",
"path",
",",
"PreferencesManager",
".",
"getViewState",
"(",
"\"welcomeProjects\"",
")",
")",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"welcomeProjects\"",
",",
"welcomeProjects",
")",
";",
"}"
] |
Adds the path to the list of welcome projects we've ever seen, if not on the list already.
@param {string} path Path to possibly add
|
[
"Adds",
"the",
"path",
"to",
"the",
"list",
"of",
"welcome",
"projects",
"we",
"ve",
"ever",
"seen",
"if",
"not",
"on",
"the",
"list",
"already",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L700-L704
|
train
|
adobe/brackets
|
src/project/ProjectManager.js
|
_getFallbackProjectPath
|
function _getFallbackProjectPath() {
var fallbackPaths = [],
recentProjects = PreferencesManager.getViewState("recentProjects") || [],
deferred = new $.Deferred();
// Build ordered fallback path array
if (recentProjects.length > 1) {
// *Most* recent project is the one that just failed to load, so use second most recent
fallbackPaths.push(recentProjects[1]);
}
// Next is Getting Started project
fallbackPaths.push(_getWelcomeProjectPath());
// Helper func for Async.firstSequentially()
function processItem(path) {
var deferred = new $.Deferred(),
fileEntry = FileSystem.getDirectoryForPath(path);
fileEntry.exists(function (err, exists) {
if (!err && exists) {
deferred.resolve();
} else {
deferred.reject();
}
});
return deferred.promise();
}
// Find first path that exists
Async.firstSequentially(fallbackPaths, processItem)
.done(function (fallbackPath) {
deferred.resolve(fallbackPath);
})
.fail(function () {
// Last resort is Brackets source folder which is guaranteed to exist
deferred.resolve(FileUtils.getNativeBracketsDirectoryPath());
});
return deferred.promise();
}
|
javascript
|
function _getFallbackProjectPath() {
var fallbackPaths = [],
recentProjects = PreferencesManager.getViewState("recentProjects") || [],
deferred = new $.Deferred();
// Build ordered fallback path array
if (recentProjects.length > 1) {
// *Most* recent project is the one that just failed to load, so use second most recent
fallbackPaths.push(recentProjects[1]);
}
// Next is Getting Started project
fallbackPaths.push(_getWelcomeProjectPath());
// Helper func for Async.firstSequentially()
function processItem(path) {
var deferred = new $.Deferred(),
fileEntry = FileSystem.getDirectoryForPath(path);
fileEntry.exists(function (err, exists) {
if (!err && exists) {
deferred.resolve();
} else {
deferred.reject();
}
});
return deferred.promise();
}
// Find first path that exists
Async.firstSequentially(fallbackPaths, processItem)
.done(function (fallbackPath) {
deferred.resolve(fallbackPath);
})
.fail(function () {
// Last resort is Brackets source folder which is guaranteed to exist
deferred.resolve(FileUtils.getNativeBracketsDirectoryPath());
});
return deferred.promise();
}
|
[
"function",
"_getFallbackProjectPath",
"(",
")",
"{",
"var",
"fallbackPaths",
"=",
"[",
"]",
",",
"recentProjects",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"recentProjects\"",
")",
"||",
"[",
"]",
",",
"deferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"if",
"(",
"recentProjects",
".",
"length",
">",
"1",
")",
"{",
"fallbackPaths",
".",
"push",
"(",
"recentProjects",
"[",
"1",
"]",
")",
";",
"}",
"fallbackPaths",
".",
"push",
"(",
"_getWelcomeProjectPath",
"(",
")",
")",
";",
"function",
"processItem",
"(",
"path",
")",
"{",
"var",
"deferred",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
",",
"fileEntry",
"=",
"FileSystem",
".",
"getDirectoryForPath",
"(",
"path",
")",
";",
"fileEntry",
".",
"exists",
"(",
"function",
"(",
"err",
",",
"exists",
")",
"{",
"if",
"(",
"!",
"err",
"&&",
"exists",
")",
"{",
"deferred",
".",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
"(",
")",
";",
"}",
"Async",
".",
"firstSequentially",
"(",
"fallbackPaths",
",",
"processItem",
")",
".",
"done",
"(",
"function",
"(",
"fallbackPath",
")",
"{",
"deferred",
".",
"resolve",
"(",
"fallbackPath",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"deferred",
".",
"resolve",
"(",
"FileUtils",
".",
"getNativeBracketsDirectoryPath",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
"(",
")",
";",
"}"
] |
After failing to load a project, this function determines which project path to fallback to.
@return {$.Promise} Promise that resolves to a project path {string}
|
[
"After",
"failing",
"to",
"load",
"a",
"project",
"this",
"function",
"determines",
"which",
"project",
"path",
"to",
"fallback",
"to",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L733-L774
|
train
|
adobe/brackets
|
src/project/ProjectManager.js
|
openProject
|
function openProject(path) {
var result = new $.Deferred();
// Confirm any unsaved changes first. We run the command in "prompt-only" mode, meaning it won't
// actually close any documents even on success; we'll do that manually after the user also oks
// the folder-browse dialog.
CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true })
.done(function () {
if (path) {
// use specified path
_loadProject(path, false).then(result.resolve, result.reject);
} else {
// Pop up a folder browse dialog
FileSystem.showOpenDialog(false, true, Strings.CHOOSE_FOLDER, model.projectRoot.fullPath, null, function (err, files) {
if (!err) {
// If length == 0, user canceled the dialog; length should never be > 1
if (files.length > 0) {
// Load the new project into the folder tree
_loadProject(files[0]).then(result.resolve, result.reject);
} else {
result.reject();
}
} else {
_showErrorDialog(ERR_TYPE_OPEN_DIALOG, null, err);
result.reject();
}
});
}
})
.fail(function () {
result.reject();
});
// if fail, don't open new project: user canceled (or we failed to save its unsaved changes)
return result.promise();
}
|
javascript
|
function openProject(path) {
var result = new $.Deferred();
// Confirm any unsaved changes first. We run the command in "prompt-only" mode, meaning it won't
// actually close any documents even on success; we'll do that manually after the user also oks
// the folder-browse dialog.
CommandManager.execute(Commands.FILE_CLOSE_ALL, { promptOnly: true })
.done(function () {
if (path) {
// use specified path
_loadProject(path, false).then(result.resolve, result.reject);
} else {
// Pop up a folder browse dialog
FileSystem.showOpenDialog(false, true, Strings.CHOOSE_FOLDER, model.projectRoot.fullPath, null, function (err, files) {
if (!err) {
// If length == 0, user canceled the dialog; length should never be > 1
if (files.length > 0) {
// Load the new project into the folder tree
_loadProject(files[0]).then(result.resolve, result.reject);
} else {
result.reject();
}
} else {
_showErrorDialog(ERR_TYPE_OPEN_DIALOG, null, err);
result.reject();
}
});
}
})
.fail(function () {
result.reject();
});
// if fail, don't open new project: user canceled (or we failed to save its unsaved changes)
return result.promise();
}
|
[
"function",
"openProject",
"(",
"path",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"CommandManager",
".",
"execute",
"(",
"Commands",
".",
"FILE_CLOSE_ALL",
",",
"{",
"promptOnly",
":",
"true",
"}",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"path",
")",
"{",
"_loadProject",
"(",
"path",
",",
"false",
")",
".",
"then",
"(",
"result",
".",
"resolve",
",",
"result",
".",
"reject",
")",
";",
"}",
"else",
"{",
"FileSystem",
".",
"showOpenDialog",
"(",
"false",
",",
"true",
",",
"Strings",
".",
"CHOOSE_FOLDER",
",",
"model",
".",
"projectRoot",
".",
"fullPath",
",",
"null",
",",
"function",
"(",
"err",
",",
"files",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"if",
"(",
"files",
".",
"length",
">",
"0",
")",
"{",
"_loadProject",
"(",
"files",
"[",
"0",
"]",
")",
".",
"then",
"(",
"result",
".",
"resolve",
",",
"result",
".",
"reject",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
"else",
"{",
"_showErrorDialog",
"(",
"ERR_TYPE_OPEN_DIALOG",
",",
"null",
",",
"err",
")",
";",
"result",
".",
"reject",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
")",
".",
"fail",
"(",
"function",
"(",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Open a new project. Currently, Brackets must always have a project open, so
this method handles both closing the current project and opening a new project.
@param {string=} path Optional absolute path to the root folder of the project.
If path is undefined or null, displays a dialog where the user can choose a
folder to load. If the user cancels the dialog, nothing more happens.
@return {$.Promise} A promise object that will be resolved when the
project is loaded and tree is rendered, or rejected if the project path
fails to load.
|
[
"Open",
"a",
"new",
"project",
".",
"Currently",
"Brackets",
"must",
"always",
"have",
"a",
"project",
"open",
"so",
"this",
"method",
"handles",
"both",
"closing",
"the",
"current",
"project",
"and",
"opening",
"a",
"new",
"project",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L1056-L1092
|
train
|
adobe/brackets
|
src/project/ProjectManager.js
|
createNewItem
|
function createNewItem(baseDir, initialName, skipRename, isFolder) {
baseDir = model.getDirectoryInProject(baseDir);
if (skipRename) {
if(isFolder) {
return model.createAtPath(baseDir + initialName + "/");
}
return model.createAtPath(baseDir + initialName);
}
return actionCreator.startCreating(baseDir, initialName, isFolder);
}
|
javascript
|
function createNewItem(baseDir, initialName, skipRename, isFolder) {
baseDir = model.getDirectoryInProject(baseDir);
if (skipRename) {
if(isFolder) {
return model.createAtPath(baseDir + initialName + "/");
}
return model.createAtPath(baseDir + initialName);
}
return actionCreator.startCreating(baseDir, initialName, isFolder);
}
|
[
"function",
"createNewItem",
"(",
"baseDir",
",",
"initialName",
",",
"skipRename",
",",
"isFolder",
")",
"{",
"baseDir",
"=",
"model",
".",
"getDirectoryInProject",
"(",
"baseDir",
")",
";",
"if",
"(",
"skipRename",
")",
"{",
"if",
"(",
"isFolder",
")",
"{",
"return",
"model",
".",
"createAtPath",
"(",
"baseDir",
"+",
"initialName",
"+",
"\"/\"",
")",
";",
"}",
"return",
"model",
".",
"createAtPath",
"(",
"baseDir",
"+",
"initialName",
")",
";",
"}",
"return",
"actionCreator",
".",
"startCreating",
"(",
"baseDir",
",",
"initialName",
",",
"isFolder",
")",
";",
"}"
] |
Create a new item in the current project.
@param baseDir {string|Directory} Full path of the directory where the item should go.
Defaults to the project root if the entry is not valid or not within the project.
@param initialName {string} Initial name for the item
@param skipRename {boolean} If true, don't allow the user to rename the item
@param isFolder {boolean} If true, create a folder instead of a file
@return {$.Promise} A promise object that will be resolved with the File
of the created object, or rejected if the user cancelled or entered an illegal
filename.
|
[
"Create",
"a",
"new",
"item",
"in",
"the",
"current",
"project",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L1114-L1124
|
train
|
adobe/brackets
|
src/project/ProjectManager.js
|
deleteItem
|
function deleteItem(entry) {
var result = new $.Deferred();
entry.moveToTrash(function (err) {
if (!err) {
DocumentManager.notifyPathDeleted(entry.fullPath);
result.resolve();
} else {
_showErrorDialog(ERR_TYPE_DELETE, entry.isDirectory, FileUtils.getFileErrorString(err), entry.fullPath);
result.reject(err);
}
});
return result.promise();
}
|
javascript
|
function deleteItem(entry) {
var result = new $.Deferred();
entry.moveToTrash(function (err) {
if (!err) {
DocumentManager.notifyPathDeleted(entry.fullPath);
result.resolve();
} else {
_showErrorDialog(ERR_TYPE_DELETE, entry.isDirectory, FileUtils.getFileErrorString(err), entry.fullPath);
result.reject(err);
}
});
return result.promise();
}
|
[
"function",
"deleteItem",
"(",
"entry",
")",
"{",
"var",
"result",
"=",
"new",
"$",
".",
"Deferred",
"(",
")",
";",
"entry",
".",
"moveToTrash",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"DocumentManager",
".",
"notifyPathDeleted",
"(",
"entry",
".",
"fullPath",
")",
";",
"result",
".",
"resolve",
"(",
")",
";",
"}",
"else",
"{",
"_showErrorDialog",
"(",
"ERR_TYPE_DELETE",
",",
"entry",
".",
"isDirectory",
",",
"FileUtils",
".",
"getFileErrorString",
"(",
"err",
")",
",",
"entry",
".",
"fullPath",
")",
";",
"result",
".",
"reject",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Delete file or directore from project
@param {!(File|Directory)} entry File or Directory to delete
|
[
"Delete",
"file",
"or",
"directore",
"from",
"project"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/project/ProjectManager.js#L1130-L1145
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_formatCountable
|
function _formatCountable(number, singularStr, pluralStr) {
return StringUtils.format(number > 1 ? pluralStr : singularStr, number);
}
|
javascript
|
function _formatCountable(number, singularStr, pluralStr) {
return StringUtils.format(number > 1 ? pluralStr : singularStr, number);
}
|
[
"function",
"_formatCountable",
"(",
"number",
",",
"singularStr",
",",
"pluralStr",
")",
"{",
"return",
"StringUtils",
".",
"format",
"(",
"number",
">",
"1",
"?",
"pluralStr",
":",
"singularStr",
",",
"number",
")",
";",
"}"
] |
Determine string based on count
@param {number} number Count
@param {string} singularStr Singular string
@param {string} pluralStr Plural string
@return {string} Proper string to use for count
|
[
"Determine",
"string",
"based",
"on",
"count"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L80-L82
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_updateLanguageInfo
|
function _updateLanguageInfo(editor) {
var doc = editor.document,
lang = doc.getLanguage();
// Show the current language as button title
languageSelect.$button.text(lang.getName());
}
|
javascript
|
function _updateLanguageInfo(editor) {
var doc = editor.document,
lang = doc.getLanguage();
// Show the current language as button title
languageSelect.$button.text(lang.getName());
}
|
[
"function",
"_updateLanguageInfo",
"(",
"editor",
")",
"{",
"var",
"doc",
"=",
"editor",
".",
"document",
",",
"lang",
"=",
"doc",
".",
"getLanguage",
"(",
")",
";",
"languageSelect",
".",
"$button",
".",
"text",
"(",
"lang",
".",
"getName",
"(",
")",
")",
";",
"}"
] |
Update file mode
@param {Editor} editor Current editor
|
[
"Update",
"file",
"mode"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L88-L94
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_updateFileInfo
|
function _updateFileInfo(editor) {
var lines = editor.lineCount();
$fileInfo.text(_formatCountable(lines, Strings.STATUSBAR_LINE_COUNT_SINGULAR, Strings.STATUSBAR_LINE_COUNT_PLURAL));
}
|
javascript
|
function _updateFileInfo(editor) {
var lines = editor.lineCount();
$fileInfo.text(_formatCountable(lines, Strings.STATUSBAR_LINE_COUNT_SINGULAR, Strings.STATUSBAR_LINE_COUNT_PLURAL));
}
|
[
"function",
"_updateFileInfo",
"(",
"editor",
")",
"{",
"var",
"lines",
"=",
"editor",
".",
"lineCount",
"(",
")",
";",
"$fileInfo",
".",
"text",
"(",
"_formatCountable",
"(",
"lines",
",",
"Strings",
".",
"STATUSBAR_LINE_COUNT_SINGULAR",
",",
"Strings",
".",
"STATUSBAR_LINE_COUNT_PLURAL",
")",
")",
";",
"}"
] |
Update file information
@param {Editor} editor Current editor
|
[
"Update",
"file",
"information"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L114-L117
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_updateIndentType
|
function _updateIndentType(fullPath) {
var indentWithTabs = Editor.getUseTabChar(fullPath);
$indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES);
$indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS);
$indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES);
}
|
javascript
|
function _updateIndentType(fullPath) {
var indentWithTabs = Editor.getUseTabChar(fullPath);
$indentType.text(indentWithTabs ? Strings.STATUSBAR_TAB_SIZE : Strings.STATUSBAR_SPACES);
$indentType.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_TOOLTIP_SPACES : Strings.STATUSBAR_INDENT_TOOLTIP_TABS);
$indentWidthLabel.attr("title", indentWithTabs ? Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_TABS : Strings.STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES);
}
|
[
"function",
"_updateIndentType",
"(",
"fullPath",
")",
"{",
"var",
"indentWithTabs",
"=",
"Editor",
".",
"getUseTabChar",
"(",
"fullPath",
")",
";",
"$indentType",
".",
"text",
"(",
"indentWithTabs",
"?",
"Strings",
".",
"STATUSBAR_TAB_SIZE",
":",
"Strings",
".",
"STATUSBAR_SPACES",
")",
";",
"$indentType",
".",
"attr",
"(",
"\"title\"",
",",
"indentWithTabs",
"?",
"Strings",
".",
"STATUSBAR_INDENT_TOOLTIP_SPACES",
":",
"Strings",
".",
"STATUSBAR_INDENT_TOOLTIP_TABS",
")",
";",
"$indentWidthLabel",
".",
"attr",
"(",
"\"title\"",
",",
"indentWithTabs",
"?",
"Strings",
".",
"STATUSBAR_INDENT_SIZE_TOOLTIP_TABS",
":",
"Strings",
".",
"STATUSBAR_INDENT_SIZE_TOOLTIP_SPACES",
")",
";",
"}"
] |
Update indent type and size
@param {string} fullPath Path to file in current editor
|
[
"Update",
"indent",
"type",
"and",
"size"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L123-L128
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_toggleIndentType
|
function _toggleIndentType() {
var current = EditorManager.getActiveEditor(),
fullPath = current && current.document.file.fullPath;
Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath);
_updateIndentType(fullPath);
_updateIndentSize(fullPath);
}
|
javascript
|
function _toggleIndentType() {
var current = EditorManager.getActiveEditor(),
fullPath = current && current.document.file.fullPath;
Editor.setUseTabChar(!Editor.getUseTabChar(fullPath), fullPath);
_updateIndentType(fullPath);
_updateIndentSize(fullPath);
}
|
[
"function",
"_toggleIndentType",
"(",
")",
"{",
"var",
"current",
"=",
"EditorManager",
".",
"getActiveEditor",
"(",
")",
",",
"fullPath",
"=",
"current",
"&&",
"current",
".",
"document",
".",
"file",
".",
"fullPath",
";",
"Editor",
".",
"setUseTabChar",
"(",
"!",
"Editor",
".",
"getUseTabChar",
"(",
"fullPath",
")",
",",
"fullPath",
")",
";",
"_updateIndentType",
"(",
"fullPath",
")",
";",
"_updateIndentSize",
"(",
"fullPath",
")",
";",
"}"
] |
Toggle indent type
|
[
"Toggle",
"indent",
"type"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L152-L159
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_changeIndentWidth
|
function _changeIndentWidth(fullPath, value) {
$indentWidthLabel.removeClass("hidden");
$indentWidthInput.addClass("hidden");
// remove all event handlers from the input field
$indentWidthInput.off("blur keyup");
// restore focus to the editor
MainViewManager.focusActivePane();
var valInt = parseInt(value, 10);
if (Editor.getUseTabChar(fullPath)) {
if (!Editor.setTabSize(valInt, fullPath)) {
return; // validation failed
}
} else {
if (!Editor.setSpaceUnits(valInt, fullPath)) {
return; // validation failed
}
}
// update indicator
_updateIndentSize(fullPath);
// column position may change when tab size changes
_updateCursorInfo();
}
|
javascript
|
function _changeIndentWidth(fullPath, value) {
$indentWidthLabel.removeClass("hidden");
$indentWidthInput.addClass("hidden");
// remove all event handlers from the input field
$indentWidthInput.off("blur keyup");
// restore focus to the editor
MainViewManager.focusActivePane();
var valInt = parseInt(value, 10);
if (Editor.getUseTabChar(fullPath)) {
if (!Editor.setTabSize(valInt, fullPath)) {
return; // validation failed
}
} else {
if (!Editor.setSpaceUnits(valInt, fullPath)) {
return; // validation failed
}
}
// update indicator
_updateIndentSize(fullPath);
// column position may change when tab size changes
_updateCursorInfo();
}
|
[
"function",
"_changeIndentWidth",
"(",
"fullPath",
",",
"value",
")",
"{",
"$indentWidthLabel",
".",
"removeClass",
"(",
"\"hidden\"",
")",
";",
"$indentWidthInput",
".",
"addClass",
"(",
"\"hidden\"",
")",
";",
"$indentWidthInput",
".",
"off",
"(",
"\"blur keyup\"",
")",
";",
"MainViewManager",
".",
"focusActivePane",
"(",
")",
";",
"var",
"valInt",
"=",
"parseInt",
"(",
"value",
",",
"10",
")",
";",
"if",
"(",
"Editor",
".",
"getUseTabChar",
"(",
"fullPath",
")",
")",
"{",
"if",
"(",
"!",
"Editor",
".",
"setTabSize",
"(",
"valInt",
",",
"fullPath",
")",
")",
"{",
"return",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"Editor",
".",
"setSpaceUnits",
"(",
"valInt",
",",
"fullPath",
")",
")",
"{",
"return",
";",
"}",
"}",
"_updateIndentSize",
"(",
"fullPath",
")",
";",
"_updateCursorInfo",
"(",
")",
";",
"}"
] |
Change indent size
@param {string} fullPath Path to file in current editor
@param {string} value Size entered into status bar
|
[
"Change",
"indent",
"size"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L207-L233
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_onActiveEditorChange
|
function _onActiveEditorChange(event, current, previous) {
if (previous) {
previous.off(".statusbar");
previous.document.off(".statusbar");
previous.document.releaseRef();
}
if (!current) {
StatusBar.hideAllPanes();
} else {
var fullPath = current.document.file.fullPath;
StatusBar.showAllPanes();
current.on("cursorActivity.statusbar", _updateCursorInfo);
current.on("optionChange.statusbar", function () {
_updateIndentType(fullPath);
_updateIndentSize(fullPath);
});
current.on("change.statusbar", function () {
// async update to keep typing speed smooth
window.setTimeout(function () { _updateFileInfo(current); }, 0);
});
current.on("overwriteToggle.statusbar", _updateOverwriteLabel);
current.document.addRef();
current.document.on("languageChanged.statusbar", function () {
_updateLanguageInfo(current);
});
_updateCursorInfo(null, current);
_updateLanguageInfo(current);
_updateEncodingInfo(current);
_updateFileInfo(current);
_initOverwriteMode(current);
_updateIndentType(fullPath);
_updateIndentSize(fullPath);
}
}
|
javascript
|
function _onActiveEditorChange(event, current, previous) {
if (previous) {
previous.off(".statusbar");
previous.document.off(".statusbar");
previous.document.releaseRef();
}
if (!current) {
StatusBar.hideAllPanes();
} else {
var fullPath = current.document.file.fullPath;
StatusBar.showAllPanes();
current.on("cursorActivity.statusbar", _updateCursorInfo);
current.on("optionChange.statusbar", function () {
_updateIndentType(fullPath);
_updateIndentSize(fullPath);
});
current.on("change.statusbar", function () {
// async update to keep typing speed smooth
window.setTimeout(function () { _updateFileInfo(current); }, 0);
});
current.on("overwriteToggle.statusbar", _updateOverwriteLabel);
current.document.addRef();
current.document.on("languageChanged.statusbar", function () {
_updateLanguageInfo(current);
});
_updateCursorInfo(null, current);
_updateLanguageInfo(current);
_updateEncodingInfo(current);
_updateFileInfo(current);
_initOverwriteMode(current);
_updateIndentType(fullPath);
_updateIndentSize(fullPath);
}
}
|
[
"function",
"_onActiveEditorChange",
"(",
"event",
",",
"current",
",",
"previous",
")",
"{",
"if",
"(",
"previous",
")",
"{",
"previous",
".",
"off",
"(",
"\".statusbar\"",
")",
";",
"previous",
".",
"document",
".",
"off",
"(",
"\".statusbar\"",
")",
";",
"previous",
".",
"document",
".",
"releaseRef",
"(",
")",
";",
"}",
"if",
"(",
"!",
"current",
")",
"{",
"StatusBar",
".",
"hideAllPanes",
"(",
")",
";",
"}",
"else",
"{",
"var",
"fullPath",
"=",
"current",
".",
"document",
".",
"file",
".",
"fullPath",
";",
"StatusBar",
".",
"showAllPanes",
"(",
")",
";",
"current",
".",
"on",
"(",
"\"cursorActivity.statusbar\"",
",",
"_updateCursorInfo",
")",
";",
"current",
".",
"on",
"(",
"\"optionChange.statusbar\"",
",",
"function",
"(",
")",
"{",
"_updateIndentType",
"(",
"fullPath",
")",
";",
"_updateIndentSize",
"(",
"fullPath",
")",
";",
"}",
")",
";",
"current",
".",
"on",
"(",
"\"change.statusbar\"",
",",
"function",
"(",
")",
"{",
"window",
".",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"_updateFileInfo",
"(",
"current",
")",
";",
"}",
",",
"0",
")",
";",
"}",
")",
";",
"current",
".",
"on",
"(",
"\"overwriteToggle.statusbar\"",
",",
"_updateOverwriteLabel",
")",
";",
"current",
".",
"document",
".",
"addRef",
"(",
")",
";",
"current",
".",
"document",
".",
"on",
"(",
"\"languageChanged.statusbar\"",
",",
"function",
"(",
")",
"{",
"_updateLanguageInfo",
"(",
"current",
")",
";",
"}",
")",
";",
"_updateCursorInfo",
"(",
"null",
",",
"current",
")",
";",
"_updateLanguageInfo",
"(",
"current",
")",
";",
"_updateEncodingInfo",
"(",
"current",
")",
";",
"_updateFileInfo",
"(",
"current",
")",
";",
"_initOverwriteMode",
"(",
"current",
")",
";",
"_updateIndentType",
"(",
"fullPath",
")",
";",
"_updateIndentSize",
"(",
"fullPath",
")",
";",
"}",
"}"
] |
Handle active editor change event
@param {Event} event (unused)
@param {Editor} current Current editor
@param {Editor} previous Previous editor
|
[
"Handle",
"active",
"editor",
"change",
"event"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L283-L320
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_populateLanguageDropdown
|
function _populateLanguageDropdown() {
// Get all non-binary languages
var languages = _.values(LanguageManager.getLanguages()).filter(function (language) {
return !language.isBinary();
});
// sort dropdown alphabetically
languages.sort(function (a, b) {
return a.getName().toLowerCase().localeCompare(b.getName().toLowerCase());
});
languageSelect.items = languages;
// Add option to top of menu for persisting the override
languageSelect.items.unshift("---");
languageSelect.items.unshift(LANGUAGE_SET_AS_DEFAULT);
}
|
javascript
|
function _populateLanguageDropdown() {
// Get all non-binary languages
var languages = _.values(LanguageManager.getLanguages()).filter(function (language) {
return !language.isBinary();
});
// sort dropdown alphabetically
languages.sort(function (a, b) {
return a.getName().toLowerCase().localeCompare(b.getName().toLowerCase());
});
languageSelect.items = languages;
// Add option to top of menu for persisting the override
languageSelect.items.unshift("---");
languageSelect.items.unshift(LANGUAGE_SET_AS_DEFAULT);
}
|
[
"function",
"_populateLanguageDropdown",
"(",
")",
"{",
"var",
"languages",
"=",
"_",
".",
"values",
"(",
"LanguageManager",
".",
"getLanguages",
"(",
")",
")",
".",
"filter",
"(",
"function",
"(",
"language",
")",
"{",
"return",
"!",
"language",
".",
"isBinary",
"(",
")",
";",
"}",
")",
";",
"languages",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"localeCompare",
"(",
"b",
".",
"getName",
"(",
")",
".",
"toLowerCase",
"(",
")",
")",
";",
"}",
")",
";",
"languageSelect",
".",
"items",
"=",
"languages",
";",
"languageSelect",
".",
"items",
".",
"unshift",
"(",
"\"---\"",
")",
";",
"languageSelect",
".",
"items",
".",
"unshift",
"(",
"LANGUAGE_SET_AS_DEFAULT",
")",
";",
"}"
] |
Populate the languageSelect DropdownButton's menu with all registered Languages
|
[
"Populate",
"the",
"languageSelect",
"DropdownButton",
"s",
"menu",
"with",
"all",
"registered",
"Languages"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L325-L341
|
train
|
adobe/brackets
|
src/editor/EditorStatusBar.js
|
_changeEncodingAndReloadDoc
|
function _changeEncodingAndReloadDoc(document) {
var promise = document.reload();
promise.done(function (text, readTimestamp) {
encodingSelect.$button.text(document.file._encoding);
// Store the preferred encoding in the state
var projectRoot = ProjectManager.getProjectRoot(),
context = {
location : {
scope: "user",
layer: "project",
layerID: projectRoot.fullPath
}
};
var encoding = PreferencesManager.getViewState("encoding", context);
encoding[document.file.fullPath] = document.file._encoding;
PreferencesManager.setViewState("encoding", encoding, context);
});
promise.fail(function (error) {
console.log("Error reloading contents of " + document.file.fullPath, error);
});
}
|
javascript
|
function _changeEncodingAndReloadDoc(document) {
var promise = document.reload();
promise.done(function (text, readTimestamp) {
encodingSelect.$button.text(document.file._encoding);
// Store the preferred encoding in the state
var projectRoot = ProjectManager.getProjectRoot(),
context = {
location : {
scope: "user",
layer: "project",
layerID: projectRoot.fullPath
}
};
var encoding = PreferencesManager.getViewState("encoding", context);
encoding[document.file.fullPath] = document.file._encoding;
PreferencesManager.setViewState("encoding", encoding, context);
});
promise.fail(function (error) {
console.log("Error reloading contents of " + document.file.fullPath, error);
});
}
|
[
"function",
"_changeEncodingAndReloadDoc",
"(",
"document",
")",
"{",
"var",
"promise",
"=",
"document",
".",
"reload",
"(",
")",
";",
"promise",
".",
"done",
"(",
"function",
"(",
"text",
",",
"readTimestamp",
")",
"{",
"encodingSelect",
".",
"$button",
".",
"text",
"(",
"document",
".",
"file",
".",
"_encoding",
")",
";",
"var",
"projectRoot",
"=",
"ProjectManager",
".",
"getProjectRoot",
"(",
")",
",",
"context",
"=",
"{",
"location",
":",
"{",
"scope",
":",
"\"user\"",
",",
"layer",
":",
"\"project\"",
",",
"layerID",
":",
"projectRoot",
".",
"fullPath",
"}",
"}",
";",
"var",
"encoding",
"=",
"PreferencesManager",
".",
"getViewState",
"(",
"\"encoding\"",
",",
"context",
")",
";",
"encoding",
"[",
"document",
".",
"file",
".",
"fullPath",
"]",
"=",
"document",
".",
"file",
".",
"_encoding",
";",
"PreferencesManager",
".",
"setViewState",
"(",
"\"encoding\"",
",",
"encoding",
",",
"context",
")",
";",
"}",
")",
";",
"promise",
".",
"fail",
"(",
"function",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"\"Error reloading contents of \"",
"+",
"document",
".",
"file",
".",
"fullPath",
",",
"error",
")",
";",
"}",
")",
";",
"}"
] |
Change the encoding and reload the current document.
If passed then save the preferred encoding in state.
|
[
"Change",
"the",
"encoding",
"and",
"reload",
"the",
"current",
"document",
".",
"If",
"passed",
"then",
"save",
"the",
"preferred",
"encoding",
"in",
"state",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/editor/EditorStatusBar.js#L347-L367
|
train
|
adobe/brackets
|
src/extensions/default/QuickOpenJavaScript/main.js
|
createFunctionList
|
function createFunctionList() {
var doc = DocumentManager.getCurrentDocument();
if (!doc) {
return;
}
var functionList = [];
var docText = doc.getText();
var lines = docText.split("\n");
var functions = JSUtils.findAllMatchingFunctionsInText(docText, "*");
functions.forEach(function (funcEntry) {
functionList.push(new FileLocation(null, funcEntry.nameLineStart, funcEntry.columnStart, funcEntry.columnEnd, funcEntry.label || funcEntry.name));
});
return functionList;
}
|
javascript
|
function createFunctionList() {
var doc = DocumentManager.getCurrentDocument();
if (!doc) {
return;
}
var functionList = [];
var docText = doc.getText();
var lines = docText.split("\n");
var functions = JSUtils.findAllMatchingFunctionsInText(docText, "*");
functions.forEach(function (funcEntry) {
functionList.push(new FileLocation(null, funcEntry.nameLineStart, funcEntry.columnStart, funcEntry.columnEnd, funcEntry.label || funcEntry.name));
});
return functionList;
}
|
[
"function",
"createFunctionList",
"(",
")",
"{",
"var",
"doc",
"=",
"DocumentManager",
".",
"getCurrentDocument",
"(",
")",
";",
"if",
"(",
"!",
"doc",
")",
"{",
"return",
";",
"}",
"var",
"functionList",
"=",
"[",
"]",
";",
"var",
"docText",
"=",
"doc",
".",
"getText",
"(",
")",
";",
"var",
"lines",
"=",
"docText",
".",
"split",
"(",
"\"\\n\"",
")",
";",
"\\n",
"var",
"functions",
"=",
"JSUtils",
".",
"findAllMatchingFunctionsInText",
"(",
"docText",
",",
"\"*\"",
")",
";",
"functions",
".",
"forEach",
"(",
"function",
"(",
"funcEntry",
")",
"{",
"functionList",
".",
"push",
"(",
"new",
"FileLocation",
"(",
"null",
",",
"funcEntry",
".",
"nameLineStart",
",",
"funcEntry",
".",
"columnStart",
",",
"funcEntry",
".",
"columnEnd",
",",
"funcEntry",
".",
"label",
"||",
"funcEntry",
".",
"name",
")",
")",
";",
"}",
")",
";",
"}"
] |
Contains a list of information about functions for a single document.
@return {?Array.<FileLocation>}
|
[
"Contains",
"a",
"list",
"of",
"information",
"about",
"functions",
"for",
"a",
"single",
"document",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/QuickOpenJavaScript/main.js#L57-L71
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
rangeEqualsSelection
|
function rangeEqualsSelection(range, selection) {
return range.from.line === selection.start.line && range.from.ch === selection.start.ch &&
range.to.line === selection.end.line && range.to.ch === selection.end.ch;
}
|
javascript
|
function rangeEqualsSelection(range, selection) {
return range.from.line === selection.start.line && range.from.ch === selection.start.ch &&
range.to.line === selection.end.line && range.to.ch === selection.end.ch;
}
|
[
"function",
"rangeEqualsSelection",
"(",
"range",
",",
"selection",
")",
"{",
"return",
"range",
".",
"from",
".",
"line",
"===",
"selection",
".",
"start",
".",
"line",
"&&",
"range",
".",
"from",
".",
"ch",
"===",
"selection",
".",
"start",
".",
"ch",
"&&",
"range",
".",
"to",
".",
"line",
"===",
"selection",
".",
"end",
".",
"line",
"&&",
"range",
".",
"to",
".",
"ch",
"===",
"selection",
".",
"end",
".",
"ch",
";",
"}"
] |
Checks if the range from and to Pos is the same as the selection start and end Pos
@param {Object} range {from, to} where from and to are CodeMirror.Pos objects
@param {Object} selection {start, end} where start and end are CodeMirror.Pos objects
@returns {Boolean} true if the range and selection span the same region and false otherwise
|
[
"Checks",
"if",
"the",
"range",
"from",
"and",
"to",
"Pos",
"is",
"the",
"same",
"as",
"the",
"selection",
"start",
"and",
"end",
"Pos"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L98-L101
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
isInViewStateSelection
|
function isInViewStateSelection(range, viewState) {
if (!viewState || !viewState.selections) {
return false;
}
return viewState.selections.some(function (selection) {
return rangeEqualsSelection(range, selection);
});
}
|
javascript
|
function isInViewStateSelection(range, viewState) {
if (!viewState || !viewState.selections) {
return false;
}
return viewState.selections.some(function (selection) {
return rangeEqualsSelection(range, selection);
});
}
|
[
"function",
"isInViewStateSelection",
"(",
"range",
",",
"viewState",
")",
"{",
"if",
"(",
"!",
"viewState",
"||",
"!",
"viewState",
".",
"selections",
")",
"{",
"return",
"false",
";",
"}",
"return",
"viewState",
".",
"selections",
".",
"some",
"(",
"function",
"(",
"selection",
")",
"{",
"return",
"rangeEqualsSelection",
"(",
"range",
",",
"selection",
")",
";",
"}",
")",
";",
"}"
] |
Checks if the range is equal to one of the selections in the viewState
@param {Object} range {from, to} where from and to are CodeMirror.Pos objects.
@param {Object} viewState The current editor's ViewState object
@returns {Boolean} true if the range is found in the list of selections or false if not.
|
[
"Checks",
"if",
"the",
"range",
"is",
"equal",
"to",
"one",
"of",
"the",
"selections",
"in",
"the",
"viewState"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L109-L117
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
saveLineFolds
|
function saveLineFolds(editor) {
var saveFolds = prefs.getSetting("saveFoldStates");
if (!editor || !saveFolds) {
return;
}
var folds = editor._codeMirror._lineFolds || {};
var path = editor.document.file.fullPath;
if (Object.keys(folds).length) {
prefs.setFolds(path, folds);
} else {
prefs.setFolds(path, undefined);
}
}
|
javascript
|
function saveLineFolds(editor) {
var saveFolds = prefs.getSetting("saveFoldStates");
if (!editor || !saveFolds) {
return;
}
var folds = editor._codeMirror._lineFolds || {};
var path = editor.document.file.fullPath;
if (Object.keys(folds).length) {
prefs.setFolds(path, folds);
} else {
prefs.setFolds(path, undefined);
}
}
|
[
"function",
"saveLineFolds",
"(",
"editor",
")",
"{",
"var",
"saveFolds",
"=",
"prefs",
".",
"getSetting",
"(",
"\"saveFoldStates\"",
")",
";",
"if",
"(",
"!",
"editor",
"||",
"!",
"saveFolds",
")",
"{",
"return",
";",
"}",
"var",
"folds",
"=",
"editor",
".",
"_codeMirror",
".",
"_lineFolds",
"||",
"{",
"}",
";",
"var",
"path",
"=",
"editor",
".",
"document",
".",
"file",
".",
"fullPath",
";",
"if",
"(",
"Object",
".",
"keys",
"(",
"folds",
")",
".",
"length",
")",
"{",
"prefs",
".",
"setFolds",
"(",
"path",
",",
"folds",
")",
";",
"}",
"else",
"{",
"prefs",
".",
"setFolds",
"(",
"path",
",",
"undefined",
")",
";",
"}",
"}"
] |
Saves the line folds in the editor using the preference storage
@param {Editor} editor the editor whose line folds should be saved
|
[
"Saves",
"the",
"line",
"folds",
"in",
"the",
"editor",
"using",
"the",
"preference",
"storage"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L159-L171
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
collapseCurrent
|
function collapseCurrent() {
var editor = EditorManager.getFocusedEditor();
if (!editor) {
return;
}
var cm = editor._codeMirror;
var cursor = editor.getCursorPos(), i;
// Move cursor up until a collapsible line is found
for (i = cursor.line; i >= 0; i--) {
if (cm.foldCode(i)) {
editor.setCursorPos(i);
return;
}
}
}
|
javascript
|
function collapseCurrent() {
var editor = EditorManager.getFocusedEditor();
if (!editor) {
return;
}
var cm = editor._codeMirror;
var cursor = editor.getCursorPos(), i;
// Move cursor up until a collapsible line is found
for (i = cursor.line; i >= 0; i--) {
if (cm.foldCode(i)) {
editor.setCursorPos(i);
return;
}
}
}
|
[
"function",
"collapseCurrent",
"(",
")",
"{",
"var",
"editor",
"=",
"EditorManager",
".",
"getFocusedEditor",
"(",
")",
";",
"if",
"(",
"!",
"editor",
")",
"{",
"return",
";",
"}",
"var",
"cm",
"=",
"editor",
".",
"_codeMirror",
";",
"var",
"cursor",
"=",
"editor",
".",
"getCursorPos",
"(",
")",
",",
"i",
";",
"for",
"(",
"i",
"=",
"cursor",
".",
"line",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"cm",
".",
"foldCode",
"(",
"i",
")",
")",
"{",
"editor",
".",
"setCursorPos",
"(",
"i",
")",
";",
"return",
";",
"}",
"}",
"}"
] |
Collapses the code region nearest the current cursor position.
Nearest is found by searching from the current line and moving up the document until an
opening code-folding region is found.
|
[
"Collapses",
"the",
"code",
"region",
"nearest",
"the",
"current",
"cursor",
"position",
".",
"Nearest",
"is",
"found",
"by",
"searching",
"from",
"the",
"current",
"line",
"and",
"moving",
"up",
"the",
"document",
"until",
"an",
"opening",
"code",
"-",
"folding",
"region",
"is",
"found",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L211-L225
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
expandCurrent
|
function expandCurrent() {
var editor = EditorManager.getFocusedEditor();
if (editor) {
var cursor = editor.getCursorPos(), cm = editor._codeMirror;
cm.unfoldCode(cursor.line);
}
}
|
javascript
|
function expandCurrent() {
var editor = EditorManager.getFocusedEditor();
if (editor) {
var cursor = editor.getCursorPos(), cm = editor._codeMirror;
cm.unfoldCode(cursor.line);
}
}
|
[
"function",
"expandCurrent",
"(",
")",
"{",
"var",
"editor",
"=",
"EditorManager",
".",
"getFocusedEditor",
"(",
")",
";",
"if",
"(",
"editor",
")",
"{",
"var",
"cursor",
"=",
"editor",
".",
"getCursorPos",
"(",
")",
",",
"cm",
"=",
"editor",
".",
"_codeMirror",
";",
"cm",
".",
"unfoldCode",
"(",
"cursor",
".",
"line",
")",
";",
"}",
"}"
] |
Expands the code region at the current cursor position.
|
[
"Expands",
"the",
"code",
"region",
"at",
"the",
"current",
"cursor",
"position",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L230-L236
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
expandAll
|
function expandAll() {
var editor = EditorManager.getFocusedEditor();
if (editor) {
var cm = editor._codeMirror;
CodeMirror.commands.unfoldAll(cm);
}
}
|
javascript
|
function expandAll() {
var editor = EditorManager.getFocusedEditor();
if (editor) {
var cm = editor._codeMirror;
CodeMirror.commands.unfoldAll(cm);
}
}
|
[
"function",
"expandAll",
"(",
")",
"{",
"var",
"editor",
"=",
"EditorManager",
".",
"getFocusedEditor",
"(",
")",
";",
"if",
"(",
"editor",
")",
"{",
"var",
"cm",
"=",
"editor",
".",
"_codeMirror",
";",
"CodeMirror",
".",
"commands",
".",
"unfoldAll",
"(",
"cm",
")",
";",
"}",
"}"
] |
Expands all folded regions in the current document
|
[
"Expands",
"all",
"folded",
"regions",
"in",
"the",
"current",
"document"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L262-L268
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
setupGutterEventListeners
|
function setupGutterEventListeners(editor) {
var cm = editor._codeMirror;
$(editor.getRootElement()).addClass("folding-enabled");
cm.setOption("foldGutter", {onGutterClick: onGutterClick});
$(cm.getGutterElement()).on({
mouseenter: function () {
if (prefs.getSetting("hideUntilMouseover")) {
foldGutter.updateInViewport(cm);
} else {
$(editor.getRootElement()).addClass("over-gutter");
}
},
mouseleave: function () {
if (prefs.getSetting("hideUntilMouseover")) {
clearGutter(editor);
} else {
$(editor.getRootElement()).removeClass("over-gutter");
}
}
});
}
|
javascript
|
function setupGutterEventListeners(editor) {
var cm = editor._codeMirror;
$(editor.getRootElement()).addClass("folding-enabled");
cm.setOption("foldGutter", {onGutterClick: onGutterClick});
$(cm.getGutterElement()).on({
mouseenter: function () {
if (prefs.getSetting("hideUntilMouseover")) {
foldGutter.updateInViewport(cm);
} else {
$(editor.getRootElement()).addClass("over-gutter");
}
},
mouseleave: function () {
if (prefs.getSetting("hideUntilMouseover")) {
clearGutter(editor);
} else {
$(editor.getRootElement()).removeClass("over-gutter");
}
}
});
}
|
[
"function",
"setupGutterEventListeners",
"(",
"editor",
")",
"{",
"var",
"cm",
"=",
"editor",
".",
"_codeMirror",
";",
"$",
"(",
"editor",
".",
"getRootElement",
"(",
")",
")",
".",
"addClass",
"(",
"\"folding-enabled\"",
")",
";",
"cm",
".",
"setOption",
"(",
"\"foldGutter\"",
",",
"{",
"onGutterClick",
":",
"onGutterClick",
"}",
")",
";",
"$",
"(",
"cm",
".",
"getGutterElement",
"(",
")",
")",
".",
"on",
"(",
"{",
"mouseenter",
":",
"function",
"(",
")",
"{",
"if",
"(",
"prefs",
".",
"getSetting",
"(",
"\"hideUntilMouseover\"",
")",
")",
"{",
"foldGutter",
".",
"updateInViewport",
"(",
"cm",
")",
";",
"}",
"else",
"{",
"$",
"(",
"editor",
".",
"getRootElement",
"(",
")",
")",
".",
"addClass",
"(",
"\"over-gutter\"",
")",
";",
"}",
"}",
",",
"mouseleave",
":",
"function",
"(",
")",
"{",
"if",
"(",
"prefs",
".",
"getSetting",
"(",
"\"hideUntilMouseover\"",
")",
")",
"{",
"clearGutter",
"(",
"editor",
")",
";",
"}",
"else",
"{",
"$",
"(",
"editor",
".",
"getRootElement",
"(",
")",
")",
".",
"removeClass",
"(",
"\"over-gutter\"",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Renders and sets up event listeners the code-folding gutter.
@param {Editor} editor the editor on which to initialise the fold gutter
|
[
"Renders",
"and",
"sets",
"up",
"event",
"listeners",
"the",
"code",
"-",
"folding",
"gutter",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L288-L309
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
removeGutters
|
function removeGutters(editor) {
Editor.unregisterGutter(GUTTER_NAME);
$(editor.getRootElement()).removeClass("folding-enabled");
CodeMirror.defineOption("foldGutter", false, null);
}
|
javascript
|
function removeGutters(editor) {
Editor.unregisterGutter(GUTTER_NAME);
$(editor.getRootElement()).removeClass("folding-enabled");
CodeMirror.defineOption("foldGutter", false, null);
}
|
[
"function",
"removeGutters",
"(",
"editor",
")",
"{",
"Editor",
".",
"unregisterGutter",
"(",
"GUTTER_NAME",
")",
";",
"$",
"(",
"editor",
".",
"getRootElement",
"(",
")",
")",
".",
"removeClass",
"(",
"\"folding-enabled\"",
")",
";",
"CodeMirror",
".",
"defineOption",
"(",
"\"foldGutter\"",
",",
"false",
",",
"null",
")",
";",
"}"
] |
Remove the fold gutter for a given CodeMirror instance.
@param {Editor} editor the editor instance whose gutter should be removed
|
[
"Remove",
"the",
"fold",
"gutter",
"for",
"a",
"given",
"CodeMirror",
"instance",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L315-L319
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
onActiveEditorChanged
|
function onActiveEditorChanged(event, current, previous) {
if (current && !current._codeMirror._lineFolds) {
enableFoldingInEditor(current);
}
if (previous) {
saveLineFolds(previous);
}
}
|
javascript
|
function onActiveEditorChanged(event, current, previous) {
if (current && !current._codeMirror._lineFolds) {
enableFoldingInEditor(current);
}
if (previous) {
saveLineFolds(previous);
}
}
|
[
"function",
"onActiveEditorChanged",
"(",
"event",
",",
"current",
",",
"previous",
")",
"{",
"if",
"(",
"current",
"&&",
"!",
"current",
".",
"_codeMirror",
".",
"_lineFolds",
")",
"{",
"enableFoldingInEditor",
"(",
"current",
")",
";",
"}",
"if",
"(",
"previous",
")",
"{",
"saveLineFolds",
"(",
"previous",
")",
";",
"}",
"}"
] |
When a brand new editor is seen, initialise fold-gutter and restore line folds in it.
Save line folds in departing editor in case it's getting closed.
@param {object} event the event object
@param {Editor} current the current editor
@param {Editor} previous the previous editor
|
[
"When",
"a",
"brand",
"new",
"editor",
"is",
"seen",
"initialise",
"fold",
"-",
"gutter",
"and",
"restore",
"line",
"folds",
"in",
"it",
".",
"Save",
"line",
"folds",
"in",
"departing",
"editor",
"in",
"case",
"it",
"s",
"getting",
"closed",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L338-L345
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
deinit
|
function deinit() {
_isInitialized = false;
KeyBindingManager.removeBinding(collapseKey);
KeyBindingManager.removeBinding(expandKey);
KeyBindingManager.removeBinding(collapseAllKey);
KeyBindingManager.removeBinding(expandAllKey);
KeyBindingManager.removeBinding(collapseAllKeyMac);
KeyBindingManager.removeBinding(expandAllKeyMac);
//remove menus
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuDivider(codeFoldingMenuDivider.id);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(COLLAPSE);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(EXPAND);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(COLLAPSE_ALL);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(EXPAND_ALL);
EditorManager.off(".CodeFolding");
DocumentManager.off(".CodeFolding");
ProjectManager.off(".CodeFolding");
// Remove gutter & revert collapsed sections in all currently open editors
Editor.forEveryEditor(function (editor) {
CodeMirror.commands.unfoldAll(editor._codeMirror);
});
removeGutters();
}
|
javascript
|
function deinit() {
_isInitialized = false;
KeyBindingManager.removeBinding(collapseKey);
KeyBindingManager.removeBinding(expandKey);
KeyBindingManager.removeBinding(collapseAllKey);
KeyBindingManager.removeBinding(expandAllKey);
KeyBindingManager.removeBinding(collapseAllKeyMac);
KeyBindingManager.removeBinding(expandAllKeyMac);
//remove menus
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuDivider(codeFoldingMenuDivider.id);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(COLLAPSE);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(EXPAND);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(COLLAPSE_ALL);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).removeMenuItem(EXPAND_ALL);
EditorManager.off(".CodeFolding");
DocumentManager.off(".CodeFolding");
ProjectManager.off(".CodeFolding");
// Remove gutter & revert collapsed sections in all currently open editors
Editor.forEveryEditor(function (editor) {
CodeMirror.commands.unfoldAll(editor._codeMirror);
});
removeGutters();
}
|
[
"function",
"deinit",
"(",
")",
"{",
"_isInitialized",
"=",
"false",
";",
"KeyBindingManager",
".",
"removeBinding",
"(",
"collapseKey",
")",
";",
"KeyBindingManager",
".",
"removeBinding",
"(",
"expandKey",
")",
";",
"KeyBindingManager",
".",
"removeBinding",
"(",
"collapseAllKey",
")",
";",
"KeyBindingManager",
".",
"removeBinding",
"(",
"expandAllKey",
")",
";",
"KeyBindingManager",
".",
"removeBinding",
"(",
"collapseAllKeyMac",
")",
";",
"KeyBindingManager",
".",
"removeBinding",
"(",
"expandAllKeyMac",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"removeMenuDivider",
"(",
"codeFoldingMenuDivider",
".",
"id",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"removeMenuItem",
"(",
"COLLAPSE",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"removeMenuItem",
"(",
"EXPAND",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"removeMenuItem",
"(",
"COLLAPSE_ALL",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"removeMenuItem",
"(",
"EXPAND_ALL",
")",
";",
"EditorManager",
".",
"off",
"(",
"\".CodeFolding\"",
")",
";",
"DocumentManager",
".",
"off",
"(",
"\".CodeFolding\"",
")",
";",
"ProjectManager",
".",
"off",
"(",
"\".CodeFolding\"",
")",
";",
"Editor",
".",
"forEveryEditor",
"(",
"function",
"(",
"editor",
")",
"{",
"CodeMirror",
".",
"commands",
".",
"unfoldAll",
"(",
"editor",
".",
"_codeMirror",
")",
";",
"}",
")",
";",
"removeGutters",
"(",
")",
";",
"}"
] |
Remove code-folding functionality
|
[
"Remove",
"code",
"-",
"folding",
"functionality"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L358-L384
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
init
|
function init() {
_isInitialized = true;
foldCode.init();
foldGutter.init();
// Many CodeMirror modes specify which fold helper should be used for that language. For a few that
// don't, we register helpers explicitly here. We also register a global helper for generic indent-based
// folding, which cuts across all languages if enabled via preference.
CodeMirror.registerGlobalHelper("fold", "selectionFold", function (mode, cm) {
return prefs.getSetting("makeSelectionsFoldable");
}, selectionFold);
CodeMirror.registerGlobalHelper("fold", "indent", function (mode, cm) {
return prefs.getSetting("alwaysUseIndentFold");
}, indentFold);
CodeMirror.registerHelper("fold", "handlebars", handlebarsFold);
CodeMirror.registerHelper("fold", "htmlhandlebars", handlebarsFold);
CodeMirror.registerHelper("fold", "htmlmixed", handlebarsFold);
EditorManager.on("activeEditorChange.CodeFolding", onActiveEditorChanged);
DocumentManager.on("documentRefreshed.CodeFolding", function (event, doc) {
restoreLineFolds(doc._masterEditor);
});
ProjectManager.on("beforeProjectClose.CodeFolding beforeAppClose.CodeFolding", saveBeforeClose);
//create menus
codeFoldingMenuDivider = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuDivider();
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE_ALL);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND_ALL);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND);
//register keybindings
KeyBindingManager.addBinding(COLLAPSE_ALL, [ {key: collapseAllKey}, {key: collapseAllKeyMac, platform: "mac"} ]);
KeyBindingManager.addBinding(EXPAND_ALL, [ {key: expandAllKey}, {key: expandAllKeyMac, platform: "mac"} ]);
KeyBindingManager.addBinding(COLLAPSE, collapseKey);
KeyBindingManager.addBinding(EXPAND, expandKey);
// Add gutters & restore saved expand/collapse state in all currently open editors
Editor.registerGutter(GUTTER_NAME, CODE_FOLDING_GUTTER_PRIORITY);
Editor.forEveryEditor(function (editor) {
enableFoldingInEditor(editor);
});
}
|
javascript
|
function init() {
_isInitialized = true;
foldCode.init();
foldGutter.init();
// Many CodeMirror modes specify which fold helper should be used for that language. For a few that
// don't, we register helpers explicitly here. We also register a global helper for generic indent-based
// folding, which cuts across all languages if enabled via preference.
CodeMirror.registerGlobalHelper("fold", "selectionFold", function (mode, cm) {
return prefs.getSetting("makeSelectionsFoldable");
}, selectionFold);
CodeMirror.registerGlobalHelper("fold", "indent", function (mode, cm) {
return prefs.getSetting("alwaysUseIndentFold");
}, indentFold);
CodeMirror.registerHelper("fold", "handlebars", handlebarsFold);
CodeMirror.registerHelper("fold", "htmlhandlebars", handlebarsFold);
CodeMirror.registerHelper("fold", "htmlmixed", handlebarsFold);
EditorManager.on("activeEditorChange.CodeFolding", onActiveEditorChanged);
DocumentManager.on("documentRefreshed.CodeFolding", function (event, doc) {
restoreLineFolds(doc._masterEditor);
});
ProjectManager.on("beforeProjectClose.CodeFolding beforeAppClose.CodeFolding", saveBeforeClose);
//create menus
codeFoldingMenuDivider = Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuDivider();
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE_ALL);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND_ALL);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(COLLAPSE);
Menus.getMenu(Menus.AppMenuBar.VIEW_MENU).addMenuItem(EXPAND);
//register keybindings
KeyBindingManager.addBinding(COLLAPSE_ALL, [ {key: collapseAllKey}, {key: collapseAllKeyMac, platform: "mac"} ]);
KeyBindingManager.addBinding(EXPAND_ALL, [ {key: expandAllKey}, {key: expandAllKeyMac, platform: "mac"} ]);
KeyBindingManager.addBinding(COLLAPSE, collapseKey);
KeyBindingManager.addBinding(EXPAND, expandKey);
// Add gutters & restore saved expand/collapse state in all currently open editors
Editor.registerGutter(GUTTER_NAME, CODE_FOLDING_GUTTER_PRIORITY);
Editor.forEveryEditor(function (editor) {
enableFoldingInEditor(editor);
});
}
|
[
"function",
"init",
"(",
")",
"{",
"_isInitialized",
"=",
"true",
";",
"foldCode",
".",
"init",
"(",
")",
";",
"foldGutter",
".",
"init",
"(",
")",
";",
"CodeMirror",
".",
"registerGlobalHelper",
"(",
"\"fold\"",
",",
"\"selectionFold\"",
",",
"function",
"(",
"mode",
",",
"cm",
")",
"{",
"return",
"prefs",
".",
"getSetting",
"(",
"\"makeSelectionsFoldable\"",
")",
";",
"}",
",",
"selectionFold",
")",
";",
"CodeMirror",
".",
"registerGlobalHelper",
"(",
"\"fold\"",
",",
"\"indent\"",
",",
"function",
"(",
"mode",
",",
"cm",
")",
"{",
"return",
"prefs",
".",
"getSetting",
"(",
"\"alwaysUseIndentFold\"",
")",
";",
"}",
",",
"indentFold",
")",
";",
"CodeMirror",
".",
"registerHelper",
"(",
"\"fold\"",
",",
"\"handlebars\"",
",",
"handlebarsFold",
")",
";",
"CodeMirror",
".",
"registerHelper",
"(",
"\"fold\"",
",",
"\"htmlhandlebars\"",
",",
"handlebarsFold",
")",
";",
"CodeMirror",
".",
"registerHelper",
"(",
"\"fold\"",
",",
"\"htmlmixed\"",
",",
"handlebarsFold",
")",
";",
"EditorManager",
".",
"on",
"(",
"\"activeEditorChange.CodeFolding\"",
",",
"onActiveEditorChanged",
")",
";",
"DocumentManager",
".",
"on",
"(",
"\"documentRefreshed.CodeFolding\"",
",",
"function",
"(",
"event",
",",
"doc",
")",
"{",
"restoreLineFolds",
"(",
"doc",
".",
"_masterEditor",
")",
";",
"}",
")",
";",
"ProjectManager",
".",
"on",
"(",
"\"beforeProjectClose.CodeFolding beforeAppClose.CodeFolding\"",
",",
"saveBeforeClose",
")",
";",
"codeFoldingMenuDivider",
"=",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"addMenuDivider",
"(",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"addMenuItem",
"(",
"COLLAPSE_ALL",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"addMenuItem",
"(",
"EXPAND_ALL",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"addMenuItem",
"(",
"COLLAPSE",
")",
";",
"Menus",
".",
"getMenu",
"(",
"Menus",
".",
"AppMenuBar",
".",
"VIEW_MENU",
")",
".",
"addMenuItem",
"(",
"EXPAND",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"COLLAPSE_ALL",
",",
"[",
"{",
"key",
":",
"collapseAllKey",
"}",
",",
"{",
"key",
":",
"collapseAllKeyMac",
",",
"platform",
":",
"\"mac\"",
"}",
"]",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"EXPAND_ALL",
",",
"[",
"{",
"key",
":",
"expandAllKey",
"}",
",",
"{",
"key",
":",
"expandAllKeyMac",
",",
"platform",
":",
"\"mac\"",
"}",
"]",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"COLLAPSE",
",",
"collapseKey",
")",
";",
"KeyBindingManager",
".",
"addBinding",
"(",
"EXPAND",
",",
"expandKey",
")",
";",
"Editor",
".",
"registerGutter",
"(",
"GUTTER_NAME",
",",
"CODE_FOLDING_GUTTER_PRIORITY",
")",
";",
"Editor",
".",
"forEveryEditor",
"(",
"function",
"(",
"editor",
")",
"{",
"enableFoldingInEditor",
"(",
"editor",
")",
";",
"}",
")",
";",
"}"
] |
Enable code-folding functionality
|
[
"Enable",
"code",
"-",
"folding",
"functionality"
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L389-L435
|
train
|
adobe/brackets
|
src/extensions/default/CodeFolding/main.js
|
watchPrefsForChanges
|
function watchPrefsForChanges() {
prefs.prefsObject.on("change", function (e, data) {
if (data.ids.indexOf("enabled") > -1) {
// Check if enabled state mismatches whether code-folding is actually initialized (can't assume
// since preference change events can occur when the value hasn't really changed)
var isEnabled = prefs.getSetting("enabled");
if (isEnabled && !_isInitialized) {
init();
} else if (!isEnabled && _isInitialized) {
deinit();
}
}
});
}
|
javascript
|
function watchPrefsForChanges() {
prefs.prefsObject.on("change", function (e, data) {
if (data.ids.indexOf("enabled") > -1) {
// Check if enabled state mismatches whether code-folding is actually initialized (can't assume
// since preference change events can occur when the value hasn't really changed)
var isEnabled = prefs.getSetting("enabled");
if (isEnabled && !_isInitialized) {
init();
} else if (!isEnabled && _isInitialized) {
deinit();
}
}
});
}
|
[
"function",
"watchPrefsForChanges",
"(",
")",
"{",
"prefs",
".",
"prefsObject",
".",
"on",
"(",
"\"change\"",
",",
"function",
"(",
"e",
",",
"data",
")",
"{",
"if",
"(",
"data",
".",
"ids",
".",
"indexOf",
"(",
"\"enabled\"",
")",
">",
"-",
"1",
")",
"{",
"var",
"isEnabled",
"=",
"prefs",
".",
"getSetting",
"(",
"\"enabled\"",
")",
";",
"if",
"(",
"isEnabled",
"&&",
"!",
"_isInitialized",
")",
"{",
"init",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isEnabled",
"&&",
"_isInitialized",
")",
"{",
"deinit",
"(",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] |
Register change listener for the preferences file.
|
[
"Register",
"change",
"listener",
"for",
"the",
"preferences",
"file",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/CodeFolding/main.js#L440-L453
|
train
|
adobe/brackets
|
src/filesystem/impls/appshell/node/FileWatcherDomain.js
|
init
|
function init(domainManager) {
if (!domainManager.hasDomain("fileWatcher")) {
domainManager.registerDomain("fileWatcher", {major: 0, minor: 1});
}
domainManager.registerCommand(
"fileWatcher",
"watchPath",
watcherManager.watchPath,
false,
"Start watching a file or directory",
[{
name: "path",
type: "string",
description: "absolute filesystem path of the file or directory to watch"
}, {
name: "ignored",
type: "array",
description: "list of path to ignore"
}]
);
domainManager.registerCommand(
"fileWatcher",
"unwatchPath",
watcherManager.unwatchPath,
false,
"Stop watching a single file or a directory and it's descendants",
[{
name: "path",
type: "string",
description: "absolute filesystem path of the file or directory to unwatch"
}]
);
domainManager.registerCommand(
"fileWatcher",
"unwatchAll",
watcherManager.unwatchAll,
false,
"Stop watching all files and directories"
);
domainManager.registerEvent(
"fileWatcher",
"change",
[
{name: "event", type: "string"},
{name: "parentDirPath", type: "string"},
{name: "entryName", type: "string"},
{name: "statsObj", type: "object"}
]
);
watcherManager.setDomainManager(domainManager);
watcherManager.setWatcherImpl(watcherImpl);
}
|
javascript
|
function init(domainManager) {
if (!domainManager.hasDomain("fileWatcher")) {
domainManager.registerDomain("fileWatcher", {major: 0, minor: 1});
}
domainManager.registerCommand(
"fileWatcher",
"watchPath",
watcherManager.watchPath,
false,
"Start watching a file or directory",
[{
name: "path",
type: "string",
description: "absolute filesystem path of the file or directory to watch"
}, {
name: "ignored",
type: "array",
description: "list of path to ignore"
}]
);
domainManager.registerCommand(
"fileWatcher",
"unwatchPath",
watcherManager.unwatchPath,
false,
"Stop watching a single file or a directory and it's descendants",
[{
name: "path",
type: "string",
description: "absolute filesystem path of the file or directory to unwatch"
}]
);
domainManager.registerCommand(
"fileWatcher",
"unwatchAll",
watcherManager.unwatchAll,
false,
"Stop watching all files and directories"
);
domainManager.registerEvent(
"fileWatcher",
"change",
[
{name: "event", type: "string"},
{name: "parentDirPath", type: "string"},
{name: "entryName", type: "string"},
{name: "statsObj", type: "object"}
]
);
watcherManager.setDomainManager(domainManager);
watcherManager.setWatcherImpl(watcherImpl);
}
|
[
"function",
"init",
"(",
"domainManager",
")",
"{",
"if",
"(",
"!",
"domainManager",
".",
"hasDomain",
"(",
"\"fileWatcher\"",
")",
")",
"{",
"domainManager",
".",
"registerDomain",
"(",
"\"fileWatcher\"",
",",
"{",
"major",
":",
"0",
",",
"minor",
":",
"1",
"}",
")",
";",
"}",
"domainManager",
".",
"registerCommand",
"(",
"\"fileWatcher\"",
",",
"\"watchPath\"",
",",
"watcherManager",
".",
"watchPath",
",",
"false",
",",
"\"Start watching a file or directory\"",
",",
"[",
"{",
"name",
":",
"\"path\"",
",",
"type",
":",
"\"string\"",
",",
"description",
":",
"\"absolute filesystem path of the file or directory to watch\"",
"}",
",",
"{",
"name",
":",
"\"ignored\"",
",",
"type",
":",
"\"array\"",
",",
"description",
":",
"\"list of path to ignore\"",
"}",
"]",
")",
";",
"domainManager",
".",
"registerCommand",
"(",
"\"fileWatcher\"",
",",
"\"unwatchPath\"",
",",
"watcherManager",
".",
"unwatchPath",
",",
"false",
",",
"\"Stop watching a single file or a directory and it's descendants\"",
",",
"[",
"{",
"name",
":",
"\"path\"",
",",
"type",
":",
"\"string\"",
",",
"description",
":",
"\"absolute filesystem path of the file or directory to unwatch\"",
"}",
"]",
")",
";",
"domainManager",
".",
"registerCommand",
"(",
"\"fileWatcher\"",
",",
"\"unwatchAll\"",
",",
"watcherManager",
".",
"unwatchAll",
",",
"false",
",",
"\"Stop watching all files and directories\"",
")",
";",
"domainManager",
".",
"registerEvent",
"(",
"\"fileWatcher\"",
",",
"\"change\"",
",",
"[",
"{",
"name",
":",
"\"event\"",
",",
"type",
":",
"\"string\"",
"}",
",",
"{",
"name",
":",
"\"parentDirPath\"",
",",
"type",
":",
"\"string\"",
"}",
",",
"{",
"name",
":",
"\"entryName\"",
",",
"type",
":",
"\"string\"",
"}",
",",
"{",
"name",
":",
"\"statsObj\"",
",",
"type",
":",
"\"object\"",
"}",
"]",
")",
";",
"watcherManager",
".",
"setDomainManager",
"(",
"domainManager",
")",
";",
"watcherManager",
".",
"setWatcherImpl",
"(",
"watcherImpl",
")",
";",
"}"
] |
Initialize the "fileWatcher" domain.
The fileWatcher domain handles watching and un-watching directories.
|
[
"Initialize",
"the",
"fileWatcher",
"domain",
".",
"The",
"fileWatcher",
"domain",
"handles",
"watching",
"and",
"un",
"-",
"watching",
"directories",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/filesystem/impls/appshell/node/FileWatcherDomain.js#L42-L96
|
train
|
adobe/brackets
|
src/extensions/default/AutoUpdate/StateHandler.js
|
_write
|
function _write(filePath, json) {
var result = $.Deferred(),
_file = FileSystem.getFileForPath(filePath);
if (_file) {
var content = JSON.stringify(json);
FileUtils.writeText(_file, content, true)
.done(function () {
result.resolve();
})
.fail(function (err) {
result.reject();
});
} else {
result.reject();
}
return result.promise();
}
|
javascript
|
function _write(filePath, json) {
var result = $.Deferred(),
_file = FileSystem.getFileForPath(filePath);
if (_file) {
var content = JSON.stringify(json);
FileUtils.writeText(_file, content, true)
.done(function () {
result.resolve();
})
.fail(function (err) {
result.reject();
});
} else {
result.reject();
}
return result.promise();
}
|
[
"function",
"_write",
"(",
"filePath",
",",
"json",
")",
"{",
"var",
"result",
"=",
"$",
".",
"Deferred",
"(",
")",
",",
"_file",
"=",
"FileSystem",
".",
"getFileForPath",
"(",
"filePath",
")",
";",
"if",
"(",
"_file",
")",
"{",
"var",
"content",
"=",
"JSON",
".",
"stringify",
"(",
"json",
")",
";",
"FileUtils",
".",
"writeText",
"(",
"_file",
",",
"content",
",",
"true",
")",
".",
"done",
"(",
"function",
"(",
")",
"{",
"result",
".",
"resolve",
"(",
")",
";",
"}",
")",
".",
"fail",
"(",
"function",
"(",
"err",
")",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"result",
".",
"reject",
"(",
")",
";",
"}",
"return",
"result",
".",
"promise",
"(",
")",
";",
"}"
] |
Performs the write of JSON object to a file.
@param {string} filepath - path to JSON file
@param {object} json - JSON object to write
@returns {$.Deferred} - a jquery deferred promise,
that is resolved with the write success or failure
|
[
"Performs",
"the",
"write",
"of",
"JSON",
"object",
"to",
"a",
"file",
"."
] |
d5d00d43602c438266d32b8eda8f8a3ca937b524
|
https://github.com/adobe/brackets/blob/d5d00d43602c438266d32b8eda8f8a3ca937b524/src/extensions/default/AutoUpdate/StateHandler.js#L169-L189
|
train
|
facebook/relay
|
packages/relay-compiler/util/dedupeJSONStringify.js
|
collectDuplicates
|
function collectDuplicates(value) {
if (value == null || typeof value !== 'object') {
return;
}
const metadata = metadataForVal.get(value);
// Only consider duplicates with hashes longer than 2 (excludes [] and {}).
if (metadata && metadata.value !== value && metadata.hash.length > 2) {
metadata.isDuplicate = true;
return;
}
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
collectDuplicates(value[i]);
}
} else {
for (const k in value) {
if (value.hasOwnProperty(k) && value[k] !== undefined) {
collectDuplicates(value[k]);
}
}
}
}
|
javascript
|
function collectDuplicates(value) {
if (value == null || typeof value !== 'object') {
return;
}
const metadata = metadataForVal.get(value);
// Only consider duplicates with hashes longer than 2 (excludes [] and {}).
if (metadata && metadata.value !== value && metadata.hash.length > 2) {
metadata.isDuplicate = true;
return;
}
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
collectDuplicates(value[i]);
}
} else {
for (const k in value) {
if (value.hasOwnProperty(k) && value[k] !== undefined) {
collectDuplicates(value[k]);
}
}
}
}
|
[
"function",
"collectDuplicates",
"(",
"value",
")",
"{",
"if",
"(",
"value",
"==",
"null",
"||",
"typeof",
"value",
"!==",
"'object'",
")",
"{",
"return",
";",
"}",
"const",
"metadata",
"=",
"metadataForVal",
".",
"get",
"(",
"value",
")",
";",
"if",
"(",
"metadata",
"&&",
"metadata",
".",
"value",
"!==",
"value",
"&&",
"metadata",
".",
"hash",
".",
"length",
">",
"2",
")",
"{",
"metadata",
".",
"isDuplicate",
"=",
"true",
";",
"return",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"value",
".",
"length",
";",
"i",
"++",
")",
"{",
"collectDuplicates",
"(",
"value",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"const",
"k",
"in",
"value",
")",
"{",
"if",
"(",
"value",
".",
"hasOwnProperty",
"(",
"k",
")",
"&&",
"value",
"[",
"k",
"]",
"!==",
"undefined",
")",
"{",
"collectDuplicates",
"(",
"value",
"[",
"k",
"]",
")",
";",
"}",
"}",
"}",
"}"
] |
Using top-down recursion, linearly scan the JSON tree to determine which values should be deduplicated.
|
[
"Using",
"top",
"-",
"down",
"recursion",
"linearly",
"scan",
"the",
"JSON",
"tree",
"to",
"determine",
"which",
"values",
"should",
"be",
"deduplicated",
"."
] |
7fb9be5182b9650637d7b92ead9a42713ac30aa4
|
https://github.com/facebook/relay/blob/7fb9be5182b9650637d7b92ead9a42713ac30aa4/packages/relay-compiler/util/dedupeJSONStringify.js#L66-L87
|
train
|
facebook/relay
|
packages/relay-compiler/util/dedupeJSONStringify.js
|
printJSCode
|
function printJSCode(isDupedVar, depth, value) {
if (value == null || typeof value !== 'object') {
return JSON.stringify(value);
}
// Only use variable references at depth beyond the top level.
if (depth !== '') {
const metadata = metadataForVal.get(value);
if (metadata && metadata.isDuplicate) {
if (!metadata.varName) {
const refCode = printJSCode(true, '', value);
metadata.varName = 'v' + varDefs.length;
varDefs.push(metadata.varName + ' = ' + refCode);
}
return '(' + metadata.varName + '/*: any*/)';
}
}
let str;
let isEmpty = true;
const depth2 = depth + ' ';
if (Array.isArray(value)) {
// Empty arrays can only have one inferred flow type and then conflict if
// used in different places, this is unsound if we would write to them but
// this whole module is based on the idea of a read only JSON tree.
if (isDupedVar && value.length === 0) {
return '([]/*: any*/)';
}
str = '[';
for (let i = 0; i < value.length; i++) {
str +=
(isEmpty ? '\n' : ',\n') +
depth2 +
printJSCode(isDupedVar, depth2, value[i]);
isEmpty = false;
}
str += isEmpty ? ']' : `\n${depth}]`;
} else {
str = '{';
for (const k in value) {
if (value.hasOwnProperty(k) && value[k] !== undefined) {
str +=
(isEmpty ? '\n' : ',\n') +
depth2 +
JSON.stringify(k) +
': ' +
printJSCode(isDupedVar, depth2, value[k]);
isEmpty = false;
}
}
str += isEmpty ? '}' : `\n${depth}}`;
}
return str;
}
|
javascript
|
function printJSCode(isDupedVar, depth, value) {
if (value == null || typeof value !== 'object') {
return JSON.stringify(value);
}
// Only use variable references at depth beyond the top level.
if (depth !== '') {
const metadata = metadataForVal.get(value);
if (metadata && metadata.isDuplicate) {
if (!metadata.varName) {
const refCode = printJSCode(true, '', value);
metadata.varName = 'v' + varDefs.length;
varDefs.push(metadata.varName + ' = ' + refCode);
}
return '(' + metadata.varName + '/*: any*/)';
}
}
let str;
let isEmpty = true;
const depth2 = depth + ' ';
if (Array.isArray(value)) {
// Empty arrays can only have one inferred flow type and then conflict if
// used in different places, this is unsound if we would write to them but
// this whole module is based on the idea of a read only JSON tree.
if (isDupedVar && value.length === 0) {
return '([]/*: any*/)';
}
str = '[';
for (let i = 0; i < value.length; i++) {
str +=
(isEmpty ? '\n' : ',\n') +
depth2 +
printJSCode(isDupedVar, depth2, value[i]);
isEmpty = false;
}
str += isEmpty ? ']' : `\n${depth}]`;
} else {
str = '{';
for (const k in value) {
if (value.hasOwnProperty(k) && value[k] !== undefined) {
str +=
(isEmpty ? '\n' : ',\n') +
depth2 +
JSON.stringify(k) +
': ' +
printJSCode(isDupedVar, depth2, value[k]);
isEmpty = false;
}
}
str += isEmpty ? '}' : `\n${depth}}`;
}
return str;
}
|
[
"function",
"printJSCode",
"(",
"isDupedVar",
",",
"depth",
",",
"value",
")",
"{",
"if",
"(",
"value",
"==",
"null",
"||",
"typeof",
"value",
"!==",
"'object'",
")",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"value",
")",
";",
"}",
"if",
"(",
"depth",
"!==",
"''",
")",
"{",
"const",
"metadata",
"=",
"metadataForVal",
".",
"get",
"(",
"value",
")",
";",
"if",
"(",
"metadata",
"&&",
"metadata",
".",
"isDuplicate",
")",
"{",
"if",
"(",
"!",
"metadata",
".",
"varName",
")",
"{",
"const",
"refCode",
"=",
"printJSCode",
"(",
"true",
",",
"''",
",",
"value",
")",
";",
"metadata",
".",
"varName",
"=",
"'v'",
"+",
"varDefs",
".",
"length",
";",
"varDefs",
".",
"push",
"(",
"metadata",
".",
"varName",
"+",
"' = '",
"+",
"refCode",
")",
";",
"}",
"return",
"'('",
"+",
"metadata",
".",
"varName",
"+",
"'/*: any*/)'",
";",
"}",
"}",
"let",
"str",
";",
"let",
"isEmpty",
"=",
"true",
";",
"const",
"depth2",
"=",
"depth",
"+",
"' '",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"if",
"(",
"isDupedVar",
"&&",
"value",
".",
"length",
"===",
"0",
")",
"{",
"return",
"'([]/*: any*/)'",
";",
"}",
"str",
"=",
"'['",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"value",
".",
"length",
";",
"i",
"++",
")",
"{",
"str",
"+=",
"(",
"isEmpty",
"?",
"'\\n'",
":",
"\\n",
")",
"+",
"',\\n'",
"+",
"\\n",
";",
"depth2",
"}",
"printJSCode",
"(",
"isDupedVar",
",",
"depth2",
",",
"value",
"[",
"i",
"]",
")",
"}",
"else",
"isEmpty",
"=",
"false",
";",
"str",
"+=",
"isEmpty",
"?",
"']'",
":",
"`",
"\\n",
"${",
"depth",
"}",
"`",
";",
"}"
] |
Stringify JS, replacing duplicates with variable references.
|
[
"Stringify",
"JS",
"replacing",
"duplicates",
"with",
"variable",
"references",
"."
] |
7fb9be5182b9650637d7b92ead9a42713ac30aa4
|
https://github.com/facebook/relay/blob/7fb9be5182b9650637d7b92ead9a42713ac30aa4/packages/relay-compiler/util/dedupeJSONStringify.js#L90-L141
|
train
|
facebook/relay
|
scripts/rewrite-modules.js
|
mapModule
|
function mapModule(state, module) {
var moduleMap = state.opts.map || {};
if (moduleMap.hasOwnProperty(module)) {
return moduleMap[module];
}
// Jest understands the haste module system, so leave modules intact.
if (process.env.NODE_ENV === 'test') {
return;
}
return './' + path.basename(module);
}
|
javascript
|
function mapModule(state, module) {
var moduleMap = state.opts.map || {};
if (moduleMap.hasOwnProperty(module)) {
return moduleMap[module];
}
// Jest understands the haste module system, so leave modules intact.
if (process.env.NODE_ENV === 'test') {
return;
}
return './' + path.basename(module);
}
|
[
"function",
"mapModule",
"(",
"state",
",",
"module",
")",
"{",
"var",
"moduleMap",
"=",
"state",
".",
"opts",
".",
"map",
"||",
"{",
"}",
";",
"if",
"(",
"moduleMap",
".",
"hasOwnProperty",
"(",
"module",
")",
")",
"{",
"return",
"moduleMap",
"[",
"module",
"]",
";",
"}",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"===",
"'test'",
")",
"{",
"return",
";",
"}",
"return",
"'./'",
"+",
"path",
".",
"basename",
"(",
"module",
")",
";",
"}"
] |
This file is a fork from fbjs's transform of the same name. It has been
modified to also apply to import statements, and to account for relative
file names in require statements.
Rewrites module string literals according to the `map` and `prefix` options.
This allows other npm packages to be published and used directly without
being a part of the same build.
|
[
"This",
"file",
"is",
"a",
"fork",
"from",
"fbjs",
"s",
"transform",
"of",
"the",
"same",
"name",
".",
"It",
"has",
"been",
"modified",
"to",
"also",
"apply",
"to",
"import",
"statements",
"and",
"to",
"account",
"for",
"relative",
"file",
"names",
"in",
"require",
"statements",
".",
"Rewrites",
"module",
"string",
"literals",
"according",
"to",
"the",
"map",
"and",
"prefix",
"options",
".",
"This",
"allows",
"other",
"npm",
"packages",
"to",
"be",
"published",
"and",
"used",
"directly",
"without",
"being",
"a",
"part",
"of",
"the",
"same",
"build",
"."
] |
7fb9be5182b9650637d7b92ead9a42713ac30aa4
|
https://github.com/facebook/relay/blob/7fb9be5182b9650637d7b92ead9a42713ac30aa4/scripts/rewrite-modules.js#L25-L35
|
train
|
lovell/sharp
|
lib/utility.js
|
cache
|
function cache (options) {
if (is.bool(options)) {
if (options) {
// Default cache settings of 50MB, 20 files, 100 items
return sharp.cache(50, 20, 100);
} else {
return sharp.cache(0, 0, 0);
}
} else if (is.object(options)) {
return sharp.cache(options.memory, options.files, options.items);
} else {
return sharp.cache();
}
}
|
javascript
|
function cache (options) {
if (is.bool(options)) {
if (options) {
// Default cache settings of 50MB, 20 files, 100 items
return sharp.cache(50, 20, 100);
} else {
return sharp.cache(0, 0, 0);
}
} else if (is.object(options)) {
return sharp.cache(options.memory, options.files, options.items);
} else {
return sharp.cache();
}
}
|
[
"function",
"cache",
"(",
"options",
")",
"{",
"if",
"(",
"is",
".",
"bool",
"(",
"options",
")",
")",
"{",
"if",
"(",
"options",
")",
"{",
"return",
"sharp",
".",
"cache",
"(",
"50",
",",
"20",
",",
"100",
")",
";",
"}",
"else",
"{",
"return",
"sharp",
".",
"cache",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
")",
"{",
"return",
"sharp",
".",
"cache",
"(",
"options",
".",
"memory",
",",
"options",
".",
"files",
",",
"options",
".",
"items",
")",
";",
"}",
"else",
"{",
"return",
"sharp",
".",
"cache",
"(",
")",
";",
"}",
"}"
] |
Gets or, when options are provided, sets the limits of _libvips'_ operation cache.
Existing entries in the cache will be trimmed after any change in limits.
This method always returns cache statistics,
useful for determining how much working memory is required for a particular task.
@example
const stats = sharp.cache();
@example
sharp.cache( { items: 200 } );
sharp.cache( { files: 0 } );
sharp.cache(false);
@param {Object|Boolean} [options=true] - Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching
@param {Number} [options.memory=50] - is the maximum memory in MB to use for this cache
@param {Number} [options.files=20] - is the maximum number of files to hold open
@param {Number} [options.items=100] - is the maximum number of operations to cache
@returns {Object}
|
[
"Gets",
"or",
"when",
"options",
"are",
"provided",
"sets",
"the",
"limits",
"of",
"_libvips",
"_",
"operation",
"cache",
".",
"Existing",
"entries",
"in",
"the",
"cache",
"will",
"be",
"trimmed",
"after",
"any",
"change",
"in",
"limits",
".",
"This",
"method",
"always",
"returns",
"cache",
"statistics",
"useful",
"for",
"determining",
"how",
"much",
"working",
"memory",
"is",
"required",
"for",
"a",
"particular",
"task",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/utility.js#L25-L38
|
train
|
lovell/sharp
|
lib/channel.js
|
extractChannel
|
function extractChannel (channel) {
if (channel === 'red') {
channel = 0;
} else if (channel === 'green') {
channel = 1;
} else if (channel === 'blue') {
channel = 2;
}
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
this.options.extractChannel = channel;
} else {
throw new Error('Cannot extract invalid channel ' + channel);
}
return this;
}
|
javascript
|
function extractChannel (channel) {
if (channel === 'red') {
channel = 0;
} else if (channel === 'green') {
channel = 1;
} else if (channel === 'blue') {
channel = 2;
}
if (is.integer(channel) && is.inRange(channel, 0, 4)) {
this.options.extractChannel = channel;
} else {
throw new Error('Cannot extract invalid channel ' + channel);
}
return this;
}
|
[
"function",
"extractChannel",
"(",
"channel",
")",
"{",
"if",
"(",
"channel",
"===",
"'red'",
")",
"{",
"channel",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"channel",
"===",
"'green'",
")",
"{",
"channel",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"channel",
"===",
"'blue'",
")",
"{",
"channel",
"=",
"2",
";",
"}",
"if",
"(",
"is",
".",
"integer",
"(",
"channel",
")",
"&&",
"is",
".",
"inRange",
"(",
"channel",
",",
"0",
",",
"4",
")",
")",
"{",
"this",
".",
"options",
".",
"extractChannel",
"=",
"channel",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Cannot extract invalid channel '",
"+",
"channel",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Extract a single channel from a multi-channel image.
@example
sharp(input)
.extractChannel('green')
.toFile('input_green.jpg', function(err, info) {
// info.channels === 1
// input_green.jpg contains the green channel of the input image
});
@param {Number|String} channel - zero-indexed band number to extract, or `red`, `green` or `blue` as alternative to `0`, `1` or `2` respectively.
@returns {Sharp}
@throws {Error} Invalid channel
|
[
"Extract",
"a",
"single",
"channel",
"from",
"a",
"multi",
"-",
"channel",
"image",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/channel.js#L64-L78
|
train
|
lovell/sharp
|
lib/input.js
|
_write
|
function _write (chunk, encoding, callback) {
/* istanbul ignore else */
if (Array.isArray(this.options.input.buffer)) {
/* istanbul ignore else */
if (is.buffer(chunk)) {
if (this.options.input.buffer.length === 0) {
const that = this;
this.on('finish', function () {
that.streamInFinished = true;
});
}
this.options.input.buffer.push(chunk);
callback();
} else {
callback(new Error('Non-Buffer data on Writable Stream'));
}
} else {
callback(new Error('Unexpected data on Writable Stream'));
}
}
|
javascript
|
function _write (chunk, encoding, callback) {
/* istanbul ignore else */
if (Array.isArray(this.options.input.buffer)) {
/* istanbul ignore else */
if (is.buffer(chunk)) {
if (this.options.input.buffer.length === 0) {
const that = this;
this.on('finish', function () {
that.streamInFinished = true;
});
}
this.options.input.buffer.push(chunk);
callback();
} else {
callback(new Error('Non-Buffer data on Writable Stream'));
}
} else {
callback(new Error('Unexpected data on Writable Stream'));
}
}
|
[
"function",
"_write",
"(",
"chunk",
",",
"encoding",
",",
"callback",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"this",
".",
"options",
".",
"input",
".",
"buffer",
")",
")",
"{",
"if",
"(",
"is",
".",
"buffer",
"(",
"chunk",
")",
")",
"{",
"if",
"(",
"this",
".",
"options",
".",
"input",
".",
"buffer",
".",
"length",
"===",
"0",
")",
"{",
"const",
"that",
"=",
"this",
";",
"this",
".",
"on",
"(",
"'finish'",
",",
"function",
"(",
")",
"{",
"that",
".",
"streamInFinished",
"=",
"true",
";",
"}",
")",
";",
"}",
"this",
".",
"options",
".",
"input",
".",
"buffer",
".",
"push",
"(",
"chunk",
")",
";",
"callback",
"(",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"new",
"Error",
"(",
"'Non-Buffer data on Writable Stream'",
")",
")",
";",
"}",
"}",
"else",
"{",
"callback",
"(",
"new",
"Error",
"(",
"'Unexpected data on Writable Stream'",
")",
")",
";",
"}",
"}"
] |
Handle incoming Buffer chunk on Writable Stream.
@private
@param {Buffer} chunk
@param {String} encoding - unused
@param {Function} callback
|
[
"Handle",
"incoming",
"Buffer",
"chunk",
"on",
"Writable",
"Stream",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/input.js#L112-L131
|
train
|
lovell/sharp
|
lib/input.js
|
_flattenBufferIn
|
function _flattenBufferIn () {
if (this._isStreamInput()) {
this.options.input.buffer = Buffer.concat(this.options.input.buffer);
}
}
|
javascript
|
function _flattenBufferIn () {
if (this._isStreamInput()) {
this.options.input.buffer = Buffer.concat(this.options.input.buffer);
}
}
|
[
"function",
"_flattenBufferIn",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_isStreamInput",
"(",
")",
")",
"{",
"this",
".",
"options",
".",
"input",
".",
"buffer",
"=",
"Buffer",
".",
"concat",
"(",
"this",
".",
"options",
".",
"input",
".",
"buffer",
")",
";",
"}",
"}"
] |
Flattens the array of chunks accumulated in input.buffer.
@private
|
[
"Flattens",
"the",
"array",
"of",
"chunks",
"accumulated",
"in",
"input",
".",
"buffer",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/input.js#L137-L141
|
train
|
lovell/sharp
|
lib/input.js
|
clone
|
function clone () {
const that = this;
// Clone existing options
const clone = this.constructor.call();
clone.options = Object.assign({}, this.options);
// Pass 'finish' event to clone for Stream-based input
if (this._isStreamInput()) {
this.on('finish', function () {
// Clone inherits input data
that._flattenBufferIn();
clone.options.bufferIn = that.options.bufferIn;
clone.emit('finish');
});
}
return clone;
}
|
javascript
|
function clone () {
const that = this;
// Clone existing options
const clone = this.constructor.call();
clone.options = Object.assign({}, this.options);
// Pass 'finish' event to clone for Stream-based input
if (this._isStreamInput()) {
this.on('finish', function () {
// Clone inherits input data
that._flattenBufferIn();
clone.options.bufferIn = that.options.bufferIn;
clone.emit('finish');
});
}
return clone;
}
|
[
"function",
"clone",
"(",
")",
"{",
"const",
"that",
"=",
"this",
";",
"const",
"clone",
"=",
"this",
".",
"constructor",
".",
"call",
"(",
")",
";",
"clone",
".",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"this",
".",
"options",
")",
";",
"if",
"(",
"this",
".",
"_isStreamInput",
"(",
")",
")",
"{",
"this",
".",
"on",
"(",
"'finish'",
",",
"function",
"(",
")",
"{",
"that",
".",
"_flattenBufferIn",
"(",
")",
";",
"clone",
".",
"options",
".",
"bufferIn",
"=",
"that",
".",
"options",
".",
"bufferIn",
";",
"clone",
".",
"emit",
"(",
"'finish'",
")",
";",
"}",
")",
";",
"}",
"return",
"clone",
";",
"}"
] |
Take a "snapshot" of the Sharp instance, returning a new instance.
Cloned instances inherit the input of their parent instance.
This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
@example
const pipeline = sharp().rotate();
pipeline.clone().resize(800, 600).pipe(firstWritableStream);
pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
readableStream.pipe(pipeline);
// firstWritableStream receives auto-rotated, resized readableStream
// secondWritableStream receives auto-rotated, extracted region of readableStream
@returns {Sharp}
|
[
"Take",
"a",
"snapshot",
"of",
"the",
"Sharp",
"instance",
"returning",
"a",
"new",
"instance",
".",
"Cloned",
"instances",
"inherit",
"the",
"input",
"of",
"their",
"parent",
"instance",
".",
"This",
"allows",
"multiple",
"output",
"Streams",
"and",
"therefore",
"multiple",
"processing",
"pipelines",
"to",
"share",
"a",
"single",
"input",
"Stream",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/input.js#L167-L182
|
train
|
lovell/sharp
|
lib/input.js
|
stats
|
function stats (callback) {
const that = this;
if (is.fn(callback)) {
if (this._isStreamInput()) {
this.on('finish', function () {
that._flattenBufferIn();
sharp.stats(that.options, callback);
});
} else {
sharp.stats(this.options, callback);
}
return this;
} else {
if (this._isStreamInput()) {
return new Promise(function (resolve, reject) {
that.on('finish', function () {
that._flattenBufferIn();
sharp.stats(that.options, function (err, stats) {
if (err) {
reject(err);
} else {
resolve(stats);
}
});
});
});
} else {
return new Promise(function (resolve, reject) {
sharp.stats(that.options, function (err, stats) {
if (err) {
reject(err);
} else {
resolve(stats);
}
});
});
}
}
}
|
javascript
|
function stats (callback) {
const that = this;
if (is.fn(callback)) {
if (this._isStreamInput()) {
this.on('finish', function () {
that._flattenBufferIn();
sharp.stats(that.options, callback);
});
} else {
sharp.stats(this.options, callback);
}
return this;
} else {
if (this._isStreamInput()) {
return new Promise(function (resolve, reject) {
that.on('finish', function () {
that._flattenBufferIn();
sharp.stats(that.options, function (err, stats) {
if (err) {
reject(err);
} else {
resolve(stats);
}
});
});
});
} else {
return new Promise(function (resolve, reject) {
sharp.stats(that.options, function (err, stats) {
if (err) {
reject(err);
} else {
resolve(stats);
}
});
});
}
}
}
|
[
"function",
"stats",
"(",
"callback",
")",
"{",
"const",
"that",
"=",
"this",
";",
"if",
"(",
"is",
".",
"fn",
"(",
"callback",
")",
")",
"{",
"if",
"(",
"this",
".",
"_isStreamInput",
"(",
")",
")",
"{",
"this",
".",
"on",
"(",
"'finish'",
",",
"function",
"(",
")",
"{",
"that",
".",
"_flattenBufferIn",
"(",
")",
";",
"sharp",
".",
"stats",
"(",
"that",
".",
"options",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"sharp",
".",
"stats",
"(",
"this",
".",
"options",
",",
"callback",
")",
";",
"}",
"return",
"this",
";",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"_isStreamInput",
"(",
")",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"that",
".",
"on",
"(",
"'finish'",
",",
"function",
"(",
")",
"{",
"that",
".",
"_flattenBufferIn",
"(",
")",
";",
"sharp",
".",
"stats",
"(",
"that",
".",
"options",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"stats",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"sharp",
".",
"stats",
"(",
"that",
".",
"options",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"stats",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
"}"
] |
Access to pixel-derived image statistics for every channel in the image.
A `Promise` is returned when `callback` is not provided.
- `channels`: Array of channel statistics for each channel in the image. Each channel statistic contains
- `min` (minimum value in the channel)
- `max` (maximum value in the channel)
- `sum` (sum of all values in a channel)
- `squaresSum` (sum of squared values in a channel)
- `mean` (mean of the values in a channel)
- `stdev` (standard deviation for the values in a channel)
- `minX` (x-coordinate of one of the pixel where the minimum lies)
- `minY` (y-coordinate of one of the pixel where the minimum lies)
- `maxX` (x-coordinate of one of the pixel where the maximum lies)
- `maxY` (y-coordinate of one of the pixel where the maximum lies)
- `isOpaque`: Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel
- `entropy`: Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental)
@example
const image = sharp(inputJpg);
image
.stats()
.then(function(stats) {
// stats contains the channel-wise statistics array and the isOpaque value
});
@param {Function} [callback] - called with the arguments `(err, stats)`
@returns {Promise<Object>}
|
[
"Access",
"to",
"pixel",
"-",
"derived",
"image",
"statistics",
"for",
"every",
"channel",
"in",
"the",
"image",
".",
"A",
"Promise",
"is",
"returned",
"when",
"callback",
"is",
"not",
"provided",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/input.js#L294-L332
|
train
|
lovell/sharp
|
lib/output.js
|
toFile
|
function toFile (fileOut, callback) {
if (!fileOut || fileOut.length === 0) {
const errOutputInvalid = new Error('Missing output file path');
if (is.fn(callback)) {
callback(errOutputInvalid);
} else {
return Promise.reject(errOutputInvalid);
}
} else {
if (this.options.input.file === fileOut) {
const errOutputIsInput = new Error('Cannot use same file for input and output');
if (is.fn(callback)) {
callback(errOutputIsInput);
} else {
return Promise.reject(errOutputIsInput);
}
} else {
this.options.fileOut = fileOut;
return this._pipeline(callback);
}
}
return this;
}
|
javascript
|
function toFile (fileOut, callback) {
if (!fileOut || fileOut.length === 0) {
const errOutputInvalid = new Error('Missing output file path');
if (is.fn(callback)) {
callback(errOutputInvalid);
} else {
return Promise.reject(errOutputInvalid);
}
} else {
if (this.options.input.file === fileOut) {
const errOutputIsInput = new Error('Cannot use same file for input and output');
if (is.fn(callback)) {
callback(errOutputIsInput);
} else {
return Promise.reject(errOutputIsInput);
}
} else {
this.options.fileOut = fileOut;
return this._pipeline(callback);
}
}
return this;
}
|
[
"function",
"toFile",
"(",
"fileOut",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"fileOut",
"||",
"fileOut",
".",
"length",
"===",
"0",
")",
"{",
"const",
"errOutputInvalid",
"=",
"new",
"Error",
"(",
"'Missing output file path'",
")",
";",
"if",
"(",
"is",
".",
"fn",
"(",
"callback",
")",
")",
"{",
"callback",
"(",
"errOutputInvalid",
")",
";",
"}",
"else",
"{",
"return",
"Promise",
".",
"reject",
"(",
"errOutputInvalid",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"this",
".",
"options",
".",
"input",
".",
"file",
"===",
"fileOut",
")",
"{",
"const",
"errOutputIsInput",
"=",
"new",
"Error",
"(",
"'Cannot use same file for input and output'",
")",
";",
"if",
"(",
"is",
".",
"fn",
"(",
"callback",
")",
")",
"{",
"callback",
"(",
"errOutputIsInput",
")",
";",
"}",
"else",
"{",
"return",
"Promise",
".",
"reject",
"(",
"errOutputIsInput",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"options",
".",
"fileOut",
"=",
"fileOut",
";",
"return",
"this",
".",
"_pipeline",
"(",
"callback",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] |
Write output image data to a file.
If an explicit output format is not selected, it will be inferred from the extension,
with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
Note that raw pixel data is only supported for buffer output.
A `Promise` is returned when `callback` is not provided.
@example
sharp(input)
.toFile('output.png', (err, info) => { ... });
@example
sharp(input)
.toFile('output.png')
.then(info => { ... })
.catch(err => { ... });
@param {String} fileOut - the path to write the image data to.
@param {Function} [callback] - called on completion with two arguments `(err, info)`.
`info` contains the output image `format`, `size` (bytes), `width`, `height`,
`channels` and `premultiplied` (indicating if premultiplication was used).
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
@returns {Promise<Object>} - when no callback is provided
@throws {Error} Invalid parameters
|
[
"Write",
"output",
"image",
"data",
"to",
"a",
"file",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/output.js#L33-L55
|
train
|
lovell/sharp
|
lib/output.js
|
toBuffer
|
function toBuffer (options, callback) {
if (is.object(options)) {
if (is.bool(options.resolveWithObject)) {
this.options.resolveWithObject = options.resolveWithObject;
}
}
return this._pipeline(is.fn(options) ? options : callback);
}
|
javascript
|
function toBuffer (options, callback) {
if (is.object(options)) {
if (is.bool(options.resolveWithObject)) {
this.options.resolveWithObject = options.resolveWithObject;
}
}
return this._pipeline(is.fn(options) ? options : callback);
}
|
[
"function",
"toBuffer",
"(",
"options",
",",
"callback",
")",
"{",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
")",
"{",
"if",
"(",
"is",
".",
"bool",
"(",
"options",
".",
"resolveWithObject",
")",
")",
"{",
"this",
".",
"options",
".",
"resolveWithObject",
"=",
"options",
".",
"resolveWithObject",
";",
"}",
"}",
"return",
"this",
".",
"_pipeline",
"(",
"is",
".",
"fn",
"(",
"options",
")",
"?",
"options",
":",
"callback",
")",
";",
"}"
] |
Write output to a Buffer.
JPEG, PNG, WebP, TIFF and RAW output are supported.
By default, the format will match the input image, except GIF and SVG input which become PNG output.
`callback`, if present, gets three arguments `(err, data, info)` where:
- `err` is an error, if any.
- `data` is the output image data.
- `info` contains the output image `format`, `size` (bytes), `width`, `height`,
`channels` and `premultiplied` (indicating if premultiplication was used).
When using a crop strategy also contains `cropOffsetLeft` and `cropOffsetTop`.
A `Promise` is returned when `callback` is not provided.
@example
sharp(input)
.toBuffer((err, data, info) => { ... });
@example
sharp(input)
.toBuffer()
.then(data => { ... })
.catch(err => { ... });
@example
sharp(input)
.toBuffer({ resolveWithObject: true })
.then(({ data, info }) => { ... })
.catch(err => { ... });
@param {Object} [options]
@param {Boolean} [options.resolveWithObject] Resolve the Promise with an Object containing `data` and `info` properties instead of resolving only with `data`.
@param {Function} [callback]
@returns {Promise<Buffer>} - when no callback is provided
|
[
"Write",
"output",
"to",
"a",
"Buffer",
".",
"JPEG",
"PNG",
"WebP",
"TIFF",
"and",
"RAW",
"output",
"are",
"supported",
".",
"By",
"default",
"the",
"format",
"will",
"match",
"the",
"input",
"image",
"except",
"GIF",
"and",
"SVG",
"input",
"which",
"become",
"PNG",
"output",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/output.js#L92-L99
|
train
|
lovell/sharp
|
lib/output.js
|
jpeg
|
function jpeg (options) {
if (is.object(options)) {
if (is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
this.options.jpegQuality = options.quality;
} else {
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
}
}
if (is.defined(options.progressive)) {
this._setBooleanOption('jpegProgressive', options.progressive);
}
if (is.defined(options.chromaSubsampling)) {
if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
this.options.jpegChromaSubsampling = options.chromaSubsampling;
} else {
throw new Error('Invalid chromaSubsampling (4:2:0, 4:4:4) ' + options.chromaSubsampling);
}
}
const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
if (is.defined(trellisQuantisation)) {
this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
}
if (is.defined(options.overshootDeringing)) {
this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
}
const optimiseScans = is.bool(options.optimizeScans) ? options.optimizeScans : options.optimiseScans;
if (is.defined(optimiseScans)) {
this._setBooleanOption('jpegOptimiseScans', optimiseScans);
if (optimiseScans) {
this.options.jpegProgressive = true;
}
}
const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
if (is.defined(optimiseCoding)) {
this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
}
const quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
if (is.defined(quantisationTable)) {
if (is.integer(quantisationTable) && is.inRange(quantisationTable, 0, 8)) {
this.options.jpegQuantisationTable = quantisationTable;
} else {
throw new Error('Invalid quantisation table (integer, 0-8) ' + quantisationTable);
}
}
}
return this._updateFormatOut('jpeg', options);
}
|
javascript
|
function jpeg (options) {
if (is.object(options)) {
if (is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
this.options.jpegQuality = options.quality;
} else {
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
}
}
if (is.defined(options.progressive)) {
this._setBooleanOption('jpegProgressive', options.progressive);
}
if (is.defined(options.chromaSubsampling)) {
if (is.string(options.chromaSubsampling) && is.inArray(options.chromaSubsampling, ['4:2:0', '4:4:4'])) {
this.options.jpegChromaSubsampling = options.chromaSubsampling;
} else {
throw new Error('Invalid chromaSubsampling (4:2:0, 4:4:4) ' + options.chromaSubsampling);
}
}
const trellisQuantisation = is.bool(options.trellisQuantization) ? options.trellisQuantization : options.trellisQuantisation;
if (is.defined(trellisQuantisation)) {
this._setBooleanOption('jpegTrellisQuantisation', trellisQuantisation);
}
if (is.defined(options.overshootDeringing)) {
this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
}
const optimiseScans = is.bool(options.optimizeScans) ? options.optimizeScans : options.optimiseScans;
if (is.defined(optimiseScans)) {
this._setBooleanOption('jpegOptimiseScans', optimiseScans);
if (optimiseScans) {
this.options.jpegProgressive = true;
}
}
const optimiseCoding = is.bool(options.optimizeCoding) ? options.optimizeCoding : options.optimiseCoding;
if (is.defined(optimiseCoding)) {
this._setBooleanOption('jpegOptimiseCoding', optimiseCoding);
}
const quantisationTable = is.number(options.quantizationTable) ? options.quantizationTable : options.quantisationTable;
if (is.defined(quantisationTable)) {
if (is.integer(quantisationTable) && is.inRange(quantisationTable, 0, 8)) {
this.options.jpegQuantisationTable = quantisationTable;
} else {
throw new Error('Invalid quantisation table (integer, 0-8) ' + quantisationTable);
}
}
}
return this._updateFormatOut('jpeg', options);
}
|
[
"function",
"jpeg",
"(",
"options",
")",
"{",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
")",
"{",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"quality",
")",
")",
"{",
"if",
"(",
"is",
".",
"integer",
"(",
"options",
".",
"quality",
")",
"&&",
"is",
".",
"inRange",
"(",
"options",
".",
"quality",
",",
"1",
",",
"100",
")",
")",
"{",
"this",
".",
"options",
".",
"jpegQuality",
"=",
"options",
".",
"quality",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid quality (integer, 1-100) '",
"+",
"options",
".",
"quality",
")",
";",
"}",
"}",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"progressive",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'jpegProgressive'",
",",
"options",
".",
"progressive",
")",
";",
"}",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"chromaSubsampling",
")",
")",
"{",
"if",
"(",
"is",
".",
"string",
"(",
"options",
".",
"chromaSubsampling",
")",
"&&",
"is",
".",
"inArray",
"(",
"options",
".",
"chromaSubsampling",
",",
"[",
"'4:2:0'",
",",
"'4:4:4'",
"]",
")",
")",
"{",
"this",
".",
"options",
".",
"jpegChromaSubsampling",
"=",
"options",
".",
"chromaSubsampling",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid chromaSubsampling (4:2:0, 4:4:4) '",
"+",
"options",
".",
"chromaSubsampling",
")",
";",
"}",
"}",
"const",
"trellisQuantisation",
"=",
"is",
".",
"bool",
"(",
"options",
".",
"trellisQuantization",
")",
"?",
"options",
".",
"trellisQuantization",
":",
"options",
".",
"trellisQuantisation",
";",
"if",
"(",
"is",
".",
"defined",
"(",
"trellisQuantisation",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'jpegTrellisQuantisation'",
",",
"trellisQuantisation",
")",
";",
"}",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"overshootDeringing",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'jpegOvershootDeringing'",
",",
"options",
".",
"overshootDeringing",
")",
";",
"}",
"const",
"optimiseScans",
"=",
"is",
".",
"bool",
"(",
"options",
".",
"optimizeScans",
")",
"?",
"options",
".",
"optimizeScans",
":",
"options",
".",
"optimiseScans",
";",
"if",
"(",
"is",
".",
"defined",
"(",
"optimiseScans",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'jpegOptimiseScans'",
",",
"optimiseScans",
")",
";",
"if",
"(",
"optimiseScans",
")",
"{",
"this",
".",
"options",
".",
"jpegProgressive",
"=",
"true",
";",
"}",
"}",
"const",
"optimiseCoding",
"=",
"is",
".",
"bool",
"(",
"options",
".",
"optimizeCoding",
")",
"?",
"options",
".",
"optimizeCoding",
":",
"options",
".",
"optimiseCoding",
";",
"if",
"(",
"is",
".",
"defined",
"(",
"optimiseCoding",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'jpegOptimiseCoding'",
",",
"optimiseCoding",
")",
";",
"}",
"const",
"quantisationTable",
"=",
"is",
".",
"number",
"(",
"options",
".",
"quantizationTable",
")",
"?",
"options",
".",
"quantizationTable",
":",
"options",
".",
"quantisationTable",
";",
"if",
"(",
"is",
".",
"defined",
"(",
"quantisationTable",
")",
")",
"{",
"if",
"(",
"is",
".",
"integer",
"(",
"quantisationTable",
")",
"&&",
"is",
".",
"inRange",
"(",
"quantisationTable",
",",
"0",
",",
"8",
")",
")",
"{",
"this",
".",
"options",
".",
"jpegQuantisationTable",
"=",
"quantisationTable",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid quantisation table (integer, 0-8) '",
"+",
"quantisationTable",
")",
";",
"}",
"}",
"}",
"return",
"this",
".",
"_updateFormatOut",
"(",
"'jpeg'",
",",
"options",
")",
";",
"}"
] |
Use these JPEG options for output image.
@example
// Convert any input to very high quality JPEG output
const data = await sharp(input)
.jpeg({
quality: 100,
chromaSubsampling: '4:4:4'
})
.toBuffer();
@param {Object} [options] - output options
@param {Number} [options.quality=80] - quality, integer 1-100
@param {Boolean} [options.progressive=false] - use progressive (interlace) scan
@param {String} [options.chromaSubsampling='4:2:0'] - set to '4:4:4' to prevent chroma subsampling when quality <= 90
@param {Boolean} [options.trellisQuantisation=false] - apply trellis quantisation, requires libvips compiled with support for mozjpeg
@param {Boolean} [options.overshootDeringing=false] - apply overshoot deringing, requires libvips compiled with support for mozjpeg
@param {Boolean} [options.optimiseScans=false] - optimise progressive scans, forces progressive, requires libvips compiled with support for mozjpeg
@param {Boolean} [options.optimizeScans=false] - alternative spelling of optimiseScans
@param {Boolean} [options.optimiseCoding=true] - optimise Huffman coding tables
@param {Boolean} [options.optimizeCoding=true] - alternative spelling of optimiseCoding
@param {Number} [options.quantisationTable=0] - quantization table to use, integer 0-8, requires libvips compiled with support for mozjpeg
@param {Number} [options.quantizationTable=0] - alternative spelling of quantisationTable
@param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
@returns {Sharp}
@throws {Error} Invalid options
|
[
"Use",
"these",
"JPEG",
"options",
"for",
"output",
"image",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/output.js#L159-L206
|
train
|
lovell/sharp
|
lib/output.js
|
png
|
function png (options) {
if (is.object(options)) {
if (is.defined(options.progressive)) {
this._setBooleanOption('pngProgressive', options.progressive);
}
if (is.defined(options.compressionLevel)) {
if (is.integer(options.compressionLevel) && is.inRange(options.compressionLevel, 0, 9)) {
this.options.pngCompressionLevel = options.compressionLevel;
} else {
throw new Error('Invalid compressionLevel (integer, 0-9) ' + options.compressionLevel);
}
}
if (is.defined(options.adaptiveFiltering)) {
this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
}
if (is.defined(options.palette)) {
this._setBooleanOption('pngPalette', options.palette);
if (this.options.pngPalette) {
if (is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
this.options.pngQuality = options.quality;
} else {
throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
}
}
const colours = options.colours || options.colors;
if (is.defined(colours)) {
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
this.options.pngColours = colours;
} else {
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
}
}
if (is.defined(options.dither)) {
if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
this.options.pngDither = options.dither;
} else {
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
}
}
}
}
}
return this._updateFormatOut('png', options);
}
|
javascript
|
function png (options) {
if (is.object(options)) {
if (is.defined(options.progressive)) {
this._setBooleanOption('pngProgressive', options.progressive);
}
if (is.defined(options.compressionLevel)) {
if (is.integer(options.compressionLevel) && is.inRange(options.compressionLevel, 0, 9)) {
this.options.pngCompressionLevel = options.compressionLevel;
} else {
throw new Error('Invalid compressionLevel (integer, 0-9) ' + options.compressionLevel);
}
}
if (is.defined(options.adaptiveFiltering)) {
this._setBooleanOption('pngAdaptiveFiltering', options.adaptiveFiltering);
}
if (is.defined(options.palette)) {
this._setBooleanOption('pngPalette', options.palette);
if (this.options.pngPalette) {
if (is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 0, 100)) {
this.options.pngQuality = options.quality;
} else {
throw is.invalidParameterError('quality', 'integer between 0 and 100', options.quality);
}
}
const colours = options.colours || options.colors;
if (is.defined(colours)) {
if (is.integer(colours) && is.inRange(colours, 2, 256)) {
this.options.pngColours = colours;
} else {
throw is.invalidParameterError('colours', 'integer between 2 and 256', colours);
}
}
if (is.defined(options.dither)) {
if (is.number(options.dither) && is.inRange(options.dither, 0, 1)) {
this.options.pngDither = options.dither;
} else {
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
}
}
}
}
}
return this._updateFormatOut('png', options);
}
|
[
"function",
"png",
"(",
"options",
")",
"{",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
")",
"{",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"progressive",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'pngProgressive'",
",",
"options",
".",
"progressive",
")",
";",
"}",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"compressionLevel",
")",
")",
"{",
"if",
"(",
"is",
".",
"integer",
"(",
"options",
".",
"compressionLevel",
")",
"&&",
"is",
".",
"inRange",
"(",
"options",
".",
"compressionLevel",
",",
"0",
",",
"9",
")",
")",
"{",
"this",
".",
"options",
".",
"pngCompressionLevel",
"=",
"options",
".",
"compressionLevel",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid compressionLevel (integer, 0-9) '",
"+",
"options",
".",
"compressionLevel",
")",
";",
"}",
"}",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"adaptiveFiltering",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'pngAdaptiveFiltering'",
",",
"options",
".",
"adaptiveFiltering",
")",
";",
"}",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"palette",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'pngPalette'",
",",
"options",
".",
"palette",
")",
";",
"if",
"(",
"this",
".",
"options",
".",
"pngPalette",
")",
"{",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"quality",
")",
")",
"{",
"if",
"(",
"is",
".",
"integer",
"(",
"options",
".",
"quality",
")",
"&&",
"is",
".",
"inRange",
"(",
"options",
".",
"quality",
",",
"0",
",",
"100",
")",
")",
"{",
"this",
".",
"options",
".",
"pngQuality",
"=",
"options",
".",
"quality",
";",
"}",
"else",
"{",
"throw",
"is",
".",
"invalidParameterError",
"(",
"'quality'",
",",
"'integer between 0 and 100'",
",",
"options",
".",
"quality",
")",
";",
"}",
"}",
"const",
"colours",
"=",
"options",
".",
"colours",
"||",
"options",
".",
"colors",
";",
"if",
"(",
"is",
".",
"defined",
"(",
"colours",
")",
")",
"{",
"if",
"(",
"is",
".",
"integer",
"(",
"colours",
")",
"&&",
"is",
".",
"inRange",
"(",
"colours",
",",
"2",
",",
"256",
")",
")",
"{",
"this",
".",
"options",
".",
"pngColours",
"=",
"colours",
";",
"}",
"else",
"{",
"throw",
"is",
".",
"invalidParameterError",
"(",
"'colours'",
",",
"'integer between 2 and 256'",
",",
"colours",
")",
";",
"}",
"}",
"if",
"(",
"is",
".",
"defined",
"(",
"options",
".",
"dither",
")",
")",
"{",
"if",
"(",
"is",
".",
"number",
"(",
"options",
".",
"dither",
")",
"&&",
"is",
".",
"inRange",
"(",
"options",
".",
"dither",
",",
"0",
",",
"1",
")",
")",
"{",
"this",
".",
"options",
".",
"pngDither",
"=",
"options",
".",
"dither",
";",
"}",
"else",
"{",
"throw",
"is",
".",
"invalidParameterError",
"(",
"'dither'",
",",
"'number between 0.0 and 1.0'",
",",
"options",
".",
"dither",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"this",
".",
"_updateFormatOut",
"(",
"'png'",
",",
"options",
")",
";",
"}"
] |
Use these PNG options for output image.
PNG output is always full colour at 8 or 16 bits per pixel.
Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
@example
// Convert any input to PNG output
const data = await sharp(input)
.png()
.toBuffer();
@param {Object} [options]
@param {Boolean} [options.progressive=false] - use progressive (interlace) scan
@param {Number} [options.compressionLevel=9] - zlib compression level, 0-9
@param {Boolean} [options.adaptiveFiltering=false] - use adaptive row filtering
@param {Boolean} [options.palette=false] - quantise to a palette-based image with alpha transparency support, requires libvips compiled with support for libimagequant
@param {Number} [options.quality=100] - use the lowest number of colours needed to achieve given quality, requires libvips compiled with support for libimagequant
@param {Number} [options.colours=256] - maximum number of palette entries, requires libvips compiled with support for libimagequant
@param {Number} [options.colors=256] - alternative spelling of `options.colours`, requires libvips compiled with support for libimagequant
@param {Number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, requires libvips compiled with support for libimagequant
@param {Boolean} [options.force=true] - force PNG output, otherwise attempt to use input format
@returns {Sharp}
@throws {Error} Invalid options
|
[
"Use",
"these",
"PNG",
"options",
"for",
"output",
"image",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/output.js#L233-L277
|
train
|
lovell/sharp
|
lib/output.js
|
webp
|
function webp (options) {
if (is.object(options) && is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
this.options.webpQuality = options.quality;
} else {
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
}
}
if (is.object(options) && is.defined(options.alphaQuality)) {
if (is.integer(options.alphaQuality) && is.inRange(options.alphaQuality, 0, 100)) {
this.options.webpAlphaQuality = options.alphaQuality;
} else {
throw new Error('Invalid webp alpha quality (integer, 0-100) ' + options.alphaQuality);
}
}
if (is.object(options) && is.defined(options.lossless)) {
this._setBooleanOption('webpLossless', options.lossless);
}
if (is.object(options) && is.defined(options.nearLossless)) {
this._setBooleanOption('webpNearLossless', options.nearLossless);
}
return this._updateFormatOut('webp', options);
}
|
javascript
|
function webp (options) {
if (is.object(options) && is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
this.options.webpQuality = options.quality;
} else {
throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
}
}
if (is.object(options) && is.defined(options.alphaQuality)) {
if (is.integer(options.alphaQuality) && is.inRange(options.alphaQuality, 0, 100)) {
this.options.webpAlphaQuality = options.alphaQuality;
} else {
throw new Error('Invalid webp alpha quality (integer, 0-100) ' + options.alphaQuality);
}
}
if (is.object(options) && is.defined(options.lossless)) {
this._setBooleanOption('webpLossless', options.lossless);
}
if (is.object(options) && is.defined(options.nearLossless)) {
this._setBooleanOption('webpNearLossless', options.nearLossless);
}
return this._updateFormatOut('webp', options);
}
|
[
"function",
"webp",
"(",
"options",
")",
"{",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
"&&",
"is",
".",
"defined",
"(",
"options",
".",
"quality",
")",
")",
"{",
"if",
"(",
"is",
".",
"integer",
"(",
"options",
".",
"quality",
")",
"&&",
"is",
".",
"inRange",
"(",
"options",
".",
"quality",
",",
"1",
",",
"100",
")",
")",
"{",
"this",
".",
"options",
".",
"webpQuality",
"=",
"options",
".",
"quality",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid quality (integer, 1-100) '",
"+",
"options",
".",
"quality",
")",
";",
"}",
"}",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
"&&",
"is",
".",
"defined",
"(",
"options",
".",
"alphaQuality",
")",
")",
"{",
"if",
"(",
"is",
".",
"integer",
"(",
"options",
".",
"alphaQuality",
")",
"&&",
"is",
".",
"inRange",
"(",
"options",
".",
"alphaQuality",
",",
"0",
",",
"100",
")",
")",
"{",
"this",
".",
"options",
".",
"webpAlphaQuality",
"=",
"options",
".",
"alphaQuality",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid webp alpha quality (integer, 0-100) '",
"+",
"options",
".",
"alphaQuality",
")",
";",
"}",
"}",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
"&&",
"is",
".",
"defined",
"(",
"options",
".",
"lossless",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'webpLossless'",
",",
"options",
".",
"lossless",
")",
";",
"}",
"if",
"(",
"is",
".",
"object",
"(",
"options",
")",
"&&",
"is",
".",
"defined",
"(",
"options",
".",
"nearLossless",
")",
")",
"{",
"this",
".",
"_setBooleanOption",
"(",
"'webpNearLossless'",
",",
"options",
".",
"nearLossless",
")",
";",
"}",
"return",
"this",
".",
"_updateFormatOut",
"(",
"'webp'",
",",
"options",
")",
";",
"}"
] |
Use these WebP options for output image.
@example
// Convert any input to lossless WebP output
const data = await sharp(input)
.webp({ lossless: true })
.toBuffer();
@param {Object} [options] - output options
@param {Number} [options.quality=80] - quality, integer 1-100
@param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
@param {Boolean} [options.lossless=false] - use lossless compression mode
@param {Boolean} [options.nearLossless=false] - use near_lossless compression mode
@param {Boolean} [options.force=true] - force WebP output, otherwise attempt to use input format
@returns {Sharp}
@throws {Error} Invalid options
|
[
"Use",
"these",
"WebP",
"options",
"for",
"output",
"image",
"."
] |
05d76eeadfe54713606a615185b2da047923406b
|
https://github.com/lovell/sharp/blob/05d76eeadfe54713606a615185b2da047923406b/lib/output.js#L297-L319
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.