Skip to content

Commit

Permalink
🔀 Merge pull request #43 from davep/make-visiting-a-command
Browse files Browse the repository at this point in the history
Add link visiting as a global command
  • Loading branch information
davep authored Jan 6, 2025
2 parents ac75af5 + 351fefa commit f7f5728
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- Fixed doubling-up of the raindrop details panel's help when the raindrop's
tags have focus. ([#39](https://github.com/davep/braindrop/issues/39))
- Added a `Visit Link` command to the command palette.
([#43](https://github.com/davep/braindrop/pull/43))
- Added <kbd>v</kbd> as a global key for visiting a currently-highlighted
link. ([#43](https://github.com/davep/braindrop/pull/43))

## v0.2.0

Expand Down
2 changes: 2 additions & 0 deletions src/braindrop/app/commands/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
ShowUnsorted,
ShowUntagged,
TagOrder,
VisitLink,
VisitRaindrop,
)
from .commands_provider import CommandHits, CommandsProvider
Expand Down Expand Up @@ -65,6 +66,7 @@ def commands(self) -> CommandHits:
yield ShowUnsorted()
yield ShowUntagged()
yield TagOrder()
yield VisitLink()
yield VisitRaindrop()


Expand Down
2 changes: 2 additions & 0 deletions src/braindrop/app/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ShowUnsorted,
ShowUntagged,
TagOrder,
VisitLink,
VisitRaindrop,
)

Expand Down Expand Up @@ -57,6 +58,7 @@
"ShowUnsorted",
"ShowUntagged",
"TagOrder",
"VisitLink",
"VisitRaindrop",
]

Expand Down
8 changes: 8 additions & 0 deletions src/braindrop/app/messages/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ class Quit(Command):
BINDING_KEY = "f10, ctrl+q"


##############################################################################
class VisitLink(Command):
"""Visit currently-highlighted link"""

BINDING_KEY = "v"
SHOW_IN_FOOTER = False


##############################################################################
class CopyLinkToClipboard(Command):
"""Copy the currently-highlighted link to the clipboard"""
Expand Down
9 changes: 9 additions & 0 deletions src/braindrop/app/screens/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
ShowUnsorted,
ShowUntagged,
TagOrder,
VisitLink,
VisitRaindrop,
)
from ..widgets import Navigation, RaindropDetails, RaindropsView
Expand Down Expand Up @@ -166,6 +167,7 @@ class Main(Screen[None]):
ShowAll,
ShowUnsorted,
ShowUntagged,
VisitLink,
)

BINDINGS = Command.bindings(*COMMAND_MESSAGES)
Expand Down Expand Up @@ -507,6 +509,13 @@ def _current_link(self, action: str) -> str | None:
return None
return raindrop.link

@on(VisitLink)
def action_visit_link_command(self) -> None:
"""Visit the currently-highlighted link."""
if (link := self._current_link("visit")) is None:
return
open_url(link)

@on(CopyLinkToClipboard)
def action_copy_link_to_clipboard_command(self) -> None:
"""Copy the currently-highlighted link to the clipboard."""
Expand Down
14 changes: 4 additions & 10 deletions src/braindrop/app/widgets/raindrop_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
##############################################################################
# Local imports.
from ...raindrop import Raindrop, Tag
from ..messages import ShowTagged
from ..messages import ShowTagged, VisitLink
from .extended_option_list import OptionListEx


Expand Down Expand Up @@ -84,12 +84,9 @@ class Link(Label):
https://github.com/Textualize/textual/issues/3690
"""

class Visit(Message):
"""Message to indicate that the link should be visited."""

def action_visit(self) -> None:
"""Handle a UI request to visit the link."""
self.post_message(self.Visit())
self.post_message(VisitLink())


##############################################################################
Expand Down Expand Up @@ -178,8 +175,7 @@ class RaindropDetails(VerticalScroll):
Binding(
"enter",
"visit_link",
description="Visit",
tooltip="Visit the current Raindrop's link",
show=False,
)
]

Expand Down Expand Up @@ -275,11 +271,9 @@ def _watch_raindrop(self) -> None:
finally:
self.query("*").set_class(not bool(self.raindrop), "hidden")

@on(Link.Visit)
def action_visit_link(self) -> None:
"""Visit a link associated with the raindrop."""
if self.raindrop is not None and self.raindrop.link:
open_url(self.raindrop.link)
self.post_message(VisitLink())


### raindrop_details.py ends here
14 changes: 3 additions & 11 deletions src/braindrop/app/widgets/raindrops_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# Local imports.
from ...raindrop import Raindrop
from ..data import Raindrops
from ..messages import VisitLink
from .extended_option_list import OptionListEx


Expand Down Expand Up @@ -111,8 +112,7 @@ class RaindropsView(OptionListEx):
Binding(
"enter",
"visit",
description="Visit",
tooltip="Visit the currently-highlighted Raindrop",
show=False,
),
]

Expand Down Expand Up @@ -173,15 +173,7 @@ def highlighted_raindrop(self, raindrop: Raindrop | None) -> None:

def action_visit(self) -> None:
"""Action that visits the currently-selected raindrop link, if there is one."""
if (raindrop := self.highlighted_raindrop) is not None:
if raindrop.link:
open_url(raindrop.link)
else:
self.notify(
"There is no link associated with that Raindrop",
title="No link",
severity="error",
)
self.post_message(VisitLink())


### raindrops_view.py ends here

0 comments on commit f7f5728

Please sign in to comment.