Sublime Forum

"Reveal in tree view" on tab bar

#1

Github Atom has a “Reveal in Tree View” feature

When you right click on the file tab, there’s a menu allow you to navigate to the file on the sidebar (aka Tree View)

Is there any plugin can do that?

0 Likes

#2

This is available when right-clicking on the file itself as “Reveal in Side Bar”, not on the tab context. I’m unsure if there is a way to make it work for the tab bar since I don’t know if or how ST passes the view that was clicked on to the target command.

2 Likes

#3

All tab bar context menu items operate on the current view, not the view relating to the tab clicked on. As far as I know, there is no way to pass the view that relates to the tab that was clicked on to the target command.

EDIT: I stand corrected - using "args": { "group": -1, "index": -1 } in the Tab Context Menu.sublime-menu, it alters them and passes the correct group and index. However, it does mean that the command being used has to look at those arguments, so you may need a custom command to execute the real command.

2 Likes

Interface Suggestions
#4

Simple example to make the Copy File Path and Open Containing Folder commands work on the appropriate tab:

Packages/User/tab_context.py:

import sublime
import sublime_plugin
from os import path

def get_view(active_view, **kwargs):
    view = active_view
    if 'group' in kwargs and 'index' in kwargs:
        view = view.window().views_in_group(kwargs['group'])[kwargs['index']]
    return view

class CopyFilePathCommand(sublime_plugin.TextCommand):
    def run(self, edit, **kwargs):
        get_view(self.view, **kwargs).run_command('copy_path')
    
    def is_enabled(self, **kwargs):
        file_path = get_view(self.view, **kwargs).file_name()
        return isinstance(file_path, str)
    
    def is_visible(self, **kwargs):
        return True

class OpenContainingFolderFromTabCommand(sublime_plugin.TextCommand):
    def run(self, edit, **kwargs):
        file_path = get_view(self.view, **kwargs).file_name()
        folder = path.dirname(file_path)
        if path.isdir(folder):
            file_name = path.basename(file_path)
            if path.isfile(file_path):
                self.view.window().run_command('open_dir', { "dir": folder, "file": file_name })
            else:
                self.view.window().run_command('open_dir', { "dir": folder })
    
    def is_enabled(self, **kwargs):
        file_path = get_view(self.view, **kwargs).file_name()
        folder = path.dirname(file_path)
        return file_path is not None and path.isdir(folder)
    
    def is_visible(self, **kwargs):
        return True

Packages/Default/Tab Context.sublime-menu (partial):

{ "command": "copy_file_path", "args": { "group": -1, "index": -1 }, "caption": "Copy File Path" }
{ "command": "open_containing_folder_from_tab", "args": { "group": -1, "index": -1 }, "caption": "Open Containing Folder…" },
1 Like