Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plug-in][java][preferences] Add files.exclude preference #4274

Merged
merged 1 commit into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Breaking changes:
- the type of `combinedSchema` property is changed from `PreferenceSchema` to `PreferenceDataSchema`.
- the return type of `getCombinedSchema` function is changed from `PreferenceSchema` to `PreferenceDataSchema`.
- `affects` function is added to `PreferenceChangeEvent` and `PreferenceChange` interface.
- `navigator.exclude` preference is renamed to `files.exclude` [#4274](https://github.com/theia-ide/theia/pull/4274)


## v0.3.19
Expand Down
7 changes: 7 additions & 0 deletions packages/filesystem/src/browser/filesystem-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,19 @@ export const filesystemPreferenceSchema: PreferenceSchema = {
'**/node_modules/**': true
},
'scope': 'resource'
},
'files.exclude': {
'type': 'object',
'default': { '**/.git': true, '**/.svn': true, '**/.hg': true, '**/CVS': true, '**/.DS_Store': true },
'description': 'Configure glob patterns for excluding files and folders.',
'scope': 'resource'
}
}
};

export interface FileSystemConfiguration {
'files.watcherExclude': { [globPattern: string]: boolean };
'files.exclude': { [key: string]: boolean };
}

export const FileSystemPreferences = Symbol('FileSystemPreferences');
Expand Down
28 changes: 17 additions & 11 deletions packages/navigator/src/browser/navigator-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,34 @@ import { Minimatch } from 'minimatch';
import { MaybePromise } from '@theia/core/lib/common/types';
import { Event, Emitter } from '@theia/core/lib/common/event';
import { PreferenceChangeEvent } from '@theia/core/lib/browser/preferences';
import { FileSystemPreferences, FileSystemConfiguration } from '@theia/filesystem/lib/browser/filesystem-preferences';
import { FileNavigatorPreferences, FileNavigatorConfiguration } from './navigator-preferences';

const FILES_EXCLUDE_PREFERENCE: keyof FileSystemConfiguration = 'files.exclude';

/**
* Filter for omitting elements from the navigator. For more details on the exclusion patterns,
* one should check either the manual with `man 5 gitignore` or just [here](https://git-scm.com/docs/gitignore).
*/
@injectable()
export class FileNavigatorFilter {

protected readonly emitter: Emitter<void> = new Emitter<void>();

protected filterPredicate: FileNavigatorFilter.Predicate;

protected showHiddenFiles: boolean;

@inject(FileSystemPreferences)
protected readonly filesPreferences: FileSystemPreferences;

constructor(
@inject(FileNavigatorPreferences) protected readonly preferences: FileNavigatorPreferences
) { }

@postConstruct()
protected async init(): Promise<void> {
this.filterPredicate = this.createFilterPredicate(this.preferences['navigator.exclude']);
this.preferences.onPreferenceChanged(this.onPreferenceChanged.bind(this));
this.filterPredicate = this.createFilterPredicate(this.filesPreferences[FILES_EXCLUDE_PREFERENCE]);
this.filesPreferences.onPreferenceChanged(event => this.onFilesPreferenceChanged(event));
this.preferences.onPreferenceChanged(event => this.onPreferenceChanged(event));
}

async filter<T extends { id: string }>(items: MaybePromise<T[]>): Promise<T[]> {
Expand All @@ -60,25 +65,26 @@ export class FileNavigatorFilter {
this.emitter.fire(undefined);
}

protected onPreferenceChanged(event: PreferenceChangeEvent<FileNavigatorConfiguration>): void {
let hasChanged = false;
protected onFilesPreferenceChanged(event: PreferenceChangeEvent<FileSystemConfiguration>): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be renamed. Please restore the original method name. Sorry for not mentioning it before :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this method as it is, and added
protected onPreferenceChanged(event: PreferenceChangeEvent<FileNavigatorConfiguration>): void with empty body. Please take another look at it :)

const { preferenceName, newValue } = event;
if (preferenceName === 'navigator.exclude') {
if (preferenceName === FILES_EXCLUDE_PREFERENCE) {
kittaakos marked this conversation as resolved.
Show resolved Hide resolved
this.filterPredicate = this.createFilterPredicate(newValue as FileNavigatorFilter.Exclusions | undefined || {});
hasChanged = true;
}
if (hasChanged) {
kittaakos marked this conversation as resolved.
Show resolved Hide resolved
this.fireFilterChanged();
}
}

protected onPreferenceChanged(event: PreferenceChangeEvent<FileNavigatorConfiguration>): void {
}

protected createFilterPredicate(exclusions: FileNavigatorFilter.Exclusions): FileNavigatorFilter.Predicate {
return new FileNavigatorFilterPredicate(this.interceptExclusions(exclusions));
}

toggleHiddenFiles(): void {
this.showHiddenFiles = !this.showHiddenFiles;
this.filterPredicate = this.createFilterPredicate(this.preferences['navigator.exclude'] || {});
const filesExcludes = this.filesPreferences[FILES_EXCLUDE_PREFERENCE];

this.filterPredicate = this.createFilterPredicate(filesExcludes || {});
this.fireFilterChanged();
}

Expand Down
9 changes: 0 additions & 9 deletions packages/navigator/src/browser/navigator-preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@ export const FileNavigatorConfigSchema: PreferenceSchema = {
type: 'boolean',
description: 'Selects file under editing in the navigator.',
default: true
},
'navigator.exclude': {
type: 'object',
description: `
Configure glob patterns for excluding files and folders from the navigator. A resource that matches any of the enabled patterns, will be filtered out from the navigator. For more details about the exclusion patterns, see: \`man 5 gitignore\`.`,
default: {
'**/.git': true
}
}
}
};

export interface FileNavigatorConfiguration {
'navigator.autoReveal': boolean;
'navigator.exclude': { [key: string]: boolean };
}

export const FileNavigatorPreferences = Symbol('NavigatorPreferences');
Expand Down