-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New prefence for mac to sort the directories first in the project tree #7138
Changes from 1 commit
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 |
---|---|---|
|
@@ -75,21 +75,18 @@ define(function (require, exports, module) { | |
FileSyncManager = require("project/FileSyncManager"), | ||
EditorManager = require("editor/EditorManager"); | ||
|
||
|
||
// Define the preference to decide how to sort the Project Tree files | ||
PreferencesManager.definePreference("sortDirsFirst", "boolean", false); | ||
|
||
|
||
/** | ||
* @private | ||
* Forward declaration for the _fileSystemChange and _fileSystemRename functions to make JSLint happy. | ||
*/ | ||
var _fileSystemChange, | ||
_fileSystemRename; | ||
|
||
/** | ||
* @private | ||
* File tree sorting for mac-specific sorting behavior | ||
*/ | ||
var _isMac = brackets.platform === "mac", | ||
_sortPrefixDir = _isMac ? "" : "0", | ||
_sortPrefixFile = _isMac ? "" : "1"; | ||
|
||
/** | ||
* @private | ||
* File and folder names which are not displayed or searched | ||
|
@@ -689,6 +686,19 @@ define(function (require, exports, module) { | |
return fileName.match(_binaryExclusionListRegEx); | ||
} | ||
|
||
/** | ||
* @private | ||
* Returns the prefix added to the filename used for sorting | ||
* @param {boolean} isFolder | ||
* @return {string} | ||
*/ | ||
function _getSortPrefix(isFolder) { | ||
if (brackets.platform === "mac" && !PreferencesManager.get("sortDirsFirst")) { | ||
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 think this preference should not be Mac-only. User should be able to specify something like "directoriesFirst" or "alphabetical". If this preference is not specified, then the current sorting is used. Do we need a separate pref for "ignoreCase"? Windows ignores case, but some systems may use strict ASCII order. 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. It would be easy to just change the default value of this pref to false or true depending on the OS, so when defined by the user, it won't matter which OS they are using. Currently we always ignore cases for any OS. Do you know of any OS or anyone who would like it to add an extra pref? Should that pref affect when we compare filenames in any operation, or just for the project tree? 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.
Sounds good.
I haven't heard anyone request it, so that can be added later. |
||
return ""; | ||
} | ||
return isFolder ? "0" : "1"; | ||
} | ||
|
||
/** | ||
* @private | ||
* Generate a string suitable for sorting | ||
|
@@ -697,7 +707,7 @@ define(function (require, exports, module) { | |
* @return {string} | ||
*/ | ||
function _toCompareString(name, isFolder) { | ||
return ((isFolder) ? _sortPrefixDir : _sortPrefixFile) + name; | ||
return _getSortPrefix(isFolder) + name; | ||
} | ||
|
||
/** | ||
|
@@ -1469,7 +1479,7 @@ define(function (require, exports, module) { | |
if (typeof node === "string") { | ||
node = { | ||
data: node, | ||
metadata: { compareString: _sortPrefixFile + node } | ||
metadata: { compareString: _getSortPrefix(false) + node } | ||
}; | ||
} | ||
|
||
|
@@ -2187,6 +2197,9 @@ define(function (require, exports, module) { | |
|
||
$(exports).on("projectOpen", _reloadProjectPreferencesScope); | ||
|
||
// Refresh the file tree when the sort pref changes | ||
PreferencesManager.on("change", "sortDirsFirst", refreshFileTree); | ||
|
||
// Event Handlers | ||
$(FileViewController).on("documentSelectionFocusChange", _documentSelectionFocusChange); | ||
$(FileViewController).on("fileViewFocusChange", _fileViewFocusChange); | ||
|
@@ -2195,7 +2208,7 @@ define(function (require, exports, module) { | |
// Commands | ||
CommandManager.register(Strings.CMD_OPEN_FOLDER, Commands.FILE_OPEN_FOLDER, openProject); | ||
CommandManager.register(Strings.CMD_PROJECT_SETTINGS, Commands.FILE_PROJECT_SETTINGS, _projectSettings); | ||
CommandManager.register(Strings.CMD_FILE_REFRESH, Commands.FILE_REFRESH, refreshFileTree); | ||
CommandManager.register(Strings.CMD_FILE_REFRESH, Commands.FILE_REFRESH, refreshFileTree); | ||
|
||
// Init invalid characters string | ||
if (brackets.platform === "mac") { | ||
|
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.
This code works as desired, but I am concerned about performance. The
PreferencesManager.get("sortDirectoriesFirst")
function gets called on averageO(n * log(n))
times for a list withn
items, but it returns the same value every time. I think the original code is better -- only need to use preference instead of platform.UPDATE: fixed original logic (was reversed)
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.
Makes sense, I am not sure how many operation
PreferencesManager.get("sortDirectoriesFirst")
does, but it might be better if it was saved as a variable or as you mention the prefixes too. I'll fix this.