Commit af83d340 authored by Sébastien Wilmet's avatar Sébastien Wilmet
Browse files

Implement TeplAbstractFactoryVala subclass

To create the main window.
parent da7c4299
......@@ -36,6 +36,7 @@ vala_files = \
document_view.vala \
encodings.vala \
error_entry.vala \
factory.vala \
file_browser.vala \
finance.vala \
latexila_app.vala \
......
/*
* 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);
}
}
}
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment