Skip to content

Commit

Permalink
add setting to disable tab context
Browse files Browse the repository at this point in the history
  • Loading branch information
braver committed Oct 21, 2023
1 parent f083c1e commit 7252853
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Commands.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"caption": "File: Copy Absolute Path",
"command": "side_bar_copy_absolute_path",
"args": { "paths": [], "trigger": "palette" }
"args": { "paths": [], "context": "palette" }
},
{
"caption": "File: Duplicate…",
Expand Down
22 changes: 12 additions & 10 deletions SideBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def get_setting(window_command, setting):

class SideBarCommand(sublime_plugin.WindowCommand):

def is_visible(self, paths=[], context=""):
if context == 'tab' and not get_setting(self, 'tab_context'):
return False
if paths:
return len(paths) < 2
return bool(self.window.active_view().file_name())

def copy_to_clipboard_and_inform(self, data):
sublime.set_clipboard(data)
lines = len(data.split('\n'))
Expand All @@ -38,11 +45,6 @@ def get_path(self, paths):
except IndexError:
return self.window.active_view().file_name()

def is_visible(self, paths=[]):
if paths:
return len(paths) < 2
return bool(self.window.active_view().file_name())

@staticmethod
def make_dirs_for(filename):
destination_dir = os.path.dirname(filename)
Expand All @@ -56,10 +58,10 @@ def make_dirs_for(filename):

class SideBarCompareCommand(sublime_plugin.WindowCommand):

def is_visible(self, paths):
def is_visible(self, paths, context=""):
return len(paths) == 2 and bool(get_setting(self, 'difftool'))

def is_enabled(self, paths):
def is_enabled(self, paths, context=""):
if len(paths) < 2 or not get_setting(self, 'difftool'):
return False
return os.path.isdir(paths[0]) == os.path.isdir(paths[1])
Expand Down Expand Up @@ -95,12 +97,12 @@ def description(self):

class SideBarCopyAbsolutePathCommand(MultipleFilesMixin, SideBarCommand):

def is_visible(self, paths=[], trigger=""):
def is_visible(self, paths=[], context=""):
# in 4158 ST gets the "copy path" sidebar context entry
# we want to keep our command palette entry though
if trigger != 'palette' and int(sublime.version()) >= 4158:
if context != 'palette' and int(sublime.version()) >= 4158:
return False
return super().is_visible(paths)
return super().is_visible(paths, context)

def run(self, paths=[]):
paths = self.get_paths(paths)
Expand Down
3 changes: 3 additions & 0 deletions SideBarTools.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@

// Add the Edit item to the Side Bar menu
"edit_command": false,

// Enable the Tab Context menu
"tab_context": true
}
14 changes: 7 additions & 7 deletions Tab Context.sublime-menu
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@
{
"caption": "Copy Filename",
"command": "side_bar_copy_name",
"args": { "paths": [] }
"args": { "paths": [], "context": "tab" }
},
{
"caption": "Copy Relative Path",
"command": "side_bar_copy_relative_path",
"args": { "paths": [] }
"args": { "paths": [], "context": "tab" }
},
{
"caption": "Copy Absolute Path",
"command": "side_bar_copy_absolute_path",
"args": { "paths": [] }
"args": { "paths": [], "context": "tab" }
},
{
"caption": "Duplicate…",
"command": "side_bar_duplicate",
"args": { "paths": [] }
"args": { "paths": [], "context": "tab" }
},
{
"caption": "Move…",
"command": "side_bar_move",
"args": { "paths": [] }
"args": { "paths": [], "context": "tab" }
},
{
"caption": "New…",
"command": "side_bar_new",
"args": { "paths": [] }
"args": { "paths": [], "context": "tab" }
},
{
"caption": "Compare",
"command": "side_bar_compare",
"args": { "paths": [] }
"args": { "paths": [], "context": "tab" }
}
]

0 comments on commit 7252853

Please sign in to comment.