From 844121a5c6ffb57d3432c5c1ebfd80a59e8087a8 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Wed, 1 Dec 2021 19:22:03 -0600 Subject: [PATCH] Added delete guard; reordered glade import/setup --- .../new/solarfm/signal_classes/Controller.py | 12 ++--- .../solarfm/signal_classes/Controller_Data.py | 1 + .../signal_classes/KeyboardSignalsMixin.py | 7 +-- .../solarfm/signal_classes/ShowHideMixin.py | 3 +- .../mixins/WidgetFileActionMixin.py | 46 +++++++++++-------- .../signal_classes/mixins/WidgetMixin.py | 7 +-- .../signal_classes/mixins/WindowMixin.py | 7 +++ .../SolarFM/new/solarfm/utils/Settings.py | 6 +-- 8 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller.py index 79916a9..9587b1d 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller.py @@ -50,6 +50,7 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \ time.sleep(event_sleep_time) Gtk.main_quit() + @threaded def gui_event_observer(self): while event_system.monitor_events: @@ -103,8 +104,6 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \ save_location_prompt.destroy() - - def do_edit_files(self, widget=None, eve=None): self.to_rename_files = self.selected_files self.rename_files() @@ -113,6 +112,7 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \ id = widget.get_active_id() self.arc_command_buffer.set_text(self.arc_commands[int(id)]) + def execute(self, _command, start_dir=os.getenv("HOME"), use_os_system=None): if use_os_system: os.system(_command) @@ -121,8 +121,6 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \ command = _command.split() subprocess.Popen(command, cwd=start_dir, shell=False, start_new_session=True, stdout=DEVNULL, stderr=DEVNULL) - - def do_action_from_menu_controls(self, widget, eventbutton): action = widget.get_name() self.ctrlDown = True @@ -130,7 +128,6 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \ self.hide_new_file_menu() self.hide_edit_file_menu() - if action == "execute": self.execute_files() if action == "execute_in_terminal": @@ -154,7 +151,8 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \ if action == "archive": self.show_archiver_dialogue() if action == "delete": - # self.delete_files() + self.delete_files() + if action == "trash": self.trash_files() if action == "go_to_trash": self.builder.get_object("path_entry").set_text(self.trash_files_path) @@ -162,8 +160,6 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \ self.ctrlDown = False - - def generate_windows(self, data = None): if data: for j, value in enumerate(data): diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller_Data.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller_Data.py index 4b1e1ca..cc72d9e 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller_Data.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/Controller_Data.py @@ -30,6 +30,7 @@ class Controller_Data: self.message_buffer = self.builder.get_object("message_buffer") self.arc_command_buffer = self.builder.get_object("arc_command_buffer") + self.warning_alert = self.builder.get_object("warning_alert") self.exists_alert = self.builder.get_object("exists_alert") self.exists_from_label = self.builder.get_object("exists_from_label") self.exists_to_label = self.builder.get_object("exists_to_label") diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/KeyboardSignalsMixin.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/KeyboardSignalsMixin.py index 657753b..6635c4c 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/KeyboardSignalsMixin.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/KeyboardSignalsMixin.py @@ -4,8 +4,7 @@ import gi gi.require_version('Gtk', '3.0') gi.require_version('Gdk', '3.0') -from gi.repository import Gtk -from gi.repository import Gdk +from gi.repository import Gtk, Gdk # Application imports @@ -67,8 +66,10 @@ class KeyboardSignalsMixin: if self.ctrlDown and keyname == "n": self.show_new_file_menu() - if keyname == "delete": + if self.ctrlDown and self.shiftDown and keyname == "t": self.trash_files() + if keyname == "delete": + self.delete_files() if keyname == "f2": self.do_edit_files() if keyname == "f4": diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/ShowHideMixin.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/ShowHideMixin.py index 2efdab0..9b95f7f 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/ShowHideMixin.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/ShowHideMixin.py @@ -3,8 +3,7 @@ # Gtk imports import gi gi.require_version('Gtk', '3.0') -from gi.repository import Gtk -from gi.repository import Gio +from gi.repository import Gtk, Gio # Application imports diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetFileActionMixin.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetFileActionMixin.py index 1ba1a28..a4ec6cb 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetFileActionMixin.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetFileActionMixin.py @@ -2,7 +2,9 @@ import os # Lib imports -from gi.repository import GObject, Gio +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, GObject, Gio # Application imports @@ -89,6 +91,7 @@ class WidgetFileActionMixin: command = f"sh -c '{path}'" if not in_terminal else f"{view.terminal_app} -e '{path}'" self.execute(command, current_dir) + def open_files(self): wid, tid, view, iconview, store = self.get_current_state() uris = self.format_to_uris(store, wid, tid, self.selected_files, True) @@ -96,7 +99,6 @@ class WidgetFileActionMixin: for file in uris: view.open_file_locally(file) - def open_with_files(self, appchooser_widget): wid, tid, view, iconview, store = self.get_current_state() uris = self.format_to_uris(store, wid, tid, self.selected_files) @@ -197,10 +199,13 @@ class WidgetFileActionMixin: # NOTE: While not fully race condition proof, we happy path it first # and then handle anything after as a conflict for renaming before - # copy, move, or edit. + # copy, move, or edit. This is literally the oppopsite of what Gtk says to do. + # But, they can't even delete directories properly. So... f**k them. def handle_file(self, paths, action, _target_path=None): paths = self.preprocess_paths(paths) target = None + response = None + self.warning_alert.format_secondary_text(f"Do you really want to {action} the {len(paths)} file(s)?") for path in paths: try: @@ -209,17 +214,6 @@ class WidgetFileActionMixin: if action == "trash": file.trash(cancellable=None) - if action == "delete": - # TODO: Add proper confirmation prompt befor doing either - type = file.query_file_type(flags=Gio.FileQueryInfoFlags.NONE) - - if type == Gio.FileType.DIRECTORY: - wid, tid = self.window_controller.get_active_data() - view = self.get_fm_window(wid).get_view_by_id(tid) - view.delete_file( file.get_path() ) - else: - file.delete(cancellable=None) - if (action == "create_file" or action == "create_dir") and not file.query_exists(): if action == "create_file": file.create(flags=Gio.FileCreateFlags.NONE, cancellable=None) @@ -261,14 +255,28 @@ class WidgetFileActionMixin: + # NOTE: Past here, we need to handle detected conflicts. # Maybe create a collection of file and target pares # that then get passed to a handler who calls show_exists_page? - # type = None - # gio_flag = None - # self.exists_alert.hide() - # if not state: - # raise GObject.GError("Failed to perform requested dir/file action!") + + if action == "delete": + if not response: + response = self.warning_alert.run() + self.warning_alert.hide() + if response == Gtk.ResponseType.YES: + type = file.query_file_type(flags=Gio.FileQueryInfoFlags.NONE) + + if type == Gio.FileType.DIRECTORY: + wid, tid = self.window_controller.get_active_data() + view = self.get_fm_window(wid).get_view_by_id(tid) + view.delete_file( file.get_path() ) + else: + file.delete(cancellable=None) + else: + break + + except GObject.GError as e: raise OSError(e) diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetMixin.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetMixin.py index cf21599..adaa2f2 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetMixin.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WidgetMixin.py @@ -46,14 +46,9 @@ class WidgetMixin: # NOTE: Might need to keep an eye on this throwing invalid iters when too # many updates are happening to a folder. Example: /tmp - # Will sink for now. (Aka ignore forever) def update_store(self, item): i, store, icon, view, fpath = item - itr = None - try: - itr = store.get_iter(i) - except Exception as e: - return + itr = store.get_iter(i) if not icon: icon = self.get_system_thumbnail(fpath, view.SYS_ICON_WH[0]) diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WindowMixin.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WindowMixin.py index 7977bda..b76ec32 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WindowMixin.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/signal_classes/mixins/WindowMixin.py @@ -93,6 +93,13 @@ class WindowMixin(TabMixin): def grid_icon_double_left_click(self, iconview, item, data=None): try: + if self.ctrlDown and self.shiftDown: + self.execute_files(in_terminal=True) + return + elif self.ctrlDown: + self.execute_files() + return + wid, tid = self.window_controller.get_active_data() notebook = self.builder.get_object(f"window_{wid}") path_entry = self.builder.get_object(f"path_entry") diff --git a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/utils/Settings.py b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/utils/Settings.py index 77a7240..93c7951 100644 --- a/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/utils/Settings.py +++ b/src/versions/solarfm-0.0.1/SolarFM/new/solarfm/utils/Settings.py @@ -21,14 +21,14 @@ class Settings: self.USER_HOME = path.expanduser('~') self.CONFIG_PATH = self.USER_HOME + "/.config/solarfm" - self.windows_glade = self.CONFIG_PATH + "/Main_Window.glade" - self.popups_glade = self.CONFIG_PATH + "/Menu_Popups.glade" self.cssFile = self.CONFIG_PATH + '/stylesheet.css' + self.popups_glade = self.CONFIG_PATH + "/Menu_Popups.glade" + self.windows_glade = self.CONFIG_PATH + "/Main_Window.glade" self.logger = Logger().get_logger() self.builder = gtk.Builder() - self.builder.add_from_file(self.windows_glade) self.builder.add_from_file(self.popups_glade) + self.builder.add_from_file(self.windows_glade) self.DEFAULT_ICONS = self.CONFIG_PATH + "/icons" self.window_icon = self.DEFAULT_ICONS + "/solarfm.png"