[Sugar-devel] [PATCH shell] Journal: defocus the search entry by default

Manuel Quiñones manuq at laptop.org
Mon Oct 1 08:36:16 EDT 2012


Do the same behavior as in the shell views, explained in detail in
commit 1570f774 .

- add signals to ListView to inform the JournalActivity when a title
  edit starts and finishes, to skip the autosearch when typing

- make MainToolBox search_entry a public attribute to make it visible
  from JournalActivity

- as a consequence of the previous item, remove give_entry_focus
  method from MainToolBox and use the attribute directly

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 src/jarabe/journal/journalactivity.py | 22 ++++++++++++++++++++--
 src/jarabe/journal/journaltoolbox.py  | 27 +++++++++++++--------------
 src/jarabe/journal/listview.py        |  8 ++++++++
 3 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 23a0b38..89d33a3 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -173,11 +173,16 @@ class JournalActivity(JournalWindow):
     def _setup_main_view(self):
         self._main_toolbox = MainToolbox()
         self._main_view = Gtk.VBox()
+        self._main_view.set_can_focus(True)
 
         self._list_view = ListView()
         self._list_view.connect('detail-clicked', self.__detail_clicked_cb)
         self._list_view.connect('clear-clicked', self.__clear_clicked_cb)
         self._list_view.connect('volume-error', self.__volume_error_cb)
+        self._list_view.connect('title-edit-started',
+                                self.__title_edit_started_cb)
+        self._list_view.connect('title-edit-finished',
+                                self.__title_edit_finished_cb)
         self._main_view.pack_start(self._list_view, True, True, 0)
         self._list_view.show()
 
@@ -188,6 +193,8 @@ class JournalActivity(JournalWindow):
         self._main_view.pack_start(self._volumes_toolbar, False, True, 0)
 
         self._main_toolbox.connect('query-changed', self._query_changed_cb)
+        self._main_toolbox.search_entry.connect('icon-press',
+                                                self.__search_icon_pressed_cb)
         self._main_toolbox.set_mount_point('/')
 
     def _setup_secondary_view(self):
@@ -203,6 +210,9 @@ class JournalActivity(JournalWindow):
         self._detail_view.show()
 
     def _key_press_event_cb(self, widget, event):
+        if not self._main_toolbox.search_entry.has_focus():
+            self._main_toolbox.search_entry.grab_focus()
+
         keyname = Gdk.keyval_name(event.keyval)
         if keyname == 'Escape':
             self.show_main_view()
@@ -220,6 +230,15 @@ class JournalActivity(JournalWindow):
         self._list_view.update_with_query(query)
         self.show_main_view()
 
+    def __search_icon_pressed_cb(self, entry, icon_pos, event):
+        self._main_view.grab_focus()
+
+    def __title_edit_started_cb(self, list_view):
+        self.disconnect_by_func(self._key_press_event_cb)
+
+    def __title_edit_finished_cb(self, list_view):
+        self.connect('key-press-event', self._key_press_event_cb)
+
     def show_main_view(self):
         if self.toolbar_box != self._main_toolbox:
             self.set_toolbar_box(self._main_toolbox)
@@ -279,7 +298,6 @@ class JournalActivity(JournalWindow):
             self.show_main_view()
 
     def _focus_in_event_cb(self, window, event):
-        self.search_grab_focus()
         self._list_view.update_dates()
 
     def _check_for_bundle(self, object_id):
@@ -319,7 +337,7 @@ class JournalActivity(JournalWindow):
         model.write(metadata)
 
     def search_grab_focus(self):
-        self._main_toolbox.give_entry_focus()
+        self._main_toolbox.search_entry.grab_focus()
 
     def __window_state_event_cb(self, window, event):
         logging.debug('window_state_event_cb %r', self)
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index a4f80fc..09d8a31 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -76,14 +76,16 @@ class MainToolbox(ToolbarBox):
 
         self._mount_point = None
 
-        self._search_entry = iconentry.IconEntry()
-        self._search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
-                                              'system-search')
-        self._search_entry.connect('activate', self._search_entry_activated_cb)
-        self._search_entry.connect('changed', self._search_entry_changed_cb)
-        self._search_entry.add_clear_button()
+        self.search_entry = iconentry.IconEntry()
+        self.search_entry.set_icon_from_name(iconentry.ICON_ENTRY_PRIMARY,
+                                             'system-search')
+        text = _('Search in %s') % _('Journal')
+        self.search_entry.set_placeholder_text(text)
+        self.search_entry.connect('activate', self._search_entry_activated_cb)
+        self.search_entry.connect('changed', self._search_entry_changed_cb)
+        self.search_entry.add_clear_button()
         self._autosearch_timer = None
-        self._add_widget(self._search_entry, expand=True)
+        self._add_widget(self.search_entry, expand=True)
 
         self._favorite_button = ToggleToolButton('emblem-favorite')
         self._favorite_button.connect('toggled',
@@ -121,9 +123,6 @@ class MainToolbox(ToolbarBox):
 
         self.refresh_filters()
 
-    def give_entry_focus(self):
-        self._search_entry.grab_focus()
-
     def _get_when_search_combo(self):
         when_search = ComboBox()
         when_search.append_item(_ACTION_ANYTIME, _('Anytime'))
@@ -188,8 +187,8 @@ class MainToolbox(ToolbarBox):
             date_from, date_to = self._get_date_range()
             query['timestamp'] = {'start': date_from, 'end': date_to}
 
-        if self._search_entry.props.text:
-            text = self._search_entry.props.text.strip()
+        if self.search_entry.props.text:
+            text = self.search_entry.props.text.strip()
             if text:
                 query['query'] = text
 
@@ -256,7 +255,7 @@ class MainToolbox(ToolbarBox):
     def _autosearch_timer_cb(self):
         logging.debug('_autosearch_timer_cb')
         self._autosearch_timer = None
-        self._search_entry.activate()
+        self.search_entry.activate()
         return False
 
     def set_mount_point(self, mount_point):
@@ -345,7 +344,7 @@ class MainToolbox(ToolbarBox):
         self._update_if_needed()
 
     def clear_query(self):
-        self._search_entry.props.text = ''
+        self.search_entry.props.text = ''
         self._what_search_combo.set_active(0)
         self._when_search_combo.set_active(0)
         self._favorite_button.props.active = False
diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index 917beb0..5b2c5ab 100644
--- a/src/jarabe/journal/listview.py
+++ b/src/jarabe/journal/listview.py
@@ -491,6 +491,10 @@ class ListView(BaseListView):
                            ([object])),
         'volume-error': (GObject.SignalFlags.RUN_FIRST, None,
                          ([str, str])),
+        'title-edit-started': (GObject.SignalFlags.RUN_FIRST, None,
+                               ([])),
+        'title-edit-finished': (GObject.SignalFlags.RUN_FIRST, None,
+                                ([])),
     }
 
     def __init__(self):
@@ -538,6 +542,8 @@ class ListView(BaseListView):
         row = self.tree_view.get_model()[path]
         metadata = model.get(row[ListModel.COLUMN_UID])
         self.cell_title.props.editable = model.is_editable(metadata)
+        if self.cell_title.props.editable:
+            self.emit('title-edit-started')
 
         tree_view.set_cursor_on_cell(path, column, self.cell_title,
                                      start_editing=True)
@@ -563,9 +569,11 @@ class ListView(BaseListView):
         metadata['title'] = new_text
         model.write(metadata, update_mtime=False)
         self.cell_title.props.editable = False
+        self.emit('title-edit-finished')
 
     def __editing_canceled_cb(self, cell):
         self.cell_title.props.editable = False
+        self.emit('title-edit-finished')
 
 
 class CellRendererFavorite(CellRendererIcon):
-- 
1.7.11.4



More information about the Sugar-devel mailing list