Skip to content

Commit

Permalink
Fix Rebuild CTags command being disabled
Browse files Browse the repository at this point in the history
Fixes #341

This commit converts `RebuildTags` into a `WindowCommand` so it keeps working
when used in sidebar context menu.

This change is required as ST4147+ restricts `TextCommand` usage
to fix sublimehq/sublime_text#5781.
  • Loading branch information
deathaxe committed Aug 11, 2023
1 parent 1ceef7f commit 033ec22
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ctagsplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def find_tags_relative_to(path, tag_file):
def read_opts(view):
# the first one is useful to change opts only on a specific project
# (by adding ctags.opts to a project settings file)
if not view:
return setting('opts')
return view.settings().get('ctags.opts') or setting('opts')

def get_alternate_tags_paths(view, tags_file):
Expand Down Expand Up @@ -812,21 +814,23 @@ def sorted_tags():
# Rebuild CTags commands


class RebuildTags(sublime_plugin.TextCommand):
class RebuildTags(sublime_plugin.WindowCommand):
"""
Provider for the ``rebuild_tags`` command.
Command (re)builds tag files for the open file(s) or folder(s), reading
relevant settings from the settings file.
"""

def run(self, edit, **args):
def run(self, **args):
"""Handler for ``rebuild_tags`` command"""
paths = []

view = self.window.active_view();

command = setting('command')
recursive = setting('recursive')
opts = read_opts(self.view)
opts = read_opts(view)
tag_file = setting('tag_file')

if 'dirs' in args and args['dirs']:
Expand All @@ -837,12 +841,10 @@ def run(self, edit, **args):
# build ctags and ignore recursive flag - we clearly only want
# to build them for a file
self.build_ctags(paths, command, tag_file, False, opts)
elif (self.view.file_name() is None and
len(self.view.window().folders()) <= 0):
elif view is None or view.file_name() is None and len(self.window.folders()) <= 0:
status_message('Cannot build CTags: No file or folder open.')
return
else:
show_build_panel(self.view)
show_build_panel(view)

@threaded(msg='Already running CTags!')
def build_ctags(self, paths, command, tag_file, recursive, opts):
Expand Down

0 comments on commit 033ec22

Please sign in to comment.