[gedit-plugins] commander: fixes for menu entry and objects lifetime
- From: Sebastien Lafargue <slafargue src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins] commander: fixes for menu entry and objects lifetime
- Date: Fri, 6 Mar 2015 22:58:44 +0000 (UTC)
commit e30aca51865861ea64771c2cc406bfcc25ba563f
Author: Sebastien Lafargue <slafargue gnome org>
Date: Fri Mar 6 23:34:37 2015 +0100
commander: fixes for menu entry and objects lifetime
When checking and unchecking the entry menu, the entry widget is not
updated correctly.
Also, when unchecking, the entry is destroyed instead of hidden,
so that we can't re-use the history.
plugins/commander/commander/entry.py | 20 ++++++----
plugins/commander/commander/windowactivatable.py | 42 +++++++++++----------
2 files changed, 34 insertions(+), 28 deletions(-)
---
diff --git a/plugins/commander/commander/entry.py b/plugins/commander/commander/entry.py
index e667514..cb7b4b2 100644
--- a/plugins/commander/commander/entry.py
+++ b/plugins/commander/commander/entry.py
@@ -44,13 +44,17 @@ import traceback
class Entry(Gtk.Box):
__gtype_name__ = "CommanderEntry"
- def remove(self):
+ def _show(self):
+ self._reveal.set_reveal_child(True)
+
+ def _hide(self):
self._reveal.set_reveal_child(False)
def __init__(self, view):
super(Entry, self).__init__()
self._view = view
+ view.connect("destroy", self._on_view_destroyed)
self._history = History(os.path.join(GLib.get_user_config_dir(), 'gedit/commander/history'))
self._history_prefix = None
@@ -164,6 +168,10 @@ GtkEntry#gedit-commander-entry {
self._copy_style_from_view()
self._view_style_updated_id = self._view.connect('style-updated', self._on_view_style_updated)
+ def _on_view_destroyed (self, widget, user_data=None):
+ self._view.disconnect(self._view_style_updated_id)
+ self._view_style_updated_id = None
+
def _on_view_style_updated(self, widget):
self._copy_style_from_view()
@@ -292,17 +300,11 @@ GtkEntry#gedit-commander-entry {
reveal.set_reveal_child(True)
self._reveal = reveal
- reveal.connect('notify::child-revealed', self._on_child_revealed)
self._entry.grab_focus()
def grab_focus(self):
self._entry.grab_focus()
- def _on_child_revealed(self, widget, spec):
- if not self._reveal.get_child_revealed():
- self.destroy()
- widget.destroy()
-
def _on_entry_key_press(self, widget, evnt):
state = evnt.state & Gtk.accelerator_get_default_mod_mask()
text = self._entry.get_text()
@@ -773,10 +775,12 @@ GtkEntry#gedit-commander-entry {
# Note we do this not as an override because somehow something
# goes wrong when finalizing in that case, maybe self is NULL
# or something like that, and then gets some new empty instance?
- self._view.disconnect(self._view_style_updated_id)
+ if self._view_style_updated_id:
+ self._view.disconnect(self._view_style_updated_id)
self._history.save()
self._view = None
+ self._view_style_updated_id = None
# vi:ex:ts=4:et
diff --git a/plugins/commander/commander/windowactivatable.py
b/plugins/commander/commander/windowactivatable.py
index 15168fa..ec75d6d 100644
--- a/plugins/commander/commander/windowactivatable.py
+++ b/plugins/commander/commander/windowactivatable.py
@@ -38,9 +38,6 @@ class CommanderWindowActivatable(GObject.Object, Gedit.WindowActivatable):
GObject.Object.__init__(self)
def do_activate(self):
- self._entry = None
- self._view = None
-
action = Gio.SimpleAction.new_stateful("commander", None, GLib.Variant.new_boolean(False))
action.connect('activate', self.activate_toggle)
action.connect('change-state', self.commander_mode)
@@ -50,42 +47,47 @@ class CommanderWindowActivatable(GObject.Object, Gedit.WindowActivatable):
self.window.remove_action("commander")
def do_update_state(self):
- pass
+ action = self.window.lookup_action("commander")
+ state = action.get_state()
+
+ action.change_state(GLib.Variant.new_boolean(state.get_boolean()))
def activate_toggle(self, action, parameter):
+ view = self.window.get_active_view()
state = action.get_state()
- if state.get_boolean() and not self._entry is None:
- self._entry.grab_focus()
- return
-
action.change_state(GLib.Variant.new_boolean(not state.get_boolean()))
+ if state.get_boolean() and view._entry:
+ view._entry.grab_focus()
+ return
+
def commander_mode(self, action, state):
view = self.window.get_active_view()
if not view:
return False
- active = state.get_boolean()
+ if not hasattr(view, '_entry'):
+ view._entry = None
+ active = state.get_boolean()
if active:
- if not self._entry or view != self._view:
- self._entry = Entry(view)
- self._entry.connect('destroy', self.on_entry_destroy)
+ if not view._entry:
+ view._entry = Entry(view)
+ view._entry.connect('destroy', self.on_entry_destroy, view)
+
+ view._entry._show()
+ view._entry.grab_focus()
- self._entry.grab_focus()
- self._view = view
- elif self._entry:
- self._entry.remove()
- self._view = None
+ elif view._entry:
+ view._entry._hide()
action.set_state(GLib.Variant.new_boolean(active))
return True
- def on_entry_destroy(self, widget, user_data=None):
- self._entry = None
- self.window.lookup_action("commander").change_state(GLib.Variant.new_boolean(False))
+ def on_entry_destroy(self, widget, view):
+ view._entry = None
# vi:ex:ts=4:et
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]