Skip to content

Commit

Permalink
Add ability to get selection context after execute command
Browse files Browse the repository at this point in the history
Signed-off-by: Vladyslav Zhukovskyi <vzhukovs@redhat.com>
  • Loading branch information
vzhukovs committed Mar 4, 2019
1 parent 7286cfb commit 02ead36
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { PluginDebugSessionContributionRegistry } from './debug/plugin-debug-ses
import { PluginDebugService } from './debug/plugin-debug-service';
import { DebugService } from '@theia/debug/lib/common/debug-service';
import { PluginSharedStyle } from './plugin-shared-style';
import { SelectionProviderCommandContribution } from './selection-provider-command';

export default new ContainerModule((bind, unbind, isBound, rebind) => {
bindHostedPluginPreferences(bind);
Expand All @@ -67,6 +68,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(HostedPluginWatcher).toSelf().inSingletonScope();
bind(HostedPluginLogViewer).toSelf().inSingletonScope();
bind(HostedPluginManagerClient).toSelf().inSingletonScope();
bind(SelectionProviderCommandContribution).toSelf().inSingletonScope();
bind(CommandContribution).toService(SelectionProviderCommandContribution);

bind(FrontendApplicationContribution).to(HostedPluginInformer).inSingletonScope();
bind(FrontendApplicationContribution).to(HostedPluginController).inSingletonScope();
Expand Down
46 changes: 46 additions & 0 deletions packages/plugin-ext/src/main/browser/selection-provider-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/********************************************************************************
* Copyright (C) 2019 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 { Command, CommandContribution, CommandRegistry } from '@theia/core/lib/common/command';
import { inject, injectable } from 'inversify';
import { UriAwareCommandHandler, UriCommandHandler } from '@theia/core/lib/common/uri-command-handler';
import URI from '@theia/core/lib/common/uri';
import { SelectionService } from '@theia/core';
import { theiaUritoUriComponents } from '../../common/uri-components';

export namespace SelectionProviderCommands {
export const GET_SELECTED_CONTEXT: Command = {
id: 'theia.plugin.workspace.selectedContext'
};
}

@injectable()
export class SelectionProviderCommandContribution implements CommandContribution {

@inject(SelectionService) protected readonly selectionService: SelectionService;

registerCommands(commands: CommandRegistry): void {
commands.registerCommand(SelectionProviderCommands.GET_SELECTED_CONTEXT, this.newMultiUriAwareCommandHandler({
isEnabled: () => true,
isVisible: () => false,
execute: (selectedUris: URI[]) => selectedUris.map(uri => theiaUritoUriComponents(uri))
}));
}

protected newMultiUriAwareCommandHandler(handler: UriCommandHandler<URI[]>): UriAwareCommandHandler<URI[]> {
return new UriAwareCommandHandler(this.selectionService, handler, { multi: true });
}
}

0 comments on commit 02ead36

Please sign in to comment.