Skip to content

Commit

Permalink
Disallow clicking active path segment
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 23, 2023
1 parent 1d6ccc1 commit 3901da9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 4 additions & 4 deletions hyperplane/path_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def remove(self, n: int) -> None:
return

try:
self.segments[-1].remove_css_class("inactive-segment")
self.segments[-2].add_css_class("inactive-segment")
self.segments[-1].active = True
self.segments[-2].active = False
except IndexError:
return

Expand Down Expand Up @@ -123,10 +123,10 @@ def append(
if self.tags:
return

segment.remove_css_class("inactive-segment")
segment.active = True

try:
self.segments[-2].add_css_class("inactive-segment")
self.segments[-2].active = False
except IndexError:
return

Expand Down
21 changes: 20 additions & 1 deletion hyperplane/path_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class HypPathSegment(Gtk.Revealer):
button: Gtk.Button = Gtk.Template.Child()
button_content: Adw.ButtonContent = Gtk.Template.Child()

_active: bool

def __init__(
self,
label: str,
Expand All @@ -52,15 +54,32 @@ def __init__(

def __navigate(self, *_args: Any) -> None:
# HACK: Do this properly
nav_bin = self.get_root().get_nav_bin()
win = self.get_root()
nav_bin = win.get_nav_bin()
page = win.get_visible_page()

if self.tag:
if page.tags == [self.tag]:
return
nav_bin.new_page(tags=[self.tag])
return

if self.uri:
if self.active: # pylint: disable=using-constant-test
return

nav_bin.new_page(Gio.File.new_for_uri(self.uri))

@GObject.Property(type=bool, default=True)
def active(self) -> bool:
"""Whether the segment is the currently active one."""
return self._active

@active.setter
def set_active(self, active) -> None:
self._active = active
(self.remove_css_class if active else self.add_css_class)("inactive-segment")

@GObject.Property(type=str)
def icon_name(self) -> str:
"""An optional icon for the path segment."""
Expand Down

0 comments on commit 3901da9

Please sign in to comment.