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

Reset position in FactTree only when needed #648

Merged
merged 1 commit into from
Dec 10, 2020
Merged
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
8 changes: 4 additions & 4 deletions src/hamster/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,19 +523,19 @@ def on_key_press(self, window, event):
if event.keyval == gdk.KEY_Escape:
self.close_window()

def find_facts(self):
def find_facts(self, scroll_to_top=False):
start, end = self.header_bar.range_pick.get_range()
search_active = self.header_bar.search_button.get_active()
search = "" if not search_active else self.filter_entry.get_text()
search = "%s*" % search if search else "" # search anywhere
self.facts = self.storage.get_facts(start, end, search_terms=search)
self.fact_tree.set_facts(self.facts)
self.fact_tree.set_facts(self.facts, scroll_to_top=scroll_to_top)
self.totals.set_facts(self.facts)
self.header_bar.stop_button.set_sensitive(
self.facts and not self.facts[-1].end_time)

def on_range_selected(self, button, range_type, start, end):
self.find_facts()
self.find_facts(scroll_to_top=True)

def on_search_changed(self, entry):
if entry.get_text():
Expand All @@ -544,7 +544,7 @@ def on_search_changed(self, entry):
else:
self.filter_entry.set_icon_from_icon_name(gtk.EntryIconPosition.SECONDARY,
None)
self.find_facts()
self.find_facts(scroll_to_top=True)

def on_search_icon_press(self, entry, position, event):
if position == gtk.EntryIconPosition.SECONDARY:
Expand Down
8 changes: 5 additions & 3 deletions src/hamster/widgets/facttree.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,18 @@ def _on_vadjustment_change(self, scene, vadjustment):
self.vadjustment.connect("value_changed", self.on_scroll_value_changed)
self.set_size_request(500, 300)

def set_facts(self, facts):
def set_facts(self, facts, scroll_to_top=False):
# FactTree adds attributes to its facts. isolate these side effects
# copy the id too; most of the checks are based on id here.
self.facts = [fact.copy(id=fact.id) for fact in facts]
del facts # make sure facts is not used by inadvertance below.

self.y = 0
# If we get an entirely new set of facts, scroll back to the top
if scroll_to_top:
self.y = 0
self.hover_fact = None
if self.vadjustment:
self.vadjustment.set_value(0)
self.vadjustment.set_value(self.y)

if self.facts:
start = self.facts[0].date
Expand Down