[gnome-latex: 25/205] - DVI to PDF - DVI to PS - view PS
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-latex: 25/205] - DVI to PDF - DVI to PS - view PS
- Date: Fri, 14 Dec 2018 10:48:59 +0000 (UTC)
commit 6fbf90b01fe34d3d655f688363d40623bd6a3e40
Author: Sébastien Wilmet <sebastien wilmet gmail com>
Date: Sat Aug 22 14:51:17 2009 +0200
- DVI to PDF
- DVI to PS
- view PS
src/callbacks.c | 75 ++++++++++++++++++++++++++++++++++++++++++++---
src/callbacks.h | 2 ++
src/icons/dvi_to_pdf.png | Bin 0 -> 1312 bytes
src/icons/dvi_to_ps.png | Bin 0 -> 1287 bytes
src/icons/view_ps.png | Bin 0 -> 1703 bytes
src/main.c | 11 +++++--
src/print.c | 2 ++
src/ui.xml | 2 ++
8 files changed, 86 insertions(+), 6 deletions(-)
---
diff --git a/src/callbacks.c b/src/callbacks.c
index fef3de4..8cbf3a4 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -24,6 +24,8 @@ static void set_title (void);
static void set_undo_redo_sensitivity (void);
static void run_compilation (gchar *title, gchar *command);
static void view_document (gchar *title, gchar *doc_extension);
+static void convert_document (gchar *title, gchar *doc_extension,
+ gchar *command);
static void add_action (gchar *title, gchar *command, gchar *command_output);
void
@@ -237,9 +239,22 @@ cb_view_pdf (void)
view_document (_("View PDF"), ".pdf");
}
+void
+cb_view_ps (void)
+{
+ view_document (_("View PS"), ".ps");
+}
+
void
cb_dvi_to_pdf (void)
{
+ convert_document (_("DVI to PDF"), ".dvi", "dvipdf");
+}
+
+void
+cb_dvi_to_ps (void)
+{
+ convert_document (_("DVI to PS"), ".dvi", "dvips");
}
void
@@ -628,11 +643,10 @@ run_compilation (gchar *title, gchar *command)
gchar *dir_backup = g_get_current_dir ();
gchar *dir = g_path_get_dirname (latexila.active_doc->path);
g_chdir (dir);
- //gchar *full_command = g_strdup_printf ("%s %s", command, latexila.active_doc->path);
- GError *error = NULL;
print_info ("execution of the command: %s", command);
+ GError *error = NULL;
g_spawn_command_line_sync (command, &command_output, NULL, NULL, &error);
g_chdir (dir_backup);
@@ -662,7 +676,7 @@ view_document (gchar *title, gchar *doc_extension)
GError *error = NULL;
GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
- // replace .tex by .pdf
+ // replace .tex by doc_extension (.pdf, .dvi, ...)
gchar *doc_path = g_regex_replace_literal (regex, latexila.active_doc->path,
-1, 0, doc_extension, 0, NULL);
@@ -721,8 +735,61 @@ view_document (gchar *title, gchar *doc_extension)
}
static void
-convert_document (gchar *title, gchar *command)
+convert_document (gchar *title, gchar *doc_extension, gchar *command)
{
+ if (latexila.active_doc != NULL)
+ {
+ gchar *full_command, *command_output;
+
+ GError *error = NULL;
+ GRegex *regex = g_regex_new ("\\.tex$", 0, 0, NULL);
+
+ // replace .tex by doc_extension (.pdf, .dvi, ...)
+ gchar *doc_path = g_regex_replace_literal (regex,
+ latexila.active_doc->path, -1, 0, doc_extension, 0, NULL);
+
+ full_command = g_strdup_printf ("%s %s", command, doc_path);
+
+ // the document to convert exist?
+ if (! g_file_test (doc_path, G_FILE_TEST_IS_REGULAR))
+ {
+ command_output = g_strdup_printf (
+ _("%s does not exist. If this is not already made, compile the
document with the right command."),
+ g_path_get_basename (doc_path));
+
+ add_action (title, full_command, command_output);
+ g_free (full_command);
+ g_free (command_output);
+ g_free (doc_path);
+ g_regex_unref (regex);
+ return;
+ }
+
+ // run the command in the directory where the .tex is
+ print_info ("execution of the command: %s", full_command);
+
+ gchar *dir_backup = g_get_current_dir ();
+ gchar *dir = g_path_get_dirname (latexila.active_doc->path);
+ g_chdir (dir);
+ g_spawn_command_line_sync (full_command, &command_output, NULL, NULL, &error);
+ g_chdir (dir_backup);
+
+
+ // an error occured
+ if (error != NULL)
+ {
+ command_output = g_strdup_printf (_("execution failed: %s"),
+ error->message);
+ g_error_free (error);
+ }
+
+ add_action (title, full_command, command_output);
+
+ g_free (full_command);
+ g_free (command_output);
+ g_free (doc_path);
+ g_regex_unref (regex);
+ }
}
static void
diff --git a/src/callbacks.h b/src/callbacks.h
index 139308e..8263cbe 100644
--- a/src/callbacks.h
+++ b/src/callbacks.h
@@ -14,7 +14,9 @@ void cb_latex (void);
void cb_pdflatex (void);
void cb_view_dvi (void);
void cb_view_pdf (void);
+void cb_view_ps (void);
void cb_dvi_to_pdf (void);
+void cb_dvi_to_ps (void);
void cb_action_list_changed (GtkTreeSelection *selection,
gpointer user_data);
void cb_about_dialog (void);
diff --git a/src/icons/dvi_to_pdf.png b/src/icons/dvi_to_pdf.png
new file mode 100644
index 0000000..e52993d
Binary files /dev/null and b/src/icons/dvi_to_pdf.png differ
diff --git a/src/icons/dvi_to_ps.png b/src/icons/dvi_to_ps.png
new file mode 100644
index 0000000..9fc712e
Binary files /dev/null and b/src/icons/dvi_to_ps.png differ
diff --git a/src/icons/view_ps.png b/src/icons/view_ps.png
new file mode 100644
index 0000000..ccbe607
Binary files /dev/null and b/src/icons/view_ps.png differ
diff --git a/src/main.c b/src/main.c
index 917dd5e..273ba21 100644
--- a/src/main.c
+++ b/src/main.c
@@ -20,7 +20,10 @@ static struct {
{DATA_DIR "/icons/compile_latex.png", "compile_latex"},
{DATA_DIR "/icons/compile_pdflatex.png", "compile_pdflatex"},
{DATA_DIR "/icons/view_dvi.png", "view_dvi"},
- {DATA_DIR "/icons/view_pdf.png", "view_pdf"}
+ {DATA_DIR "/icons/view_pdf.png", "view_pdf"},
+ {DATA_DIR "/icons/view_ps.png", "view_ps"},
+ {DATA_DIR "/icons/dvi_to_pdf.png", "dvi_to_pdf"},
+ {DATA_DIR "/icons/dvi_to_ps.png", "dvi_to_ps"}
};
static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
@@ -124,8 +127,12 @@ main (int argc, char *argv[])
_("Produce the document in PDF format"), G_CALLBACK (cb_pdflatex)},
{"viewPDF", "view_pdf", _("View PDF"), "<Release>F8",
_("View the PDF file"), G_CALLBACK (cb_view_pdf)},
- {"DVItoPDF", NULL, _("DVI to PDF"), NULL,
+ {"DVItoPDF", "dvi_to_pdf", _("DVI to PDF"), NULL,
_("Convert the DVI document to the PDF format"), G_CALLBACK (cb_dvi_to_pdf)},
+ {"DVItoPS", "dvi_to_ps", _("DVI to PS"), NULL,
+ _("Convert the DVI document to the PostScript format"), G_CALLBACK (cb_dvi_to_ps)},
+ {"viewPS", "view_ps", _("View PS"), NULL,
+ _("View the PostScript file"), G_CALLBACK (cb_view_ps)},
{"Help", NULL, _("Help"), NULL, NULL, NULL},
{"HelpAbout", GTK_STOCK_ABOUT, _("About"), NULL,
diff --git a/src/print.c b/src/print.c
index 2519ca7..2f83702 100644
--- a/src/print.c
+++ b/src/print.c
@@ -3,6 +3,8 @@
#include <stdarg.h>
#include <gtk/gtk.h>
+#include "print.h"
+
void
print_log (GtkTextView *log, gchar *title, gchar *command,
gchar *command_output)
diff --git a/src/ui.xml b/src/ui.xml
index c1f0592..27a200b 100644
--- a/src/ui.xml
+++ b/src/ui.xml
@@ -34,6 +34,8 @@ In the code, GtkUIManager is used to construct them.
<menuitem action="viewPDF" />
<separator />
<menuitem action="DVItoPDF" />
+ <menuitem action="DVItoPS" />
+ <menuitem action="viewPS" />
</menu>
<menu action="Help">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]