From 49e2bc59832531e08e41df5d27301be8e0470a57 Mon Sep 17 00:00:00 2001
From: itdominator <1itdominator@gmail.com>
Date: Sat, 27 Nov 2021 00:51:31 -0600
Subject: [PATCH] Added open with feature; fixed delete non empty dir
---
.../pyfm-0.0.1/PyFM/new/pyfm/__main__.py | 1 +
.../PyFM/new/pyfm/resources/Main_Window.glade | 107 +++++++++++++++++-
.../shellfm/windows/view/utils/FileHandler.py | 20 ++--
.../PyFM/new/pyfm/signal_classes/Signals.py | 30 ++++-
.../pyfm/signal_classes/mixins/TabMixin.py | 6 +-
.../mixins/WidgetFileActionMixin.py | 60 +++++++---
6 files changed, 189 insertions(+), 35 deletions(-)
diff --git a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/__main__.py b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/__main__.py
index 5f409b0..b808f3e 100644
--- a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/__main__.py
+++ b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/__main__.py
@@ -33,6 +33,7 @@ if __name__ == "__main__":
Main(args, unknownargs)
Gtk.main()
except Exception as e:
+ print(repr(e))
event_system.keep_ipc_alive = False
if debug:
traceback.print_exc()
diff --git a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/resources/Main_Window.glade b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/resources/Main_Window.glade
index b6b5cb7..8b701ce 100644
--- a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/resources/Main_Window.glade
+++ b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/resources/Main_Window.glade
@@ -383,6 +383,75 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
+
+
@@ -1269,6 +1347,7 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
False
mouse
splashscreen
+ True
False
False
static
@@ -1321,7 +1400,7 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
False
True
- 3
+ 4
@@ -1341,6 +1420,22 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
0
+
+
+
+ False
+ True
+ 1
+
+
@@ -1375,7 +1470,7 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
False
True
end
- 2
+ 3
@@ -1393,7 +1488,7 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
False
True
- 3
+ 4
@@ -1411,7 +1506,7 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
False
True
- 4
+ 5
@@ -1429,7 +1524,7 @@ PyFM is developed on Atom, git, and using Python 3+ with Gtk GObject introspecti
False
True
- 5
+ 6
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 e5f4797..1073681 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
@@ -13,7 +13,7 @@ class FileHandler:
return True
except Exception as e:
print("An error occured renaming the file:")
- print(e)
+ print(repr(e))
return False
def delete_file(self, toDeleteFile):
@@ -32,7 +32,7 @@ class FileHandler:
return False
except Exception as e:
print("An error occured deleting the file:")
- print(e)
+ print(repr(e))
return False
return True
@@ -50,16 +50,22 @@ class FileHandler:
return False
except Exception as e:
print("An error occured moving the file:")
- print(e)
+ print(repr(e))
return False
return True
- def copy_file(self):
- pass
+ def copy_file(self,fFile, tFile, symlinks=False, ignore=None):
+ try:
+ if os.path.isdir(fFile):
+ shutil.copytree(fFile, tFile, symlinks, ignore)
+ else:
+ shutil.copy2(fFile, tFile)
+ except Exception as e:
+ print("An error occured copying the file:")
+ print(repr(e))
+ return False
- def cut_file(self):
- pass
def paste_file(self):
pass
diff --git a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/Signals.py b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/Signals.py
index 5b50f13..95707ff 100644
--- a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/Signals.py
+++ b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/Signals.py
@@ -222,24 +222,42 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
def hide_about_page(self, widget=None, eve=None):
about_page = self.builder.get_object("about_page").hide()
+
+ def show_appchooser_menu(self, widget=None, eve=None):
+ appchooser_menu = self.builder.get_object("appchooser_menu")
+ appchooser_widget = self.builder.get_object("appchooser_widget")
+
+ resp = appchooser_menu.run()
+ if resp == Gtk.ResponseType.CANCEL:
+ self.hide_appchooser_menu()
+ if resp == Gtk.ResponseType.OK:
+ self.open_with_files(appchooser_widget)
+ self.hide_appchooser_menu()
+
+ def hide_appchooser_menu(self, widget=None, eve=None):
+ self.builder.get_object("appchooser_menu").hide()
+
+ def run_appchooser_launch(self, widget=None, eve=None):
+ self.builder.get_object("appchooser_select_btn").pressed()
+
def show_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").run()
def hide_context_menu(self, widget=None, eve=None):
self.builder.get_object("context_menu").hide()
- def show_edit_file_menu(self, widget=None, eve=None):
- self.builder.get_object("edit_file_menu").run()
-
- def hide_edit_file_menu(self, widget=None, eve=None):
- self.builder.get_object("edit_file_menu").hide()
-
def show_new_file_menu(self, widget=None, eve=None):
self.builder.get_object("new_file_menu").run()
def hide_new_file_menu(self, widget=None, eve=None):
self.builder.get_object("new_file_menu").hide()
+ def show_edit_file_menu(self, widget=None, eve=None):
+ self.builder.get_object("edit_file_menu").run()
+
+ def hide_edit_file_menu(self, widget=None, eve=None):
+ self.builder.get_object("edit_file_menu").hide()
+
def hide_edit_file_menu_skip(self, widget=None, eve=None):
self.skip_edit = True
self.builder.get_object("edit_file_menu").hide()
diff --git a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/TabMixin.py b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/TabMixin.py
index 9ca7452..3359d43 100644
--- a/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/TabMixin.py
+++ b/src/versions/pyfm-0.0.1/PyFM/new/pyfm/signal_classes/mixins/TabMixin.py
@@ -62,8 +62,8 @@ class TabMixin(WidgetMixin):
page = notebook.page_num(scroll)
view = self.get_fm_window(wid).get_view_by_id(tid)
watcher = view.get_dir_watcher()
- watcher.cancel()
+ watcher.cancel()
self.get_fm_window(wid).delete_view_by_id(tid)
notebook.remove_page(page)
self.window_controller.save_state()
@@ -76,8 +76,8 @@ class TabMixin(WidgetMixin):
for i, view in enumerate(window.views):
if view.id == tid:
- _view = window.get_view_by_id(tid)
- watcher = _view.get_dir_watcher()
+ _view = window.get_view_by_id(tid)
+ watcher = _view.get_dir_watcher()
watcher.cancel()
window.views.insert(new_index, window.views.pop(i))
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 db15ec0..e7fe8c4 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
@@ -74,6 +74,17 @@ class WidgetFileActionMixin:
for file in uris:
view.open_file_locally(file)
+ def open_with_files(self, appchooser_widget):
+ wid, tid = self.window_controller.get_active_data()
+ view = self.get_fm_window(wid).get_view_by_id(tid)
+ iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
+ store = iconview.get_model()
+ uris = self.format_to_uris(store, wid, tid, self.selected_files)
+
+ f = Gio.File.new_for_uri(uris[0])
+ app_info = appchooser_widget.get_app_info()
+ app_info.launch([f], None)
+
def edit_files(self):
pass
@@ -84,9 +95,9 @@ class WidgetFileActionMixin:
view = self.get_fm_window(wid).get_view_by_id(tid)
iconview = self.builder.get_object(f"{wid}|{tid}|iconview")
store = iconview.get_model()
- uris = self.format_to_uris(store, wid, tid, self.to_rename_files, True)
+ uris = self.format_to_uris(store, wid, tid, self.to_rename_files)
- # The rename button hides the rename dialog box which lets this loop continue.
+ # The rename button hides the rename dialog box which lets the loop continue.
# Weirdly, the show at the end is needed to flow through all the list properly
# than auto chosing the first rename entry you do.
for uri in uris:
@@ -97,6 +108,7 @@ class WidgetFileActionMixin:
self.skip_edit = False
self.show_edit_file_menu()
+ # Yes...this step is required even with the above... =/
self.show_edit_file_menu()
if self.skip_edit:
@@ -106,7 +118,7 @@ class WidgetFileActionMixin:
rname_to = rename_input.get_text().strip()
target = f"file://{view.get_current_directory()}/{rname_to}"
- self.handle_file([f"file://{uri}"], "edit", target)
+ self.handle_file([uri], "edit", target)
self.show_edit_file_menu()
@@ -190,8 +202,8 @@ class WidgetFileActionMixin:
if _target_path:
if os.path.isdir(_target_path):
info = f.query_info("standard::display-name", 0, cancellable=None)
- _target = f"file://{base_dir}/{info.get_display_name()}"
- target = Gio.File.new_for_uri(_target_path)
+ _target = f"file://{_target_path}/{info.get_display_name()}"
+ target = Gio.File.new_for_uri(_target)
else:
target = Gio.File.new_for_uri(_target_path)
@@ -200,14 +212,36 @@ class WidgetFileActionMixin:
(f.get_parent().get_path() == target.get_parent().get_path()):
break
- if action == "delete":
- f.delete(cancellable=None)
- if action == "trash":
- f.trash(cancellable=None)
- if action == "copy":
- f.copy(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
- if action == "move" or action == "edit":
- f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
+ type = f.query_file_type(flags=Gio.FileQueryInfoFlags.NONE, cancellable=None)
+ if not type == Gio.FileType.DIRECTORY:
+ if action == "delete":
+ f.delete(cancellable=None)
+ if action == "trash":
+ f.trash(cancellable=None)
+ if action == "copy":
+ f.copy(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
+ if action == "move" or action == "edit":
+ f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
+ else:
+ 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
+
+ if target:
+ tPath = target.get_path()
+
+ if action == "delete":
+ 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)
+ if action == "move" or action == "edit":
+ view.move_file(fPath, tPath)
+ # f.move(target, flags=Gio.FileCopyFlags.BACKUP, cancellable=None)
+
except GObject.GError as e:
raise OSError(e.message)