1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sublime, sublime_plugin

class toggleTabs(sublime_plugin.EventListener):
    def __init__(self):
        self.tabs_shown = True

    def toggleTabs(self):
        if sublime.active_window() == None:
            return
            
        for group in range(sublime.active_window().num_groups()):
            if len(sublime.active_window().views_in_group(group)) > 1:
                self.show_tabs()
                break
            else:
                self.hide_tabs()
                
    def show_tabs(self):
        if not self.tabs_shown:
            tabs_shown = True
            sublime.active_window().run_command('toggle_tabs')

    def hide_tabs(self):
        if self.tabs_shown:
            tabs_shown = False
            sublime.active_window().run_command('toggle_tabs')

    def on_close(self, view):
        self.toggleTabs()

    def on_activated(self, view):
        self.toggleTabs()