Home Download Buy Blog Forum Support

Multi-Line Tabbar for ST2

Multi-Line Tabbar for ST2

Postby wwwweb on Wed Apr 09, 2014 4:26 pm

Hi folks,

I work with ST2 for one week now (coming from Notepad++) and the only thing really annoying me, is that the titles of the tabs are truncated when a lot of tabs are open and there is no multi row tab layout. So I used the ST layout to provide a hacky kind of multiple line tabs:

Code: Select all
import sublime, sublime_plugin

multi_col_layout = 1
bar_height = 0.025

class MultiColumnTabBarCommand(sublime_plugin.EventListener):
  def on_activated(self, view):
    a = sublime.active_window()
    b = a.get_view_index(view)

    if (b[0] == 0) and (multi_col_layout == 1):
      a.run_command("set_layout",{"cols":[0.0,1],"rows":[0.0,bar_height,bar_height*2,1],"cells":[[0,2,1,3],[0,0,1,1],[0,1,1,2]]})

    if (b[0] == 1) and (multi_col_layout == 1):
      a.run_command("set_layout",{"cols":[0.0,1],"rows":[0.0,bar_height,bar_height*2,1],"cells":[[0,0,1,1],[0,2,1,3],[0,1,1,2]]})

    if (b[0] == 2) and (multi_col_layout == 1):
      a.run_command("set_layout",{"cols":[0.0,1],"rows":[0.0,bar_height,bar_height*2,1],"cells":[[0,0,1,1],[0,1,1,2],[0,2,1,3]]})

class ToggleMultiColLayoutCommand(sublime_plugin.TextCommand):
  def run(self,edit):
    global multi_col_layout
    if (multi_col_layout == 1):
      multi_col_layout = 0
      print "Multi Col Layout disabled"
    elif (multi_col_layout == 0):
      multi_col_layout = 1
      print "Multi Col Layout enabled"


Image

This is a quite static approach to provide a 3 row tab layout. The main idea is to set up a 3 row layout and only show one tab group whereas only the top of the other tabgroups is shown above. On click on a tab of another group, the active group is changed and shown whereas the others go to background.

Known issues are:

- the height of a tab row is dependent on screen resolution and window size; can be manually adjusted using the bar_height variable
- goto anything opens a file in the focussed tab group although it is already open in another group
- 3 static rows
- tabs have to be distributed to tab rows manually (i.e. drag and drop)
- not compatible to own layouts (split column,...), therefore can be disabled by toggle_multi_col_layout command
-...

For me it is fine like this and maybe it is helpful for someone else, but of course I would also appreciate if there is a Python/ST expert who can make this more flexible.

Best regards,
wwwweb
wwwweb
 
Posts: 2
Joined: Wed Apr 09, 2014 4:09 pm

Re: Multi-Line Tabbar for ST2

Postby cricrazy on Tue Jan 20, 2015 10:28 pm

Great work. I know it is not the complete solution, but I would take it as an interim solution. It allows me to view filenames easily. Heck...I use three rows as a way to sort files from three different projects too!!!

Thanks. It has crashed on me some times, but I am ok with that.

Thanks again.
cricrazy
 
Posts: 2
Joined: Fri Oct 25, 2013 6:33 pm

Re: Multi-Line Tabbar for ST2

Postby valerij_ on Wed Jan 21, 2015 6:45 pm

neat hack,
i guess by hooking `EventListener.on_activate` to detect the click on a tab and using `Window.set_view_index` to move the tab to lowest pane you should be able to mimic multiline tabbar behaviour really close
valerij_
 
Posts: 58
Joined: Fri Feb 14, 2014 5:59 pm

Re: Multi-Line Tabbar for ST2

Postby wwwweb on Mon Mar 09, 2015 3:39 pm

Hi,

Thanks for the positive responses, nice to hear that it is useful to someone else. In combination with the "run multiple commands" plugin viewtopic.php?f=5&t=8677 , I created some keyboard shortcuts for tabline switching that you can find attached.

Best regards,
wwwweb

Code: Select all
  //layout: enable/disable multi line tabbar switching
  { "keys": ["ctrl+u","ctrl+r"], "command": "toggle_multi_col_layout" },
     
  //disable multiline tabbar and show single tabline only
  {
    "keys": ["ctrl+alt+b"],
    "command": "run_multiple_commands",
    "args": {
      "commands": [
      {"command": "disable_multi_col_layout", "context": "window"},
      {"command": "set_layout", "context": "window","args":{"cols": [0.0, 1.0],"rows": [0.0, 1.0],"cells": [[0, 0, 1, 1]]}}     
    ]}},
   
  //split screen
  {
  "keys": ["ctrl+alt+n"],
  "command": "run_multiple_commands",
  "args": {
    "commands": [
      {"command": "disable_multi_col_layout", "context": "window"},
      {
        "command": "set_layout",
        "context":"window",
        "args":
        {
          "cols": [0.0, 0.5, 1.0],
          "rows": [0.0, 1.0],
          "cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
        }}
  ]}},
 
  //move current file to other row
  { "keys": ["ctrl+alt+,"], "command": "move_to_group", "args": { "group": 0 } },
  { "keys": ["ctrl+alt+."], "command": "move_to_group", "args": { "group": 1 } },
  { "keys": ["ctrl+alt+-"], "command": "move_to_group", "args": { "group": 2 } },

  //first group to foreground
  {
  "keys": ["ctrl+,"],
  "command": "run_multiple_commands",
  "args": {
    "commands": [
      {"command": "enable_multi_col_layout", "context": "window"},
      {
        "command": "set_layout",
        "context":"window",
        "args":
        {
          "cols": [0.0 ,1],
          "rows": [0.0, 0.025, 0.05, 1.0],
          "cells": [[0, 2, 1, 3],[0, 0, 1, 1],[0, 1, 1, 2]]
        }}
  ]}},
 
  //second group to foreground
  {
  "keys": ["ctrl+."],
  "command": "run_multiple_commands",
  "args": {
    "commands": [
      {"command": "enable_multi_col_layout", "context": "window"},
      {
        "command": "set_layout",
        "context":"window",
        "args":
        {
          "cols": [0.0 ,1],
          "rows": [0.0, 0.025, 0.05, 1.0],
          "cells": [[0, 0, 1, 1],[0, 2, 1, 3],[0, 1, 1, 2]]
        }}
  ]}},
 
  //third group to foreground
  {
  "keys": ["ctrl+-"],
  "command": "run_multiple_commands",
  "args": {
    "commands": [
      {"command": "enable_multi_col_layout", "context": "window"},
      {
        "command": "set_layout",
        "context":"window",
        "args":
        {
          "cols": [0.0 ,1],
          "rows": [0.0, 0.025, 0.05, 1.0],
          "cells": [[0, 0, 1, 1],[0, 1, 1, 2], [0, 2, 1, 3]]
        }}
  ]}},
 
  //disable multi tabline view and show first row only
    {
  "keys": ["ctrl+b"],
  "command": "run_multiple_commands",
  "args": {
    "commands": [
      {"command": "disable_multi_col_layout", "context": "window"},
      {
        "command": "set_layout",
        "context":"window",
        "args":
        {
          "cols": [0.0 ,1],
          "rows": [0.0, 0.025, 0.05, 1.0],
          "cells": [[0, 0, 1, 3],[0, 0, 0, 0],[0, 0, 0, 0]]
        }}
  ]}},

  //disable multi tabline view and show second row only
    {
  "keys": ["ctrl+n"],
  "command": "run_multiple_commands",
  "args": {
    "commands": [
      {"command": "disable_multi_col_layout", "context": "window"},
      {
        "command": "set_layout",
        "context":"window",
        "args":
        {
          "cols": [0.0 ,1],
          "rows": [0.0, 0.025, 0.05, 1.0],
          "cells": [[0, 0, 0, 0],[0, 0, 1, 3],[0, 0, 0, 0]]
        }}
  ]}},
 
  //disable multi tabline view and show third row only
    {
  "keys": ["ctrl+m"],
  "command": "run_multiple_commands",
  "args": {
    "commands": [
      {"command": "disable_multi_col_layout", "context": "window"},
      {
        "command": "set_layout",
        "context":"window",
        "args":
        {
          "cols": [0.0 ,1],
          "rows": [0.0, 0.025, 0.05, 1.0],
          "cells": [[0, 0, 0, 0],[0, 0, 0, 0],[0, 0, 1, 3]]
        }}
  ]}}

wwwweb
 
Posts: 2
Joined: Wed Apr 09, 2014 4:09 pm


Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 6 guests