Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent search entry #964

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions GTG/gtk/browser/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', ['<ctrl>T'])),
('focus_sidebar', self.focus_sidebar, ('win.focus_sidebar', ['<ctrl>B'])),
('search', self.toggle_search, ('win.search', ['<ctrl>F'])),
('toggle_search', self.toggle_search, None),
('focus_search', self.focus_search, ('win.focus_search', ['<ctrl>F'])),
('focus_quickentry', self.focus_quickentry, ('win.focus_quickentry', ['<ctrl>L'])),
('delete_task', self.on_delete_tasks, ('win.delete_task', ['<ctrl>Delete'])),
('help_overlay', None, ('win.show-help-overlay', ['<ctrl>question'])),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion GTG/gtk/data/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Activate Search Entry</property>
<property name="valign">center</property>
<property name="action_name">win.search</property>
<property name="action_name">win.toggle_search</property>
<child>
<object class="GtkImage" id="search_icon">
<property name="visible">True</property>
Expand Down