Home Download Buy Blog Forum Support

Auto-hide tabs

Auto-hide tabs

Postby toggleViews on Fri Oct 15, 2010 11:49 am

Auto-hides tabs panel when a single tab is present, and allows you to set a custom keybinding to toggle the tabs panel.

Feel free to test it and modify it as you see fit.

# Update: Simplified it a bit, and now it works with panels correctly.

Code: Select all
# Remember to set the keybinding:
# <binding key="ctrl+t" command="toggleTabs"/>

import sublime, sublimeplugin

def doToggleTabs():
  show = 0
  for group in range(sublime.activeWindow().numGroups()):
    views = len(sublime.activeWindow().viewsInGroup(group))
    if views > 1:
      show = 1
      break
  if show == 1:
    sublime.options().set('showTabs', True)
  else:
    sublime.options().set('showTabs', False)

class toggleTabs(sublimeplugin.TextCommand):
  def run(self, view, args):
    showTabs = sublime.options().get('showTabs')
    if showTabs == True:
      sublime.options().set('showTabs', False)
    else:
      sublime.options().set('showTabs', True)

class toggleTabsPlugin(sublimeplugin.Plugin):
  def onClose(self, view):
    doToggleTabs()
  def onActivated(self, view):
    doToggleTabs()

A copy is saved here: http://pastebin.com/hB1KJSjz
toggleViews
 
Posts: 5
Joined: Fri Oct 15, 2010 11:35 am

Re: Auto-hide tabs

Postby toggleViews on Sun Oct 24, 2010 11:10 pm

A small followup, I cleaned the code a bit.

Code: Select all
import sublime, sublimeplugin

class doToggleTabs(sublimeplugin.TextCommand):
  def run(self, view, args):
    if sublime.options().get('showTabs') == True:
      sublime.options().set('showTabs', False)
    else:
      sublime.options().set('showTabs', True)

class toggleTabs(sublimeplugin.Plugin):
  def toggleTabs(self):
    for group in range(sublime.activeWindow().numGroups()):
      if len(sublime.activeWindow().viewsInGroup(group)) > 1:
        sublime.options().set('showTabs', True)
        break
      else:
        sublime.options().set('showTabs', False)
  def onClose(self, view):
    self.toggleTabs()
  def onActivated(self, view):
    self.toggleTabs()
toggleViews
 
Posts: 5
Joined: Fri Oct 15, 2010 11:35 am


Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 16 guests