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

Adding activities in retrospect is very hard #630

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Changes in 3.0.3 (unreleased)

* Fixed Adding activities in retrospect is very hard (issue 627)

## Changes in 3.0.2

* Switch from deprecated xml2po to itstool for translating help files
Expand Down
40 changes: 18 additions & 22 deletions src/hamster/edit_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,8 @@ def date(self):

@date.setter
def date(self, value):
delta = value - self._date if self._date else None
self._date = value
self.cmdline.default_day = value
if self.fact and delta:
if self.fact.start_time:
self.fact.start_time += delta
if self.fact.end_time:
self.fact.end_time += delta
# self.update_fields() here would enter an infinite loop

def on_prev_day_clicked(self, button):
self.increment_date(-1)
Expand All @@ -161,7 +154,7 @@ def get_widget(self, name):

def increment_date(self, days):
delta = dt.timedelta(days=days)
self.date += delta
self.change_start_date(self.date + delta)
self.update_fields()

def show(self):
Expand Down Expand Up @@ -240,18 +233,21 @@ def on_end_time_changed(self, widget):

def on_start_date_changed(self, widget):
if not self.master_is_cmdline:
if self.fact.start_time:
previous_date = self.fact.start_time.date()
new_date = self.start_date.date
delta = new_date - previous_date
self.fact.start_time += delta
if self.fact.end_time:
# preserve fact duration
self.fact.end_time += delta
self.end_date.date = self.fact.end_time
self.date = self.fact.date or dt.hday.today()
self.validate_fields()
self.update_cmdline()
new_date = self.start_date.date
self.change_start_date(new_date)

def change_start_date(self, new_date):
if self.fact.start_time:
previous_date = self.fact.start_time.date()
delta = new_date - previous_date
self.fact.start_time += delta
if self.fact.end_time:
# preserve fact duration
self.fact.end_time += delta
self.end_date.date = self.fact.end_time
self.date = self.fact.date or dt.hday.today()
self.validate_fields()
self.update_cmdline()

def on_start_date_expander_activated(self, widget):
# state has not changed yet, toggle also end_date calendar visibility
Expand Down Expand Up @@ -302,8 +298,8 @@ def update_fields(self):
self.start_time.time = self.fact.start_time
self.end_time.time = self.fact.end_time
self.end_time.set_start_time(self.fact.start_time)
self.start_date.date = self.fact.start_time
self.end_date.date = self.fact.end_time
self.start_date.date = self.fact.date or self.date
self.end_date.date = self.fact.date or self.date
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gsobczyk, Why is this change needed? It has a bug, since it uses self.fact.date also for the start date, but I also wonder why this is needed at all. Especially the or self.data part seems to set a default, but why not just let (especially) the end date unset when none is set yet?

self.activity_entry.set_text(self.fact.activity)
self.category_entry.set_text(self.fact.category)
self.description_buffer.set_text(self.fact.description)
Expand Down