Added initial save/load logic
This commit is contained in:
parent
ca855712b1
commit
7534bf141e
@ -72,6 +72,34 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
||||
self.plugins.set_message_on_plugin(type, data)
|
||||
|
||||
|
||||
def save_load_session(self, action="save_session"):
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
view = self.get_fm_window(wid).get_view_by_id(tid)
|
||||
save_load_dialog = self.builder.get_object("save_load_dialog")
|
||||
save_load_dialog.set_current_folder(view.get_current_directory())
|
||||
save_load_dialog.set_current_name("session.json")
|
||||
|
||||
if action == "save_session":
|
||||
save_load_dialog.set_action(Gtk.FileChooserAction.SAVE)
|
||||
elif action == "load_session":
|
||||
save_load_dialog.set_action(Gtk.FileChooserAction.OPEN)
|
||||
|
||||
|
||||
response = save_load_dialog.run()
|
||||
if response == Gtk.ResponseType.OK:
|
||||
path = f"{save_load_dialog.get_current_folder()}/{save_load_dialog.get_current_name()}"
|
||||
|
||||
if action == "save_session":
|
||||
self.window_controller.save_state(path)
|
||||
elif action == "load_session":
|
||||
session_json = self.window_controller.load_state(path)
|
||||
print(session_json)
|
||||
if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT):
|
||||
pass
|
||||
|
||||
save_load_dialog.hide()
|
||||
|
||||
|
||||
def do_action_from_menu_controls(self, widget, eventbutton):
|
||||
action = widget.get_name()
|
||||
self.ctrlDown = True
|
||||
@ -104,7 +132,7 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
||||
if action == "trash":
|
||||
self.trash_files()
|
||||
if action == "go_to_trash":
|
||||
self.builder.get_object("path_entry").set_text(self.trash_files_path)
|
||||
self.path_entry.set_text(self.trash_files_path)
|
||||
if action == "restore_from_trash":
|
||||
self.restore_trash_files()
|
||||
if action == "empty_trash":
|
||||
@ -112,5 +140,7 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
||||
|
||||
if action == "create":
|
||||
self.create_files()
|
||||
if action in ["save_session", "load_session"]:
|
||||
self.save_load_session(action)
|
||||
|
||||
self.ctrlDown = False
|
||||
|
@ -36,13 +36,14 @@ class Controller_Data:
|
||||
self.message_buffer = self.builder.get_object("message_buffer")
|
||||
self.arc_command_buffer = self.builder.get_object("arc_command_buffer")
|
||||
|
||||
self.exists_file_rename_bttn = self.builder.get_object("exists_file_rename_bttn")
|
||||
self.warning_alert = self.builder.get_object("warning_alert")
|
||||
self.edit_file_menu = self.builder.get_object("edit_file_menu")
|
||||
self.file_exists_dialog = self.builder.get_object("file_exists_dialog")
|
||||
self.exists_file_label = self.builder.get_object("exists_file_label")
|
||||
self.exists_file_field = self.builder.get_object("exists_file_field")
|
||||
self.path_menu = self.builder.get_object("path_menu")
|
||||
self.exists_file_rename_bttn = self.builder.get_object("exists_file_rename_bttn")
|
||||
self.path_entry = self.builder.get_object("path_entry")
|
||||
|
||||
self.bottom_size_label = self.builder.get_object("bottom_size_label")
|
||||
self.bottom_file_count_label = self.builder.get_object("bottom_file_count_label")
|
||||
|
@ -151,7 +151,10 @@ class WindowController:
|
||||
|
||||
|
||||
|
||||
def save_state(self):
|
||||
def save_state(self, session_file = None):
|
||||
if not session_file:
|
||||
session_file = self.session_file
|
||||
|
||||
windows = []
|
||||
for window in self.windows:
|
||||
views = []
|
||||
@ -172,10 +175,13 @@ class WindowController:
|
||||
]
|
||||
)
|
||||
|
||||
with open(self.session_file, 'w') as outfile:
|
||||
with open(session_file, 'w') as outfile:
|
||||
json.dump(windows, outfile, separators=(',', ':'), indent=4)
|
||||
|
||||
def load_state(self):
|
||||
if path.isfile(self.session_file):
|
||||
with open(self.session_file) as infile:
|
||||
def load_state(self, session_file = None):
|
||||
if not session_file:
|
||||
session_file = self.session_file
|
||||
|
||||
if path.isfile(session_file):
|
||||
with open(session_file) as infile:
|
||||
return json.load(infile)
|
||||
|
Loading…
Reference in New Issue
Block a user