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
32 changes: 13 additions & 19 deletions src/hamster/edit_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,12 @@ def __init__(self, action, fact_id=None):
else:
self.fact = Fact(start_time=dt.datetime.now())

original_fact = self.fact
# TODO: should use hday, not date.
self.date = self.fact.date

self.update_fields()
self.update_cmdline(select=True)

self.cmdline.original_fact = original_fact

# This signal should be emitted only after a manual modification,
# not at init time when cmdline might not always be fully parsable.
self.cmdline.connect("changed", self.on_cmdline_changed)
Expand Down Expand Up @@ -135,15 +132,19 @@ 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

def move_to_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.update_fields() here would enter an infinite loop
self.end_date.date = self.fact.end_time
self.date = self.fact.date or dt.hday.today()

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

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

def show(self):
Expand Down Expand Up @@ -196,6 +197,7 @@ def on_cmdline_changed(self, widget):
# no change to description here, keep the main one
fact.description = self.fact.description
self.fact = fact
self.date = fact.date
self.update_fields()

def on_cmdline_focus_in_event(self, widget, event):
Expand Down Expand Up @@ -240,16 +242,8 @@ 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()
new_date = self.start_date.date
self.move_to_date(new_date)
self.validate_fields()
self.update_cmdline()

Expand Down
14 changes: 5 additions & 9 deletions src/hamster/widgets/activityentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
# Code redundancy to be removed later.


def extract_search(text):
fact = Fact.parse(text)
def extract_search(fact):
search = fact.activity
if fact.category:
search += "@%s" % fact.category
Expand Down Expand Up @@ -209,9 +208,6 @@ def __init__(self, updating=True, **kwargs):
# default day for times without date
self.default_day = None

# to be set by the caller, if editing an existing fact
self.original_fact = None

self.popup = gtk.Window(type = gtk.WindowType.POPUP)
self.popup.set_type_hint(gdk.WindowTypeHint.COMBO) # why not
self.popup.set_attached_to(self) # attributes
Expand Down Expand Up @@ -325,8 +321,8 @@ def load_suggestions(self):

def complete_first(self):
text = self.get_text()
fact = Fact.parse(text)
search = extract_search(text)
fact = Fact.parse(text, default_day=self.default_day)
search = extract_search(fact)
if not self.complete_tree.rows or not fact.activity:
return text, None

Expand Down Expand Up @@ -361,7 +357,7 @@ def update_suggestions(self, text=""):

res = []

fact = Fact.parse(text)
fact = Fact.parse(text, default_day=self.default_day)
now = dt.datetime.now()

# figure out what we are looking for
Expand All @@ -382,7 +378,7 @@ def update_suggestions(self, text=""):
current_fragment = fragments[-1] if fragments else ""


search = extract_search(text)
search = extract_search(fact)

matches = []
for match, score in self.suggestions:
Expand Down