Home Download Buy Blog Forum Support

Opening new tabs on the right

Opening new tabs on the right

Postby glycerine on Sat Feb 04, 2012 7:51 pm

Hi. I tried to make a plugin that will open new tabs on the right. (Instead of next to the currently active tab.)

My plugin sort-of works, but it seems like the actual tabs aren't redrawn; the GUI does not change. I can't figure out how to fix this :-(
Maybe someone on this forum can help me?

Code: Select all

import sublime, sublime_plugin

class TabrightEvent(sublime_plugin.EventListener):

   def __init__(self, *args, **kwargs):
      super(TabrightEvent, self).__init__(*args, **kwargs)
      self.new_buffers = []

   def on_new(self,view):
      self.new_buffers.append(view.buffer_id())

   def on_activated(self, view):
      # print 'on_activated', self.last_syntax, view.buffer_id()
      if view.buffer_id() in self.new_buffers:
         self.new_buffers.remove(view.buffer_id())

         window = view.window()
         group = window.active_group()
         viewcount = len(window.views()) - 1
         window.set_view_index(view, group, viewcount)
         window.focus_view(view)
glycerine
 
Posts: 22
Joined: Thu Dec 15, 2011 11:16 pm

Re: Opening new tabs on the right

Postby glycerine on Sat Feb 04, 2012 11:18 pm

After reading some forum posts, I've come up with this solution. I haven't tested it much though.
I'd be grateful for any insights or comments.

Also, I've noticed that running window commands (window.run_command) from on_activated doesn't work?

Code: Select all
import sublime, sublime_plugin

class TabrightEvent(sublime_plugin.EventListener):

   def on_new(self,view):
      window = sublime.active_window()
      rightIndex = len(window.views()) - 1
      window.set_view_index(view, window.active_group(), rightIndex)
      window.run_command("select_by_index", {"index": rightIndex})
glycerine
 
Posts: 22
Joined: Thu Dec 15, 2011 11:16 pm

Re: Opening new tabs on the right

Postby glycerine on Sun Feb 05, 2012 2:19 pm

For those interested: I moved this to GitHub for convenience.

https://github.com/stylishmedia/SublimeText-Tabright
glycerine
 
Posts: 22
Joined: Thu Dec 15, 2011 11:16 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 6 guests