[latexila/wip/latexila-next: 34/56] Use the build tools written in C



commit f0d31034293b29a9f3d46159b89430bf0b43e1c7
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed May 7 13:45:27 2014 +0200

    Use the build tools written in C
    
    The build tools in C are far from finished, but it's better to use them
    as soon as possible, so it will be better tested.
    
    This commit also renames Latexila -> LatexilaApp (in Vala), because
    there is a conflict with the Latexila namespace used by the liblatexila.

 configure.ac                                   |    2 +-
 docs/reference/latexila-sections.txt           |    4 +
 src/Makefile.am                                |   26 +-
 src/app_settings.vala                          |   18 +-
 src/bottom_panel.vala                          |    2 +-
 src/build_command_runner.vala                  |  170 -----
 src/build_job_runner.vala                      |  191 ------
 src/build_tool_dialog.vala                     |   58 +-
 src/build_tool_runner.vala                     |  312 ---------
 src/build_tools.vala                           |  560 ----------------
 src/build_tools_preferences.vala               |   41 +-
 src/build_view.vala                            |  396 -----------
 src/completion.vala                            |    2 +-
 src/document.vala                              |    2 +-
 src/latex_post_processor.vala                  |  830 ------------------------
 src/{latexila.vala => latexila_app.vala}       |   10 +-
 src/liblatexila/latexila-build-job.c           |   19 +
 src/liblatexila/latexila-build-job.h           |    2 +
 src/liblatexila/latexila-build-tool.c          |   38 ++
 src/liblatexila/latexila-build-tool.h          |    2 +
 src/liblatexila/latexila-build-tools-default.c |    2 +-
 src/liblatexila/latexila-build-tools.c         |   21 +
 src/liblatexila/latexila-build-tools.h         |    7 +-
 src/liblatexila/latexila-post-processor.h      |    4 +-
 src/main.vala                                  |    4 +-
 src/main_window.vala                           |    6 +-
 src/main_window_build_tools.vala               |   68 ++-
 src/main_window_documents.vala                 |    2 +-
 src/main_window_file.vala                      |    2 +-
 src/post_processors.vala                       |  253 -------
 src/projects.vala                              |   10 +-
 src/synctex.vala                               |    4 +-
 32 files changed, 235 insertions(+), 2833 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 71b3fa9..07a1342 100644
--- a/configure.ac
+++ b/configure.ac
@@ -10,7 +10,7 @@ AC_INIT([LaTeXila],
        [latexila],
        [https://wiki.gnome.org/Apps/LaTeXila])
 
-AC_CONFIG_SRCDIR([src/latexila.vala])
+AC_CONFIG_SRCDIR([src/liblatexila/latexila.h])
 AC_CONFIG_HEADERS([config.h])
 AC_CONFIG_MACRO_DIR([m4])
 
diff --git a/docs/reference/latexila-sections.txt b/docs/reference/latexila-sections.txt
index e8e291c..85eae96 100644
--- a/docs/reference/latexila-sections.txt
+++ b/docs/reference/latexila-sections.txt
@@ -6,6 +6,7 @@
 LatexilaBuildTools
 latexila_build_tools_load
 latexila_build_tools_set_enabled
+latexila_build_tools_nth
 <SUBSECTION Standard>
 LATEXILA_BUILD_TOOLS
 LATEXILA_BUILD_TOOLS_CLASS
@@ -61,10 +62,12 @@ LatexilaBuildToolsPersonalPrivate
 <TITLE>LatexilaBuildTool</TITLE>
 LatexilaBuildTool
 latexila_build_tool_new
+latexila_build_tool_clone
 latexila_build_tool_add_job
 latexila_build_tool_get_jobs
 latexila_build_tool_get_description
 latexila_build_tool_to_xml
+latexila_build_tool_run
 <SUBSECTION Standard>
 LATEXILA_BUILD_TOOL
 LATEXILA_BUILD_TOOL_CLASS
@@ -82,6 +85,7 @@ latexila_build_tool_get_type
 <TITLE>LatexilaBuildJob</TITLE>
 LatexilaBuildJob
 latexila_build_job_new
+latexila_build_job_clone
 latexila_build_job_to_xml
 <SUBSECTION Standard>
 LATEXILA_BUILD_JOB
diff --git a/src/Makefile.am b/src/Makefile.am
index b36511f..508fd87 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,13 +17,8 @@ vapidir = ../vapi
 vala_files =                           \
        app_settings.vala               \
        bottom_panel.vala               \
-       build_command_runner.vala       \
-       build_job_runner.vala           \
        build_tool_dialog.vala          \
-       build_tool_runner.vala          \
        build_tools_preferences.vala    \
-       build_tools.vala                \
-       build_view.vala                 \
        clean_build_files.vala          \
        completion.vala                 \
        custom_statusbar.vala           \
@@ -36,9 +31,8 @@ vala_files =                          \
        encodings.vala                  \
        error_entry.vala                \
        file_browser.vala               \
-       latexila.vala                   \
+       latexila_app.vala               \
        latex_menu.vala                 \
-       latex_post_processor.vala       \
        main.vala                       \
        main_window_build_tools.vala    \
        main_window_documents.vala      \
@@ -48,7 +42,6 @@ vala_files =                          \
        main_window.vala                \
        menu_in_toolbar.vala            \
        most_used_symbols.vala          \
-       post_processors.vala            \
        preferences_dialog.vala         \
        project_dialogs.vala            \
        projects.vala                   \
@@ -65,19 +58,22 @@ vala_files =                                \
        templates.vala                  \
        utils.vala
 
-latexila_SOURCES =                     \
-       $(vala_files)                   \
-       $(vapidir)/config.vapi          \
-       $(vapidir)/gedit.vapi           \
-       $(vapidir)/menu_tool_action.vapi
+latexila_SOURCES =                             \
+       $(vala_files)                           \
+       $(vapidir)/config.vapi                  \
+       $(vapidir)/gedit.vapi                   \
+       $(vapidir)/menu_tool_action.vapi        \
+       liblatexila/latexila.vapi
 
 latexila_CPPFLAGS =            \
        -I$(top_srcdir)         \
        -I$(srcdir)/gedit       \
+       -I$(srcdir)/liblatexila \
        -include config.h
 
-latexila_LDADD =               \
-       gedit/libgedit.la
+latexila_LDADD =                       \
+       gedit/libgedit.la               \
+       liblatexila/liblatexila.la
 
 MAINTAINERCLEANFILES =         \
        $(vala_files:.vala=.c)  \
diff --git a/src/app_settings.vala b/src/app_settings.vala
index b3e00ff..b519238 100644
--- a/src/app_settings.vala
+++ b/src/app_settings.vala
@@ -76,7 +76,7 @@ public class AppSettings : GLib.Settings
                 Gtk.SourceStyleSchemeManager.get_default ();
             Gtk.SourceStyleScheme scheme = manager.get_scheme (scheme_id);
 
-            foreach (Document doc in Latexila.get_instance ().get_documents ())
+            foreach (Document doc in LatexilaApp.get_instance ().get_documents ())
                 doc.style_scheme = scheme;
 
             // we don't use doc.set_style_scheme_from_string() for performance reason
@@ -87,7 +87,7 @@ public class AppSettings : GLib.Settings
             uint val;
             setting.get (key, "u", out val);
 
-            foreach (DocumentView view in Latexila.get_instance ().get_views ())
+            foreach (DocumentView view in LatexilaApp.get_instance ().get_views ())
                 view.tab_width = val;
         });
 
@@ -95,7 +95,7 @@ public class AppSettings : GLib.Settings
         {
             bool val = setting.get_boolean (key);
 
-            foreach (DocumentView view in Latexila.get_instance ().get_views ())
+            foreach (DocumentView view in LatexilaApp.get_instance ().get_views ())
                 view.insert_spaces_instead_of_tabs = val;
         });
 
@@ -103,7 +103,7 @@ public class AppSettings : GLib.Settings
         {
             bool val = setting.get_boolean (key);
 
-            foreach (DocumentView view in Latexila.get_instance ().get_views ())
+            foreach (DocumentView view in LatexilaApp.get_instance ().get_views ())
                 view.show_line_numbers = val;
         });
 
@@ -111,7 +111,7 @@ public class AppSettings : GLib.Settings
         {
             bool val = setting.get_boolean (key);
 
-            foreach (DocumentView view in Latexila.get_instance ().get_views ())
+            foreach (DocumentView view in LatexilaApp.get_instance ().get_views ())
                 view.highlight_current_line = val;
         });
 
@@ -119,7 +119,7 @@ public class AppSettings : GLib.Settings
         {
             bool val = setting.get_boolean (key);
 
-            foreach (Document doc in Latexila.get_instance ().get_documents ())
+            foreach (Document doc in LatexilaApp.get_instance ().get_documents ())
                 doc.highlight_matching_brackets = val;
         });
 
@@ -127,7 +127,7 @@ public class AppSettings : GLib.Settings
         {
             bool val = setting.get_boolean (key);
 
-            foreach (Document doc in Latexila.get_instance ().get_documents ())
+            foreach (Document doc in LatexilaApp.get_instance ().get_documents ())
                 doc.tab.auto_save = val;
         });
 
@@ -136,14 +136,14 @@ public class AppSettings : GLib.Settings
             uint val;
             setting.get (key, "u", out val);
 
-            foreach (Document doc in Latexila.get_instance ().get_documents ())
+            foreach (Document doc in LatexilaApp.get_instance ().get_documents ())
                 doc.tab.auto_save_interval = val;
         });
     }
 
     private void set_font (string font)
     {
-        foreach (DocumentView view in Latexila.get_instance ().get_views ())
+        foreach (DocumentView view in LatexilaApp.get_instance ().get_views ())
             view.set_font_from_string (font);
     }
 }
diff --git a/src/bottom_panel.vala b/src/bottom_panel.vala
index 13a5d27..c9af892 100644
--- a/src/bottom_panel.vala
+++ b/src/bottom_panel.vala
@@ -23,7 +23,7 @@ using Gtk;
 
 public class BottomPanel : Grid
 {
-    public BottomPanel (BuildView build_view, Toolbar toolbar)
+    public BottomPanel (Latexila.BuildView build_view, Toolbar toolbar)
     {
         set_orientation (Orientation.HORIZONTAL);
 
diff --git a/src/build_tool_dialog.vala b/src/build_tool_dialog.vala
index 28ebc21..3b1f6b0 100644
--- a/src/build_tool_dialog.vala
+++ b/src/build_tool_dialog.vala
@@ -1,7 +1,7 @@
 /*
  * This file is part of LaTeXila.
  *
- * Copyright © 2010-2012 Sébastien Wilmet
+ * Copyright © 2010-2012, 2014 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
@@ -89,12 +89,12 @@ public class BuildToolDialog : GLib.Object
     }
 
     // Returns true if the build tool is edited.
-    public bool open_build_tool (BuildTools build_tools, int build_tool_num)
+    public bool open_build_tool (Latexila.BuildTools build_tools, int build_tool_num)
     {
-        BuildTool? build_tool = build_tools.get_build_tool (build_tool_num);
+        Latexila.BuildTool? build_tool = build_tools.nth (build_tool_num);
         return_val_if_fail (build_tool != null, false);
 
-        if (build_tools is DefaultBuildTools)
+        if (build_tools is Latexila.BuildToolsDefault)
             set_read_only ();
         else
             set_editable ();
@@ -105,11 +105,12 @@ public class BuildToolDialog : GLib.Object
 
         if (ok)
         {
-            BuildTool new_build_tool = retrieve_build_tool ();
+            Latexila.BuildTool new_build_tool = retrieve_build_tool ();
             new_build_tool.enabled = build_tool.enabled;
 
-            PersonalBuildTools personal_build_tools = build_tools as PersonalBuildTools;
-            personal_build_tools.update (build_tool_num, new_build_tool);
+            Latexila.BuildToolsPersonal personal_build_tools =
+                build_tools as Latexila.BuildToolsPersonal;
+            personal_build_tools.replace (new_build_tool, build_tool_num);
         }
 
         _dialog.destroy ();
@@ -127,10 +128,11 @@ public class BuildToolDialog : GLib.Object
 
         if (ok)
         {
-            BuildTool new_build_tool = retrieve_build_tool ();
+            Latexila.BuildTool new_build_tool = retrieve_build_tool ();
             new_build_tool.enabled = true;
 
-            PersonalBuildTools build_tools = PersonalBuildTools.get_default ();
+            Latexila.BuildToolsPersonal build_tools =
+                Latexila.BuildToolsPersonal.get_instance ();
             build_tools.add (new_build_tool);
         }
 
@@ -207,10 +209,10 @@ public class BuildToolDialog : GLib.Object
             typeof (string) // the name of the post processor
         );
 
-        for (int type = 0 ; type < PostProcessorType.N_POST_PROCESSORS ; type++)
+        for (int type = 0 ; type < Latexila.PostProcessorType.NB_TYPES ; type++)
         {
-            string name = BuildTools.get_post_processor_name_from_type (
-                (PostProcessorType) type);
+            unowned string name = Latexila.PostProcessor.get_name_from_type (
+                (Latexila.PostProcessorType) type);
 
             TreeIter iter;
             post_processor_store.append (out iter);
@@ -266,9 +268,9 @@ public class BuildToolDialog : GLib.Object
 
         add_button.clicked.connect (() =>
         {
-            BuildJob new_job = BuildJob ();
+            Latexila.BuildJob new_job = new Latexila.BuildJob ();
             new_job.command = "";
-            new_job.post_processor = PostProcessorType.ALL_OUTPUT;
+            new_job.post_processor_type = Latexila.PostProcessorType.ALL_OUTPUT;
             add_build_job (new_job);
         });
 
@@ -426,7 +428,7 @@ public class BuildToolDialog : GLib.Object
         _jobs_view.columns_autosize ();
     }
 
-    private void set_build_tool (BuildTool build_tool)
+    private void set_build_tool (Latexila.BuildTool build_tool)
     {
         /* Text entries */
 
@@ -461,21 +463,21 @@ public class BuildToolDialog : GLib.Object
         /* Jobs */
 
         _jobs_store.clear ();
-        foreach (BuildJob build_job in build_tool.jobs)
+        foreach (Latexila.BuildJob build_job in build_tool.get_jobs ())
             add_build_job (build_job);
 
         _jobs_view.columns_autosize ();
     }
 
     // Retrieve the build tool from the data stored in the main widgets of the dialog.
-    private BuildTool retrieve_build_tool ()
+    private Latexila.BuildTool retrieve_build_tool ()
     {
-        BuildTool tool = BuildTool ();
+        Latexila.BuildTool tool = new Latexila.BuildTool ();
 
         /* Text entries */
 
         tool.label = _entry_label.text.strip ();
-        tool.set_description (_entry_desc.text.strip ());
+        tool.description = _entry_desc.text.strip ();
         tool.extensions = _entry_extensions.text.strip ();
         tool.files_to_open = _entry_files_to_open.text.strip ();
 
@@ -484,7 +486,9 @@ public class BuildToolDialog : GLib.Object
         TreeIter iter;
         _icons_combobox.get_active_iter (out iter);
         TreeModel model = _icons_store as TreeModel;
-        model.get (iter, IconColumn.STOCK_ID, out tool.icon);
+        string icon;
+        model.get (iter, IconColumn.STOCK_ID, out icon);
+        tool.icon = icon;
 
         /* Jobs */
 
@@ -493,7 +497,7 @@ public class BuildToolDialog : GLib.Object
 
         while (valid)
         {
-            BuildJob job = BuildJob ();
+            Latexila.BuildJob job = new Latexila.BuildJob ();
             string command;
             string post_processor_name;
 
@@ -503,10 +507,12 @@ public class BuildToolDialog : GLib.Object
             );
 
             job.command = command.strip ();
-            job.post_processor = BuildTools.get_post_processor_type_from_name (
-                post_processor_name);
 
-            tool.jobs.add (job);
+            Latexila.PostProcessorType type;
+            if (Latexila.PostProcessor.get_type_from_name (post_processor_name, out type))
+                job.post_processor_type = type;
+
+            tool.add_job (job);
 
             valid = _jobs_store.iter_next (ref iter);
         }
@@ -517,10 +523,10 @@ public class BuildToolDialog : GLib.Object
     /*************************************************************************/
     // Misc utilities functions
 
-    private void add_build_job (BuildJob job)
+    private void add_build_job (Latexila.BuildJob job)
     {
         string post_processor_name =
-            BuildTools.get_post_processor_name_from_type (job.post_processor);
+            Latexila.PostProcessor.get_name_from_type (job.post_processor_type);
 
         TreeIter iter;
         _jobs_store.append (out iter);
diff --git a/src/build_tools_preferences.vala b/src/build_tools_preferences.vala
index 911fc5d..528ed9d 100644
--- a/src/build_tools_preferences.vala
+++ b/src/build_tools_preferences.vala
@@ -1,7 +1,7 @@
 /*
  * This file is part of LaTeXila.
  *
- * Copyright © 2012 Sébastien Wilmet
+ * Copyright © 2012, 2014 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
@@ -72,10 +72,10 @@ public class BuildToolsPreferences : GLib.Object
     private void init_views ()
     {
         _default_view = get_new_view (_default_store,
-            DefaultBuildTools.get_default ());
+            Latexila.BuildToolsDefault.get_instance ());
 
         _personal_view = get_new_view (_personal_store,
-            PersonalBuildTools.get_default ());
+            Latexila.BuildToolsPersonal.get_instance ());
 
         // Only one item of the two views can be selected at once.
 
@@ -95,7 +95,8 @@ public class BuildToolsPreferences : GLib.Object
 
     private Grid get_default_grid ()
     {
-        BuildTools default_build_tools = DefaultBuildTools.get_default ();
+        Latexila.BuildTools default_build_tools =
+            Latexila.BuildToolsDefault.get_instance () as Latexila.BuildTools;
         ToolButton properties_button = get_properties_button (_default_view,
             default_build_tools);
         ToolButton copy_button = get_copy_button (_default_view, default_build_tools);
@@ -111,7 +112,8 @@ public class BuildToolsPreferences : GLib.Object
 
     private Grid get_personal_grid ()
     {
-        BuildTools personal_build_tools = PersonalBuildTools.get_default ();
+        Latexila.BuildTools personal_build_tools =
+            Latexila.BuildToolsPersonal.get_instance () as Latexila.BuildTools;
         ToolButton properties_button = get_properties_button (_personal_view,
             personal_build_tools);
         ToolButton copy_button = get_copy_button (_personal_view, personal_build_tools);
@@ -163,7 +165,7 @@ public class BuildToolsPreferences : GLib.Object
         );
     }
 
-    private TreeView get_new_view (ListStore store, BuildTools build_tools)
+    private TreeView get_new_view (ListStore store, Latexila.BuildTools build_tools)
     {
         TreeView view = new TreeView.with_model (store);
         view.set_rules_hint (true);
@@ -234,7 +236,8 @@ public class BuildToolsPreferences : GLib.Object
             other_select.unselect_all ();
     }
 
-    private ToolButton get_properties_button (TreeView view, BuildTools build_tools)
+    private ToolButton get_properties_button (TreeView view,
+        Latexila.BuildTools build_tools)
     {
         ToolButton properties_button = new ToolButton (null, null);
         properties_button.set_icon_name ("document-properties-symbolic");
@@ -253,7 +256,7 @@ public class BuildToolsPreferences : GLib.Object
         return properties_button;
     }
 
-    private ToolButton get_copy_button (TreeView view, BuildTools build_tools)
+    private ToolButton get_copy_button (TreeView view, Latexila.BuildTools build_tools)
     {
         ToolButton copy_button = new ToolButton (null, null);
         copy_button.set_icon_name ("edit-copy-symbolic");
@@ -267,13 +270,15 @@ public class BuildToolsPreferences : GLib.Object
             if (selected_row < 0)
                 return;
 
-            BuildTool? tool = build_tools.get_build_tool (selected_row);
+            Latexila.BuildTool? tool = build_tools.nth (selected_row);
             return_if_fail (tool != null);
 
+            tool = tool.clone ();
             tool.enabled = false;
             tool.label = _("%s [copy]").printf (tool.label);
 
-            PersonalBuildTools personal_build_tools = PersonalBuildTools.get_default ();
+            Latexila.BuildToolsPersonal personal_build_tools =
+                Latexila.BuildToolsPersonal.get_instance ();
             personal_build_tools.add (tool);
 
             update_personal_store ();
@@ -330,7 +335,7 @@ public class BuildToolsPreferences : GLib.Object
             if (dialog.run () == ResponseType.YES)
             {
                 _personal_store.remove (iter);
-                PersonalBuildTools.get_default ().delete (selected_row);
+                Latexila.BuildToolsPersonal.get_instance ().delete (selected_row);
             }
 
             dialog.destroy ();
@@ -380,7 +385,7 @@ public class BuildToolsPreferences : GLib.Object
                 if (Utils.tree_model_iter_prev (_personal_store, ref iter_up))
                 {
                     _personal_store.swap (iter_selected, iter_up);
-                    PersonalBuildTools.get_default ().move_up (selected_row);
+                    Latexila.BuildToolsPersonal.get_instance ().move_up (selected_row);
 
                     // Force the 'changed' signal on the selection to be emitted
                     select.changed ();
@@ -435,7 +440,7 @@ public class BuildToolsPreferences : GLib.Object
                 if (_personal_store.iter_next (ref iter_down))
                 {
                     _personal_store.swap (iter_selected, iter_down);
-                    PersonalBuildTools.get_default ().move_down (selected_row);
+                    Latexila.BuildToolsPersonal.get_instance ().move_down (selected_row);
 
                     // Force the 'changed' signal on the selection to be emitted
                     select.changed ();
@@ -448,19 +453,19 @@ public class BuildToolsPreferences : GLib.Object
 
     private void update_default_store ()
     {
-        update_store (_default_store, DefaultBuildTools.get_default ());
+        update_store (_default_store, Latexila.BuildToolsDefault.get_instance ());
     }
 
     private void update_personal_store ()
     {
-        update_store (_personal_store, PersonalBuildTools.get_default ());
+        update_store (_personal_store, Latexila.BuildToolsPersonal.get_instance ());
     }
 
-    private void update_store (ListStore store, BuildTools build_tools)
+    private void update_store (ListStore store, Latexila.BuildTools build_tools)
     {
         store.clear ();
 
-        foreach (BuildTool tool in build_tools)
+        foreach (Latexila.BuildTool tool in build_tools.build_tools)
         {
             string description = Markup.escape_text (tool.get_description ());
 
@@ -475,7 +480,7 @@ public class BuildToolsPreferences : GLib.Object
         }
     }
 
-    private void open_build_tool (BuildTools build_tools, int build_tool_num)
+    private void open_build_tool (Latexila.BuildTools build_tools, int build_tool_num)
     {
         BuildToolDialog dialog = new BuildToolDialog (_dialog);
 
diff --git a/src/completion.vala b/src/completion.vala
index 4902dbc..677766e 100644
--- a/src/completion.vala
+++ b/src/completion.vala
@@ -355,7 +355,7 @@ public class CompletionProvider : GLib.Object, SourceCompletionProvider
 
         _calltip_window_label.set_markup (markup);
 
-        MainWindow window = Latexila.get_instance ().active_window as MainWindow;
+        MainWindow window = LatexilaApp.get_instance ().active_window as MainWindow;
         _calltip_window.set_transient_for (window);
         _calltip_window.set_attached_to (window.active_view);
 
diff --git a/src/document.vala b/src/document.vala
index 51418cb..e91cdb1 100644
--- a/src/document.vala
+++ b/src/document.vala
@@ -305,7 +305,7 @@ public class Document : Gtk.SourceBuffer
 
         // get all unsaved document numbers
         uint[] all_nums = {};
-        foreach (Document doc in Latexila.get_instance ().get_documents ())
+        foreach (Document doc in LatexilaApp.get_instance ().get_documents ())
         {
             // avoid infinite loop
             if (doc == this)
diff --git a/src/latexila.vala b/src/latexila_app.vala
similarity index 96%
rename from src/latexila.vala
rename to src/latexila_app.vala
index 9704adc..03a138c 100644
--- a/src/latexila.vala
+++ b/src/latexila_app.vala
@@ -19,9 +19,9 @@
  * Author: Sébastien Wilmet
  */
 
-public class Latexila : Gtk.Application
+public class LatexilaApp : Gtk.Application
 {
-    public Latexila ()
+    public LatexilaApp ()
     {
         Object (application_id: "org.gnome.latexila");
         Environment.set_application_name (Config.PACKAGE_NAME);
@@ -45,7 +45,7 @@ public class Latexila : Gtk.Application
         {
             hold ();
             Projects.get_default ().save ();
-            PersonalBuildTools.get_default ().save ();
+            Latexila.BuildToolsPersonal.get_instance ().save ();
             MostUsedSymbols.get_default ().save ();
             Gtk.AccelMap.save (get_accel_filename ());
             release ();
@@ -97,9 +97,9 @@ public class Latexila : Gtk.Application
         });
     }
 
-    public static Latexila get_instance ()
+    public static LatexilaApp get_instance ()
     {
-        return GLib.Application.get_default () as Latexila;
+        return GLib.Application.get_default () as LatexilaApp;
     }
 
     private void init_primary_instance ()
diff --git a/src/liblatexila/latexila-build-job.c b/src/liblatexila/latexila-build-job.c
index bacf1f4..f6d458b 100644
--- a/src/liblatexila/latexila-build-job.c
+++ b/src/liblatexila/latexila-build-job.c
@@ -159,6 +159,25 @@ latexila_build_job_new (void)
 }
 
 /**
+ * latexila_build_job_clone:
+ * @build_job: the build job to clone.
+ *
+ * Clones a build job (deep copy).
+ *
+ * Returns: (transfer full): the cloned build job.
+ */
+LatexilaBuildJob *
+latexila_build_job_clone (LatexilaBuildJob *build_job)
+{
+  g_return_val_if_fail (LATEXILA_IS_BUILD_JOB (build_job), NULL);
+
+  return g_object_new (LATEXILA_TYPE_BUILD_JOB,
+                       "command", build_job->priv->command,
+                       "post-processor-type", build_job->priv->post_processor_type,
+                       NULL);
+}
+
+/**
  * latexila_build_job_to_xml:
  * @build_job: a #LatexilaBuildJob object.
  *
diff --git a/src/liblatexila/latexila-build-job.h b/src/liblatexila/latexila-build-job.h
index d636bc7..d09da3d 100644
--- a/src/liblatexila/latexila-build-job.h
+++ b/src/liblatexila/latexila-build-job.h
@@ -52,6 +52,8 @@ GType               latexila_build_job_get_type                   (void) G_GNUC_
 
 LatexilaBuildJob *  latexila_build_job_new                        (void);
 
+LatexilaBuildJob *  latexila_build_job_clone                      (LatexilaBuildJob *build_job);
+
 gchar *             latexila_build_job_to_xml                     (LatexilaBuildJob *build_job);
 
 G_END_DECLS
diff --git a/src/liblatexila/latexila-build-tool.c b/src/liblatexila/latexila-build-tool.c
index c9da018..b1e2e8f 100644
--- a/src/liblatexila/latexila-build-tool.c
+++ b/src/liblatexila/latexila-build-tool.c
@@ -291,6 +291,44 @@ latexila_build_tool_new (void)
 }
 
 /**
+ * latexila_build_tool_clone:
+ * @build_tool: the build tool to clone.
+ *
+ * Clones a build tool (deep copy).
+ *
+ * Returns: (transfer full): the cloned build tool.
+ */
+LatexilaBuildTool *
+latexila_build_tool_clone (LatexilaBuildTool *build_tool)
+{
+  LatexilaBuildTool *new_build_tool;
+  GList *l;
+
+  g_return_val_if_fail (LATEXILA_IS_BUILD_TOOL (build_tool), NULL);
+
+  new_build_tool = g_object_new (LATEXILA_TYPE_BUILD_TOOL,
+                                 "label", build_tool->priv->label,
+                                 "description", build_tool->priv->description,
+                                 "extensions", build_tool->priv->extensions,
+                                 "icon", build_tool->priv->icon,
+                                 "files-to-open", build_tool->priv->files_to_open,
+                                 "enabled", build_tool->priv->enabled,
+                                 "id", build_tool->priv->id,
+                                 NULL);
+
+  for (l = build_tool->priv->jobs->head; l != NULL; l = l->next)
+    {
+      LatexilaBuildJob *build_job = l->data;
+      LatexilaBuildJob *new_build_job = latexila_build_job_clone (build_job);
+
+      latexila_build_tool_add_job (new_build_tool, new_build_job);
+      g_object_unref (new_build_job);
+    }
+
+  return new_build_tool;
+}
+
+/**
  * latexila_build_tool_get_description:
  * @build_tool: a #LatexilaBuildTool.
  *
diff --git a/src/liblatexila/latexila-build-tool.h b/src/liblatexila/latexila-build-tool.h
index 62635f7..77c6443 100644
--- a/src/liblatexila/latexila-build-tool.h
+++ b/src/liblatexila/latexila-build-tool.h
@@ -51,6 +51,8 @@ GType                 latexila_build_tool_get_type                  (void) G_GNU
 
 LatexilaBuildTool *   latexila_build_tool_new                       (void);
 
+LatexilaBuildTool *   latexila_build_tool_clone                     (LatexilaBuildTool *build_tool);
+
 const gchar *         latexila_build_tool_get_description           (LatexilaBuildTool *build_tool);
 
 void                  latexila_build_tool_add_job                   (LatexilaBuildTool *build_tool,
diff --git a/src/liblatexila/latexila-build-tools-default.c b/src/liblatexila/latexila-build-tools-default.c
index f57ff8a..326bdee 100644
--- a/src/liblatexila/latexila-build-tools-default.c
+++ b/src/liblatexila/latexila-build-tools-default.c
@@ -211,7 +211,7 @@ latexila_build_tools_default_init (LatexilaBuildToolsDefault *build_tools)
                     NULL);
 
   xml_file = get_xml_file ();
-  latexila_build_tools_load (LATEXILA_BUILD_TOOLS (instance), xml_file);
+  latexila_build_tools_load (LATEXILA_BUILD_TOOLS (build_tools), xml_file);
   g_object_unref (xml_file);
 }
 
diff --git a/src/liblatexila/latexila-build-tools.c b/src/liblatexila/latexila-build-tools.c
index 3e02f20..4daa0d6 100644
--- a/src/liblatexila/latexila-build-tools.c
+++ b/src/liblatexila/latexila-build-tools.c
@@ -405,6 +405,27 @@ latexila_build_tools_load (LatexilaBuildTools *build_tools,
 }
 
 /**
+ * latexila_build_tools_nth:
+ * @build_tools: a #LatexilaBuildTools object.
+ * @tool_num: the build tool position in the list.
+ *
+ * Returns: (transfer none): the #LatexilaBuildTool located at @tool_num.
+ */
+LatexilaBuildTool *
+latexila_build_tools_nth (LatexilaBuildTools *build_tools,
+                          guint               tool_num)
+{
+  LatexilaBuildTool *build_tool;
+
+  g_return_val_if_fail (LATEXILA_IS_BUILD_TOOLS (build_tools), NULL);
+
+  build_tool = g_list_nth_data (build_tools->build_tools, tool_num);
+  g_return_val_if_fail (build_tool != NULL, NULL);
+
+  return build_tool;
+}
+
+/**
  * latexila_build_tools_set_enabled:
  * @build_tools: a #LatexilaBuildTools object.
  * @tool_num: the build tool position in the list.
diff --git a/src/liblatexila/latexila-build-tools.h b/src/liblatexila/latexila-build-tools.h
index 0a9c7be..7710556 100644
--- a/src/liblatexila/latexila-build-tools.h
+++ b/src/liblatexila/latexila-build-tools.h
@@ -37,8 +37,8 @@ typedef struct _LatexilaBuildToolsPrivate LatexilaBuildToolsPrivate;
 
 /**
  * LatexilaBuildTools:
- * @build_tools: a list of #LatexilaBuildTool's. External code should just read
- * the list, not modify it.
+ * @build_tools: (element-type LatexilaBuildTool): a list of
+ * #LatexilaBuildTool's. External code should just read the list, not modify it.
  */
 struct _LatexilaBuildTools
 {
@@ -62,6 +62,9 @@ GType                 latexila_build_tools_get_type                 (void) G_GNU
 void                  latexila_build_tools_load                     (LatexilaBuildTools *build_tools,
                                                                      GFile              *xml_file);
 
+LatexilaBuildTool *   latexila_build_tools_nth                      (LatexilaBuildTools *build_tools,
+                                                                     guint               tool_num);
+
 void                  latexila_build_tools_set_enabled              (LatexilaBuildTools *build_tools,
                                                                      guint               tool_num,
                                                                      gboolean            enabled);
diff --git a/src/liblatexila/latexila-post-processor.h b/src/liblatexila/latexila-post-processor.h
index 61049a1..51e5bab 100644
--- a/src/liblatexila/latexila-post-processor.h
+++ b/src/liblatexila/latexila-post-processor.h
@@ -42,6 +42,7 @@ typedef struct _LatexilaPostProcessorPrivate LatexilaPostProcessorPrivate;
  * @LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT: all output.
  * @LATEXILA_POST_PROCESSOR_TYPE_LATEX: for a LaTeX command.
  * @LATEXILA_POST_PROCESSOR_TYPE_LATEXMK: for the latexmk command.
+ * @LATEXILA_POST_PROCESSOR_TYPE_NB_TYPES: number of post-processor types.
  *
  * Types of post-processors.
  */
@@ -50,7 +51,8 @@ typedef enum
   LATEXILA_POST_PROCESSOR_TYPE_NO_OUTPUT,
   LATEXILA_POST_PROCESSOR_TYPE_ALL_OUTPUT,
   LATEXILA_POST_PROCESSOR_TYPE_LATEX,
-  LATEXILA_POST_PROCESSOR_TYPE_LATEXMK
+  LATEXILA_POST_PROCESSOR_TYPE_LATEXMK,
+  LATEXILA_POST_PROCESSOR_TYPE_NB_TYPES
 } LatexilaPostProcessorType;
 
 struct _LatexilaPostProcessor
diff --git a/src/main.vala b/src/main.vala
index 5ef897f..821a106 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -94,7 +94,7 @@ private CmdLineData parse_cmd_line_options (string[] args)
         string[] uris = {};
         foreach (string filename in files_list)
         {
-            // Call File.new_for_commandline_arg() here (and not in the Latexila class)
+            // Call File.new_for_commandline_arg() here (and not in the LatexilaApp class)
             // because relative path resolution needs the right current working directory,
             // which can be different for the primary instance.
             File file = File.new_for_commandline_arg (filename);
@@ -113,7 +113,7 @@ int main (string[] args)
 
     CmdLineData data = parse_cmd_line_options (args);
 
-    Latexila app = new Latexila ();
+    LatexilaApp app = new LatexilaApp ();
 
     try
     {
diff --git a/src/main_window.vala b/src/main_window.vala
index d088542..4559d39 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -470,7 +470,7 @@ public class MainWindow : Window
 
     private BottomPanel get_bottom_panel ()
     {
-        BuildView build_view = new BuildView (this);
+        Latexila.BuildView build_view = new Latexila.BuildView ();
         _main_window_build_tools.set_build_view (build_view);
 
         Toolbar build_toolbar = _ui_manager.get_widget ("/BuildToolbar") as Toolbar;
@@ -526,7 +526,7 @@ public class MainWindow : Window
         Gtk.drag_dest_add_uri_targets (this);
         drag_data_received.connect ((dc, x, y, selection_data, info, time) =>
         {
-            Latexila app = Latexila.get_instance ();
+            LatexilaApp app = LatexilaApp.get_instance ();
 
             File[] files = {};
             foreach (string uri in selection_data.get_uris ())
@@ -631,7 +631,7 @@ public class MainWindow : Window
     public DocumentTab? open_document (File location, bool jump_to = true)
     {
         /* check if the document is already opened */
-        foreach (Window window in Latexila.get_instance ().get_windows ())
+        foreach (Window window in LatexilaApp.get_instance ().get_windows ())
         {
             MainWindow w = window as MainWindow;
 
diff --git a/src/main_window_build_tools.vala b/src/main_window_build_tools.vala
index 301c83e..e675e44 100644
--- a/src/main_window_build_tools.vala
+++ b/src/main_window_build_tools.vala
@@ -1,7 +1,7 @@
 /*
  * This file is part of LaTeXila.
  *
- * Copyright © 2012 Sébastien Wilmet
+ * Copyright © 2012, 2014 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
@@ -55,13 +55,12 @@ public class MainWindowBuildTools
 
     private unowned MainWindow _main_window;
     private UIManager _ui_manager;
-    private BuildView _build_view;
+    private Latexila.BuildView _build_view;
     private BottomPanel _bottom_panel;
 
     private Gtk.ActionGroup _static_action_group;
     private Gtk.ActionGroup _dynamic_action_group;
     private uint _menu_ui_id;
-    private BuildToolRunner _build_tool_runner;
 
     public MainWindowBuildTools (MainWindow main_window, UIManager ui_manager)
     {
@@ -84,14 +83,16 @@ public class MainWindowBuildTools
         ui_manager.insert_action_group (_dynamic_action_group, 0);
         update_menu ();
 
-        PersonalBuildTools personal_build_tools = PersonalBuildTools.get_default ();
+        Latexila.BuildToolsPersonal personal_build_tools =
+            Latexila.BuildToolsPersonal.get_instance ();
         personal_build_tools.modified.connect (() => update_menu ());
 
-        DefaultBuildTools default_build_tools = DefaultBuildTools.get_default ();
+        Latexila.BuildToolsDefault default_build_tools =
+            Latexila.BuildToolsDefault.get_instance ();
         default_build_tools.modified.connect (() => update_menu ());
     }
 
-    public void set_build_view (BuildView build_view)
+    public void set_build_view (Latexila.BuildView build_view)
     {
         _build_view = build_view;
         connect_toggle_actions ();
@@ -121,16 +122,20 @@ public class MainWindowBuildTools
         clean_action.set_sensitive (is_tex);
         view_log_action.set_sensitive (is_tex);
 
+        Latexila.BuildTools build_tools =
+            Latexila.BuildToolsDefault.get_instance () as Latexila.BuildTools;
+
         int tool_num = 0;
-        foreach (BuildTool tool in DefaultBuildTools.get_default ())
+        foreach (Latexila.BuildTool tool in build_tools.build_tools)
         {
             string action_name = get_default_build_tool_name (tool_num);
             update_build_tool_sensitivity (tool, action_name);
             tool_num++;
         }
 
+        build_tools = Latexila.BuildToolsPersonal.get_instance () as Latexila.BuildTools;
         tool_num = 0;
-        foreach (BuildTool tool in PersonalBuildTools.get_default ())
+        foreach (Latexila.BuildTool tool in build_tools.build_tools)
         {
             string action_name = get_personal_build_tool_name (tool_num);
             update_build_tool_sensitivity (tool, action_name);
@@ -148,15 +153,15 @@ public class MainWindowBuildTools
         return @"PersonalBuildTool_$tool_num";
     }
 
-    private BuildTool? get_build_tool_from_name (string action_name)
+    private Latexila.BuildTool? get_build_tool_from_name (string action_name)
     {
-        BuildTools build_tools;
+        Latexila.BuildTools build_tools;
 
         if (action_name.has_prefix ("DefaultBuildTool_"))
-            build_tools = DefaultBuildTools.get_default ();
+            build_tools = Latexila.BuildToolsDefault.get_instance () as Latexila.BuildTools;
 
         else if (action_name.has_prefix ("PersonalBuildTool_"))
-            build_tools = PersonalBuildTools.get_default ();
+            build_tools = Latexila.BuildToolsPersonal.get_instance () as Latexila.BuildTools;
 
         else
             return_val_if_reached (null);
@@ -166,10 +171,11 @@ public class MainWindowBuildTools
 
         int tool_num = int.parse (name[1]);
 
-        return build_tools.get_build_tool (tool_num);
+        return build_tools.nth (tool_num);
     }
 
-    private void update_build_tool_sensitivity (BuildTool tool, string action_name)
+    private void update_build_tool_sensitivity (Latexila.BuildTool tool,
+        string action_name)
     {
         if (! tool.enabled)
             return;
@@ -181,7 +187,7 @@ public class MainWindowBuildTools
 
         if (unsaved_doc)
         {
-            action.set_sensitive (tool.has_jobs ());
+            action.set_sensitive (tool.get_jobs () != null);
             return;
         }
 
@@ -219,11 +225,14 @@ public class MainWindowBuildTools
             _dynamic_action_group.remove_action (action);
         }
 
+        Latexila.BuildTools default_build_tools =
+            Latexila.BuildToolsDefault.get_instance () as Latexila.BuildTools;
+        Latexila.BuildTools personal_build_tools =
+            Latexila.BuildToolsPersonal.get_instance () as Latexila.BuildTools;
 
-        DefaultBuildTools default_build_tools = DefaultBuildTools.get_default ();
-        PersonalBuildTools personal_build_tools = PersonalBuildTools.get_default ();
-
-        if (default_build_tools.is_empty () && personal_build_tools.is_empty ())
+        /* Empty */
+        if (default_build_tools.build_tools == null &&
+            personal_build_tools.build_tools == null)
         {
             _menu_ui_id = 0;
             return;
@@ -234,7 +243,7 @@ public class MainWindowBuildTools
         /* Add the default build tools */
         int tool_num = 0;
         int accel_num = 2;
-        foreach (BuildTool build_tool in default_build_tools)
+        foreach (Latexila.BuildTool build_tool in default_build_tools.build_tools)
         {
             string action_name = get_default_build_tool_name (tool_num);
             add_dynamic_action (build_tool, action_name, ref accel_num);
@@ -245,7 +254,7 @@ public class MainWindowBuildTools
 
         /* Add the personal build tools */
         tool_num = 0;
-        foreach (BuildTool build_tool in personal_build_tools)
+        foreach (Latexila.BuildTool build_tool in personal_build_tools.build_tools)
         {
             string action_name = get_personal_build_tool_name (tool_num);
             add_dynamic_action (build_tool, action_name, ref accel_num);
@@ -266,7 +275,7 @@ public class MainWindowBuildTools
             "BuildToolsSeparator", null, UIManagerItemType.SEPARATOR, false);
     }
 
-    private void add_dynamic_action (BuildTool build_tool, string action_name,
+    private void add_dynamic_action (Latexila.BuildTool build_tool, string action_name,
         ref int accel_num)
     {
         if (! build_tool.enabled)
@@ -301,16 +310,16 @@ public class MainWindowBuildTools
         return_if_fail (_build_view != null);
         return_if_fail (_bottom_panel != null);
 
-        BuildTool? tool = get_build_tool_from_name (action.name);
+        Latexila.BuildTool? tool = get_build_tool_from_name (action.name);
         return_if_fail (tool != null);
 
         Document active_doc = _main_window.active_document;
 
-        if (! tool.has_jobs ())
+        if (tool.get_jobs () == null)
             return_if_fail (active_doc.location != null);
 
         /* Save the document if jobs are executed */
-        if (tool.has_jobs ())
+        if (tool.get_jobs () != null)
         {
             if (active_doc.location == null)
             {
@@ -326,7 +335,7 @@ public class MainWindowBuildTools
             // Save all the documents belonging to the project
             else
             {
-                Gee.List<Document> docs = Latexila.get_instance ().get_documents ();
+                Gee.List<Document> docs = LatexilaApp.get_instance ().get_documents ();
                 foreach (Document doc in docs)
                 {
                     if (doc.project_id == project_id)
@@ -344,9 +353,13 @@ public class MainWindowBuildTools
         stop_exec.sensitive = true;
 
         File main_file = active_doc.get_main_file ();
+        tool.run (main_file, _build_view);
+        /* TODO port this code. */
+        /*
         _build_tool_runner = new BuildToolRunner (tool, main_file, _build_view);
         _build_tool_runner.finished.connect (() => stop_exec.sensitive = false);
         _build_tool_runner.run ();
+        */
     }
 
     private void connect_toggle_actions ()
@@ -393,8 +406,11 @@ public class MainWindowBuildTools
 
     public void on_stop_execution ()
     {
+        /* TODO port this code. */
+        /*
         return_if_fail (_build_tool_runner != null);
         _build_tool_runner.abort ();
+        */
     }
 
     public void on_clean ()
diff --git a/src/main_window_documents.vala b/src/main_window_documents.vala
index 9642f10..db51603 100644
--- a/src/main_window_documents.vala
+++ b/src/main_window_documents.vala
@@ -282,7 +282,7 @@ public class MainWindowDocuments
         return_if_fail (tab != null);
         return_if_fail (_documents_panel != null);
 
-        MainWindow new_window = Latexila.get_instance ().create_window ();
+        MainWindow new_window = LatexilaApp.get_instance ().create_window ();
         DocumentView view = tab.view;
         _documents_panel.remove_tab (tab);
 
diff --git a/src/main_window_file.vala b/src/main_window_file.vala
index 8443e63..24bf85c 100644
--- a/src/main_window_file.vala
+++ b/src/main_window_file.vala
@@ -135,7 +135,7 @@ public class MainWindowFile
 
     public void on_new_window ()
     {
-        Latexila.get_instance ().create_window ();
+        LatexilaApp.get_instance ().create_window ();
     }
 
     public void on_file_open ()
diff --git a/src/projects.vala b/src/projects.vala
index 2d61759..a2d3690 100644
--- a/src/projects.vala
+++ b/src/projects.vala
@@ -80,7 +80,7 @@ public class Projects
 
     private void update_all_menus ()
     {
-        foreach (Gtk.Window window in Latexila.get_instance ().get_windows ())
+        foreach (Gtk.Window window in LatexilaApp.get_instance ().get_windows ())
         {
             MainWindow main_window = window as MainWindow;
             main_window.update_config_project_sensitivity ();
@@ -105,7 +105,7 @@ public class Projects
         modified = true;
 
         // find if some opened documents are belonging to the new project
-        Gee.List<Document> docs = Latexila.get_instance ().get_documents ();
+        Gee.List<Document> docs = LatexilaApp.get_instance ().get_documents ();
         foreach (Document doc in docs)
         {
             if (doc.project_id != -1 || doc.location == null)
@@ -136,7 +136,7 @@ public class Projects
         modified = true;
 
         // refresh docs
-        Gee.List<Document> docs = Latexila.get_instance ().get_documents ();
+        Gee.List<Document> docs = LatexilaApp.get_instance ().get_documents ();
         foreach (Document doc in docs)
         {
             if (doc.project_id == num)
@@ -153,7 +153,7 @@ public class Projects
         modified = true;
 
         // refresh docs
-        Gee.List<Document> docs = Latexila.get_instance ().get_documents ();
+        Gee.List<Document> docs = LatexilaApp.get_instance ().get_documents ();
         foreach (Document doc in docs)
         {
             if (doc.project_id == num)
@@ -175,7 +175,7 @@ public class Projects
 
     private void update_all_documents ()
     {
-        Gee.List<Document> docs = Latexila.get_instance ().get_documents ();
+        Gee.List<Document> docs = LatexilaApp.get_instance ().get_documents ();
         foreach (Document doc in docs)
         {
             doc.project_id = -1;
diff --git a/src/synctex.vala b/src/synctex.vala
index eeceea5..7ed4665 100644
--- a/src/synctex.vala
+++ b/src/synctex.vala
@@ -116,7 +116,7 @@ public class Synctex : Object
 
     private void show_warning (string message)
     {
-        MainWindow main_window = Latexila.get_instance ().active_window as MainWindow;
+        MainWindow main_window = LatexilaApp.get_instance ().active_window as MainWindow;
 
         MessageDialog dialog = new MessageDialog (main_window,
             DialogFlags.DESTROY_WITH_PARENT,
@@ -256,7 +256,7 @@ public class Synctex : Object
                 return;
             }
 
-            MainWindow main_window = Latexila.get_instance ().active_window as MainWindow;
+            MainWindow main_window = LatexilaApp.get_instance ().active_window as MainWindow;
             main_window.jump_to_file_position (tex_file, pos.line - 1, pos.line);
             main_window.present_with_time (timestamp);
         });



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