From c16da39330448a0a79653312d7100ce99c69f65a Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 27 Nov 2021 01:21:52 -0600 Subject: [PATCH] Updated file actions logic --- .../shellfm/windows/view/utils/FileHandler.py | 21 +++++++++++++------ .../mixins/WidgetFileActionMixin.py | 14 ++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/shellfm/windows/view/utils/FileHandler.py b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/shellfm/windows/view/utils/FileHandler.py index 1073681..57c69e3 100644 --- a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/shellfm/windows/view/utils/FileHandler.py +++ b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/shellfm/windows/view/utils/FileHandler.py @@ -3,19 +3,30 @@ import os, shutil, subprocess, threading class FileHandler: - def create_file(self, nFile): - pass + def create_file(self, nFile, type): + try: + if TYPE == "dir": + os.mkdir(nFile) + elif TYPE == "file": + open(nFile, 'a').close() + except Exception as e: + print("An error occured creating the file/dir:") + print(repr(e)) + return False + + return True def update_file(self, oFile, nFile): try: print(f"Renaming: {oFile} --> {nFile}") os.rename(oFile, nFile) - return True except Exception as e: print("An error occured renaming the file:") print(repr(e)) return False + return True + def delete_file(self, toDeleteFile): try: print(f"Deleting: {toDeleteFile}") @@ -66,6 +77,4 @@ class FileHandler: print(repr(e)) return False - - def paste_file(self): - pass + return True diff --git a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/WidgetFileActionMixin.py b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/WidgetFileActionMixin.py index e7fe8c4..9cb70c8 100644 --- a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/WidgetFileActionMixin.py +++ b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/WidgetFileActionMixin.py @@ -223,25 +223,29 @@ class WidgetFileActionMixin: if action == "move" or action == "edit": f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None) else: + # Yes, life is hopeless and there is no God. Blame Gio for this sinful shitshow. =/ wid, tid = self.window_controller.get_active_data() view = self.get_fm_window(wid).get_view_by_id(tid) fPath = f.get_path() tPath = None + state = True if target: tPath = target.get_path() + if action == "delete": - view.delete_file(fPath) + state = view.delete_file(fPath) if action == "trash": f.trash(cancellable=None) if action == "copy": - view.copy_file(fPath, tPath) - # f.copy(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None) + state = view.copy_file(fPath, tPath) if action == "move" or action == "edit": - view.move_file(fPath, tPath) - # f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None) + tPath = target.get_parent().get_path() + state = view.move_file(fPath, tPath) + if not state: + raise Exception("Failed to perform requested dir/file action!") except GObject.GError as e: raise OSError(e.message)