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 了,然后把命令删了重新敲一遍". 自己还真不知道怎么操作,只知道历史命令 ...
随机推荐
- Hive高阶聚合函数 GROUPING SETS、Cube、Rollup
-- GROUPING SETS作为GROUP BY的子句,允许开发人员在GROUP BY语句后面指定多个统计选项,可以简单理解为多条group by语句通过union all把查询结果聚合起来结合起 ...
- C#中的?操作符
一.1个?的用法 1. 表示可空数据类型,如 int? bool? 2. 跟在对象后,如该对象为null,则不会触发空值异常,且整个表达式返回null,如: string kk = "123 ...
- ]ubuntu开机自动挂载的ntfs硬盘的权限问题
原文地址:ubuntu开机自动挂载的ntfs硬盘的权限问题 在linux操作系统中, 挂载是一个非常重要的功能,使用非常频繁. 它指将一个设备(通常是存储设备)挂接到一个已存在的目录上. (这个目录可 ...
- 2019-8-31-dotnet-将文件删除到回收站
title author date CreateTime categories dotnet 将文件删除到回收站 lindexi 2019-08-31 16:55:58 +0800 2019-03-2 ...
- 使用php函数ini_set()重新设置某个配置的设置值
使用PHP的ini_set()函数 ini_set (PHP 4, PHP 5, PHP 7) ini_set — 为一个配置选项设置值 说明 string ini_set ( string $var ...
- Python 的经典入门书籍
实python非常适合初学者入门,上手很容易.我就是完全通过网上资源学了python的.最大的是3点经验:1.找一本浅显易懂,例程比较好的教程,从头到尾看下去.不要看很多本,专注于一本.把里面的例程都 ...
- JS iFrame 加载慢怎么解决
在项目中经常要动态添加iframe,然后再对添加的iframe进行相关操作,有时候会遇到iframe加载很慢什么原因呢,该如何解决呢?带着这个问题一起通过本文学习,寻找答案吧! aaa.html &l ...
- java表达式和三目运算符
是由数字.运算符.数字分组符号(括号)等以能求得数值的有意义排列的序列; a + b 3.14 + a (x + y) * z + 100 boolean b= i < 10 && ...
- 2019年第二阶段我要变强个人训练赛第八场 B.序列(seq)
传送门 B.序列(seq) •题目描述 给出一个长度为n的序列a,每次对序列进行一下的某一个操作. •输入 第一行两个整数n,q表示序列长度和操作个数. 接下来一行n个数,表示序列a. 接下来q行表示 ...
- P1091 剧院广场
题目描述 柏林首都的剧院广场呈长方形,面积为 \(n \times m\) 平方米.在这座城市的周年纪念日之际,人们决定用方形花岗岩石板铺设广场.每块石板的大小都是 \(a \times a\) . ...