Sublime Forum

Opening Files (Externally) in Open Sublime Project

#1

Hey guys -

I use Sublime text with Unity and open files through each application. When telling Unity to open a source file externally I expect it to show as a tab in it’s Sublime project if the project is open and if not in a new window. This way I can keep multiple projects open in Sublime text and make it clear where all the source files belong.

Is there a way to do this currently?

Thanks.

1 Like

#2

You could write a Python plugin that, whenever a new file is opened, scans open windows for their project folders and opens the file in a window that contains the file in its folders.

Since ST internally does not differeniate between files being opened by you and files being opened externally (froma plugin point of view), it would have to make a few guesses as to whether the file was opened externally and what actions to perform after the file was moved (notably, whether to close the current window).

0 Likes

#3

Well that’s a bummer.

0 Likes

#4

I don’t quite follow what you mean by the different kind of file opening. Why would the file move or a window have to close?

ST has an index of all the files in the open project, seems simple to check if it’s in that project before opening it in a new window.

0 Likes

#5

It means that the on_load event only kicks in when the file is already opening. You’ll then have to re-open it in a different window and close it in the current, effectively moving it. If the current window is then empty (in case you ran ST with the -n command line option), it should also be closed since it’s not needed anymore.

The “index” that ST keeps only contains defined symbols, not the files themselves. You’d have to see if the file would be part of a folder in that project manually.

1 Like

#6

Put this files in your User directory, or create a plugin from them. Works on linux. For mac OS replace xdg-open with open.

open_with_default_application.py:

import os
import subprocess
import sublime
import sublime_plugin


class OpenWithDefaultApplicationCommand(sublime_plugin.WindowCommand):
    def is_visible(self):
        view = self.window.active_view()
        return bool(view and view.file_name())

    def run(self):
        view = self.window.active_view()
        path = view.file_name()
        subprocess.Popen(["xdg-open", path])

Side Bar.sublime-menu:

[
  {
    "caption": "Open with default application",
    "command": "open_with_default_application",
  }
]

0 Likes

#7

How about https://packagecontrol.io/packages/Open%20in%20Default%20Application?

2 Likes