From bbfbd3be07363096871c32eff270463cc8a9b3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Mon, 29 Oct 2012 21:01:35 -0300 Subject: [PATCH 1/6] WorkingSet Sort Feature --- src/brackets.js | 3 +- src/command/Commands.js | 4 + src/command/Menus.js | 5 + src/document/DocumentManager.js | 19 +- src/nls/root/strings.js | 4 + src/project/WorkingSetView.js | 19 +- src/utils/SortUtils.js | 334 ++++++++++++++++++++++++++++++++ 7 files changed, 382 insertions(+), 6 deletions(-) create mode 100644 src/utils/SortUtils.js diff --git a/src/brackets.js b/src/brackets.js index ed28fb88d41..689bec87edd 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -91,7 +91,8 @@ define(function (require, exports, module) { UrlParams = require("utils/UrlParams").UrlParams, NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem, PreferencesManager = require("preferences/PreferencesManager"), - Resizer = require("utils/Resizer"); + Resizer = require("utils/Resizer"), + SortUtils = require("utils/SortUtils"); // Local variables var params = new UrlParams(), diff --git a/src/command/Commands.js b/src/command/Commands.js index 90fbdbafbfe..0d88adaf636 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -73,6 +73,10 @@ define(function (require, exports, module) { exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize"; exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize"; exports.TOGGLE_JSLINT = "debug.jslint"; + exports.SORT_WORKINGSET_BY_NAME = "view.sortWorkingSetByName"; + exports.SORT_WORKINGSET_BY_TYPE = "view.sortWorkingSetByType"; + exports.SORT_WORKINGSET_BY_MRU = "view.sortWorkingSetByMRU"; + exports.SORT_WORKINGSET_AUTO = "view.sortWorkingSetAuto"; // Navigate exports.NAVIGATE_NEXT_DOC = "navigate.nextDoc"; diff --git a/src/command/Menus.js b/src/command/Menus.js index 59c4cf3a2b9..8db670023ce 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -974,6 +974,11 @@ define(function (require, exports, module) { working_set_cmenu.addMenuItem(Commands.FILE_SAVE); working_set_cmenu.addMenuItem(Commands.FILE_RENAME); working_set_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE); + working_set_cmenu.addMenuDivider(); + working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_NAME); + working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_TYPE); + working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_MRU); + working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_AUTO); var editor_cmenu = registerContextMenu(ContextMenuIds.EDITOR_MENU); editor_cmenu.addMenuItem(Commands.TOGGLE_QUICK_EDIT); diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index 39a5fea0dc9..5b022ca418e 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -176,6 +176,10 @@ define(function (require, exports, module) { return file.fullPath === fullPath; }); } + + function findInWorkingSetMRUOrder(fullPath) { + return findInWorkingSet(fullPath, _workingSetMRUOrder); + } /** * Returns all Documents that are 'open' in the UI somewhere (for now, this means open in an @@ -315,7 +319,18 @@ define(function (require, exports, module) { } } + /** + * Sorts _workingSet using the compare function + * @param {function(a, b)} compareFn - the function that will be used inside the JavaScript sort function. This function receives 2 + * as parameters and should return a value >0 (sort a to a lower index than b), =0 (leaves a and b unchanged with respect to each other) or <0 + * (sort b to a lower index than a) and must always returns the same value when given a specific pair of elements a and b as its two arguments. + * More information at: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort + */ + function sortWorkingSet(compareFn) { + _workingSet.sort(compareFn); + } + /** * Indicate that changes to currentDocument are temporary for now, and should not update the MRU * ordering of the working set. Useful for next/previous keyboard navigation (until Ctrl is released) @@ -1132,6 +1147,7 @@ define(function (require, exports, module) { exports.getOpenDocumentForPath = getOpenDocumentForPath; exports.getWorkingSet = getWorkingSet; exports.findInWorkingSet = findInWorkingSet; + exports.findInWorkingSetMRUOrder = findInWorkingSetMRUOrder; exports.getAllOpenDocuments = getAllOpenDocuments; exports.setCurrentDocument = setCurrentDocument; exports.addToWorkingSet = addToWorkingSet; @@ -1139,6 +1155,7 @@ define(function (require, exports, module) { exports.removeFromWorkingSet = removeFromWorkingSet; exports.getNextPrevFile = getNextPrevFile; exports.swapWorkingSetIndexes = swapWorkingSetIndexes; + exports.sortWorkingSet = sortWorkingSet; exports.beginDocumentNavigation = beginDocumentNavigation; exports.finalizeDocumentNavigation = finalizeDocumentNavigation; exports.closeFullEditor = closeFullEditor; @@ -1148,7 +1165,7 @@ define(function (require, exports, module) { // Setup preferences _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); - $(exports).bind("currentDocumentChange workingSetAdd workingSetAddList workingSetRemove workingSetRemoveList fileNameChange workingSetReorder", _savePreferences); + $(exports).bind("currentDocumentChange workingSetAdd workingSetAddList workingSetRemove workingSetRemoveList fileNameChange workingSetReorder workingSetSort", _savePreferences); // Performance measurements PerfUtils.createPerfMeasurement("DOCUMENT_MANAGER_GET_DOCUMENT_FOR_PATH", "DocumentManager.getDocumentForPath()"); diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index 2098587018e..5c29b217520 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -192,6 +192,10 @@ define({ "CMD_INCREASE_FONT_SIZE" : "Increase Font Size", "CMD_DECREASE_FONT_SIZE" : "Decrease Font Size", "CMD_RESTORE_FONT_SIZE" : "Restore Font Size", + "CMD_SORT_WORKINGSET_BY_NAME" : "Sort by Name", + "CMD_SORT_WORKINGSET_BY_TYPE" : "Sort by Type", + "CMD_SORT_WORKINGSET_BY_MRU" : "Sort by Recently View", + "CMD_SORT_WORKINGSET_AUTO" : "Automatic Sort", // Navigate menu Commands "NAVIGATE_MENU" : "Navigate", diff --git a/src/project/WorkingSetView.js b/src/project/WorkingSetView.js index fb8a445c9dc..d32e1ffe2de 100644 --- a/src/project/WorkingSetView.js +++ b/src/project/WorkingSetView.js @@ -244,10 +244,10 @@ define(function (require, exports, module) { // Restore the shadows ViewUtils.addScrollerShadow($openFilesContainer[0], null, true); } + + // Dispatch event + $(DocumentManager).triggerHandler("workingSetReorder"); } - - // Dispatch event - $(DocumentManager).triggerHandler("workingSetReorder"); } @@ -275,7 +275,6 @@ define(function (require, exports, module) { $openFilesContainer.on("mouseup.workingSet mouseleave.workingSet", function (e) { $openFilesContainer.off("mousemove.workingSet mouseup.workingSet mouseleave.workingSet"); drop(); - }); } @@ -506,6 +505,14 @@ define(function (require, exports, module) { _redraw(); } + + /** + * @private + */ + function _handleWorkingSetSort() { + _rebuildWorkingSet(); + _scrollSelectedDocIntoView(); + } /** * @private @@ -553,6 +560,10 @@ define(function (require, exports, module) { $(DocumentManager).on("workingSetRemoveList", function (event, removedFiles) { _handleRemoveList(removedFiles); }); + + $(DocumentManager).on("workingSetSort", function (event) { + _handleWorkingSetSort(); + }); $(DocumentManager).on("dirtyFlagChange", function (event, doc) { _handleDirtyFlagChanged(doc); diff --git a/src/utils/SortUtils.js b/src/utils/SortUtils.js new file mode 100644 index 00000000000..511e45a5b0e --- /dev/null +++ b/src/utils/SortUtils.js @@ -0,0 +1,334 @@ +/* + * Copyright (c) 2012 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, indent: 4, maxerr: 50 */ +/*global define, $ */ + +/** + * Manages the workingSet sort methods. + */ +define(function (require, exports, module) { + "use strict"; + + var Commands = require("command/Commands"), + CommandManager = require("command/CommandManager"), + DocumentManager = require("document/DocumentManager"), + PreferencesManager = require("preferences/PreferencesManager"), + AppInit = require("utils/AppInit"), + Strings = require("strings"); + + var PREFERENCES_CLIENT_ID = module.id, + defaultPrefs = { currentSort: null, automaticSort: false }; + + /** + * @private + * @type {PreferenceStorage} + */ + var _prefs = {}; + + /** + * @private + * @type {Array.} + */ + var _sorts = []; + + /** + * @private + * @type {} + */ + var _currentSort = null; + + /** + * @private + * @type {boolean} + */ + var _automaticSort = false; + + + /** + * Retrieves a Sort object by id + * @param {string} CommandID + * @return {} + */ + function get(commandID) { + return _sorts[commandID]; + } + + /** + * @return {boolean} Enabled state of Automatic Sort. + */ + function getAutomatic() { + return _automaticSort; + } + + + /** + * @private + * Removes current sort DocumentManager listeners. + */ + function _removeListeners() { + if (_currentSort && _currentSort.getEvents()) { + $(DocumentManager).off(".sort"); + } + } + + /** + * Disables Automatic Sort. + */ + function disableAutomatic() { + _automaticSort = false; + _removeListeners(); + _prefs.setValue("automaticSort", _automaticSort); + CommandManager.get(Commands.SORT_WORKINGSET_AUTO).setChecked(_automaticSort); + } + + /** + * @private + * Adds current sort DocumentManager listeners. + */ + function _addListeners() { + if (_automaticSort && _currentSort && _currentSort.getEvents()) { + $(DocumentManager) + .on(_currentSort.getEvents(), function () { + _currentSort.sort(); + }) + .on("workingSetReorder.sort", function () { + disableAutomatic(); + }); + } + } + + /** + * Enables Automatic Sort. + */ + function enableAutomatic() { + _automaticSort = true; + _addListeners(); + _prefs.setValue("automaticSort", _automaticSort); + CommandManager.get(Commands.SORT_WORKINGSET_AUTO).setChecked(_automaticSort); + } + + + /** + * @private + * Sets the current sort method and checks it on the context menu. + */ + function _setCurrentSort(newSort) { + var command; + if (_currentSort !== newSort) { + if (_currentSort !== null) { + command = CommandManager.get(_currentSort.getCommandID()); + if (command) { + command.setChecked(false); + } + } + command = CommandManager.get(newSort.getCommandID()); + if (command) { + command.setChecked(true); + } + _currentSort = newSort; + _prefs.setValue("currentSort", _currentSort.getCommandID()); + } + } + + + /** + * @constructor + * @private + * + * @param {string} commandID - valid command identifier. + * @param {function (a, b)} compareFn - a valid sort function (see register for a longer explanation). + * @param {string} events - space-separated DocumentManager possible events ending on ".sort". + */ + function Sort(commandID, compareFn, events) { + this._commandID = commandID; + this._compareFn = compareFn; + this._events = events; + } + + /** @return {CommandID} */ + Sort.prototype.getCommandID = function () { + return this._commandID; + }; + + /** @return {CompareFn} */ + Sort.prototype.getCompareFn = function () { + return this._compareFn; + }; + + /** @return {Events} */ + Sort.prototype.getEvents = function () { + return this._events; + }; + + /** + * Performs the sort and makes it the current sort method + */ + Sort.prototype.execute = function () { + _removeListeners(); + _setCurrentSort(this); + _addListeners(); + this.sort(); + }; + + /** + * Only performs the working set sort if this is the current sort + */ + Sort.prototype.sort = function () { + if (_currentSort === this) { + DocumentManager.sortWorkingSet(this._compareFn); + $(DocumentManager).triggerHandler("workingSetSort"); + } + }; + + + /** + * Registers a working set sort method. + * @param {string} commandID - valid command identifier used for the sort method. + * Core commands in Brackets use a simple command title as an id, for example "open.file". + * Extensions should use the following format: "author.myextension.mycommandname". + * For example, "lschmitt.csswizard.format.css". + * @param {function(a, b)} compareFn - the function that will be used inside the JavaScript sort function. This function receives 2 + * as parameters and should return a value >0 (sort a to a lower index than b), =0 (leaves a and b unchanged with respect to each other) or <0 + * (sort b to a lower index than a) and must always returns the same value when given a specific pair of elements a and b as its two arguments. + * More information at: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort + * @param {string} events - one or more space-separated event types that DocumentManger uses. Each event passed will trigger the automatic sort. + * @return {?Sort} + */ + function register(commandID, compareFn, events) { + if (_sorts[commandID]) { + console.log("Attempting to register an already-registered sort: " + commandID); + return; + } + if (!commandID || !compareFn) { + console.log("Attempting to register a sort with a missing id, or compare function: " + commandID); + return; + } + + // Adds ".sort" to the end of each event to make them specific for the automatic sort + if (events) { + events = events.split(" "); + events.forEach(function (event, index) { + events[index] = $.trim(events[index]) + ".sort"; + }); + events = events.join(" "); + } + + var sort = new Sort(commandID, compareFn, events); + _sorts[commandID] = sort; + return sort; + } + + + /** Command Handlers */ + function _handleSortWorkingSetByName() { + get(Commands.SORT_WORKINGSET_BY_NAME).execute(); + } + + function _handleSortWorkingSetByType() { + get(Commands.SORT_WORKINGSET_BY_TYPE).execute(); + } + + function _handleSortWorkingSetByMRU() { + get(Commands.SORT_WORKINGSET_BY_MRU).execute(); + } + + function _handleAutomaticSort() { + if (getAutomatic()) { + disableAutomatic(); + } else { + enableAutomatic(); + } + } + + + // Register sorts + register( + Commands.SORT_WORKINGSET_BY_NAME, + function (file1, file2) { + return file1.name.toLocaleLowerCase().localeCompare(file2.name.toLocaleLowerCase()); + }, + "workingSetAdd workingSetAddList" + ); + register( + Commands.SORT_WORKINGSET_BY_TYPE, + function (file1, file2) { + var ext1 = file1.name.split('.').pop(), + ext2 = file2.name.split('.').pop(), + cmp = ext1.localeCompare(ext2); + + if (cmp === 0) { + return file1.name.toLocaleLowerCase().localeCompare(file2.name.toLocaleLowerCase()); + } else { + return cmp; + } + }, + "workingSetAdd workingSetAddList" + ); + register( + Commands.SORT_WORKINGSET_BY_MRU, + function (file1, file2) { + var index1 = DocumentManager.findInWorkingSetMRUOrder(file1.fullPath), + index2 = DocumentManager.findInWorkingSetMRUOrder(file2.fullPath); + return index1 - index2; + }, + "workingSetAdd workingSetAddList" + ); + + + // Register command handlers + CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_NAME, Commands.SORT_WORKINGSET_BY_NAME, _handleSortWorkingSetByName); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_TYPE, Commands.SORT_WORKINGSET_BY_TYPE, _handleSortWorkingSetByType); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_MRU, Commands.SORT_WORKINGSET_BY_MRU, _handleSortWorkingSetByMRU); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_AUTO, Commands.SORT_WORKINGSET_AUTO, _handleAutomaticSort); + + + // Init PreferenceStorage + _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs); + + + // Initialize items dependent on extensions/workingSet + AppInit.appReady(function () { + var curSort = get(_prefs.getValue("currentSort")), + autoSort = _prefs.getValue("automaticSort"); + + if (curSort) { + _setCurrentSort(curSort); + } + if (autoSort) { + enableAutomatic(); + } + if (curSort && autoSort) { + curSort.sort(); + } + }); + + + // Define public API + exports.register = register; + exports.get = get; + exports.getAutomatic = getAutomatic; + exports.enableAutomatic = enableAutomatic; + exports.disableAutomatic = disableAutomatic; +}); From be130bbf47730dc31c7a44ba9b975e0519f81026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Wed, 31 Oct 2012 02:48:04 -0300 Subject: [PATCH 2/6] Several fixes --- src/command/Menus.js | 1 + src/document/DocumentManager.js | 42 ++++++++++++------------ src/utils/SortUtils.js | 57 ++++++++++++++++++++++++++------- 3 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/command/Menus.js b/src/command/Menus.js index 8db670023ce..26979dea06b 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -978,6 +978,7 @@ define(function (require, exports, module) { working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_NAME); working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_TYPE); working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_MRU); + working_set_cmenu.addMenuDivider(); working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_AUTO); var editor_cmenu = registerContextMenu(ContextMenuIds.EDITOR_MENU); diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index 7f2f8270c86..a0651ddc0a7 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -1143,27 +1143,27 @@ define(function (require, exports, module) { } // Define public API - exports.Document = Document; - exports.getCurrentDocument = getCurrentDocument; - exports.getDocumentForPath = getDocumentForPath; - exports.getOpenDocumentForPath = getOpenDocumentForPath; - exports.getWorkingSet = getWorkingSet; - exports.findInWorkingSet = findInWorkingSet; - exports.findInWorkingSetMRUOrder = findInWorkingSetMRUOrder; - exports.getAllOpenDocuments = getAllOpenDocuments; - exports.setCurrentDocument = setCurrentDocument; - exports.addToWorkingSet = addToWorkingSet; - exports.addListToWorkingSet = addListToWorkingSet; - exports.removeFromWorkingSet = removeFromWorkingSet; - exports.getNextPrevFile = getNextPrevFile; - exports.swapWorkingSetIndexes = swapWorkingSetIndexes; - exports.sortWorkingSet = sortWorkingSet; - exports.beginDocumentNavigation = beginDocumentNavigation; - exports.finalizeDocumentNavigation = finalizeDocumentNavigation; - exports.closeFullEditor = closeFullEditor; - exports.closeAll = closeAll; - exports.notifyFileDeleted = notifyFileDeleted; - exports.notifyPathNameChanged = notifyPathNameChanged; + exports.Document = Document; + exports.getCurrentDocument = getCurrentDocument; + exports.getDocumentForPath = getDocumentForPath; + exports.getOpenDocumentForPath = getOpenDocumentForPath; + exports.getWorkingSet = getWorkingSet; + exports.findInWorkingSet = findInWorkingSet; + exports.findInWorkingSetMRUOrder = findInWorkingSetMRUOrder; + exports.getAllOpenDocuments = getAllOpenDocuments; + exports.setCurrentDocument = setCurrentDocument; + exports.addToWorkingSet = addToWorkingSet; + exports.addListToWorkingSet = addListToWorkingSet; + exports.removeFromWorkingSet = removeFromWorkingSet; + exports.getNextPrevFile = getNextPrevFile; + exports.swapWorkingSetIndexes = swapWorkingSetIndexes; + exports.sortWorkingSet = sortWorkingSet; + exports.beginDocumentNavigation = beginDocumentNavigation; + exports.finalizeDocumentNavigation = finalizeDocumentNavigation; + exports.closeFullEditor = closeFullEditor; + exports.closeAll = closeAll; + exports.notifyFileDeleted = notifyFileDeleted; + exports.notifyPathNameChanged = notifyPathNameChanged; // Setup preferences _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID); diff --git a/src/utils/SortUtils.js b/src/utils/SortUtils.js index 511e45a5b0e..64d82417479 100644 --- a/src/utils/SortUtils.js +++ b/src/utils/SortUtils.js @@ -23,7 +23,7 @@ /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ -/*global define, $ */ +/*global define, $, window */ /** * Manages the workingSet sort methods. @@ -65,6 +65,12 @@ define(function (require, exports, module) { */ var _automaticSort = false; + /** + * @private + * @type {boolean} + * Used to know when to do the automatic sort for MRU order. + */ + var _openedDocument = false; /** * Retrieves a Sort object by id @@ -110,8 +116,8 @@ define(function (require, exports, module) { function _addListeners() { if (_automaticSort && _currentSort && _currentSort.getEvents()) { $(DocumentManager) - .on(_currentSort.getEvents(), function () { - _currentSort.sort(); + .on(_currentSort.getEvents(), function (event) { + _currentSort.callAutomaticFn(event); }) .on("workingSetReorder.sort", function () { disableAutomatic(); @@ -160,11 +166,13 @@ define(function (require, exports, module) { * @param {string} commandID - valid command identifier. * @param {function (a, b)} compareFn - a valid sort function (see register for a longer explanation). * @param {string} events - space-separated DocumentManager possible events ending on ".sort". + * @param {function (event)} automaticFn - the function that will be called when an automatic sort event is triggered. */ - function Sort(commandID, compareFn, events) { - this._commandID = commandID; - this._compareFn = compareFn; - this._events = events; + function Sort(commandID, compareFn, events, automaticFn) { + this._commandID = commandID; + this._compareFn = compareFn; + this._events = events; + this._automaticFn = automaticFn; } /** @return {CommandID} */ @@ -182,6 +190,11 @@ define(function (require, exports, module) { return this._events; }; + /** Calls automaticFn */ + Sort.prototype.callAutomaticFn = function (event) { + return this._automaticFn(event); + }; + /** * Performs the sort and makes it the current sort method */ @@ -214,9 +227,11 @@ define(function (require, exports, module) { * (sort b to a lower index than a) and must always returns the same value when given a specific pair of elements a and b as its two arguments. * More information at: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort * @param {string} events - one or more space-separated event types that DocumentManger uses. Each event passed will trigger the automatic sort. + * @param {function (event)} automaticFn - the function that will be called when an automatic sort event is triggered. + * If no function is passed the automatic sort will just call the sort function. * @return {?Sort} */ - function register(commandID, compareFn, events) { + function register(commandID, compareFn, events, automaticFn) { if (_sorts[commandID]) { console.log("Attempting to register an already-registered sort: " + commandID); return; @@ -230,12 +245,16 @@ define(function (require, exports, module) { if (events) { events = events.split(" "); events.forEach(function (event, index) { - events[index] = $.trim(events[index]) + ".sort"; + events[index] = events[index].trim() + ".sort"; }); events = events.join(" "); } - var sort = new Sort(commandID, compareFn, events); + automaticFn = automaticFn || function (event) { + _currentSort.sort(); + }; + + var sort = new Sort(commandID, compareFn, events, automaticFn); _sorts[commandID] = sort; return sort; } @@ -263,6 +282,7 @@ define(function (require, exports, module) { } + // Register sorts register( Commands.SORT_WORKINGSET_BY_NAME, @@ -293,7 +313,22 @@ define(function (require, exports, module) { index2 = DocumentManager.findInWorkingSetMRUOrder(file2.fullPath); return index1 - index2; }, - "workingSetAdd workingSetAddList" + "workingSetAdd workingSetAddList currentDocumentChange", + function (event) { + switch (event.type) { + case "workingSetAddList": + _openedDocument = true; + break; + case "currentDocumentChange": + if (_openedDocument) { + _currentSort.sort(); + _openedDocument = false; + } + break; + default: + _currentSort.sort(); + } + } ); From 25fa801d60b4dd93e07c75a09bce82c2601d8e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Wed, 31 Oct 2012 03:02:30 -0300 Subject: [PATCH 3/6] Minor update --- src/utils/SortUtils.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/utils/SortUtils.js b/src/utils/SortUtils.js index 64d82417479..073f60bdb0a 100644 --- a/src/utils/SortUtils.js +++ b/src/utils/SortUtils.js @@ -153,6 +153,8 @@ define(function (require, exports, module) { if (command) { command.setChecked(true); } + + CommandManager.get(Commands.SORT_WORKINGSET_AUTO).setEnabled(!!newSort.getEvents()); _currentSort = newSort; _prefs.setValue("currentSort", _currentSort.getCommandID()); } @@ -218,16 +220,17 @@ define(function (require, exports, module) { /** * Registers a working set sort method. - * @param {string} commandID - valid command identifier used for the sort method. + * @param {!string} commandID - valid command identifier used for the sort method. * Core commands in Brackets use a simple command title as an id, for example "open.file". * Extensions should use the following format: "author.myextension.mycommandname". * For example, "lschmitt.csswizard.format.css". - * @param {function(a, b)} compareFn - the function that will be used inside the JavaScript sort function. This function receives 2 + * @param {!function(a, b)} compareFn - the function that will be used inside the JavaScript sort function. This function receives 2 * as parameters and should return a value >0 (sort a to a lower index than b), =0 (leaves a and b unchanged with respect to each other) or <0 * (sort b to a lower index than a) and must always returns the same value when given a specific pair of elements a and b as its two arguments. * More information at: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort - * @param {string} events - one or more space-separated event types that DocumentManger uses. Each event passed will trigger the automatic sort. - * @param {function (event)} automaticFn - the function that will be called when an automatic sort event is triggered. + * @param {?string} events - one or more space-separated event types that DocumentManger uses. Each event passed will trigger the automatic sort. + * If noe events are passed, the automatic sort will be disabled for that sort method. + * @param {?function (event)} automaticFn - the function that will be called when an automatic sort event is triggered. * If no function is passed the automatic sort will just call the sort function. * @return {?Sort} */ From a8c67be2a1a398c7a261f645a9174ffc8d90a981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Wed, 31 Oct 2012 21:56:56 -0300 Subject: [PATCH 4/6] Fixes after review --- src/brackets.js | 2 +- src/document/DocumentManager.js | 16 ++++++--- src/{utils => project}/SortUtils.js | 53 +++++++++++++++-------------- 3 files changed, 40 insertions(+), 31 deletions(-) rename src/{utils => project}/SortUtils.js (84%) diff --git a/src/brackets.js b/src/brackets.js index 8efba0dcf32..35104837e4b 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -92,7 +92,7 @@ define(function (require, exports, module) { NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem, PreferencesManager = require("preferences/PreferencesManager"), Resizer = require("utils/Resizer"), - SortUtils = require("utils/SortUtils"); + SortUtils = require("project/SortUtils"); // Local variables var params = new UrlParams(), diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index a0651ddc0a7..ee003ece473 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -177,6 +177,12 @@ define(function (require, exports, module) { }); } + /** + * Returns the index of the file matching fullPath in _workingSetMRUOrder. + * Returns -1 if not found. + * @param {!string} fullPath + * @returns {number} index + */ function findInWorkingSetMRUOrder(fullPath) { return findInWorkingSet(fullPath, _workingSetMRUOrder); } @@ -323,13 +329,15 @@ define(function (require, exports, module) { /** * Sorts _workingSet using the compare function - * @param {function(a, b)} compareFn - the function that will be used inside the JavaScript sort function. This function receives 2 - * as parameters and should return a value >0 (sort a to a lower index than b), =0 (leaves a and b unchanged with respect to each other) or <0 - * (sort b to a lower index than a) and must always returns the same value when given a specific pair of elements a and b as its two arguments. - * More information at: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort + * @param {!function(FileEntry, FileEntry)} compareFn - the function that will be used inside JavaScript's + * sort function. The return a value should be >0 (sort a to a lower index than b), =0 (leaves a and b + * unchanged with respect to each other) or <0 (sort b to a lower index than a) and must always returns + * the same value when given a specific pair of elements a and b as its two arguments. + * Documentation: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort */ function sortWorkingSet(compareFn) { _workingSet.sort(compareFn); + $(exports).triggerHandler("workingSetSort"); } diff --git a/src/utils/SortUtils.js b/src/project/SortUtils.js similarity index 84% rename from src/utils/SortUtils.js rename to src/project/SortUtils.js index 073f60bdb0a..f0a6c482b9a 100644 --- a/src/utils/SortUtils.js +++ b/src/project/SortUtils.js @@ -75,7 +75,7 @@ define(function (require, exports, module) { /** * Retrieves a Sort object by id * @param {string} CommandID - * @return {} + * @return {Sort} */ function get(commandID) { return _sorts[commandID]; @@ -165,10 +165,10 @@ define(function (require, exports, module) { * @constructor * @private * - * @param {string} commandID - valid command identifier. - * @param {function (a, b)} compareFn - a valid sort function (see register for a longer explanation). - * @param {string} events - space-separated DocumentManager possible events ending on ".sort". - * @param {function (event)} automaticFn - the function that will be called when an automatic sort event is triggered. + * @param {!string} commandID - valid command identifier. + * @param {!function(FileEntry, FileEntry)} compareFn - a valid sort function (see register for a longer explanation). + * @param {!string} events - space-separated DocumentManager possible events ending on ".sort". + * @param {!function($.Event)} automaticFn - the function that will be called when an automatic sort event is triggered. */ function Sort(commandID, compareFn, events, automaticFn) { this._commandID = commandID; @@ -213,7 +213,6 @@ define(function (require, exports, module) { Sort.prototype.sort = function () { if (_currentSort === this) { DocumentManager.sortWorkingSet(this._compareFn); - $(DocumentManager).triggerHandler("workingSetSort"); } }; @@ -224,14 +223,16 @@ define(function (require, exports, module) { * Core commands in Brackets use a simple command title as an id, for example "open.file". * Extensions should use the following format: "author.myextension.mycommandname". * For example, "lschmitt.csswizard.format.css". - * @param {!function(a, b)} compareFn - the function that will be used inside the JavaScript sort function. This function receives 2 - * as parameters and should return a value >0 (sort a to a lower index than b), =0 (leaves a and b unchanged with respect to each other) or <0 - * (sort b to a lower index than a) and must always returns the same value when given a specific pair of elements a and b as its two arguments. - * More information at: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort - * @param {?string} events - one or more space-separated event types that DocumentManger uses. Each event passed will trigger the automatic sort. - * If noe events are passed, the automatic sort will be disabled for that sort method. - * @param {?function (event)} automaticFn - the function that will be called when an automatic sort event is triggered. - * If no function is passed the automatic sort will just call the sort function. + * @param {!function(FileEntry, FileEntry)} compareFn - the function that will be used inside JavaScript's + * sort function. The return a value should be >0 (sort a to a lower index than b), =0 (leaves a and b + * unchanged with respect to each other) or <0 (sort b to a lower index than a) and must always returns + * the same value when given a specific pair of elements a and b as its two arguments. + * Documentation: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort + * @param {?string} events - one or more space-separated event types that DocumentManger uses. + * Each event passed will trigger the automatic sort. If no events are passed, the automatic + * sort will be disabled for that sort method. + * @param {?function($.Event)} automaticFn - the function that will be called when an automatic sort + * event is triggered. If no function is passed the automatic sort will just call the sort function. * @return {?Sort} */ function register(commandID, compareFn, events, automaticFn) { @@ -265,16 +266,16 @@ define(function (require, exports, module) { /** Command Handlers */ function _handleSortWorkingSetByName() { - get(Commands.SORT_WORKINGSET_BY_NAME).execute(); - } - - function _handleSortWorkingSetByType() { - get(Commands.SORT_WORKINGSET_BY_TYPE).execute(); - } - - function _handleSortWorkingSetByMRU() { - get(Commands.SORT_WORKINGSET_BY_MRU).execute(); - } + get(Commands.SORT_WORKINGSET_BY_NAME).execute(); + } + + function _handleSortWorkingSetByType() { + get(Commands.SORT_WORKINGSET_BY_TYPE).execute(); + } + + function _handleSortWorkingSetByMRU() { + get(Commands.SORT_WORKINGSET_BY_MRU).execute(); + } function _handleAutomaticSort() { if (getAutomatic()) { @@ -338,8 +339,8 @@ define(function (require, exports, module) { // Register command handlers CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_NAME, Commands.SORT_WORKINGSET_BY_NAME, _handleSortWorkingSetByName); CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_TYPE, Commands.SORT_WORKINGSET_BY_TYPE, _handleSortWorkingSetByType); - CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_MRU, Commands.SORT_WORKINGSET_BY_MRU, _handleSortWorkingSetByMRU); - CommandManager.register(Strings.CMD_SORT_WORKINGSET_AUTO, Commands.SORT_WORKINGSET_AUTO, _handleAutomaticSort); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_MRU, Commands.SORT_WORKINGSET_BY_MRU, _handleSortWorkingSetByMRU); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_AUTO, Commands.SORT_WORKINGSET_AUTO, _handleAutomaticSort); // Init PreferenceStorage From 8cbeb79845fb66cb6b6f68f2f3c7ecd671cbd372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 2 Nov 2012 04:06:40 -0300 Subject: [PATCH 5/6] Fixes after second review and changing MRU sort for Added sort --- src/brackets.js | 4 +- src/command/Commands.js | 2 +- src/command/Menus.js | 2 +- src/document/DocumentManager.js | 31 ++++- src/nls/root/strings.js | 2 +- .../{SortUtils.js => WorkingSetSort.js} | 115 +++++++++--------- src/project/WorkingSetView.js | 3 - 7 files changed, 91 insertions(+), 68 deletions(-) rename src/project/{SortUtils.js => WorkingSetSort.js} (84%) diff --git a/src/brackets.js b/src/brackets.js index 35104837e4b..77c0c322490 100644 --- a/src/brackets.js +++ b/src/brackets.js @@ -68,6 +68,7 @@ define(function (require, exports, module) { CSSInlineEditor = require("editor/CSSInlineEditor"), JSUtils = require("language/JSUtils"), WorkingSetView = require("project/WorkingSetView"), + WorkingSetSort = require("project/WorkingSetSort"), DocumentCommandHandlers = require("document/DocumentCommandHandlers"), FileViewController = require("project/FileViewController"), FileSyncManager = require("project/FileSyncManager"), @@ -91,8 +92,7 @@ define(function (require, exports, module) { UrlParams = require("utils/UrlParams").UrlParams, NativeFileSystem = require("file/NativeFileSystem").NativeFileSystem, PreferencesManager = require("preferences/PreferencesManager"), - Resizer = require("utils/Resizer"), - SortUtils = require("project/SortUtils"); + Resizer = require("utils/Resizer"); // Local variables var params = new UrlParams(), diff --git a/src/command/Commands.js b/src/command/Commands.js index 0d88adaf636..5867786d1ef 100644 --- a/src/command/Commands.js +++ b/src/command/Commands.js @@ -73,9 +73,9 @@ define(function (require, exports, module) { exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize"; exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize"; exports.TOGGLE_JSLINT = "debug.jslint"; + exports.SORT_WORKINGSET_BY_ADDED = "view.sortWorkingSetByAdded"; exports.SORT_WORKINGSET_BY_NAME = "view.sortWorkingSetByName"; exports.SORT_WORKINGSET_BY_TYPE = "view.sortWorkingSetByType"; - exports.SORT_WORKINGSET_BY_MRU = "view.sortWorkingSetByMRU"; exports.SORT_WORKINGSET_AUTO = "view.sortWorkingSetAuto"; // Navigate diff --git a/src/command/Menus.js b/src/command/Menus.js index 26979dea06b..cadfc5c5e0c 100644 --- a/src/command/Menus.js +++ b/src/command/Menus.js @@ -975,9 +975,9 @@ define(function (require, exports, module) { working_set_cmenu.addMenuItem(Commands.FILE_RENAME); working_set_cmenu.addMenuItem(Commands.NAVIGATE_SHOW_IN_FILE_TREE); working_set_cmenu.addMenuDivider(); + working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_ADDED); working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_NAME); working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_TYPE); - working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_BY_MRU); working_set_cmenu.addMenuDivider(); working_set_cmenu.addMenuItem(Commands.SORT_WORKINGSET_AUTO); diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index ee003ece473..fdc48ad196c 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -66,6 +66,8 @@ * The 2nd arg to the listener is the array of removed FileEntry objects. * - fileNameChange -- When the name of a file or folder has changed. The 2nd arg is the old name. * The 3rd arg is the new name. + * - workingSetReorder -- When the indexes of 2 files are swapped during a drag and drop order. + * - workingSetSort -- When the workingSet array is sorted. * * These are jQuery events, so to listen for them you do something like this: * $(DocumentManager).on("eventname", handler); @@ -125,6 +127,13 @@ define(function (require, exports, module) { */ var _workingSetMRUOrder = []; + /** + * @private + * Contains the same set of items as _workinSet, but ordered in the way they where added to _workingSet (0 = last added). + * @type {Array.} + */ + var _workingSetAddedOrder = []; + /** * While true, the MRU order is frozen * @type {boolean} @@ -178,13 +187,13 @@ define(function (require, exports, module) { } /** - * Returns the index of the file matching fullPath in _workingSetMRUOrder. + * Returns the index of the file matching fullPath in _workingSetAddedOrder. * Returns -1 if not found. * @param {!string} fullPath * @returns {number} index */ - function findInWorkingSetMRUOrder(fullPath) { - return findInWorkingSet(fullPath, _workingSetMRUOrder); + function findInWorkingSetAddedOrder(fullPath) { + return findInWorkingSet(fullPath, _workingSetAddedOrder); } /** @@ -228,6 +237,9 @@ define(function (require, exports, module) { _workingSetMRUOrder.push(file); } + // Add first to Added order + _workingSetAddedOrder.unshift(file); + // Dispatch event $(exports).triggerHandler("workingSetAdd", file); } @@ -243,7 +255,7 @@ define(function (require, exports, module) { var uniqueFileList = []; // Process only files not already in working set - fileList.forEach(function (file) { + fileList.forEach(function (file, index) { // If doc is already in working set, don't add it again if (findInWorkingSet(file.fullPath) === -1) { uniqueFileList.push(file); @@ -257,8 +269,12 @@ define(function (require, exports, module) { } else { _workingSetMRUOrder.push(file); } + + // Add first to Added order + _workingSetAddedOrder.splice(index, 1, file); } }); + // Dispatch event $(exports).triggerHandler("workingSetAddList", [uniqueFileList]); @@ -279,6 +295,7 @@ define(function (require, exports, module) { // Remove _workingSet.splice(index, 1); _workingSetMRUOrder.splice(findInWorkingSet(file.fullPath, _workingSetMRUOrder), 1); + _workingSetAddedOrder.splice(findInWorkingSet(file.fullPath, _workingSetAddedOrder), 1); // Dispatch event $(exports).triggerHandler("workingSetRemove", file); @@ -293,6 +310,7 @@ define(function (require, exports, module) { // Remove all _workingSet = []; _workingSetMRUOrder = []; + _workingSetAddedOrder = []; // Dispatch event $(exports).triggerHandler("workingSetRemoveList", [fileList]); @@ -324,6 +342,9 @@ define(function (require, exports, module) { temp = _workingSet[index1]; _workingSet[index1] = _workingSet[index2]; _workingSet[index2] = temp; + + // Dispatch event + $(exports).triggerHandler("workingSetReorder"); } } @@ -1157,7 +1178,7 @@ define(function (require, exports, module) { exports.getOpenDocumentForPath = getOpenDocumentForPath; exports.getWorkingSet = getWorkingSet; exports.findInWorkingSet = findInWorkingSet; - exports.findInWorkingSetMRUOrder = findInWorkingSetMRUOrder; + exports.findInWorkingSetAddedOrder = findInWorkingSetAddedOrder; exports.getAllOpenDocuments = getAllOpenDocuments; exports.setCurrentDocument = setCurrentDocument; exports.addToWorkingSet = addToWorkingSet; diff --git a/src/nls/root/strings.js b/src/nls/root/strings.js index b4ea2b652f3..c48a1204412 100644 --- a/src/nls/root/strings.js +++ b/src/nls/root/strings.js @@ -193,9 +193,9 @@ define({ "CMD_INCREASE_FONT_SIZE" : "Increase Font Size", "CMD_DECREASE_FONT_SIZE" : "Decrease Font Size", "CMD_RESTORE_FONT_SIZE" : "Restore Font Size", + "CMD_SORT_WORKINGSET_BY_ADDED" : "Sort by Added", "CMD_SORT_WORKINGSET_BY_NAME" : "Sort by Name", "CMD_SORT_WORKINGSET_BY_TYPE" : "Sort by Type", - "CMD_SORT_WORKINGSET_BY_MRU" : "Sort by Recently View", "CMD_SORT_WORKINGSET_AUTO" : "Automatic Sort", // Navigate menu Commands diff --git a/src/project/SortUtils.js b/src/project/WorkingSetSort.js similarity index 84% rename from src/project/SortUtils.js rename to src/project/WorkingSetSort.js index f0a6c482b9a..7ce92649fba 100644 --- a/src/project/SortUtils.js +++ b/src/project/WorkingSetSort.js @@ -38,8 +38,11 @@ define(function (require, exports, module) { AppInit = require("utils/AppInit"), Strings = require("strings"); - var PREFERENCES_CLIENT_ID = module.id, - defaultPrefs = { currentSort: null, automaticSort: false }; + var PREFERENCES_CLIENT_ID = "com.adobe.brackets.WorkingSetSort", + defaultPrefs = { + currentSort: Commands.SORT_WORKINGSET_BY_ADDED, + automaticSort: false + }; /** * @private @@ -55,7 +58,7 @@ define(function (require, exports, module) { /** * @private - * @type {} + * @type {Sort} */ var _currentSort = null; @@ -89,6 +92,17 @@ define(function (require, exports, module) { } + /** + * @private + * Sets the value to _automaticSort and updates the menu item. + * @param {boolean} value + */ + function _setAutomatic(value) { + _automaticSort = value; + _prefs.setValue("automaticSort", _automaticSort); + CommandManager.get(Commands.SORT_WORKINGSET_AUTO).setChecked(_automaticSort); + } + /** * @private * Removes current sort DocumentManager listeners. @@ -100,13 +114,12 @@ define(function (require, exports, module) { } /** + * @private * Disables Automatic Sort. */ - function disableAutomatic() { - _automaticSort = false; + function _disableAutomatic() { + _setAutomatic(false); _removeListeners(); - _prefs.setValue("automaticSort", _automaticSort); - CommandManager.get(Commands.SORT_WORKINGSET_AUTO).setChecked(_automaticSort); } /** @@ -120,25 +133,37 @@ define(function (require, exports, module) { _currentSort.callAutomaticFn(event); }) .on("workingSetReorder.sort", function () { - disableAutomatic(); + _disableAutomatic(); }); } } /** + * @private * Enables Automatic Sort. */ - function enableAutomatic() { - _automaticSort = true; + function _enableAutomatic() { + _setAutomatic(true); _addListeners(); - _prefs.setValue("automaticSort", _automaticSort); - CommandManager.get(Commands.SORT_WORKINGSET_AUTO).setChecked(_automaticSort); + } + + /** + * Enables/Disables Automatic Sort depending on the value. + * @param {boolean} value + */ + function setAutomatic(value) { + if (value) { + _enableAutomatic(); + } else { + _disableAutomatic(); + } } /** * @private * Sets the current sort method and checks it on the context menu. + * @param {Sort} newSort */ function _setCurrentSort(newSort) { var command; @@ -265,6 +290,10 @@ define(function (require, exports, module) { /** Command Handlers */ + function _handleSortWorkingSetByAdded() { + get(Commands.SORT_WORKINGSET_BY_ADDED).execute(); + } + function _handleSortWorkingSetByName() { get(Commands.SORT_WORKINGSET_BY_NAME).execute(); } @@ -273,21 +302,22 @@ define(function (require, exports, module) { get(Commands.SORT_WORKINGSET_BY_TYPE).execute(); } - function _handleSortWorkingSetByMRU() { - get(Commands.SORT_WORKINGSET_BY_MRU).execute(); - } - function _handleAutomaticSort() { - if (getAutomatic()) { - disableAutomatic(); - } else { - enableAutomatic(); - } + setAutomatic(!getAutomatic()); } // Register sorts + register( + Commands.SORT_WORKINGSET_BY_ADDED, + function (file1, file2) { + var index1 = DocumentManager.findInWorkingSetAddedOrder(file1.fullPath), + index2 = DocumentManager.findInWorkingSetAddedOrder(file2.fullPath); + return index1 - index2; + }, + "workingSetAdd workingSetAddList" + ); register( Commands.SORT_WORKINGSET_BY_NAME, function (file1, file2) { @@ -310,37 +340,13 @@ define(function (require, exports, module) { }, "workingSetAdd workingSetAddList" ); - register( - Commands.SORT_WORKINGSET_BY_MRU, - function (file1, file2) { - var index1 = DocumentManager.findInWorkingSetMRUOrder(file1.fullPath), - index2 = DocumentManager.findInWorkingSetMRUOrder(file2.fullPath); - return index1 - index2; - }, - "workingSetAdd workingSetAddList currentDocumentChange", - function (event) { - switch (event.type) { - case "workingSetAddList": - _openedDocument = true; - break; - case "currentDocumentChange": - if (_openedDocument) { - _currentSort.sort(); - _openedDocument = false; - } - break; - default: - _currentSort.sort(); - } - } - ); // Register command handlers - CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_NAME, Commands.SORT_WORKINGSET_BY_NAME, _handleSortWorkingSetByName); - CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_TYPE, Commands.SORT_WORKINGSET_BY_TYPE, _handleSortWorkingSetByType); - CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_MRU, Commands.SORT_WORKINGSET_BY_MRU, _handleSortWorkingSetByMRU); - CommandManager.register(Strings.CMD_SORT_WORKINGSET_AUTO, Commands.SORT_WORKINGSET_AUTO, _handleAutomaticSort); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_ADDED, Commands.SORT_WORKINGSET_BY_ADDED, _handleSortWorkingSetByAdded); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_NAME, Commands.SORT_WORKINGSET_BY_NAME, _handleSortWorkingSetByName); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_TYPE, Commands.SORT_WORKINGSET_BY_TYPE, _handleSortWorkingSetByType); + CommandManager.register(Strings.CMD_SORT_WORKINGSET_AUTO, Commands.SORT_WORKINGSET_AUTO, _handleAutomaticSort); // Init PreferenceStorage @@ -356,7 +362,7 @@ define(function (require, exports, module) { _setCurrentSort(curSort); } if (autoSort) { - enableAutomatic(); + _enableAutomatic(); } if (curSort && autoSort) { curSort.sort(); @@ -365,9 +371,8 @@ define(function (require, exports, module) { // Define public API - exports.register = register; - exports.get = get; - exports.getAutomatic = getAutomatic; - exports.enableAutomatic = enableAutomatic; - exports.disableAutomatic = disableAutomatic; + exports.register = register; + exports.get = get; + exports.getAutomatic = getAutomatic; + exports.setAutomatic = setAutomatic; }); diff --git a/src/project/WorkingSetView.js b/src/project/WorkingSetView.js index d32e1ffe2de..0e50c4cbd02 100644 --- a/src/project/WorkingSetView.js +++ b/src/project/WorkingSetView.js @@ -244,9 +244,6 @@ define(function (require, exports, module) { // Restore the shadows ViewUtils.addScrollerShadow($openFilesContainer[0], null, true); } - - // Dispatch event - $(DocumentManager).triggerHandler("workingSetReorder"); } } From b696315f588c4dc80aaabcc354e758c83c19f40d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Malbr=C3=A1n?= Date: Fri, 2 Nov 2012 04:16:49 -0300 Subject: [PATCH 6/6] Typo fixes --- src/document/DocumentManager.js | 5 ++--- src/project/WorkingSetSort.js | 11 +++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/document/DocumentManager.js b/src/document/DocumentManager.js index fdc48ad196c..8d967c8f793 100644 --- a/src/document/DocumentManager.js +++ b/src/document/DocumentManager.js @@ -122,14 +122,14 @@ define(function (require, exports, module) { /** * @private - * Contains the same set of items as _workinSet, but ordered by how recently they were _currentDocument (0 = most recent). + * Contains the same set of items as _workingSet, but ordered by how recently they were _currentDocument (0 = most recent). * @type {Array.} */ var _workingSetMRUOrder = []; /** * @private - * Contains the same set of items as _workinSet, but ordered in the way they where added to _workingSet (0 = last added). + * Contains the same set of items as _workingSet, but ordered in the way they where added to _workingSet (0 = last added). * @type {Array.} */ var _workingSetAddedOrder = []; @@ -361,7 +361,6 @@ define(function (require, exports, module) { $(exports).triggerHandler("workingSetSort"); } - /** * Indicate that changes to currentDocument are temporary for now, and should not update the MRU * ordering of the working set. Useful for next/previous keyboard navigation (until Ctrl is released) diff --git a/src/project/WorkingSetSort.js b/src/project/WorkingSetSort.js index 7ce92649fba..5a0eb566fb1 100644 --- a/src/project/WorkingSetSort.js +++ b/src/project/WorkingSetSort.js @@ -77,7 +77,7 @@ define(function (require, exports, module) { /** * Retrieves a Sort object by id - * @param {string} CommandID + * @param {string} commandID * @return {Sort} */ function get(commandID) { @@ -94,7 +94,7 @@ define(function (require, exports, module) { /** * @private - * Sets the value to _automaticSort and updates the menu item. + * Sets the value of Automatic Sort and updates the menu item. * @param {boolean} value */ function _setAutomatic(value) { @@ -307,8 +307,7 @@ define(function (require, exports, module) { } - - // Register sorts + // Register Sort Methods register( Commands.SORT_WORKINGSET_BY_ADDED, function (file1, file2) { @@ -342,14 +341,14 @@ define(function (require, exports, module) { ); - // Register command handlers + // Register Command Handlers CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_ADDED, Commands.SORT_WORKINGSET_BY_ADDED, _handleSortWorkingSetByAdded); CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_NAME, Commands.SORT_WORKINGSET_BY_NAME, _handleSortWorkingSetByName); CommandManager.register(Strings.CMD_SORT_WORKINGSET_BY_TYPE, Commands.SORT_WORKINGSET_BY_TYPE, _handleSortWorkingSetByType); CommandManager.register(Strings.CMD_SORT_WORKINGSET_AUTO, Commands.SORT_WORKINGSET_AUTO, _handleAutomaticSort); - // Init PreferenceStorage + // Initialize PreferenceStorage _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs);