Sublime Text Plugin Dev - Open a file, Focus folder in sidbar

user4831663

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
ig0774

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Sublime Text Plugin Dev - Open a file, Focus folder in sidbar

From Dev

sublime text : open containing folder

From Dev

sublime text 3 - console - how to open a file

From Dev

"unable to open" a sublime text macro file

From Dev

Open a folder in Sublime Text 3 using command line

From Dev

Sublime Text Plugin using applescript can not open FirefoxDeveloperEdition

From Dev

Open text file not in current folder in MATLAB

From Dev

How can I find the particular file in a Project/Folder in Sublime Text

From Dev

How do I echo the changes to a file in a sublime text plugin

From Dev

Get file syntax selection in sublime text 3 plugin

From Dev

Sublime Text open a specific file with the command palette or key binding

From Java

Sublime Text 2 and 3: open the same file multiple times

From Dev

How can I open the current file in a new pane in sublime text?

From Dev

Is there a shortcut for Sublime Text to find an open file (Eclipse Ctrl + E)?

From Dev

Sublime Text: How to automatically open with specific encoding for some file extensions?

From Dev

sublime text 2 open file from find results keyboard shortcut

From Dev

How to open file using only keyboard in Sublime Text?

From Dev

Sublime Text open a specific file with the command palette or key binding

From Dev

IntellijIdea plugin dev: Navigate to the source file of a given class in the text editor

From Dev

IntellijIdea plugin dev: Navigate to the source file of a given class in the text editor

From Dev

sublime plugin: find and select text

From Dev

Sublime Text hour counter plugin

From Dev

Sublime Text plugin installing and using?

From Dev

Sublime Text 2 Terminal plugin

From Dev

Can I right-click a folder in Windows 7 and choose "Open with Sublime Text"?

From Dev

Can't open folder that was dragged and dropped to sidebar in sublime text3

From Dev

How to open a different tab in same folder using sublime text or visual studio code?

From Dev

Shortcut/"Open with" Sublime Text, in a new Sublime window

From Dev

Possible for Sublime Text 2 to save on loss of focus?

Related Related

  1. 1

    Sublime Text Plugin Dev - Open a file, Focus folder in sidbar

  2. 2

    sublime text : open containing folder

  3. 3

    sublime text 3 - console - how to open a file

  4. 4

    "unable to open" a sublime text macro file

  5. 5

    Open a folder in Sublime Text 3 using command line

  6. 6

    Sublime Text Plugin using applescript can not open FirefoxDeveloperEdition

  7. 7

    Open text file not in current folder in MATLAB

  8. 8

    How can I find the particular file in a Project/Folder in Sublime Text

  9. 9

    How do I echo the changes to a file in a sublime text plugin

  10. 10

    Get file syntax selection in sublime text 3 plugin

  11. 11

    Sublime Text open a specific file with the command palette or key binding

  12. 12

    Sublime Text 2 and 3: open the same file multiple times

  13. 13

    How can I open the current file in a new pane in sublime text?

  14. 14

    Is there a shortcut for Sublime Text to find an open file (Eclipse Ctrl + E)?

  15. 15

    Sublime Text: How to automatically open with specific encoding for some file extensions?

  16. 16

    sublime text 2 open file from find results keyboard shortcut

  17. 17

    How to open file using only keyboard in Sublime Text?

  18. 18

    Sublime Text open a specific file with the command palette or key binding

  19. 19

    IntellijIdea plugin dev: Navigate to the source file of a given class in the text editor

  20. 20

    IntellijIdea plugin dev: Navigate to the source file of a given class in the text editor

  21. 21

    sublime plugin: find and select text

  22. 22

    Sublime Text hour counter plugin

  23. 23

    Sublime Text plugin installing and using?

  24. 24

    Sublime Text 2 Terminal plugin

  25. 25

    Can I right-click a folder in Windows 7 and choose "Open with Sublime Text"?

  26. 26

    Can't open folder that was dragged and dropped to sidebar in sublime text3

  27. 27

    How to open a different tab in same folder using sublime text or visual studio code?

  28. 28

    Shortcut/"Open with" Sublime Text, in a new Sublime window

  29. 29

    Possible for Sublime Text 2 to save on loss of focus?

HotTag

Archive