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

Add configuration for some default new bookmark values #50

Merged
merged 4 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
5 changes: 5 additions & 0 deletions tinboard/commands/core_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions tinboard/data/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions tinboard/screens/bookmark_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

##############################################################################
# Local imports.
from ..data import load_configuration
from ..pinboard import API, BookmarkData
from ..suggestions import SuggestTags

Expand Down Expand Up @@ -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:")
Expand All @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions tinboard/screens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -84,6 +85,7 @@ class Main(Screen[None]):
| <kbd>F2</kbd> | `Visit Pinboard` | Visit the main Pinboard website. |
| <kbd>F3</kbd> | | Toggle the bookmark details pane. |
| <kbd>F4</kbd> | | Toggle the sort order of the tags menu. |
| <kbd>F11</kbd> | `Settings` | Edit the application settings. |
| <kbd>F12</kbd> | `Logout` | Forgot your API token and remove the local bookmark cache. |
| <kbd>Ctrl</kbd>+<kbd>l</kbd> | `Redownload/refresh bookmarks` | Reload the local bookmarks from Pinboard. |
| <kbd>Ctrl</kbd>+<kbd>q</kbd> | `Quit the application` | Shockingly... quit the application! |
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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(
Expand Down
83 changes: 83 additions & 0 deletions tinboard/screens/settings.py
Original file line number Diff line number Diff line change
@@ -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