_id
stringlengths 2
6
| title
stringlengths 0
58
| partition
stringclasses 3
values | text
stringlengths 52
373k
| language
stringclasses 1
value | meta_information
dict |
|---|---|---|---|---|---|
q17200
|
removeMenuItemEventListeners
|
train
|
function removeMenuItemEventListeners(menuItem) {
menuItem._command
.off("enabledStateChange", menuItem._enabledChanged)
.off("checkedStateChange", menuItem._checkedChanged)
.off("nameChange", menuItem._nameChanged)
.off("keyBindingAdded", menuItem._keyBindingAdded)
.off("keyBindingRemoved", menuItem._keyBindingRemoved);
}
|
javascript
|
{
"resource": ""
}
|
q17201
|
_insertInList
|
train
|
function _insertInList($list, $element, position, $relativeElement) {
// Determine where to insert. Default is LAST.
var inserted = false;
if (position) {
// Adjust relative position for menu section positions since $relativeElement
// has already been resolved by _getRelativeMenuItem() to a menuItem
if (position === FIRST_IN_SECTION) {
position = BEFORE;
} else if (position === LAST_IN_SECTION) {
position = AFTER;
}
if (position === FIRST) {
$list.prepend($element);
inserted = true;
} else if ($relativeElement && $relativeElement.length > 0) {
if (position === AFTER) {
$relativeElement.after($element);
inserted = true;
} else if (position === BEFORE) {
$relativeElement.before($element);
inserted = true;
}
}
}
// Default to LAST
if (!inserted) {
$list.append($element);
}
}
|
javascript
|
{
"resource": ""
}
|
q17202
|
MenuItem
|
train
|
function MenuItem(id, command) {
this.id = id;
this.isDivider = (command === DIVIDER);
this.isNative = false;
if (!this.isDivider && command !== SUBMENU) {
// Bind event handlers
this._enabledChanged = this._enabledChanged.bind(this);
this._checkedChanged = this._checkedChanged.bind(this);
this._nameChanged = this._nameChanged.bind(this);
this._keyBindingAdded = this._keyBindingAdded.bind(this);
this._keyBindingRemoved = this._keyBindingRemoved.bind(this);
this._command = command;
this._command
.on("enabledStateChange", this._enabledChanged)
.on("checkedStateChange", this._checkedChanged)
.on("nameChange", this._nameChanged)
.on("keyBindingAdded", this._keyBindingAdded)
.on("keyBindingRemoved", this._keyBindingRemoved);
}
}
|
javascript
|
{
"resource": ""
}
|
q17203
|
addMenu
|
train
|
function addMenu(name, id, position, relativeID) {
name = _.escape(name);
var $menubar = $("#titlebar .nav"),
menu;
if (!name || !id) {
console.error("call to addMenu() is missing required parameters");
return null;
}
// Guard against duplicate menu ids
if (menuMap[id]) {
console.log("Menu added with same name and id of existing Menu: " + id);
return null;
}
menu = new Menu(id);
menuMap[id] = menu;
if (!_isHTMLMenu(id)) {
brackets.app.addMenu(name, id, position, relativeID, function (err) {
switch (err) {
case NO_ERROR:
// Make sure name is up to date
brackets.app.setMenuTitle(id, name, function (err) {
if (err) {
console.error("setMenuTitle() -- error: " + err);
}
});
break;
case ERR_UNKNOWN:
console.error("addMenu(): Unknown Error when adding the menu " + id);
break;
case ERR_INVALID_PARAMS:
console.error("addMenu(): Invalid Parameters when adding the menu " + id);
break;
case ERR_NOT_FOUND:
console.error("addMenu(): Menu with command " + relativeID + " could not be found when adding the menu " + id);
break;
default:
console.error("addMenu(): Unknown Error (" + err + ") when adding the menu " + id);
}
});
return menu;
}
var $toggle = $("<a href='#' class='dropdown-toggle' data-toggle='dropdown'>" + name + "</a>"),
$popUp = $("<ul class='dropdown-menu'></ul>"),
$newMenu = $("<li class='dropdown' id='" + id + "'></li>").append($toggle).append($popUp);
// Insert menu
var $relativeElement = relativeID && $(_getHTMLMenu(relativeID));
_insertInList($menubar, $newMenu, position, $relativeElement);
// Install ESC key handling
PopUpManager.addPopUp($popUp, closeAll, false);
// todo error handling
return menu;
}
|
javascript
|
{
"resource": ""
}
|
q17204
|
removeMenu
|
train
|
function removeMenu(id) {
var menu,
commandID = "";
if (!id) {
console.error("removeMenu(): missing required parameter: id");
return;
}
if (!menuMap[id]) {
console.error("removeMenu(): menu id not found: %s", id);
return;
}
// Remove all of the menu items in the menu
menu = getMenu(id);
_.forEach(menuItemMap, function (value, key) {
if (_.startsWith(key, id)) {
if (value.isDivider) {
menu.removeMenuDivider(key);
} else {
commandID = value.getCommand();
menu.removeMenuItem(commandID);
}
}
});
if (_isHTMLMenu(id)) {
$(_getHTMLMenu(id)).remove();
} else {
brackets.app.removeMenu(id, function (err) {
if (err) {
console.error("removeMenu() -- id not found: " + id + " (error: " + err + ")");
}
});
}
delete menuMap[id];
}
|
javascript
|
{
"resource": ""
}
|
q17205
|
ContextMenu
|
train
|
function ContextMenu(id) {
Menu.apply(this, arguments);
var $newMenu = $("<li class='dropdown context-menu' id='" + StringUtils.jQueryIdEscape(id) + "'></li>"),
$popUp = $("<ul class='dropdown-menu'></ul>"),
$toggle = $("<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>").hide();
// assemble the menu fragments
$newMenu.append($toggle).append($popUp);
// insert into DOM
$("#context-menu-bar > ul").append($newMenu);
var self = this;
PopUpManager.addPopUp($popUp,
function () {
self.close();
},
false);
// Listen to ContextMenu's beforeContextMenuOpen event to first close other popups
PopUpManager.listenToContextMenu(this);
}
|
javascript
|
{
"resource": ""
}
|
q17206
|
registerContextMenu
|
train
|
function registerContextMenu(id) {
if (!id) {
console.error("call to registerContextMenu() is missing required parameters");
return null;
}
// Guard against duplicate menu ids
if (contextMenuMap[id]) {
console.log("Context Menu added with same name and id of existing Context Menu: " + id);
return null;
}
var cmenu = new ContextMenu(id);
contextMenuMap[id] = cmenu;
return cmenu;
}
|
javascript
|
{
"resource": ""
}
|
q17207
|
getServer
|
train
|
function getServer(localPath) {
var provider, server, i;
for (i = 0; i < _serverProviders.length; i++) {
provider = _serverProviders[i];
server = provider.create();
if (server.canServe(localPath)) {
return server;
}
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q17208
|
registerServer
|
train
|
function registerServer(provider, priority) {
if (!provider.create) {
console.error("Incompatible live development server provider");
return;
}
var providerObj = {};
providerObj.create = provider.create;
providerObj.priority = priority || 0;
_serverProviders.push(providerObj);
_serverProviders.sort(_providerSort);
return providerObj;
}
|
javascript
|
{
"resource": ""
}
|
q17209
|
removeServer
|
train
|
function removeServer(provider) {
var i;
for (i = 0; i < _serverProviders.length; i++) {
if (provider === _serverProviders[i]) {
_serverProviders.splice(i, 1);
}
}
}
|
javascript
|
{
"resource": ""
}
|
q17210
|
settingsToRegExp
|
train
|
function settingsToRegExp(settings, baseRegExp, defaultRegExp) {
var regExpString = "";
if (settings instanceof Array && settings.length > 0) {
// Append base settings to user settings. The base
// settings are builtin and cannot be overridden.
if (baseRegExp) {
settings.push("/" + baseRegExp.source + "/");
}
// convert each string, with optional wildcards to an equivalent
// string in a regular expression.
settings.forEach(function (value, index) {
if (typeof value === "string") {
var isRegExp = value[0] === '/' && value[value.length - 1] === '/';
if (isRegExp) {
value = value.substring(1, value.length - 1);
} else {
value = StringUtils.regexEscape(value);
// convert user input wildcard, "*" or "?", to a regular
// expression. We can just replace the escaped "*" or "?"
// since we know it is a wildcard.
value = value.replace("\\?", ".?");
value = value.replace("\\*", ".*");
// Add "^" and "$" to prevent matching in the middle of strings.
value = "^" + value + "$";
}
if (index > 0) {
regExpString += "|";
}
regExpString = regExpString.concat(value);
}
});
}
if (!regExpString) {
var defaultParts = [];
if (baseRegExp) {
defaultParts.push(baseRegExp.source);
}
if (defaultRegExp) {
defaultParts.push(defaultRegExp.source);
}
if (defaultParts.length > 0) {
regExpString = defaultParts.join("|");
} else {
return null;
}
}
return new RegExp(regExpString);
}
|
javascript
|
{
"resource": ""
}
|
q17211
|
Preferences
|
train
|
function Preferences(prefs) {
var BASE_EXCLUDED_DIRECTORIES = null, /* if the user has settings, we don't exclude anything by default */
// exclude node_modules for performance reasons and because we don't do full hinting for those anyhow.
DEFAULT_EXCLUDED_DIRECTORIES = /node_modules/,
// exclude require and jquery since we have special knowledge of those
BASE_EXCLUDED_FILES = /^require.*\.js$|^jquery.*\.js$/,
DEFAULT_MAX_FILE_COUNT = 100,
DEFAULT_MAX_FILE_SIZE = 512 * 1024;
if (prefs) {
this._excludedDirectories = settingsToRegExp(prefs["excluded-directories"],
BASE_EXCLUDED_DIRECTORIES,
DEFAULT_EXCLUDED_DIRECTORIES);
this._excludedFiles = settingsToRegExp(prefs["excluded-files"],
BASE_EXCLUDED_FILES);
this._maxFileCount = prefs["max-file-count"];
this._maxFileSize = prefs["max-file-size"];
// sanity check values
if (!this._maxFileCount || this._maxFileCount < 0) {
this._maxFileCount = DEFAULT_MAX_FILE_COUNT;
}
if (!this._maxFileSize || this._maxFileSize < 0) {
this._maxFileSize = DEFAULT_MAX_FILE_SIZE;
}
} else {
this._excludedDirectories = DEFAULT_EXCLUDED_DIRECTORIES;
this._excludedFiles = BASE_EXCLUDED_FILES;
this._maxFileCount = DEFAULT_MAX_FILE_COUNT;
this._maxFileSize = DEFAULT_MAX_FILE_SIZE;
}
}
|
javascript
|
{
"resource": ""
}
|
q17212
|
InlineMenu
|
train
|
function InlineMenu(editor, menuText) {
/**
* The list of items to display
*
* @type {Array.<{id: number, name: string>}
*/
this.items = [];
/**
* The selected position in the list; otherwise -1.
*
* @type {number}
*/
this.selectedIndex = -1;
/**
* Is the list currently open?
*
* @type {boolean}
*/
this.opened = false;
/**
* The editor context
*
* @type {Editor}
*/
this.editor = editor;
/**
* The menu selection callback function
*
* @type {Function}
*/
this.handleSelect = null;
/**
* The menu closure callback function
*
* @type {Function}
*/
this.handleClose = null;
/**
* The menu object
*
* @type {jQuery.Object}
*/
this.$menu =
$("<li class='dropdown inlinemenu-menu'></li>")
.append($("<a href='#' class='dropdown-toggle' data-toggle='dropdown'></a>")
.hide())
.append("<ul class='dropdown-menu'>" +
"<li class='inlinemenu-header'>" +
"<a>" + menuText + "</a>" +
"</li>" +
"</ul>");
this._keydownHook = this._keydownHook.bind(this);
}
|
javascript
|
{
"resource": ""
}
|
q17213
|
_findFileInMRUList
|
train
|
function _findFileInMRUList(paneId, file) {
return _.findIndex(_mruList, function (record) {
return (record.file.fullPath === file.fullPath && record.paneId === paneId);
});
}
|
javascript
|
{
"resource": ""
}
|
q17214
|
isExclusiveToPane
|
train
|
function isExclusiveToPane(file, paneId) {
paneId = paneId === ACTIVE_PANE && _activePaneId ? _activePaneId : paneId;
var index = _.findIndex(_mruList, function (record) {
return (record.file.fullPath === file.fullPath && record.paneId !== paneId);
});
return index === -1;
}
|
javascript
|
{
"resource": ""
}
|
q17215
|
_getPane
|
train
|
function _getPane(paneId) {
paneId = _resolvePaneId(paneId);
if (_panes[paneId]) {
return _panes[paneId];
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q17216
|
_makeFileMostRecent
|
train
|
function _makeFileMostRecent(paneId, file) {
var index,
entry,
pane = _getPane(paneId);
if (!_traversingFileList) {
pane.makeViewMostRecent(file);
index = _findFileInMRUList(pane.id, file);
entry = _makeMRUListEntry(file, pane.id);
if (index !== -1) {
_mruList.splice(index, 1);
}
if (_findFileInMRUList(pane.id, file) !== -1) {
console.log(file.fullPath + " duplicated in mru list");
}
// add it to the front of the list
_mruList.unshift(entry);
}
}
|
javascript
|
{
"resource": ""
}
|
q17217
|
_makePaneMostRecent
|
train
|
function _makePaneMostRecent(paneId) {
var pane = _getPane(paneId);
if (pane.getCurrentlyViewedFile()) {
_makeFileMostRecent(paneId, pane.getCurrentlyViewedFile());
}
}
|
javascript
|
{
"resource": ""
}
|
q17218
|
_activeEditorChange
|
train
|
function _activeEditorChange(e, current) {
if (current) {
var $container = current.$el.parent().parent(),
pane = _getPaneFromElement($container);
if (pane) {
// Editor is a full editor
if (pane.id !== _activePaneId) {
// we just need to set the active pane in this case
// it will dispatch the currentFileChange message as well
// as dispatching other events when the active pane changes
setActivePaneId(pane.id);
}
} else {
// Editor is an inline editor, find the parent pane
var parents = $container.parents(".view-pane");
if (parents.length === 1) {
$container = $(parents[0]);
pane = _getPaneFromElement($container);
if (pane) {
if (pane.id !== _activePaneId) {
// activate the pane which will put focus in the pane's doc
setActivePaneId(pane.id);
// reset the focus to the inline editor
current.focus();
}
}
}
}
}
}
|
javascript
|
{
"resource": ""
}
|
q17219
|
_forEachPaneOrPanes
|
train
|
function _forEachPaneOrPanes(paneId, callback) {
if (paneId === ALL_PANES) {
_.forEach(_panes, callback);
} else {
callback(_getPane(paneId));
}
}
|
javascript
|
{
"resource": ""
}
|
q17220
|
cacheScrollState
|
train
|
function cacheScrollState(paneId) {
_forEachPaneOrPanes(paneId, function (pane) {
_paneScrollStates[pane.id] = pane.getScrollState();
});
}
|
javascript
|
{
"resource": ""
}
|
q17221
|
restoreAdjustedScrollState
|
train
|
function restoreAdjustedScrollState(paneId, heightDelta) {
_forEachPaneOrPanes(paneId, function (pane) {
pane.restoreAndAdjustScrollState(_paneScrollStates[pane.id], heightDelta);
delete _paneScrollStates[pane.id];
});
}
|
javascript
|
{
"resource": ""
}
|
q17222
|
getWorkingSet
|
train
|
function getWorkingSet(paneId) {
var result = [];
_forEachPaneOrPanes(paneId, function (pane) {
var viewList = pane.getViewList();
result = _.union(result, viewList);
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
q17223
|
getAllOpenFiles
|
train
|
function getAllOpenFiles() {
var result = getWorkingSet(ALL_PANES);
_.forEach(_panes, function (pane) {
var file = pane.getCurrentlyViewedFile();
if (file) {
result = _.union(result, [file]);
}
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
q17224
|
getWorkingSetSize
|
train
|
function getWorkingSetSize(paneId) {
var result = 0;
_forEachPaneOrPanes(paneId, function (pane) {
result += pane.getViewListSize();
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
q17225
|
findInAllWorkingSets
|
train
|
function findInAllWorkingSets(fullPath) {
var index,
result = [];
_.forEach(_panes, function (pane) {
index = pane.findInViewList(fullPath);
if (index >= 0) {
result.push({paneId: pane.id, index: index});
}
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
q17226
|
addToWorkingSet
|
train
|
function addToWorkingSet(paneId, file, index, force) {
// look for the file to have already been added to another pane
var pane = _getPane(paneId);
if (!pane) {
throw new Error("invalid pane id: " + paneId);
}
var result = pane.reorderItem(file, index, force),
entry = _makeMRUListEntry(file, pane.id);
// handles the case of save as so that the file remains in the
// the same location in the working set as the file that was renamed
if (result === pane.ITEM_FOUND_NEEDS_SORT) {
console.warn("pane.reorderItem returned pane.ITEM_FOUND_NEEDS_SORT which shouldn't happen " + file);
exports.trigger("workingSetSort", pane.id);
} else if (result === pane.ITEM_NOT_FOUND) {
index = pane.addToViewList(file, index);
if (_findFileInMRUList(pane.id, file) === -1) {
// Add to or update the position in MRU
if (pane.getCurrentlyViewedFile() === file) {
_mruList.unshift(entry);
} else {
_mruList.push(entry);
}
}
exports.trigger("workingSetAdd", file, index, pane.id);
}
}
|
javascript
|
{
"resource": ""
}
|
q17227
|
addListToWorkingSet
|
train
|
function addListToWorkingSet(paneId, fileList) {
var uniqueFileList,
pane = _getPane(paneId);
uniqueFileList = pane.addListToViewList(fileList);
uniqueFileList.forEach(function (file) {
if (_findFileInMRUList(pane.id, file) !== -1) {
console.log(file.fullPath + " duplicated in mru list");
}
_mruList.push(_makeMRUListEntry(file, pane.id));
});
exports.trigger("workingSetAddList", uniqueFileList, pane.id);
// find all of the files that could be added but were not
var unsolvedList = fileList.filter(function (item) {
// if the file open in another pane, then add it to the list of unsolvedList
return (pane.findInViewList(item.fullPath) === -1 && _getPaneIdForPath(item.fullPath));
});
// Use the pane id of the first one in the list for pane id and recurse
// if we add more panes, then this will recurse until all items in the list are satisified
if (unsolvedList.length) {
addListToWorkingSet(_getPaneIdForPath(unsolvedList[0].fullPath), unsolvedList);
}
}
|
javascript
|
{
"resource": ""
}
|
q17228
|
_removeFileFromMRU
|
train
|
function _removeFileFromMRU(paneId, file) {
var index,
compare = function (record) {
return (record.file === file && record.paneId === paneId);
};
// find and remove all instances
do {
index = _.findIndex(_mruList, compare);
if (index !== -1) {
_mruList.splice(index, 1);
}
} while (index !== -1);
}
|
javascript
|
{
"resource": ""
}
|
q17229
|
_removeView
|
train
|
function _removeView(paneId, file, suppressRedraw) {
var pane = _getPane(paneId);
if (pane.removeView(file)) {
_removeFileFromMRU(pane.id, file);
exports.trigger("workingSetRemove", file, suppressRedraw, pane.id);
}
}
|
javascript
|
{
"resource": ""
}
|
q17230
|
_moveView
|
train
|
function _moveView(sourcePaneId, destinationPaneId, file, destinationIndex) {
var result = new $.Deferred(),
sourcePane = _getPane(sourcePaneId),
destinationPane = _getPane(destinationPaneId);
sourcePane.moveView(file, destinationPane, destinationIndex)
.done(function () {
// remove existing entry from mrulist for the same document if present
_removeFileFromMRU(destinationPane.id, file);
// update the mru list
_mruList.every(function (record) {
if (record.file === file && record.paneId === sourcePane.id) {
record.paneId = destinationPane.id;
return false;
}
return true;
});
exports.trigger("workingSetMove", file, sourcePane.id, destinationPane.id);
result.resolve();
});
return result.promise();
}
|
javascript
|
{
"resource": ""
}
|
q17231
|
_removeDeletedFileFromMRU
|
train
|
function _removeDeletedFileFromMRU(e, fullPath) {
var index,
compare = function (record) {
return (record.file.fullPath === fullPath);
};
// find and remove all instances
do {
index = _.findIndex(_mruList, compare);
if (index !== -1) {
_mruList.splice(index, 1);
}
} while (index !== -1);
}
|
javascript
|
{
"resource": ""
}
|
q17232
|
_sortWorkingSet
|
train
|
function _sortWorkingSet(paneId, compareFn) {
_forEachPaneOrPanes(paneId, function (pane) {
pane.sortViewList(compareFn);
exports.trigger("workingSetSort", pane.id);
});
}
|
javascript
|
{
"resource": ""
}
|
q17233
|
_moveWorkingSetItem
|
train
|
function _moveWorkingSetItem(paneId, fromIndex, toIndex) {
var pane = _getPane(paneId);
pane.moveWorkingSetItem(fromIndex, toIndex);
exports.trigger("workingSetSort", pane.id);
exports.trigger("_workingSetDisableAutoSort", pane.id);
}
|
javascript
|
{
"resource": ""
}
|
q17234
|
_swapWorkingSetListIndexes
|
train
|
function _swapWorkingSetListIndexes(paneId, index1, index2) {
var pane = _getPane(paneId);
pane.swapViewListIndexes(index1, index2);
exports.trigger("workingSetSort", pane.id);
exports.trigger("_workingSetDisableAutoSort", pane.id);
}
|
javascript
|
{
"resource": ""
}
|
q17235
|
traverseToNextViewByMRU
|
train
|
function traverseToNextViewByMRU(direction) {
var file = getCurrentlyViewedFile(),
paneId = getActivePaneId(),
index = _.findIndex(_mruList, function (record) {
return (record.file === file && record.paneId === paneId);
});
return ViewUtils.traverseViewArray(_mruList, index, direction);
}
|
javascript
|
{
"resource": ""
}
|
q17236
|
traverseToNextViewInListOrder
|
train
|
function traverseToNextViewInListOrder(direction) {
var file = getCurrentlyViewedFile(),
curPaneId = getActivePaneId(),
allFiles = [],
index;
getPaneIdList().forEach(function (paneId) {
var paneFiles = getWorkingSet(paneId).map(function (file) {
return { file: file, pane: paneId };
});
allFiles = allFiles.concat(paneFiles);
});
index = _.findIndex(allFiles, function (record) {
return (record.file === file && record.pane === curPaneId);
});
return ViewUtils.traverseViewArray(allFiles, index, direction);
}
|
javascript
|
{
"resource": ""
}
|
q17237
|
_synchronizePaneSize
|
train
|
function _synchronizePaneSize(pane, forceRefresh) {
var available;
if (_orientation === VERTICAL) {
available = _$el.innerWidth();
} else {
available = _$el.innerHeight();
}
// Update the pane's sizer element if it has one and update the max size
Resizer.resyncSizer(pane.$el);
pane.$el.data("maxsize", available - MIN_PANE_SIZE);
pane.updateLayout(forceRefresh);
}
|
javascript
|
{
"resource": ""
}
|
q17238
|
_updateLayout
|
train
|
function _updateLayout(event, viewAreaHeight, forceRefresh) {
var available;
if (_orientation === VERTICAL) {
available = _$el.innerWidth();
} else {
available = _$el.innerHeight();
}
_.forEach(_panes, function (pane) {
// For VERTICAL orientation, we set the second pane to be width: auto
// so that it resizes to fill the available space in the containing div
// unfortunately, that doesn't work in the HORIZONTAL orientation so we
// must update the height and convert it into a percentage
if (pane.id === SECOND_PANE && _orientation === HORIZONTAL) {
var percentage = ((_panes[FIRST_PANE].$el.height() + 1) / available);
pane.$el.css("height", 100 - (percentage * 100) + "%");
}
_synchronizePaneSize(pane, forceRefresh);
});
}
|
javascript
|
{
"resource": ""
}
|
q17239
|
_initialLayout
|
train
|
function _initialLayout(forceRefresh) {
var panes = Object.keys(_panes),
size = 100 / panes.length;
_.forEach(_panes, function (pane) {
if (pane.id === FIRST_PANE) {
if (_orientation === VERTICAL) {
pane.$el.css({height: "100%",
width: size + "%",
float: "left"
});
} else {
pane.$el.css({ height: size + "%",
width: "100%"
});
}
} else {
if (_orientation === VERTICAL) {
pane.$el.css({ height: "100%",
width: "auto",
float: "none"
});
} else {
pane.$el.css({ width: "100%",
height: "50%"
});
}
}
_synchronizePaneSize(pane, forceRefresh);
});
}
|
javascript
|
{
"resource": ""
}
|
q17240
|
_createPaneIfNecessary
|
train
|
function _createPaneIfNecessary(paneId) {
var newPane;
if (!_panes.hasOwnProperty(paneId)) {
newPane = new Pane(paneId, _$el);
_panes[paneId] = newPane;
exports.trigger("paneCreate", newPane.id);
newPane.$el.on("click.mainview dragover.mainview", function () {
setActivePaneId(newPane.id);
});
newPane.on("viewListChange.mainview", function () {
_updatePaneHeaders();
exports.trigger("workingSetUpdate", newPane.id);
});
newPane.on("currentViewChange.mainview", function (e, newView, oldView) {
_updatePaneHeaders();
if (_activePaneId === newPane.id) {
exports.trigger("currentFileChange",
newView && newView.getFile(),
newPane.id, oldView && oldView.getFile(),
newPane.id);
}
});
newPane.on("viewDestroy.mainView", function (e, view) {
_removeFileFromMRU(newPane.id, view.getFile());
});
}
return newPane;
}
|
javascript
|
{
"resource": ""
}
|
q17241
|
_makeFirstPaneResizable
|
train
|
function _makeFirstPaneResizable() {
var firstPane = _panes[FIRST_PANE];
Resizer.makeResizable(firstPane.$el,
_orientation === HORIZONTAL ? Resizer.DIRECTION_VERTICAL : Resizer.DIRECTION_HORIZONTAL,
_orientation === HORIZONTAL ? Resizer.POSITION_BOTTOM : Resizer.POSITION_RIGHT,
MIN_PANE_SIZE, false, false, false, true, true);
firstPane.$el.on("panelResizeUpdate", function () {
_updateLayout();
});
}
|
javascript
|
{
"resource": ""
}
|
q17242
|
_doSplit
|
train
|
function _doSplit(orientation) {
var firstPane, newPane;
if (orientation === _orientation) {
return;
}
firstPane = _panes[FIRST_PANE];
Resizer.removeSizable(firstPane.$el);
if (_orientation) {
_$el.removeClass("split-" + _orientation.toLowerCase());
}
_$el.addClass("split-" + orientation.toLowerCase());
_orientation = orientation;
newPane = _createPaneIfNecessary(SECOND_PANE);
_makeFirstPaneResizable();
// reset the layout to 50/50 split
// if we changed orientation then
// the percentages are reset as well
_initialLayout();
exports.trigger("paneLayoutChange", _orientation);
// if new pane was created, and original pane is not empty, make new pane the active pane
if (newPane && getCurrentlyViewedFile(firstPane.id)) {
setActivePaneId(newPane.id);
}
}
|
javascript
|
{
"resource": ""
}
|
q17243
|
_open
|
train
|
function _open(paneId, file, optionsIn) {
var result = new $.Deferred(),
options = optionsIn || {};
function doPostOpenActivation() {
if (!options.noPaneActivate) {
setActivePaneId(paneId);
}
}
if (!file || !_getPane(paneId)) {
return result.reject("bad argument").promise();
}
// See if there is already a view for the file
var pane = _getPane(paneId);
// See if there is a factory to create a view for this file
// we want to do this first because, we don't want our internal
// editor to edit files for which there are suitable viewfactories
var factory = MainViewFactory.findSuitableFactoryForPath(file.fullPath);
if (factory) {
file.exists(function (fileError, fileExists) {
if (fileExists) {
// let the factory open the file and create a view for it
factory.openFile(file, pane)
.done(function () {
// if we opened a file that isn't in the project
// then add the file to the working set
if (!ProjectManager.isWithinProject(file.fullPath)) {
addToWorkingSet(paneId, file);
}
doPostOpenActivation();
result.resolve(file);
})
.fail(function (fileError) {
result.reject(fileError);
});
} else {
result.reject(fileError || FileSystemError.NOT_FOUND);
}
});
} else {
DocumentManager.getDocumentForPath(file.fullPath, file)
.done(function (doc) {
if (doc) {
_edit(paneId, doc, $.extend({}, options, {
noPaneActivate: true
}));
doPostOpenActivation();
result.resolve(doc.file);
} else {
result.resolve(null);
}
})
.fail(function (fileError) {
result.reject(fileError);
});
}
result.done(function () {
_makeFileMostRecent(paneId, file);
});
return result;
}
|
javascript
|
{
"resource": ""
}
|
q17244
|
_mergePanes
|
train
|
function _mergePanes() {
if (_panes.hasOwnProperty(SECOND_PANE)) {
var firstPane = _panes[FIRST_PANE],
secondPane = _panes[SECOND_PANE],
fileList = secondPane.getViewList(),
lastViewed = getCurrentlyViewedFile();
Resizer.removeSizable(firstPane.$el);
firstPane.mergeFrom(secondPane);
exports.trigger("workingSetRemoveList", fileList, secondPane.id);
setActivePaneId(firstPane.id);
secondPane.$el.off(".mainview");
secondPane.off(".mainview");
secondPane.destroy();
delete _panes[SECOND_PANE];
exports.trigger("paneDestroy", secondPane.id);
exports.trigger("workingSetAddList", fileList, firstPane.id);
_mruList.forEach(function (record) {
if (record.paneId === secondPane.id) {
record.paneId = firstPane.id;
}
});
_$el.removeClass("split-" + _orientation.toLowerCase());
_orientation = null;
// this will set the remaining pane to 100%
_initialLayout();
exports.trigger("paneLayoutChange", _orientation);
// if the current view before the merger was in the pane
// that went away then reopen it so that it's now the current view again
if (lastViewed && getCurrentlyViewedFile() !== lastViewed) {
exports._open(firstPane.id, lastViewed);
}
}
}
|
javascript
|
{
"resource": ""
}
|
q17245
|
_close
|
train
|
function _close(paneId, file, optionsIn) {
var options = optionsIn || {};
_forEachPaneOrPanes(paneId, function (pane) {
if (pane.removeView(file, options.noOpenNextFile) && (paneId === ACTIVE_PANE || pane.id === paneId)) {
_removeFileFromMRU(pane.id, file);
exports.trigger("workingSetRemove", file, false, pane.id);
return false;
}
});
}
|
javascript
|
{
"resource": ""
}
|
q17246
|
_closeList
|
train
|
function _closeList(paneId, fileList) {
_forEachPaneOrPanes(paneId, function (pane) {
var closedList = pane.removeViews(fileList);
closedList.forEach(function (file) {
_removeFileFromMRU(pane.id, file);
});
exports.trigger("workingSetRemoveList", closedList, pane.id);
});
}
|
javascript
|
{
"resource": ""
}
|
q17247
|
_closeAll
|
train
|
function _closeAll(paneId) {
_forEachPaneOrPanes(paneId, function (pane) {
var closedList = pane.getViewList();
closedList.forEach(function (file) {
_removeFileFromMRU(pane.id, file);
});
pane._reset();
exports.trigger("workingSetRemoveList", closedList, pane.id);
});
}
|
javascript
|
{
"resource": ""
}
|
q17248
|
_findPaneForDocument
|
train
|
function _findPaneForDocument(document) {
// First check for an editor view of the document
var pane = _getPaneFromElement($(document._masterEditor.$el.parent().parent()));
if (!pane) {
// No view of the document, it may be in a working set and not yet opened
var info = findInAllWorkingSets(document.file.fullPath).shift();
if (info) {
pane = _panes[info.paneId];
}
}
return pane;
}
|
javascript
|
{
"resource": ""
}
|
q17249
|
_destroyEditorIfNotNeeded
|
train
|
function _destroyEditorIfNotNeeded(document) {
if (!(document instanceof DocumentManager.Document)) {
throw new Error("_destroyEditorIfUnneeded() should be passed a Document");
}
if (document._masterEditor) {
// findPaneForDocument tries to locate the pane in which the document
// is either opened or will be opened (in the event that the document is
// in a working set but has yet to be opened) and then asks the pane
// to destroy the view if it doesn't need it anymore
var pane = _findPaneForDocument(document);
if (pane) {
// let the pane deceide if it wants to destroy the view if it's no needed
pane.destroyViewIfNotNeeded(document._masterEditor);
} else {
// in this case, the document isn't referenced at all so just destroy it
document._masterEditor.destroy();
}
}
}
|
javascript
|
{
"resource": ""
}
|
q17250
|
_saveViewState
|
train
|
function _saveViewState() {
function _computeSplitPercentage() {
var available,
used;
if (getPaneCount() === 1) {
// just short-circuit here and
// return 100% to avoid any rounding issues
return 1;
} else {
if (_orientation === VERTICAL) {
available = _$el.innerWidth();
used = _panes[FIRST_PANE].$el.width();
} else {
available = _$el.innerHeight();
used = _panes[FIRST_PANE].$el.height();
}
return used / available;
}
}
var projectRoot = ProjectManager.getProjectRoot(),
context = { location : { scope: "user",
layer: "project",
layerID: projectRoot.fullPath } },
state = {
orientation: _orientation,
activePaneId: getActivePaneId(),
splitPercentage: _computeSplitPercentage(),
panes: {
}
};
if (!projectRoot) {
return;
}
_.forEach(_panes, function (pane) {
state.panes[pane.id] = pane.saveState();
});
PreferencesManager.setViewState(PREFS_NAME, state, context);
}
|
javascript
|
{
"resource": ""
}
|
q17251
|
_initialize
|
train
|
function _initialize($container) {
if (_activePaneId) {
throw new Error("MainViewManager has already been initialized");
}
_$el = $container;
_createPaneIfNecessary(FIRST_PANE);
_activePaneId = FIRST_PANE;
// One-time init so the pane has the "active" appearance
_panes[FIRST_PANE]._handleActivePaneChange(undefined, _activePaneId);
_initialLayout();
// This ensures that unit tests that use this function
// get an event handler for workspace events and we don't listen
// to the event before we've been initialized
WorkspaceManager.on("workspaceUpdateLayout", _updateLayout);
// Listen to key Alt-W to toggle between panes
CommandManager.register(Strings.CMD_SWITCH_PANE_FOCUS, Commands.CMD_SWITCH_PANE_FOCUS, switchPaneFocus);
KeyBindingManager.addBinding(Commands.CMD_SWITCH_PANE_FOCUS, {key: 'Alt-W'});
}
|
javascript
|
{
"resource": ""
}
|
q17252
|
setLayoutScheme
|
train
|
function setLayoutScheme(rows, columns) {
if ((rows < 1) || (rows > 2) || (columns < 1) || (columns > 2) || (columns === 2 && rows === 2)) {
console.error("setLayoutScheme unsupported layout " + rows + ", " + columns);
return false;
}
if (rows === columns) {
_mergePanes();
} else if (rows > columns) {
_doSplit(HORIZONTAL);
} else {
_doSplit(VERTICAL);
}
return true;
}
|
javascript
|
{
"resource": ""
}
|
q17253
|
getLayoutScheme
|
train
|
function getLayoutScheme() {
var result = {
rows: 1,
columns: 1
};
if (_orientation === HORIZONTAL) {
result.rows = 2;
} else if (_orientation === VERTICAL) {
result.columns = 2;
}
return result;
}
|
javascript
|
{
"resource": ""
}
|
q17254
|
InlineTimingFunctionEditor
|
train
|
function InlineTimingFunctionEditor(timingFunction, startBookmark, endBookmark) {
this._timingFunction = timingFunction;
this._startBookmark = startBookmark;
this._endBookmark = endBookmark;
this._isOwnChange = false;
this._isHostChange = false;
this._origin = "+InlineTimingFunctionEditor_" + (lastOriginId++);
this._handleTimingFunctionChange = this._handleTimingFunctionChange.bind(this);
this._handleHostDocumentChange = this._handleHostDocumentChange.bind(this);
InlineWidget.call(this);
}
|
javascript
|
{
"resource": ""
}
|
q17255
|
performNpmInstallIfRequired
|
train
|
function performNpmInstallIfRequired(npmOptions, validationResult, callback) {
function finish() {
callback(null, validationResult);
}
var installDirectory = path.join(validationResult.extractDir, validationResult.commonPrefix);
var packageJson;
try {
packageJson = fs.readJsonSync(path.join(installDirectory, "package.json"));
} catch (e) {
packageJson = null;
}
if (!packageJson || !packageJson.dependencies || !Object.keys(packageJson.dependencies).length) {
return finish();
}
_performNpmInstall(installDirectory, npmOptions, function (err) {
if (err) {
validationResult.errors.push([Errors.NPM_INSTALL_FAILED, err.toString()]);
}
finish();
});
}
|
javascript
|
{
"resource": ""
}
|
q17256
|
showDialog
|
train
|
function showDialog() {
var currentSettings = getValues();
var newSettings = {};
var themes = _.map(loadedThemes, function (theme) { return theme; });
var template = $("<div>").append($settings).html();
var $template = $(Mustache.render(template, {"settings": currentSettings, "themes": themes, "Strings": Strings}));
// Select the correct theme.
var $currentThemeOption = $template
.find("[value='" + currentSettings.theme + "']");
if ($currentThemeOption.length === 0) {
$currentThemeOption = $template.find("[value='" + defaults.theme + "']");
}
$currentThemeOption.attr("selected", "selected");
$template
.find("[data-toggle=tab].default")
.tab("show");
$template
.on("change", "[data-target]:checkbox", function () {
var $target = $(this);
var attr = $target.attr("data-target");
newSettings[attr] = $target.is(":checked");
})
.on("input", "[data-target='fontSize']", function () {
var target = this;
var targetValue = $(this).val();
var $btn = $("#theme-settings-done-btn")[0];
// Make sure that the font size is expressed in terms
// we can handle (px or em). If not, 'done' button is
// disabled until input has been corrected.
if (target.checkValidity() === true) {
$btn.disabled = false;
newSettings["fontSize"] = targetValue;
} else {
$btn.disabled = true;
}
})
.on("input", "[data-target='fontFamily']", function () {
var targetValue = $(this).val();
newSettings["fontFamily"] = targetValue;
})
.on("change", "select", function () {
var $target = $(":selected", this);
var attr = $target.attr("data-target");
if (attr) {
prefs.set(attr, $target.val());
}
});
Dialogs.showModalDialogUsingTemplate($template).done(function (id) {
var setterFn;
if (id === "save") {
// Go through each new setting and apply it
Object.keys(newSettings).forEach(function (setting) {
if (defaults.hasOwnProperty(setting)) {
prefs.set(setting, newSettings[setting]);
} else {
// Figure out if the setting is in the ViewCommandHandlers, which means it is
// a font setting
setterFn = "set" + setting[0].toLocaleUpperCase() + setting.substr(1);
if (typeof ViewCommandHandlers[setterFn] === "function") {
ViewCommandHandlers[setterFn](newSettings[setting]);
}
}
});
} else if (id === "cancel") {
// Make sure we revert any changes to theme selection
prefs.set("theme", currentSettings.theme);
}
});
}
|
javascript
|
{
"resource": ""
}
|
q17257
|
getCurrentDocument
|
train
|
function getCurrentDocument() {
var file = MainViewManager.getCurrentlyViewedFile(MainViewManager.ACTIVE_PANE);
if (file) {
return getOpenDocumentForPath(file.fullPath);
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q17258
|
getWorkingSet
|
train
|
function getWorkingSet() {
DeprecationWarning.deprecationWarning("Use MainViewManager.getWorkingSet() instead of DocumentManager.getWorkingSet()", true);
return MainViewManager.getWorkingSet(MainViewManager.ALL_PANES)
.filter(function (file) {
// Legacy didn't allow for files with custom viewers
return !MainViewFactory.findSuitableFactoryForPath(file.fullPath);
});
}
|
javascript
|
{
"resource": ""
}
|
q17259
|
findInWorkingSet
|
train
|
function findInWorkingSet(fullPath) {
DeprecationWarning.deprecationWarning("Use MainViewManager.findInWorkingSet() instead of DocumentManager.findInWorkingSet()", true);
return MainViewManager.findInWorkingSet(MainViewManager.ACTIVE_PANE, fullPath);
}
|
javascript
|
{
"resource": ""
}
|
q17260
|
addToWorkingSet
|
train
|
function addToWorkingSet(file, index, forceRedraw) {
DeprecationWarning.deprecationWarning("Use MainViewManager.addToWorkingSet() instead of DocumentManager.addToWorkingSet()", true);
MainViewManager.addToWorkingSet(MainViewManager.ACTIVE_PANE, file, index, forceRedraw);
}
|
javascript
|
{
"resource": ""
}
|
q17261
|
removeListFromWorkingSet
|
train
|
function removeListFromWorkingSet(list) {
DeprecationWarning.deprecationWarning("Use CommandManager.execute(Commands.FILE_CLOSE_LIST, {PaneId: MainViewManager.ALL_PANES, fileList: list}) instead of DocumentManager.removeListFromWorkingSet()", true);
CommandManager.execute(Commands.FILE_CLOSE_LIST, {PaneId: MainViewManager.ALL_PANES, fileList: list});
}
|
javascript
|
{
"resource": ""
}
|
q17262
|
closeAll
|
train
|
function closeAll() {
DeprecationWarning.deprecationWarning("Use CommandManager.execute(Commands.FILE_CLOSE_ALL,{PaneId: MainViewManager.ALL_PANES}) instead of DocumentManager.closeAll()", true);
CommandManager.execute(Commands.FILE_CLOSE_ALL, {PaneId: MainViewManager.ALL_PANES});
}
|
javascript
|
{
"resource": ""
}
|
q17263
|
closeFullEditor
|
train
|
function closeFullEditor(file) {
DeprecationWarning.deprecationWarning("Use CommandManager.execute(Commands.FILE_CLOSE, {File: file} instead of DocumentManager.closeFullEditor()", true);
CommandManager.execute(Commands.FILE_CLOSE, {File: file});
}
|
javascript
|
{
"resource": ""
}
|
q17264
|
setCurrentDocument
|
train
|
function setCurrentDocument(doc) {
DeprecationWarning.deprecationWarning("Use CommandManager.execute(Commands.CMD_OPEN) instead of DocumentManager.setCurrentDocument()", true);
CommandManager.execute(Commands.CMD_OPEN, {fullPath: doc.file.fullPath});
}
|
javascript
|
{
"resource": ""
}
|
q17265
|
notifyPathDeleted
|
train
|
function notifyPathDeleted(fullPath) {
// FileSyncManager.syncOpenDocuments() does all the work prompting
// the user to save any unsaved changes and then calls us back
// via notifyFileDeleted
FileSyncManager.syncOpenDocuments(Strings.FILE_DELETED_TITLE);
var projectRoot = ProjectManager.getProjectRoot(),
context = {
location : {
scope: "user",
layer: "project",
layerID: projectRoot.fullPath
}
};
var encoding = PreferencesManager.getViewState("encoding", context);
delete encoding[fullPath];
PreferencesManager.setViewState("encoding", encoding, context);
if (!getOpenDocumentForPath(fullPath) &&
!MainViewManager.findInAllWorkingSets(fullPath).length) {
// For images not open in the workingset,
// FileSyncManager.syncOpenDocuments() will
// not tell us to close those views
exports.trigger("pathDeleted", fullPath);
}
}
|
javascript
|
{
"resource": ""
}
|
q17266
|
notifyPathNameChanged
|
train
|
function notifyPathNameChanged(oldName, newName) {
// Notify all open documents
_.forEach(_openDocuments, function (doc) {
// TODO: Only notify affected documents? For now _notifyFilePathChange
// just updates the language if the extension changed, so it's fine
// to call for all open docs.
doc._notifyFilePathChanged();
});
// Send a "fileNameChange" event. This will trigger the views to update.
exports.trigger("fileNameChange", oldName, newName);
}
|
javascript
|
{
"resource": ""
}
|
q17267
|
_proxyDeprecatedEvent
|
train
|
function _proxyDeprecatedEvent(eventName) {
DeprecationWarning.deprecateEvent(exports,
MainViewManager,
eventName,
eventName,
"DocumentManager." + eventName,
"MainViewManager." + eventName);
}
|
javascript
|
{
"resource": ""
}
|
q17268
|
marker
|
train
|
function marker(spec) {
var elt = window.document.createElement("div");
elt.className = spec;
return elt;
}
|
javascript
|
{
"resource": ""
}
|
q17269
|
updateFoldInfo
|
train
|
function updateFoldInfo(cm, from, to) {
var minFoldSize = prefs.getSetting("minFoldSize") || 2;
var opts = cm.state.foldGutter.options;
var fade = prefs.getSetting("hideUntilMouseover");
var $gutter = $(cm.getGutterElement());
var i = from;
function clear(m) {
return m.clear();
}
/**
* @private
* helper function to check if the given line is in a folded region in the editor.
* @param {number} line the
* @return {Object} the range that hides the specified line or undefine if the line is not hidden
*/
function _isCurrentlyFolded(line) {
var keys = Object.keys(cm._lineFolds), i = 0, range;
while (i < keys.length) {
range = cm._lineFolds[keys[i]];
if (range.from.line < line && range.to.line >= line) {
return range;
}
i++;
}
}
/**
This case is needed when unfolding a region that does not cause the viewport to change.
For instance in a file with about 15 lines, if some code regions are folded and unfolded, the
viewport change event isn't fired by CodeMirror. The setTimeout is a workaround to trigger the
gutter update after the viewport has been drawn.
*/
if (i === to) {
window.setTimeout(function () {
var vp = cm.getViewport();
updateFoldInfo(cm, vp.from, vp.to);
}, 200);
}
while (i < to) {
var sr = _isCurrentlyFolded(i), // surrounding range for the current line if one exists
range;
var mark = marker("CodeMirror-foldgutter-blank");
var pos = CodeMirror.Pos(i, 0),
func = opts.rangeFinder || CodeMirror.fold.auto;
// don't look inside collapsed ranges
if (sr) {
i = sr.to.line + 1;
} else {
range = cm._lineFolds[i] || (func && func(cm, pos));
if (!fade || (fade && $gutter.is(":hover"))) {
if (cm.isFolded(i)) {
// expand fold if invalid
if (range) {
mark = marker(opts.indicatorFolded);
} else {
cm.findMarksAt(pos).filter(isFold)
.forEach(clear);
}
} else {
if (range && range.to.line - range.from.line >= minFoldSize) {
mark = marker(opts.indicatorOpen);
}
}
}
cm.setGutterMarker(i, opts.gutter, mark);
i++;
}
}
}
|
javascript
|
{
"resource": ""
}
|
q17270
|
updateInViewport
|
train
|
function updateInViewport(cm, from, to) {
var vp = cm.getViewport(), state = cm.state.foldGutter;
from = isNaN(from) ? vp.from : from;
to = isNaN(to) ? vp.to : to;
if (!state) { return; }
cm.operation(function () {
updateFoldInfo(cm, from, to);
});
state.from = from;
state.to = to;
}
|
javascript
|
{
"resource": ""
}
|
q17271
|
getFoldOnLine
|
train
|
function getFoldOnLine(cm, line) {
var pos = CodeMirror.Pos(line, 0);
var folds = cm.findMarksAt(pos) || [];
folds = folds.filter(isFold);
return folds.length ? folds[0] : undefined;
}
|
javascript
|
{
"resource": ""
}
|
q17272
|
syncDocToFoldsCache
|
train
|
function syncDocToFoldsCache(cm, from, lineAdded) {
var minFoldSize = prefs.getSetting("minFoldSize") || 2;
var i, fold, range;
if (lineAdded <= 0) {
return;
}
for (i = from; i <= from + lineAdded; i = i + 1) {
fold = getFoldOnLine(cm, i);
if (fold) {
range = fold.find();
if (range && range.to.line - range.from.line >= minFoldSize) {
cm._lineFolds[i] = range;
i = range.to.line;
} else {
delete cm._lineFolds[i];
}
}
}
}
|
javascript
|
{
"resource": ""
}
|
q17273
|
moveRange
|
train
|
function moveRange(range, numLines) {
return {from: CodeMirror.Pos(range.from.line + numLines, range.from.ch),
to: CodeMirror.Pos(range.to.line + numLines, range.to.ch)};
}
|
javascript
|
{
"resource": ""
}
|
q17274
|
onCursorActivity
|
train
|
function onCursorActivity(cm) {
var state = cm.state.foldGutter;
var vp = cm.getViewport();
window.clearTimeout(state.changeUpdate);
state.changeUpdate = window.setTimeout(function () {
//need to render the entire visible viewport to remove fold marks rendered from previous selections if any
updateInViewport(cm, vp.from, vp.to);
}, 400);
}
|
javascript
|
{
"resource": ""
}
|
q17275
|
onFold
|
train
|
function onFold(cm, from, to) {
var state = cm.state.foldGutter;
updateFoldInfo(cm, from.line, from.line + 1);
}
|
javascript
|
{
"resource": ""
}
|
q17276
|
onUnFold
|
train
|
function onUnFold(cm, from, to) {
var state = cm.state.foldGutter;
var vp = cm.getViewport();
delete cm._lineFolds[from.line];
updateFoldInfo(cm, from.line, to.line || vp.to);
}
|
javascript
|
{
"resource": ""
}
|
q17277
|
init
|
train
|
function init() {
CodeMirror.defineOption("foldGutter", false, function (cm, val, old) {
if (old && old !== CodeMirror.Init) {
cm.clearGutter(cm.state.foldGutter.options.gutter);
cm.state.foldGutter = null;
cm.off("gutterClick", old.onGutterClick);
cm.off("change", onChange);
cm.off("viewportChange", onViewportChange);
cm.off("cursorActivity", onCursorActivity);
cm.off("fold", onFold);
cm.off("unfold", onUnFold);
cm.off("swapDoc", updateInViewport);
}
if (val) {
cm.state.foldGutter = new State(parseOptions(val));
updateInViewport(cm);
cm.on("gutterClick", val.onGutterClick);
cm.on("change", onChange);
cm.on("viewportChange", onViewportChange);
cm.on("cursorActivity", onCursorActivity);
cm.on("fold", onFold);
cm.on("unfold", onUnFold);
cm.on("swapDoc", updateInViewport);
}
});
}
|
javascript
|
{
"resource": ""
}
|
q17278
|
_getCondensedForm
|
train
|
function _getCondensedForm(filter) {
if (!_.isArray(filter)) {
return "";
}
// Format filter in condensed form
if (filter.length > 2) {
return filter.slice(0, 2).join(", ") + " " +
StringUtils.format(Strings.FILE_FILTER_CLIPPED_SUFFIX, filter.length - 2);
}
return filter.join(", ");
}
|
javascript
|
{
"resource": ""
}
|
q17279
|
_doPopulate
|
train
|
function _doPopulate() {
var dropdownItems = [Strings.NEW_FILE_FILTER, Strings.CLEAR_FILE_FILTER],
filterSets = PreferencesManager.get("fileFilters") || [];
if (filterSets.length) {
dropdownItems.push("---");
// Remove all the empty exclusion sets before concatenating to the dropdownItems.
filterSets = filterSets.filter(function (filter) {
return (_getCondensedForm(filter.patterns) !== "");
});
// FIRST_FILTER_INDEX needs to stay in sync with the number of static items (plus separator)
// ie. the number of items populated so far before we concatenate with the actual filter sets.
dropdownItems = dropdownItems.concat(filterSets);
}
_picker.items = dropdownItems;
}
|
javascript
|
{
"resource": ""
}
|
q17280
|
_getFilterIndex
|
train
|
function _getFilterIndex(filterSets, filter) {
var index = -1;
if (!filter || !filterSets.length) {
return index;
}
return _.findIndex(filterSets, _.partial(_.isEqual, filter));
}
|
javascript
|
{
"resource": ""
}
|
q17281
|
filterFileList
|
train
|
function filterFileList(compiledFilter, files) {
if (!compiledFilter) {
return files;
}
var re = new RegExp(compiledFilter);
return files.filter(function (f) {
return !re.test(f.fullPath);
});
}
|
javascript
|
{
"resource": ""
}
|
q17282
|
getPathsMatchingFilter
|
train
|
function getPathsMatchingFilter(compiledFilter, filePaths) {
if (!compiledFilter) {
return filePaths;
}
var re = new RegExp(compiledFilter);
return filePaths.filter(function (f) {
return f.match(re);
});
}
|
javascript
|
{
"resource": ""
}
|
q17283
|
_handleDeleteFilter
|
train
|
function _handleDeleteFilter(e) {
// Remove the filter set from the preferences and
// clear the active filter set index from view state.
var filterSets = PreferencesManager.get("fileFilters") || [],
activeFilterIndex = PreferencesManager.getViewState("activeFileFilter"),
filterIndex = $(e.target).parent().data("index") - FIRST_FILTER_INDEX;
// Don't let the click bubble upward.
e.stopPropagation();
filterSets.splice(filterIndex, 1);
PreferencesManager.set("fileFilters", filterSets);
if (activeFilterIndex === filterIndex) {
// Removing the active filter, so clear the active filter
// both in the view state.
setActiveFilter(null);
} else if (activeFilterIndex > filterIndex) {
// Adjust the active filter index after the removal of a filter set before it.
--activeFilterIndex;
setActiveFilter(filterSets[activeFilterIndex], activeFilterIndex);
}
_updatePicker();
_doPopulate();
_picker.refresh();
}
|
javascript
|
{
"resource": ""
}
|
q17284
|
_handleEditFilter
|
train
|
function _handleEditFilter(e) {
var filterSets = PreferencesManager.get("fileFilters") || [],
filterIndex = $(e.target).parent().data("index") - FIRST_FILTER_INDEX;
// Don't let the click bubble upward.
e.stopPropagation();
// Close the dropdown first before opening the edit filter dialog
// so that it will restore focus to the DOM element that has focus
// prior to opening it.
_picker.closeDropdown();
editFilter(filterSets[filterIndex], filterIndex);
}
|
javascript
|
{
"resource": ""
}
|
q17285
|
_handleListRendered
|
train
|
function _handleListRendered(event, $dropdown) {
var activeFilterIndex = PreferencesManager.getViewState("activeFileFilter"),
checkedItemIndex = (activeFilterIndex > -1) ? (activeFilterIndex + FIRST_FILTER_INDEX) : -1;
_picker.setChecked(checkedItemIndex, true);
$dropdown.find(".filter-trash-icon")
.on("click", _handleDeleteFilter);
$dropdown.find(".filter-edit-icon")
.on("click", _handleEditFilter);
}
|
javascript
|
{
"resource": ""
}
|
q17286
|
searchAndShowResults
|
train
|
function searchAndShowResults(queryInfo, scope, filter, replaceText, candidateFilesPromise) {
return FindInFiles.doSearchInScope(queryInfo, scope, filter, replaceText, candidateFilesPromise)
.done(function (zeroFilesToken) {
// Done searching all files: show results
if (FindInFiles.searchModel.hasResults()) {
_resultsView.open();
if (_findBar) {
_findBar.enable(true);
_findBar.focus();
}
} else {
_resultsView.close();
if (_findBar) {
var showMessage = false;
_findBar.enable(true);
if (zeroFilesToken === FindInFiles.ZERO_FILES_TO_SEARCH) {
_findBar.showError(StringUtils.format(Strings.FIND_IN_FILES_ZERO_FILES,
FindUtils.labelForScope(FindInFiles.searchModel.scope)), true);
} else {
showMessage = true;
}
_findBar.showNoResults(true, showMessage);
}
}
StatusBar.hideBusyIndicator();
})
.fail(function (err) {
console.log("find in files failed: ", err);
StatusBar.hideBusyIndicator();
});
}
|
javascript
|
{
"resource": ""
}
|
q17287
|
searchAndReplaceResults
|
train
|
function searchAndReplaceResults(queryInfo, scope, filter, replaceText, candidateFilesPromise) {
return FindInFiles.doSearchInScope(queryInfo, scope, filter, replaceText, candidateFilesPromise)
.done(function (zeroFilesToken) {
// Done searching all files: replace all
if (FindInFiles.searchModel.hasResults()) {
_finishReplaceBatch(FindInFiles.searchModel);
if (_findBar) {
_findBar.enable(true);
_findBar.focus();
}
}
StatusBar.hideBusyIndicator();
})
.fail(function (err) {
console.log("replace all failed: ", err);
StatusBar.hideBusyIndicator();
});
}
|
javascript
|
{
"resource": ""
}
|
q17288
|
_defferedSearch
|
train
|
function _defferedSearch() {
if (_findBar && _findBar._options.multifile && !_findBar._options.replace) {
_findBar.redoInstantSearch();
}
}
|
javascript
|
{
"resource": ""
}
|
q17289
|
ModalBar
|
train
|
function ModalBar(template, autoClose, animate) {
if (animate === undefined) {
animate = true;
}
this._handleKeydown = this._handleKeydown.bind(this);
this._handleFocusChange = this._handleFocusChange.bind(this);
this._$root = $("<div class='modal-bar'/>")
.html(template)
.insertBefore("#editor-holder");
if (animate) {
this._$root.addClass("popout offscreen");
// Forcing the renderer to do a layout, which will cause it to apply the transform for the "offscreen"
// class, so it will animate when you remove the class.
window.getComputedStyle(this._$root.get(0)).getPropertyValue("top");
this._$root.removeClass("popout offscreen");
}
// If something *other* than an editor (like another modal bar) has focus, set the focus
// to the editor here, before opening up the new modal bar. This ensures that the old
// focused item has time to react and close before the new modal bar is opened.
// See bugs #4287 and #3424
MainViewManager.focusActivePane();
if (autoClose) {
this._autoClose = true;
this._$root.on("keydown", this._handleKeydown);
window.document.body.addEventListener("focusin", this._handleFocusChange, true);
// Set focus to the first input field, or the first button if there is no input field.
// TODO: remove this logic?
var $firstInput = $("input[type='text']", this._$root).first();
if ($firstInput.length > 0) {
$firstInput.focus();
} else {
$("button", this._$root).first().focus();
}
}
// Preserve scroll position of the current full editor across the editor refresh, adjusting for the
// height of the modal bar so the code doesn't appear to shift if possible.
MainViewManager.cacheScrollState(MainViewManager.ALL_PANES);
WorkspaceManager.recomputeLayout(); // changes available ht for editor area
MainViewManager.restoreAdjustedScrollState(MainViewManager.ALL_PANES, this.height());
}
|
javascript
|
{
"resource": ""
}
|
q17290
|
simplify
|
train
|
function simplify(folds) {
if (!folds) {
return;
}
var res = {}, range;
Object.keys(folds).forEach(function (line) {
range = folds[line];
res[line] = Array.isArray(range) ? range : [[range.from.line, range.from.ch], [range.to.line, range.to.ch]];
});
return res;
}
|
javascript
|
{
"resource": ""
}
|
q17291
|
getFolds
|
train
|
function getFolds(path) {
var context = getViewStateContext();
var folds = PreferencesManager.getViewState(FOLDS_PREF_KEY, context);
return inflate(folds[path]);
}
|
javascript
|
{
"resource": ""
}
|
q17292
|
setFolds
|
train
|
function setFolds(path, folds) {
var context = getViewStateContext();
var allFolds = PreferencesManager.getViewState(FOLDS_PREF_KEY, context);
allFolds[path] = simplify(folds);
PreferencesManager.setViewState(FOLDS_PREF_KEY, allFolds, context);
}
|
javascript
|
{
"resource": ""
}
|
q17293
|
_convertToNumber
|
train
|
function _convertToNumber(str) {
if (typeof str !== "string") {
return { isNumber: false, value: null };
}
var val = parseFloat(+str, 10),
isNum = (typeof val === "number") && !isNaN(val) &&
(val !== Infinity) && (val !== -Infinity);
return {
isNumber: isNum,
value: val
};
}
|
javascript
|
{
"resource": ""
}
|
q17294
|
_getValidBezierParams
|
train
|
function _getValidBezierParams(match) {
var param,
// take ease-in-out as default value in case there are no params yet (or they are invalid)
def = [ ".42", "0", ".58", "1" ],
oldIndex = match.index, // we need to store the old match.index to re-set the index afterwards
originalString = match[0],
i;
if (match) {
match = match[1].split(",");
}
if (match) {
for (i = 0; i <= 3; i++) {
if (match[i]) {
match[i] = match[i].trim();
param = _convertToNumber(match[i]);
// Verify the param is a number
// If not, replace it with the default value
if (!param.isNumber) {
match[i] = undefined;
// Verify x coordinates are in 0-1 range
// If not, set them to the closest value in range
} else if (i === 0 || i === 2) {
if (param.value < 0) {
match[i] = "0";
} else if (param.value > 1) {
match[i] = "1";
}
}
}
if (!match[i]) {
match[i] = def[i];
}
}
} else {
match = def;
}
match = match.splice(0, 4); // make sure there are only 4 params
match = "cubic-bezier(" + match.join(", ") + ")";
match = match.match(BEZIER_CURVE_VALID_REGEX);
if (match) {
match.index = oldIndex; // re-set the index here to get the right context
match.originalString = originalString;
return match;
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q17295
|
_getValidStepsParams
|
train
|
function _getValidStepsParams(match) {
var param,
def = [ "5", "end" ],
params = def,
oldIndex = match.index, // we need to store the old match.index to re-set the index afterwards
originalString = match[0];
if (match) {
match = match[1].split(",");
}
if (match) {
if (match[0]) {
param = match[0].replace(/[\s\"']/g, ""); // replace possible trailing whitespace or leading quotes
param = _convertToNumber(param);
// Verify number_of_params is a number
// If not, replace it with the default value
if (!param.isNumber) {
param.value = def[0];
// Round number_of_params to an integer
} else if (param.value) {
param.value = Math.floor(param.value);
}
// Verify number_of_steps is >= 1
// If not, set them to the default value
if (param.value < 1) {
param.value = def[0];
}
params[0] = param.value;
}
if (match[1]) {
// little autocorrect feature: leading s gets 'start', everything else gets 'end'
param = match[1].replace(/[\s\"']/g, ""); // replace possible trailing whitespace or leading quotes
param = param.substr(0, 1);
if (param === "s") {
params[1] = "start";
} else {
params[1] = "end";
}
}
}
params = "steps(" + params.join(", ") + ")";
params = params.match(STEPS_VALID_REGEX);
if (params) {
params.index = oldIndex; // re-set the index here to get the right context
params.originalString = originalString;
return params;
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q17296
|
showHideHint
|
train
|
function showHideHint(hint, show, documentCode, editorCode) {
if (!hint || !hint.elem) {
return;
}
if (show) {
hint.shown = true;
hint.animationInProgress = false;
hint.elem.removeClass("fadeout");
hint.elem.html(StringUtils.format(Strings.INLINE_TIMING_EDITOR_INVALID, documentCode, editorCode));
hint.elem.css("display", "block");
} else if (hint.shown) {
hint.animationInProgress = true;
AnimationUtils.animateUsingClass(hint.elem[0], "fadeout", 750)
.done(function () {
if (hint.animationInProgress) { // do this only if the animation was not cancelled
hint.elem.hide();
}
hint.shown = false;
hint.animationInProgress = false;
});
} else {
hint.elem.hide();
}
}
|
javascript
|
{
"resource": ""
}
|
q17297
|
_tagMatch
|
train
|
function _tagMatch(match, type) {
switch (type) {
case BEZIER:
match.isBezier = true;
break;
case STEP:
match.isStep = true;
break;
}
return match;
}
|
javascript
|
{
"resource": ""
}
|
q17298
|
bezierCurveMatch
|
train
|
function bezierCurveMatch(str, lax) {
var match;
// First look for any cubic-bezier().
match = str.match(BEZIER_CURVE_VALID_REGEX);
if (match && _validateCubicBezierParams(match)) { // cubic-bezier() with valid params
return _tagMatch(match, BEZIER);
}
match = str.match(BEZIER_CURVE_GENERAL_REGEX);
if (match) {
match = _getValidBezierParams(match);
if (match && _validateCubicBezierParams(match)) {
return _tagMatch(match, BEZIER);
} else { // this should not happen!
window.console.log("brackets-cubic-bezier: TimingFunctionUtils._getValidBezierParams created invalid code");
}
}
// Next look for the ease functions (which are special cases of cubic-bezier())
if (lax) {
// For lax parsing, just look for the keywords
match = str.match(EASE_LAX_REGEX);
if (match) {
return _tagMatch(match, BEZIER);
}
} else {
// For strict parsing, start with a syntax verifying search
match = str.match(EASE_STRICT_REGEX);
if (match) {
// return exact match to keyword that we need for later replacement
return _tagMatch(str.match(EASE_LAX_REGEX), BEZIER);
}
}
// Final case is linear.
if (lax) {
// For lax parsing, just look for the keyword
match = str.match(LINEAR_LAX_REGEX);
if (match) {
return _tagMatch(match, BEZIER);
}
} else {
// The linear keyword can occur in other values, so for strict parsing we
// only detect when it's on same line as "transition" or "animation"
match = str.match(LINEAR_STRICT_REGEX);
if (match) {
// return exact match to keyword that we need for later replacement
return _tagMatch(str.match(LINEAR_LAX_REGEX), BEZIER);
}
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
q17299
|
stepsMatch
|
train
|
function stepsMatch(str, lax) {
var match;
// First look for any steps().
match = str.match(STEPS_VALID_REGEX);
if (match && _validateStepsParams(match)) { // cubic-bezier() with valid params
return _tagMatch(match, STEP);
}
match = str.match(STEPS_GENERAL_REGEX);
if (match) {
match = _getValidStepsParams(match);
if (match && _validateStepsParams(match)) {
return _tagMatch(match, STEP);
} else { // this should not happen!
window.console.log("brackets-steps: TimingFunctionUtils._getValidStepsParams created invalid code");
}
}
// Next look for the step functions (which are special cases of steps())
if (lax) {
// For lax parsing, just look for the keywords
match = str.match(STEP_LAX_REGEX);
if (match) {
return _tagMatch(match, STEP);
}
} else {
// For strict parsing, start with a syntax verifying search
match = str.match(STEP_STRICT_REGEX);
if (match) {
// return exact match to keyword that we need for later replacement
return _tagMatch(str.match(STEP_LAX_REGEX), STEP);
}
}
return null;
}
|
javascript
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.