1
我想展開我的Sublime Text 3 Plugin,它目前正在觀察創建一個帶有lp_前綴的.php文件並創建一個相同的文件夾名稱爲CSS和圖像。Sublime Text Plugin Dev - 在sidbar中打開一個文件,Focus文件夾
我試圖找到一種方法,在創建後將資源文件夾側邊欄關注,並且還打開style.css文件。目標是能夠創建一個允許快速創建登錄頁面的插件。
任何崇高的文本/ Python大師沒有如何我可能專注於側邊欄/打開文件?
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
非常感謝你,iv一直在嘗試.open_file(path +'/style.css'),但沒有意識到我需要事先sublime.active_window()。 至於聚焦邊欄,我希望創建的資產文件夾在邊欄中打開(就好像用戶要在文件樹中導航到文件夾本身一樣)。 它可能是類似sublime.active_window()的東西。 run_command(「reveal_in_side_bar」) – James
或者如果可能的話,在打開的style.css文件(alt + shit + n)上運行一個熱鍵組合,它會在邊欄中顯示 – James
@James:希望有人知道,不幸的是,我沒有。一個'prompt_add_folder'命令和一個'remove_folder'命令,但沒有添加任何我能找到的文件夾。 – ig0774