Skip to content

Commit

Permalink
Save task before closing editor
Browse files Browse the repository at this point in the history
Fixes getting-things-gnome#1138

When the task editor gets closed, it first calls
`self.textview.process()` which, after processing, calls
`self.save_cb()`, which is set to `TaskEditor.light_save()`. This only
calls `TaskEditor.save()` at most every 7 seconds. So if you crete a new
task and close its editor within 7 seconds, the task doesn't get saved.

This commit makes `TaskEditor.desctruction()` call `TaskEditor.save()`,
to make sure the task is saved properly before closing the task popup.
  • Loading branch information
SqAtx committed Jan 20, 2025
1 parent 3910d84 commit 744b73d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
11 changes: 7 additions & 4 deletions GTG/gtk/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self, app, task):

self.app = app
self.ds = app.ds
self.task = task
self.task: Task = task
self.config = app.config_core
self.task_config = self.config.get_task_config(str(task.id))
self.time = None
Expand Down Expand Up @@ -778,7 +778,7 @@ def save(self):
self.time = time.time()


# light_save save the task without refreshing every 30seconds
# light_save save the task without refreshing every 30 seconds
# We will reduce the time when the get_text will be in another thread

def light_save(self):
Expand Down Expand Up @@ -836,13 +836,16 @@ def destruction(self, _=None):
# process textview to make sure every tag is parsed
self.textview.process()

# Save should be also called when buffer is modified
# Save because self.textview.process() only calls light_save(), which
# isn't guaranteed to actually save (see #1138)
self.save()

# self.pengine.onTaskClose(self.plugin_api)
# self.pengine.remove_api(self.plugin_api)

tid = self.task.id

if self.is_new():
if self.task.is_new():
self.app.ds.tasks.remove(tid)
else:
self.save()
Expand Down
3 changes: 2 additions & 1 deletion GTG/gtk/editor/taskview.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def process(self,mask_current_word:bool=False) -> None:

if not self.buffer.props.text:
# Why process if there's nothing to process
log.warning('No text to process')
return

log.debug('Processing text buffer after %dms', self.PROCESSING_DELAY)
Expand Down Expand Up @@ -266,7 +267,7 @@ def process(self,mask_current_word:bool=False) -> None:
self.detect_url(text, start)
self.detect_internal_link(text, start)

# remove current word from the text befor looking for tags
# remove current word from the text before looking for tags
if mask_current_word and cursor_line==start.get_line():
cur_pos = cursor_iter.get_line_offset()
text = TaskView.mask_current_word(text,cur_pos)
Expand Down

0 comments on commit 744b73d

Please sign in to comment.