Skip to content

Commit

Permalink
Special properties windows for special directories
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 21, 2023
1 parent 9e920b0 commit a152de8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
4 changes: 4 additions & 0 deletions hyperplane/postmaster_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ def tag_location_created(
and set it up so they append `new_location` to their list of locations
if all `tags` are in their tags.
"""

@GObject.Signal(name="trash-emptied")
def trash_emptied(self) -> None:
"""Emitted when the trash is emptied by the app."""
37 changes: 34 additions & 3 deletions hyperplane/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from gi.repository import Adw, Gio, GLib, Gtk, Pango

from hyperplane import shared
from hyperplane.utils.files import get_gfile_path
from hyperplane.utils.files import empty_trash, get_gfile_path
from hyperplane.utils.get_color_for_content_type import get_color_for_content_type


Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self, gfile: Gio.File, **kwargs) -> None:
content_type = file_info.get_content_type()
gicon = file_info.get_symbolic_icon()
thumbnail_path = file_info.get_attribute_byte_string(Gio.FILE_ATTRIBUTE_THUMBNAIL_PATH)
size = file_info.get_size()
size = file_info.get_size() if gfile.get_uri().startswith("file://") else None
file_type = file_info.get_file_type()
access = file_info.get_access_date_time()
modified = file_info.get_modification_date_time()
Expand Down Expand Up @@ -159,7 +159,9 @@ def __init__(self, gfile: Gio.File, **kwargs) -> None:
)
)

elif file_type == Gio.FileType.DIRECTORY:
elif file_type == Gio.FileType.DIRECTORY and gfile.get_uri().startswith(
"file://"
):
folder_size_box = Gtk.Box(
margin_top=6, spacing=6, halign=Gtk.Align.CENTER
)
Expand Down Expand Up @@ -255,6 +257,35 @@ def stop_loading(thread: GLib.Thread):
trash_items_row.add_css_class("property")
trash_items_row.set_subtitle_selectable(True)

trash_group.add(
empty_trash_button := Gtk.Button(
margin_top=24,
label=_("Empty Trash"),
halign="center",
)
)

def empty(*_args: Any) -> None:
empty_trash()
self.close()

empty_trash_button.add_css_class("pill")
empty_trash_button.add_css_class("destructive-action")
empty_trash_button.connect("clicked", empty)
empty_trash_button.set_sensitive(bool(shared.trash_list.get_n_items()))

elif gfile.get_uri() == "recent:///":
page.add(recent_group := Adw.PreferencesGroup())

recent_group.add(
recent_items_row := Adw.ActionRow(
title=_("Items"),
subtitle=str(len(shared.recent_manager.get_items())),
)
)
recent_items_row.add_css_class("property")
recent_items_row.set_subtitle_selectable(True)

if access or modified or created:
page.add(history_group := Adw.PreferencesGroup())

Expand Down
2 changes: 2 additions & 0 deletions hyperplane/utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ def empty_trash() -> None:
logging.warning("Failed to empty trash: %s", error)
return

shared.postmaster.emit("trash-emptied")

for key, value in shared.undo_queue.copy().items():
if value[0] == "trash":
key.dismiss()
Expand Down
4 changes: 3 additions & 1 deletion hyperplane/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def __init__(self, **kwargs: Any) -> None:
self.search_button.connect("clicked", self.__toggle_search_entry)

shared.postmaster.connect("tags-changed", self.__update_tags)
shared.postmaster.connect(
"trash-emptied", lambda *_: self.trash_empty_animation.play()
)

self.right_click_menu.connect("closed", self.__set_actions)

Expand Down Expand Up @@ -837,7 +840,6 @@ def __emptry_trash(self, *_args: Any) -> None:
def handle_response(_dialog: Adw.MessageDialog, response: str) -> None:
if response == "empty":
empty_trash()
self.get_root().trash_empty_animation.play()

dialog.connect("response", handle_response)
dialog.present()

0 comments on commit a152de8

Please sign in to comment.