Skip to content

Commit

Permalink
Allow entering a path on left clicking the bar
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 22, 2023
1 parent 9796930 commit c0bf3c1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
13 changes: 12 additions & 1 deletion hyperplane/gtk/path-bar.blp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ template $HypPathBar : ScrolledWindow {
hscrollbar-policy: external;

Viewport viewport {
Box segments_box {}
Overlay {
[overlay]
Box segments_box {
valign: start;
halign: start;
}

Box dummy_box {
vexpand: true;
hexpand: true;
}
}
}

styles [
Expand Down
2 changes: 1 addition & 1 deletion hyperplane/gtk/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ rubberband {
border-right: solid 1px @borders;
border-radius: 0px 6px 6px 0px;
}
.path-bar > viewport > box > revealer > button {
.path-bar > viewport > overlay > box > revealer > button {
padding: 2px 9px;
margin: 3px;
border-radius: 4px;
Expand Down
31 changes: 23 additions & 8 deletions hyperplane/path_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"""The path bar in a HypWindow."""
from typing import Optional

from gi.repository import GLib, Gtk
from gi.repository import Gdk, GLib, Gtk

from hyperplane import shared
from hyperplane.path_segment import HypPathSegment
Expand All @@ -34,6 +34,8 @@ class HypPathBar(Gtk.ScrolledWindow):

viewport: Gtk.Viewport = Gtk.Template.Child()
segments_box: Gtk.Box = Gtk.Template.Child()
# A box for capturing left clicks on the bar itself, not a segment
dummy_box: Gtk.Box = Gtk.Template.Child()

segments: list
separators: dict
Expand All @@ -45,13 +47,12 @@ def __init__(self, **kwargs) -> None:
self.separators = {}
self.tags = False

def __remove_child(self, parent: Gtk.Box, child: Gtk.Widget) -> None:
# This is so GTK doesn't freak out when the child isn't in the box anymore
if child.get_parent == parent:
parent.remove(child)
left_click = Gtk.GestureClick(button=Gdk.BUTTON_PRIMARY)
left_click.connect("released", self.__left_click)
self.dummy_box.add_controller(left_click)

def remove(self, n: int) -> None:
"""Removes n number of segments form self."""
"""Removes `n` number of segments form self, animating them."""
for _index in range(n):
child = self.segments.pop()
child.set_reveal_child(False)
Expand Down Expand Up @@ -90,7 +91,13 @@ def append(
uri: Optional[str] = None,
tag: Optional[str] = None,
) -> None:
"""Appends a HypPathSegment with `label` to self."""
"""
Appends a HypPathSegment with `label` and `icon_name` to self.
`uri` or `tag` will be opened when the segment is clicked.
Adding an item is animated.
"""
if self.segments:
# Add a separator only if there is more than one item
sep_label = Gtk.Label.new("+" if self.tags else "/")
Expand Down Expand Up @@ -130,9 +137,17 @@ def append(
return

def purge(self) -> None:
"""Removes all segments from self."""
"""Removes all segments from self, without animation."""
while child := self.segments_box.get_first_child():
self.segments_box.remove(child)

self.segments = []
self.separators = {}

def __remove_child(self, parent: Gtk.Box, child: Gtk.Widget) -> None:
# This is so GTK doesn't freak out when the child isn't in the parent anymore
if child.get_parent == parent:
parent.remove(child)

def __left_click(self, *_args) -> None:
self.get_root().lookup_action("toggle-path-bar").activate()

0 comments on commit c0bf3c1

Please sign in to comment.