This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
File exclusions usability improvements (bug #7149) #7400
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ define(function (require, exports, module) { | |
| "use strict"; | ||
|
|
||
| var _ = require("thirdparty/lodash"), | ||
| ProjectManager = require("project/ProjectManager"), | ||
| DefaultDialogs = require("widgets/DefaultDialogs"), | ||
| Dialogs = require("widgets/Dialogs"), | ||
| DropdownButton = require("widgets/DropdownButton").DropdownButton, | ||
|
|
@@ -59,44 +60,6 @@ define(function (require, exports, module) { | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Opens a dialog box to edit the given filter. When editing is finished, the value of getLastFilter() changes to | ||
| * reflect the edits. If the dialog was canceled, the preference is left unchanged. | ||
| * @param {!Array.<string>} filter | ||
| * @return {!$.Promise} Dialog box promise | ||
| */ | ||
| function editFilter(filter) { | ||
| var lastFocus = window.document.activeElement; | ||
|
|
||
| var html = StringUtils.format(Strings.FILE_FILTER_INSTRUCTIONS, brackets.config.glob_help_url) + | ||
| "<textarea class='exclusions-editor'></textarea>"; | ||
| var buttons = [ | ||
| { className : Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL, text: Strings.CANCEL }, | ||
| { className : Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK, text: Strings.OK } | ||
| ]; | ||
| var dialog = Dialogs.showModalDialog(DefaultDialogs.DIALOG_ID_INFO, Strings.FILE_FILTER_DIALOG, html, buttons); | ||
|
|
||
| dialog.getElement().find(".exclusions-editor").val(filter.join("\n")).focus(); | ||
|
|
||
| dialog.done(function (buttonId) { | ||
| if (buttonId === Dialogs.DIALOG_BTN_OK) { | ||
| var newFilter = dialog.getElement().find(".exclusions-editor").val().split("\n"); | ||
|
|
||
| // Remove blank lines | ||
| newFilter = newFilter.filter(function (glob) { | ||
| return glob.trim().length; | ||
| }); | ||
|
|
||
| // Update saved filter preference | ||
| setLastFilter(newFilter); | ||
| } | ||
| lastFocus.focus(); // restore focus to old pos | ||
| }); | ||
|
|
||
| return dialog.getPromise(); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Converts a user-specified filter object (as chosen in picker or retrieved from getFilters()) to a 'compiled' form | ||
| * that can be used with filterPath()/filterFileList(). | ||
|
|
@@ -153,6 +116,109 @@ define(function (require, exports, module) { | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Returns false if the given path matches any of the exclusion globs in the given filter. Returns true | ||
| * if the path does not match any of the globs. If filtering many paths at once, use filterFileList() | ||
| * for much better performance. | ||
| * | ||
| * @param {?string} compiledFilter 'Compiled' filter object as returned by compile(), or null to no-op | ||
| * @param {!string} fullPath | ||
| * @return {boolean} | ||
| */ | ||
| function filterPath(compiledFilter, fullPath) { | ||
| if (!compiledFilter) { | ||
| return true; | ||
| } | ||
|
|
||
| var re = new RegExp(compiledFilter); | ||
| return !fullPath.match(re); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a copy of 'files' filtered to just those that don't match any of the exclusion globs in the filter. | ||
| * | ||
| * @param {?string} compiledFilter 'Compiled' filter object as returned by compile(), or null to no-op | ||
| * @param {!Array.<File>} files | ||
| * @return {!Array.<File>} | ||
| */ | ||
| function filterFileList(compiledFilter, files) { | ||
| if (!compiledFilter) { | ||
| return files; | ||
| } | ||
|
|
||
| var re = new RegExp(compiledFilter); | ||
| return files.filter(function (f) { | ||
| return !f.fullPath.match(re); | ||
| }); | ||
| } | ||
|
Member
Author
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. filterPath() and filterFileList() were simply moved higher up in the file, with zero changes to the actual code (verified by diffing the text) |
||
|
|
||
|
|
||
| /** | ||
| * Opens a dialog box to edit the given filter. When editing is finished, the value of getLastFilter() changes to | ||
| * reflect the edits. If the dialog was canceled, the preference is left unchanged. | ||
| * @param {!Array.<string>} filter | ||
| * @param {?{label:string, promise:$.Promise}} context Info on which files the filter will be applied to. If specified, | ||
| * editing UI will indicate how many files are excluded by the filter. Label should be of the form "in ..." | ||
| * @return {!$.Promise} Dialog box promise | ||
| */ | ||
| function editFilter(filter, context) { | ||
| var lastFocus = window.document.activeElement; | ||
|
|
||
| var html = StringUtils.format(Strings.FILE_FILTER_INSTRUCTIONS, brackets.config.glob_help_url) + | ||
| "<textarea class='exclusions-editor'></textarea><div class='exclusions-filecount'>" + Strings.FILTER_COUNTING_FILES + "</div>"; | ||
| var buttons = [ | ||
| { className : Dialogs.DIALOG_BTN_CLASS_NORMAL, id: Dialogs.DIALOG_BTN_CANCEL, text: Strings.CANCEL }, | ||
| { className : Dialogs.DIALOG_BTN_CLASS_PRIMARY, id: Dialogs.DIALOG_BTN_OK, text: Strings.OK } | ||
| ]; | ||
| var dialog = Dialogs.showModalDialog(DefaultDialogs.DIALOG_ID_INFO, Strings.FILE_FILTER_DIALOG, html, buttons); | ||
|
|
||
| var $editField = dialog.getElement().find(".exclusions-editor"); | ||
| $editField.val(filter.join("\n")).focus(); | ||
|
|
||
| function getValue() { | ||
| var newFilter = $editField.val().split("\n"); | ||
|
|
||
| // Remove blank lines | ||
| return newFilter.filter(function (glob) { | ||
| return glob.trim().length; | ||
| }); | ||
| } | ||
|
|
||
| dialog.done(function (buttonId) { | ||
| if (buttonId === Dialogs.DIALOG_BTN_OK) { | ||
| // Update saved filter preference | ||
| setLastFilter(getValue()); | ||
| } | ||
| lastFocus.focus(); // restore focus to old pos | ||
| }); | ||
|
|
||
|
|
||
| // Code to update the file count readout at bottom of dialog (if context provided) | ||
| var $fileCount = dialog.getElement().find(".exclusions-filecount"); | ||
|
|
||
| function updateFileCount() { | ||
| context.promise.done(function (files) { | ||
| var filter = getValue(); | ||
| if (filter.length) { | ||
| var filtered = filterFileList(compile(filter), files); | ||
| $fileCount.html(StringUtils.format(Strings.FILTER_FILE_COUNT, filtered.length, files.length, context.label)); | ||
| } else { | ||
| $fileCount.html(StringUtils.format(Strings.FILTER_FILE_COUNT_ALL, files.length, context.label)); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| if (context) { | ||
| $editField.on("input", _.debounce(updateFileCount, 400)); | ||
| updateFileCount(); | ||
| } else { | ||
| $fileCount.hide(); | ||
| } | ||
|
|
||
| return dialog.getPromise(); | ||
| } | ||
|
Member
Author
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. |
||
|
|
||
|
|
||
| /** | ||
| * Marks the filter picker's currently selected item as most-recently used, and returns the corresponding | ||
| * 'compiled' filter object ready for use with filterPath(). | ||
|
|
@@ -170,9 +236,10 @@ define(function (require, exports, module) { | |
| * client should call commitDropdown() when the UI containing the filter picker is confirmed (which updates the MRU | ||
| * order) and then use the returned filter object as needed. | ||
| * | ||
| * @param {?{label:string, promise:$.Promise}} context Info on files filter will apply to - see editFilter() | ||
| * @return {!jQueryObject} Picker UI. To retrieve the selected value, use commitPicker(). | ||
| */ | ||
| function createFilterPicker() { | ||
| function createFilterPicker(context) { | ||
| var $picker = $("<div class='filter-picker'><span class='filter-label'></span><button class='btn no-focus'></button></div>"), | ||
| $button = $picker.find("button"); | ||
|
|
||
|
|
@@ -208,7 +275,7 @@ define(function (require, exports, module) { | |
| updatePicker(); | ||
|
|
||
| $button.click(function () { | ||
| editFilter(getLastFilter()) | ||
| editFilter(getLastFilter(), context) | ||
| .done(function (buttonId) { | ||
| if (buttonId === Dialogs.DIALOG_BTN_OK) { | ||
| updatePicker(); | ||
|
|
@@ -220,43 +287,6 @@ define(function (require, exports, module) { | |
| } | ||
|
|
||
|
|
||
| /** | ||
| * Returns false if the given path matches any of the exclusion globs in the given filter. Returns true | ||
| * if the path does not match any of the globs. If filtering many paths at once, use filterFileList() | ||
| * for much better performance. | ||
| * | ||
| * @param {!string} compiledFilter 'Compiled' filter object as returned by compile() | ||
| * @param {!string} fullPath | ||
| * @return {boolean} | ||
| */ | ||
| function filterPath(compiledFilter, fullPath) { | ||
| if (!compiledFilter) { | ||
| return true; | ||
| } | ||
|
|
||
| var re = new RegExp(compiledFilter); | ||
| return !fullPath.match(re); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a copy of 'files' filtered to just those that don't match any of the exclusion globs in the filter. | ||
| * | ||
| * @param {!string} compiledFilter 'Compiled' filter object as returned by compile() | ||
| * @param {!Array.<File>} files | ||
| * @return {!Array.<File>} | ||
| */ | ||
| function filterFileList(compiledFilter, files) { | ||
| if (!compiledFilter) { | ||
| return files; | ||
| } | ||
|
|
||
| var re = new RegExp(compiledFilter); | ||
| return files.filter(function (f) { | ||
| return !f.fullPath.match(re); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| exports.createFilterPicker = createFilterPicker; | ||
| exports.commitPicker = commitPicker; | ||
| exports.getLastFilter = getLastFilter; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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.
We changed from "globs" to "wildcards" in last sprint's update notification & the wiki documentation, but didn't update the UI to match. This syncs it up with the preferred terminology.