Small refactor

This commit is contained in:
itdominator 2021-12-06 17:21:19 -06:00
parent aa984b6be4
commit 5c0dcd02e2
4 changed files with 59 additions and 66 deletions

View File

@ -18,8 +18,8 @@ def threaded(fn):
return wrapper
class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
WidgetFileActionMixin, PaneMixin, WindowMixin):
class Controller(WidgetFileActionMixin, PaneMixin, WindowMixin, ShowHideMixin, \
KeyboardSignalsMixin, Controller_Data):
def __init__(self, args, unknownargs, _settings):
# sys.excepthook = self.custom_except_hook
self.settings = _settings
@ -109,7 +109,12 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
self.arc_command_buffer.set_text(self.arc_commands[int(id)])
def get_current_state(self):
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()
return wid, tid, view, iconview, store
def do_action_from_menu_controls(self, widget, eventbutton):
action = widget.get_name()
@ -147,29 +152,7 @@ class Controller(Controller_Data, ShowHideMixin, KeyboardSignalsMixin, \
if action == "create":
self.create_file()
self.create_files()
self.hide_new_file_menu()
self.ctrlDown = False
def generate_windows(self, data = None):
if data:
for j, value in enumerate(data):
i = j + 1
isHidden = True if value[0]["window"]["isHidden"] == "True" else False
object = self.builder.get_object(f"tggl_notebook_{i}")
views = value[0]["window"]["views"]
self.window_controller.create_window()
object.set_active(True)
for view in views:
self.create_new_view_notebook(None, i, view)
if isHidden:
self.toggle_notebook_pane(object)
else:
for j in range(0, 4):
i = j + 1
self.window_controller.create_window()
self.create_new_view_notebook(None, i, None)

View File

@ -106,15 +106,21 @@ class TabMixin(WidgetMixin):
return notebook.get_children()[1].get_children()[0]
def refresh_tab(data=None):
self, ids = data
wid, tid = ids.split("|")
notebook = self.builder.get_object(f"window_{wid}")
store, tab_label = self.get_store_and_label_from_notebook(notebook, f"{wid}|{tid}")
view = self.get_fm_window(wid).get_view_by_id(tid)
wid, tid, view, iconview, store = self.get_current_state()
view.load_directory()
self.load_store(view, store)
def update_view(self, tab_label, view, store, wid, tid):
self.load_store(view, store)
self.set_path_text(wid, tid)
char_width = len(view.get_end_of_path())
tab_label.set_width_chars(char_width)
tab_label.set_label(view.get_end_of_path())
self.set_window_title()
self.set_file_watcher(view)
self.window_controller.save_state()
def do_action_from_bar_controls(self, widget, eve=None):
action = widget.get_name()
wid, tid = self.window_controller.get_active_data()
@ -143,16 +149,7 @@ class TabMixin(WidgetMixin):
if not traversed:
return
self.load_store(view, store)
self.set_path_text(wid, tid)
char_width = len(view.get_end_of_path())
tab_label.set_width_chars(char_width)
tab_label.set_label(view.get_end_of_path())
self.set_window_title()
self.set_file_watcher(view)
self.window_controller.save_state()
self.update_view(tab_label, view, store, wid, tid)
def keyboard_close_tab(self):

View File

@ -58,13 +58,6 @@ class WidgetFileActionMixin:
tab_label.set_label(view.get_end_of_path())
self.set_bottom_labels(view)
def get_current_state(self):
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()
return wid, tid, view, iconview, store
@ -132,7 +125,7 @@ class WidgetFileActionMixin:
rname_to = rename_input.get_text().strip()
target = f"file://{view.get_current_directory()}/{rname_to}"
self.handle_file([uri], "rename", target)
self.handle_files([uri], "rename", target)
self.skip_edit = False
@ -156,9 +149,9 @@ class WidgetFileActionMixin:
target = f"file://{view.get_current_directory()}"
if len(self.to_copy_files) > 0:
self.handle_file(self.to_copy_files, "copy", target)
self.handle_files(self.to_copy_files, "copy", target)
elif len(self.to_cut_files) > 0:
self.handle_file(self.to_cut_files, "move", target)
self.handle_files(self.to_cut_files, "move", target)
def delete_files(self):
wid, tid, view, iconview, store = self.get_current_state()
@ -193,7 +186,7 @@ class WidgetFileActionMixin:
def create_file(self):
def create_files(self):
fname_field = self.builder.get_object("context_menu_fname")
file_name = fname_field.get_text().strip()
type = self.builder.get_object("context_menu_type_toggle").get_state()
@ -203,22 +196,22 @@ class WidgetFileActionMixin:
target = f"{view.get_current_directory()}"
if file_name:
path = "file://{target}/{file_name}"
path = f"file://{target}/{file_name}"
if type == True: # Create File
self.handle_file([path], "create_file")
self.handle_files([path], "create_file")
else: # Create Folder
self.handle_file([path], "create_dir")
self.handle_files([path], "create_dir")
fname_field.set_text("")
def move_files(self, files, target):
self.handle_file(files, "move", target)
self.handle_files(files, "move", target)
# NOTE: Gtk recommends using fail flow than pre check existence which is more
# race condition proof. They're right; but, they can't even delete
# directories properly. So... f**k them. I'll do it my way.
def handle_file(self, paths, action, _target_path=None):
def handle_files(self, paths, action, _target_path=None):
target = None
_file = None
response = None
@ -261,9 +254,11 @@ class WidgetFileActionMixin:
_file = self.rename_proc(_file)
if response == "overwrite" or overwrite_all:
type = _file.query_file_type(flags=Gio.FileQueryInfoFlags.NONE)
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)

View File

@ -15,6 +15,28 @@ from . import WidgetMixin
class WindowMixin(TabMixin):
"""docstring for WindowMixin"""
def generate_windows(self, data = None):
if data:
for j, value in enumerate(data):
i = j + 1
isHidden = True if value[0]["window"]["isHidden"] == "True" else False
object = self.builder.get_object(f"tggl_notebook_{i}")
views = value[0]["window"]["views"]
self.window_controller.create_window()
object.set_active(True)
for view in views:
self.create_new_view_notebook(None, i, view)
if isHidden:
self.toggle_notebook_pane(object)
else:
for j in range(0, 4):
i = j + 1
self.window_controller.create_window()
self.create_new_view_notebook(None, i, None)
def get_fm_window(self, wid):
return self.window_controller.get_window_by_nickname(f"window_{wid}")
@ -106,19 +128,15 @@ class WindowMixin(TabMixin):
tab_label = self.get_tab_label(notebook, iconview)
view = self.get_fm_window(wid).get_view_by_id(tid)
model = iconview.get_model()
store = iconview.get_model()
fileName = model[item][1]
fileName = store[item][1]
dir = view.get_current_directory()
file = f"{dir}/{fileName}"
if isdir(file):
view.set_path(file)
self.load_store(view, model)
tab_label.set_label(view.get_end_of_path())
path_entry.set_text(view.get_current_directory())
self.set_file_watcher(view)
self.set_bottom_labels(view)
self.update_view(tab_label, view, store, wid, tid)
else:
self.open_files()
except Exception as e: