我正在尝试扩展我的Sublime Text 3插件,它目前正在监视创建一个前缀为lp_的.php文件,并为css和images创建一个同名文件夹。
我试图在创建后找到一种方法将侧边栏集中在assets文件夹上,同时也打开style.css文件。目标是能够创建一个允许快速创建登录页面的插件。
任何Sublime Text / Python Gurus都没有我可能专注于侧边栏/打开文件?
import sublime, sublime_plugin, os
# We extend event listener
class lp_folder_create(sublime_plugin.EventListener):
# This method is called every time a file is saved (not only the first time is saved)
def on_post_save_async(self, view):
variables = view.window().extract_variables()
fileBaseName = variables['file_base_name'] # File name without extension
file_path = variables['file_path']
if fileBaseName.startswith('lp_'): #checks for php prefix
if file_path.endswith('/themes/folder'): # Only watches certain folder
path = file_path + '/lp/' + fileBaseName
imagepath = path + '/images/'
os.mkdir(path) # Creates folder
#TRYING TO FOCUS SIDEBAR ON THIS FOLDER
os.mkdir(imagepath)
open(path + "/style.css", 'w') # Creates style.css
#TRYING TO OPEN THIS FILE IN SUBLIME AFTER CREATION
os.system('open "%s"' % (path + "/")) #Opens in finder for placement of image assets
答案 0 :(得分:1)
打开一个您知道完整路径的文件非常简单。只需使用sublime.Window
open_file
方法即可
如,
sublime.active_window().open_file(path + '/style.css')
虽然在告诉Sublime打开它之前,最好确保它在Python代码中显式关闭。
我并不完全清楚你的意思是什么?"专注于侧边栏,"但也许SideBarEnhancements项目作为模型有一些帮助?