@theia/cpp
Version:
Theia - Cpp Extension
68 lines (58 loc) • 2.41 kB
text/typescript
/********************************************************************************
* Copyright (C) 2017 Ericsson 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 { isOSX } from '@theia/core/lib/common/os';
import { EditorManager } from '@theia/editor/lib/browser';
import {
KeybindingContext, Keybinding, KeybindingContribution, KeybindingRegistry
} from '@theia/core/lib/browser';
import { editorContainsCppFiles } from './cpp-commands';
()
export class CppKeybindingContext implements KeybindingContext {
constructor( (EditorManager) protected readonly editorService: EditorManager) { }
id = 'cpp.keybinding.context';
/**
* Determine if the keybinding is enabled.
* The keybinding is enabled if the editor currently contains an active C/C++ file.
* @param arg the keybinding.
*
* @returns `true` if the keybinding is enabled.
*/
isEnabled(arg: Keybinding): boolean {
return editorContainsCppFiles(this.editorService);
}
}
()
export class CppKeybindingContribution implements KeybindingContribution {
constructor(
(CppKeybindingContext) protected readonly cppKeybindingContext: CppKeybindingContext
) { }
/**
* Register keybindings.
* @param registry the keybinding registry.
*/
registerKeybindings(registry: KeybindingRegistry): void {
[
{
command: 'switch_source_header',
context: this.cppKeybindingContext.id,
keybinding: isOSX ? 'option+cmd+o' : 'alt+o'
}
].forEach(binding => {
registry.registerKeybinding(binding);
});
}
}