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
[] =
43 "ActionMenuGit", /* Action name */
44 NULL
, /* Stock icon, if any */
45 N_("_Git"), /* Display label */
48 NULL
/* action callback */
51 "ActionGitCommit", /* Action name */
52 GTK_STOCK_YES
, /* Stock icon, if any */
53 N_("_Commit..."), /* Display label */
56 G_CALLBACK (on_menu_git_commit
) /* action callback */
59 "ActionGitUnstageFiles", /* Action name */
60 GTK_STOCK_CANCEL
, /* Stock icon, if any */
61 N_("_Unstage files..."), /* Display label */
64 G_CALLBACK (on_menu_git_unstage
) /* action callback */
67 "ActionGitCheckoutFiles", /* Action name */
68 GTK_STOCK_UNDO
, /* Stock icon, if any */
69 N_("_Check out files..."), /* Display label */
72 G_CALLBACK (on_menu_git_checkout_files
) /* action callback */
75 "ActionGitResolve", /* Action name */
76 GTK_STOCK_PREFERENCES
, /* Stock icon, if any */
77 N_("_Resolve conflicts..."), /* Display label */
80 G_CALLBACK (on_menu_git_resolve
) /* action callback */
83 "ActionGitLog", /* Action name */
84 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
85 N_("_View log..."), /* Display label */
88 G_CALLBACK (on_menu_git_log
) /* action callback */
91 "ActionGitAdd", /* Action name */
92 GTK_STOCK_ADD
, /* Stock icon, if any */
93 N_("_Add..."), /* Display label */
96 G_CALLBACK (on_menu_git_add
) /* action callback */
99 "ActionGitRemove", /* Action name */
100 GTK_STOCK_REMOVE
, /* Stock icon, if any */
101 N_("_Remove..."), /* Display label */
102 NULL
, /* short-cut */
104 G_CALLBACK (on_menu_git_remove
) /* action callback */
107 "ActionGitCreateBranch", /* Action name */
108 GTK_STOCK_NEW
, /* Stock icon, if any */
109 N_("_Create branch..."), /* Display label */
110 NULL
, /* short-cut */
112 G_CALLBACK (on_menu_git_create_branch
) /* action callback */
115 "ActionGitDeleteBranch", /* Action name */
116 GTK_STOCK_DELETE
, /* Stock icon, if any */
117 N_("_Delete branch..."), /* Display label */
118 NULL
, /* short-cut */
120 G_CALLBACK (on_menu_git_delete_branch
) /* action callback */
123 "ActionGitSwitch", /* Action name */
124 GTK_STOCK_JUMP_TO
, /* Stock icon, if any */
125 N_("_Switch to another branch..."), /* Display label */
126 NULL
, /* short-cut */
128 G_CALLBACK (on_menu_git_switch
) /* action callback */
131 "ActionGitMerge", /* Action name */
132 GTK_STOCK_CONVERT
, /* Stock icon, if any */
133 N_("_Merge..."), /* Display label */
134 NULL
, /* short-cut */
136 G_CALLBACK (on_menu_git_merge
) /* action callback */
139 "ActionGitDiffUncommitted", /* Action name */
140 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
141 N_("_Diff uncommitted changes"), /* Display label */
142 NULL
, /* short-cut */
144 G_CALLBACK (on_menu_git_diff
) /* action callback */
148 static GtkActionEntry actions_log
[] =
151 "ActionGitLogCommitDiff", /* Action name */
152 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
153 N_("_Show commit diff"), /* Display label */
154 NULL
, /* short-cut */
156 G_CALLBACK (on_log_menu_git_commit_diff
) /* action callback */
161 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
162 const GValue
*value
, gpointer user_data
)
165 gchar
*project_root_uri
;
166 GtkAction
*git_menu_action
;
168 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
170 g_free (git_plugin
->project_root_directory
);
171 project_root_uri
= g_value_dup_string (value
);
172 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
174 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
179 gtk_action_set_sensitive (git_menu_action
, TRUE
);
180 gtk_widget_set_sensitive (git_plugin
->log_viewer
, TRUE
);
181 git_log_set_whole_project_sensitive (git_plugin
, TRUE
);
183 g_free (project_root_uri
);
187 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
190 GtkAction
*git_menu_action
;
193 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
195 g_free (git_plugin
->project_root_directory
);
196 git_plugin
->project_root_directory
= NULL
;
198 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
203 gtk_action_set_sensitive (git_menu_action
, FALSE
);
204 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
205 git_log_window_clear (git_plugin
);
209 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
213 gchar
*current_editor_uri
;
214 IAnjutaEditor
*editor
;
216 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
217 editor
= g_value_get_object (value
);
219 if (IANJUTA_IS_EDITOR (editor
))
221 g_free (git_plugin
->current_editor_filename
);
222 current_editor_uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
223 git_plugin
->current_editor_filename
= gnome_vfs_get_local_path_from_uri (current_editor_uri
);
228 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
232 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
234 g_free (git_plugin
->current_editor_filename
);
235 git_plugin
->current_editor_filename
= NULL
;
239 git_activate_plugin (AnjutaPlugin
*plugin
)
243 GtkAction
*git_menu_action
;
245 DEBUG_PRINT ("Git: Activating Git plugin ...");
247 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
248 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
250 /* Add all our actions */
251 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
254 G_N_ELEMENTS (actions_git
),
255 GETTEXT_PACKAGE
, TRUE
, plugin
);
256 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGitLog",
257 _("Git log operations"),
259 G_N_ELEMENTS (actions_log
),
260 GETTEXT_PACKAGE
, TRUE
, plugin
);
262 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
264 git_plugin
->log_popup_menu
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
),
268 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
270 on_project_root_added
,
271 on_project_root_removed
,
274 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
275 "document_manager_current_editor",
281 git_plugin
->log_viewer
= git_log_window_create (git_plugin
);
282 anjuta_shell_add_widget (plugin
->shell
,
283 git_plugin
->log_viewer
,
287 ANJUTA_SHELL_PLACEMENT_CENTER
,
289 g_object_unref (git_plugin
->log_viewer
);
293 /* Git needs a working directory to work with; it can't take full paths,
294 * so make sure that Git can't be used if there's no project opened. */
295 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
300 if (!git_plugin
->project_root_directory
)
302 gtk_action_set_sensitive (git_menu_action
, FALSE
);
303 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
310 git_deactivate_plugin (AnjutaPlugin
*plugin
)
312 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
315 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
317 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
318 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
319 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
321 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
324 anjuta_shell_remove_widget (plugin
->shell
, git_plugin
->log_viewer
, NULL
);
325 gtk_widget_destroy (git_plugin
->log_popup_menu
);
331 git_finalize (GObject
*obj
)
333 /* Finalization codes here */
334 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
338 git_dispose (GObject
*obj
)
340 /* Disposition codes */
341 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
345 git_instance_init (GObject
*obj
)
347 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
352 git_class_init (GObjectClass
*klass
)
354 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
356 parent_class
= g_type_class_peek_parent (klass
);
358 plugin_class
->activate
= git_activate_plugin
;
359 plugin_class
->deactivate
= git_deactivate_plugin
;
360 klass
->finalize
= git_finalize
;
361 klass
->dispose
= git_dispose
;
364 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
365 ANJUTA_SIMPLE_PLUGIN (Git
, git
);