From f984ced6b9393adda05f3bf6e3c5cc47f75d0a1b Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 14 May 2024 09:05:28 +0100 Subject: [PATCH 1/4] :sparkles: Add config properties for new bookmark defaults Adds properties for the default value of private and read later. In support of satisfying #49. --- tinboard/data/config.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tinboard/data/config.py b/tinboard/data/config.py index b97be8d..c790ba3 100644 --- a/tinboard/data/config.py +++ b/tinboard/data/config.py @@ -26,6 +26,12 @@ class Configuration: sort_tags_by_count: bool = False """Should the tag menu sort on count?""" + default_private: bool = True + """Should a new bookmark be private by default?""" + + default_read_later: bool = True + """should a bookmark be marked for reading later by default?""" + ############################################################################## def configuration_file() -> Path: From d0e9b0a410b85c34a5d812b247edefa3818c6aa6 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 14 May 2024 09:06:37 +0100 Subject: [PATCH 2/4] :sparkles: Set the default values for private and read later Make use of the new default values held in the configuration; setting the defaults for private and read later when adding a new bookmark. In support of #49. --- tinboard/screens/bookmark_input.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tinboard/screens/bookmark_input.py b/tinboard/screens/bookmark_input.py index cd12f4a..45a09e3 100644 --- a/tinboard/screens/bookmark_input.py +++ b/tinboard/screens/bookmark_input.py @@ -26,6 +26,7 @@ ############################################################################## # Local imports. +from ..data import load_configuration from ..pinboard import API, BookmarkData from ..suggestions import SuggestTags @@ -113,6 +114,7 @@ def __init__( def compose(self) -> ComposeResult: """Compose the layout of the dialog.""" + config = load_configuration() with Vertical() as dialog: dialog.border_title = "Bookmark" yield Label("URL:") @@ -131,8 +133,8 @@ def compose(self) -> ComposeResult: ) yield Label(id="tag-suggestions") with Horizontal(id="flags"): - yield Checkbox("Private", id="private") - yield Checkbox("Read Later", id="read-later") + yield Checkbox("Private", config.default_private, id="private") + yield Checkbox("Read Later", config.default_read_later, id="read-later") with Horizontal(id="buttons"): yield Button("Save [dim]\\[F2][/]", id="save") yield Button("Cancel [dim]\\[Esc][/]", id="cancel") From 8fc0feb57342329dbca6c1bc6856d944d320985c Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 14 May 2024 17:18:44 +0100 Subject: [PATCH 3/4] :sparkles: Add a UI for editing the bookmark defaults Provides a dialog for editing the defaults for private and read-only when editing a new bookmark. See #49. --- tinboard/commands/core_commands.py | 5 ++ tinboard/screens/main.py | 7 +++ tinboard/screens/settings.py | 83 ++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 tinboard/screens/settings.py diff --git a/tinboard/commands/core_commands.py b/tinboard/commands/core_commands.py index 5a8ef4d..f031236 100644 --- a/tinboard/commands/core_commands.py +++ b/tinboard/commands/core_commands.py @@ -31,6 +31,11 @@ class CoreCommands(Provider): "logout", "Forget your Pinboard API token and remove the local copies of all bookmarks.", ), + ( + "Settings", + "settings", + "Modify the application settings and defaults.", + ), ( "Toggle details", "toggle_details", diff --git a/tinboard/screens/main.py b/tinboard/screens/main.py index 9bd74dc..0c0d0fd 100644 --- a/tinboard/screens/main.py +++ b/tinboard/screens/main.py @@ -53,6 +53,7 @@ from .confirm import Confirm from .help import Help from .search_input import SearchInput +from .settings import Settings from .wayback_checker import WaybackChecker @@ -84,6 +85,7 @@ class Main(Screen[None]): | F2 | `Visit Pinboard` | Visit the main Pinboard website. | | F3 | | Toggle the bookmark details pane. | | F4 | | Toggle the sort order of the tags menu. | + | F11 | `Settings` | Edit the application settings. | | F12 | `Logout` | Forgot your API token and remove the local bookmark cache. | | Ctrl+l | `Redownload/refresh bookmarks` | Reload the local bookmarks from Pinboard. | | Ctrl+q | `Quit the application` | Shockingly... quit the application! | @@ -197,6 +199,7 @@ class Main(Screen[None]): Binding("f2", "goto_pinboard"), Binding("f3", "toggle_details"), Binding("f4", "toggle_tag_order"), + Binding("f11", "settings"), Binding("f12", "logout"), Binding("ctrl+l", "redownload"), Binding("escape", "escape"), @@ -361,6 +364,10 @@ def _logout(self, confirmed: bool) -> None: bookmarks_file().unlink(True) self.app.exit(ExitStates.TOKEN_FORGOTTEN) + def action_settings(self) -> None: + """Edit the application settings.""" + self.app.push_screen(Settings()) + def action_logout(self) -> None: """Perform the logout action.""" self.app.push_screen( diff --git a/tinboard/screens/settings.py b/tinboard/screens/settings.py new file mode 100644 index 0000000..58c7187 --- /dev/null +++ b/tinboard/screens/settings.py @@ -0,0 +1,83 @@ +"""Provides a settings screen.""" + +############################################################################## +# Textual imports. +from textual import on +from textual.app import ComposeResult +from textual.containers import Horizontal, Vertical +from textual.screen import ModalScreen +from textual.widgets import Button, Checkbox + +############################################################################## +# Local imports. +from ..data import load_configuration, save_configuration + + +############################################################################## +class Settings(ModalScreen[None]): + """A modal dialog for editing settings.""" + + CSS = """ + Settings { + align: center middle; + + &> Vertical { + height: auto; + width: auto; + background: $surface; + border: panel $primary; + border-title-color: $accent; + } + + #buttons { + height: auto; + width: 100%; + margin-top: 1; + align-horizontal: right; + } + + Checkbox { + background: $surface; + } + + Button { + margin-right: 1; + } + } + """ + + BINDINGS = [("escape", "cancel"), ("f2", "save")] + + def compose(self) -> ComposeResult: + """Compose the layout of the dialog.""" + with Vertical() as dialog: + dialog.border_title = "Application Settings" + config = load_configuration() + yield Checkbox( + "Bookmarks are private by default", config.default_private, id="private" + ) + yield Checkbox( + "Bookmarks read-later by default", + config.default_read_later, + id="read-later", + ) + with Horizontal(id="buttons"): + yield Button("Save [dim]\\[F2][/]", id="save") + yield Button("Cancel [dim]\\[Esc][/]", id="cancel") + + @on(Button.Pressed, "#save") + def action_save(self) -> None: + """Save the configuration.""" + config = load_configuration() + config.default_private = self.query_one("#private", Checkbox).value + config.default_read_later = self.query_one("#read-later", Checkbox).value + save_configuration(config) + self.dismiss(None) + + @on(Button.Pressed, "#cancel") + def action_cancel(self) -> None: + """Cancel the edit of the bookmark data.""" + self.dismiss(None) + + +### settings.py ends here From a43dd494a7cdc794fbe3abf817dbe753b05bad81 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Tue, 14 May 2024 17:22:48 +0100 Subject: [PATCH 4/4] :books: Updated the ChangeLog --- ChangeLog.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 1b545e1..5cccc60 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,18 @@ # Tinboard ChangeLog +## WiP + +**Released: WiP** + +- Added the ability to set the default value for new bookmark privacy. + ([#50](https://github.com/davep/tinboard/pull/50)) +- Added the ability to set the default value for new bookmark read-later + status. ([#50](https://github.com/davep/tinboard/pull/50)) +- Added an applications settings dialog. + ([#50](https://github.com/davep/tinboard/pull/50)) +- Added a command palette command for the applications settings dialog. + ([#50](https://github.com/davep/tinboard/pull/50)) + ## v0.13.0 **Released: 2024-05-02**