2005-11-22 12:26:26 +00:00
|
|
|
/*
|
|
|
|
* build.c - this file is part of Geany, a fast and lightweight IDE
|
|
|
|
*
|
2008-01-06 18:11:57 +00:00
|
|
|
* Copyright 2005-2008 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
|
|
|
* Copyright 2006-2008 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-06-13 19:37:21 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-11-22 12:26:26 +00:00
|
|
|
*
|
2006-01-03 12:39:25 +00:00
|
|
|
* $Id$
|
2005-11-22 12:26:26 +00:00
|
|
|
*/
|
|
|
|
|
2007-02-24 11:41:56 +00:00
|
|
|
/*
|
|
|
|
* Build commands and menu items.
|
|
|
|
*/
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-07-20 21:16:12 +00:00
|
|
|
#include "geany.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
#include "build.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
2007-04-16 15:58:34 +00:00
|
|
|
#include <glib/gstdio.h>
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <sys/wait.h>
|
2006-11-14 01:27:12 +00:00
|
|
|
# include <signal.h>
|
2007-11-02 12:58:38 +00:00
|
|
|
#else
|
|
|
|
# include <windows.h>
|
2005-11-22 12:26:26 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
#include "prefs.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
#include "support.h"
|
2008-06-15 13:35:48 +00:00
|
|
|
#include "document.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
#include "utils.h"
|
2006-09-08 13:40:30 +00:00
|
|
|
#include "ui_utils.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
#include "dialogs.h"
|
2008-06-12 20:09:57 +00:00
|
|
|
#include "msgwindow.h"
|
2007-08-15 15:37:21 +00:00
|
|
|
#include "filetypes.h"
|
2006-10-18 19:35:42 +00:00
|
|
|
#include "keybindings.h"
|
2006-12-10 21:29:04 +00:00
|
|
|
#include "vte.h"
|
2007-03-01 11:38:14 +00:00
|
|
|
#include "project.h"
|
2007-05-29 16:30:54 +00:00
|
|
|
#include "editor.h"
|
2008-03-14 16:59:36 +00:00
|
|
|
#include "win32.h"
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
|
2008-05-16 14:35:41 +00:00
|
|
|
GeanyBuildInfo build_info = {GBO_COMPILE, 0, NULL, GEANY_FILETYPES_NONE, NULL};
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2007-09-27 15:10:22 +00:00
|
|
|
static gchar *current_dir_entered = NULL;
|
|
|
|
|
2006-11-29 10:29:34 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
GPid pid;
|
|
|
|
gint file_type_id;
|
2008-05-07 13:54:21 +00:00
|
|
|
} run_info = {0, GEANY_FILETYPES_NONE};
|
2006-11-29 10:29:34 +00:00
|
|
|
|
2007-03-03 13:14:41 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2007-11-04 19:26:02 +00:00
|
|
|
static const gchar RUN_SCRIPT_CMD[] = "geany_run_script.bat";
|
2007-03-03 13:14:41 +00:00
|
|
|
#else
|
|
|
|
static const gchar RUN_SCRIPT_CMD[] = "./geany_run_script.sh";
|
|
|
|
#endif
|
|
|
|
|
2006-11-11 18:51:33 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LATEX_CMD_TO_DVI,
|
|
|
|
LATEX_CMD_TO_PDF,
|
|
|
|
LATEX_CMD_VIEW_DVI,
|
|
|
|
LATEX_CMD_VIEW_PDF
|
|
|
|
};
|
2006-10-16 14:15:04 +00:00
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
static BuildMenuItems default_menu_items =
|
2006-12-08 15:50:10 +00:00
|
|
|
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
2006-11-30 15:42:52 +00:00
|
|
|
static BuildMenuItems latex_menu_items =
|
2006-12-08 15:50:10 +00:00
|
|
|
{NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
2006-11-30 15:42:52 +00:00
|
|
|
|
2006-10-16 14:15:04 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
GtkWidget *run_button;
|
|
|
|
GtkWidget *compile_button;
|
|
|
|
}
|
|
|
|
widgets;
|
|
|
|
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data);
|
2007-03-03 16:54:04 +00:00
|
|
|
static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, gboolean autoclose);
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir);
|
2006-11-11 18:51:33 +00:00
|
|
|
static void set_stop_button(gboolean stop);
|
|
|
|
static void build_exit_cb(GPid child_pid, gint status, gpointer user_data);
|
2006-11-29 10:29:34 +00:00
|
|
|
static void run_exit_cb(GPid child_pid, gint status, gpointer user_data);
|
2007-06-13 12:00:23 +00:00
|
|
|
static void on_build_arguments_activate(GtkMenuItem *menuitem, gpointer user_data);
|
2006-11-29 10:29:34 +00:00
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static void on_build_compile_activate(GtkMenuItem *menuitem, gpointer user_data);
|
|
|
|
static void on_build_tex_activate(GtkMenuItem *menuitem, gpointer user_data);
|
|
|
|
static void on_build_build_activate(GtkMenuItem *menuitem, gpointer user_data);
|
|
|
|
static void on_build_make_activate(GtkMenuItem *menuitem, gpointer user_data);
|
|
|
|
static void on_build_execute_activate(GtkMenuItem *menuitem, gpointer user_data);
|
|
|
|
static void on_build_next_error(GtkMenuItem *menuitem, gpointer user_data);
|
2006-11-29 10:29:34 +00:00
|
|
|
static void kill_process(GPid *pid);
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-12-08 15:50:10 +00:00
|
|
|
|
2006-10-16 14:41:57 +00:00
|
|
|
void build_finalize()
|
|
|
|
{
|
|
|
|
g_free(build_info.dir);
|
|
|
|
g_free(build_info.custom_target);
|
2006-11-30 15:42:52 +00:00
|
|
|
|
|
|
|
if (default_menu_items.menu != NULL && GTK_IS_WIDGET(default_menu_items.menu))
|
|
|
|
gtk_widget_destroy(default_menu_items.menu);
|
|
|
|
if (latex_menu_items.menu != NULL && GTK_IS_WIDGET(latex_menu_items.menu))
|
|
|
|
gtk_widget_destroy(latex_menu_items.menu);
|
2006-10-16 14:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_compile_tex_file(GeanyDocument *doc, gint mode)
|
2006-01-11 18:44:52 +00:00
|
|
|
{
|
2007-02-28 17:24:22 +00:00
|
|
|
const gchar *cmd = NULL;
|
2006-01-11 18:44:52 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL || doc->file_name == NULL)
|
|
|
|
return (GPid) 1;
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2006-11-11 18:51:33 +00:00
|
|
|
if (mode == LATEX_CMD_TO_DVI)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
cmd = doc->file_type->programs->compiler;
|
2006-11-11 18:51:33 +00:00
|
|
|
build_info.type = GBO_COMPILE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
cmd = doc->file_type->programs->linker;
|
2006-11-11 18:51:33 +00:00
|
|
|
build_info.type = GBO_BUILD;
|
|
|
|
}
|
2006-01-11 18:44:52 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
return build_spawn_cmd(doc, cmd, NULL);
|
2006-01-11 18:44:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_view_tex_file(GeanyDocument *doc, gint mode)
|
2006-01-18 12:11:44 +00:00
|
|
|
{
|
2006-11-11 18:51:33 +00:00
|
|
|
gchar **argv, **term_argv;
|
2006-04-27 18:06:35 +00:00
|
|
|
gchar *executable = NULL;
|
|
|
|
gchar *view_file = NULL;
|
|
|
|
gchar *locale_filename = NULL;
|
|
|
|
gchar *cmd_string = NULL;
|
|
|
|
gchar *locale_cmd_string = NULL;
|
2006-11-11 18:51:33 +00:00
|
|
|
gchar *locale_term_cmd;
|
2007-11-04 19:26:02 +00:00
|
|
|
gchar *script_name;
|
|
|
|
gchar *working_dir;
|
2006-11-11 18:51:33 +00:00
|
|
|
gint term_argv_len, i;
|
2006-01-18 12:11:44 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
struct stat st;
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL || doc->file_name == NULL)
|
2007-11-04 19:26:02 +00:00
|
|
|
return (GPid) 1;
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-11-29 10:29:34 +00:00
|
|
|
run_info.file_type_id = GEANY_FILETYPES_LATEX;
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
executable = utils_remove_ext_from_filename(doc->file_name);
|
2006-11-11 18:51:33 +00:00
|
|
|
view_file = g_strconcat(executable, (mode == LATEX_CMD_VIEW_DVI) ? ".dvi" : ".pdf", NULL);
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* try convert in locale for stat() */
|
2006-08-13 09:07:10 +00:00
|
|
|
locale_filename = utils_get_locale_from_utf8(view_file);
|
2006-01-18 12:11:44 +00:00
|
|
|
|
2008-02-27 16:09:06 +00:00
|
|
|
/* check whether view_file exists */
|
2007-04-16 15:58:34 +00:00
|
|
|
if (g_stat(locale_filename, &st) != 0)
|
2006-01-18 12:11:44 +00:00
|
|
|
{
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Failed to view %s (make sure it is already compiled)"), view_file);
|
2007-03-03 13:14:41 +00:00
|
|
|
utils_free_pointers(executable, view_file, locale_filename, NULL);
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2006-01-18 12:11:44 +00:00
|
|
|
return (GPid) 1;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* replace %f and %e in the run_cmd string */
|
2006-11-11 18:51:33 +00:00
|
|
|
cmd_string = g_strdup((mode == LATEX_CMD_VIEW_DVI) ?
|
2008-06-15 13:35:48 +00:00
|
|
|
g_strdup(doc->file_type->programs->run_cmd) :
|
|
|
|
g_strdup(doc->file_type->programs->run_cmd2));
|
2006-04-27 18:06:35 +00:00
|
|
|
cmd_string = utils_str_replace(cmd_string, "%f", view_file);
|
|
|
|
cmd_string = utils_str_replace(cmd_string, "%e", executable);
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* try convert in locale */
|
2006-08-13 09:07:10 +00:00
|
|
|
locale_cmd_string = utils_get_locale_from_utf8(cmd_string);
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-11-11 18:51:33 +00:00
|
|
|
/* get the terminal path */
|
2008-05-16 12:08:39 +00:00
|
|
|
locale_term_cmd = utils_get_locale_from_utf8(tool_prefs.term_cmd);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* split the term_cmd, so arguments will work too */
|
2006-11-11 18:51:33 +00:00
|
|
|
term_argv = g_strsplit(locale_term_cmd, " ", -1);
|
|
|
|
term_argv_len = g_strv_length(term_argv);
|
2006-09-22 12:05:18 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* check that terminal exists (to prevent misleading error messages) */
|
2006-11-11 18:51:33 +00:00
|
|
|
if (term_argv[0] != NULL)
|
|
|
|
{
|
|
|
|
gchar *tmp = term_argv[0];
|
2008-02-27 13:17:29 +00:00
|
|
|
/* g_find_program_in_path checks tmp exists and is executable */
|
2006-11-11 18:51:33 +00:00
|
|
|
term_argv[0] = g_find_program_in_path(tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
}
|
|
|
|
if (term_argv[0] == NULL)
|
|
|
|
{
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE,
|
2007-09-09 16:13:30 +00:00
|
|
|
_("Could not find terminal \"%s\" "
|
2008-05-16 12:08:39 +00:00
|
|
|
"(check path for Terminal tool setting in Preferences)"), tool_prefs.term_cmd);
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2007-01-14 17:09:17 +00:00
|
|
|
utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string,
|
2007-03-03 13:14:41 +00:00
|
|
|
locale_term_cmd, NULL);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_strfreev(term_argv);
|
|
|
|
return (GPid) 1;
|
|
|
|
}
|
2006-01-18 12:11:44 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* RUN_SCRIPT_CMD should be ok in UTF8 without converting in locale because
|
|
|
|
* it contains no umlauts */
|
|
|
|
working_dir = g_path_get_dirname(locale_filename); /** TODO do we need project support here? */
|
2007-11-04 19:26:02 +00:00
|
|
|
script_name = g_build_filename(working_dir, RUN_SCRIPT_CMD, NULL);
|
|
|
|
if (! build_create_shellscript(script_name, locale_cmd_string, TRUE))
|
2006-11-11 18:51:33 +00:00
|
|
|
{
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Failed to execute \"%s\" (start-script could not be created)"),
|
2007-03-05 12:44:02 +00:00
|
|
|
executable);
|
2007-01-14 17:09:17 +00:00
|
|
|
utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string,
|
2007-11-04 19:26:02 +00:00
|
|
|
locale_term_cmd, working_dir, NULL);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_strfreev(term_argv);
|
|
|
|
return (GPid) 1;
|
|
|
|
}
|
2007-11-04 19:26:02 +00:00
|
|
|
g_free(working_dir);
|
2006-11-11 18:51:33 +00:00
|
|
|
|
|
|
|
argv = g_new0(gchar *, term_argv_len + 3);
|
|
|
|
for (i = 0; i < term_argv_len; i++)
|
|
|
|
{
|
|
|
|
argv[i] = g_strdup(term_argv[i]);
|
|
|
|
}
|
|
|
|
#ifdef G_OS_WIN32
|
2008-02-27 13:17:29 +00:00
|
|
|
/* command line arguments only for cmd.exe */
|
2007-11-04 19:26:02 +00:00
|
|
|
if (strstr(argv[0], "cmd.exe") != NULL)
|
|
|
|
{
|
|
|
|
argv[term_argv_len ] = g_strdup("/Q /C");
|
|
|
|
argv[term_argv_len + 1] = script_name;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
argv[term_argv_len ] = script_name;
|
|
|
|
argv[term_argv_len + 1] = NULL;
|
|
|
|
}
|
2006-11-11 18:51:33 +00:00
|
|
|
#else
|
|
|
|
argv[term_argv_len ] = g_strdup("-e");
|
2007-11-04 19:26:02 +00:00
|
|
|
argv[term_argv_len + 1] = script_name;
|
2006-09-11 11:13:36 +00:00
|
|
|
#endif
|
2006-11-11 18:51:33 +00:00
|
|
|
argv[term_argv_len + 2] = NULL;
|
|
|
|
|
|
|
|
|
2007-11-04 19:26:02 +00:00
|
|
|
if (! g_spawn_async(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
|
|
|
|
NULL, NULL, &(run_info.pid), &error))
|
2006-01-18 12:11:44 +00:00
|
|
|
{
|
2007-11-04 19:26:02 +00:00
|
|
|
geany_debug("g_spawn_async() failed: %s", error->message);
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Process failed (%s)"), error->message);
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2007-01-14 17:09:17 +00:00
|
|
|
utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string,
|
2007-03-03 13:14:41 +00:00
|
|
|
locale_term_cmd, NULL);
|
2006-01-18 12:11:44 +00:00
|
|
|
g_strfreev(argv);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_strfreev(term_argv);
|
2006-01-18 12:11:44 +00:00
|
|
|
g_error_free(error);
|
|
|
|
error = NULL;
|
|
|
|
return (GPid) 0;
|
|
|
|
}
|
|
|
|
|
2006-11-29 10:29:34 +00:00
|
|
|
if (run_info.pid > 0)
|
2006-11-11 18:51:33 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/*setpgid(0, getppid());*/
|
2006-11-29 10:29:34 +00:00
|
|
|
g_child_watch_add(run_info.pid, (GChildWatchFunc) run_exit_cb, NULL);
|
2008-06-15 13:35:48 +00:00
|
|
|
build_menu_update(doc);
|
2006-11-11 18:51:33 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 17:09:17 +00:00
|
|
|
utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string,
|
2007-03-03 13:14:41 +00:00
|
|
|
locale_term_cmd, NULL);
|
2006-01-18 12:11:44 +00:00
|
|
|
g_strfreev(argv);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_strfreev(term_argv);
|
2006-04-27 18:06:35 +00:00
|
|
|
|
2006-11-29 10:29:34 +00:00
|
|
|
return run_info.pid;
|
2006-01-18 12:11:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* get curfile.o in locale encoding from document::file_name */
|
2008-06-15 13:35:48 +00:00
|
|
|
static gchar *get_object_filename(GeanyDocument *doc)
|
2006-10-16 14:15:04 +00:00
|
|
|
{
|
|
|
|
gchar *locale_filename, *short_file, *noext, *object_file;
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc->file_name == NULL) return NULL;
|
2006-10-16 14:15:04 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
2006-10-16 14:15:04 +00:00
|
|
|
|
|
|
|
short_file = g_path_get_basename(locale_filename);
|
|
|
|
g_free(locale_filename);
|
|
|
|
|
|
|
|
noext = utils_remove_ext_from_filename(short_file);
|
|
|
|
g_free(short_file);
|
|
|
|
|
|
|
|
object_file = g_strdup_printf("%s.o", noext);
|
|
|
|
g_free(noext);
|
2006-10-24 18:02:38 +00:00
|
|
|
|
2006-10-16 14:15:04 +00:00
|
|
|
return object_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_make_file(GeanyDocument *doc, gint build_opts)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-02-28 17:24:22 +00:00
|
|
|
GString *cmdstr;
|
2007-10-28 17:02:36 +00:00
|
|
|
gchar *dir = NULL;
|
2007-02-28 17:24:22 +00:00
|
|
|
GPid pid;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL || doc->file_name == NULL)
|
|
|
|
return (GPid) 1;
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2008-05-16 12:08:39 +00:00
|
|
|
cmdstr = g_string_new(tool_prefs.make_cmd);
|
2007-02-28 17:24:22 +00:00
|
|
|
g_string_append_c(cmdstr, ' ');
|
2006-10-24 18:02:38 +00:00
|
|
|
|
2006-10-16 14:15:04 +00:00
|
|
|
if (build_opts == GBO_MAKE_OBJECT)
|
|
|
|
{
|
2007-02-28 17:24:22 +00:00
|
|
|
gchar *tmp;
|
|
|
|
|
|
|
|
build_info.type = build_opts;
|
2008-06-15 13:35:48 +00:00
|
|
|
tmp = get_object_filename(doc);
|
2007-02-28 17:24:22 +00:00
|
|
|
g_string_append(cmdstr, tmp);
|
|
|
|
g_free(tmp);
|
2006-10-16 14:15:04 +00:00
|
|
|
}
|
2006-10-16 14:41:57 +00:00
|
|
|
else if (build_opts == GBO_MAKE_CUSTOM && build_info.custom_target)
|
2007-02-28 17:24:22 +00:00
|
|
|
{
|
2006-11-11 18:51:33 +00:00
|
|
|
build_info.type = GBO_MAKE_CUSTOM;
|
2007-02-28 17:24:22 +00:00
|
|
|
g_string_append(cmdstr, build_info.custom_target);
|
2007-03-01 11:38:14 +00:00
|
|
|
dir = project_get_make_dir();
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
else /* GBO_MAKE_ALL */
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2006-11-11 18:51:33 +00:00
|
|
|
build_info.type = GBO_MAKE_ALL;
|
2007-02-28 17:24:22 +00:00
|
|
|
g_string_append(cmdstr, "all");
|
2007-03-01 11:38:14 +00:00
|
|
|
dir = project_get_make_dir();
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
pid = build_spawn_cmd(doc, cmdstr->str, dir); /* if dir is NULL, idx filename is used */
|
2007-10-28 17:02:36 +00:00
|
|
|
g_free(dir);
|
2007-02-28 17:24:22 +00:00
|
|
|
g_string_free(cmdstr, TRUE);
|
|
|
|
return pid;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_compile_file(GeanyDocument *doc)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL || doc->file_name == NULL)
|
2008-03-17 17:13:56 +00:00
|
|
|
return (GPid) 1;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-11-11 18:51:33 +00:00
|
|
|
build_info.type = GBO_COMPILE;
|
2008-06-15 13:35:48 +00:00
|
|
|
return build_spawn_cmd(doc, doc->file_type->programs->compiler, NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_link_file(GeanyDocument *doc)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL || doc->file_name == NULL)
|
2007-02-03 17:01:44 +00:00
|
|
|
return (GPid) 1;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-11-11 18:51:33 +00:00
|
|
|
build_info.type = GBO_BUILD;
|
2008-06-15 13:35:48 +00:00
|
|
|
return build_spawn_cmd(doc, doc->file_type->programs->linker, NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-23 12:55:37 +00:00
|
|
|
/* If linking, clear all error indicators in all documents.
|
|
|
|
* Otherwise, just clear error indicators in document idx. */
|
2008-06-15 13:35:48 +00:00
|
|
|
static void clear_errors(GeanyDocument *doc)
|
2007-04-23 12:55:37 +00:00
|
|
|
{
|
|
|
|
switch (build_info.type)
|
|
|
|
{
|
|
|
|
case GBO_COMPILE:
|
|
|
|
case GBO_MAKE_OBJECT:
|
2008-06-15 13:35:48 +00:00
|
|
|
editor_clear_indicators(doc);
|
2007-04-23 12:55:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GBO_BUILD:
|
|
|
|
case GBO_MAKE_ALL:
|
|
|
|
case GBO_MAKE_CUSTOM:
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
2008-05-29 17:00:54 +00:00
|
|
|
for (i = 0; i < documents_array->len; i++)
|
2007-04-23 12:55:37 +00:00
|
|
|
{
|
2008-05-29 17:00:54 +00:00
|
|
|
if (documents[i]->is_valid)
|
2008-06-15 13:35:48 +00:00
|
|
|
editor_clear_indicators(documents[i]);
|
2007-04-23 12:55:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-06 17:07:26 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
/* cmd is a command line separated with spaces, first element will be escaped with double quotes
|
|
|
|
* and a newly allocated string will be returned */
|
|
|
|
static gchar *quote_executable(const gchar *cmd)
|
|
|
|
{
|
|
|
|
gchar **fields;
|
|
|
|
gchar *result;
|
|
|
|
|
|
|
|
if (! NZV(cmd))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fields = g_strsplit(cmd, " ", 2);
|
|
|
|
if (fields == NULL || g_strv_length(fields) != 2)
|
|
|
|
return g_strdup(cmd);
|
|
|
|
|
|
|
|
result = g_strconcat("\"", fields[0], "\" ", fields[1], NULL);
|
|
|
|
|
|
|
|
g_strfreev(fields);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-03-01 11:38:14 +00:00
|
|
|
/* dir is the UTF-8 working directory to run cmd in. It can be NULL to use the
|
|
|
|
* idx document directory */
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *dir)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2007-02-01 14:42:25 +00:00
|
|
|
gchar **argv;
|
2005-11-22 12:26:26 +00:00
|
|
|
gchar *working_dir;
|
2006-04-27 18:06:35 +00:00
|
|
|
gchar *utf8_working_dir;
|
2005-11-22 12:26:26 +00:00
|
|
|
gchar *cmd_string;
|
2006-04-27 18:06:35 +00:00
|
|
|
gchar *utf8_cmd_string;
|
|
|
|
gchar *locale_filename;
|
|
|
|
gchar *executable;
|
|
|
|
gchar *tmp;
|
2005-11-22 12:26:26 +00:00
|
|
|
gint stdout_fd;
|
|
|
|
gint stderr_fd;
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
g_return_val_if_fail(doc != NULL, (GPid) 1);
|
2006-08-14 15:02:52 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
clear_errors(doc);
|
2007-09-27 15:10:22 +00:00
|
|
|
setptr(current_dir_entered, NULL);
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
2006-04-27 18:06:35 +00:00
|
|
|
executable = utils_remove_ext_from_filename(locale_filename);
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2007-02-28 17:24:22 +00:00
|
|
|
cmd_string = g_strdup(cmd);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* replace %f and %e in the command string */
|
2006-04-27 18:06:35 +00:00
|
|
|
tmp = g_path_get_basename(locale_filename);
|
|
|
|
cmd_string = utils_str_replace(cmd_string, "%f", tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
tmp = g_path_get_basename(executable);
|
|
|
|
cmd_string = utils_str_replace(cmd_string, "%e", tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
g_free(executable);
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2007-11-01 12:54:38 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2008-02-27 13:17:29 +00:00
|
|
|
/* due to g_shell_parse_argv() we need to enclose the command(first element) of cmd_string with
|
|
|
|
* "" if the command contains a full path(i.e. backslashes) otherwise the backslashes will be
|
|
|
|
* eaten by g_shell_parse_argv(). */
|
2007-11-06 17:07:26 +00:00
|
|
|
setptr(cmd_string, quote_executable(cmd_string));
|
2007-11-04 09:57:47 +00:00
|
|
|
if (! g_shell_parse_argv(cmd_string, NULL, &argv, NULL))
|
2008-02-27 13:17:29 +00:00
|
|
|
/* if automatic parsing failed, fall back to simple, unsafe argv creation */
|
2007-11-04 09:57:47 +00:00
|
|
|
argv = g_strsplit(cmd_string, " ", 0);
|
2007-11-01 12:54:38 +00:00
|
|
|
#else
|
2006-04-27 18:06:35 +00:00
|
|
|
argv = g_new0(gchar *, 4);
|
2005-11-22 12:26:26 +00:00
|
|
|
argv[0] = g_strdup("/bin/sh");
|
|
|
|
argv[1] = g_strdup("-c");
|
|
|
|
argv[2] = cmd_string;
|
|
|
|
argv[3] = NULL;
|
2007-11-01 12:54:38 +00:00
|
|
|
#endif
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-03-01 11:38:14 +00:00
|
|
|
utf8_cmd_string = utils_get_utf8_from_locale(cmd_string);
|
|
|
|
utf8_working_dir = (dir != NULL) ? g_strdup(dir) :
|
2008-06-15 13:35:48 +00:00
|
|
|
g_path_get_dirname(doc->file_name);
|
2007-03-01 11:38:14 +00:00
|
|
|
working_dir = utils_get_locale_from_utf8(utf8_working_dir);
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
gtk_list_store_clear(msgwindow.store_compiler);
|
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_COMPILER);
|
2007-03-01 11:38:14 +00:00
|
|
|
msgwin_compiler_add_fmt(COLOR_BLUE, _("%s (in directory: %s)"), utf8_cmd_string, utf8_working_dir);
|
|
|
|
g_free(utf8_working_dir);
|
|
|
|
g_free(utf8_cmd_string);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* set the build info for the message window */
|
2006-11-15 17:07:15 +00:00
|
|
|
g_free(build_info.dir);
|
|
|
|
build_info.dir = g_strdup(working_dir);
|
2008-06-15 13:35:48 +00:00
|
|
|
build_info.file_type_id = FILETYPE_ID(doc->file_type);
|
2006-08-14 15:02:52 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
if (! g_spawn_async_with_pipes(working_dir, argv, NULL, G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
|
2006-11-11 18:51:33 +00:00
|
|
|
NULL, NULL, &(build_info.pid), NULL, &stdout_fd, &stderr_fd, &error))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2006-01-18 12:11:44 +00:00
|
|
|
geany_debug("g_spawn_async_with_pipes() failed: %s", error->message);
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Process failed (%s)"), error->message);
|
2005-11-22 12:26:26 +00:00
|
|
|
g_strfreev(argv);
|
|
|
|
g_error_free(error);
|
2006-03-02 23:28:52 +00:00
|
|
|
g_free(working_dir);
|
2006-04-27 18:06:35 +00:00
|
|
|
g_free(locale_filename);
|
2005-11-22 12:26:26 +00:00
|
|
|
error = NULL;
|
|
|
|
return (GPid) 0;
|
|
|
|
}
|
|
|
|
|
2006-11-11 18:51:33 +00:00
|
|
|
if (build_info.pid > 0)
|
|
|
|
{
|
|
|
|
g_child_watch_add(build_info.pid, (GChildWatchFunc) build_exit_cb, NULL);
|
2008-06-15 13:35:48 +00:00
|
|
|
build_menu_update(doc);
|
2006-11-11 18:51:33 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* use GIOChannels to monitor stdout and stderr */
|
2006-07-13 14:30:44 +00:00
|
|
|
utils_set_up_io_channel(stdout_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
|
2007-03-01 21:45:43 +00:00
|
|
|
TRUE, build_iofunc, GINT_TO_POINTER(0));
|
2006-07-13 14:30:44 +00:00
|
|
|
utils_set_up_io_channel(stderr_fd, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL,
|
2007-03-01 21:45:43 +00:00
|
|
|
TRUE, build_iofunc, GINT_TO_POINTER(1));
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
g_strfreev(argv);
|
|
|
|
g_free(working_dir);
|
2006-04-27 18:06:35 +00:00
|
|
|
g_free(locale_filename);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-11-11 18:51:33 +00:00
|
|
|
return build_info.pid;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-24 16:12:12 +00:00
|
|
|
/* Checks if the executable file corresponding to document idx exists.
|
|
|
|
* Returns the name part of the filename, without extension.
|
|
|
|
* Returns NULL if executable file doesn't exist. */
|
2007-05-25 12:03:35 +00:00
|
|
|
static gchar *get_build_executable(const gchar *locale_filename, gboolean check_exists,
|
|
|
|
filetype_id ft_id)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-05-24 16:12:12 +00:00
|
|
|
gchar *long_executable = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
struct stat st;
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
long_executable = utils_remove_ext_from_filename(locale_filename);
|
2006-09-11 11:13:36 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2007-05-24 16:12:12 +00:00
|
|
|
setptr(long_executable, g_strconcat(long_executable, ".exe", NULL));
|
2006-09-11 11:13:36 +00:00
|
|
|
#endif
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-05-25 12:03:35 +00:00
|
|
|
if (check_exists)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-05-24 16:12:12 +00:00
|
|
|
gchar *check_executable = NULL;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* add .class extension for JAVA source files (only for stat) */
|
2007-05-25 12:03:35 +00:00
|
|
|
if (ft_id == GEANY_FILETYPES_JAVA)
|
2006-09-11 11:13:36 +00:00
|
|
|
{
|
|
|
|
#ifdef G_OS_WIN32
|
2007-03-03 16:54:04 +00:00
|
|
|
gchar *tmp;
|
2008-02-27 13:17:29 +00:00
|
|
|
/* there is already the extension .exe, so first remove it and then add .class */
|
2007-03-03 16:54:04 +00:00
|
|
|
tmp = utils_remove_ext_from_filename(long_executable);
|
|
|
|
check_executable = g_strconcat(tmp, ".class", NULL);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* store the filename without "exe" extension for Java, tmp will be freed by setptr */
|
2007-11-29 18:18:52 +00:00
|
|
|
setptr(long_executable, tmp);
|
2006-09-11 11:13:36 +00:00
|
|
|
#else
|
2006-04-27 18:06:35 +00:00
|
|
|
check_executable = g_strconcat(long_executable, ".class", NULL);
|
2006-09-11 11:13:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
2006-04-27 18:06:35 +00:00
|
|
|
else
|
|
|
|
check_executable = g_strdup(long_executable);
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* check for filename extension and abort if filename doesn't have one */
|
2007-02-01 14:42:25 +00:00
|
|
|
if (utils_str_equal(locale_filename, check_executable))
|
|
|
|
{
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Command stopped because the current file has no extension."));
|
2007-02-01 14:42:25 +00:00
|
|
|
utils_beep();
|
2007-05-24 16:12:12 +00:00
|
|
|
g_free(check_executable);
|
|
|
|
return NULL;
|
2007-02-01 14:42:25 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* check whether executable exists */
|
2007-04-16 15:58:34 +00:00
|
|
|
if (g_stat(check_executable, &st) != 0)
|
2006-04-27 18:06:35 +00:00
|
|
|
{
|
2007-05-24 16:12:12 +00:00
|
|
|
gchar *utf8_check_executable = utils_get_utf8_from_locale(check_executable);
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Failed to execute \"%s\" (make sure it is already built)"),
|
2006-04-27 18:06:35 +00:00
|
|
|
utf8_check_executable);
|
2007-05-24 16:12:12 +00:00
|
|
|
g_free(utf8_check_executable);
|
|
|
|
g_free(check_executable);
|
|
|
|
return NULL;
|
2006-04-27 18:06:35 +00:00
|
|
|
}
|
2007-11-29 18:18:52 +00:00
|
|
|
g_free(check_executable);
|
2006-02-01 20:21:34 +00:00
|
|
|
}
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* remove path */
|
2007-05-24 16:12:12 +00:00
|
|
|
setptr(long_executable, g_path_get_basename(long_executable));
|
|
|
|
return long_executable;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-17 16:58:26 +00:00
|
|
|
/* Returns: NULL if there was an error, or the working directory the script was created in.
|
|
|
|
* vte_cmd_nonscript is the location of a string which is filled with the command to be used
|
|
|
|
* when vc->skip_run_script is set, otherwise it will be set to NULL */
|
2008-06-15 13:35:48 +00:00
|
|
|
static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript)
|
2007-05-24 16:12:12 +00:00
|
|
|
{
|
|
|
|
gchar *locale_filename = NULL;
|
2007-05-25 12:03:35 +00:00
|
|
|
gboolean have_project;
|
|
|
|
GeanyProject *project = app->project;
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyFiletype *ft = doc->file_type;
|
2007-05-25 12:03:35 +00:00
|
|
|
gboolean check_exists;
|
2007-05-24 16:12:12 +00:00
|
|
|
gchar *cmd = NULL;
|
|
|
|
gchar *executable = NULL;
|
|
|
|
gchar *working_dir = NULL;
|
|
|
|
gboolean autoclose = FALSE;
|
|
|
|
gboolean result = FALSE;
|
|
|
|
gchar *tmp;
|
|
|
|
|
2007-12-17 16:58:26 +00:00
|
|
|
if (vte_cmd_nonscript != NULL)
|
|
|
|
*vte_cmd_nonscript = NULL;
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
locale_filename = utils_get_locale_from_utf8(doc->file_name);
|
2007-05-24 16:12:12 +00:00
|
|
|
|
2007-05-25 12:03:35 +00:00
|
|
|
have_project = (project != NULL && NZV(project->run_cmd));
|
|
|
|
cmd = (have_project) ?
|
|
|
|
project->run_cmd :
|
|
|
|
ft->programs->run_cmd;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* only check for existing executable, if executable is required by %e */
|
2007-05-25 12:03:35 +00:00
|
|
|
check_exists = (strstr(cmd, "%e") != NULL);
|
|
|
|
executable = get_build_executable(locale_filename, check_exists, FILETYPE_ID(ft));
|
2007-05-24 16:12:12 +00:00
|
|
|
if (executable == NULL)
|
|
|
|
{
|
|
|
|
g_free(locale_filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-10-28 17:02:36 +00:00
|
|
|
if (have_project)
|
|
|
|
{
|
2008-01-11 16:53:25 +00:00
|
|
|
gchar *project_base_path = project_get_base_path();
|
2007-10-28 17:02:36 +00:00
|
|
|
working_dir = utils_get_locale_from_utf8(project_base_path);
|
|
|
|
g_free(project_base_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
working_dir = g_path_get_dirname(locale_filename);
|
2007-05-25 12:03:35 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* only test whether working dir exists, don't change it or else Windows support will break
|
|
|
|
* (gspawn-win32-helper.exe is used by GLib and must be in $PATH which means current working
|
|
|
|
* dir where geany.exe was started from, so we can't change it) */
|
2007-11-04 19:26:02 +00:00
|
|
|
if (! g_file_test(working_dir, G_FILE_TEST_EXISTS) ||
|
|
|
|
! g_file_test(working_dir, G_FILE_TEST_IS_DIR))
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-12-17 16:58:26 +00:00
|
|
|
gchar *utf8_working_dir = utils_get_utf8_from_locale(working_dir);
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Failed to change the working directory to \"%s\""), utf8_working_dir);
|
2007-12-17 16:58:26 +00:00
|
|
|
utils_free_pointers(utf8_working_dir, working_dir, executable, locale_filename, NULL);
|
2007-05-24 16:12:12 +00:00
|
|
|
return NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2006-06-29 14:00:09 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* replace %f and %e in the run_cmd string */
|
2007-05-25 12:03:35 +00:00
|
|
|
cmd = g_strdup(cmd);
|
2006-04-27 18:06:35 +00:00
|
|
|
tmp = g_path_get_basename(locale_filename);
|
|
|
|
cmd = utils_str_replace(cmd, "%f", tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
cmd = utils_str_replace(cmd, "%e", executable);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-12-10 21:29:04 +00:00
|
|
|
#ifdef HAVE_VTE
|
|
|
|
if (vte_info.load_vte && vc != NULL && vc->run_in_vte)
|
2007-12-17 16:58:26 +00:00
|
|
|
{
|
|
|
|
if (vc->skip_run_script)
|
|
|
|
{
|
|
|
|
if (vte_cmd_nonscript != NULL)
|
|
|
|
*vte_cmd_nonscript = cmd;
|
|
|
|
|
|
|
|
utils_free_pointers(executable, locale_filename, NULL);
|
|
|
|
return working_dir;
|
|
|
|
}
|
|
|
|
else
|
2008-02-27 13:17:29 +00:00
|
|
|
/* don't wait for user input at the end of script when we are running in VTE */
|
2007-12-17 16:58:26 +00:00
|
|
|
autoclose = TRUE;
|
|
|
|
}
|
2006-12-10 21:29:04 +00:00
|
|
|
#endif
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* RUN_SCRIPT_CMD should be ok in UTF8 without converting in locale because it
|
|
|
|
* contains no umlauts */
|
2007-11-04 19:26:02 +00:00
|
|
|
tmp = g_build_filename(working_dir, RUN_SCRIPT_CMD, NULL);
|
|
|
|
result = build_create_shellscript(tmp, cmd, autoclose);
|
2007-05-24 16:12:12 +00:00
|
|
|
if (! result)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
2007-05-24 16:12:12 +00:00
|
|
|
gchar *utf8_cmd = utils_get_utf8_from_locale(cmd);
|
|
|
|
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Failed to execute \"%s\" (start-script could not be created)"),
|
2007-05-24 16:12:12 +00:00
|
|
|
utf8_cmd);
|
|
|
|
g_free(utf8_cmd);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 16:58:26 +00:00
|
|
|
utils_free_pointers(tmp, cmd, executable, locale_filename, NULL);
|
2007-03-03 13:14:41 +00:00
|
|
|
|
|
|
|
if (result)
|
|
|
|
return working_dir;
|
|
|
|
|
|
|
|
g_free(working_dir);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
static GPid build_run_cmd(GeanyDocument *doc)
|
2007-03-03 13:14:41 +00:00
|
|
|
{
|
|
|
|
gchar *working_dir;
|
2007-12-17 16:58:26 +00:00
|
|
|
gchar *vte_cmd_nonscript = NULL;
|
2007-03-03 13:14:41 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL || doc->file_name == NULL)
|
2007-11-04 19:26:02 +00:00
|
|
|
return (GPid) 0;
|
2007-03-05 12:13:09 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
working_dir = prepare_run_script(doc, &vte_cmd_nonscript);
|
2007-03-03 13:14:41 +00:00
|
|
|
if (working_dir == NULL)
|
|
|
|
{
|
2007-11-04 19:26:02 +00:00
|
|
|
return (GPid) 0;
|
2007-03-03 13:14:41 +00:00
|
|
|
}
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
run_info.file_type_id = FILETYPE_ID(doc->file_type);
|
2007-03-03 13:14:41 +00:00
|
|
|
|
2006-12-10 21:29:04 +00:00
|
|
|
#ifdef HAVE_VTE
|
|
|
|
if (vte_info.load_vte && vc != NULL && vc->run_in_vte)
|
2006-04-27 18:06:35 +00:00
|
|
|
{
|
2007-12-19 15:37:10 +00:00
|
|
|
GeanyProject *project = app->project;
|
2007-12-17 16:58:26 +00:00
|
|
|
gchar *vte_cmd;
|
|
|
|
|
|
|
|
if (vc->skip_run_script)
|
|
|
|
{
|
|
|
|
setptr(vte_cmd_nonscript, utils_get_utf8_from_locale(vte_cmd_nonscript));
|
|
|
|
vte_cmd = g_strconcat(vte_cmd_nonscript, "\n", NULL);
|
|
|
|
g_free(vte_cmd_nonscript);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
vte_cmd = g_strconcat(RUN_SCRIPT_CMD, "\n", NULL);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* change into current directory if it is not done by default or we have a project and
|
|
|
|
* project run command(working_dir is already set accordingly) */
|
2007-12-17 16:58:26 +00:00
|
|
|
if (! vc->follow_path || (project != NULL && NZV(project->run_cmd)))
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* we need to convert the working_dir back to UTF-8 because the VTE expects it */
|
2007-12-17 16:58:26 +00:00
|
|
|
gchar *utf8_working_dir = utils_get_utf8_from_locale(working_dir);
|
|
|
|
vte_cwd(utf8_working_dir, TRUE);
|
|
|
|
g_free(utf8_working_dir);
|
|
|
|
}
|
2007-12-06 16:38:13 +00:00
|
|
|
if (! vte_send_cmd(vte_cmd))
|
|
|
|
ui_set_statusbar(FALSE,
|
|
|
|
_("Could not execute the file in the VTE because it probably contains a command."));
|
2006-12-10 21:29:04 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* show the VTE */
|
2006-12-10 21:29:04 +00:00
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_VTE);
|
|
|
|
gtk_widget_grab_focus(vc->vte);
|
2006-12-13 16:41:25 +00:00
|
|
|
msgwin_show_hide(TRUE);
|
2006-12-10 21:29:04 +00:00
|
|
|
|
|
|
|
run_info.pid = 1;
|
|
|
|
|
2007-03-03 13:14:41 +00:00
|
|
|
g_free(vte_cmd);
|
2006-04-27 18:06:35 +00:00
|
|
|
}
|
2006-12-10 21:29:04 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2007-03-03 13:14:41 +00:00
|
|
|
gchar *locale_term_cmd = NULL;
|
|
|
|
gchar **term_argv = NULL;
|
|
|
|
guint term_argv_len, i;
|
|
|
|
gchar **argv = NULL;
|
|
|
|
|
|
|
|
/* get the terminal path */
|
2008-05-16 12:08:39 +00:00
|
|
|
locale_term_cmd = utils_get_locale_from_utf8(tool_prefs.term_cmd);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* split the term_cmd, so arguments will work too */
|
2007-03-03 13:14:41 +00:00
|
|
|
term_argv = g_strsplit(locale_term_cmd, " ", -1);
|
|
|
|
term_argv_len = g_strv_length(term_argv);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* check that terminal exists (to prevent misleading error messages) */
|
2007-03-03 13:14:41 +00:00
|
|
|
if (term_argv[0] != NULL)
|
|
|
|
{
|
|
|
|
gchar *tmp = term_argv[0];
|
2008-02-27 13:17:29 +00:00
|
|
|
/* g_find_program_in_path checks whether tmp exists and is executable */
|
2007-03-03 13:14:41 +00:00
|
|
|
term_argv[0] = g_find_program_in_path(tmp);
|
|
|
|
g_free(tmp);
|
|
|
|
}
|
|
|
|
if (term_argv[0] == NULL)
|
|
|
|
{
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE,
|
2007-09-09 16:13:30 +00:00
|
|
|
_("Could not find terminal \"%s\" "
|
2008-05-16 12:08:39 +00:00
|
|
|
"(check path for Terminal tool setting in Preferences)"), tool_prefs.term_cmd);
|
2007-03-03 13:14:41 +00:00
|
|
|
run_info.pid = (GPid) 1;
|
|
|
|
goto free_strings;
|
|
|
|
}
|
|
|
|
|
2006-12-10 21:29:04 +00:00
|
|
|
argv = g_new0(gchar *, term_argv_len + 3);
|
|
|
|
for (i = 0; i < term_argv_len; i++)
|
|
|
|
{
|
|
|
|
argv[i] = g_strdup(term_argv[i]);
|
|
|
|
}
|
2006-09-11 11:13:36 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2008-02-27 13:17:29 +00:00
|
|
|
/* command line arguments only for cmd.exe */
|
2007-11-04 09:57:47 +00:00
|
|
|
if (strstr(argv[0], "cmd.exe") != NULL)
|
|
|
|
{
|
|
|
|
argv[term_argv_len ] = g_strdup("/Q /C");
|
2007-11-04 19:26:02 +00:00
|
|
|
argv[term_argv_len + 1] = g_strdup(RUN_SCRIPT_CMD);
|
2007-11-04 09:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
2007-11-04 19:26:02 +00:00
|
|
|
{
|
|
|
|
argv[term_argv_len ] = g_strdup(RUN_SCRIPT_CMD);
|
|
|
|
argv[term_argv_len + 1] = NULL;
|
|
|
|
}
|
2006-09-11 11:13:36 +00:00
|
|
|
#else
|
2006-12-10 21:29:04 +00:00
|
|
|
argv[term_argv_len ] = g_strdup("-e");
|
2008-04-20 11:43:07 +00:00
|
|
|
argv[term_argv_len + 1] = g_strconcat("/bin/sh ", RUN_SCRIPT_CMD, NULL);
|
2006-09-11 11:13:36 +00:00
|
|
|
#endif
|
2006-12-10 21:29:04 +00:00
|
|
|
argv[term_argv_len + 2] = NULL;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-11-04 19:26:02 +00:00
|
|
|
if (! g_spawn_async(working_dir, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD,
|
|
|
|
NULL, NULL, &(run_info.pid), &error))
|
2006-12-10 21:29:04 +00:00
|
|
|
{
|
2007-11-04 19:26:02 +00:00
|
|
|
geany_debug("g_spawn_async() failed: %s", error->message);
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Process failed (%s)"), error->message);
|
2007-11-04 19:26:02 +00:00
|
|
|
g_unlink(RUN_SCRIPT_CMD);
|
2006-12-10 21:29:04 +00:00
|
|
|
g_error_free(error);
|
|
|
|
error = NULL;
|
2007-03-03 13:14:41 +00:00
|
|
|
run_info.pid = (GPid) 0;
|
2006-12-10 21:29:04 +00:00
|
|
|
}
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-12-10 21:29:04 +00:00
|
|
|
if (run_info.pid > 0)
|
|
|
|
{
|
|
|
|
g_child_watch_add(run_info.pid, (GChildWatchFunc) run_exit_cb, NULL);
|
2008-06-15 13:35:48 +00:00
|
|
|
build_menu_update(doc);
|
2006-12-10 21:29:04 +00:00
|
|
|
}
|
2007-03-03 13:14:41 +00:00
|
|
|
free_strings:
|
|
|
|
g_strfreev(argv);
|
|
|
|
g_strfreev(term_argv);
|
|
|
|
g_free(locale_term_cmd);
|
2006-11-11 18:51:33 +00:00
|
|
|
}
|
2006-02-10 20:58:08 +00:00
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
g_free(working_dir);
|
2007-03-03 13:14:41 +00:00
|
|
|
return run_info.pid;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-27 18:06:35 +00:00
|
|
|
static gboolean build_iofunc(GIOChannel *ioc, GIOCondition cond, gpointer data)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
|
|
|
if (cond & (G_IO_IN | G_IO_PRI))
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/*GIOStatus s;*/
|
2007-09-27 15:10:22 +00:00
|
|
|
gchar *msg;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
while (g_io_channel_read_line(ioc, &msg, NULL, NULL, NULL) && msg)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/*if (s != G_IO_STATUS_NORMAL && s != G_IO_STATUS_EOF) break;*/
|
2006-09-08 10:20:15 +00:00
|
|
|
gint color;
|
2007-01-04 11:49:14 +00:00
|
|
|
gchar *tmp;
|
|
|
|
|
2006-09-08 10:20:15 +00:00
|
|
|
color = (GPOINTER_TO_INT(data)) ? COLOR_DARK_RED : COLOR_BLACK;
|
|
|
|
g_strstrip(msg);
|
2006-06-27 15:29:33 +00:00
|
|
|
|
2007-01-04 11:49:14 +00:00
|
|
|
if (build_parse_make_dir(msg, &tmp))
|
|
|
|
{
|
2007-09-27 15:10:22 +00:00
|
|
|
setptr(current_dir_entered, tmp);
|
2006-12-30 16:16:59 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 16:30:54 +00:00
|
|
|
if (editor_prefs.use_indicators)
|
2006-06-27 15:29:33 +00:00
|
|
|
{
|
|
|
|
gchar *filename;
|
|
|
|
gint line;
|
2006-12-30 16:16:59 +00:00
|
|
|
|
2007-09-27 15:10:22 +00:00
|
|
|
msgwin_parse_compiler_error_line(msg, current_dir_entered,
|
|
|
|
&filename, &line);
|
2006-09-08 10:20:15 +00:00
|
|
|
if (line != -1 && filename != NULL)
|
2006-06-13 19:37:21 +00:00
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_find_by_filename(filename);
|
2007-09-27 15:10:22 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
editor_set_indicator_on_line(doc, line - 1); /* will check valid idx */
|
2008-02-27 13:17:29 +00:00
|
|
|
color = COLOR_RED; /* error message parsed on the line */
|
2006-06-13 19:37:21 +00:00
|
|
|
}
|
2006-06-27 15:29:33 +00:00
|
|
|
g_free(filename);
|
2006-06-13 19:37:21 +00:00
|
|
|
}
|
2006-12-08 15:50:10 +00:00
|
|
|
msgwin_compiler_add(color, msg);
|
2005-11-22 12:26:26 +00:00
|
|
|
|
|
|
|
g_free(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-04 11:49:14 +00:00
|
|
|
gboolean build_parse_make_dir(const gchar *string, gchar **prefix)
|
2006-12-30 16:16:59 +00:00
|
|
|
{
|
2007-01-04 11:49:14 +00:00
|
|
|
const gchar *pos;
|
2006-12-30 16:16:59 +00:00
|
|
|
|
|
|
|
*prefix = NULL;
|
|
|
|
|
2007-01-04 11:49:14 +00:00
|
|
|
if (string == NULL)
|
2006-12-30 16:16:59 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2007-01-04 11:49:14 +00:00
|
|
|
if ((pos = strstr(string, "Entering directory")) != NULL)
|
2006-12-30 16:16:59 +00:00
|
|
|
{
|
2007-01-04 11:49:14 +00:00
|
|
|
gsize len;
|
|
|
|
gchar *input;
|
2006-12-30 16:16:59 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* get the start of the path */
|
2007-01-04 11:49:14 +00:00
|
|
|
pos = strstr(string, "/");
|
2006-12-30 16:16:59 +00:00
|
|
|
|
2007-01-04 11:49:14 +00:00
|
|
|
if (pos == NULL)
|
2006-12-30 16:16:59 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2007-01-04 11:49:14 +00:00
|
|
|
input = g_strdup(pos);
|
2006-12-30 16:16:59 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* kill the ' at the end of the path */
|
2007-01-04 11:49:14 +00:00
|
|
|
len = strlen(input);
|
|
|
|
input[len - 1] = '\0';
|
2008-02-27 13:17:29 +00:00
|
|
|
input = g_realloc(input, len); /* shorten by 1 */
|
2007-01-04 11:49:14 +00:00
|
|
|
*prefix = input;
|
2006-12-30 16:16:59 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-27 11:32:45 +00:00
|
|
|
static void show_build_result_message(gboolean failure)
|
|
|
|
{
|
|
|
|
gchar *msg;
|
|
|
|
|
|
|
|
if (failure)
|
|
|
|
{
|
|
|
|
msg = _("Compilation failed.");
|
2007-01-21 18:22:14 +00:00
|
|
|
msgwin_compiler_add(COLOR_DARK_RED, msg);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* If msgwindow is hidden, user will want to display it to see the error */
|
2007-08-23 11:34:06 +00:00
|
|
|
if (! ui_prefs.msgwindow_visible)
|
2006-11-27 11:32:45 +00:00
|
|
|
{
|
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_COMPILER);
|
2006-12-13 16:41:25 +00:00
|
|
|
msgwin_show_hide(TRUE);
|
2006-11-27 11:32:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (gtk_notebook_get_current_page(GTK_NOTEBOOK(msgwindow.notebook)) != MSG_COMPILER)
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(FALSE, "%s", msg);
|
2006-11-27 11:32:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg = _("Compilation finished successfully.");
|
2007-01-21 18:22:14 +00:00
|
|
|
msgwin_compiler_add(COLOR_BLUE, msg);
|
2007-08-23 11:34:06 +00:00
|
|
|
if (! ui_prefs.msgwindow_visible ||
|
2006-11-27 11:32:45 +00:00
|
|
|
gtk_notebook_get_current_page(GTK_NOTEBOOK(msgwindow.notebook)) != MSG_COMPILER)
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(FALSE, "%s", msg);
|
2006-11-27 11:32:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-18 19:35:42 +00:00
|
|
|
static void build_exit_cb(GPid child_pid, gint status, gpointer user_data)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
|
|
|
#ifdef G_OS_UNIX
|
2006-11-29 10:29:34 +00:00
|
|
|
gboolean failure = FALSE;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-11-29 10:29:34 +00:00
|
|
|
if (WIFEXITED(status))
|
|
|
|
{
|
|
|
|
if (WEXITSTATUS(status) != EXIT_SUCCESS)
|
2006-11-11 18:51:33 +00:00
|
|
|
failure = TRUE;
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
2006-11-29 10:29:34 +00:00
|
|
|
else if (WIFSIGNALED(status))
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* the terminating signal: WTERMSIG (status)); */
|
2006-11-29 10:29:34 +00:00
|
|
|
failure = TRUE;
|
|
|
|
}
|
|
|
|
else
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* any other failure occured */
|
2006-11-29 10:29:34 +00:00
|
|
|
failure = TRUE;
|
|
|
|
}
|
|
|
|
show_build_result_message(failure);
|
2007-11-01 12:54:38 +00:00
|
|
|
#else
|
2008-03-14 16:59:36 +00:00
|
|
|
show_build_result_message(! win32_get_exit_status(child_pid));
|
2006-11-29 10:29:34 +00:00
|
|
|
#endif
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2006-11-29 10:29:34 +00:00
|
|
|
utils_beep();
|
2005-11-22 12:26:26 +00:00
|
|
|
g_spawn_close_pid(child_pid);
|
2006-11-11 18:51:33 +00:00
|
|
|
|
|
|
|
build_info.pid = 0;
|
2008-02-27 13:17:29 +00:00
|
|
|
/* enable build items again */
|
2008-06-15 13:35:48 +00:00
|
|
|
build_menu_update(NULL);
|
2006-11-29 10:29:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void run_exit_cb(GPid child_pid, gint status, gpointer user_data)
|
|
|
|
{
|
|
|
|
g_spawn_close_pid(child_pid);
|
|
|
|
|
|
|
|
run_info.pid = 0;
|
2008-02-27 13:17:29 +00:00
|
|
|
/* reset the stop button and menu item to the original meaning */
|
2008-06-15 13:35:48 +00:00
|
|
|
build_menu_update(NULL);
|
2005-11-22 12:26:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* write a little shellscript to call the executable (similar to anjuta_launcher but "internal")
|
|
|
|
* fname is the full file name (including path) for the script to create */
|
2007-03-03 16:54:04 +00:00
|
|
|
static gboolean build_create_shellscript(const gchar *fname, const gchar *cmd, gboolean autoclose)
|
2005-11-22 12:26:26 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2006-09-11 11:13:36 +00:00
|
|
|
gchar *str;
|
2005-11-22 12:26:26 +00:00
|
|
|
|
2007-07-17 12:04:46 +00:00
|
|
|
fp = g_fopen(fname, "w");
|
2005-11-22 12:26:26 +00:00
|
|
|
if (! fp) return FALSE;
|
2006-09-11 11:13:36 +00:00
|
|
|
#ifdef G_OS_WIN32
|
2007-11-04 19:26:02 +00:00
|
|
|
str = g_strdup_printf("%s\n\n%s\ndel %s\n", cmd, (autoclose) ? "" : "pause", fname);
|
2006-09-11 11:13:36 +00:00
|
|
|
#else
|
2005-11-22 12:26:26 +00:00
|
|
|
str = g_strdup_printf(
|
2006-04-27 18:06:35 +00:00
|
|
|
"#!/bin/sh\n\n%s\n\necho \"\n\n------------------\n(program exited with code: $?)\" \
|
2007-01-19 15:45:43 +00:00
|
|
|
\n\n%s\nrm $0\n", cmd, (autoclose) ? "" :
|
2006-12-10 21:29:04 +00:00
|
|
|
"\necho \"Press return to continue\"\n#to be more compatible with shells like dash\ndummy_var=\"\"\nread dummy_var");
|
2006-09-11 11:13:36 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-22 12:26:26 +00:00
|
|
|
fputs(str, fp);
|
|
|
|
g_free(str);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-04 16:11:59 +00:00
|
|
|
/* note: copied from keybindings.c.
|
|
|
|
* Perhaps the separate Tex menu could be merged with the default build menu?
|
|
|
|
* Then this could be done with Glade and set the accels in keybindings.c. */
|
|
|
|
static void add_menu_accel(KeyBindingGroup *group, guint kb_id,
|
|
|
|
GtkAccelGroup *accel_group, GtkWidget *menuitem)
|
|
|
|
{
|
|
|
|
KeyBinding *kb = &group->keys[kb_id];
|
|
|
|
|
|
|
|
if (kb->key != 0)
|
|
|
|
gtk_widget_add_accelerator(menuitem, "activate", accel_group,
|
|
|
|
kb->key, kb->mods, GTK_ACCEL_VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define GEANY_ADD_WIDGET_ACCEL(kb_id, menuitem) \
|
|
|
|
add_menu_accel(group, kb_id, accel_group, menuitem)
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
static void create_build_menu_gen(BuildMenuItems *menu_items)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *menu, *item = NULL, *image, *separator;
|
|
|
|
GtkAccelGroup *accel_group = gtk_accel_group_new();
|
2008-05-22 14:41:28 +00:00
|
|
|
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(main_widgets.window, "tooltips"));
|
2008-03-12 13:37:39 +00:00
|
|
|
KeyBindingGroup *group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_BUILD);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
|
|
|
menu = gtk_menu_new();
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* compile the code */
|
2006-11-30 15:42:52 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Compile"));
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item, _("Compiles the current file"), NULL);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_COMPILE, item);
|
|
|
|
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);
|
|
|
|
menu_items->item_compile = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* build the code */
|
2006-11-30 15:42:52 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Build"));
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item,
|
|
|
|
_("Builds the current file (generate an executable file)"), NULL);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_LINK, item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_build_activate), NULL);
|
|
|
|
menu_items->item_link = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* build the code with make all */
|
2006-12-12 12:12:20 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Make All"));
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
|
|
|
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);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_MAKE, item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate),
|
|
|
|
GINT_TO_POINTER(GBO_MAKE_ALL));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_make_all = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* build the code with make custom */
|
2006-12-12 12:12:20 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("Make Custom _Target"));
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_MAKEOWNTARGET, item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item, _("Builds the current file with the "
|
|
|
|
"make tool and the specified target"), NULL);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate),
|
|
|
|
GINT_TO_POINTER(GBO_MAKE_CUSTOM));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_make_custom = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* build the code with make object */
|
2006-12-12 12:12:20 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("Make _Object"));
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_MAKEOBJECT, item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item, _("Compiles the current file using the "
|
|
|
|
"make tool"), NULL);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate),
|
|
|
|
GINT_TO_POINTER(GBO_MAKE_OBJECT));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_make_object = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* next error */
|
2006-12-08 15:50:10 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Next Error"));
|
|
|
|
gtk_widget_show(item);
|
2006-12-09 17:03:03 +00:00
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_NEXTERROR, item);
|
2006-12-08 15:50:10 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_next_error), NULL);
|
|
|
|
menu_items->item_next_error = item;
|
|
|
|
|
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* execute the code */
|
2006-11-30 15:42:52 +00:00
|
|
|
item = gtk_image_menu_item_new_from_stock("gtk-execute", accel_group);
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item, _("Run or view the current file"), NULL);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_RUN, item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_execute_activate), NULL);
|
|
|
|
menu_items->item_exec = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
separator = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(separator);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), separator);
|
|
|
|
gtk_widget_set_sensitive(separator, FALSE);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* arguments */
|
2006-11-30 15:42:52 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Set Includes and Arguments"));
|
|
|
|
gtk_widget_show(item);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_OPTIONS, item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item,
|
|
|
|
_("Sets the includes and library paths for the compiler and "
|
|
|
|
"the program arguments for execution"), NULL);
|
|
|
|
image = gtk_image_new_from_stock("gtk-preferences", 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_arguments_activate), NULL);
|
|
|
|
menu_items->item_set_args = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->menu = menu;
|
2008-02-27 13:17:29 +00:00
|
|
|
g_object_ref((gpointer)menu_items->menu); /* to hold it after removing */
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
static void create_build_menu_tex(BuildMenuItems *menu_items)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
|
|
|
GtkWidget *menu, *item, *image, *separator;
|
|
|
|
GtkAccelGroup *accel_group = gtk_accel_group_new();
|
2008-05-22 14:41:28 +00:00
|
|
|
GtkTooltips *tooltips = GTK_TOOLTIPS(lookup_widget(main_widgets.window, "tooltips"));
|
2008-03-12 13:37:39 +00:00
|
|
|
KeyBindingGroup *group = g_ptr_array_index(keybinding_groups, GEANY_KEY_GROUP_BUILD);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
|
|
|
menu = gtk_menu_new();
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* DVI */
|
2008-03-31 13:09:56 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("LaTeX -> _DVI"));
|
2006-10-18 19:35:42 +00:00
|
|
|
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);
|
2006-12-09 17:03:03 +00:00
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_COMPILE, item);
|
2006-10-18 19:35:42 +00:00
|
|
|
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);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_signal_connect((gpointer) item, "activate",
|
|
|
|
G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(LATEX_CMD_TO_DVI));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_compile = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* PDF */
|
2008-03-31 13:09:56 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("LaTeX -> _PDF"));
|
2006-10-18 19:35:42 +00:00
|
|
|
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);
|
2006-12-09 17:03:03 +00:00
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_LINK, item);
|
2006-10-18 19:35:42 +00:00
|
|
|
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);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_signal_connect((gpointer) item, "activate",
|
|
|
|
G_CALLBACK(on_build_tex_activate), GINT_TO_POINTER(LATEX_CMD_TO_PDF));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_link = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-12-08 15:50:10 +00:00
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* build the code with make all */
|
2006-12-12 12:12:20 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Make All"));
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
|
|
|
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);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_MAKE, item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate),
|
|
|
|
GINT_TO_POINTER(GBO_MAKE_ALL));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_make_all = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* build the code with make custom */
|
2006-12-12 12:12:20 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("Make Custom _Target"));
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_MAKEOWNTARGET, item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item, _("Builds the current file with the "
|
|
|
|
"make tool and the specified target"), NULL);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_make_activate),
|
|
|
|
GINT_TO_POINTER(GBO_MAKE_CUSTOM));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_make_custom = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-12-08 15:50:10 +00:00
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* next error */
|
2006-12-08 15:50:10 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Next Error"));
|
|
|
|
gtk_widget_show(item);
|
2006-12-09 17:03:03 +00:00
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_NEXTERROR, item);
|
2006-12-08 15:50:10 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_build_next_error), NULL);
|
|
|
|
menu_items->item_next_error = item;
|
|
|
|
|
|
|
|
item = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* DVI view */
|
2008-03-31 13:09:56 +00:00
|
|
|
#define LATEX_VIEW_DVI_LABEL _("_View DVI File") /* used later again */
|
2006-11-11 18:51:33 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(LATEX_VIEW_DVI_LABEL);
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
2006-12-09 17:03:03 +00:00
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_RUN, item);
|
2007-03-05 12:44:02 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, item, _("Compile and view the current file"), NULL);
|
2006-10-18 19:35:42 +00:00
|
|
|
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);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_signal_connect((gpointer) item, "activate",
|
|
|
|
G_CALLBACK(on_build_execute_activate), GINT_TO_POINTER(LATEX_CMD_VIEW_DVI));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_exec = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* PDF view */
|
2008-03-31 13:09:56 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("V_iew PDF File"));
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
2006-12-09 17:03:03 +00:00
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_RUN2, item);
|
2007-03-05 12:44:02 +00:00
|
|
|
gtk_tooltips_set_tip(tooltips, item, _("Compile and view the current file"), NULL);
|
2006-10-18 19:35:42 +00:00
|
|
|
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);
|
2006-11-11 18:51:33 +00:00
|
|
|
g_signal_connect((gpointer) item, "activate",
|
|
|
|
G_CALLBACK(on_build_execute_activate), GINT_TO_POINTER(LATEX_CMD_VIEW_PDF));
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->item_exec2 = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* separator */
|
2006-10-18 19:35:42 +00:00
|
|
|
separator = gtk_separator_menu_item_new();
|
|
|
|
gtk_widget_show(separator);
|
|
|
|
gtk_container_add(GTK_CONTAINER(menu), separator);
|
|
|
|
gtk_widget_set_sensitive(separator, FALSE);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* arguments */
|
2008-03-31 13:09:56 +00:00
|
|
|
item = gtk_image_menu_item_new_with_mnemonic(_("_Set Arguments"));
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_widget_show(item);
|
2006-12-09 17:03:03 +00:00
|
|
|
GEANY_ADD_WIDGET_ACCEL(GEANY_KEYS_BUILD_OPTIONS, item);
|
2006-10-18 19:35:42 +00:00
|
|
|
gtk_container_add(GTK_CONTAINER(menu), item);
|
|
|
|
gtk_tooltips_set_tip(tooltips, item,
|
|
|
|
_("Sets the program paths and arguments"), NULL);
|
|
|
|
image = gtk_image_new_from_stock("gtk-preferences", GTK_ICON_SIZE_MENU);
|
|
|
|
gtk_widget_show(image);
|
|
|
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
|
2006-11-29 10:29:34 +00:00
|
|
|
g_signal_connect((gpointer) item, "activate",
|
2006-11-30 15:42:52 +00:00
|
|
|
G_CALLBACK(on_build_arguments_activate), filetypes[GEANY_FILETYPES_LATEX]);
|
|
|
|
menu_items->item_set_args = item;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_window_add_accel_group(GTK_WINDOW(main_widgets.window), accel_group);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->menu = menu;
|
2008-02-27 13:17:29 +00:00
|
|
|
g_object_ref((gpointer)menu_items->menu); /* to hold it after removing */
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-24 12:40:20 +00:00
|
|
|
static void
|
|
|
|
on_includes_arguments_tex_dialog_response (GtkDialog *dialog,
|
|
|
|
gint response,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft = user_data;
|
2007-03-24 12:40:20 +00:00
|
|
|
g_return_if_fail(ft != NULL);
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
const gchar *newstr;
|
|
|
|
struct build_programs *programs = ft->programs;
|
|
|
|
|
|
|
|
newstr = gtk_entry_get_text(
|
|
|
|
GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry1")));
|
|
|
|
if (! utils_str_equal(newstr, programs->compiler))
|
|
|
|
{
|
|
|
|
if (programs->compiler) g_free(programs->compiler);
|
|
|
|
programs->compiler = g_strdup(newstr);
|
|
|
|
programs->modified = TRUE;
|
|
|
|
}
|
|
|
|
newstr = gtk_entry_get_text(
|
|
|
|
GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry2")));
|
|
|
|
if (! utils_str_equal(newstr, programs->linker))
|
|
|
|
{
|
|
|
|
if (programs->linker) g_free(programs->linker);
|
|
|
|
programs->linker = g_strdup(newstr);
|
|
|
|
programs->modified = TRUE;
|
|
|
|
}
|
|
|
|
newstr = gtk_entry_get_text(
|
|
|
|
GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry3")));
|
|
|
|
if (! utils_str_equal(newstr, programs->run_cmd))
|
|
|
|
{
|
|
|
|
if (programs->run_cmd) g_free(programs->run_cmd);
|
|
|
|
programs->run_cmd = g_strdup(newstr);
|
|
|
|
programs->modified = TRUE;
|
|
|
|
}
|
|
|
|
newstr = gtk_entry_get_text(
|
|
|
|
GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry4")));
|
|
|
|
if (! utils_str_equal(newstr, programs->run_cmd2))
|
|
|
|
{
|
|
|
|
if (programs->run_cmd2) g_free(programs->run_cmd2);
|
|
|
|
programs->run_cmd2 = g_strdup(newstr);
|
|
|
|
programs->modified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void show_includes_arguments_tex(void)
|
2007-03-24 12:40:20 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog, *label, *entries[4], *vbox, *table;
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2007-03-24 12:40:20 +00:00
|
|
|
gint response;
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft = NULL;
|
2007-03-24 12:40:20 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc != NULL)
|
|
|
|
ft = doc->file_type;
|
2007-03-24 12:40:20 +00:00
|
|
|
g_return_if_fail(ft != NULL);
|
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
dialog = gtk_dialog_new_with_buttons(_("Set Arguments"), GTK_WINDOW(main_widgets.window),
|
2007-03-24 12:40:20 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
|
|
|
|
vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(dialog, "GeanyDialog");
|
2007-03-24 12:40:20 +00:00
|
|
|
|
|
|
|
label = gtk_label_new(_("Set programs and options for compiling and viewing (La)TeX files."));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), label);
|
|
|
|
|
|
|
|
table = gtk_table_new(4, 2, FALSE);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(table), 6);
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), table);
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* LaTeX -> DVI args */
|
2007-06-10 19:28:50 +00:00
|
|
|
if (ft->programs->compiler != NULL && ft->actions->can_compile)
|
2007-03-24 12:40:20 +00:00
|
|
|
{
|
|
|
|
label = gtk_label_new(_("DVI creation:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
|
|
|
|
GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0);
|
|
|
|
|
|
|
|
entries[0] = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entries[0]), 30);
|
|
|
|
if (ft->programs->compiler)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entries[0]), ft->programs->compiler);
|
|
|
|
}
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), entries[0], 1, 2, 0, 1);
|
|
|
|
g_object_set_data_full(G_OBJECT(dialog), "tex_entry1",
|
|
|
|
gtk_widget_ref(entries[0]), (GDestroyNotify)gtk_widget_unref);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* LaTeX -> PDF args */
|
2007-06-10 19:28:50 +00:00
|
|
|
if (ft->programs->linker != NULL && ft->actions->can_link)
|
2007-03-24 12:40:20 +00:00
|
|
|
{
|
|
|
|
label = gtk_label_new(_("PDF creation:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
|
|
|
|
GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0);
|
|
|
|
|
|
|
|
entries[1] = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entries[1]), 30);
|
|
|
|
if (ft->programs->linker)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entries[1]), ft->programs->linker);
|
|
|
|
}
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), entries[1], 1, 2, 1, 2);
|
|
|
|
g_object_set_data_full(G_OBJECT(dialog), "tex_entry2",
|
|
|
|
gtk_widget_ref(entries[1]), (GDestroyNotify)gtk_widget_unref);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* View LaTeX -> DVI args */
|
2007-03-24 12:40:20 +00:00
|
|
|
if (ft->programs->run_cmd != NULL)
|
|
|
|
{
|
|
|
|
label = gtk_label_new(_("DVI preview:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3,
|
|
|
|
GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0);
|
|
|
|
|
|
|
|
entries[2] = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entries[2]), 30);
|
|
|
|
if (ft->programs->run_cmd)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entries[2]), ft->programs->run_cmd);
|
|
|
|
}
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), entries[2], 1, 2, 2, 3);
|
|
|
|
g_object_set_data_full(G_OBJECT(dialog), "tex_entry3",
|
|
|
|
gtk_widget_ref(entries[2]), (GDestroyNotify)gtk_widget_unref);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* View LaTeX -> PDF args */
|
2007-03-24 12:40:20 +00:00
|
|
|
if (ft->programs->run_cmd2 != NULL)
|
|
|
|
{
|
|
|
|
label = gtk_label_new(_("PDF preview:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4,
|
|
|
|
GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0);
|
|
|
|
|
|
|
|
entries[3] = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entries[3]), 30);
|
|
|
|
if (ft->programs->run_cmd2)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entries[3]), ft->programs->run_cmd2);
|
|
|
|
}
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(table), entries[3], 1, 2, 3, 4);
|
|
|
|
g_object_set_data_full(G_OBJECT(dialog), "tex_entry4",
|
|
|
|
gtk_widget_ref(entries[3]), (GDestroyNotify)gtk_widget_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
label = gtk_label_new(_("%f will be replaced by the current filename, e.g. test_file.c\n"
|
|
|
|
"%e will be replaced by the filename without extension, e.g. test_file"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), label);
|
|
|
|
|
|
|
|
gtk_widget_show_all(dialog);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* run modally to prevent user changing idx filetype */
|
2007-03-24 12:40:20 +00:00
|
|
|
response = gtk_dialog_run(GTK_DIALOG(dialog));
|
2008-02-27 13:17:29 +00:00
|
|
|
/* call the callback manually */
|
2007-03-24 12:40:20 +00:00
|
|
|
on_includes_arguments_tex_dialog_response(GTK_DIALOG(dialog), response, ft);
|
|
|
|
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_includes_arguments_dialog_response (GtkDialog *dialog,
|
|
|
|
gint response,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft = user_data;
|
2007-03-24 12:40:20 +00:00
|
|
|
|
|
|
|
g_return_if_fail(ft != NULL);
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
|
|
|
const gchar *newstr;
|
|
|
|
struct build_programs *programs = ft->programs;
|
|
|
|
|
|
|
|
if (ft->actions->can_compile)
|
|
|
|
{
|
|
|
|
newstr = gtk_entry_get_text(
|
|
|
|
GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry1")));
|
|
|
|
if (! utils_str_equal(newstr, programs->compiler))
|
|
|
|
{
|
|
|
|
if (programs->compiler) g_free(programs->compiler);
|
|
|
|
programs->compiler = g_strdup(newstr);
|
|
|
|
programs->modified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ft->actions->can_link)
|
|
|
|
{
|
|
|
|
newstr = gtk_entry_get_text(
|
|
|
|
GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry2")));
|
|
|
|
if (! utils_str_equal(newstr, programs->linker))
|
|
|
|
{
|
|
|
|
if (programs->linker) g_free(programs->linker);
|
|
|
|
programs->linker = g_strdup(newstr);
|
|
|
|
programs->modified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ft->actions->can_exec)
|
|
|
|
{
|
|
|
|
newstr = gtk_entry_get_text(
|
|
|
|
GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry3")));
|
|
|
|
if (! utils_str_equal(newstr, programs->run_cmd))
|
|
|
|
{
|
|
|
|
if (programs->run_cmd) g_free(programs->run_cmd);
|
|
|
|
programs->run_cmd = g_strdup(newstr);
|
|
|
|
programs->modified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 11:24:23 +00:00
|
|
|
static void show_includes_arguments_gen(void)
|
2007-03-24 12:40:20 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog, *label, *entries[3], *vbox;
|
|
|
|
GtkWidget *ft_table = NULL;
|
|
|
|
gint row = 0;
|
|
|
|
gint response;
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft = NULL;
|
2007-03-24 12:40:20 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc != NULL)
|
|
|
|
ft = doc->file_type;
|
2007-03-24 12:40:20 +00:00
|
|
|
g_return_if_fail(ft != NULL);
|
|
|
|
|
2008-05-22 14:41:28 +00:00
|
|
|
dialog = gtk_dialog_new_with_buttons(_("Set Includes and Arguments"), GTK_WINDOW(main_widgets.window),
|
2007-03-24 12:40:20 +00:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
|
|
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
|
|
|
|
vbox = ui_dialog_vbox_new(GTK_DIALOG(dialog));
|
2007-05-15 15:16:16 +00:00
|
|
|
gtk_widget_set_name(dialog, "GeanyDialog");
|
2007-03-24 12:40:20 +00:00
|
|
|
|
|
|
|
label = gtk_label_new(_("Set the commands for building and running programs."));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), label);
|
|
|
|
|
|
|
|
if (ft->actions->can_compile || ft->actions->can_link || ft->actions->can_exec)
|
|
|
|
{
|
|
|
|
GtkWidget *align, *frame;
|
2008-02-27 13:17:29 +00:00
|
|
|
/* in-dialog heading for the "Set Includes and Arguments" dialog */
|
2007-09-09 16:13:30 +00:00
|
|
|
gchar *frame_title = g_strdup_printf(_("%s commands"), ft->title);
|
2007-03-24 12:40:20 +00:00
|
|
|
|
|
|
|
frame = ui_frame_new_with_alignment(frame_title, &align);
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), frame);
|
|
|
|
g_free(frame_title);
|
|
|
|
|
|
|
|
ft_table = gtk_table_new(3, 2, FALSE);
|
|
|
|
gtk_table_set_row_spacings(GTK_TABLE(ft_table), 6);
|
|
|
|
gtk_container_add(GTK_CONTAINER(align), ft_table);
|
|
|
|
row = 0;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* include-args */
|
2007-03-24 12:40:20 +00:00
|
|
|
if (ft->actions->can_compile)
|
|
|
|
{
|
|
|
|
label = gtk_label_new(_("Compile:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_table_attach(GTK_TABLE(ft_table), label, 0, 1, row, row + 1,
|
|
|
|
GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0);
|
|
|
|
|
|
|
|
entries[0] = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entries[0]), 30);
|
|
|
|
if (ft->programs->compiler)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entries[0]), ft->programs->compiler);
|
|
|
|
}
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(ft_table), entries[0], 1, 2, row, row + 1);
|
|
|
|
row++;
|
|
|
|
|
|
|
|
g_object_set_data_full(G_OBJECT(dialog), "includes_entry1",
|
|
|
|
gtk_widget_ref(entries[0]), (GDestroyNotify)gtk_widget_unref);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* lib-args */
|
2007-03-24 12:40:20 +00:00
|
|
|
if (ft->actions->can_link)
|
|
|
|
{
|
|
|
|
label = gtk_label_new(_("Build:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_table_attach(GTK_TABLE(ft_table), label, 0, 1, row, row + 1,
|
|
|
|
GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0);
|
|
|
|
|
|
|
|
entries[1] = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entries[1]), 30);
|
|
|
|
if (ft->programs->linker)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entries[1]), ft->programs->linker);
|
|
|
|
}
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(ft_table), entries[1], 1, 2, row, row + 1);
|
|
|
|
row++;
|
|
|
|
|
|
|
|
g_object_set_data_full(G_OBJECT(dialog), "includes_entry2",
|
|
|
|
gtk_widget_ref(entries[1]), (GDestroyNotify)gtk_widget_unref);
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* program-args */
|
2007-03-24 12:40:20 +00:00
|
|
|
if (ft->actions->can_exec)
|
|
|
|
{
|
|
|
|
label = gtk_label_new(_("Execute:"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_table_attach(GTK_TABLE(ft_table), label, 0, 1, row, row + 1,
|
|
|
|
GTK_FILL, GTK_FILL | GTK_EXPAND, 6, 0);
|
|
|
|
|
|
|
|
entries[2] = gtk_entry_new();
|
|
|
|
gtk_entry_set_width_chars(GTK_ENTRY(entries[2]), 30);
|
|
|
|
if (ft->programs->run_cmd)
|
|
|
|
{
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(entries[2]), ft->programs->run_cmd);
|
|
|
|
}
|
|
|
|
gtk_table_attach_defaults(GTK_TABLE(ft_table), entries[2], 1, 2, row, row + 1);
|
|
|
|
row++;
|
|
|
|
|
|
|
|
g_object_set_data_full(G_OBJECT(dialog), "includes_entry3",
|
|
|
|
gtk_widget_ref(entries[2]), (GDestroyNotify)gtk_widget_unref);
|
2007-04-30 16:16:49 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* disable the run command if there is a valid project run command set */
|
2007-04-30 16:16:49 +00:00
|
|
|
if (app->project && NZV(app->project->run_cmd))
|
|
|
|
gtk_widget_set_sensitive(entries[2], FALSE);
|
2007-03-24 12:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
label = gtk_label_new(_("%f will be replaced by the current filename, e.g. test_file.c\n"
|
|
|
|
"%e will be replaced by the filename without extension, e.g. test_file"));
|
|
|
|
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
|
|
gtk_container_add(GTK_CONTAINER(vbox), label);
|
|
|
|
|
|
|
|
gtk_widget_show_all(dialog);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* run modally to prevent user changing idx filetype */
|
2007-03-24 12:40:20 +00:00
|
|
|
response = gtk_dialog_run(GTK_DIALOG(dialog));
|
2008-02-27 13:17:29 +00:00
|
|
|
/* call the callback manually */
|
2007-03-24 12:40:20 +00:00
|
|
|
on_includes_arguments_dialog_response(GTK_DIALOG(dialog), response, ft);
|
|
|
|
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_build_arguments_activate (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-05-16 14:17:54 +00:00
|
|
|
if (user_data && FILETYPE_ID((GeanyFiletype*) user_data) == GEANY_FILETYPES_LATEX)
|
2007-03-24 12:40:20 +00:00
|
|
|
show_includes_arguments_tex();
|
|
|
|
else
|
|
|
|
show_includes_arguments_gen();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-18 19:35:42 +00:00
|
|
|
static gboolean is_c_header(const gchar *fname)
|
|
|
|
{
|
|
|
|
gchar *ext = NULL;
|
|
|
|
|
|
|
|
if (fname)
|
|
|
|
{
|
|
|
|
ext = strrchr(fname, '.');
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
return (ext == NULL) ? FALSE : (*(ext + 1) == 'h'); /* match *.h* */
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
/* Call this whenever build menu items need to be enabled/disabled.
|
|
|
|
* Uses current document (if there is one) when idx == -1 */
|
2008-06-15 13:35:48 +00:00
|
|
|
void build_menu_update(GeanyDocument *doc)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft;
|
2007-05-01 12:27:56 +00:00
|
|
|
gboolean have_path, can_build, can_make, can_run, can_stop, can_set_args, have_errors;
|
2006-11-30 15:42:52 +00:00
|
|
|
BuildMenuItems *menu_items;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
|
|
|
doc = document_get_current();
|
|
|
|
if (doc == NULL ||
|
|
|
|
(FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_NONE && doc->file_name == NULL))
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_widget_set_sensitive(lookup_widget(main_widgets.window, "menu_build1"), FALSE);
|
|
|
|
gtk_menu_item_remove_submenu(GTK_MENU_ITEM(lookup_widget(main_widgets.window, "menu_build1")));
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(widgets.compile_button, FALSE);
|
|
|
|
gtk_widget_set_sensitive(widgets.run_button, FALSE);
|
2006-10-18 19:35:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_widget_set_sensitive(lookup_widget(main_widgets.window, "menu_build1"), TRUE);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
ft = doc->file_type;
|
2006-11-30 15:42:52 +00:00
|
|
|
g_return_if_fail(ft != NULL);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2006-12-08 15:50:10 +00:00
|
|
|
menu_items = build_get_menu_items(ft->id);
|
2006-11-29 10:29:34 +00:00
|
|
|
/* Note: don't remove the submenu first because it can now cause an X hang if
|
|
|
|
* the menu is already open when called from build_exit_cb(). */
|
2008-05-22 14:41:28 +00:00
|
|
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(lookup_widget(main_widgets.window, "menu_build1")),
|
2006-11-30 15:42:52 +00:00
|
|
|
menu_items->menu);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
have_path = (doc->file_name != NULL);
|
2006-11-29 10:29:34 +00:00
|
|
|
|
2006-12-09 13:06:50 +00:00
|
|
|
can_make = have_path && build_info.pid <= (GPid) 1;
|
2006-11-29 10:29:34 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* disable compile and link for C/C++ header files */
|
2006-11-29 10:29:34 +00:00
|
|
|
if (ft->id == GEANY_FILETYPES_C || ft->id == GEANY_FILETYPES_CPP)
|
2008-06-15 13:35:48 +00:00
|
|
|
can_build = can_make && ! is_c_header(doc->file_name);
|
2006-11-29 10:29:34 +00:00
|
|
|
else
|
|
|
|
can_build = can_make;
|
|
|
|
|
2006-11-30 15:42:52 +00:00
|
|
|
if (menu_items->item_compile)
|
|
|
|
gtk_widget_set_sensitive(menu_items->item_compile, can_build && ft->actions->can_compile);
|
|
|
|
if (menu_items->item_link)
|
|
|
|
gtk_widget_set_sensitive(menu_items->item_link, can_build && ft->actions->can_link);
|
|
|
|
if (menu_items->item_make_all)
|
|
|
|
gtk_widget_set_sensitive(menu_items->item_make_all, can_make);
|
|
|
|
if (menu_items->item_make_custom)
|
|
|
|
gtk_widget_set_sensitive(menu_items->item_make_custom, can_make);
|
|
|
|
if (menu_items->item_make_object)
|
|
|
|
gtk_widget_set_sensitive(menu_items->item_make_object, can_make);
|
|
|
|
|
2007-05-01 12:27:56 +00:00
|
|
|
if (app->project && NZV(app->project->run_cmd))
|
2008-02-27 13:17:29 +00:00
|
|
|
can_run = have_path; /* for now run is disabled for all untitled files */
|
2007-05-01 12:27:56 +00:00
|
|
|
else
|
|
|
|
can_run = have_path && ft->actions->can_exec;
|
|
|
|
|
|
|
|
can_stop = run_info.pid > (GPid) 1;
|
|
|
|
can_run &= ! can_stop;
|
|
|
|
|
|
|
|
/* item_exec is enabled for both run and stop commands */
|
2006-11-30 15:42:52 +00:00
|
|
|
if (menu_items->item_exec)
|
2007-05-01 12:27:56 +00:00
|
|
|
gtk_widget_set_sensitive(menu_items->item_exec, can_run || can_stop);
|
|
|
|
/* item_exec2 is disabled if there's a running process already */
|
2006-11-30 15:42:52 +00:00
|
|
|
if (menu_items->item_exec2)
|
2007-05-01 12:27:56 +00:00
|
|
|
gtk_widget_set_sensitive(menu_items->item_exec2, can_run);
|
2006-11-30 15:42:52 +00:00
|
|
|
|
|
|
|
can_set_args =
|
|
|
|
((ft->actions->can_compile ||
|
|
|
|
ft->actions->can_link ||
|
|
|
|
ft->actions->can_exec) &&
|
2008-05-07 13:54:21 +00:00
|
|
|
FILETYPE_ID(ft) != GEANY_FILETYPES_NONE);
|
2006-11-30 15:42:52 +00:00
|
|
|
if (menu_items->item_set_args)
|
|
|
|
gtk_widget_set_sensitive(menu_items->item_set_args, can_set_args);
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_widget_set_sensitive(widgets.compile_button, can_build && ft->actions->can_compile);
|
|
|
|
gtk_widget_set_sensitive(widgets.run_button, can_run || can_stop);
|
2006-11-29 10:29:34 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* show the stop command if a program is running, otherwise show run command */
|
2007-05-01 12:27:56 +00:00
|
|
|
set_stop_button(can_stop);
|
2006-12-08 15:50:10 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* simply enable next error command if the compiler window has any items */
|
2006-12-08 15:50:10 +00:00
|
|
|
have_errors = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(msgwindow.store_compiler),
|
|
|
|
NULL) > 0;
|
2007-06-19 17:11:46 +00:00
|
|
|
if (menu_items->item_next_error)
|
|
|
|
gtk_widget_set_sensitive(menu_items->item_next_error, have_errors);
|
2006-11-29 10:29:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* Call build_menu_update() instead of calling this directly. */
|
2006-11-29 10:29:34 +00:00
|
|
|
static void set_stop_button(gboolean stop)
|
|
|
|
{
|
|
|
|
GtkStockItem sitem;
|
|
|
|
GtkWidget *menuitem =
|
2006-12-08 15:50:10 +00:00
|
|
|
build_get_menu_items(run_info.file_type_id)->item_exec;
|
2006-11-29 10:29:34 +00:00
|
|
|
|
2006-12-07 16:09:45 +00:00
|
|
|
if (stop && utils_str_equal(
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(widgets.run_button)), "gtk-stop")) return;
|
2006-12-07 16:09:45 +00:00
|
|
|
if (! stop && utils_str_equal(
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_tool_button_get_stock_id(GTK_TOOL_BUTTON(widgets.run_button)), "gtk-execute")) return;
|
2006-11-29 10:29:34 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* use the run button also as stop button */
|
2006-11-29 10:29:34 +00:00
|
|
|
if (stop)
|
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(widgets.run_button), "gtk-stop");
|
2006-11-29 10:29:34 +00:00
|
|
|
|
|
|
|
if (menuitem != NULL)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
2006-11-29 10:29:34 +00:00
|
|
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),
|
|
|
|
gtk_image_new_from_stock("gtk-stop", GTK_ICON_SIZE_MENU));
|
|
|
|
gtk_stock_lookup("gtk-stop", &sitem);
|
|
|
|
gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),
|
|
|
|
sitem.label);
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
2006-11-29 10:29:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-23 11:34:06 +00:00
|
|
|
gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(widgets.run_button), "gtk-execute");
|
2006-11-29 10:29:34 +00:00
|
|
|
|
|
|
|
if (menuitem != NULL)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* LaTeX hacks ;-( */
|
2006-11-29 10:29:34 +00:00
|
|
|
if (run_info.file_type_id == GEANY_FILETYPES_LATEX)
|
|
|
|
{
|
|
|
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),
|
|
|
|
gtk_image_new_from_stock("gtk-find", GTK_ICON_SIZE_MENU));
|
|
|
|
gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),
|
|
|
|
LATEX_VIEW_DVI_LABEL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem),
|
|
|
|
gtk_image_new_from_stock("gtk-execute", GTK_ICON_SIZE_MENU));
|
|
|
|
|
|
|
|
gtk_stock_lookup("gtk-execute", &sitem);
|
|
|
|
gtk_label_set_text_with_mnemonic(GTK_LABEL(gtk_bin_get_child(GTK_BIN(menuitem))),
|
|
|
|
sitem.label);
|
|
|
|
}
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-08 15:50:10 +00:00
|
|
|
/* Creates the relevant build menu if necessary.
|
2008-05-07 13:54:21 +00:00
|
|
|
* If filetype_idx is -1, the current filetype is used, or GEANY_FILETYPES_NONE */
|
2007-01-03 16:21:44 +00:00
|
|
|
BuildMenuItems *build_get_menu_items(gint filetype_idx)
|
2006-11-30 15:42:52 +00:00
|
|
|
{
|
|
|
|
BuildMenuItems *items;
|
|
|
|
|
2007-01-03 16:21:44 +00:00
|
|
|
if (filetype_idx == -1)
|
2006-12-08 15:50:10 +00:00
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft = NULL;
|
2006-12-08 15:50:10 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc != NULL)
|
|
|
|
ft = doc->file_type;
|
2007-01-03 16:21:44 +00:00
|
|
|
filetype_idx = FILETYPE_ID(ft);
|
2006-12-08 15:50:10 +00:00
|
|
|
}
|
|
|
|
|
2007-01-03 16:21:44 +00:00
|
|
|
if (filetype_idx == GEANY_FILETYPES_LATEX)
|
2006-11-30 15:42:52 +00:00
|
|
|
{
|
|
|
|
items = &latex_menu_items;
|
|
|
|
if (items->menu == NULL)
|
|
|
|
create_build_menu_tex(items);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
items = &default_menu_items;
|
|
|
|
if (items->menu == NULL)
|
|
|
|
create_build_menu_gen(items);
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static void
|
2006-10-18 19:35:42 +00:00
|
|
|
on_build_compile_activate (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
|
|
|
return;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc->changed)
|
|
|
|
document_save_file(doc, FALSE);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_LATEX)
|
|
|
|
build_compile_tex_file(doc, 0);
|
2006-10-18 19:35:42 +00:00
|
|
|
else
|
2008-06-15 13:35:48 +00:00
|
|
|
build_compile_file(doc);
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static void
|
2006-10-18 19:35:42 +00:00
|
|
|
on_build_tex_activate (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
2007-11-04 19:26:02 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc->changed)
|
|
|
|
document_save_file(doc, FALSE);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
|
|
|
switch (GPOINTER_TO_INT(user_data))
|
|
|
|
{
|
2006-11-11 18:51:33 +00:00
|
|
|
case LATEX_CMD_TO_DVI:
|
|
|
|
case LATEX_CMD_TO_PDF:
|
2008-06-15 13:35:48 +00:00
|
|
|
build_compile_tex_file(doc, GPOINTER_TO_INT(user_data)); break;
|
2006-11-11 18:51:33 +00:00
|
|
|
case LATEX_CMD_VIEW_DVI:
|
|
|
|
case LATEX_CMD_VIEW_PDF:
|
2008-06-15 13:35:48 +00:00
|
|
|
build_view_tex_file(doc, GPOINTER_TO_INT(user_data)); break;
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static void
|
2006-10-18 19:35:42 +00:00
|
|
|
on_build_build_activate (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
|
|
|
return;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc->changed)
|
|
|
|
document_save_file(doc, FALSE);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_LATEX)
|
|
|
|
build_compile_tex_file(doc, 1);
|
2006-10-18 19:35:42 +00:00
|
|
|
else
|
2008-06-15 13:35:48 +00:00
|
|
|
build_link_file(doc);
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-21 13:09:09 +00:00
|
|
|
static void
|
|
|
|
on_make_custom_input_response(const gchar *input)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2007-12-21 13:09:09 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc->changed)
|
|
|
|
document_save_file(doc, FALSE);
|
2007-12-21 13:09:09 +00:00
|
|
|
|
|
|
|
setptr(build_info.custom_target, g_strdup(input));
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
build_make_file(doc, GBO_MAKE_CUSTOM);
|
2007-12-21 13:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2008-02-20 11:24:23 +00:00
|
|
|
show_make_custom(void)
|
2007-12-21 13:09:09 +00:00
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
static GtkWidget *dialog = NULL; /* keep dialog for combo history */
|
2007-12-21 13:09:09 +00:00
|
|
|
|
|
|
|
if (! dialog)
|
|
|
|
dialog = dialogs_show_input(_("Make Custom Target"),
|
|
|
|
_("Enter custom options here, all entered text is passed to the make command."),
|
|
|
|
build_info.custom_target, TRUE, &on_make_custom_input_response);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_show(dialog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static void
|
2006-10-18 19:35:42 +00:00
|
|
|
on_build_make_activate (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2006-10-18 19:35:42 +00:00
|
|
|
gint build_opts = GPOINTER_TO_INT(user_data);
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
g_return_if_fail(doc != NULL && doc->file_name != NULL);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
|
|
|
switch (build_opts)
|
|
|
|
{
|
|
|
|
case GBO_MAKE_CUSTOM:
|
|
|
|
{
|
2007-12-21 13:09:09 +00:00
|
|
|
show_make_custom();
|
2006-10-18 19:35:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GBO_MAKE_OBJECT:
|
2008-02-27 13:17:29 +00:00
|
|
|
/* fall through */
|
2006-10-18 19:35:42 +00:00
|
|
|
case GBO_MAKE_ALL:
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc->changed)
|
|
|
|
document_save_file(doc, FALSE);
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
build_make_file(doc, build_opts);
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
static gboolean use_html_builtin(GeanyDocument *doc, GeanyFiletype *ft)
|
2007-12-14 13:39:15 +00:00
|
|
|
{
|
|
|
|
gboolean use_builtin = FALSE;
|
|
|
|
if (ft->id == GEANY_FILETYPES_HTML)
|
|
|
|
{
|
2008-02-27 13:17:29 +00:00
|
|
|
/* we have a project, check its run_cmd */
|
2007-12-14 13:39:15 +00:00
|
|
|
if (app->project != NULL)
|
|
|
|
{
|
|
|
|
if (utils_str_equal(app->project->run_cmd, "builtin"))
|
|
|
|
use_builtin = TRUE;
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* no project, check for filetype run_cmd */
|
2007-12-14 13:39:15 +00:00
|
|
|
else if (ft->actions->can_exec && utils_str_equal(ft->programs->run_cmd, "builtin"))
|
|
|
|
use_builtin = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_builtin)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
gchar *uri = g_strconcat("file:///", g_path_skip_root(doc->file_name), NULL);
|
2007-12-14 13:39:15 +00:00
|
|
|
utils_start_browser(uri);
|
|
|
|
g_free(uri);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static void
|
2006-10-18 19:35:42 +00:00
|
|
|
on_build_execute_activate (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2008-06-15 13:35:48 +00:00
|
|
|
GeanyDocument *doc = document_get_current();
|
2007-12-14 13:39:15 +00:00
|
|
|
filetype_id ft_id;
|
2008-05-16 14:17:54 +00:00
|
|
|
GeanyFiletype *ft;
|
2006-10-18 19:35:42 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc == NULL)
|
2007-11-04 19:26:02 +00:00
|
|
|
return;
|
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* make the process "stopable" */
|
2006-11-29 10:29:34 +00:00
|
|
|
if (run_info.pid > (GPid) 1)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
2006-11-29 10:29:34 +00:00
|
|
|
kill_process(&run_info.pid);
|
2006-11-11 18:51:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
ft_id = FILETYPE_ID(doc->file_type);
|
2007-12-14 13:39:15 +00:00
|
|
|
ft = filetypes[ft_id];
|
|
|
|
if (ft_id == GEANY_FILETYPES_LATEX)
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* run LaTeX file */
|
2008-06-15 13:35:48 +00:00
|
|
|
if (build_view_tex_file(doc, GPOINTER_TO_INT(user_data)) == (GPid) 0)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Failed to execute the view program"));
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-27 13:17:29 +00:00
|
|
|
/* use_html_builtin() checks for HTML builtin request and returns FALSE if not */
|
2008-06-15 13:35:48 +00:00
|
|
|
else if (! use_html_builtin(doc, ft))
|
2008-02-27 13:17:29 +00:00
|
|
|
{ /* run everything else */
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2008-02-27 13:17:29 +00:00
|
|
|
/* save the file only if the run command uses it */
|
2008-06-15 13:35:48 +00:00
|
|
|
if (doc->changed &&
|
2008-03-27 18:07:43 +00:00
|
|
|
NZV(ft->programs->run_cmd) && /* can happen when project is open */
|
2007-12-14 13:39:15 +00:00
|
|
|
strstr(ft->programs->run_cmd, "%f") != NULL)
|
2008-06-15 13:35:48 +00:00
|
|
|
document_save_file(doc, FALSE);
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2008-06-15 13:35:48 +00:00
|
|
|
if (build_run_cmd(doc) == (GPid) 0)
|
2006-10-18 19:35:42 +00:00
|
|
|
{
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Failed to execute the terminal program"));
|
2006-10-18 19:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-29 10:29:34 +00:00
|
|
|
static void kill_process(GPid *pid)
|
2006-11-11 18:51:33 +00:00
|
|
|
{
|
2007-11-06 15:54:46 +00:00
|
|
|
/* Unix: SIGQUIT is not the best signal to use because it causes a core dump (this should not
|
2006-11-11 18:51:33 +00:00
|
|
|
* perforce necessary for just killing a process). But we must use a signal which we can
|
|
|
|
* ignore because the main process get it too, it is declared to ignore in main.c. */
|
|
|
|
|
2007-02-25 13:08:01 +00:00
|
|
|
gint result;
|
|
|
|
|
2007-11-06 15:54:46 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
g_return_if_fail(*pid != NULL);
|
|
|
|
result = TerminateProcess(*pid, 0);
|
2008-02-27 13:17:29 +00:00
|
|
|
/* TerminateProcess() returns TRUE on success, for the check below we have to convert
|
|
|
|
* it to FALSE (and vice versa) */
|
2007-11-06 15:54:46 +00:00
|
|
|
result = ! result;
|
|
|
|
#else
|
2007-02-25 13:08:01 +00:00
|
|
|
g_return_if_fail(*pid > 1);
|
2006-11-29 10:29:34 +00:00
|
|
|
result = kill(*pid, SIGQUIT);
|
2007-11-06 15:54:46 +00:00
|
|
|
#endif
|
2006-11-11 18:51:33 +00:00
|
|
|
|
2007-02-25 13:08:01 +00:00
|
|
|
if (result != 0)
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(TRUE, _("Process could not be stopped (%s)."), g_strerror(errno));
|
2006-11-11 18:51:33 +00:00
|
|
|
else
|
|
|
|
{
|
2006-11-29 10:29:34 +00:00
|
|
|
*pid = 0;
|
2008-06-15 13:35:48 +00:00
|
|
|
build_menu_update(NULL);
|
2006-11-11 18:51:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
static void
|
2006-12-08 15:50:10 +00:00
|
|
|
on_build_next_error (GtkMenuItem *menuitem,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2007-03-12 12:13:45 +00:00
|
|
|
if (ui_tree_view_find_next(GTK_TREE_VIEW(msgwindow.tree_compiler),
|
2006-12-08 15:50:10 +00:00
|
|
|
msgwin_goto_compiler_file_line))
|
2007-03-12 12:13:45 +00:00
|
|
|
{
|
|
|
|
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_COMPILER);
|
|
|
|
}
|
|
|
|
else
|
2007-10-24 10:52:48 +00:00
|
|
|
ui_set_statusbar(FALSE, _("No more build errors."));
|
2006-12-08 15:50:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-23 11:34:06 +00:00
|
|
|
void build_init()
|
|
|
|
{
|
2008-05-22 14:41:28 +00:00
|
|
|
widgets.compile_button = lookup_widget(main_widgets.window, "toolbutton13");
|
|
|
|
widgets.run_button = lookup_widget(main_widgets.window, "toolbutton26");
|
2007-08-23 11:34:06 +00:00
|
|
|
}
|