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"
25 #include "git-add-dialog.h"
26 #include "git-remove-dialog.h"
27 #include "git-resolve-dialog.h"
28 #include "git-merge-dialog.h"
29 #include "git-switch-dialog.h"
30 #include "git-create-branch-dialog.h"
32 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
34 static gpointer parent_class
;
36 static GtkActionEntry actions_git
[] = {
38 "ActionMenuGit", /* Action name */
39 NULL
, /* Stock icon, if any */
40 N_("_Git"), /* Display label */
43 NULL
/* action callback */
46 "ActionGitCommit", /* Action name */
47 GTK_STOCK_YES
, /* Stock icon, if any */
48 N_("_Commit..."), /* Display label */
51 G_CALLBACK (on_menu_git_commit
) /* action callback */
54 "ActionGitResolve", /* Action name */
55 GTK_STOCK_PREFERENCES
, /* Stock icon, if any */
56 N_("_Resolve conflicts..."), /* Display label */
59 G_CALLBACK (on_menu_git_resolve
) /* action callback */
62 "ActionGitAdd", /* Action name */
63 GTK_STOCK_ADD
, /* Stock icon, if any */
64 N_("_Add..."), /* Display label */
67 G_CALLBACK (on_menu_git_add
) /* action callback */
70 "ActionGitRemove", /* Action name */
71 GTK_STOCK_REMOVE
, /* Stock icon, if any */
72 N_("_Remove..."), /* Display label */
75 G_CALLBACK (on_menu_git_remove
) /* action callback */
78 "ActionGitCreateBranch", /* Action name */
79 GTK_STOCK_NEW
, /* Stock icon, if any */
80 N_("_Create branch..."), /* Display label */
83 G_CALLBACK (on_menu_git_create_branch
) /* action callback */
86 "ActionGitSwitch", /* Action name */
87 GTK_STOCK_JUMP_TO
, /* Stock icon, if any */
88 N_("_Switch to another branch..."), /* Display label */
91 G_CALLBACK (on_menu_git_switch
) /* action callback */
94 "ActionGitMerge", /* Action name */
95 GTK_STOCK_CONVERT
, /* Stock icon, if any */
96 N_("_Merge..."), /* Display label */
99 G_CALLBACK (on_menu_git_merge
) /* action callback */
102 "ActionGitDiffUncommitted", /* Action name */
103 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
104 N_("_Diff uncommitted changes"), /* Display label */
105 NULL
, /* short-cut */
107 G_CALLBACK (on_menu_git_diff
) /* action callback */
112 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
113 const GValue
*value
, gpointer user_data
)
116 gchar
*project_root_uri
;
117 GtkAction
*git_menu_action
;
119 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
121 g_free (git_plugin
->project_root_directory
);
122 project_root_uri
= g_value_dup_string (value
);
123 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
125 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
130 gtk_action_set_sensitive (git_menu_action
, TRUE
);
132 g_free (project_root_uri
);
136 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
139 GtkAction
*git_menu_action
;
142 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
144 g_free (git_plugin
->project_root_directory
);
145 git_plugin
->project_root_directory
= NULL
;
147 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
152 gtk_action_set_sensitive (git_menu_action
, FALSE
);
156 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
160 gchar
*current_editor_uri
;
161 IAnjutaEditor
*editor
;
163 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
164 editor
= g_value_get_object (value
);
166 if (IANJUTA_IS_EDITOR (editor
))
168 g_free (git_plugin
->current_editor_filename
);
169 current_editor_uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
170 git_plugin
->current_editor_filename
= gnome_vfs_get_local_path_from_uri (current_editor_uri
);
175 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
179 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
181 g_free (git_plugin
->current_editor_filename
);
182 git_plugin
->current_editor_filename
= NULL
;
186 git_activate_plugin (AnjutaPlugin
*plugin
)
190 GtkAction
*git_menu_action
192 DEBUG_PRINT ("Git: Activating Git plugin ...");
194 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
195 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
197 /* Add all our actions */
198 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
201 G_N_ELEMENTS (actions_git
),
202 GETTEXT_PACKAGE
, TRUE
, plugin
);
203 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
206 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
208 on_project_root_added
,
209 on_project_root_removed
,
212 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
213 "document_manager_current_editor",
218 /* Git needs a working directory to work with; it can't take full paths,
219 * so make sure that Git can't be used if there's no project opened. */
220 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
225 if (!git_plugin
->project_root_directory
)
226 gtk_action_set_sensitive (git_menu_action
, FALSE
);
232 git_deactivate_plugin (AnjutaPlugin
*plugin
)
234 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
237 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
239 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
240 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
241 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
243 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
250 git_finalize (GObject
*obj
)
252 /* Finalization codes here */
253 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
257 git_dispose (GObject
*obj
)
259 /* Disposition codes */
260 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
264 git_instance_init (GObject
*obj
)
266 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
271 git_class_init (GObjectClass
*klass
)
273 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
275 parent_class
= g_type_class_peek_parent (klass
);
277 plugin_class
->activate
= git_activate_plugin
;
278 plugin_class
->deactivate
= git_deactivate_plugin
;
279 klass
->finalize
= git_finalize
;
280 klass
->dispose
= git_dispose
;
283 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
284 ANJUTA_SIMPLE_PLUGIN (Git
, git
);