Create a new file in the Packages/User directory and call it open_vm.py or something like that. Paste the following code into that file.
import sublime, sublime_plugin, os
class OpenInstanceVmFileCommand(sublime_plugin.WindowCommand):
def run(self):
#for each selection execute open file
for sel in self.window.active_view().sel():
# select the region for the file name
# this will be used to locate the correct
# instanceIdentifier
target = self.get_target_file_region(sel)
# skip if we didn't find a match
if(not target):
continue
#extract the target file name
target_file = self.window.active_view().substr(target).split("\'")[1]
#get the identifier for this xml entry
identifier = self.get_instance_identifier(target)
self.open_vm_file(identifier, target_file)
def open_vm_file(self, identifier, target_file):
# I was getting weird results with this comment code, it may be needed for you.
## get the xml file path
## file_loc = os.path.dirname(self.window.active_view().file_name())
## file_path = file_loc + os.sep + identifier + os.sep + target_file
file_path = identifier + os.sep + target_file
print (file_path)
self.window.run_command("open_file", {"file": file_path})
def get_instance_identifier(self, target):
instanceIdentifiers = self.window.active_view().find_all("instanceIdentifier\=\"[a-z0-9]+")
#locate the instanceId prior to this line
for iid in reversed(instanceIdentifiers):
# the current iid region is lower in the file so skip it
if (iid.begin() > target.begin()):
continue
#we found a match so return it
return self.window.active_view().substr(iid).replace("instanceIdentifier=\"", "")
def get_target_file_region(self, sel):
#get the line starting position
line_start = self.window.active_view().line(sel).begin()
#locate the executeFile call within that line
return self.window.active_view().find("ExecuteFile\(\'[a-z0-9\_\.]+", line_start, sublime.IGNORECASE)
To get the double click working you will need to create a “Default (Window/OSX/Linux).sublime-mousemap” file as well. Just use the OS you are using in the parenthesis and paste the following code.
{
"button": "button1", "modifiers": "ctrl"], "count": 2,
"command": "open_instance_vm_file"
}
]
I forget if there is way to limit this mouse map to a specific file type. I know keyboard mapping can be done through context entries, but I couldn’t get it to work with this. Just use “CTRL+ DOuble Click” and that should launch the file.
I am sure this coudl be cleaned up quite a bit, but this should get you started.