在Atom编辑器初始化脚本中使用树状视图 [英] Use the tree-view in Atom editor init script

查看:118
本文介绍了在Atom编辑器初始化脚本中使用树状视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Atom编辑器编写一个初始化脚本,以添加一个自定义命令,以便能够使用一种组合键(而不是两种组合键)在树状视图中显示当前打开的编辑器文件.

I'm trying to write a init script for the Atom editor to add a custom command to be able to reveal the currently opened editor file in the tree-view with one key combination, instead of two.

下面是一个示例代码(它有所不同),以阐明其总体外观.

Here is an example code (which makes something different) to make clear how it generally has to look like.

atom.commands.add 'atom-editor', 'custom:cut-line', ->
  editor = atom.workspace.getActiveEditor()
  editor.selectLine()
  editor.cutSelectedText()

我需要的两个命令不应发送到editor,而应发送到tree-view.这是两个命令:

The two commands I need should not be sent to the editor, but to the tree-view. Here are the two commands:

  tree-view:toggle-focus
  tree-view:reveal-active-file

我认为我必须做与上述类似的事情,例如getActiveTreeView或类似的事情.我试图用谷歌搜索它,但它似乎并不明显.有人知道该怎么做吗?

I assume I have to do something similar as above, like getActiveTreeView or something like that. I tried to google it but it doesn't seem to be obvious. Does someone know how to do this?

它可能看起来像这样:

atom.commands.add 'atom-editor', 'custom:show-active-file', ->
  tree-view.toggle-focus()
  tree-view.reveal-active-file()

推荐答案

当很难获得要发送命令的对象时,可以使用atom.commands.dispatch()方法发送命令.您可以使用:

You can use the atom.commands.dispatch() method to send a command when getting a hold of the object to send the commands to is hard. In your case, you can use:

atom.commands.add 'atom-editor', 'custom:show-active-file', ->
  atom.commands.dispatch(atom.workspaceView.element, 'tree-view:toggle-focus')
  atom.commands.dispatch(atom.workspaceView.element, 'tree-view:reveal-active-file')

这篇关于在Atom编辑器初始化脚本中使用树状视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆