Revision: 2105 http://geany.svn.sourceforge.net/geany/?rev=2105&view=rev Author: eht16 Date: 2007-12-17 08:58:26 -0800 (Mon, 17 Dec 2007)
Log Message: ----------- 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.
Modified Paths: -------------- trunk/ChangeLog trunk/src/build.c trunk/src/keyfile.c trunk/src/prefs.c trunk/src/vte.c trunk/src/vte.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-12-16 16:54:47 UTC (rev 2104) +++ trunk/ChangeLog 2007-12-17 16:58:26 UTC (rev 2105) @@ -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:
Modified: trunk/src/build.c =================================================================== --- trunk/src/build.c 2007-12-16 16:54:47 UTC (rev 2104) +++ trunk/src/build.c 2007-12-17 16:58:26 UTC (rev 2105) @@ -654,8 +654,10 @@ }
-// 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 @@ 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 @@ 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 @@
#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 @@ 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 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 @@ #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."));
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2007-12-16 16:54:47 UTC (rev 2104) +++ trunk/src/keyfile.c 2007-12-17 16:58:26 UTC (rev 2105) @@ -289,6 +289,7 @@ 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 @@ 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);
Modified: trunk/src/prefs.c =================================================================== --- trunk/src/prefs.c 2007-12-16 16:54:47 UTC (rev 2104) +++ trunk/src/prefs.c 2007-12-17 16:58:26 UTC (rev 2105) @@ -532,6 +532,9 @@
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 @@ 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
Modified: trunk/src/vte.c =================================================================== --- trunk/src/vte.c 2007-12-16 16:54:47 UTC (rev 2104) +++ trunk/src/vte.c 2007-12-17 16:58:26 UTC (rev 2105) @@ -568,15 +568,23 @@ }
-// 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 @@ }
+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 @@ 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,11 +768,23 @@ 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);
g_object_set_data_full(G_OBJECT(ui_widgets.prefs_dialog), "font_term", @@ -783,6 +809,8 @@ 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);
Modified: trunk/src/vte.h =================================================================== --- trunk/src/vte.h 2007-12-16 16:54:47 UTC (rev 2104) +++ trunk/src/vte.h 2007-12-17 16:58:26 UTC (rev 2105) @@ -54,6 +54,7 @@ gboolean ignore_menu_bar_accel; gboolean follow_path; gboolean run_in_vte; + gboolean skip_run_script; gboolean enable_bash_keys; gint scrollback_lines; gchar *emulation;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.