Updated file actions logic
This commit is contained in:
parent
49e2bc5983
commit
c16da39330
|
@ -3,19 +3,30 @@ import os, shutil, subprocess, threading
|
||||||
|
|
||||||
|
|
||||||
class FileHandler:
|
class FileHandler:
|
||||||
def create_file(self, nFile):
|
def create_file(self, nFile, type):
|
||||||
pass
|
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):
|
def update_file(self, oFile, nFile):
|
||||||
try:
|
try:
|
||||||
print(f"Renaming: {oFile} --> {nFile}")
|
print(f"Renaming: {oFile} --> {nFile}")
|
||||||
os.rename(oFile, nFile)
|
os.rename(oFile, nFile)
|
||||||
return True
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("An error occured renaming the file:")
|
print("An error occured renaming the file:")
|
||||||
print(repr(e))
|
print(repr(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def delete_file(self, toDeleteFile):
|
def delete_file(self, toDeleteFile):
|
||||||
try:
|
try:
|
||||||
print(f"Deleting: {toDeleteFile}")
|
print(f"Deleting: {toDeleteFile}")
|
||||||
|
@ -66,6 +77,4 @@ class FileHandler:
|
||||||
print(repr(e))
|
print(repr(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
def paste_file(self):
|
|
||||||
pass
|
|
||||||
|
|
|
@ -223,25 +223,29 @@ class WidgetFileActionMixin:
|
||||||
if action == "move" or action == "edit":
|
if action == "move" or action == "edit":
|
||||||
f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
||||||
else:
|
else:
|
||||||
|
# Yes, life is hopeless and there is no God. Blame Gio for this sinful shitshow. =/
|
||||||
wid, tid = self.window_controller.get_active_data()
|
wid, tid = self.window_controller.get_active_data()
|
||||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||||
fPath = f.get_path()
|
fPath = f.get_path()
|
||||||
tPath = None
|
tPath = None
|
||||||
|
state = True
|
||||||
|
|
||||||
if target:
|
if target:
|
||||||
tPath = target.get_path()
|
tPath = target.get_path()
|
||||||
|
|
||||||
|
|
||||||
if action == "delete":
|
if action == "delete":
|
||||||
view.delete_file(fPath)
|
state = view.delete_file(fPath)
|
||||||
if action == "trash":
|
if action == "trash":
|
||||||
f.trash(cancellable=None)
|
f.trash(cancellable=None)
|
||||||
if action == "copy":
|
if action == "copy":
|
||||||
view.copy_file(fPath, tPath)
|
state = view.copy_file(fPath, tPath)
|
||||||
# f.copy(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
|
||||||
if action == "move" or action == "edit":
|
if action == "move" or action == "edit":
|
||||||
view.move_file(fPath, tPath)
|
tPath = target.get_parent().get_path()
|
||||||
# f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
|
state = view.move_file(fPath, tPath)
|
||||||
|
|
||||||
|
if not state:
|
||||||
|
raise Exception("Failed to perform requested dir/file action!")
|
||||||
except GObject.GError as e:
|
except GObject.GError as e:
|
||||||
raise OSError(e.message)
|
raise OSError(e.message)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue