Skip to content

Commit

Permalink
Add animation for trashing files & emptying trash
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 21, 2023
1 parent a26755a commit 27655d9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
7 changes: 4 additions & 3 deletions hyperplane/gtk/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ template $HypWindow : Adw.ApplicationWindow {
ListBox trash_box {
selection-mode: none;
Box {
spacing: 12;
margin-start: 6;
margin-end: 6;
Image trash_icon {}
Image trash_icon {
width-request: 28;
}
Label {
margin-start: 6;
label: _("Trash");
}
}
Expand Down
7 changes: 6 additions & 1 deletion hyperplane/items_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ def __popup_menu(self) -> None:
"open-with",
}
if self.gfile.get_uri() == "trash:///":
items.add("empty-trash")
if shared.trash_list.get_n_items():
items.add("empty-trash")
items.remove("paste")
items.remove("new-folder")

Expand Down Expand Up @@ -712,6 +713,8 @@ def __trash(self, *args) -> None:
shared.undo_queue[toast] = ("trash", files)
toast.connect("button-clicked", self.__undo)

self.get_root().trash_animation.play()

def __trash_delete(self, *args: Any) -> None:
gfiles = self.get_selected_gfiles()

Expand Down Expand Up @@ -765,6 +768,8 @@ def __scroll(
if self.scroll.get_current_event_state() != Gdk.ModifierType.CONTROL_MASK:
return

# TODO: Temporairily disallow scrolling in the ScrolledWindow here

if dy < 0:
self.get_root().zoom_in()
return
Expand Down
2 changes: 1 addition & 1 deletion hyperplane/navigation_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def new_page(
tag: Optional[str] = None,
tags: Optional[Iterable[str]] = None,
) -> None:
"""Push a new page with the given path or tag to the navigation stack."""
"""Push a new page with the given file or tag to the navigation stack."""
if gfile:
self.tags = []
page = HypItemsPage(gfile=gfile)
Expand Down
51 changes: 33 additions & 18 deletions hyperplane/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ def __init__(self, **kwargs: Any) -> None:
self.tab_view.connect("close-page", self.__close_page)
self.closed_tabs = []

# Set up animations

target = Adw.PropertyAnimationTarget.new(self.trash_icon, "pixel-size")
params = Adw.SpringParams.new(0.4, 0.8, 250)
self.trash_animation = Adw.SpringAnimation.new(
self.trash_icon, 10, 16, params, target
)
self.trash_animation.props.epsilon = 0.01500

self.trash_empty_animation = Adw.SpringAnimation.new(
self.trash_icon, 22, 16, params, target
)
self.trash_empty_animation.props.epsilon = 0.02500

# Create actions

navigation_view = HypNavigationBin(
Expand Down Expand Up @@ -269,6 +283,24 @@ def get_visible_page(self) -> HypItemsPage:
"""Return the currently visible HypItemsPage."""
return self.get_nav_bin().view.get_visible_page()

def zoom_in(self, *_args: Any) -> None:
"""Increases the zoom level of all views."""

if (zoom_level := shared.state_schema.get_uint("zoom-level")) > 4:
return

shared.state_schema.set_uint("zoom-level", zoom_level + 1)
self.update_zoom()

def zoom_out(self, *_args: Any) -> None:
"""Decreases the zoom level of all views."""

if (zoom_level := shared.state_schema.get_uint("zoom-level")) < 2:
return

shared.state_schema.set_uint("zoom-level", zoom_level - 1)
self.update_zoom()

def update_zoom(self) -> None:
"""Update the zoom level of all items in the navigation stack"""
shared.postmaster.emit("zoom", shared.state_schema.get_uint("zoom-level"))
Expand Down Expand Up @@ -600,24 +632,6 @@ def __forward(self, *_args: Any) -> None:

nav_bin.view.push(nav_bin.next_pages[-1])

def zoom_in(self, *_args: Any) -> None:
"""Increases the zoom level of all views."""

if (zoom_level := shared.state_schema.get_uint("zoom-level")) > 4:
return

shared.state_schema.set_uint("zoom-level", zoom_level + 1)
self.update_zoom()

def zoom_out(self, *_args: Any) -> None:
"""Decreases the zoom level of all views."""

if (zoom_level := shared.state_schema.get_uint("zoom-level")) < 2:
return

shared.state_schema.set_uint("zoom-level", zoom_level - 1)
self.update_zoom()

def __reset_zoom(self, *_args: Any) -> None:
shared.state_schema.reset("zoom-level")
self.update_zoom()
Expand Down Expand Up @@ -823,6 +837,7 @@ 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 27655d9

Please sign in to comment.