-
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.
Allow label providers to notify that changes require a refresh
Signed-off-by: Nigel Westbury <nigelipse@miegel.org>
- Loading branch information
Showing
27 changed files
with
451 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Theia - Examples - API Samples - Label Provider | ||
|
||
This package contains examples of how to use Theia's internal API. The examples here can provide code that enables new features to be tested. The examples also show how to use certain API. | ||
|
||
The examples here are all deactivated by default. Commands are provided that toggles on the example behavior. These commands are prefixed with "API Sample". | ||
|
||
## License | ||
- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/) | ||
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp) |
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,10 @@ | ||
{ | ||
"extends": "../../configs/base.tsconfig", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "lib" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
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,39 @@ | ||
{ | ||
"private": true, | ||
"name": "@theia/api-samples", | ||
"version": "0.12.0", | ||
"description": "Theia - Example code to demonstrate Theia API", | ||
"dependencies": { | ||
"@theia/core": "^0.12.0" | ||
}, | ||
"theiaExtensions": [ | ||
{ | ||
"frontend": "lib/browser/api-samples-frontend-module" | ||
} | ||
], | ||
"keywords": [ | ||
"theia-extension" | ||
], | ||
"license": "EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/eclipse-theia/theia.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/eclipse-theia/theia/issues" | ||
}, | ||
"homepage": "https://github.com/eclipse-theia/theia", | ||
"files": [ | ||
"lib", | ||
"src" | ||
], | ||
"scripts": { | ||
"prepare": "yarn run clean && yarn run build", | ||
"clean": "theiaext clean", | ||
"build": "theiaext build", | ||
"watch": "theiaext watch" | ||
}, | ||
"devDependencies": { | ||
"@theia/ext-scripts": "^0.12.0" | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
examples/api-samples/src/browser/api-samples-contribution.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,55 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 Arm and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable, inject } from 'inversify'; | ||
import { Command, CommandContribution, CommandRegistry, CommandHandler } from '@theia/core'; | ||
import { FrontendApplicationContribution } from '@theia/core/lib/browser'; | ||
import { SampleDynamicLabelProviderContribution } from './sample-dynamic-label-provider-contribution'; | ||
|
||
export namespace ExampleLabelProviderCommands { | ||
const EXAMPLE_CATEGORY = 'Examples'; | ||
export const TOGGLE_SAMPLE: Command = { | ||
id: 'example_label_provider.toggle', | ||
category: EXAMPLE_CATEGORY, | ||
label: 'Toggle Dynamically-Changing Labels' | ||
}; | ||
} | ||
|
||
@injectable() | ||
export class ApiSamplesContribution implements FrontendApplicationContribution, CommandContribution { | ||
|
||
@inject(SampleDynamicLabelProviderContribution) | ||
protected readonly labelProviderContribution: SampleDynamicLabelProviderContribution; | ||
|
||
initialize(): void { } | ||
|
||
registerCommands(commands: CommandRegistry): void { | ||
commands.registerCommand(ExampleLabelProviderCommands.TOGGLE_SAMPLE, new ExampleLabelProviderCommandHandler(this.labelProviderContribution)); | ||
} | ||
|
||
} | ||
|
||
export class ExampleLabelProviderCommandHandler implements CommandHandler { | ||
|
||
constructor(private readonly labelProviderContribution: SampleDynamicLabelProviderContribution) { | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
execute(...args: any[]): any { | ||
this.labelProviderContribution.toggle(); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
examples/api-samples/src/browser/api-samples-frontend-module.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,28 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 Arm and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { ContainerModule } from 'inversify'; | ||
import { CommandContribution } from '@theia/core'; | ||
import { LabelProviderContribution } from '@theia/core/lib/browser/label-provider'; | ||
import { ApiSamplesContribution } from './api-samples-contribution'; | ||
import { SampleDynamicLabelProviderContribution } from './sample-dynamic-label-provider-contribution'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(CommandContribution).to(ApiSamplesContribution).inSingletonScope(); | ||
|
||
bind(SampleDynamicLabelProviderContribution).toSelf().inSingletonScope(); | ||
bind(LabelProviderContribution).toService(SampleDynamicLabelProviderContribution); | ||
}); |
91 changes: 91 additions & 0 deletions
91
examples/api-samples/src/browser/sample-dynamic-label-provider-contribution.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,91 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 Arm and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { DefaultUriLabelProviderContribution, DidChangeLabelEvent, FILE_ICON } from '@theia/core/lib/browser/label-provider'; | ||
import URI from '@theia/core/lib/common/uri'; | ||
import { injectable } from 'inversify'; | ||
import { Emitter, Event } from '@theia/core'; | ||
|
||
@injectable() | ||
export class SampleDynamicLabelProviderContribution extends DefaultUriLabelProviderContribution { | ||
|
||
protected isActive: boolean = false; | ||
|
||
constructor() { | ||
super(); | ||
const outer = this; | ||
|
||
setInterval(() => { | ||
if (this.isActive) { | ||
outer.x++; | ||
outer.fireLabelsDidChange(); | ||
} | ||
}, 1000); | ||
} | ||
|
||
canHandle(element: object): number { | ||
if (element.toString().includes('test')) { | ||
return 30; | ||
} | ||
return 0; | ||
} | ||
|
||
toggle(): void { | ||
this.isActive = !this.isActive; | ||
this.fireLabelsDidChange(); | ||
} | ||
|
||
private fireLabelsDidChange(): void { | ||
this.onDidChangeEmitter.fire({ | ||
affects: (element: URI) => element.toString().includes('test') | ||
}); | ||
} | ||
|
||
private getUri(element: URI): URI { | ||
return new URI(element.toString()); | ||
} | ||
|
||
async getIcon(element: URI): Promise<string> { | ||
const uri = this.getUri(element); | ||
const icon = super.getFileIcon(uri); | ||
if (!icon) { | ||
return FILE_ICON; | ||
} | ||
return icon; | ||
} | ||
|
||
protected readonly onDidChangeEmitter = new Emitter<DidChangeLabelEvent>(); | ||
private x: number = 0; | ||
|
||
getName(element: URI): string { | ||
const uri = this.getUri(element); | ||
if (this.isActive && uri.toString().includes('test')) { | ||
return super.getName(uri) + '-' + this.x.toString(10); | ||
} else { | ||
return super.getName(uri); | ||
} | ||
} | ||
|
||
getLongName(element: URI): string { | ||
const uri = this.getUri(element); | ||
return super.getLongName(uri); | ||
} | ||
|
||
get onDidChange(): Event<DidChangeLabelEvent> { | ||
return this.onDidChangeEmitter.event; | ||
} | ||
|
||
} |
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
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.