Theia APIs——命令和快捷键
上一篇:使用Theia——创建语言支持
命令和快捷键
Theia可以通过多种不同的方式进行扩展。命令允许packages提供可以被其它包调用的唯一命令,还可以向这些命令添加快捷键和上下文,使得它们只能在某些特定的条件下被调用(如窗口获取焦点、当前选项等)。
在Theia中添加命令
要将命令添加到Theia,必须实现CommandContribution类,如:
java-commands.ts
@injectable()
export class JavaCommandContribution implements CommandContribution {
...
registerCommands(commands: CommandRegistry): void {
commands.registerCommand(SHOW_JAVA_REFERENCES, {
execute: (uri: string, position: Position, locations: Location[]) =>
commands.executeCommand(SHOW_REFERENCES.id, uri, position, locations)
});
commands.registerCommand(APPLY_WORKSPACE_EDIT, {
execute: (changes: WorkspaceEdit) =>
!!this.workspace.applyEdit && this.workspace.applyEdit(changes)
});
}
}
export default new ContainerModule(bind => {
bind(CommandContribution).to(JavaCommandContribution).inSingletonScope();
...
});
负责注册和执行命令的类是CommandRegistry,通过get commandIds() api可以获取命令列表。
添加快捷键
@injectable()
export class EditorKeybindingContribution implements KeybindingContribution { constructor(
@inject(EditorKeybindingContext) protected readonly editorKeybindingContext: EditorKeybindingContext
) { } registerKeybindings(registry: KeybindingRegistry): void {
[
{
command: 'editor.close',
context: this.editorKeybindingContext,
keybinding: "alt+w"
},
{
command: 'editor.close.all',
context: this.editorKeybindingContext,
keybinding: "alt+shift+w"
}
].forEach(binding => {
registry.registerKeybinding(binding);
});
}
}
@injectable()
export class EditorKeybindingContext implements KeybindingContext {
constructor( @inject(EditorManager) protected readonly editorService: EditorManager) { } id = 'editor.keybinding.context'; isEnabled(arg?: Keybinding) {
return this.editorService && !!this.editorService.activeEditor;
}
}
export declare type Keystroke = { first: Key, modifiers?: Modifier[] };
Modifier是平台无关的,所以Modifier.M1在OS X上是Command而在Windows/Linux上是CTRL。Key字符串常量定义在keys.ts中。
将contribution绑定到KeybindingContribution
export default new ContainerModule(bind => {
...
bind(CommandContribution).to(EditorCommandHandlers);
bind(EditorKeybindingContext).toSelf().inSingletonScope();
bind(KeybindingContext).toDynamicValue(context => context.container.get(EditorKeybindingContext));
bind(KeybindingContribution).to(EditorKeybindingContribution);
});
Theia APIs——命令和快捷键的更多相关文章
- Theia APIs——Preferences
上一篇:Theia APIs——命令和快捷键 Preferences Theia有一个preference service,模块可以通过它来获取preference的值,提供默认的preference ...
- CentOS最常用命令及快捷键整理
CentOS最常用命令及快捷键整理 整理了Linux常用命令及快捷键. 常用命令: 文件和目录: # cd /home 进入 '/home' 目录 # ...
- Linux最常用命令及快捷键整理
最近在学Linux系统命令,在阿里云买了一台linux服务器.为方便自己也方便他人,整理了Linux常用命令及快捷键. 用命令: 文件和目录: # cd /home ...
- Linux学习新篇——常用命令和快捷键总结
最近刚接触Linux,整理了一些常用的命令和快捷键 Tab补全命令 当命令记不清了,输入记得的前几个用Tab就可以将该命令自动补全. 启动tomcat服务用$startup.sh 停止tomcat服务 ...
- Linux经常用到的命令以及快捷键
Linux常用命令和快捷键 最近一直在对CentOS系统进行各种体验,为方便自己也方便他人,整理了Linux常用命令及快捷键,不过其实大多和DOS是一样的,只是命令的表达上可能有点儿不一样. Linu ...
- 【转载】Linux 命令行快捷键 - 移动光标
Linux 命令行快捷键 - 移动光标 涉及在linux命令行下进行快速移动光标.命令编辑.编辑后执行历史命令.Bang(!)命令.控制命令等.让basher更有效率. 常用 ctrl+左右键:在单词 ...
- Linux命令行快捷键及vim快捷方式
Linux命令行快捷键 快捷键: tab键 自动补全路径 目录 名字, 自动不全命令 快捷键: ctrl +l(小写) 清屏 . ctrl +c 取消当前操作 快捷键: ctrl +d(小写) 退出当 ...
- (转帖)CentOS最常用命令及快捷键整理
原文:http://www.centoscn.com/CentOS/help/2014/0306/2493.html 最近开始学Linux,在VMware Player中安装了CentOS 6.4.为 ...
- [转]Linux 命令行快捷键
群里有人问"问个问题,Linux 命令行有没有快捷键一下从行末会到行头?经常敲了很多命令发现忘加 sudo 了,然后把命令删了重新敲一遍". 自己还真不知道怎么操作,只知道历史命令 ...
随机推荐
- jQuery的引入和使用
https://www.cnblogs.com/sandraryan/ 前端代码优化:无效循环越少越好,DOM节点操作越少越好,HTTP请求越少越好 jq是一个js库.(不是框架) JQ优点 1. 方 ...
- MVC插件式开发平台
---恢复内容开始--- 经过DyOS.BraveOS1.0再到BraveOS2.0,系统现在已经开发了下载. 我们的目标是,网页版操作系统,可以在线安装更新软件,并提供二次开发平台,提供基础的逻辑和 ...
- zoj 2954 Hanoi Tower
Hanoi Tower Time Limit: 2 Seconds Memory Limit: 65536 KB You all must know the puzzle named "Th ...
- win10 uwp xaml 绑定接口
本文告诉大家如何在 xaml 绑定属性使用显式继承接口 早上快乐 就在你的心问了我一个问题,他使用的属性是显式继承,但是无法在xaml绑定 我写了简单的代码,一个接口和属性 public class ...
- Vue 路由的嵌套使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Codeforces Round #196 (Div. 1 + Div. 2)
A. Puzzles 对\(f[]\)排序,取连续的\(m\)个. B. Routine Problem 考虑\(\frac{a}{b}\)和\(\frac{c}{d}\)的大小关系,适配后就是分数的 ...
- springboot aop的使用 学习总结
版权声明:本文为博主武伟峰原创文章,转载请注明地址http://blog.csdn.net/tianyaleixiaowu. aop是spring的两大功能模块之一,功能非常强大,为解耦提供了非常优秀 ...
- tensorflow在文本处理中的使用——Doc2Vec情感分析
代码来源于:tensorflow机器学习实战指南(曾益强 译,2017年9月)——第七章:自然语言处理 代码地址:https://github.com/nfmcclure/tensorflow-coo ...
- 2019-9-24-dotnet-remoting-抛出异常
title author date CreateTime categories dotnet remoting 抛出异常 lindexi 2019-09-24 15:39:50 +0800 2018- ...
- Linux 内核即插即用规范
一些新 ISA 设备板遵循特殊的设计规范并且需要一个特别的初始化顺序, 对增加接口板 的简单安装和配置的扩展. 这些板的设计规范称为即插即用, 由一个麻烦的规则集组成, 来建立和配置无跳线的 ISA ...