I am trying to expand my Sublime Text 3 Plugin, it currently watches for the creation of a .php file with a prefix of lp_ and creates a folder of the same name for css and images.
I am trying to find a way to focus the sidebar on the assets folder after creation and also open the style.css file as well. The goal is to be able to create a plugin that allows for rapid creation of landing pages.
Any Sublime Text / Python Gurus no how I could possibly focus on sidebar / open file?
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
Opening a file where you know the full path is pretty straight-forward. Just use the open_file
method of sublime.Window
e.g.,
sublime.active_window().open_file(path + '/style.css')
Although it would be best to ensure that it is explicitly closed in Python code before telling Sublime to open it.
I'm not entirely clear what you mean by "focus the sidebar," but perhaps the SideBarEnhancements project is of some help as a model?
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments