[latexila] More robust BuildToolRunner calls



commit 26523267ac3e6a01c7af4652b36d2964c0f3a26b
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Tue Aug 16 21:20:41 2011 +0200

    More robust BuildToolRunner calls

 src/build_tool_runner.vala |    3 +-
 src/file_browser.vala      |   53 +++++++++++++++++++++++++------------------
 src/main_window.vala       |    5 ++-
 3 files changed, 36 insertions(+), 25 deletions(-)
---
diff --git a/src/build_tool_runner.vala b/src/build_tool_runner.vala
index 3e10215..fefc4bf 100644
--- a/src/build_tool_runner.vala
+++ b/src/build_tool_runner.vala
@@ -51,7 +51,8 @@ public class BuildToolRunner : GLib.Object
     public BuildToolRunner (File file, BuildTool? tool, BuildView view,
         Gtk.Action action_stop_exec)
     {
-        // FIXME really useful?
+        // TODO remove this and the '?' when the bug in vala is fixed
+        // https://bugzilla.gnome.org/show_bug.cgi?id=656693
         return_if_fail (tool != null);
 
         this.file = file;
diff --git a/src/file_browser.vala b/src/file_browser.vala
index b70445a..76965f0 100644
--- a/src/file_browser.vala
+++ b/src/file_browser.vala
@@ -259,31 +259,40 @@ public class FileBrowser : VBox
 
             BuildTools build_tools = BuildTools.get_default ();
             string extension = Utils.get_extension (basename);
+            DocType doc_type;
+
             switch (extension)
             {
-            // View DVI
-            case ".dvi":
-                new BuildToolRunner (file, build_tools.get_view_doc (DocType.DVI),
-                    build_view, main_window.get_action_stop_exec ());
-                break;
-
-            // View PDF
-            case ".pdf":
-                new BuildToolRunner (file, build_tools.get_view_doc (DocType.PDF),
-                    build_view, main_window.get_action_stop_exec ());
-                break;
-
-            // View PS
-            case ".ps":
-                new BuildToolRunner (file, build_tools.get_view_doc (DocType.PS),
-                    build_view, main_window.get_action_stop_exec ());
-                break;
+                // View DVI
+                case ".dvi":
+                    doc_type = DocType.DVI;
+                    break;
+
+                // View PDF
+                case ".pdf":
+                    doc_type = DocType.PDF;
+                    break;
+
+                // View PS
+                case ".ps":
+                    doc_type = DocType.PS;
+                    break;
+
+                // Open document
+                default:
+                    main_window.open_document (file);
+                    return;
+            }
 
-            // Open document
-            default:
-                main_window.open_document (file);
-                break;
+            BuildTool? tool = build_tools.get_view_doc (doc_type);
+            if (tool == null)
+            {
+                warning ("There is no build tool to view the file '%s'", basename);
+                return;
             }
+
+            new BuildToolRunner (file, tool, build_view,
+                main_window.get_action_stop_exec ());
         });
     }
 
diff --git a/src/main_window.vala b/src/main_window.vala
index a239d1a..868b839 100644
--- a/src/main_window.vala
+++ b/src/main_window.vala
@@ -1218,9 +1218,10 @@ public class MainWindow : Window
         return_if_fail (active_document.location != null);
 
         string[] _name = action.name.split ("_");
-        int i = int.parse (_name[1]);
+        int tool_index = int.parse (_name[1]);
 
-        BuildTool tool = BuildTools.get_default ()[i];
+        BuildTool? tool = BuildTools.get_default ()[tool_index];
+        return_if_fail (tool != null);
 
         build_view.show ();
 



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