Use project's base dir and run command when running commands in the VTE.
Add VTE preference to skip the generated run script. when running commands in the VTE. Make vte_cwd() accept also paths not only filenames. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2105 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
47c7c69214
commit
0d92c102b5
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
2007-12-17 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
||||
* src/build.c, src/keyfile.c, src/prefs.c, src/vte.c, src/vte.h:
|
||||
Use project's base dir and run command when running commands in the
|
||||
VTE.
|
||||
Add VTE preference to skip the generated run script. when running
|
||||
commands in the VTE.
|
||||
Make vte_cwd() accept also paths not only filenames.
|
||||
|
||||
|
||||
2007-12-16 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
|
||||
|
||||
* geany.desktop.in.in:
|
||||
|
63
src/build.c
63
src/build.c
@ -654,8 +654,10 @@ static gchar *get_build_executable(const gchar *locale_filename, gboolean check_
|
||||
}
|
||||
|
||||
|
||||
// Returns: NULL if there was an error, or the working directory the script was created in.
|
||||
static gchar *prepare_run_script(gint idx)
|
||||
/* 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 */
|
||||
static gchar *prepare_run_script(gint idx, gchar **vte_cmd_nonscript)
|
||||
{
|
||||
gchar *locale_filename = NULL;
|
||||
gboolean have_project;
|
||||
@ -669,6 +671,9 @@ static gchar *prepare_run_script(gint idx)
|
||||
gboolean result = FALSE;
|
||||
gchar *tmp;
|
||||
|
||||
if (vte_cmd_nonscript != NULL)
|
||||
*vte_cmd_nonscript = NULL;
|
||||
|
||||
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
|
||||
|
||||
have_project = (project != NULL && NZV(project->run_cmd));
|
||||
@ -700,14 +705,10 @@ static gchar *prepare_run_script(gint idx)
|
||||
if (! g_file_test(working_dir, G_FILE_TEST_EXISTS) ||
|
||||
! g_file_test(working_dir, G_FILE_TEST_IS_DIR))
|
||||
{
|
||||
gchar *utf8_working_dir =
|
||||
utils_get_utf8_from_locale(working_dir);
|
||||
gchar *utf8_working_dir = utils_get_utf8_from_locale(working_dir);
|
||||
|
||||
ui_set_statusbar(TRUE, _("Failed to change the working directory to \"%s\""), utf8_working_dir);
|
||||
g_free(utf8_working_dir);
|
||||
g_free(working_dir);
|
||||
g_free(executable);
|
||||
g_free(locale_filename);
|
||||
utils_free_pointers(utf8_working_dir, working_dir, executable, locale_filename, NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -720,13 +721,24 @@ static gchar *prepare_run_script(gint idx)
|
||||
|
||||
#ifdef HAVE_VTE
|
||||
if (vte_info.load_vte && vc != NULL && vc->run_in_vte)
|
||||
autoclose = TRUE; // don't wait for user input at the end of script when we are running in VTE
|
||||
{
|
||||
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
|
||||
// don't wait for user input at the end of script when we are running in VTE
|
||||
autoclose = TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
// (RUN_SCRIPT_CMD should be ok in UTF8 without converting in locale because it contains no umlauts)
|
||||
tmp = g_build_filename(working_dir, RUN_SCRIPT_CMD, NULL);
|
||||
result = build_create_shellscript(tmp, cmd, autoclose);
|
||||
g_free(tmp);
|
||||
if (! result)
|
||||
{
|
||||
gchar *utf8_cmd = utils_get_utf8_from_locale(cmd);
|
||||
@ -736,9 +748,7 @@ static gchar *prepare_run_script(gint idx)
|
||||
g_free(utf8_cmd);
|
||||
}
|
||||
|
||||
g_free(cmd);
|
||||
g_free(executable);
|
||||
g_free(locale_filename);
|
||||
utils_free_pointers(tmp, cmd, executable, locale_filename, NULL);
|
||||
|
||||
if (result)
|
||||
return working_dir;
|
||||
@ -750,13 +760,15 @@ static gchar *prepare_run_script(gint idx)
|
||||
|
||||
static GPid build_run_cmd(gint idx)
|
||||
{
|
||||
GeanyProject *project = app->project;
|
||||
gchar *working_dir;
|
||||
gchar *vte_cmd_nonscript = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (! DOC_IDX_VALID(idx) || doc_list[idx].file_name == NULL)
|
||||
return (GPid) 0;
|
||||
|
||||
working_dir = prepare_run_script(idx);
|
||||
working_dir = prepare_run_script(idx, &vte_cmd_nonscript);
|
||||
if (working_dir == NULL)
|
||||
{
|
||||
return (GPid) 0;
|
||||
@ -767,9 +779,26 @@ static GPid build_run_cmd(gint idx)
|
||||
#ifdef HAVE_VTE
|
||||
if (vte_info.load_vte && vc != NULL && vc->run_in_vte)
|
||||
{
|
||||
gchar *vte_cmd = g_strconcat(RUN_SCRIPT_CMD, "\n", NULL);
|
||||
// change into current directory if it is not done by default
|
||||
if (! vc->follow_path) vte_cwd(doc_list[idx].file_name, TRUE);
|
||||
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);
|
||||
|
||||
// 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)
|
||||
if (! vc->follow_path || (project != NULL && NZV(project->run_cmd)))
|
||||
{
|
||||
// we need to convert the working_dir back to UTF-8 because the VTE expects it
|
||||
gchar *utf8_working_dir = utils_get_utf8_from_locale(working_dir);
|
||||
vte_cwd(utf8_working_dir, TRUE);
|
||||
g_free(utf8_working_dir);
|
||||
}
|
||||
if (! vte_send_cmd(vte_cmd))
|
||||
ui_set_statusbar(FALSE,
|
||||
_("Could not execute the file in the VTE because it probably contains a command."));
|
||||
|
@ -289,6 +289,7 @@ static void save_dialog_prefs(GKeyFile *config)
|
||||
g_key_file_set_boolean(config, "VTE", "ignore_menu_bar_accel", vc->ignore_menu_bar_accel);
|
||||
g_key_file_set_boolean(config, "VTE", "follow_path", vc->follow_path);
|
||||
g_key_file_set_boolean(config, "VTE", "run_in_vte", vc->run_in_vte);
|
||||
g_key_file_set_boolean(config, "VTE", "skip_run_script", vc->skip_run_script);
|
||||
g_key_file_set_integer(config, "VTE", "scrollback_lines", vc->scrollback_lines);
|
||||
g_key_file_set_string(config, "VTE", "font", vc->font);
|
||||
g_key_file_set_string(config, "VTE", "shell", vc->shell);
|
||||
@ -606,6 +607,7 @@ static void load_dialog_prefs(GKeyFile *config)
|
||||
vc->ignore_menu_bar_accel = utils_get_setting_boolean(config, "VTE", "ignore_menu_bar_accel", FALSE);
|
||||
vc->follow_path = utils_get_setting_boolean(config, "VTE", "follow_path", FALSE);
|
||||
vc->run_in_vte = utils_get_setting_boolean(config, "VTE", "run_in_vte", FALSE);
|
||||
vc->skip_run_script = utils_get_setting_boolean(config, "VTE", "skip_run_script", FALSE);
|
||||
vc->enable_bash_keys = utils_get_setting_boolean(config, "VTE", "enable_bash_keys", TRUE);
|
||||
vc->scrollback_lines = utils_get_setting_integer(config, "VTE", "scrollback_lines", 500);
|
||||
vc->colour_fore = g_new0(GdkColor, 1);
|
||||
|
@ -532,6 +532,9 @@ void prefs_init_dialog(void)
|
||||
|
||||
widget = lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->run_in_vte);
|
||||
|
||||
widget = lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vc->skip_run_script);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -892,6 +895,9 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data)
|
||||
widget = lookup_widget(ui_widgets.prefs_dialog, "check_run_in_vte");
|
||||
vc->run_in_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
||||
|
||||
widget = lookup_widget(ui_widgets.prefs_dialog, "check_skip_script");
|
||||
vc->skip_run_script = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
|
||||
|
||||
vte_apply_user_settings();
|
||||
}
|
||||
#endif
|
||||
|
36
src/vte.c
36
src/vte.c
@ -568,15 +568,23 @@ const gchar* vte_get_working_directory()
|
||||
}
|
||||
|
||||
|
||||
// if force is set to TRUE, it will always change the cwd
|
||||
/* Changes the current working directory of the VTE to the path of the given filename.
|
||||
* filename is expected to be in UTF-8 encoding.
|
||||
* filename can also be a path, then it is used directly.
|
||||
* If force is set to TRUE, it will always change the cwd
|
||||
* */
|
||||
void vte_cwd(const gchar *filename, gboolean force)
|
||||
{
|
||||
if (vte_info.have_vte && (vc->follow_path || force) && filename != NULL)
|
||||
{
|
||||
gchar *path;
|
||||
|
||||
path = g_path_get_dirname(filename);
|
||||
vte_get_working_directory(); // refresh vte_info.dir
|
||||
if (g_file_test(filename, G_FILE_TEST_IS_DIR))
|
||||
path = g_strdup(filename);
|
||||
else
|
||||
path = g_path_get_dirname(filename);
|
||||
|
||||
vte_get_working_directory(); // refresh vte_info.dir
|
||||
if (! utils_str_equal(path, vte_info.dir))
|
||||
{
|
||||
// use g_shell_quote to avoid problems with spaces, '!' or something else in path
|
||||
@ -613,6 +621,12 @@ void vte_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gin
|
||||
}
|
||||
|
||||
|
||||
static void check_run_in_vte_toggled(GtkToggleButton *togglebutton, GtkWidget *user_data)
|
||||
{
|
||||
gtk_widget_set_sensitive(user_data, gtk_toggle_button_get_active(togglebutton));
|
||||
}
|
||||
|
||||
|
||||
void vte_append_preferences_tab()
|
||||
{
|
||||
if (vte_info.have_vte)
|
||||
@ -620,7 +634,7 @@ void vte_append_preferences_tab()
|
||||
GtkWidget *notebook, *vbox, *label, *alignment, *table, *frame, *box;
|
||||
GtkWidget *font_term, *color_fore, *color_back, *spin_scrollback, *entry_emulation;
|
||||
GtkWidget *check_scroll_key, *check_scroll_out, *check_follow_path, *check_ignore_menu_key;
|
||||
GtkWidget *check_run_in_vte, *entry_shell, *button_shell, *image_shell;
|
||||
GtkWidget *check_run_in_vte, *check_skip_script, *entry_shell, *button_shell, *image_shell;
|
||||
GtkTooltips *tooltips;
|
||||
GtkObject *spin_scrollback_adj;
|
||||
|
||||
@ -754,10 +768,22 @@ void vte_append_preferences_tab()
|
||||
gtk_button_set_focus_on_click(GTK_BUTTON(check_follow_path), FALSE);
|
||||
gtk_container_add(GTK_CONTAINER(box), check_follow_path);
|
||||
|
||||
// create check_skip_script checkbox before the check_skip_script checkbox to be able to
|
||||
// use the object for the toggled handler of check_skip_script checkbox
|
||||
check_skip_script = gtk_check_button_new_with_mnemonic(_("Don't use run script"));
|
||||
gtk_tooltips_set_tip(tooltips, check_skip_script, _("Don't use the simple run script which is usually used to display the exit status of the executed program."), NULL);
|
||||
gtk_button_set_focus_on_click(GTK_BUTTON(check_skip_script), FALSE);
|
||||
gtk_widget_set_sensitive(check_skip_script, vc->run_in_vte);
|
||||
|
||||
check_run_in_vte = gtk_check_button_new_with_mnemonic(_("Execute programs in VTE"));
|
||||
gtk_tooltips_set_tip(tooltips, check_run_in_vte, _("Run programs in VTE instead of opening a terminal emulation window. Please note, programs executed in VTE cannot be stopped."), NULL);
|
||||
gtk_button_set_focus_on_click(GTK_BUTTON(check_run_in_vte), FALSE);
|
||||
gtk_container_add(GTK_CONTAINER(box), check_run_in_vte);
|
||||
g_signal_connect((gpointer) check_run_in_vte, "toggled",
|
||||
G_CALLBACK(check_run_in_vte_toggled), check_skip_script);
|
||||
|
||||
// now add the check_skip_script checkbox after the check_run_in_vte checkbox
|
||||
gtk_container_add(GTK_CONTAINER(box), check_skip_script);
|
||||
|
||||
gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 0);
|
||||
|
||||
@ -783,6 +809,8 @@ void vte_append_preferences_tab()
|
||||
gtk_widget_ref(check_follow_path), (GDestroyNotify) gtk_widget_unref);
|
||||
g_object_set_data_full(G_OBJECT(ui_widgets.prefs_dialog), "check_run_in_vte",
|
||||
gtk_widget_ref(check_run_in_vte), (GDestroyNotify) gtk_widget_unref);
|
||||
g_object_set_data_full(G_OBJECT(ui_widgets.prefs_dialog), "check_skip_script",
|
||||
gtk_widget_ref(check_skip_script), (GDestroyNotify) gtk_widget_unref);
|
||||
|
||||
gtk_widget_show_all(frame);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user