Bringing to latest changes #3

Merged
itdominator merged 41 commits from develop into master 2022-07-16 19:14:30 +00:00
3 changed files with 52 additions and 29 deletions
Showing only changes of commit 67c13d264a - Show all commits

View File

@ -1,5 +1,5 @@
# Python imports # Python imports
import traceback, threading, inspect, os, time import traceback, threading, inspect, os, gc, time
# Lib imports # Lib imports
import gi import gi
@ -76,30 +76,44 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
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)
save_load_dialog = self.builder.get_object("save_load_dialog") 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": if action == "save_session":
save_load_dialog.set_action(Gtk.FileChooserAction.SAVE) save_load_dialog.set_action(Gtk.FileChooserAction.SAVE)
elif action == "load_session": elif action == "load_session":
save_load_dialog.set_action(Gtk.FileChooserAction.OPEN) save_load_dialog.set_action(Gtk.FileChooserAction.OPEN)
save_load_dialog.set_current_folder(view.get_current_directory())
save_load_dialog.set_current_name("session.json")
response = save_load_dialog.run() response = save_load_dialog.run()
if response == Gtk.ResponseType.OK: if response == Gtk.ResponseType.OK:
path = f"{save_load_dialog.get_current_folder()}/{save_load_dialog.get_current_name()}"
if action == "save_session": if action == "save_session":
path = f"{save_load_dialog.get_current_folder()}/{save_load_dialog.get_current_name()}"
self.window_controller.save_state(path) self.window_controller.save_state(path)
elif action == "load_session": elif action == "load_session":
path = f"{save_load_dialog.get_file().get_path()}"
session_json = self.window_controller.load_state(path) session_json = self.window_controller.load_state(path)
print(session_json) self.load_session(session_json)
if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT): if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT):
pass pass
save_load_dialog.hide() save_load_dialog.hide()
def load_session(self, session_json):
if debug:
print(f"Session Data: {session_json}")
self.ctrlDown = False
self.shiftDown = False
self.altDown = False
for notebook in self.notebooks:
self.clear_children(notebook)
self.window_controller.unload_views_and_windows()
self.generate_windows(session_json)
gc.collect()
def do_action_from_menu_controls(self, widget, eventbutton): def do_action_from_menu_controls(self, widget, eventbutton):
action = widget.get_name() action = widget.get_name()
self.ctrlDown = True self.ctrlDown = True

View File

@ -16,9 +16,9 @@ from . import TabMixin, WidgetMixin
class WindowMixin(TabMixin): class WindowMixin(TabMixin):
"""docstring for WindowMixin""" """docstring for WindowMixin"""
def generate_windows(self, data = None): def generate_windows(self, session_json = None):
if data: if session_json:
for j, value in enumerate(data): for j, value in enumerate(session_json):
i = j + 1 i = j + 1
isHidden = True if value[0]["window"]["isHidden"] == "True" else False isHidden = True if value[0]["window"]["isHidden"] == "True" else False
object = self.builder.get_object(f"tggl_notebook_{i}") object = self.builder.get_object(f"tggl_notebook_{i}")

View File

@ -151,32 +151,41 @@ class WindowController:
def unload_views_and_windows(self):
for window in self.windows:
window.views.clear()
self.windows.clear()
def save_state(self, session_file = None): def save_state(self, session_file = None):
if not session_file: if not session_file:
session_file = self.session_file session_file = self.session_file
windows = [] if len(self.windows) > 0:
for window in self.windows: windows = []
views = [] for window in self.windows:
for view in window.views: views = []
views.append(view.get_current_directory()) for view in window.views:
views.append(view.get_current_directory())
windows.append( windows.append(
[ [
{ {
'window':{ 'window':{
"ID": window.id, "ID": window.id,
"Name": window.name, "Name": window.name,
"Nickname": window.nickname, "Nickname": window.nickname,
"isHidden": f"{window.isHidden}", "isHidden": f"{window.isHidden}",
'views': views 'views': views
}
} }
} ]
] )
)
with open(session_file, 'w') as outfile: with open(session_file, 'w') as outfile:
json.dump(windows, outfile, separators=(',', ':'), indent=4) json.dump(windows, outfile, separators=(',', ':'), indent=4)
else:
raise Exception("Window dara corrupted! Can not save session!")
def load_state(self, session_file = None): def load_state(self, session_file = None):
if not session_file: if not session_file: