[gedit-plugins/sessionsaver] Split files
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins/sessionsaver] Split files
- Date: Mon, 1 Jul 2019 08:33:30 +0000 (UTC)
commit 1a0bc20b30ea85223b46f020c879fd9f41f3e1da
Author: Jordi Mas <jmas softcatala org>
Date: Mon Jul 1 10:33:10 2019 +0200
Split files
plugins/sessionsaver/sessionsaver/__init__.py | 149 +--------------------
plugins/sessionsaver/sessionsaver/appactivable.py | 75 +++++++++++
.../sessionsaver/sessionsaver/windowactivable.py | 122 +++++++++++++++++
3 files changed, 199 insertions(+), 147 deletions(-)
---
diff --git a/plugins/sessionsaver/sessionsaver/__init__.py b/plugins/sessionsaver/sessionsaver/__init__.py
index 8b00c0b..8cbcd77 100644
--- a/plugins/sessionsaver/sessionsaver/__init__.py
+++ b/plugins/sessionsaver/sessionsaver/__init__.py
@@ -17,150 +17,5 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
-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 .store import XMLSessionStore
-
-try:
- import gettext
- gettext.bindtextdomain('gedit-plugins')
- gettext.textdomain('gedit-plugins')
- _ = gettext.gettext
-except:
- _ = lambda s: s
-
-
-
-class SessionSaverAppActivatable(GObject.Object, Gedit.AppActivatable):
-
- app = GObject.Property(type=Gedit.App)
- __instance = None
-
- def __init__(self):
- GObject.Object.__init__(self)
- SessionSaverAppActivatable.__instance = self
- print("SessionSaverAppActivatable.__init__\n")
-
- @classmethod
- def get_instance(cls):
- return cls.__instance
-
- def do_activate(self):
- self._insert_session_menu()
-
- def do_deactivate(self):
- self.menu_ext = None
-
- def _insert_session_menu(self):
- print("SessionSaverAppActivatable._insert_session_menu\n")
-
- self.menu_ext = self.extend_menu("tools-section")
-
- item = Gio.MenuItem.new(_("_Manage saved sessions..."), "win.managedsession")
- self.menu_ext.append_menu_item(item)
-
- item = Gio.MenuItem.new(_("_Save session..."), "win.savesession")
- self.menu_ext.append_menu_item(item)
-
- self.sessions = XMLSessionStore()
- for i, session in enumerate(self.sessions):
- session_id = 'win.session_{0}'.format(i)
- item = Gio.MenuItem.new(_("Recover '{0}' session").format(session.name), session_id)
- self.menu_ext.append_menu_item(item)
-
- def _remove_session_menu(self):
- self.menu_ext.remove_items()
-
- def update_session_menu(self):
- self._remove_session_menu()
- self._insert_session_menu()
-
-
-class SessionSaverWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable):
-
- __gtype_name__ = "SessionSaverWindowActivatable"
- window = GObject.Property(type=Gedit.Window)
-
- def __init__(self):
- GObject.Object.__init__(self)
- print("SessionSaverWindowActivatable.__init__\n")
- self.n_sessions = 0
- self.sessions = XMLSessionStore()
-
- def do_activate(self):
- self._insert_menus()
-
- def _insert_menus(self):
- print("SessionSaverWindowActivatable._insert_menus")
- action = Gio.SimpleAction(name="managedsession")
- action.connect('activate', lambda a, p: self._on_manage_sessions_action())
- self.window.add_action(action)
-
- action = Gio.SimpleAction(name="savesession")
- action.connect('activate', lambda a, p: self._on_save_session_action())
- self.window.add_action(action)
-
- self.sessions = XMLSessionStore()
- n_sessions = len(self.sessions)
- for i, session in enumerate(self.sessions):
- session_id = 'session_{0}'.format(i)
- action = Gio.SimpleAction(name=session_id)
- action.connect('activate', self._session_menu_action, session)
- self.window.add_action(action)
-
- def _remove_menus(self):
- print("SessionSaverWindowActivatable._remove_menus")
- self.window.remove_action("managedsession")
- self.window.remove_action("savesession")
-
- for i in range(self.n_sessions):
- session_id = 'session_{0}'.format(i)
- print("SessionSaverWindowActivatable._remove_session_menu. remove {0}".format(session_id))
- self.window.remove_action(session_id)
-
- def _session_menu_action(self, action, parameter, session):
- print("SessionSaverWindowActivatable._session_menu_action {0}".format(session.name))
- self._load_session(session)
-
- def do_deactivate(self):
- self._remove_menus()
- return
-
- def do_update_state(self):
- return
-
- def _on_manage_sessions_action(self):
- print("on_manage_sessions_action\n")
- 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_updated_sessions, self.sessions, data_dir)
- dialog.run()
-
- def on_updated_sessions(self):
- print("on_updated_sessions")
- SessionSaverAppActivatable.get_instance().update_session_menu()
- self._insert_menus()
-
- 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
-
- Gedit.commands_load_locations(window, session.files, None, 0, 0)
+from .appactivable import SessionSaverAppActivatable
+from .windowactivable import SessionSaverWindowActivatable
diff --git a/plugins/sessionsaver/sessionsaver/appactivable.py
b/plugins/sessionsaver/sessionsaver/appactivable.py
new file mode 100644
index 0000000..06ec671
--- /dev/null
+++ b/plugins/sessionsaver/sessionsaver/appactivable.py
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+#
+# Copyrignt (C) 2019 Jordi Mas <jmas softcatala org>
+#
+# 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.
+#
+# 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 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, Gio, Gedit
+from .store import XMLSessionStore
+
+try:
+ import gettext
+ gettext.bindtextdomain('gedit-plugins')
+ gettext.textdomain('gedit-plugins')
+ _ = gettext.gettext
+except:
+ _ = lambda s: s
+
+
+
+class SessionSaverAppActivatable(GObject.Object, Gedit.AppActivatable):
+
+ app = GObject.Property(type=Gedit.App)
+ __instance = None
+
+ def __init__(self):
+ GObject.Object.__init__(self)
+ SessionSaverAppActivatable.__instance = self
+ print("SessionSaverAppActivatable.__init__\n")
+
+ @classmethod
+ def get_instance(cls):
+ return cls.__instance
+
+ def do_activate(self):
+ self._insert_session_menu()
+
+ def do_deactivate(self):
+ self.menu_ext = None
+
+ def _insert_session_menu(self):
+ print("SessionSaverAppActivatable._insert_session_menu\n")
+
+ self.menu_ext = self.extend_menu("tools-section")
+
+ item = Gio.MenuItem.new(_("_Manage saved sessions..."), "win.managedsession")
+ self.menu_ext.append_menu_item(item)
+
+ item = Gio.MenuItem.new(_("_Save session..."), "win.savesession")
+ self.menu_ext.append_menu_item(item)
+
+ self.sessions = XMLSessionStore()
+ for i, session in enumerate(self.sessions):
+ session_id = 'win.session_{0}'.format(i)
+ item = Gio.MenuItem.new(_("Recover '{0}' session").format(session.name), session_id)
+ self.menu_ext.append_menu_item(item)
+
+ def _remove_session_menu(self):
+ self.menu_ext.remove_items()
+
+ def update_session_menu(self):
+ self._remove_session_menu()
+ self._insert_session_menu()
diff --git a/plugins/sessionsaver/sessionsaver/windowactivable.py
b/plugins/sessionsaver/sessionsaver/windowactivable.py
new file mode 100644
index 0000000..e8d7ad4
--- /dev/null
+++ b/plugins/sessionsaver/sessionsaver/windowactivable.py
@@ -0,0 +1,122 @@
+# -*- coding: utf-8 -*-
+#
+# Copyrignt (C) 2019 Jordi Mas <jmas softcatala org>
+#
+# 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.
+#
+# 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+import gi
+from gi.repository import GObject, Gio, Gedit, PeasGtk
+from .dialogs import SaveSessionDialog, SessionManagerDialog
+from .store import XMLSessionStore
+from .appactivable import SessionSaverAppActivatable
+
+gi.require_version('Gtk', '3.0')
+gi.require_version('GtkSource', '4')
+gi.require_version('PeasGtk', '1.0')
+
+
+try:
+ import gettext
+ gettext.bindtextdomain('gedit-plugins')
+ gettext.textdomain('gedit-plugins')
+ _ = gettext.gettext
+except:
+ _ = lambda s: s
+
+
+class SessionSaverWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable):
+
+ __gtype_name__ = "SessionSaverWindowActivatable"
+ window = GObject.Property(type=Gedit.Window)
+
+ def __init__(self):
+ GObject.Object.__init__(self)
+ print("SessionSaverWindowActivatable.__init__\n")
+ self.sessions = XMLSessionStore()
+ self.n_sessions = 0
+
+ def do_activate(self):
+ self._insert_menus()
+
+ def _insert_menus(self):
+ print("SessionSaverWindowActivatable._insert_menus")
+ action = Gio.SimpleAction(name="managedsession")
+ action.connect('activate', lambda a, p: self._on_manage_sessions_action())
+ self.window.add_action(action)
+
+ action = Gio.SimpleAction(name="savesession")
+ action.connect('activate', lambda a, p: self._on_save_session_action())
+ self.window.add_action(action)
+
+ self.sessions = XMLSessionStore()
+ self.n_sessions = len(self.sessions)
+ for i, session in enumerate(self.sessions):
+ session_id = 'session_{0}'.format(i)
+ action = Gio.SimpleAction(name=session_id)
+ action.connect('activate', self._session_menu_action, session)
+ self.window.add_action(action)
+
+ def _remove_menus(self):
+ print("SessionSaverWindowActivatable._remove_menus")
+ self.window.remove_action("managedsession")
+ self.window.remove_action("savesession")
+
+ for i in range(self.n_sessions):
+ session_id = 'session_{0}'.format(i)
+ print("SessionSaverWindowActivatable._remove_session_menu. remove {0}".format(session_id))
+ self.window.remove_action(session_id)
+
+ def _session_menu_action(self, action, parameter, session):
+ print("SessionSaverWindowActivatable._session_menu_action {0}".format(session.name))
+ self._load_session(session)
+
+ def do_deactivate(self):
+ self._remove_menus()
+ return
+
+ def do_update_state(self):
+ return
+
+ def _on_manage_sessions_action(self):
+ print("on_manage_sessions_action\n")
+ 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_updated_sessions, self.sessions, data_dir)
+ dialog.run()
+
+ def on_updated_sessions(self):
+ print("on_updated_sessions")
+ SessionSaverAppActivatable.get_instance().update_session_menu()
+ self._insert_menus()
+
+ 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
+
+ Gedit.commands_load_locations(window, session.files, None, 0, 0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]