This repository has been archived by the owner on Apr 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Plugin management #162
Merged
Merged
Plugin management #162
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
177 changes: 177 additions & 0 deletions
177
...nsions/eclipse-che-theia-plugin-ext/src/browser/plugin/che-plugin-command-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,177 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2018 Red Hat, Inc. 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 { CommandRegistry, CommandContribution } from '@theia/core/lib/common'; | ||
import { MessageService, Command } from '@theia/core/lib/common'; | ||
import { ChePluginRegistry } from '../../common/che-protocol'; | ||
import { ChePluginManager } from './che-plugin-manager'; | ||
import { QuickInputService } from '@theia/core/lib/browser'; | ||
import { MonacoQuickOpenService } from '@theia/monaco/lib/browser/monaco-quick-open-service'; | ||
import { QuickOpenModel, QuickOpenItem, QuickOpenMode } from '@theia/core/lib/browser/quick-open/quick-open-model'; | ||
|
||
function cmd(id: string, label: string): Command { | ||
return { | ||
id: `${ChePluginManagerCommands.PLUGIN_MANAGER_ID}:${id}`, | ||
category: ChePluginManagerCommands.PLUGIN_MANAGER_CATEGORY, | ||
label: label | ||
}; | ||
} | ||
|
||
export namespace ChePluginManagerCommands { | ||
|
||
export const PLUGIN_MANAGER_ID = 'plugin-manager'; | ||
export const PLUGIN_MANAGER_CATEGORY = 'Plugin Manager'; | ||
|
||
export const SHOW_AVAILABLE_PLUGINS = cmd('show-available-plugins', 'Show Available Plugins'); | ||
export const SHOW_INSTALLED_PLUGINS = cmd('show-installed-plugins', 'Show Installed Plugins'); | ||
export const SHOW_BUILT_IN_PLUGINS = cmd('show-built-in-plugins', 'Show Built-in Plugins'); | ||
|
||
export const CHANGE_REGISTRY = cmd('change-registry', 'Change Registry'); | ||
export const ADD_REGISTRY = cmd('add-registry', 'Add Registry'); | ||
} | ||
|
||
@injectable() | ||
export class ChePluginCommandContribution implements CommandContribution { | ||
|
||
@inject(MessageService) | ||
protected readonly messageService: MessageService; | ||
|
||
@inject(QuickInputService) | ||
protected readonly quickInputService: QuickInputService; | ||
|
||
@inject(MonacoQuickOpenService) | ||
protected readonly monacoQuickOpenService: MonacoQuickOpenService; | ||
|
||
@inject(ChePluginManager) | ||
protected readonly chePluginManager: ChePluginManager; | ||
|
||
registerCommands(commands: CommandRegistry): void { | ||
commands.registerCommand(ChePluginManagerCommands.CHANGE_REGISTRY, { | ||
execute: () => this.changePluginRegistry() | ||
}); | ||
|
||
commands.registerCommand(ChePluginManagerCommands.ADD_REGISTRY, { | ||
execute: () => this.addPluginRegistry() | ||
}); | ||
} | ||
|
||
// | ||
async showAvailablePlugins() { | ||
this.chePluginManager.changeFilter('', true); | ||
} | ||
|
||
// @installed | ||
async showInstalledPlugins() { | ||
this.chePluginManager.changeFilter('@installed', true); | ||
} | ||
|
||
// @builtin | ||
async showBuiltInPlugins() { | ||
mmorhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Displays prompt to add new plugin registry | ||
mmorhun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
async addPluginRegistry(): Promise<void> { | ||
const name = await this.quickInputService.open({ | ||
prompt: 'Name of your registry' | ||
}); | ||
|
||
if (!name) { | ||
return; | ||
} | ||
|
||
const uri = await this.quickInputService.open({ | ||
prompt: 'Registry URI' | ||
}); | ||
|
||
if (!uri) { | ||
return; | ||
} | ||
|
||
const registry = { | ||
name, | ||
uri | ||
}; | ||
|
||
this.chePluginManager.addRegistry(registry); | ||
this.chePluginManager.changeRegistry(registry); | ||
} | ||
|
||
private async pickPluginRegistry(): Promise<ChePluginRegistry | undefined> { | ||
const registryList = this.chePluginManager.getRegistryList(); | ||
|
||
return new Promise<ChePluginRegistry | undefined>((resolve, reject) => { | ||
// Return undefined if registry list is empty | ||
if (!registryList || registryList.length === 0) { | ||
resolve(undefined); | ||
return; | ||
} | ||
|
||
// Active before appearing the pick menu | ||
const activeElement: HTMLElement | undefined = window.document.activeElement as HTMLElement; | ||
|
||
// ChePluginRegistry to be returned | ||
let returnValue: ChePluginRegistry | undefined; | ||
|
||
const items = registryList.map(registry => | ||
new QuickOpenItem({ | ||
label: registry.name, | ||
detail: registry.uri, | ||
run: mode => { | ||
if (mode === QuickOpenMode.OPEN) { | ||
returnValue = { | ||
name: registry.name, | ||
uri: registry.uri | ||
} as ChePluginRegistry; | ||
} | ||
return true; | ||
} | ||
}) | ||
); | ||
|
||
// Create quick open model | ||
const model = { | ||
onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): void { | ||
acceptor(items); | ||
} | ||
} as QuickOpenModel; | ||
|
||
// Show pick menu | ||
this.monacoQuickOpenService.open(model, { | ||
fuzzyMatchLabel: true, | ||
fuzzyMatchDetail: true, | ||
fuzzyMatchDescription: true, | ||
onClose: () => { | ||
if (activeElement) { | ||
activeElement.focus(); | ||
} | ||
|
||
resolve(returnValue); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async changePluginRegistry(): Promise<void> { | ||
const registry = await this.pickPluginRegistry(); | ||
if (registry) { | ||
this.chePluginManager.changeRegistry(registry); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix year, please, for all files...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done