提交 ae31e8c1 编写于 作者: J Johannes Rieken

add setting to toggle between filter or find, #49922

上级 2e2220c9
......@@ -44,32 +44,26 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
'order': 117,
'type': 'object',
'properties': {
[OutlineConfigKeys.filterOnType]: {
'description': localize('outline.typeToFilter', "Defines if typing in the input-box filters or finds elements."),
'type': 'boolean',
'default': true
},
[OutlineConfigKeys.problemsEnabled]: {
'description': localize('outline.showProblem', "Show Errors & Warnings on Outline Elements."),
'type': 'boolean',
'default': true
}
}
});
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
'id': 'outline',
'order': 117,
'type': 'object',
'properties': {
},
[OutlineConfigKeys.problemsEnabled]: {
'description': localize('outline.showProblem', "Show Errors & Warnings on Outline Elements."),
'type': 'boolean',
'default': true
},
[OutlineConfigKeys.problemsColors]: {
'description': localize('outline.problem.colors', "Use colors for Errors & Warnings."),
'type': 'boolean',
'default': true
}
}
});
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).registerConfiguration({
'id': 'outline',
'order': 117,
'type': 'object',
'properties': {
},
[OutlineConfigKeys.problemsBadges]: {
'description': localize('outline.problems.badges', "Use badges for Errors & Warnings."),
'type': 'boolean',
......
......@@ -7,6 +7,7 @@
export enum OutlineConfigKeys {
'filterOnType' = 'outline.filterOnType',
'problemsEnabled' = 'outline.problems.enabled',
'problemsColors' = 'outline.problems.colors',
'problemsBadges' = 'outline.problems.badges'
......
......@@ -217,6 +217,7 @@ export class OutlinePanel extends ViewletPanel {
private _input: InputBox;
private _progressBar: ProgressBar;
private _tree: WorkbenchTree;
private _treeDataSource: OutlineDataSource;
private _treeFilter: OutlineItemFilter;
private _treeComparator: OutlineItemComparator;
private _treeStates = new LRUCache<string, OutlineTreeState>(10);
......@@ -319,11 +320,11 @@ export class OutlinePanel extends ViewletPanel {
return false;
}
};
const dataSource = new OutlineDataSource();
const renderer = this._instantiationService.createInstance(OutlineRenderer);
this._treeDataSource = new OutlineDataSource();
this._treeComparator = new OutlineItemComparator(this._outlineViewState.sortBy);
this._treeFilter = new OutlineItemFilter();
this._tree = this._instantiationService.createInstance(WorkbenchTree, treeContainer, { controller, dataSource, renderer, sorter: this._treeComparator, filter: this._treeFilter }, {});
this._tree = this._instantiationService.createInstance(WorkbenchTree, treeContainer, { controller, renderer, dataSource: this._treeDataSource, sorter: this._treeComparator, filter: this._treeFilter }, {});
this._disposables.push(this._tree, this._input);
this._disposables.push(this._outlineViewState.onDidChange(this._onDidChangeUserState, this));
......@@ -461,6 +462,16 @@ export class OutlinePanel extends ViewletPanel {
OutlineTreeState.restore(this._tree, state);
}
// depending on the user setting we filter or find elements
if (this._configurationService.getValue(OutlineConfigKeys.filterOnType)) {
this._treeFilter.enabled = true;
this._treeDataSource.filterOnScore = true;
this._input.setPlaceHolder(localize('filter', "Filter"));
} else {
this._treeFilter.enabled = false;
this._treeDataSource.filterOnScore = false;
this._input.setPlaceHolder(localize('find', "Find"));
}
this._input.enable();
this.layoutBody();
......
......@@ -64,13 +64,22 @@ export class OutlineItemComparator implements ISorter {
export class OutlineItemFilter implements IFilter {
enabled: boolean = true;
isVisible(tree: ITree, element: OutlineElement | any): boolean {
if (!this.enabled) {
return true;
}
return !(element instanceof OutlineElement) || Boolean(element.score);
}
}
export class OutlineDataSource implements IDataSource {
// this is a workaround for the tree showing twisties for items
// with only filtered children
filterOnScore: boolean = true;
getId(tree: ITree, element: TreeElement): string {
return element ? element.id : 'empty';
}
......@@ -82,11 +91,11 @@ export class OutlineDataSource implements IDataSource {
if (element instanceof OutlineModel) {
return true;
}
if (element instanceof OutlineElement && !element.score) {
if (element instanceof OutlineElement && (this.filterOnScore && !element.score)) {
return false;
}
for (const id in element.children) {
if (element.children[id].score) {
if (!this.filterOnScore || element.children[id].score) {
return true;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册