diff --git a/GTG/gtk/browser/main_window.py b/GTG/gtk/browser/main_window.py index 470cb2c496..2bb19585aa 100644 --- a/GTG/gtk/browser/main_window.py +++ b/GTG/gtk/browser/main_window.py @@ -176,7 +176,8 @@ def _set_actions(self): ('expand_all_tasks', self.on_expand_all_tasks, None), ('change_tags', self.on_modify_tags, ('win.change_tags', ['T'])), ('focus_sidebar', self.focus_sidebar, ('win.focus_sidebar', ['B'])), - ('search', self.toggle_search, ('win.search', ['F'])), + ('toggle_search', self.toggle_search, None), + ('focus_search', self.focus_search, ('win.focus_search', ['F'])), ('focus_quickentry', self.focus_quickentry, ('win.focus_quickentry', ['L'])), ('delete_task', self.on_delete_tasks, ('win.delete_task', ['Delete'])), ('help_overlay', None, ('win.show-help-overlay', ['question'])), @@ -456,21 +457,31 @@ def _init_signal_connections(self): # HELPER FUNCTIONS ########################################################## + def focus_search(self, action, param): + """Callback to focus search entry""" + + if self.searchbar.get_search_mode(): + if self.search_entry.has_focus(): + self._set_searchbar_visibility(False) + else: + self.search_entry.grab_focus() + else: + self._set_searchbar_visibility(True) + def toggle_search(self, action, param): """Callback to toggle search bar.""" - self.on_search_toggled() + self._set_searchbar_visibility(not self.searchbar.get_search_mode()) - def on_search_toggled(self, widget=None): - if self.searchbar.get_search_mode(): - self.search_button.set_active(False) - self.searchbar.set_search_mode(False) - self.search_entry.set_text('') - self.get_selected_tree().unapply_filter(SEARCH_TAG) - else: + def _set_searchbar_visibility(self, visible: bool): + if visible: self.search_button.set_active(True) self.searchbar.set_search_mode(True) self.search_entry.grab_focus() + else: + self.search_button.set_active(False) + self.searchbar.set_search_mode(False) + self.get_selected_tree().unapply_filter(SEARCH_TAG) def _try_filter_by_query(self, query, refresh: bool = True): log.debug("Searching for %r", query) diff --git a/GTG/gtk/data/main_window.ui b/GTG/gtk/data/main_window.ui index 685edaf6f7..ca56a278aa 100644 --- a/GTG/gtk/data/main_window.ui +++ b/GTG/gtk/data/main_window.ui @@ -353,7 +353,7 @@ False Activate Search Entry center - win.search + win.toggle_search True