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"
31 #include "git-delete-branch-dialog.h"
32 #include "git-unstage-dialog.h"
33 #include "git-checkout-files-dialog.h"
34 #include "git-log-dialog.h"
36 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
38 static gpointer parent_class
;
40 static GtkActionEntry actions_git
[] = {
42 "ActionMenuGit", /* Action name */
43 NULL
, /* Stock icon, if any */
44 N_("_Git"), /* Display label */
47 NULL
/* action callback */
50 "ActionGitCommit", /* Action name */
51 GTK_STOCK_YES
, /* Stock icon, if any */
52 N_("_Commit..."), /* Display label */
55 G_CALLBACK (on_menu_git_commit
) /* action callback */
58 "ActionGitUnstageFiles", /* Action name */
59 GTK_STOCK_CANCEL
, /* Stock icon, if any */
60 N_("_Unstage files..."), /* Display label */
63 G_CALLBACK (on_menu_git_unstage
) /* action callback */
66 "ActionGitCheckoutFiles", /* Action name */
67 GTK_STOCK_UNDO
, /* Stock icon, if any */
68 N_("_Check out files..."), /* Display label */
71 G_CALLBACK (on_menu_git_checkout_files
) /* action callback */
74 "ActionGitResolve", /* Action name */
75 GTK_STOCK_PREFERENCES
, /* Stock icon, if any */
76 N_("_Resolve conflicts..."), /* Display label */
79 G_CALLBACK (on_menu_git_resolve
) /* action callback */
82 "ActionGitLog", /* Action name */
83 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
84 N_("_View log..."), /* Display label */
87 G_CALLBACK (on_menu_git_log
) /* action callback */
90 "ActionGitAdd", /* Action name */
91 GTK_STOCK_ADD
, /* Stock icon, if any */
92 N_("_Add..."), /* Display label */
95 G_CALLBACK (on_menu_git_add
) /* action callback */
98 "ActionGitRemove", /* Action name */
99 GTK_STOCK_REMOVE
, /* Stock icon, if any */
100 N_("_Remove..."), /* Display label */
101 NULL
, /* short-cut */
103 G_CALLBACK (on_menu_git_remove
) /* action callback */
106 "ActionGitCreateBranch", /* Action name */
107 GTK_STOCK_NEW
, /* Stock icon, if any */
108 N_("_Create branch..."), /* Display label */
109 NULL
, /* short-cut */
111 G_CALLBACK (on_menu_git_create_branch
) /* action callback */
114 "ActionGitDeleteBranch", /* Action name */
115 GTK_STOCK_DELETE
, /* Stock icon, if any */
116 N_("_Delete branch..."), /* Display label */
117 NULL
, /* short-cut */
119 G_CALLBACK (on_menu_git_delete_branch
) /* action callback */
122 "ActionGitSwitch", /* Action name */
123 GTK_STOCK_JUMP_TO
, /* Stock icon, if any */
124 N_("_Switch to another branch..."), /* Display label */
125 NULL
, /* short-cut */
127 G_CALLBACK (on_menu_git_switch
) /* action callback */
130 "ActionGitMerge", /* Action name */
131 GTK_STOCK_CONVERT
, /* Stock icon, if any */
132 N_("_Merge..."), /* Display label */
133 NULL
, /* short-cut */
135 G_CALLBACK (on_menu_git_merge
) /* action callback */
138 "ActionGitDiffUncommitted", /* Action name */
139 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
140 N_("_Diff uncommitted changes"), /* Display label */
141 NULL
, /* short-cut */
143 G_CALLBACK (on_menu_git_diff
) /* action callback */
148 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
149 const GValue
*value
, gpointer user_data
)
152 gchar
*project_root_uri
;
153 GtkAction
*git_menu_action
;
155 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
157 g_free (git_plugin
->project_root_directory
);
158 project_root_uri
= g_value_dup_string (value
);
159 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
161 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
166 gtk_action_set_sensitive (git_menu_action
, TRUE
);
167 gtk_widget_set_sensitive (git_plugin
->log_viewer
, TRUE
);
168 git_log_set_whole_project_sensitive (git_plugin
, TRUE
);
170 g_free (project_root_uri
);
174 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
177 GtkAction
*git_menu_action
;
180 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
182 g_free (git_plugin
->project_root_directory
);
183 git_plugin
->project_root_directory
= NULL
;
185 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
190 gtk_action_set_sensitive (git_menu_action
, FALSE
);
191 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
192 git_log_window_clear (git_plugin
);
196 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
200 gchar
*current_editor_uri
;
201 IAnjutaEditor
*editor
;
203 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
204 editor
= g_value_get_object (value
);
206 if (IANJUTA_IS_EDITOR (editor
))
208 g_free (git_plugin
->current_editor_filename
);
209 current_editor_uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
210 git_plugin
->current_editor_filename
= gnome_vfs_get_local_path_from_uri (current_editor_uri
);
215 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
219 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
221 g_free (git_plugin
->current_editor_filename
);
222 git_plugin
->current_editor_filename
= NULL
;
226 git_activate_plugin (AnjutaPlugin
*plugin
)
230 GtkAction
*git_menu_action
232 DEBUG_PRINT ("Git: Activating Git plugin ...");
234 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
235 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
237 /* Add all our actions */
238 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
241 G_N_ELEMENTS (actions_git
),
242 GETTEXT_PACKAGE
, TRUE
, plugin
);
243 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
246 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
248 on_project_root_added
,
249 on_project_root_removed
,
252 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
253 "document_manager_current_editor",
259 git_plugin
->log_viewer
= git_log_window_create (git_plugin
);
260 anjuta_shell_add_widget (plugin
->shell
,
261 git_plugin
->log_viewer
,
265 ANJUTA_SHELL_PLACEMENT_CENTER
,
267 g_object_unref (git_plugin
->log_viewer
);
269 /* Git needs a working directory to work with; it can't take full paths,
270 * so make sure that Git can't be used if there's no project opened. */
271 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
276 if (!git_plugin
->project_root_directory
)
278 gtk_action_set_sensitive (git_menu_action
, FALSE
);
279 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
286 git_deactivate_plugin (AnjutaPlugin
*plugin
)
288 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
291 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
293 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
294 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
295 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
297 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
300 anjuta_shell_remove_widget (plugin
->shell
, git_plugin
->log_viewer
, NULL
);
306 git_finalize (GObject
*obj
)
308 /* Finalization codes here */
309 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
313 git_dispose (GObject
*obj
)
315 /* Disposition codes */
316 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
320 git_instance_init (GObject
*obj
)
322 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
327 git_class_init (GObjectClass
*klass
)
329 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
331 parent_class
= g_type_class_peek_parent (klass
);
333 plugin_class
->activate
= git_activate_plugin
;
334 plugin_class
->deactivate
= git_deactivate_plugin
;
335 klass
->finalize
= git_finalize
;
336 klass
->dispose
= git_dispose
;
339 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
340 ANJUTA_SIMPLE_PLUGIN (Git
, git
);