improved build support for filetype LaTeX

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@145 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2006-01-18 12:11:44 +00:00
parent 0b18a2bd64
commit c02322ae35
6 changed files with 161 additions and 49 deletions

View File

@ -40,25 +40,72 @@
#include "msgwindow.h"
GPid build_compile_tex_file(gint idx)
GPid build_compile_tex_file(gint idx, gint mode)
{
gchar **argv;
gchar **argv;
argv = g_new(gchar *, 5);
argv[0] = g_strdup(app->build_tex_dvi_cmd);
argv = g_new(gchar*, 3);
argv[0] = (mode == 0) ? g_strdup(app->build_tex_dvi_cmd) : g_strdup(app->build_tex_pdf_cmd);
argv[1] = g_path_get_basename(doc_list[idx].file_name);
argv[2] = g_strdup(app->build_args_inc);
argv[3] = NULL;
argv[2] = NULL;
return build_spawn_cmd(idx, argv);
}
GPid build_view_tex_file(gint idx, gint mode)
{
gchar **argv;
gchar *executable = g_malloc0(strlen(doc_list[idx].file_name));
gchar *view_file;
gchar *last_dot = strrchr(doc_list[idx].file_name, '.');
GError *error = NULL;
gint i = 0;
GPid child_pid;
struct stat st;
while ((doc_list[idx].file_name + i) != last_dot)
{
executable[i] = doc_list[idx].file_name[i];
i++;
}
view_file = g_strconcat(executable, (mode == 0) ? ".dvi" : ".pdf", NULL);
g_free(executable);
// check wether view_file exists
if (stat(view_file, &st) != 0)
{
msgwin_status_add(_("Failed to view %s (make sure it is already compiled)"), view_file);
g_free(view_file);
return (GPid) 1;
}
argv = g_new(gchar*, 3);
argv[0] = (mode == 0) ? g_strdup(app->build_tex_view_dvi_cmd) : g_strdup(app->build_tex_view_pdf_cmd);
argv[1] = view_file;
argv[2] = NULL;
if (! g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
NULL, NULL, &child_pid, NULL, NULL, NULL, &error))
{
geany_debug("g_spawn_async_with_pipes() failed: %s", error->message);
msgwin_status_add(_("Process failed (%s)"), error->message);
g_strfreev(argv);
g_error_free(error);
error = NULL;
return (GPid) 0;
}
g_strfreev(argv);
return child_pid;
}
GPid build_make_c_file(gint idx, gboolean cust_target)
{
gchar **argv;
gchar **argv;
argv = g_new(gchar *, 3);
argv = g_new(gchar*, 3);
if (cust_target && app->build_make_custopt)
{
//cust-target
@ -79,9 +126,9 @@ GPid build_make_c_file(gint idx, gboolean cust_target)
GPid build_compile_c_file(gint idx)
{
gchar **argv;
gchar **argv;
argv = g_new(gchar *, 5);
argv = g_new(gchar*, 5);
argv[0] = g_strdup(app->build_c_cmd);
argv[1] = g_strdup("-c");
argv[2] = g_path_get_basename(doc_list[idx].file_name);
@ -272,7 +319,7 @@ GPid build_spawn_cmd(gint idx, gchar **cmd)
if (! g_spawn_async_with_pipes(working_dir, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
NULL, NULL, &child_pid, NULL, &stdout_fd, &stderr_fd, &error))
{
g_warning("g_spawn_async_with_pipes() failed: %s", error->message);
geany_debug("g_spawn_async_with_pipes() failed: %s", error->message);
msgwin_status_add(_("Process failed (%s)"), error->message);
g_strfreev(argv);
g_error_free(error);
@ -425,7 +472,7 @@ GIOChannel *build_set_up_io_channel (gint fd, GIOCondition cond, GIOFunc func, g
g_io_channel_set_encoding(ioc, encoding, &error);
if (error)
{
g_warning("compile: %s", error->message);
geany_debug("compile: %s", error->message);
g_error_free(error);
return ioc;
}
@ -445,12 +492,12 @@ void build_exit_cb (GPid child_pid, gint status, gpointer user_data)
#ifdef G_OS_UNIX
gboolean failure = FALSE;
if (WIFEXITED (status))
if (WIFEXITED(status))
{
if (WEXITSTATUS (status) != EXIT_SUCCESS)
if (WEXITSTATUS(status) != EXIT_SUCCESS)
failure = TRUE;
}
else if (WIFSIGNALED (status))
else if (WIFSIGNALED(status))
{
// the terminating signal: WTERMSIG (status));
failure = TRUE;

View File

@ -30,7 +30,9 @@ GPid build_make_c_file(gint idx, gboolean cust_target);
GPid build_compile_c_file(gint idx);
GPid build_compile_tex_file(gint idx);
GPid build_compile_tex_file(gint idx, gint mode);
GPid build_view_tex_file(gint idx, gint mode);
GPid build_link_c_file(gint idx);

View File

@ -1827,7 +1827,7 @@ on_build_compile_activate (GtkMenuItem *menuitem,
case GEANY_FILETYPES_CPP: child_pid = build_compile_cpp_file(idx); break;
case GEANY_FILETYPES_JAVA: child_pid = build_compile_java_file(idx); break;
case GEANY_FILETYPES_PASCAL: child_pid = build_compile_pascal_file(idx); break;
case GEANY_FILETYPES_TEX: child_pid = build_compile_tex_file(idx); break;
case GEANY_FILETYPES_TEX: child_pid = build_compile_tex_file(idx, 0); break;
}
if (child_pid != (GPid) 0)
@ -1838,6 +1838,31 @@ on_build_compile_activate (GtkMenuItem *menuitem,
}
void
on_build_tex_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
gint idx = document_get_cur_idx();
GPid child_pid = (GPid) 0;
if (doc_list[idx].changed) document_save_file(idx);
switch (GPOINTER_TO_INT(user_data))
{
case 0: child_pid = build_compile_tex_file(idx, 0); break;
case 1: child_pid = build_compile_tex_file(idx, 1); break;
case 2: child_pid = build_view_tex_file(idx, 0); break;
case 3: child_pid = build_view_tex_file(idx, 1); break;
}
if (GPOINTER_TO_INT(user_data) <= 1 && child_pid != (GPid) 0)
{
gtk_widget_set_sensitive(app->compile_button, FALSE);
g_child_watch_add(child_pid, build_exit_cb, NULL);
}
}
void
on_build_build_activate (GtkMenuItem *menuitem,
gpointer user_data)
@ -1851,6 +1876,9 @@ on_build_build_activate (GtkMenuItem *menuitem,
{
case GEANY_FILETYPES_C: child_pid = build_link_c_file(idx); break;
case GEANY_FILETYPES_CPP: child_pid = build_link_cpp_file(idx); break;
/* FIXME: temporary switch to catch F5-shortcut pressed on LaTeX files, as long as
* LaTeX build menu has no key accelerator */
case GEANY_FILETYPES_TEX: child_pid = build_compile_tex_file(idx, 1); break;
}
if (child_pid != (GPid) 0)
@ -1893,9 +1921,25 @@ on_build_execute_activate (GtkMenuItem *menuitem,
{
gint idx = document_get_cur_idx();
if (build_run_cmd(idx) == (GPid) 0)
/* FIXME: temporary switch to catch F5-shortcut pressed on LaTeX files, as long as
* LaTeX build menu has no key accelerator */
switch (doc_list[idx].file_type->id)
{
msgwin_status_add(_("Failed to execute the terminal program"));
case GEANY_FILETYPES_TEX:
{
if (build_view_tex_file(idx, 0) == (GPid) 0)
{
msgwin_status_add(_("Failed to execute the DVI view program"));
}
break;
}
default:
{
if (build_run_cmd(idx) == (GPid) 0)
{
msgwin_status_add(_("Failed to execute the terminal program"));
}
}
}
//gtk_widget_grab_focus(GTK_WIDGET(doc_list[idx].sci));
}

View File

@ -407,6 +407,10 @@ void
on_build_compile_activate (GtkMenuItem *menuitem,
gpointer user_data);
void
on_build_tex_activate (GtkMenuItem *menuitem,
gpointer user_data);
void
on_build_build_activate (GtkMenuItem *menuitem,
gpointer user_data);

View File

@ -556,38 +556,22 @@ GtkWidget *dialogs_create_build_menu_tex(void)
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
gtk_tooltips_set_tip(tooltips, item, _("Compiles the current file into a DVI file"), NULL);
gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F8, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
// gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F8, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
image = gtk_image_new_from_stock("gtk-convert", GTK_ICON_SIZE_MENU);
gtk_widget_show(image);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_compile_activate), NULL);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(0));
// PDF
item = gtk_image_menu_item_new_with_label(_("LaTeX -> PDF"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
gtk_tooltips_set_tip(tooltips, item, _("Compiles the current file into a PDF file"), NULL);
gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F9, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
// gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F9, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
image = gtk_image_new_from_stock("gtk-convert", GTK_ICON_SIZE_MENU);
gtk_widget_show(image);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_compile_activate), NULL);
// DVI view
item = gtk_menu_item_new_with_label(_("View DVI file"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
gtk_tooltips_set_tip(tooltips, item, _("Compiles and view the current file"), NULL);
gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F9,
(GdkModifierType) GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate), GINT_TO_POINTER(0));
// PDF view
item = gtk_menu_item_new_with_label(_("View PDF file"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
gtk_tooltips_set_tip(tooltips, item, _("Compiles and view the current file"), NULL);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate), GINT_TO_POINTER(1));
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(1));
// build the code with make all
item = gtk_menu_item_new_with_label(_("Build with \"make\""));
@ -595,9 +579,9 @@ GtkWidget *dialogs_create_build_menu_tex(void)
gtk_container_add(GTK_CONTAINER(menu), item);
gtk_tooltips_set_tip(tooltips, item, _("Builds the current file with the "
"make tool and the default target"), NULL);
gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F9,
/* gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F9,
(GdkModifierType) GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate), GINT_TO_POINTER(0));
*/ g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate), GINT_TO_POINTER(0));
// build the code with make
item = gtk_menu_item_new_with_label(_("Build with make (custom target)"));
@ -607,6 +591,29 @@ GtkWidget *dialogs_create_build_menu_tex(void)
"make tool and the specified target"), NULL);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate), GINT_TO_POINTER(1));
// DVI view
item = gtk_image_menu_item_new_with_label(_("View DVI file"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
// gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F5, (GdkModifierType) 0, GTK_ACCEL_VISIBLE);
gtk_tooltips_set_tip(tooltips, item, _("Compiles and view the current file"), NULL);
image = gtk_image_new_from_stock("gtk-find", GTK_ICON_SIZE_MENU);
gtk_widget_show(image);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(2));
// PDF view
item = gtk_image_menu_item_new_with_label(_("View PDF file"));
gtk_widget_show(item);
gtk_container_add(GTK_CONTAINER(menu), item);
/* gtk_widget_add_accelerator(item, "activate", accel_group, GDK_F5,
(GdkModifierType) GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE);
*/ gtk_tooltips_set_tip(tooltips, item, _("Compiles and view the current file"), NULL);
image = gtk_image_new_from_stock("gtk-find", GTK_ICON_SIZE_MENU);
gtk_widget_show(image);
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(3));
// separator
separator = gtk_separator_menu_item_new();
gtk_widget_show(separator);
@ -872,12 +879,12 @@ void dialogs_show_includes_arguments_tex(void)
{
GtkWidget *dialog, *label, *entries[3];
dialog = gtk_dialog_new_with_buttons(_("Set Includes and Arguments"), GTK_WINDOW(app->window),
dialog = gtk_dialog_new_with_buttons(_("Set Arguments"), GTK_WINDOW(app->window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
label = gtk_label_new(_("Sets the includes and library paths for the compiler and the program arguments for execution\n"));
label = gtk_label_new(_("Set programs and options for compilation and viewing (La)TeX files.\nThe filename is appended automatically at the end.\n"));
gtk_misc_set_padding(GTK_MISC(label), 0, 6);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
@ -893,6 +900,7 @@ void dialogs_show_includes_arguments_tex(void)
gtk_entry_set_text(GTK_ENTRY(entries[0]), app->build_tex_dvi_cmd);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entries[0]);
// whitespace
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), gtk_label_new(""));
// LaTeX -> PDF args
@ -906,10 +914,11 @@ void dialogs_show_includes_arguments_tex(void)
gtk_entry_set_text(GTK_ENTRY(entries[1]), app->build_tex_pdf_cmd);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entries[1]);
// whitespace
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), gtk_label_new(""));
// View LaTeX -> DVI args
label = gtk_label_new(_("Enter here the (La)TeX command (for DVI creation and preview) and some useful options."));
label = gtk_label_new(_("Enter here the (La)TeX command (for DVI preview) and some useful options."));
gtk_misc_set_padding(GTK_MISC(label), 0, 6);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
@ -919,10 +928,11 @@ void dialogs_show_includes_arguments_tex(void)
gtk_entry_set_text(GTK_ENTRY(entries[2]), app->build_tex_view_dvi_cmd);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entries[2]);
// whitespace
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), gtk_label_new(""));
// View LaTeX -> PDF args
label = gtk_label_new(_("Enter here the (La)TeX command (for PDF creation and preview) and some useful options."));
label = gtk_label_new(_("Enter here the (La)TeX command (for PDF preview) and some useful options."));
gtk_misc_set_padding(GTK_MISC(label), 0, 6);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
@ -932,6 +942,7 @@ void dialogs_show_includes_arguments_tex(void)
gtk_entry_set_text(GTK_ENTRY(entries[3]), app->build_tex_view_pdf_cmd);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entries[3]);
// whitespace
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), gtk_label_new(""));
g_object_set_data_full(G_OBJECT(dialog), "tex_entry1",

View File

@ -296,19 +296,23 @@ gboolean configuration_load(void)
app->build_fpc_cmd = utils_get_setting_string(config, "build", "build_fpc_cmd", tmp_string);
g_free(tmp_string);
tmp_string = g_find_program_in_path("latex");
tmp_string2 = g_find_program_in_path("latex");
tmp_string = g_strconcat(tmp_string2, " -interaction=nonstopmode", NULL);
app->build_tex_dvi_cmd = utils_get_setting_string(config, "build", "build_tex_dvi_cmd", tmp_string);
g_free(tmp_string);
g_free(tmp_string2);
tmp_string = g_find_program_in_path("pdflatex");
tmp_string2 = g_find_program_in_path("pdflatex");
tmp_string = g_strconcat(tmp_string2, " -interaction=nonstopmode", NULL);
app->build_tex_pdf_cmd = utils_get_setting_string(config, "build", "build_tex_pdf_cmd", tmp_string);
g_free(tmp_string);
g_free(tmp_string2);
tmp_string = g_find_program_in_path("latex");
tmp_string = g_find_program_in_path("xdvi");
app->build_tex_view_dvi_cmd = utils_get_setting_string(config, "build", "build_tex_view_dvi_cmd", tmp_string);
g_free(tmp_string);
tmp_string = g_find_program_in_path("pdflatex");
tmp_string = g_find_program_in_path("xpdf");
app->build_tex_view_pdf_cmd = utils_get_setting_string(config, "build", "build_tex_view_pdf_cmd", tmp_string);
g_free(tmp_string);