Skip to content

Commit

Permalink
sort categories with uncheck items atop, #90664
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Feb 14, 2020
1 parent 968b019 commit 245358a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/vs/workbench/contrib/bulkEdit/browser/bulkEditPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import 'vs/css!./bulkEdit';
import { WorkbenchAsyncDataTree, TreeResourceNavigator, IOpenEvent } from 'vs/platform/list/browser/listService';
import { WorkspaceEdit } from 'vs/editor/common/modes';
import { BulkEditElement, BulkEditDelegate, TextEditElementRenderer, FileElementRenderer, BulkEditDataSource, BulkEditIdentityProvider, FileElement, TextEditElement, BulkEditAccessibilityProvider, BulkEditAriaProvider, CategoryElementRenderer, BulkEditNaviLabelProvider, CategoryElement } from 'vs/workbench/contrib/bulkEdit/browser/bulkEditTree';
import { BulkEditElement, BulkEditDelegate, TextEditElementRenderer, FileElementRenderer, BulkEditDataSource, BulkEditIdentityProvider, FileElement, TextEditElement, BulkEditAccessibilityProvider, BulkEditAriaProvider, CategoryElementRenderer, BulkEditNaviLabelProvider, CategoryElement, BulkEditSorter } from 'vs/workbench/contrib/bulkEdit/browser/bulkEditTree';
import { FuzzyScore } from 'vs/base/common/filters';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { registerThemingParticipant, ITheme, ICssStyleCollector, IThemeService } from 'vs/platform/theme/common/themeService';
Expand Down Expand Up @@ -135,6 +135,7 @@ export class BulkEditPane extends ViewPane {
expandOnlyOnTwistieClick: true,
multipleSelectionSupport: false,
keyboardNavigationLabelProvider: new BulkEditNaviLabelProvider(),
sorter: new BulkEditSorter()
}
);

Expand Down
11 changes: 10 additions & 1 deletion src/vs/workbench/contrib/bulkEdit/browser/bulkEditPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ export class BulkFileOperation {
this.newUri = edit.newUri;
}
}

needsConfirmation(): boolean {
for (let [, edit] of this.originalEdits) {
if (!this.parent.checked.isChecked(edit)) {
return true;
}
}
return false;
}
}

export class BulkCategory {
Expand Down Expand Up @@ -230,7 +239,7 @@ export class BulkFileOperations {
}

operationByResource.forEach(value => this.fileOperations.push(value));
operationByCategory.forEach(value => value.metadata.needsConfirmation ? this.categories.unshift(value) : this.categories.push(value));
operationByCategory.forEach(value => this.categories.push(value));

// "correct" invalid parent-check child states that is
// unchecked file edits (rename, create, delete) uncheck
Expand Down
36 changes: 35 additions & 1 deletion src/vs/workbench/contrib/bulkEdit/browser/bulkEditTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IAsyncDataSource, ITreeRenderer, ITreeNode } from 'vs/base/browser/ui/tree/tree';
import { IAsyncDataSource, ITreeRenderer, ITreeNode, ITreeSorter } from 'vs/base/browser/ui/tree/tree';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { FuzzyScore, createMatches } from 'vs/base/common/filters';
import { IResourceLabel, ResourceLabels } from 'vs/workbench/browser/labels';
Expand All @@ -24,6 +24,7 @@ import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
import { basename } from 'vs/base/common/resources';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { WorkspaceFileEdit } from 'vs/editor/common/modes';
import { compare } from 'vs/base/common/strings';

// --- VIEW MODEL

Expand Down Expand Up @@ -248,6 +249,39 @@ export class BulkEditDataSource implements IAsyncDataSource<BulkFileOperations,
}
}


export class BulkEditSorter implements ITreeSorter<BulkEditElement> {

compare(a: BulkEditElement, b: BulkEditElement): number {
if (a instanceof CategoryElement && b instanceof CategoryElement) {
//
const aConfirm = BulkEditSorter._needsConfirmation(a.category);
const bConfirm = BulkEditSorter._needsConfirmation(b.category);
if (aConfirm === bConfirm) {
return a.category.metadata.label.localeCompare(b.category.metadata.label);
} else if (aConfirm) {
return -1;
} else {
return 1;
}
}

if (a instanceof FileElement && b instanceof FileElement) {
return compare(a.edit.uri.toString(), b.edit.uri.toString());
}

if (a instanceof TextEditElement && b instanceof TextEditElement) {
return Range.compareRangesUsingStarts(a.edit.textEdit.edit.range, b.edit.textEdit.edit.range);
}

return 0;
}

private static _needsConfirmation(a: BulkCategory): boolean {
return a.fileOperations.some(ops => ops.needsConfirmation());
}
}

// --- ACCESSI

export class BulkEditAccessibilityProvider implements IAccessibilityProvider<BulkEditElement> {
Expand Down

0 comments on commit 245358a

Please sign in to comment.