From 219d0fb72647346366392bd045f3a638794cfe36 Mon Sep 17 00:00:00 2001 From: James Liggett Date: Tue, 22 Apr 2008 00:10:37 -0700 Subject: [PATCH] Set up editor filename watch. --- plugins/git/plugin.c | 38 ++++++++++++++++++++++++++++++++++++++ plugins/git/plugin.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c index 1edf4516..05460c3a 100644 --- a/plugins/git/plugin.c +++ b/plugins/git/plugin.c @@ -98,6 +98,36 @@ on_project_root_removed (AnjutaPlugin *plugin, const gchar *name, gtk_action_set_sensitive (git_menu_action, FALSE); } +static void +on_editor_added (AnjutaPlugin *plugin, const gchar *name, const GValue *value, + gpointer user_data) +{ + Git *git_plugin; + gchar *current_editor_uri; + IAnjutaEditor *editor; + + git_plugin = ANJUTA_PLUGIN_GIT (plugin); + editor = g_value_get_object (value); + + if (IANJUTA_IS_EDITOR (editor)) + { + g_free (git_plugin->current_editor_filename); + current_editor_uri = ianjuta_file_get_uri (IANJUTA_FILE (editor), NULL); + git_plugin->current_editor_filename = gnome_vfs_get_local_path_from_uri (current_editor_uri); + } +} + +static void +on_editor_removed (AnjutaPlugin *plugin, const gchar *name, gpointer user_data) +{ + Git *git_plugin; + + git_plugin = ANJUTA_PLUGIN_GIT (plugin); + + g_free (git_plugin->current_editor_filename); + git_plugin->current_editor_filename = NULL; +} + static gboolean git_activate_plugin (AnjutaPlugin *plugin) { @@ -125,6 +155,12 @@ git_activate_plugin (AnjutaPlugin *plugin) on_project_root_removed, NULL); + git_plugin->editor_watch_id = anjuta_plugin_add_watch (plugin, + "document_manager_current_editor", + on_editor_added, + on_editor_removed, + NULL); + /* Git needs a working directory to work with; it can't take full paths, * so make sure that Git can't be used if there's no project opened. */ git_menu_action = anjuta_ui_get_action (anjuta_shell_get_ui (plugin->shell, @@ -149,6 +185,8 @@ git_deactivate_plugin (AnjutaPlugin *plugin) anjuta_ui_unmerge (ui, git_plugin->uiid); anjuta_plugin_remove_watch (plugin, git_plugin->project_root_watch_id, TRUE); + anjuta_plugin_remove_watch (plugin, git_plugin->editor_watch_id, + TRUE); return TRUE; } diff --git a/plugins/git/plugin.h b/plugins/git/plugin.h index eba8528d..69ca387b 100644 --- a/plugins/git/plugin.h +++ b/plugins/git/plugin.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -48,10 +49,12 @@ struct _Git AnjutaPlugin parent; gint uiid; gchar *project_root_directory; + gchar *current_editor_filename; IAnjutaMessageView *message_view; /* Watches */ gint project_root_watch_id; + gint editor_watch_id; }; struct _GitClass -- 2.11.4.GIT