-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement Preference API Signed-off-by: Oleksii Kurinnyi <okurinny@redhat.com>
- Loading branch information
Showing
13 changed files
with
573 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
/** | ||
* Returns `true` if the parameter has type "object" and not null, an array, a regexp, a date. | ||
*/ | ||
export function isObject(obj: any): boolean { | ||
return typeof obj === 'object' | ||
&& obj !== null | ||
&& !Array.isArray(obj) | ||
&& !(obj instanceof RegExp) | ||
&& !(obj instanceof Date); | ||
} |
This file contains 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 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
61 changes: 61 additions & 0 deletions
61
packages/plugin-ext/src/main/browser/preference-registry-main.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2018 Red Hat, Inc. and others. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
|
||
import { | ||
PreferenceService, | ||
PreferenceServiceImpl, | ||
PreferenceScope | ||
} from '@theia/core/lib/browser/preferences'; | ||
import { interfaces } from 'inversify'; | ||
import { | ||
MAIN_RPC_CONTEXT, | ||
PreferenceRegistryExt, | ||
PreferenceRegistryMain, | ||
} from '../../api/plugin-api'; | ||
import { RPCProtocol } from '../../api/rpc-protocol'; | ||
import { ConfigurationTarget } from '../../plugin/types-impl'; | ||
|
||
export class PreferenceRegistryMainImpl implements PreferenceRegistryMain { | ||
private proxy: PreferenceRegistryExt; | ||
private preferenceService: PreferenceService; | ||
|
||
constructor(prc: RPCProtocol, container: interfaces.Container) { | ||
this.proxy = prc.getProxy(MAIN_RPC_CONTEXT.PREFERENCE_REGISTRY_EXT); | ||
this.preferenceService = container.get(PreferenceService); | ||
const preferenceServiceImpl = container.get(PreferenceServiceImpl); | ||
|
||
preferenceServiceImpl.onPreferenceChanged(e => { | ||
this.proxy.$acceptConfigurationChanged(preferenceServiceImpl.getPreferences(), e); | ||
}); | ||
} | ||
|
||
$updateConfigurationOption(target: boolean | ConfigurationTarget | undefined, key: string, value: any): PromiseLike<void> { | ||
const scope = this.parseConfigurationTarget(target); | ||
return this.preferenceService.set(key, value, scope); | ||
} | ||
|
||
$removeConfigurationOption(target: boolean | ConfigurationTarget | undefined, key: string): PromiseLike<void> { | ||
const scope = this.parseConfigurationTarget(target); | ||
return this.preferenceService.set(key, undefined, scope); | ||
} | ||
|
||
private parseConfigurationTarget(arg?: boolean | ConfigurationTarget): PreferenceScope { | ||
if (arg === void 0 || arg === null) { | ||
return PreferenceScope.Workspace; | ||
} | ||
if (typeof arg === 'boolean') { | ||
return arg ? PreferenceScope.User : PreferenceScope.Workspace; | ||
} | ||
|
||
if (arg === ConfigurationTarget.User) { | ||
return PreferenceScope.User; | ||
} else { | ||
return PreferenceScope.Workspace; | ||
} | ||
} | ||
|
||
} |
This file contains 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
Oops, something went wrong.