I'm trying to write a plugin that will allow me to open a group of related files in one go. The premise being:
- The plugin presents the user with a list of directories (ostensibly self contained ui components)
- The user chooses a directory
- The plugin creates a new 3 column layout
- A .js file is opened in the first column from the selected directory
- A .html file is opened in the second column from the selected directory
- A .scss file is opened in the third column from the selected directory
So far, I've got the plugin presenting the user with a choice of directories, and creating the three column layout, but I can;t figure out how to traverse the three column layout to open files in new views
import sublime, sublime_plugin, os
class OpenSesameCommand(sublime_plugin.TextCommand):
def run(self, edit):
#This is the directory where the components are kept
self.thedir = '/Users/tom/Documents/Tradeweb/tradeweb-uscc/src/js/components'
self.window = sublime.active_window()
#Get all directories in the component directory
self.listings = [ name for name in os.listdir(self.thedir) if os.path.isdir(os.path.join(self.thedir, name)) ]
#Show all directories in the quick panel
self.window.show_quick_panel(self.listings, self.open_component, sublime.MONOSPACE_FONT)
def open_component(self, index):
# Generate file paths to the relevant files
compName = self.listings[index]
jsFile = self.create_file_ref(compName, 'js')
htmlFile = self.create_file_ref(compName, 'html')
sassFile = self.create_file_ref(compName, 'scss')
#create a new layout
self.window.set_layout({
"cols": [0.0, 0.3, 0.6, 1.0],
"rows": [0.0, 1.0],
"cells": [ [0, 0, 1, 1], [1, 0, 1, 1], [2, 0, 2, 1]]
})
# ??? how can I set the focus on different columns
#open files
#self.window.open_file(htmlFile)
#self.window.open_file(jsFile)
#self.window.open_file(sassFile)
def create_file_ref(self, component, type):
componentDir = self.thedir + '/' + component + '/'
return componentDir + component + '.' + type
Looking through the API I get the impression it's going to have something to do with the view
and group
related methods on the Window
object but I can't for the life of me piece it together.
If someone could point out how I could open a file in the third column for example, I'm sure I could take it from there.
BTW: This is the first time I've used python so please forgive any bad-practices (but please point them out).