facelessuser / FavoriteFiles

Sublime Text plugin to save favorite files http://facelessuser.github.io/FavoriteFiles/
70 stars 8 forks source link

Favorites created in Windows fail in MacOS and vice-versa #24

Closed tomhundt closed 1 year ago

tomhundt commented 4 years ago

I work cross-platform Mac/Windows these days, and have my Sublime User dir synced via Dropbox. This means that when I create a new Favorite, it shows up on all my computers -- great!

But: if a favorite was created on a Mac, its path gets saved with forward slashes (/Users/thundt/Downloads/foo.txt) and if saved on Windows, it's saved with backslashes (C:\Users\thundt\Downloads\foo.txt).

When I go to open these, there is no error, but rather (if opening a Mac favorite on Windows) presents me with an empty file, marked as modified, or (if opening a Win file on Mac) silently fails (no console output).

Any ideas? Looking at the code, it appears you're just doing this, and letting Sublime worry about any conversion:

                for n in names:
                    if os.path.exists(n):
                        view = self.window.open_file(n)
                        if view is not None:
                            focus_view = view
                            if active_group >= 0:
                                self.window.set_view_index(view, active_group, count)
                            count += 1
                    else:
                        error("The following file does not exist:\n%s" % n)
                if focus_view is not None:
                    # Horrible ugly hack to ensure opened file gets focus
                    def fn(focus_view):
                        """Ensure focus of view."""
                        self.window.focus_view(focus_view)
                        self.window.show_quick_panel(["None"], None)
                        self.window.run_command("hide_overlay")
                    sublime.set_timeout(lambda: fn(focus_view), 500)

One issue is probably the drive letter... silly Windows. It doesn't look like there's a hook I could easily patch into to add a little conversion routine, which is probably what I'd need.

Thanks

facelessuser commented 4 years ago

Unfortunately, as a favorite could be found anywhere on a system, there is no easy way to be OS agnostic. While in your specific use case, your files follow a similar path, I'd argue that you're in a minority. Any solution I could provide would not be very portable for most. I would not normally suggest syncing the favorite settings across platforms, or even systems, as available files and folder paths are not guaranteed to be the same.