Skip to content

Commit

Permalink
Added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Micah Carrick committed Dec 17, 2011
1 parent e2a53fd commit accee56
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions restoretabs.py
Expand Up @@ -12,19 +12,30 @@ def __init__(self):
self._handlers = []

def do_activate(self):
"""
Connect signal handlers.
"""
handlers = []
handler_id = self.window.connect("delete-event",
self.on_window_delete_event)
self._handlers.append(handler_id)

# temporary handler to catch the first time a window is shown
self._temp_handler = self.window.connect("show", self.on_window_show)

def do_deactivate(self):
"""
Disconect any signal handlers that were added in do_activate().
"""
[self.window.disconnect(handler_id) for handler_id in self._handlers]

def do_update_state(self):
pass

def is_first_window(self):
"""
Return True if the window being added is the first window instance.
"""
app = Gedit.App.get_default()
if len(app.get_windows()) <= 1:
return True
Expand All @@ -42,6 +53,9 @@ def on_window_delete_event(self, window, event, data=None):
return False

def on_window_show(self, window, data=None):
"""
Only restore tabs if this window is the first Gedit window instance.
"""
if self.is_first_window():
tab = self.window.get_active_tab()
if tab.get_state() == 0 and not tab.get_document().get_location():
Expand Down

0 comments on commit accee56

Please sign in to comment.