如何使用sublime插件api创建新布局并在每个单元格中打开一个文件



我正在尝试编写一个插件,它将允许我一次性打开一组相关文件。前提是:

  1. 插件向用户提供目录列表(表面上是自包含的ui组件)
  2. 用户选择一个目录
  3. 该插件创建了一个新的3列布局
  4. 在所选目录的第一列中打开一个.js文件
  5. 在所选目录的第二列中打开一个.html文件
  6. scss文件在所选目录的第三列中打开

到目前为止,我已经获得了为用户提供目录选择的插件,并创建了三列布局,但我可以;我不知道如何遍历三列布局以在新视图中打开文件

import sublime, sublime_plugin, os
class OpenSesameCommand(sublime_plugin.TextCommand):
def run(self, edit):
#This is the directory where the components are kept
self.thedir = '/Users/tom/Documents/Tradeweb/tradeweb-uscc/src/js/components'
self.window = sublime.active_window()
#Get all directories in the component directory
self.listings = [ name for name in os.listdir(self.thedir) if os.path.isdir(os.path.join(self.thedir, name)) ]
#Show all directories in the quick panel
self.window.show_quick_panel(self.listings, self.open_component, sublime.MONOSPACE_FONT)
def open_component(self, index):
# Generate file paths to the relevant files
compName = self.listings[index]
jsFile = self.create_file_ref(compName, 'js')
htmlFile = self.create_file_ref(compName, 'html')
sassFile = self.create_file_ref(compName, 'scss')
#create a new layout
self.window.set_layout({
"cols": [0.0, 0.3, 0.6, 1.0],
"rows": [0.0, 1.0],
"cells": [ [0, 0, 1, 1], [1, 0, 1, 1], [2, 0, 2, 1]]
})
# ??? how can I set the focus on different columns
#open files
#self.window.open_file(htmlFile)
#self.window.open_file(jsFile)
#self.window.open_file(sassFile)

def create_file_ref(self, component, type):
componentDir = self.thedir + '/' + component + '/'
return componentDir + component + '.' + type 

通过查看API,我得到的印象是它与Window对象上的viewgroup相关方法有关,但我无法将其拼凑在一起。

例如,如果有人能指出我如何在第三列中打开一个文件,我相信我可以从那里得到它。

BTW:这是我第一次使用python,所以请原谅任何不好的做法(但请指出)。

您需要使用

self.window.focus_group(0)
self.window.open_file(htmlFile)
self.window.focus_group(1)
self.window.open_file(jsFile)
self.window.focus_group(2)
self.window.open_file(sassFile)

或者,等效地,

for i, file in enumerate([htmlFile, jsFile, sassFile]):
self.window.focus_group(i)
self.window.open_file(file)

要设置布局,请使用此参考。这里有一个缓存,因为它一直处于关闭状态。

相关内容

最新更新