Kaydet (Commit) ac3d9284 authored tarafından Nick Treleaven's avatar Nick Treleaven

Remember the VTE current directory

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@746 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 3d4aea44
...@@ -14,6 +14,13 @@ ...@@ -14,6 +14,13 @@
* src/callbacks.c: Fix a segfault at startup if terminal follow path * src/callbacks.c: Fix a segfault at startup if terminal follow path
setting is enabled. 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@uvena.de> 2006-08-18 Enrico Tröger <enrico.troeger@uvena.de>
......
...@@ -141,8 +141,8 @@ gint destroyapp(GtkWidget *widget, gpointer gdata) ...@@ -141,8 +141,8 @@ gint destroyapp(GtkWidget *widget, gpointer gdata)
} }
scintilla_release_resources(); scintilla_release_resources();
#ifdef HAVE_VTE #ifdef HAVE_VTE
if (app->have_vte) vte_close(); if (vte_info.have_vte) vte_close();
g_free(app->lib_vte); g_free(vte_info.lib_vte);
#endif #endif
gtk_widget_destroy(app->window); gtk_widget_destroy(app->window);
...@@ -779,23 +779,25 @@ on_notebook1_switch_page_after (GtkNotebook *notebook, ...@@ -779,23 +779,25 @@ on_notebook1_switch_page_after (GtkNotebook *notebook,
if (idx >= 0 && app->opening_session_files == FALSE) if (idx >= 0 && app->opening_session_files == FALSE)
{ {
utils_check_disk_status(idx); utils_check_disk_status(idx);
}
#ifdef HAVE_VTE #ifdef HAVE_VTE
// at startup, idx is always -1, so terminal startup dir is wrong, if (vte_info.have_vte && vc->follow_path && doc_list[idx].file_name != NULL)
// 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;
gchar *path;
gchar *cmd;
path = g_path_get_dirname(doc_list[idx].file_name); path = g_path_get_dirname(doc_list[idx].file_name);
cmd = g_strconcat("cd ", path, "\n", NULL); vte_get_working_directory(); // refresh vte_info.dir
vte_send_cmd(cmd); if (! g_str_equal(path, vte_info.dir))
g_free(path); {
g_free(cmd); cmd = g_strconcat("cd ", path, "\n", NULL);
} vte_send_cmd(cmd);
g_free(cmd);
}
g_free(path);
}
#endif #endif
}
} }
......
...@@ -171,12 +171,6 @@ typedef struct MyApp ...@@ -171,12 +171,6 @@ typedef struct MyApp
#ifdef HAVE_FIFO #ifdef HAVE_FIFO
gboolean ignore_fifo; gboolean ignore_fifo;
GIOChannel *fifo_ioc; GIOChannel *fifo_ioc;
#endif
#ifdef HAVE_VTE
gboolean load_vte;
gboolean have_vte;
gchar *lib_vte;
gchar *terminal_settings;
#endif #endif
gchar *long_line_color; gchar *long_line_color;
gchar *pref_template_developer; gchar *pref_template_developer;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "document.h" #include "document.h"
#include "sciwrappers.h" #include "sciwrappers.h"
#include "encodings.h" #include "encodings.h"
#include "vte.h"
static gchar *scribble_text = NULL; static gchar *scribble_text = NULL;
...@@ -108,10 +109,12 @@ void configuration_save() ...@@ -108,10 +109,12 @@ void configuration_save()
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_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); g_key_file_set_boolean(config, PACKAGE, "auto_complete_constructs", app->pref_editor_auto_complete_constructs);
#ifdef HAVE_VTE #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", 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); _(" 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 #endif
g_key_file_set_string(config, PACKAGE, "custom_date_format", app->custom_date_format); 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); g_key_file_set_string(config, PACKAGE, "editor_font", app->editor_font);
...@@ -321,8 +324,9 @@ gboolean configuration_load() ...@@ -321,8 +324,9 @@ gboolean configuration_load()
app->pref_toolbar_show_colour = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_colour", TRUE); 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); app->pref_toolbar_show_fileops = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_fileops", TRUE);
#ifdef HAVE_VTE #ifdef HAVE_VTE
app->load_vte = utils_get_setting_boolean(config, PACKAGE, "load_vte", TRUE); vte_info.load_vte = utils_get_setting_boolean(config, PACKAGE, "load_vte", TRUE);
app->terminal_settings = utils_get_setting_string(config, PACKAGE, "terminal_settings", ""); 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 #endif
app->pref_template_developer = utils_get_setting_string(config, PACKAGE, "pref_template_developer", g_get_real_name()); 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", ""); app->pref_template_company = utils_get_setting_string(config, PACKAGE, "pref_template_company", "");
......
...@@ -515,7 +515,7 @@ static void parse_command_line_options(gint *argc, gchar ***argv) ...@@ -515,7 +515,7 @@ static void parse_command_line_options(gint *argc, gchar ***argv)
app->ignore_fifo = ignore_fifo; app->ignore_fifo = ignore_fifo;
#endif #endif
#ifdef HAVE_VTE #ifdef HAVE_VTE
app->lib_vte = lib_vte; vte_info.lib_vte = lib_vte;
#endif #endif
app->ignore_global_tags = ignore_global_tags; app->ignore_global_tags = ignore_global_tags;
} }
...@@ -586,8 +586,7 @@ gint main(gint argc, gchar **argv) ...@@ -586,8 +586,7 @@ gint main(gint argc, gchar **argv)
configuration_load(); configuration_load();
// do this here to let cmdline options overwrite configuration settings // do this here to let cmdline options overwrite configuration settings
#ifdef HAVE_VTE #ifdef HAVE_VTE
app->have_vte = app->load_vte; vte_info.have_vte = (no_vte) ? FALSE : vte_info.load_vte;
if (no_vte) app->have_vte = FALSE;
#endif #endif
if (no_msgwin) app->msgwindow_visible = FALSE; if (no_msgwin) app->msgwindow_visible = FALSE;
......
...@@ -322,10 +322,10 @@ void prefs_init_dialog(void) ...@@ -322,10 +322,10 @@ void prefs_init_dialog(void)
// make VTE switch visible only when VTE is compiled in, it is hidden by default // make VTE switch visible only when VTE is compiled in, it is hidden by default
widget = lookup_widget(app->prefs_dialog, "check_vte"); widget = lookup_widget(app->prefs_dialog, "check_vte");
gtk_widget_show(widget); 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 // VTE settings
if (app->have_vte) if (vte_info.have_vte)
{ {
widget = lookup_widget(app->prefs_dialog, "font_term"); widget = lookup_widget(app->prefs_dialog, "font_term");
gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font); gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);
...@@ -568,10 +568,10 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat ...@@ -568,10 +568,10 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat
#ifdef HAVE_VTE #ifdef HAVE_VTE
widget = lookup_widget(app->prefs_dialog, "check_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 // VTE settings
if (app->have_vte) if (vte_info.have_vte)
{ {
gchar *hex_color_back, *hex_color_fore; gchar *hex_color_back, *hex_color_fore;
...@@ -591,10 +591,10 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat ...@@ -591,10 +591,10 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat
widget = lookup_widget(app->prefs_dialog, "check_follow_path"); widget = lookup_widget(app->prefs_dialog, "check_follow_path");
vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); 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_fore = utils_get_hex_from_color(vc->color_fore);
hex_color_back = utils_get_hex_from_color(vc->color_back); 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, hex_color_fore, hex_color_back,
vc->scrollback_lines, vc->emulation, vc->scrollback_lines, vc->emulation,
utils_btoa(vc->scroll_on_key), utils_btoa(vc->scroll_on_out), utils_btoa(vc->scroll_on_key), utils_btoa(vc->scroll_on_out),
...@@ -933,7 +933,7 @@ void dialogs_show_prefs_dialog(void) ...@@ -933,7 +933,7 @@ void dialogs_show_prefs_dialog(void)
} }
#ifdef HAVE_VTE #ifdef HAVE_VTE
if (app->have_vte) if (vte_info.have_vte)
{ {
tooltips = GTK_TOOLTIPS(lookup_widget(app->prefs_dialog, "tooltips")); tooltips = GTK_TOOLTIPS(lookup_widget(app->prefs_dialog, "tooltips"));
notebook = lookup_widget(app->prefs_dialog, "notebook2"); notebook = lookup_widget(app->prefs_dialog, "notebook2");
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "callbacks.h" #include "callbacks.h"
VteInfo vte_info;
extern gchar **environ; extern gchar **environ;
static pid_t pid; static pid_t pid;
static GModule *module = NULL; static GModule *module = NULL;
...@@ -103,15 +105,15 @@ void vte_init(void) ...@@ -103,15 +105,15 @@ void vte_init(void)
GtkWidget *vte, *scrollbar, *hbox, *frame; 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 { // app->have_vte can be false, even if VTE is compiled in, think of command line option
geany_debug("Disabling terminal support"); geany_debug("Disabling terminal support");
return; 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 else
{ {
...@@ -122,13 +124,13 @@ void vte_init(void) ...@@ -122,13 +124,13 @@ void vte_init(void)
if (module == NULL) if (module == NULL)
{ {
app->have_vte = FALSE; vte_info.have_vte = FALSE;
geany_debug("Could not load libvte.so.4, terminal support disabled"); geany_debug("Could not load libvte.so.4, terminal support disabled");
return; return;
} }
else else
{ {
app->have_vte = TRUE; vte_info.have_vte = TRUE;
vf = g_new0(struct vte_funcs, 1); vf = g_new0(struct vte_funcs, 1);
vc = g_new0(struct vte_conf, 1); vc = g_new0(struct vte_conf, 1);
vte_register_symbols(module); vte_register_symbols(module);
...@@ -234,7 +236,8 @@ static void vte_start(GtkWidget *widget) ...@@ -234,7 +236,8 @@ static void vte_start(GtkWidget *widget)
} }
env = vte_get_child_environment(); 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); g_strfreev(env);
} }
...@@ -310,12 +313,13 @@ void vte_apply_user_settings(void) ...@@ -310,12 +313,13 @@ void vte_apply_user_settings(void)
static void vte_get_settings(void) 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) if (g_strv_length(values) != 8)
{ {
app->terminal_settings = g_strdup_printf("Monospace 10;#FFFFFF;#000000;500;xterm;true;true;false"); vte_info.terminal_settings =
values = g_strsplit(app->terminal_settings, ";", 8); 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->font = g_strdup(values[0]);
vc->color_fore = g_new0(GdkColor, 1); vc->color_fore = g_new0(GdkColor, 1);
...@@ -408,6 +412,49 @@ void vte_send_cmd(const gchar *cmd) ...@@ -408,6 +412,49 @@ void vte_send_cmd(const gchar *cmd)
} }
/* 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, void vte_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y,
GtkSelectionData *data, guint info, guint time) GtkSelectionData *data, guint info, guint time)
......
...@@ -30,6 +30,20 @@ ...@@ -30,6 +30,20 @@
#include <unistd.h> #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_init(void);
void vte_close(void); void vte_close(void);
...@@ -38,6 +52,8 @@ void vte_apply_user_settings(void); ...@@ -38,6 +52,8 @@ void vte_apply_user_settings(void);
void vte_send_cmd(const gchar *cmd); 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, void vte_drag_data_received(GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y,
GtkSelectionData *data, guint info, guint time); GtkSelectionData *data, guint info, guint time);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment