-
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.
Add ability to register keybindings from 'package.json' file of a plugin
Signed-off-by: Roman Nikitenko <[email protected]>
- Loading branch information
1 parent
a37b81d
commit 585399d
Showing
5 changed files
with
103 additions
and
0 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
65 changes: 65 additions & 0 deletions
65
packages/plugin-ext/src/main/browser/keybindings/keybindings-contribution-handler.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,65 @@ | ||
/******************************************************************************** | ||
* 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 { PluginContribution } from '../../../common'; | ||
import { Keybinding, KeybindingRegistry, KeybindingScope } from '@theia/core/lib/browser/keybinding'; | ||
import { KeySequence } from '@theia/core/lib/browser'; | ||
import { ILogger } from '@theia/core/lib/common/logger'; | ||
|
||
@injectable() | ||
export class KeybindingsContributionPointHandler { | ||
|
||
@inject(ILogger) | ||
protected readonly logger: ILogger; | ||
|
||
@inject(KeybindingRegistry) | ||
private readonly keybindingRegistry: KeybindingRegistry; | ||
|
||
handle(contributions: PluginContribution): void { | ||
if (!contributions || !contributions.keybindings) { | ||
return; | ||
} | ||
|
||
const keybindings = contributions.keybindings; | ||
keybindings.forEach(keybinding => { | ||
const keybindingResult = this.keybindingRegistry.getKeybindingsForKeySequence(KeySequence.parse(keybinding.keybinding)); | ||
|
||
this.handleShadingKeybindings(keybinding, keybindingResult.shadow); | ||
this.handlePartialKeybindings(keybinding, keybindingResult.partial); | ||
}); | ||
|
||
this.keybindingRegistry.setKeymap(KeybindingScope.USER, keybindings); | ||
} | ||
|
||
private handlePartialKeybindings(keybinding: Keybinding, partialKeybindings: Keybinding[]) { | ||
partialKeybindings.forEach(partial => { | ||
if (keybinding.context === undefined || keybinding.context === partial.context) { | ||
this.logger.warn(`Partial keybinding is ignored; ${Keybinding.stringify(keybinding)} shadows ${Keybinding.stringify(partial)}`); | ||
} | ||
}); | ||
} | ||
|
||
private handleShadingKeybindings(keybinding: Keybinding, shadingKeybindings: Keybinding[]) { | ||
shadingKeybindings.forEach(shadow => { | ||
if (shadow.context === undefined || shadow.context === keybinding.context) { | ||
this.keybindingRegistry.unregisterKeybinding(shadow); | ||
|
||
this.logger.warn(`Shadowing keybinding is ignored; ${Keybinding.stringify(shadow)}, shadows ${Keybinding.stringify(keybinding)}`); | ||
} | ||
}); | ||
} | ||
} |
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