[latexila] SyncTeX: nice error messages for the forward search



commit 3fb9547584d56223d29651b4f6109fc50c422cad
Author: SÃbastien Wilmet <swilmet gnome org>
Date:   Mon Sep 10 00:07:04 2012 +0200

    SyncTeX: nice error messages for the forward search
    
    It is easier than listening to file changes etc to update the
    sensitivity. And with error messages, the user knows why it doesn't
    work.

 src/synctex.vala |   48 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 44 insertions(+), 4 deletions(-)
---
diff --git a/src/synctex.vala b/src/synctex.vala
index d49a017..15eda08 100644
--- a/src/synctex.vala
+++ b/src/synctex.vala
@@ -57,18 +57,58 @@ public class Synctex : Object
     public void forward_search (Document doc)
     {
         string? pdf_uri = get_pdf_uri (doc);
-        return_if_fail (pdf_uri != null);
+
+        if (pdf_uri == null)
+        {
+            show_warning (_("The document is not saved."));
+            return;
+        }
+
+        File pdf_file = File.new_for_uri (pdf_uri);
+        if (! pdf_file.query_exists ())
+        {
+            show_warning (_("The PDF file doesn't exist."));
+            return;
+        }
+
+        string synctex_uri = Utils.get_shortname (pdf_uri) + ".synctex.gz";
+        File synctex_file = File.new_for_uri (synctex_uri);
+        if (! synctex_file.query_exists ())
+        {
+            string synctex_basename = synctex_file.get_basename ();
+            show_warning (_("The file \"%s\" doesn't exist.").printf (synctex_basename));
+            return;
+        }
 
         EvinceWindow? ev_window = get_evince_window (pdf_uri);
-        return_if_fail (ev_window != null);
+        if (ev_window == null)
+        {
+            show_warning (_("Can not communicate with evince."));
+            return;
+        }
 
-        return_if_fail (doc.location != null);
         string tex_path = doc.location.get_path ();
-
         DocPosition pos = get_doc_position (doc);
+
         sync_view (ev_window, tex_path, pos);
     }
 
+    private void show_warning (string message)
+    {
+        MainWindow main_window = Latexila.get_instance ().active_window;
+
+        MessageDialog dialog = new MessageDialog (main_window,
+            DialogFlags.DESTROY_WITH_PARENT,
+            MessageType.ERROR,
+            ButtonsType.OK,
+            "%s", _("Impossible to do the forward search."));
+
+        dialog.format_secondary_text ("%s", message);
+
+        dialog.run ();
+        dialog.destroy ();
+    }
+
     private DocPosition get_doc_position (Document doc)
     {
         TextIter iter;



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