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

Implement a way to edit the last entry. #247

Merged
merged 3 commits into from Jan 30, 2024

Conversation

icemac
Copy link
Contributor

@icemac icemac commented Nov 30, 2023

Fixes #160.

Copy link

@sallner sallner left a comment

Choose a reason for hiding this comment

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

Looks good from my side.

Copy link
Member

@mgedmin mgedmin left a comment

Choose a reason for hiding this comment

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

I like this! With some minor suggestions.

I could merge it as-is and then fix up the things I want done differently directly in git master. Should I do that? I would like to hear your opinion about e.g. commenting out entries instead of removing them entirely, to avoid possible loss of data.

if text is not None:
window.task_entry.set_text(text)
window.task_entry.grab_focus()
window.task_entry.select_region(-1, -1)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an app-global action rather than a window action?

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should do something special if the user is currently engaged in history browsing, like jump to the current day when you do this?

Currently if you're history browsing and enter something in the log enter, when you press Enter, the view returns back to today. I think the same thing should happen if you press Ctrl+Backspace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be an app-global action rather than a window action?

I do not know what's the difference. Does app global mean it gets an entry in the menu?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

gocept.gtimelog had no history browsing. So I did not consider it during the implementation. I think if previous days cannot be edited (= adding entries), deletion should not happen, when the user is not looking at the current day. Removing the last entry from the current day when looking at a different one, I'd consider unexpected.

Copy link
Member

Choose a reason for hiding this comment

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

I do not know what's the difference. Does app global mean it gets an entry in the menu?

No, this is a purely internal distinction. Window actions get dispatched to the current window, and seeing as the first thing you do in the global action is find the current window to do things with its widgets, this seems like it would be more natural to move the handler method into the window subclass.

I think if previous days cannot be edited (= adding entries), deletion should not happen, when the user is not looking at the current day. Removing the last entry from the current day when looking at a different one, I'd consider unexpected.

Yeah, that makes sense.

# remove line which divides days if necessary
lines = lines[:-1]
with open(self.filename, "w", encoding='utf-8') as f:
f.write(''.join(lines))
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if f.writelines(lines) would be nicer here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would probably be nicer and more performant.

@@ -40,6 +40,8 @@ Changelog
- Grouped task entries can now be sorted by start date, name, duration or
according to tasks.txt order (GH: #228).

- Add the ability to change the last entry using Primary+BackSpace (GH: #247).
Copy link
Member

Choose a reason for hiding this comment

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

I find the GTK terminology of Primary+... confusing (and I think they dropped it for GTK 4?) so I would suggest

Suggested change
- Add the ability to change the last entry using Primary+BackSpace (GH: #247).
- Add the ability to change the last entry using Ctrl+Backspace (GH: #247).

instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On MacOS it is actually Command-Backspace, so I wrote primary. But I am also fine with Ctrl.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, MacOS was probably why Gtk introduced those Primary+ etc. modifiers. That's fine then.

lines = lines[:-1]
if not lines[-1].strip():
# remove line which divides days if necessary
lines = lines[:-1]
Copy link
Member

Choose a reason for hiding this comment

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

My greatest worry about this feature is that there's no undo if you (accidentally) press Ctrl+Backspace more than once in a row. Maybe instead of removing the line from the file it would be better to comment it out? Then at least you can recover with a text editor.

The timelog.txt format supports comments using # at the beginning of the line. I plan to use some of the comments for directives that set things like timezones or virtual midnight times, so maybe we should use ## for commented-out entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have been using this feature without undo for years in gocept.gtimelog. Yes, it happened to me that I called the command too often and thus loosing data. But I was usually able to reconstruct from memory, when it happened. (Mostly I use this feature when I added an entry because I thought I was done with a task, but then worked for some minutes on it to really complete it.)

So I see no immediate need for an undo ability. If it is too dangerous for some users, then they still can do it the old way be editing the timelog.txt file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The alternative could be, to do nothing when hitting the key combination and there is text in the field where you enter your time log entries.

Copy link
Member

Choose a reason for hiding this comment

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

The alternative could be, to do nothing when hitting the key combination and there is text in the field where you enter your time log entries.

I like this!

@icemac
Copy link
Contributor Author

icemac commented Dec 15, 2023

I like this! With some minor suggestions.

I like that you like it. 😀

I could merge it as-is and then fix up the things I want done differently directly in git master. Should I do that? I would like to hear your opinion about e.g. commenting out entries instead of removing them entirely, to avoid possible loss of data.

Feel free to merge and to improve afterwards.

@icemac
Copy link
Contributor Author

icemac commented Jan 29, 2024

I am using this branch in my daily work for over a month now. I think it is good enough to be merged.

@mgedmin mgedmin merged commit ad94da1 into gtimelog:master Jan 30, 2024
12 checks passed
@mgedmin
Copy link
Member

mgedmin commented Jan 30, 2024

Amazingly, I discovered the biggest flaw only after merging this: Ctrl-Backspace, by default, is used to delete word backwards in text entry boxes. And I use it a lot.

Luckily, this discovery happened after I already changed my copy of the code to comment out the entry instead of removing it.

But. I need to find a different shortcut.

@mgedmin
Copy link
Member

mgedmin commented Jan 30, 2024

I need to find a different shortcut.

Without much thought I changed it to Ctrl+Shift+Backspace.

@mgedmin
Copy link
Member

mgedmin commented Jan 30, 2024

And now I rewrote the implementation to comment out the lines instead of deleting them, as well as made some refactorings. You may want to give it another test, in case I broke something and didn't catch it while testing locally.

@icemac icemac deleted the edit-last-entry branch January 31, 2024 07:58
@mgedmin
Copy link
Member

mgedmin commented Feb 2, 2024

Without much thought I changed it to Ctrl+Shift+Backspace.

Today I reached for this feature for the first time, and my first instinct was to press Ctrl+Shift+Up, like I was editing the last message on Slack.

Hmm.

@icemac
Copy link
Contributor Author

icemac commented Feb 2, 2024

Thank you for merging this branch and doing some adaptions to it.

I have to admin that I am not a big fan of commenting lines instead of removing them as it clutters timelog.txt (yes, I am using this command quite often) and it requires changes in gtimelog2jira and gtimelog2tick (and other tools parsing timelog.txt) to be able to handle comments.

@mgedmin
Copy link
Member

mgedmin commented Feb 4, 2024

it requires changes in gtimelog2jira

Ehh? I've had comments in my timelog.txt since a long time ago, and I never noticed gtimelog2jira having problems with that.

Looking at the code, gtimelog2jira uses the same algorithm as gtimelog itself and silently ignores all the lines that don't start with a valid ISO 8601 datetime followed by a colon, so it should work fine.

@icemac
Copy link
Contributor Author

icemac commented Feb 6, 2024

I thought having comments was a new concept. Sorry for the noise, I did not even check gtimelog2tick. As I now found out, it works well with comments.

So now I have less of a problem with commenting out instead of deleting.
Let's just keep it like it is now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Differences between gtimelog and gocept.gtimelog.
3 participants