1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) James Liggett 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301 USA
23 #include "git-diff-dialog.h"
24 #include "git-commit-dialog.h"
26 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
28 static gpointer parent_class
;
30 static GtkActionEntry actions_git
[] = {
32 "ActionMenuGit", /* Action name */
33 NULL
, /* Stock icon, if any */
34 N_("_Git"), /* Display label */
37 NULL
/* action callback */
40 "ActionGitCommit", /* Action name */
41 GTK_STOCK_YES
, /* Stock icon, if any */
42 N_("_Commit..."), /* Display label */
45 G_CALLBACK (on_menu_git_commit
) /* action callback */
48 "ActionGitDiffUncommitted", /* Action name */
49 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
50 N_("_Diff uncommitted changes"), /* Display label */
53 G_CALLBACK (on_menu_git_diff
) /* action callback */
58 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
59 const GValue
*value
, gpointer user_data
)
62 gchar
*project_root_uri
;
63 GtkAction
*git_menu_action
;
65 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
67 g_free (git_plugin
->project_root_directory
);
68 project_root_uri
= g_value_dup_string (value
);
69 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
71 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
76 gtk_action_set_sensitive (git_menu_action
, TRUE
);
78 g_free (project_root_uri
);
82 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
85 GtkAction
*git_menu_action
;
88 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
90 g_free (git_plugin
->project_root_directory
);
91 git_plugin
->project_root_directory
= NULL
;
93 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
98 gtk_action_set_sensitive (git_menu_action
, FALSE
);
102 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
106 gchar
*current_editor_uri
;
107 IAnjutaEditor
*editor
;
109 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
110 editor
= g_value_get_object (value
);
112 if (IANJUTA_IS_EDITOR (editor
))
114 g_free (git_plugin
->current_editor_filename
);
115 current_editor_uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
116 git_plugin
->current_editor_filename
= gnome_vfs_get_local_path_from_uri (current_editor_uri
);
121 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
125 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
127 g_free (git_plugin
->current_editor_filename
);
128 git_plugin
->current_editor_filename
= NULL
;
132 git_activate_plugin (AnjutaPlugin
*plugin
)
136 GtkAction
*git_menu_action
138 DEBUG_PRINT ("Git: Activating Git plugin ...");
140 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
141 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
143 /* Add all our actions */
144 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
147 G_N_ELEMENTS (actions_git
),
148 GETTEXT_PACKAGE
, TRUE
, plugin
);
149 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
152 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
154 on_project_root_added
,
155 on_project_root_removed
,
158 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
159 "document_manager_current_editor",
164 /* Git needs a working directory to work with; it can't take full paths,
165 * so make sure that Git can't be used if there's no project opened. */
166 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
171 gtk_action_set_sensitive (git_menu_action
, FALSE
);
177 git_deactivate_plugin (AnjutaPlugin
*plugin
)
179 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
182 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
184 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
185 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
186 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
188 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
195 git_finalize (GObject
*obj
)
197 /* Finalization codes here */
198 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
202 git_dispose (GObject
*obj
)
204 /* Disposition codes */
205 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
209 git_instance_init (GObject
*obj
)
211 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
216 git_class_init (GObjectClass
*klass
)
218 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
220 parent_class
= g_type_class_peek_parent (klass
);
222 plugin_class
->activate
= git_activate_plugin
;
223 plugin_class
->deactivate
= git_deactivate_plugin
;
224 klass
->finalize
= git_finalize
;
225 klass
->dispose
= git_dispose
;
228 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
229 ANJUTA_SIMPLE_PLUGIN (Git
, git
);