[gedit-plugins/sessionsaver] Session manager dlgbox



commit a9a413ed3affa735b7087a58913b5833729e8278
Author: Jordi Mas <jmas softcatala org>
Date:   Mon Jun 24 11:57:04 2019 +0200

    Session manager dlgbox

 plugins/sessionsaver/meson.build                   |  12 ++
 plugins/sessionsaver/sessionsaver/__init__.py      | 194 ++++++---------------
 plugins/sessionsaver/sessionsaver/dialogs.py       |  16 +-
 .../sessionsaver/{ => ui}/sessionsaver.ui          |   0
 4 files changed, 75 insertions(+), 147 deletions(-)
---
diff --git a/plugins/sessionsaver/meson.build b/plugins/sessionsaver/meson.build
index 3f4ef18..f73e51d 100644
--- a/plugins/sessionsaver/meson.build
+++ b/plugins/sessionsaver/meson.build
@@ -1,11 +1,23 @@
 install_subdir(
   'sessionsaver',
+  exclude_directories: ['ui'],
   install_dir: join_paths(
     pkglibdir,
     'plugins',
   )
 )
 
+install_data(
+  'sessionsaver/ui/sessionsaver.ui',
+  install_dir: join_paths(
+    pkgdatadir,
+    'plugins',
+    'sessionsaver',
+    'ui',
+  )
+)
+
+
 sessionsaver_plugin_in = configure_file(
   input: 'sessionsaver.plugin.desktop.in.in',
   output: 'sessionsaver.plugin.desktop.in',
diff --git a/plugins/sessionsaver/sessionsaver/__init__.py b/plugins/sessionsaver/sessionsaver/__init__.py
index b1f9ac5..c515709 100644
--- a/plugins/sessionsaver/sessionsaver/__init__.py
+++ b/plugins/sessionsaver/sessionsaver/__init__.py
@@ -1,169 +1,83 @@
 # -*- coding: utf-8 -*-
-# __init__.py
-# This file is part of gedit Session Saver Plugin
 #
-# Copyright (C) 2006-2007 - Steve Frécinaux <code istique net>
-# Copyright (C) 2010 - Kenny Meyer <knny myer gmail com>
+#  Copyrignt (C) 2019 Jordi Mas <jmas softcatala org>
 #
-# gedit Session Saver Plugin is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
 #
-# gedit Session Saver Plugin is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License
-# along with gedit Session Saver Plugin; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor,
-# Boston, MA  02110-1301  USA
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin Street, Fifth Floor,
+#  Boston, MA 02110-1301, USA.
 
-from gi.repository import GObject, Gtk, Gedit
-import gettext
-from .store import XMLSessionStore
+import gi
+gi.require_version('Gtk', '3.0')
+gi.require_version('GtkSource', '4')
+gi.require_version('PeasGtk', '1.0')
+
+from gi.repository import GObject, Gio, Gtk, Gedit, PeasGtk
 from .dialogs import SaveSessionDialog, SessionManagerDialog
-from .gpdefs import *
+from .store import XMLSessionStore
 
 try:
-    gettext.bindtextdomain(GETTEXT_PACKAGE, GP_LOCALEDIR)
-    _ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
+    import gettext
+    gettext.bindtextdomain('gedit-plugins')
+    gettext.textdomain('gedit-plugins')
+    _ = gettext.gettext
 except:
     _ = lambda s: s
 
-ui_string = """
-<ui>
-  <menubar name="MenuBar">
-    <menu name="FileMenu" action="File">
-      <placeholder name="FileOps_2">
-        <separator/>
-        <menu name="FileSessionMenu" action="FileSession">
-          <placeholder name="SessionPluginPlaceHolder"/>
-          <separator/>
-          <menuitem name="FileSessionSaveMenu" action="FileSessionSave"/>
-          <menuitem name="FileSessionManageMenu" action="FileSessionManage"/>
-        </menu>
-      </placeholder>
-    </menu>
-  </menubar>
-</ui>
-"""
-
-class SessionSaverPlugin(GObject.Object, Gedit.WindowActivatable):
-    __gtype_name__ = "SessionSaverPlugin"
-
-    window = GObject.property(type=Gedit.Window)
-
-    SESSION_MENU_PATH = '/MenuBar/FileMenu/FileOps_2/FileSessionMenu/SessionPluginPlaceHolder'
+class SessionSaverAppActivatable(GObject.Object, Gedit.AppActivatable):
+
+    app = GObject.Property(type=Gedit.App)
 
     def __init__(self):
         GObject.Object.__init__(self)
-        self.sessions = XMLSessionStore()
+        print("SessionSaverAppActivatable.__init__\n")
 
     def do_activate(self):
-        self._insert_menu()
+        self.menu_ext = self.extend_menu("tools-section")
+        item = Gio.MenuItem.new(_("_Manage saved sessions..."), "win.managedsession")
+        self.menu_ext.prepend_menu_item(item)
 
     def do_deactivate(self):
-        self._remove_menu()
-
-    def do_update_state(self):
-        self._action_group.get_action("FileSessionSave").set_sensitive(self.window.get_active_document() != 
None)
-
-    def _insert_menu(self):
-        ui_manager = self.window.get_ui_manager()
-
-        self._action_group = Gtk.ActionGroup("SessionSaverPluginActions")
-        self._action_group.add_actions(
-            [("FileSession", None, _("Sa_ved sessions"), None, None),
-             ("FileSessionSave", Gtk.STOCK_SAVE_AS,
-              _("_Save current session"), None,
-              _("Save the current document list as a new session"),
-              self.on_save_session_action),
-             ("FileSessionManage", None,
-              _("_Manage saved sessions..."), None,
-              _("Open the saved session manager"),
-              self.on_manage_sessions_action)
-            ])
-        ui_manager.insert_action_group(self._action_group)
-
-        self._ui_id = ui_manager.add_ui_from_string(ui_string)
-
-        self._insert_session_menu()
-
-        ui_manager.ensure_update()
-
-    def _remove_menu(self):
-        ui_manager = self.window.get_ui_manager()
-
-        self._remove_session_menu()
-
-        ui_manager.remove_ui(self._ui_id)
-        ui_manager.remove_action_group(self._action_group)
+        self.menu_ext = None
 
-        ui_manager.ensure_update()
 
-    def _insert_session_menu(self):
-        ui_manager = self.window.get_ui_manager()
+       
+class SessionSaverWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable):
 
-        self._merge_id = ui_manager.new_merge_id()
+    __gtype_name__ = "SessionSaverWindowActivatable"
+    window = GObject.Property(type=Gedit.Window)
 
-        self._session_action_group = Gtk.ActionGroup(name="SessionSaverPluginSessionActions")
-        ui_manager.insert_action_group(self._session_action_group)
-
-        for i, session in enumerate(self.sessions):
-            action_name = 'SessionSaver%X' % i
-            action = Gtk.Action(action_name,
-                                session.name,
-                                _("Recover '%s' session") % session.name,
-                                None)
-            handler = action.connect("activate", self.session_menu_action, session)
-
-            self._session_action_group.add_action(action)
-
-            ui_manager.add_ui(self._merge_id,
-                              self.SESSION_MENU_PATH,
-                              action_name,
-                              action_name,
-                              Gtk.UIManagerItemType.MENUITEM,
-                              False)
-
-    def _remove_session_menu(self):
-        ui_manager = self.window.get_ui_manager()
-
-        for action in self._session_action_group.list_actions():
-            action.disconnect_by_func(self.session_menu_action)
-
-        ui_manager.remove_ui(self._merge_id)
-        ui_manager.remove_action_group(self._session_action_group)
-
-        ui_manager.ensure_update()
-
-    def _update_session_menu(self):
-        self._remove_session_menu()
-        self._insert_session_menu()
+    def __init__(self):
+        GObject.Object.__init__(self)
+        print("SessionSaverWindowActivatable.__init__\n")
+        self.sessions = XMLSessionStore()
 
-    def _load_session(self, session):
-        # Note: a session has to stand on its own window.
-        tab = self.window.get_active_tab()
-        if tab is not None and \
-           not (tab.get_document().is_untouched() and \
-                tab.get_state() == Gedit.TabState.STATE_NORMAL):
-            # Create a new gedit window
-            window = Gedit.App.get_default().create_window(None)
-            window.show()
-        else:
-            window = self.window
+    def do_activate(self):
+        action = Gio.SimpleAction(name="managedsession")
+        action.connect('activate', lambda a, p: self.on_manage_sessions_action())
+        self.window.add_action(action)
+        return
+     
+    def do_deactivate(self):
+        return
 
-        Gedit.commands_load_locations(window, session.files, None, 0, 0)
+    def do_update_state(self):
+        return
 
-    def on_save_session_action(self, action):
-        SaveSessionDialog(self.window, self, self.sessions).run()
+    def on_manage_sessions_action(self):
+        print("on_manage_sessions_action\n")
+        dialog = SessionManagerDialog(self, self.sessions)
+        dialog.run()
 
-    def on_manage_sessions_action(self, action):
-        SessionManagerDialog(self, self.sessions).run()
 
-    def session_menu_action(self, action, session):
-        self._load_session(session)
 
-# ex:ts=4:et:
diff --git a/plugins/sessionsaver/sessionsaver/dialogs.py b/plugins/sessionsaver/sessionsaver/dialogs.py
index b45dade..ea6fd82 100644
--- a/plugins/sessionsaver/sessionsaver/dialogs.py
+++ b/plugins/sessionsaver/sessionsaver/dialogs.py
@@ -51,10 +51,10 @@ class SessionModel(Gtk.ListStore):
 class Dialog(object):
     UI_FILE = "sessionsaver.ui"
 
-    def __new__(cls):
-        if not ('_instance' in cls.__dict__) or cls._instance is None:
-            cls._instance = object.__new__(cls)
-        return cls._instance
+#    def __new__(cls):
+#        if not ('_instance' in cls.__dict__) or cls._instance is None:
+#            cls._instance = object.__new__(cls)
+#        return cls._instance
 
     def __init__(self, main_widget, datadir, parent_window = None):
         super(Dialog, self).__init__()
@@ -65,7 +65,10 @@ class Dialog(object):
 
         self.ui = Gtk.Builder()
         self.ui.set_translation_domain(GETTEXT_PACKAGE)
-        self.ui.add_from_file(os.path.join(datadir, self.UI_FILE))
+
+        self.ui.add_from_file(os.path.join(datadir, 'ui', self.UI_FILE))
+#        self._ui_path = os.path.join(datadir, 'ui', 'preferences.ui')
+#        self.ui.add_from_file(os.path.join(datadir, self.UI_FILE))
         self.dialog = self.ui.get_object(main_widget)
         self.dialog.connect('delete-event', self.on_delete_event)
 
@@ -118,8 +121,7 @@ class SaveSessionDialog(Dialog):
 
 class SessionManagerDialog(Dialog):
     def __init__(self, plugin, sessions):
-        super(SessionManagerDialog, self).__init__('session-manager-dialog',
-                                                   plugin.plugin_info.get_data_dir())
+        super(SessionManagerDialog, self).__init__('session-manager-dialog', 
plugin.plugin_info.get_data_dir())
         self.plugin = plugin
         self.sessions = sessions
 
diff --git a/plugins/sessionsaver/sessionsaver/sessionsaver.ui 
b/plugins/sessionsaver/sessionsaver/ui/sessionsaver.ui
similarity index 100%
rename from plugins/sessionsaver/sessionsaver/sessionsaver.ui
rename to plugins/sessionsaver/sessionsaver/ui/sessionsaver.ui


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