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 了,然后把命令删了重新敲一遍". 自己还真不知道怎么操作,只知道历史命令 ...
随机推荐
- day5_python之subprocess模块
subprocess作用:用来执行系统命令它会开启一个子进程,通过子进程去执行一些命令 读取正确的命令执行结果,如果没有指定把结果输出到哪里,默认打印到屏幕上 #subprocess.Popen(r' ...
- H3C SSH配置例子
- css3 word-wrap属性
允许长单词换行到下一行: word-wrap:break-word
- Android Studio(八):Android Studio设置教程
Android Studio相关博客: Android Studio(一):介绍.安装.配置 Android Studio(二):快捷键设置.插件安装 Android Studio(三):设置Andr ...
- AtCoder Beginner Contest 077 C Snuke Festival(二分)
二分水题,A,B,C三个数组排序,对于每个B[i],二分算出来有多少A比他小,多少C比他大,然后扫一遍出结果.O(nlog(n))水过. #include <bits/stdc++.h> ...
- Keras框架下的保存模型和加载模型
在Keras框架下训练深度学习模型时,一般思路是在训练环境下训练出模型,然后拿训练好的模型(即保存模型相应信息的文件)到生产环境下去部署.在训练过程中我们可能会遇到以下情况: 需要运行很长时间的程序在 ...
- Vue 路由的嵌套使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- POJ 2488 深搜dfs、
题意:模拟国际象棋中马的走棋方式,其实和中国象棋的马走的方式其实是一样的,马可以从给定的方格棋盘中任意点开始,问是否能遍历全部格子,能的话输出字典序最小的走棋方式,否则输出impossible 思路: ...
- P1105 数列
题目描述 给定一个正整数 \(k(2 \le k \le 15)\) ,把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当 \(k = 3\) 时,这个序列是: 1,3,4, ...
- Spring Security原理篇(一) 启动原理
1.概述 spring security有参考的中文翻译文档https://springcloud.cc/spring-security-zhcn.html 在学习spring security的时候 ...