beeware / toga

A Python native, OS native GUI toolkit.
https://toga.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
4.2k stars 656 forks source link

Add support for user-defined New, Save, Save As and Save All commands #2688

Open freakboy3742 opened 3 days ago

freakboy3742 commented 3 days ago

Builds on #2666; that PR should be reviewed and merged before this one.

This is the last of the PRs derived from #2244. It adds the rest of the APIs needed by a real Document-based app: New, Save, Save As, and Save All.

There are app-level entry points for these commands that can be overridden to activate the corresponding menu items; or, they will all be installed if there is at least one document type registered.

The save commands all trigger file dialogs to pick filenames (and check for overwriting existing files) as required.

On GTK/Windows, the new document handling is used to generate an empty document when there are no command line arguments.

One area for future improvement - the save/save as menu items are always active, but only save the current window. Making the menu items enabled/disabled depends on having either gain/lost focus events for windows (#2009), and/or window-based menus (#2210). In the meantime, if the current window defines a save()/save_as() method, that method will be invoked; if the current window doesn't define those methods, the save request will be ignored.

PR Checklist: