Commit Graph

752 Commits

Author SHA1 Message Date
Isaiah Odhner
c2fd1f5dfd Make Open / Save As dialogs' handle_button code more similar
- request_close() instead of close() for Open dialog
- code path structure
- `filename` vs `name`
- `self.content.query_one` vs `self.query_one`
2023-05-07 13:37:27 -04:00
Isaiah Odhner
ad9983ecfe Remove Static() wrappers and disable markup parsing for messages
- This is shorter/cleaner.
- This is less prone to mistaken parentheses placement, although it
  should give a type error to do `Static() + Static()`
- I already disabled markup parsing for two cases where filenames are
  interpolated, but there was still:
  "An unexpected error occurred while reading %1"
  which was liable to misinterpret things as markup.
  Note that anything in square brackets can be treated as markup and
  become hidden, not just recognized tags like [red].
2023-05-07 13:36:32 -04:00
Isaiah Odhner
08cef5e875 Rename parameter that does not have to be a widget 2023-05-07 13:09:34 -04:00
Isaiah Odhner
e3ccb7614c Rename message box helper method 2023-05-07 13:05:55 -04:00
Isaiah Odhner
6c1b458cee Fix warning icon not showing up on subsequent dialogs 2023-05-07 12:55:19 -04:00
Isaiah Odhner
a06cf807e0 Fix immediate closing of dialog opened with Enter
For example, in the Open dialog, typing a filename that doesn't exist,
and then hitting enter, it's supposed to say "File not found", but
if the event isn't prevented/stopped, it will also be handled by
the new dialog, and you won't even see it.
2023-05-07 12:51:10 -04:00
Isaiah Odhner
b4971a0abf DRY Open / Save As dialog window content 2023-05-07 12:41:41 -04:00
Isaiah Odhner
e7b251a1c3 Add label for filename input, instead of using placeholder text 2023-05-07 12:26:55 -04:00
Isaiah Odhner
1a28f5cb49 Focus filename input in file dialogs by default 2023-05-07 12:02:25 -04:00
Isaiah Odhner
302fb628f6 Get absolute path, if only for logging 2023-05-07 11:41:36 -04:00
Isaiah Odhner
162167ef05 Remove filename suggestion for Copy To 2023-05-07 11:36:22 -04:00
Isaiah Odhner
84dc738140 Fix starting directory for Save As dialog
I think the `if self._selected_file_path is None: return` was from
copying from CharacterSelectorDialogWindow and isn't applicable.
(I renamed anything with "character" to "file_path".)
After removing this check, I shouldn't need `or ""` for the Open dialogs
2023-05-07 11:33:48 -04:00
Isaiah Odhner
0c671510a0 Support exporting to multiple formats with Edit > Copy To 2023-05-07 02:07:04 -04:00
Isaiah Odhner
6c76de66bf Discard backup file when restarting the program upon file changes etc. 2023-05-07 01:47:41 -04:00
Isaiah Odhner
f6bff095d6 Fix a theoretical race condition, and simplify
- This fixes a potential race condition where it could auto-save
  to the wrong backup file while the file_path was temporarily
  set to the path attempting to be written to,
  overwriting the backup if it existed, and leaving it behind on close,
  since the file_path would be reverted momentarily.
- save_as() no longer uses save(), so save doesn't need a from_save_as
  parameter to change the error dialog titles, and there's no more
  conceptual awkwardness due to the fact that each function could call
  the other.
- discard_backup() no longer needs an optional parameter, because
  we no longer discard a backup that isn't associated to the current
  document's file_path.
- The "correct thing" is now obvious enough that I don't feel the need
  for the "Don't discard the backup until..." comment.
  (And of course all that todo junk can go, although the Copy To bit
  remains to do.)

It's nice when things Actually Get Simpler!
2023-05-07 01:29:26 -04:00
Isaiah Odhner
ede6ea25b5 Refactor: split out encode_image from save 2023-05-07 01:07:24 -04:00
Isaiah Odhner
8861f4fa2b Add a todo comment about a possible race condition and refactoring 2023-05-07 00:40:47 -04:00
Isaiah Odhner
0d658d4a7f Restore old file path when Save As fails, and don't close the dialog 2023-05-07 00:24:57 -04:00
Isaiah Odhner
e806f25fad Don't discard backup until after file is saved for Save As 2023-05-06 23:51:10 -04:00
Isaiah Odhner
c172adc032 Discard backup file also when doing Save As 2023-05-06 23:40:50 -04:00
Isaiah Odhner
aa915915c8 Add sample art: Clippy
👀
📎
2023-05-06 19:55:46 -04:00
Isaiah Odhner
6bc6e6e305 Add some missing type signatures 2023-05-06 19:21:17 -04:00
Isaiah Odhner
be0285fc45 Use crayon emoji for pencil icon in VS Code 2023-05-06 19:01:30 -04:00
Isaiah Odhner
c86d8c01ae Use bucket emoji for fill tool icon, outside of VS Code
Other terminals may fail, so perhaps I should just stick to the more
reliable emoji, but the bucket is much better as an icon...
2023-05-06 18:56:09 -04:00
Isaiah Odhner
edd1c755e1 Fix type checker error by extracting expression to a variable
I was going to add a type hint, but it seems to have figured it out now.
2023-05-06 18:27:59 -04:00
Isaiah Odhner
b5b302e51f Rename things to avoid ambiguity of term "auto-save"
"Auto-save" can mean saving the actual document you're editing;
in this case it means saving a temporary backup file.
I might even want to introduce auto-saving of the main file later on.
2023-05-06 16:55:58 -04:00
Isaiah Odhner
6b46d99627 Clarify messaging about the backup feature 2023-05-06 16:41:43 -04:00
Isaiah Odhner
35197a8608 Discard backup on Open or New, not just on Exit 2023-05-06 02:02:55 -04:00
Isaiah Odhner
74ffc34de4 Automatically recover from backup file
- Recover from backup file if it exists for the document when loading
  a document via the CLI or TUI, or if it exists for Untitled when
  creating a new document.
- Reorganize CLI arguments handling into passive and active,
  so that the active recovery step can use the passive* backup folder
  option. (*Directories are created if they don't exist.)

Working on automatically recovering the document,
I'm realizing this is more complicated than I thought.
Consider two instances of the app (A and B) editing the same file:

- Make changes in A
- Open same file in B
- A auto-saves after timer
- Close B
- B deletes auto-save when closing
- A doesn't re-create the auto-save unless further changes are made to
  the document, because of the undo tracking, which is basically an
  optimization to avoid writing to the disk all day while idle.

Also, there could be a race condition where it saves over the auto save
before recovering it — potentially — like if the auto save interval
was implemented such that it made an immediate call at the start, or
if some other app code tries to auto save initially.
Or, consider if you:

- Make changes in A
- Open same file in B
- Make changes in B, maybe before it detects the backup file if the disk
  is very slow for some reason, or if you just ignore the prompt.
  (None of the prompts are modal, currently.)

To address these issues, I could add a flag that says whether the
auto save was written, and thus owned by, this session, and make it
not write to a backup file that it didn't create in the current session.
But it still ideally would auto save, just to a different file,
so I could instead have a map of file paths to bools saying whether it's
owned by the app or not and then have a number incremented in the
filename (maybe like `.ans~` and then `.ans~SESSION2~`, including
"SESSION" so it's clear it's not time-based), adding 1 until it's a file
that can be owned by the session when auto saving.
But if an earlier-numbered session closes, you wouldn't want it to leave
a file behind. Either it should delete/rename its backup file to the
earlier number and start saving to that, or it should keep the existing
higher number. I guess if looks at the map first, before checking the
file system, it shouldn't be a problem. It should keep using the higher
number. Would this be a little overkill? Eh, maybe.
2023-05-06 01:27:03 -04:00
Isaiah Odhner
1911b11a13 Postpone auto-save until there is no tool preview in the image data 2023-05-05 21:59:50 -04:00
Isaiah Odhner
2a6ad003d8 Discard backup file on (normal) exit 2023-05-05 21:52:17 -04:00
Isaiah Odhner
ce4fabd923 Add --backup-folder option 2023-05-05 21:51:25 -04:00
Isaiah Odhner
d12942700a Tweak auto-save backup file name 2023-05-05 21:50:42 -04:00
Isaiah Odhner
3cdc308b95 Optionally singularize a word 2023-05-05 20:03:15 -04:00
Isaiah Odhner
40496c312f Clarify filename argument 2023-05-05 19:59:10 -04:00
Isaiah Odhner
2af9f4fd53 Auto-save to ~ files 2023-05-05 19:59:10 -04:00
Isaiah Odhner
a792b7a132 Get path to readme relative to the Python script 2023-05-05 19:46:08 -04:00
Isaiah Odhner
f15ce6962c DRY file writing with error handling 2023-05-05 19:24:01 -04:00
Isaiah Odhner
5dd74165bc Generalize focusable control finding 2023-05-05 16:46:21 -04:00
Isaiah Odhner
c8c468662d Actually prioritize the submit button for default focus 2023-05-05 16:41:42 -04:00
Isaiah Odhner
d947fa605a Exclude localization data from GitHub language statistics (and diffs...) 2023-05-05 16:31:54 -04:00
Isaiah Odhner
cdfd42e1eb Fix clicking Edit Colors window not focusing the focusable button within
Don't try to focus an unfocusable control; find the first focusable one.

The Edit Colors dialog is not yet keyboard accessible, or very fully
implemented in general, but this at least prevents a scenario where
focus is unexpectedly left in an important dialog window, such as the
"Save changes to X?" prompt, which may also be obscured by Edit Colors.
You don't want pressing Enter to interact with a different dialog than
you're expecting, and suddenly quit without saving.
2023-05-05 16:17:55 -04:00
Isaiah Odhner
5ba2ad5cd3 Fix flash of incorrect layout while windows are opening 2023-05-05 15:57:54 -04:00
Isaiah Odhner
12c494983e Revert "Remove update_styles hack, seemingly not needed anymore"
This reverts commit 42ca86f7eb.

It's needed again after the last commit...
I did override `focus`, so it's not that surprising.
But I definitely want to figure this out.
2023-05-05 13:41:48 -04:00
Isaiah Odhner
eba3043d09 Focus last control within window when clicking to bring it to the front 2023-05-05 13:32:29 -04:00
Isaiah Odhner
e2f4c24e1b Appease the type checker 2023-05-05 13:04:27 -04:00
Isaiah Odhner
5d6074c549 Remove commented out code for custom zoom integer Input
- MS Paint uses radio buttons, as I've now implemented.
- Truly custom zoom levels make much less sense in the terminal.
2023-05-05 13:04:19 -04:00
Isaiah Odhner
6effab854c Fix grammar
I stopped at this word and changed how I was wording the sentence haha
2023-05-05 12:52:34 -04:00
Isaiah Odhner
baf2b076d1 Visually reorder radio buttons, preserving numerical navigation order 2023-05-05 01:45:47 -04:00
Isaiah Odhner
c880b1c8cc Revert "Reorder radio buttons to match MS Paint"
This reverts commit 848db8180b.
2023-05-05 01:04:44 -04:00