2015-08-21 76 views
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 

回答

1

打開一個文件,你知道完整的路徑是非常直接的。只要使用的sublime.Window

例如在open_file方法,

sublime.active_window().open_file(path + '/style.css') 

雖然這將是最好的,以確保它在Python代碼告訴崇高打開它之前明確關閉。

我並不完全清楚你的意思是「專注邊欄」,但作爲一個模型,作爲SideBarEnhancements項目可能有些幫助嗎?

+0

非常感謝你,iv一直在嘗試.open_file(path +'/style.css'),但沒有意識到我需要事先sublime.active_window()。 至於聚焦邊欄,我希望創建的資產文件夾在邊欄中打開(就好像用戶要在文件樹中導航到文件夾本身一樣)。 它可能是類似sublime.active_window()的東西。 run_command(「reveal_in_side_bar」) – James

+0

或者如果可能的話,在打開的style.css文件(alt + shit + n)上運行一個熱鍵組合,它會在邊欄中顯示 – James

+0

@James:希望有人知道,不幸的是,我沒有。一個'prompt_add_folder'命令和一個'remove_folder'命令,但沒有添加任何我能找到的文件夾。 – ig0774

相關問題