gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:29:32 25 4
gpt4 key购买 nike

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

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

到目前为止,我已经让插件向用户展示了目录选择,并创建了三列布局,但我不知道如何遍历三列布局以在新 View 中打开文件

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 相关方法有关,但我不能我的生活把它拼凑起来。

如果有人可以指出我如何打开第三列中的文件,我确信我可以从那里获取它。

顺便说一句:这是我第一次使用 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)

要设置布局,请使用 this引用。缓存是 here ,因为它一直处于关闭状态。

关于python - 如何使用 sublime 插件 api 创建新布局并在每个单元格中打开一个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21121050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com