Skip to content

Commit

Permalink
Reduce opacity of items about to be cut
Browse files Browse the repository at this point in the history
  • Loading branch information
kra-mo committed Dec 24, 2023
1 parent c240f98 commit 5cd0a02
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
4 changes: 4 additions & 0 deletions hyperplane/gtk/style-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ navigation-view > shadow {
background: radial-gradient(farthest-side at right, rgba(0,0,0,.15) 0%, rgba(0,0,0,0) 100%);
}

.cut-item {
filter: brightness(60%);
}

.blue-icon { color: @blue_1; }
.blue-background { background: alpha(@blue_5, 0.5); }
.blue-extension { background: @blue_1; color: @dark_5; }
Expand Down
9 changes: 9 additions & 0 deletions hyperplane/gtk/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ rubberband {
font-size: small;
}

/*
This makes it look like the opacity decreased
The reason I cannot actually do that is that it reduces the opacity of widgets individually
and that looks ugly.
*/
.cut-item {
filter: contrast(50%) brightness(130%);
}

.sidebar-check-button > check {
color: @sidebar_fg_color;
background-color: @sidebar_shade_color;
Expand Down
31 changes: 21 additions & 10 deletions hyperplane/items_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,7 @@ def __unbind(self, _factory: Gtk.SignalListItemFactory, item: Gtk.ListItem) -> N

def __tags_changed(self, _obj: GObject.Object, change: Gtk.FilterChange) -> None:
# TODO: I could do less/more strict with adding/removing tags separately
self.item_filter.changed(
change
)
self.item_filter.changed(change)

def __toggle_hidden(self, *_args: Any) -> None:
if shared.show_hidden:
Expand Down Expand Up @@ -421,7 +419,12 @@ def __popup_menu(self) -> None:
# Read-only special directories
if self.gfile:
items.add("properties")
if (self.gfile.get_uri_scheme() in {"trash", "recent", "burn", "network"}):
if self.gfile.get_uri_scheme() in {
"trash",
"recent",
"burn",
"network",
}:
items.remove("paste")
items.remove("new-folder")

Expand Down Expand Up @@ -711,7 +714,7 @@ def create_folder(*_args: Any):
dialog.choose()

def __copy(self, *_args: Any) -> None:
shared.cut_page = None
shared.set_cut_widgets(set())
clipboard = Gdk.Display.get_default().get_clipboard()
if not (items := self.get_selected_gfiles()):
return
Expand All @@ -722,7 +725,15 @@ def __copy(self, *_args: Any) -> None:

def __cut(self, _obj: Any, *args: Any) -> None:
self.__copy(*args)
shared.cut_page = self

children = self.grid_view.observe_children()

cut_widgets = set()

for pos in self.get_selected_positions():
cut_widgets.add(children.get_item(pos).get_first_child())

shared.set_cut_widgets(cut_widgets)

def __paste(self, *_args: Any) -> None:
clipboard = Gdk.Display.get_default().get_clipboard()
Expand All @@ -748,7 +759,7 @@ def paste_file_cb(clipboard: Gdk.Clipboard, result: Gio.AsyncResult) -> None:
try:
file_list = clipboard.read_value_finish(result)
except GLib.Error:
shared.cut_page = None
shared.set_cut_widgets(set())
return

for src in file_list:
Expand All @@ -759,7 +770,7 @@ def paste_file_cb(clipboard: Gdk.Clipboard, result: Gio.AsyncResult) -> None:
except (FileNotFoundError, TypeError):
continue

if shared.cut_page:
if shared.cut_widgets:
try:
move(src, dst)
except FileExistsError:
Expand All @@ -785,11 +796,11 @@ def paste_file_cb(clipboard: Gdk.Clipboard, result: Gio.AsyncResult) -> None:

paths.append(dst)

if shared.cut_page:
if shared.cut_widgets:
shared.undo_queue[time()] = ("cut", paths)
else:
shared.undo_queue[time()] = ("copy", paths)
shared.cut_page = None
shared.set_cut_widgets(set())

def paste_texture_cb(clipboard: Gdk.Clipboard, result: Gio.AsyncResult) -> None:
nonlocal dst
Expand Down
20 changes: 19 additions & 1 deletion hyperplane/shared.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ del path

app = None # pylint: disable=invalid-name
search = "" # pylint: disable=invalid-name
cut_page = None # pylint: disable=invalid-name
right_clicked_file = None # pylint: disable=invalid-name
undo_queue = {}

Expand Down Expand Up @@ -82,3 +81,22 @@ else:
recent_manager = Gtk.RecentManager.get_default()

icon_names = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()).get_icon_names()

cut_widgets = set()


def set_cut_widgets(widgets: list[Gtk.Widget]) -> None:
"""
Sets widgets representing files that are going to be moved after a paste operation.

This is so their "opacity" can be reduced.
"""
global cut_widgets # pylint: disable=global-statement

for widget in cut_widgets:
widget.remove_css_class("cut-item")

for widget in widgets:
widget.add_css_class("cut-item")

cut_widgets = widgets

0 comments on commit 5cd0a02

Please sign in to comment.