Permalink
Browse files

Leverage new Sublime Text 3 APIs to track sidebar visibility. Doesn't…

… totally fix #6, but definitely helps.
  • Loading branch information...
1 parent b1d0fe9 commit 5081282ed85176f1272a257c0aef486dfb92c0f3 @TheSpyder committed Mar 4, 2013
Showing with 41 additions and 1 deletion.
  1. +6 −0 README.md
  2. +35 −1 SyncedSideBar.py
View
@@ -12,6 +12,12 @@ http://www.sublimetext.com/forum/viewtopic.php?f=2&t=4080
Usage
-----
+#### Note
+
+This plugin works on both Sublime Text 2 and Sublime Text 3 beta. None of the APIs this plugin uses changed between releases.
+
+When running on Sublime Text 3 beta, the plugin is able track the sidebar visibility (but only when the keyboard shortcut for "toggle_side_bar" is used, not the view -> sidebar toggle). It still forces the sidebar to become visible the first time a window is activated, but after that the plugin will detect when the keyboard shortcut is used and stop calling "reveal_in_side_bar" until it is used again. It will even remember the visible state when multiple windows are open.
+
### Configuration
SyncedSideBar enables/disables automatic syncing via the setting `reveal-on-activate`.
View
@@ -1,14 +1,48 @@
import sublime
import sublime_plugin
+# assume sidebar is visible by default on every window (there's no way to check, unfortunately)
+DEFAULT_VISIBILITY = True
+
+sidebar_visible = DEFAULT_VISIBILITY
+lastActive = None
+
+# Keep track of active windows so we rememeber sidebar_visible for each one
+windows = {}
+
class SideBarListener(sublime_plugin.EventListener):
def on_activated(self, view):
+ global sidebar_visible, lastActive
active = view.window()
- if active and view.settings().get('reveal-on-activate') != False:
+
+ if not active:
+ return
+
+ if not active.id() in windows:
+ # first activation in this window, use default
+ windows[active.id()] = DEFAULT_VISIBILITY
+
+ if lastActive == None:
+ # plugin just loaded
+ lastActive = active
+ elif lastActive != active:
+ # store the old window state
+ windows[lastActive.id()] = sidebar_visible
+ # load the new window state
+ sidebar_visible = windows[active.id()]
+ lastActive = active
+
+ if sidebar_visible and view.settings().get('reveal-on-activate') != False:
active.run_command('reveal_in_side_bar')
+ # Sublime text v3 window command listener, safe to include unconditionally as it's simply ignored by v2.
+ def on_window_command(self, window, command_name, args):
+ global sidebar_visible
+ if command_name == "toggle_side_bar":
+ sidebar_visible = not sidebar_visible
+
class SideBarUpdateSync(sublime_plugin.ApplicationCommand):

0 comments on commit 5081282

Please sign in to comment.