Skip to content

Commit

Permalink
Implement HypHoverPageOpener for HypPathSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Jan 14, 2024
1 parent fd20f32 commit 44ec6d8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
23 changes: 12 additions & 11 deletions hyperplane/navigation_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ def new_page(
return

page = HypItemsPage(gfile=gfile)
# Prefer tags over tag because of HypPathSegment, which has both
elif tags:
tags = list(tags)

if page.tags == tags:
return

if next_page and next_page.tags == tags:
self.view.push(next_page)
return

page = HypItemsPage(tags=tags)
elif tag:
if page.tags:
if tag in page.tags:
Expand All @@ -97,17 +109,6 @@ def new_page(

tags.append(tag)

if next_page and next_page.tags == tags:
self.view.push(next_page)
return

page = HypItemsPage(tags=tags)
elif tags:
tags = list(tags)

if page.tags == tags:
return

if next_page and next_page.tags == tags:
self.view.push(next_page)
return
Expand Down
16 changes: 11 additions & 5 deletions hyperplane/path_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
from gi.repository import Adw, Gdk, Gio, GObject, Gtk

from hyperplane import shared
from hyperplane.hover_page_opener import HypHoverPageOpener


@Gtk.Template(resource_path=shared.PREFIX + "/gtk/path-segment.ui")
class HypPathSegment(Gtk.Revealer):
class HypPathSegment(Gtk.Revealer, HypHoverPageOpener):
"""A segment in a HypPathBar."""

__gtype_name__ = "HypPathSegment"
Expand All @@ -45,17 +46,22 @@ def __init__(
**kwargs
) -> None:
super().__init__(**kwargs)
HypHoverPageOpener.__init__(self)

self.icon_name = icon_name
self.label = label
self.uri = uri
self.gfile = Gio.File.new_for_uri(self.uri) if self.uri else None
self.tag = tag

# This is needed for HypHoverPageOpener
self.tags = [tag]

middle_click = Gtk.GestureClick(button=Gdk.BUTTON_MIDDLE)
middle_click.connect(
"pressed",
lambda *_: self.get_root().new_tab(
Gio.File.new_for_uri(self.uri) if self.uri else None,
tags=[self.tag] if self.tag else None,
self.gfile, tags=[self.tag] if self.tag else None
),
)
self.add_controller(middle_click)
Expand Down Expand Up @@ -105,8 +111,8 @@ def __navigate(self, *_args: Any) -> None:
self.get_root().new_page(tags=[self.tag])
return

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

self.get_root().new_page(Gio.File.new_for_uri(self.uri))
self.get_root().new_page(self.gfile)
23 changes: 18 additions & 5 deletions hyperplane/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
empty_trash,
get_gfile_display_name,
get_paste_gfile,
trash,
validate_name,
)
from hyperplane.utils.tags import add_tags, move_tag, remove_tags
Expand Down Expand Up @@ -967,11 +968,23 @@ def __drop(
page = self.get_visible_page()
page.multi_selection.unselect_all()

if page.gfile and not page.gfile.query_info(
Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE, Gio.FileQueryInfoFlags.NONE
).get_attribute_boolean(Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE):
self.send_toast(_("The location is not writable"))
return False
if page.gfile:
if page.gfile.get_uri() == "trash:///":
if isinstance(value, Gdk.FileList):
for gfile in value:
if gfile.get_uri_scheme() == "trash":
return False

trash(*value)
return True

return False

if not page.gfile.query_info(
Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE, Gio.FileQueryInfoFlags.NONE
).get_attribute_boolean(Gio.FILE_ATTRIBUTE_ACCESS_CAN_WRITE):
self.send_toast(_("The location is not writable"))
return False

if isinstance(value, Gdk.FileList):
dst = self.get_visible_page().get_dst()
Expand Down

0 comments on commit 44ec6d8

Please sign in to comment.