[latexila] Implement TeplAbstractFactoryVala subclass



commit af83d3408072247dd4afd9e72e23fc055ae2607c
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Nov 5 17:52:58 2017 +0100

    Implement TeplAbstractFactoryVala subclass
    
    To create the main window.

 src/Makefile.am       |    1 +
 src/factory.vala      |   65 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/latexila_app.vala |   35 ++------------------------
 src/main.vala         |    3 ++
 4 files changed, 72 insertions(+), 32 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 212316f..e6b89ab 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,6 +36,7 @@ vala_files =                          \
        document_view.vala              \
        encodings.vala                  \
        error_entry.vala                \
+       factory.vala                    \
        file_browser.vala               \
        finance.vala                    \
        latexila_app.vala               \
diff --git a/src/factory.vala b/src/factory.vala
new file mode 100644
index 0000000..e525366
--- /dev/null
+++ b/src/factory.vala
@@ -0,0 +1,65 @@
+/*
+ * This file is part of LaTeXila.
+ *
+ * Copyright © 2017 Sébastien Wilmet
+ *
+ * LaTeXila 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * LaTeXila 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 LaTeXila.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+public class Factory : Tepl.AbstractFactoryVala
+{
+    public Factory ()
+    {
+    }
+
+    public override Gtk.ApplicationWindow? create_main_window_vala (Gtk.Application gtk_app)
+    {
+        return_if_fail (gtk_app is LatexilaApp);
+        LatexilaApp app = gtk_app as LatexilaApp;
+
+        MainWindow? active_main_window = app.get_active_main_window ();
+        if (active_main_window != null)
+            active_main_window.save_state ();
+
+        bool first_window = active_main_window == null;
+
+        MainWindow new_window = new MainWindow (app);
+        if (first_window)
+            reopen_files (app);
+
+        return new_window;
+    }
+
+    private void reopen_files (LatexilaApp app)
+    {
+        GLib.Settings editor_settings =
+            new GLib.Settings ("org.gnome.latexila.preferences.editor");
+
+        if (editor_settings.get_boolean ("reopen-files"))
+        {
+            GLib.Settings window_settings =
+                new GLib.Settings ("org.gnome.latexila.state.window");
+
+            string[] uris = window_settings.get_strv ("documents");
+            File[] files = {};
+            foreach (string uri in uris)
+            {
+                if (0 < uri.length)
+                    files += File.new_for_uri (uri);
+            }
+
+            app.open_documents (files);
+        }
+    }
+}
diff --git a/src/latexila_app.vala b/src/latexila_app.vala
index d85ff81..1d47000 100644
--- a/src/latexila_app.vala
+++ b/src/latexila_app.vala
@@ -354,28 +354,6 @@ public class LatexilaApp : Gtk.Application
         }
     }
 
-    private void reopen_files ()
-    {
-        GLib.Settings editor_settings =
-            new GLib.Settings ("org.gnome.latexila.preferences.editor");
-
-        if (editor_settings.get_boolean ("reopen-files"))
-        {
-            GLib.Settings window_settings =
-                new GLib.Settings ("org.gnome.latexila.state.window");
-
-            string[] uris = window_settings.get_strv ("documents");
-            File[] files = {};
-            foreach (string uri in uris)
-            {
-                if (0 < uri.length)
-                    files += File.new_for_uri (uri);
-            }
-
-            open_documents (files);
-        }
-    }
-
     // Get all the documents currently opened.
     public Gee.List<Document> get_documents ()
     {
@@ -410,17 +388,10 @@ public class LatexilaApp : Gtk.Application
 
     public MainWindow create_window ()
     {
-        MainWindow? active_main_window = get_active_main_window ();
-        if (active_main_window != null)
-            active_main_window.save_state ();
-
-        bool first_window = active_main_window == null;
-
-        MainWindow new_window = new MainWindow (this);
-        if (first_window)
-            reopen_files ();
+        Tepl.AbstractFactoryVala factory = Tepl.AbstractFactory.get_singleton ()
+            as Tepl.AbstractFactoryVala;
 
-        return new_window;
+        return factory.create_main_window_vala (this) as MainWindow;
     }
 
     public void open_documents (File[] files)
diff --git a/src/main.vala b/src/main.vala
index ceeefb7..44f37a5 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -31,7 +31,10 @@ private void init_i18n ()
 int main (string[] argv)
 {
     init_i18n ();
+
     Tepl.init ();
+    Factory factory = new Factory ();
+    factory.set_singleton_vala ();
 
     LatexilaApp app = new LatexilaApp ();
     int status = app.run (argv);


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