SF.net SVN: geany: [746] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Sat Aug 19 15:07:21 UTC 2006
Revision: 746
Author: ntrel
Date: 2006-08-19 08:07:11 -0700 (Sat, 19 Aug 2006)
ViewCVS: http://svn.sourceforge.net/geany/?rev=746&view=rev
Log Message:
-----------
Remember the VTE current directory
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/callbacks.c
trunk/src/geany.h
trunk/src/keyfile.c
trunk/src/main.c
trunk/src/prefs.c
trunk/src/vte.c
trunk/src/vte.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/ChangeLog 2006-08-19 15:07:11 UTC (rev 746)
@@ -14,6 +14,13 @@
* src/callbacks.c: Fix a segfault at startup if terminal follow path
setting is enabled.
+ * src/geany.h, src/callbacks.c, src/keyfile.c, src/vte.c, src/vte.h,
+ src/prefs.c, src/main.c:
+ Move HAVE_VTE MyApp settings to vte_info struct in src/vte.c.
+ * src/vte.c, src/vte.h:
+ Add vte_get_working_directory adapted from Terminal by os-cillation.
+ * src/vte.c, src/keyfile.c: Remember the VTE current directory.
+ * src/callbacks.c: Only send VTE cd command if directory is different.
2006-08-18 Enrico Tröger <enrico.troeger at uvena.de>
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/src/callbacks.c 2006-08-19 15:07:11 UTC (rev 746)
@@ -141,8 +141,8 @@
}
scintilla_release_resources();
#ifdef HAVE_VTE
- if (app->have_vte) vte_close();
- g_free(app->lib_vte);
+ if (vte_info.have_vte) vte_close();
+ g_free(vte_info.lib_vte);
#endif
gtk_widget_destroy(app->window);
@@ -779,23 +779,25 @@
if (idx >= 0 && app->opening_session_files == FALSE)
{
utils_check_disk_status(idx);
- }
#ifdef HAVE_VTE
- // at startup, idx is always -1, so terminal startup dir is wrong,
- // but we could remember the vte dir to fix this.
- if (idx >= 0 && app->have_vte && vc->follow_path && doc_list[idx].file_name != NULL)
- {
- gchar *path;
- gchar *cmd;
+ if (vte_info.have_vte && vc->follow_path && doc_list[idx].file_name != NULL)
+ {
+ gchar *path;
+ gchar *cmd;
- path = g_path_get_dirname(doc_list[idx].file_name);
- cmd = g_strconcat("cd ", path, "\n", NULL);
- vte_send_cmd(cmd);
- g_free(path);
- g_free(cmd);
+ path = g_path_get_dirname(doc_list[idx].file_name);
+ vte_get_working_directory(); // refresh vte_info.dir
+ if (! g_str_equal(path, vte_info.dir))
+ {
+ cmd = g_strconcat("cd ", path, "\n", NULL);
+ vte_send_cmd(cmd);
+ g_free(cmd);
+ }
+ g_free(path);
+ }
+#endif
}
-#endif
}
Modified: trunk/src/geany.h
===================================================================
--- trunk/src/geany.h 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/src/geany.h 2006-08-19 15:07:11 UTC (rev 746)
@@ -172,12 +172,6 @@
gboolean ignore_fifo;
GIOChannel *fifo_ioc;
#endif
-#ifdef HAVE_VTE
- gboolean load_vte;
- gboolean have_vte;
- gchar *lib_vte;
- gchar *terminal_settings;
-#endif
gchar *long_line_color;
gchar *pref_template_developer;
gchar *pref_template_company;
Modified: trunk/src/keyfile.c
===================================================================
--- trunk/src/keyfile.c 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/src/keyfile.c 2006-08-19 15:07:11 UTC (rev 746)
@@ -31,6 +31,7 @@
#include "document.h"
#include "sciwrappers.h"
#include "encodings.h"
+#include "vte.h"
static gchar *scribble_text = NULL;
@@ -108,10 +109,12 @@
g_key_file_set_boolean(config, PACKAGE, "auto_close_xml_tags", app->pref_editor_auto_close_xml_tags);
g_key_file_set_boolean(config, PACKAGE, "auto_complete_constructs", app->pref_editor_auto_complete_constructs);
#ifdef HAVE_VTE
- g_key_file_set_boolean(config, PACKAGE, "load_vte", app->load_vte);
+ g_key_file_set_boolean(config, PACKAGE, "load_vte", vte_info.load_vte);
g_key_file_set_comment(config, PACKAGE, "terminal_settings",
_(" VTE settings: FONT;FOREGROUND;BACKGROUND;scrollback;type;scroll on keystroke;scroll on output;follow path of file"), NULL);
- g_key_file_set_string(config, PACKAGE, "terminal_settings", app->terminal_settings);
+ g_key_file_set_string(config, PACKAGE, "terminal_settings", vte_info.terminal_settings);
+ vte_get_working_directory(); // refresh vte_info.dir
+ g_key_file_set_string(config, PACKAGE, "terminal_dir", vte_info.dir);
#endif
g_key_file_set_string(config, PACKAGE, "custom_date_format", app->custom_date_format);
g_key_file_set_string(config, PACKAGE, "editor_font", app->editor_font);
@@ -321,8 +324,9 @@
app->pref_toolbar_show_colour = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_colour", TRUE);
app->pref_toolbar_show_fileops = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_fileops", TRUE);
#ifdef HAVE_VTE
- app->load_vte = utils_get_setting_boolean(config, PACKAGE, "load_vte", TRUE);
- app->terminal_settings = utils_get_setting_string(config, PACKAGE, "terminal_settings", "");
+ vte_info.load_vte = utils_get_setting_boolean(config, PACKAGE, "load_vte", TRUE);
+ vte_info.terminal_settings = utils_get_setting_string(config, PACKAGE, "terminal_settings", "");
+ vte_info.dir = utils_get_setting_string(config, PACKAGE, "terminal_dir", NULL);
#endif
app->pref_template_developer = utils_get_setting_string(config, PACKAGE, "pref_template_developer", g_get_real_name());
app->pref_template_company = utils_get_setting_string(config, PACKAGE, "pref_template_company", "");
Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/src/main.c 2006-08-19 15:07:11 UTC (rev 746)
@@ -515,7 +515,7 @@
app->ignore_fifo = ignore_fifo;
#endif
#ifdef HAVE_VTE
- app->lib_vte = lib_vte;
+ vte_info.lib_vte = lib_vte;
#endif
app->ignore_global_tags = ignore_global_tags;
}
@@ -586,8 +586,7 @@
configuration_load();
// do this here to let cmdline options overwrite configuration settings
#ifdef HAVE_VTE
- app->have_vte = app->load_vte;
- if (no_vte) app->have_vte = FALSE;
+ vte_info.have_vte = (no_vte) ? FALSE : vte_info.load_vte;
#endif
if (no_msgwin) app->msgwindow_visible = FALSE;
Modified: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/src/prefs.c 2006-08-19 15:07:11 UTC (rev 746)
@@ -322,10 +322,10 @@
// make VTE switch visible only when VTE is compiled in, it is hidden by default
widget = lookup_widget(app->prefs_dialog, "check_vte");
gtk_widget_show(widget);
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->load_vte);
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), vte_info.load_vte);
// VTE settings
- if (app->have_vte)
+ if (vte_info.have_vte)
{
widget = lookup_widget(app->prefs_dialog, "font_term");
gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);
@@ -568,10 +568,10 @@
#ifdef HAVE_VTE
widget = lookup_widget(app->prefs_dialog, "check_vte");
- app->load_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+ vte_info.load_vte = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
// VTE settings
- if (app->have_vte)
+ if (vte_info.have_vte)
{
gchar *hex_color_back, *hex_color_fore;
@@ -591,10 +591,10 @@
widget = lookup_widget(app->prefs_dialog, "check_follow_path");
vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
- g_free(app->terminal_settings);
+ g_free(vte_info.terminal_settings);
hex_color_fore = utils_get_hex_from_color(vc->color_fore);
hex_color_back = utils_get_hex_from_color(vc->color_back);
- app->terminal_settings = g_strdup_printf("%s;%s;%s;%d;%s;%s;%s;%s", vc->font,
+ vte_info.terminal_settings = g_strdup_printf("%s;%s;%s;%d;%s;%s;%s;%s", vc->font,
hex_color_fore, hex_color_back,
vc->scrollback_lines, vc->emulation,
utils_btoa(vc->scroll_on_key), utils_btoa(vc->scroll_on_out),
@@ -933,7 +933,7 @@
}
#ifdef HAVE_VTE
- if (app->have_vte)
+ if (vte_info.have_vte)
{
tooltips = GTK_TOOLTIPS(lookup_widget(app->prefs_dialog, "tooltips"));
notebook = lookup_widget(app->prefs_dialog, "notebook2");
Modified: trunk/src/vte.c
===================================================================
--- trunk/src/vte.c 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/src/vte.c 2006-08-19 15:07:11 UTC (rev 746)
@@ -37,6 +37,8 @@
#include "callbacks.h"
+VteInfo vte_info;
+
extern gchar **environ;
static pid_t pid;
static GModule *module = NULL;
@@ -103,15 +105,15 @@
GtkWidget *vte, *scrollbar, *hbox, *frame;
- if (app->have_vte == FALSE)
+ if (vte_info.have_vte == FALSE)
{ // app->have_vte can be false, even if VTE is compiled in, think of command line option
geany_debug("Disabling terminal support");
return;
}
- if (app->lib_vte && strlen(app->lib_vte))
+ if (vte_info.lib_vte && strlen(vte_info.lib_vte))
{
- module = g_module_open(app->lib_vte, G_MODULE_BIND_LAZY);
+ module = g_module_open(vte_info.lib_vte, G_MODULE_BIND_LAZY);
}
else
{
@@ -122,13 +124,13 @@
if (module == NULL)
{
- app->have_vte = FALSE;
+ vte_info.have_vte = FALSE;
geany_debug("Could not load libvte.so.4, terminal support disabled");
return;
}
else
{
- app->have_vte = TRUE;
+ vte_info.have_vte = TRUE;
vf = g_new0(struct vte_funcs, 1);
vc = g_new0(struct vte_conf, 1);
vte_register_symbols(module);
@@ -234,7 +236,8 @@
}
env = vte_get_child_environment();
- pid = vf->vte_terminal_fork_command(VTE_TERMINAL(vte), shell, NULL, env, dir, TRUE, TRUE, TRUE);
+ pid = vf->vte_terminal_fork_command(VTE_TERMINAL(vte), shell, NULL, env,
+ (vte_info.dir == NULL) ? dir : vte_info.dir, TRUE, TRUE, TRUE);
g_strfreev(env);
}
@@ -310,12 +313,13 @@
static void vte_get_settings(void)
{
- gchar **values = g_strsplit(app->terminal_settings, ";", 8);
+ gchar **values = g_strsplit(vte_info.terminal_settings, ";", 8);
if (g_strv_length(values) != 8)
{
- app->terminal_settings = g_strdup_printf("Monospace 10;#FFFFFF;#000000;500;xterm;true;true;false");
- values = g_strsplit(app->terminal_settings, ";", 8);
+ vte_info.terminal_settings =
+ g_strdup_printf("Monospace 10;#FFFFFF;#000000;500;xterm;true;true;false");
+ values = g_strsplit(vte_info.terminal_settings, ";", 8);
}
vc->font = g_strdup(values[0]);
vc->color_fore = g_new0(GdkColor, 1);
@@ -408,6 +412,49 @@
}
+/* Taken from Terminal by os-cillation: terminal_screen_get_working_directory, thanks.
+ * Determinies the working directory using various OS-specific mechanisms. */
+const gchar* vte_get_working_directory()
+{
+ gchar buffer[4096 + 1];
+ gchar *file;
+ gchar *cwd;
+ gint length;
+
+ if (pid >= 0)
+ {
+ file = g_strdup_printf ("/proc/%d/cwd", pid);
+ length = readlink (file, buffer, sizeof (buffer));
+
+ if (length > 0 && *buffer == '/')
+ {
+ buffer[length] = '\0';
+ g_free(vte_info.dir);
+ vte_info.dir = g_strdup (buffer);
+ }
+ else if (length == 0)
+ {
+ cwd = g_get_current_dir ();
+ if (G_LIKELY (cwd != NULL))
+ {
+ if (chdir (file) == 0)
+ {
+ g_free(vte_info.dir);
+ vte_info.dir = g_get_current_dir ();
+ chdir (cwd);
+ }
+
+ g_free (cwd);
+ }
+ }
+
+ g_free (file);
+ }
+
+ return vte_info.dir;
+}
+
+
/*
void vte_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y,
GtkSelectionData *data, guint info, guint time)
Modified: trunk/src/vte.h
===================================================================
--- trunk/src/vte.h 2006-08-19 14:46:04 UTC (rev 745)
+++ trunk/src/vte.h 2006-08-19 15:07:11 UTC (rev 746)
@@ -30,6 +30,20 @@
#include <unistd.h>
+#ifdef HAVE_VTE
+typedef struct
+{
+ gboolean load_vte;
+ gboolean have_vte;
+ gchar *lib_vte;
+ gchar *terminal_settings;
+ gchar *dir;
+} VteInfo;
+
+extern VteInfo vte_info;
+#endif
+
+
void vte_init(void);
void vte_close(void);
@@ -38,6 +52,8 @@
void vte_send_cmd(const gchar *cmd);
+const gchar* vte_get_working_directory();
+
/*
void vte_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y,
GtkSelectionData *data, guint info, guint time);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list