[gedit-plugins/sessionsaver] Fix dlgs



commit 4bfc0c6e7f9ab5990bf089f1551de7dd3f707773
Author: Jordi Mas <jmas softcatala org>
Date:   Thu Jun 27 21:23:25 2019 +0200

    Fix dlgs

 plugins/sessionsaver/sessionsaver/__init__.py |  9 +++++----
 plugins/sessionsaver/sessionsaver/dialogs.py  | 29 ++++++++++++++++++++-------
 2 files changed, 27 insertions(+), 11 deletions(-)
---
diff --git a/plugins/sessionsaver/sessionsaver/__init__.py b/plugins/sessionsaver/sessionsaver/__init__.py
index 3a4120a..16552b0 100644
--- a/plugins/sessionsaver/sessionsaver/__init__.py
+++ b/plugins/sessionsaver/sessionsaver/__init__.py
@@ -136,17 +136,18 @@ class SessionSaverWindowActivatable(GObject.Object, Gedit.WindowActivatable, Pea
 
     def _on_manage_sessions_action(self):
         print("on_manage_sessions_action\n")
-        dialog = SessionManagerDialog(app_activable, self.sessions)
+        data_dir = SessionSaverAppActivatable.get_instance().plugin_info.get_data_dir()
+        dialog = SessionManagerDialog(self.window, self.on_updated_sessions, self.sessions, data_dir)
         dialog.run()
 
     def _on_save_session_action(self):
         print("on_save_session_action\n")
         data_dir = SessionSaverAppActivatable.get_instance().plugin_info.get_data_dir()
-        dialog = SaveSessionDialog(self.window, self.on_save_session_dialog_ok, self.sessions, data_dir)
+        dialog = SaveSessionDialog(self.window, self.on_updated_sessions, self.sessions, data_dir)
         dialog.run()
 
-    def on_save_session_dialog_ok(self):
-        print("on_save_session_dialog_ok")
+    def on_updated_sessions(self):
+        print("on_updated_sessions")
         SessionSaverAppActivatable.get_instance().update_session_menu()
         self._insert_menus()
 
diff --git a/plugins/sessionsaver/sessionsaver/dialogs.py b/plugins/sessionsaver/sessionsaver/dialogs.py
index 1d3d8fa..aa14035 100644
--- a/plugins/sessionsaver/sessionsaver/dialogs.py
+++ b/plugins/sessionsaver/sessionsaver/dialogs.py
@@ -114,14 +114,18 @@ class SaveSessionDialog(Dialog):
             name = self['session-name'].get_child().get_text()
             self.sessions.add(Session(name, files))
             self.sessions.save()
-            self.on_ok()
+            self.on_updated_sessions()
         self.destroy()
 
 class SessionManagerDialog(Dialog):
-    def __init__(self, plugin, sessions):
-        super(SessionManagerDialog, self).__init__('session-manager-dialog', 
plugin.plugin_info.get_data_dir())
-        self.plugin = plugin
+    def __init__(self, window, on_updated_sessions, sessions, data_dir):
+        super(SessionManagerDialog, self).__init__('session-manager-dialog',
+                                                data_dir,
+                                                window)
+
+        self.on_updated_sessions = on_updated_sessions
         self.sessions = sessions
+        self.sessions_updated = False
 
         model = SessionModel(sessions)
 
@@ -141,7 +145,7 @@ class SessionManagerDialog(Dialog):
 
     def on_delete_event(self, dialog, event):
         dialog.hide()
-        self.sessions.save()
+        self._should_save_sessions()
         return True
 
     def get_current_session(self):
@@ -158,10 +162,21 @@ class SessionManagerDialog(Dialog):
     def on_delete_button_clicked(self, button):
         session = self.get_current_session()
         self.sessions.remove(session)
-        self.plugin._update_session_menu()
+        self.sessions_updated = True
+        self._should_save_sessions()
+
+    def _should_save_sessions(self):
+        if self.sessions_updated == False:
+            return
 
-    def on_close_button_clicked(self, button):
         self.sessions.save()
+        self.on_updated_sessions()
+        self.sessions_updated = False
+        print(" _should_save_sessions saved")
+
+    def on_close_button_clicked(self, button):
+        self._should_save_sessions()
         self.destroy()
 
+
 # ex:ts=4:et:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]