-
Notifications
You must be signed in to change notification settings - Fork 7.6k
"close others" extension added to default extensions directory. #4590
Changes from 3 commits
d36c1e9
01c33fb
e8fae97
540e140
9e412f0
0bccd24
a288ce1
9086c1d
5f2c809
024b654
841a923
967738e
bd4018d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,29 +316,41 @@ define(function (require, exports, module) { | |
// Dispatch event | ||
$(exports).triggerHandler("workingSetAddList", [uniqueFileList]); | ||
} | ||
|
||
/** | ||
* Warning: low level API - use FILE_CLOSE command in most cases. | ||
* Removes the given file from the working set list, if it was in the list. Does not change | ||
* the current editor even if it's for this file. Does not prompt for unsaved changes. | ||
* @param {!FileEntry} file | ||
* @param {boolean=} true to suppress redraw after removal | ||
*/ | ||
function removeFromWorkingSet(file, suppressRedraw) { | ||
|
||
function _internalRemoveFromWorkingSet(file) { | ||
// If doc isn't in working set, do nothing | ||
var index = findInWorkingSet(file.fullPath); | ||
if (index === -1) { | ||
return; | ||
return false; | ||
} | ||
|
||
// Remove | ||
_workingSet.splice(index, 1); | ||
_workingSetMRUOrder.splice(findInWorkingSet(file.fullPath, _workingSetMRUOrder), 1); | ||
_workingSetAddedOrder.splice(findInWorkingSet(file.fullPath, _workingSetAddedOrder), 1); | ||
|
||
return true; | ||
} | ||
|
||
function removeFromWorkingSet(file, suppressRedraw) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor nit: this should be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually what would be better is if you could pass a string or an array to I think you could re-work the handlers for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can also use the new EcmaScript 5 Array.isArray() function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In project/WorkingSetView.js see
In comments it stated that it is used to show icon on the next file. But i removed this block and still i'm able to see icon on the next file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you want to remove this block. the icon shows up on mouse over so this is just to make sure that when you click the 'x' that it shows up when the item below moves up. |
||
if (_internalRemoveFromWorkingSet(file)) { | ||
$(exports).triggerHandler("workingSetRemove", [file, suppressRedraw]); | ||
} | ||
} | ||
|
||
function removeFilesFromWorkingSet(fileList) { | ||
if (!fileList) { | ||
return; | ||
} | ||
|
||
fileList.forEach(function (file) { | ||
_internalRemoveFromWorkingSet(file); | ||
}); | ||
|
||
// Dispatch event | ||
$(exports).triggerHandler("workingSetRemove", [file, suppressRedraw]); | ||
$(exports).triggerHandler("workingSetRemoveList", [fileList]); | ||
} | ||
|
||
|
||
/** | ||
* Removes all files from the working set list. | ||
|
@@ -569,7 +581,6 @@ define(function (require, exports, module) { | |
_removeAllFromWorkingSet(); | ||
} | ||
|
||
|
||
/** | ||
* Cleans up any loose Documents whose only ref is its own master Editor, and that Editor is not | ||
* rooted in the UI anywhere. This can happen if the Editor is auto-created via Document APIs that | ||
|
@@ -817,43 +828,32 @@ define(function (require, exports, module) { | |
* @param {boolean} isFolder True if path is a folder; False if it is a file. | ||
*/ | ||
function notifyPathNameChanged(oldName, newName, isFolder) { | ||
var i, path; | ||
|
||
// Update open documents. This will update _currentDocument too, since | ||
// the current document is always open. | ||
var keysToDelete = []; | ||
for (path in _openDocuments) { | ||
if (_openDocuments.hasOwnProperty(path)) { | ||
if (FileUtils.isAffectedWhenRenaming(path, oldName, newName, isFolder)) { | ||
var doc = _openDocuments[path]; | ||
|
||
// Copy value to new key | ||
var newKey = path.replace(oldName, newName); | ||
_openDocuments[newKey] = doc; | ||
|
||
keysToDelete.push(path); | ||
|
||
// Update document file | ||
FileUtils.updateFileEntryPath(doc.file, oldName, newName, isFolder); | ||
doc._notifyFilePathChanged(); | ||
|
||
if (!isFolder) { | ||
// If the path name is a file, there can only be one matched entry in the open document | ||
// list, which we just updated. Break out of the for .. in loop. | ||
break; | ||
} | ||
} | ||
CollectionUtils.forEach(_openDocuments, function (doc, path) { | ||
if (FileUtils.isAffectedWhenRenaming(path, oldName, newName, isFolder)) { | ||
// Copy value to new key | ||
var newKey = path.replace(oldName, newName); | ||
_openDocuments[newKey] = doc; | ||
|
||
keysToDelete.push(path); | ||
|
||
// Update document file | ||
FileUtils.updateFileEntryPath(doc.file, oldName, newName, isFolder); | ||
doc._notifyFilePathChanged(); | ||
} | ||
} | ||
}); | ||
|
||
// Delete the old keys | ||
for (i = 0; i < keysToDelete.length; i++) { | ||
delete _openDocuments[keysToDelete[i]]; | ||
} | ||
keysToDelete.forEach(function (fullPath) { | ||
delete _openDocuments[fullPath]; | ||
}); | ||
|
||
// Update working set | ||
for (i = 0; i < _workingSet.length; i++) { | ||
FileUtils.updateFileEntryPath(_workingSet[i], oldName, newName, isFolder); | ||
} | ||
_workingSet.forEach(function (fileEntry) { | ||
FileUtils.updateFileEntryPath(fileEntry, oldName, newName, isFolder); | ||
}); | ||
|
||
// Send a "fileNameChanged" event. This will trigger the views to update. | ||
$(exports).triggerHandler("fileNameChange", [oldName, newName]); | ||
|
@@ -951,6 +951,7 @@ define(function (require, exports, module) { | |
exports.addToWorkingSet = addToWorkingSet; | ||
exports.addListToWorkingSet = addListToWorkingSet; | ||
exports.removeFromWorkingSet = removeFromWorkingSet; | ||
exports.removeFilesFromWorkingSet = removeFilesFromWorkingSet; | ||
exports.getNextPrevFile = getNextPrevFile; | ||
exports.swapWorkingSetIndexes = swapWorkingSetIndexes; | ||
exports.sortWorkingSet = sortWorkingSet; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, regexp: true, indent: 4, maxerr: 50 */ | ||
/*global define, $, brackets, window, document */ | ||
|
||
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
var Menus = brackets.getModule("command/Menus"), | ||
CommandManager = brackets.getModule("command/CommandManager"), | ||
Commands = brackets.getModule("command/Commands"), | ||
dm = brackets.getModule("document/DocumentManager"), | ||
docCH = brackets.getModule("document/DocumentCommandHandlers"), | ||
strings = brackets.getModule("i18n!nls/strings"), | ||
settings = JSON.parse(require("text!settings.json")), | ||
working_set_cmenu = Menus.getContextMenu(Menus.ContextMenuIds.WORKING_SET_MENU), | ||
close_others = "file.close_others", | ||
close_above = "file.close_above", | ||
close_below = "file.close_below"; | ||
|
||
function handleClose(mode) { | ||
|
||
var targetIndex = dm.findInWorkingSet(dm.getCurrentDocument().file.fullPath), | ||
workingSet = dm.getWorkingSet().slice(0), | ||
start = (mode === close_below) ? (targetIndex + 1) : 0, | ||
end = (mode === close_above) ? (targetIndex) : (workingSet.length), | ||
docList = [], | ||
i; | ||
|
||
if (mode === close_others) { | ||
end--; | ||
workingSet.splice(targetIndex, 1); | ||
} | ||
|
||
for (i = start; i < end; i++) { | ||
docList.push(workingSet[i]); | ||
} | ||
|
||
docCH.handleFileCloseList(docList); | ||
} | ||
|
||
if (settings.close_below) { | ||
CommandManager.register(strings.CMD_FILE_CLOSE_BELOW, close_below, function () { | ||
handleClose(close_below); | ||
}); | ||
working_set_cmenu.addMenuItem(close_below, "", Menus.AFTER, Commands.FILE_CLOSE); | ||
} | ||
|
||
if (settings.close_others) { | ||
CommandManager.register(strings.CMD_FILE_CLOSE_OTHERS, close_others, function () { | ||
handleClose(close_others); | ||
}); | ||
working_set_cmenu.addMenuItem(close_others, "", Menus.AFTER, Commands.FILE_CLOSE); | ||
} | ||
|
||
if (settings.close_above) { | ||
CommandManager.register(strings.CMD_FILE_CLOSE_ABOVE, close_above, function () { | ||
handleClose(close_above); | ||
}); | ||
working_set_cmenu.addMenuItem(close_above, "", Menus.AFTER, Commands.FILE_CLOSE); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"close_others": true, | ||
"close_above": true, | ||
"close_below": true | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JeffryBooher Shall we enable only "close others"? Because, it would annoy users by showing other two (close_above and close_below) all the time. If i once know how to add and remove menus dynamically we can add them. what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I say show them. If it becomes a problem we can easily turn it off There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. consider if there is only one file in the working set, it will still show "Close Others", "Close Others Above" and "Close Others Below". So i should work next to add and remove menus intelligently based user click. So if you wish, i can down those two flags and give pull request for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered it and the convention is to disable the menu items which we have a story for and we will be working soon. So leave them enabled for now and then we'll have to fix it so they are disabled when the first/last item are selected later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we have many menu items that are enabled when they shouldn't be so we are aware of the problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh. that's cool. just making sure you know this nit. then, no problem. let me do those small change and give PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every other API in this file is exposed as a command instead of directly. For consistency it seems like this one should be the same way.