Skip to content

Commit eeebde6

Browse files
committed
wip: scm tree filter
1 parent de31067 commit eeebde6

1 file changed

Lines changed: 43 additions & 26 deletions

File tree

src/vs/workbench/contrib/scm/browser/scmViewlet.ts

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { createAndFillInContextMenuActions, ContextAwareMenuEntryActionViewItem,
2929
import { SCMMenus } from './scmMenus';
3030
import { ActionBar, IActionViewItemProvider, ActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar';
3131
import { IThemeService, LIGHT } from 'vs/platform/theme/common/themeService';
32-
import { isSCMResource, isSCMRepository } from './scmUtil';
32+
import { isSCMResource, isSCMRepository, isSCMResourceGroup } from './scmUtil';
3333
import { attachBadgeStyler, attachInputBoxStyler } from 'vs/platform/theme/common/styler';
3434
import { IStorageService } from 'vs/platform/storage/common/storage';
3535
import { InputBox, MessageType } from 'vs/base/browser/ui/inputbox/inputBox';
@@ -50,7 +50,7 @@ import { IViewsRegistry, IViewDescriptor, Extensions } from 'vs/workbench/common
5050
import { Registry } from 'vs/platform/registry/common/platform';
5151
import { nextTick } from 'vs/base/common/process';
5252
import { DataTree } from 'vs/base/browser/ui/tree/dataTree';
53-
import { ITreeRenderer, ITreeNode, IDataSource } from 'vs/base/browser/ui/tree/tree';
53+
import { ITreeRenderer, ITreeNode, IDataSource, ITreeFilter } from 'vs/base/browser/ui/tree/tree';
5454
import { ISequence, ISpliceable, ISplice } from 'vs/base/common/sequence';
5555

5656
export interface ISpliceEvent<T> {
@@ -589,6 +589,19 @@ class SCMTreeDataSource implements IDataSource<ISCMRepository, TreeNode> {
589589
}
590590
}
591591

592+
class SCMTreeFilter implements ITreeFilter<TreeNode> {
593+
594+
filter(element: TreeNode): boolean {
595+
if (typeof element === 'string') {
596+
return true;
597+
} else if (isSCMResourceGroup(element)) {
598+
return element.elements.length > 0 || !element.hideWhenEmpty;
599+
} else {
600+
return true;
601+
}
602+
}
603+
}
604+
592605
const scmResourceIdentityProvider = new class implements IIdentityProvider<ISCMResourceGroup | ISCMResource> {
593606
getId(r: ISCMResourceGroup | ISCMResource): string {
594607
if (isSCMResource(r)) {
@@ -618,6 +631,7 @@ const scmKeyboardNavigationLabelProvider = new class implements IKeyboardNavigat
618631

619632
interface IGroupItem {
620633
readonly group: ISCMResourceGroup;
634+
visible: boolean;
621635
readonly disposable: IDisposable;
622636
}
623637

@@ -639,7 +653,7 @@ class ResourceGroupSplicer {
639653

640654
for (const group of toInsert) {
641655
const disposable = combinedDisposable(
642-
// group.onDidChange(() => this.onDidChangeGroup(group)),
656+
group.onDidChange(() => this.onDidChangeGroup(group)),
643657
group.onDidSplice(splice => this.onDidSpliceGroup(group, splice))
644658
);
645659

@@ -655,35 +669,36 @@ class ResourceGroupSplicer {
655669
this.tree.updateChildren();
656670
}
657671

658-
// private onDidChangeGroup(group: ISCMResourceGroup): void {
659-
// const itemIndex = firstIndex(this.items, item => item.group === group);
672+
private onDidChangeGroup(group: ISCMResourceGroup): void {
673+
this.tree.updateChildren();
674+
// const itemIndex = firstIndex(this.items, item => item.group === group);
660675

661-
// if (itemIndex < 0) {
662-
// return;
663-
// }
676+
// if (itemIndex < 0) {
677+
// return;
678+
// }
664679

665-
// const item = this.items[itemIndex];
666-
// const visible = isGroupVisible(group);
680+
// const item = this.items[itemIndex];
681+
// const visible = isGroupVisible(group);
667682

668-
// if (item.visible === visible) {
669-
// return;
670-
// }
683+
// if (item.visible === visible) {
684+
// return;
685+
// }
671686

672-
// let absoluteStart = 0;
687+
// let absoluteStart = 0;
673688

674-
// for (let i = 0; i < itemIndex; i++) {
675-
// const item = this.items[i];
676-
// absoluteStart += (item.visible ? 1 : 0) + item.group.elements.length;
677-
// }
689+
// for (let i = 0; i < itemIndex; i++) {
690+
// const item = this.items[i];
691+
// absoluteStart += (item.visible ? 1 : 0) + item.group.elements.length;
692+
// }
678693

679-
// if (visible) {
680-
// this.spliceable.splice(absoluteStart, 0, [group, ...group.elements]);
681-
// } else {
682-
// this.spliceable.splice(absoluteStart, 1 + group.elements.length, []);
683-
// }
694+
// if (visible) {
695+
// this.spliceable.splice(absoluteStart, 0, [group, ...group.elements]);
696+
// } else {
697+
// this.spliceable.splice(absoluteStart, 1 + group.elements.length, []);
698+
// }
684699

685-
// item.visible = visible;
686-
// }
700+
// item.visible = visible;
701+
}
687702

688703
private onDidSpliceGroup(group: ISCMResourceGroup, { start, deleteCount, toInsert }: ISplice<ISCMResource>): void {
689704
this.tree.updateChildren(group);
@@ -881,6 +896,7 @@ export class RepositoryPanel extends ViewletPanel {
881896
];
882897

883898
const dataSource = new SCMTreeDataSource();
899+
const filter = new SCMTreeFilter();
884900

885901
this.tree = this.instantiationService.createInstance(
886902
WorkbenchDataTree,
@@ -892,7 +908,8 @@ export class RepositoryPanel extends ViewletPanel {
892908
{
893909
identityProvider: scmResourceIdentityProvider,
894910
keyboardNavigationLabelProvider: scmKeyboardNavigationLabelProvider,
895-
horizontalScrolling: false
911+
horizontalScrolling: false,
912+
filter
896913
}) as WorkbenchDataTree<ISCMRepository, TreeNode>;
897914

898915
this._register(Event.chain(this.tree.onDidOpen)

0 commit comments

Comments
 (0)