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 了,然后把命令删了重新敲一遍". 自己还真不知道怎么操作,只知道历史命令 ...
随机推荐
- H3C用Telnet登录
- iPython的安装过程
http://blog.csdn.net/u012587561/article/details/50900781 python2.7.10 amd64 win10 x64 1. 安装setuptool ...
- HTML的优化
HTML的优化 : 1).h标签的使用: 要注意的是,不论任何页面,h1标签只能出现一次,它是当前页面的主标题,权重最高, 所以要慎用 . 一般情况下,如果有关键词的话最好是在h1里面出现. h2是表 ...
- oracle之简null空值问题,用nvl(a,b)函数解决
oracle之简null空值问题,用nvl(a,b)函数解决 原文链接:https://blog.csdn.net/u013821825/article/details/48766749 oracle ...
- 精选Pycharm里6大神器插件
http://www.sohu.com/a/306693644_752099 上次写了一篇关于Sublime的精品插件推荐,有小伙伴提议再来一篇Pycharm的主题.相比Sublime,Pycharm ...
- CentOS 安装 semanage 命令
CentOS 安装 semanage 命令 在服务器上运行: [root@ca1 ~]# yum install policycoreutils-python vim /etc/selinux/con ...
- vue调用兄弟组件的方法使用vueBus调用$emit、$on(只需触发方法即可,不需要考虑传值或参数的问题)
触发方: vueBus.$emit('queryAll') 被触发方: created() { vueBus.$on('queryAll', () => { this.getList() // ...
- Scheduler
先看看文档对于Scheduler的作用介绍 https://code4craft.gitbooks.io/webmagic-in-action/content/zh/posts/ch1-overvie ...
- H3C RIP基本配置
- P1081 弹珠游戏
题目出处 灵灵和他的小伙伴聪聪发掘了一个骨灰级别的游戏--超级弹珠. 游戏的内容是:在一个 n*n 的矩阵里,有若干个敌人,你的弹珠可以摧毁敌人,但只能攻击你所在的行.列里的所有敌人,然后你就可以获得 ...