[gnome-latex: 118/205] File browser: view document



commit 6532e5ec403b6510e1503f7fa812b0e222cbae28
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date:   Wed Nov 11 18:19:51 2009 +0100

    File browser: view document
    
    If we select a *.pdf, *.dvi or *.ps file in the file browser, we view
    the document with the external program (evince for example) instead of
    opening it like a *.tex file.

 TODO                    |  2 +-
 src/callbacks.c         |  6 +++---
 src/external_commands.c | 27 +++++++++++++++++++++++----
 src/external_commands.h |  3 ++-
 src/file_browser.c      |  9 +++++++++
 5 files changed, 38 insertions(+), 9 deletions(-)
---
diff --git a/TODO b/TODO
index 4b6b862..8f1a43f 100644
--- a/TODO
+++ b/TODO
@@ -7,7 +7,7 @@ TODO LaTeXila
        x save the current folder in the prefs
        x add a link to the home user directory
        x other pixbuf for *.pdf, *.dvi and *.ps files
-       - if clicking on a *.pdf, *.dvi or *.ps file, show the document (add a new action)
+       x if clicking on a *.pdf, *.dvi or *.ps file, show the document (add a new action)
        - add an option in the preferences: show only *.tex, *.pdf, *.dvi and *.ps files
 
 [-] Templates
diff --git a/src/callbacks.c b/src/callbacks.c
index bd3b85e..773f3c3 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -585,7 +585,7 @@ cb_view_dvi (void)
        if (latexila.active_doc == NULL)
                return;
 
-       view_document (_("View DVI"), ".dvi");
+       view_current_document (_("View DVI"), ".dvi");
 }
 
 void
@@ -594,7 +594,7 @@ cb_view_pdf (void)
        if (latexila.active_doc == NULL)
                return;
 
-       view_document (_("View PDF"), ".pdf");
+       view_current_document (_("View PDF"), ".pdf");
 }
 
 void
@@ -603,7 +603,7 @@ cb_view_ps (void)
        if (latexila.active_doc == NULL)
                return;
 
-       view_document (_("View PS"), ".ps");
+       view_current_document (_("View PS"), ".ps");
 }
 
 void
diff --git a/src/external_commands.c b/src/external_commands.c
index 924c674..26a0405 100644
--- a/src/external_commands.c
+++ b/src/external_commands.c
@@ -38,6 +38,7 @@ static gboolean cb_watch_output_command (GIOChannel *channel,
                GIOCondition condition, gpointer user_data);
 static void add_action (gchar *title, gchar *command);
 static void set_action_sensitivity (gboolean sensitive);
+static void view_document_run (gchar *filename);
 
 static gchar *
 get_command_line (gchar **command)
@@ -220,7 +221,7 @@ compile_document (gchar *title, gchar **command)
 }
 
 void
-view_document (gchar *title, gchar *doc_extension)
+view_current_document (gchar *title, gchar *doc_extension)
 {
        if (latexila.active_doc == NULL)
                return;
@@ -267,16 +268,35 @@ view_document (gchar *title, gchar *doc_extension)
                return;
        }
 
-       /* run the command */
+       view_document_run (doc_path);
+       g_free (doc_path);
+}
+
+void
+view_document (gchar *title, gchar *filename)
+{
+       gchar *command_line = g_strdup_printf ("%s %s", latexila.prefs.command_view,
+                       filename);
+       add_action (title, command_line);
+       print_info ("execution of the command: %s", command_line);
+       g_free (command_line);
+
+       view_document_run (filename);
+}
+
+static void
+view_document_run (gchar *filename)
+{
        // we use here g_spawn_async () and not g_spawn_command_line_async ()
        // because the spaces in doc_path are not escaped, so with the command line
        // it doesn't work fine...
        
        GError *error = NULL;
-       gchar *argv[] = {latexila.prefs.command_view, doc_path, NULL};
+       gchar *argv[] = {latexila.prefs.command_view, filename, NULL};
        g_spawn_async (NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error);
 
        gboolean is_error = TRUE;
+       gchar *command_output;
 
        if (error != NULL)
        {
@@ -294,7 +314,6 @@ view_document (gchar *title, gchar *doc_extension)
        print_log_add (latexila.action_log.text_view, command_output, is_error);
 
        g_free (command_output);
-       g_free (doc_path);
 }
 
 void
diff --git a/src/external_commands.h b/src/external_commands.h
index 26db6b2..b6ac7df 100644
--- a/src/external_commands.h
+++ b/src/external_commands.h
@@ -21,7 +21,8 @@
 #define EXTERNAL_COMMANDS_H
 
 void compile_document (gchar *title, gchar **command);
-void view_document (gchar *title, gchar *doc_extension);
+void view_current_document (gchar *title, gchar *doc_extension);
+void view_document (gchar *title, gchar *filename);
 void convert_document (gchar *title, gchar *doc_extension, gchar *command);
 
 #endif /* EXTERNAL_COMMANDS_H */
diff --git a/src/file_browser.c b/src/file_browser.c
index 4624fb1..ada56d9 100644
--- a/src/file_browser.c
+++ b/src/file_browser.c
@@ -30,6 +30,7 @@
 #include "print.h"
 #include "file_browser.h"
 #include "callbacks.h"
+#include "external_commands.h"
 
 static void fill_list_store_with_current_dir (void);
 static void cb_go_to_home_dir (GtkButton *button, gpointer user_data);
@@ -288,6 +289,14 @@ cb_file_browser_row_activated (GtkTreeView *tree_view, GtkTreePath *path,
                fill_list_store_with_current_dir ();
        }
 
+       // view the document
+       else if (g_str_has_suffix (full_path, ".pdf"))
+               view_document (_("View PDF"), full_path);
+       else if (g_str_has_suffix (full_path, ".dvi"))
+               view_document (_("View DVI"), full_path);
+       else if (g_str_has_suffix (full_path, ".ps"))
+               view_document (_("View PS"), full_path);
+
        // open the file
        else
        {


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