Updated file actions logic
This commit is contained in:
parent
49e2bc5983
commit
c16da39330
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user