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"
35 #include "git-create-tag-dialog.h"
36 #include "git-reset-dialog.h"
37 #include "git-revert-dialog.h"
38 #include "git-fetch-dialog.h"
39 #include "git-rebase-dialog.h"
40 #include "git-bisect-dialog.h"
41 #include "git-ignore-dialog.h"
42 #include "git-add-remote-dialog.h"
43 #include "git-delete-remote-dialog.h"
44 #include "git-create-patch-series-dialog.h"
45 #include "git-pull-dialog.h"
47 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
49 static gpointer parent_class
;
51 static GtkActionEntry actions_git
[] =
54 "ActionMenuGit", /* Action name */
55 NULL
, /* Stock icon, if any */
56 N_("_Git"), /* Display label */
59 NULL
/* action callback */
62 "ActionGitCommit", /* Action name */
63 GTK_STOCK_YES
, /* Stock icon, if any */
64 N_("_Commit..."), /* Display label */
67 G_CALLBACK (on_menu_git_commit
) /* action callback */
70 "ActionGitFetch", /* Action name */
71 GTK_STOCK_CONNECT
, /* Stock icon, if any */
72 N_("_Fetch"), /* Display label */
75 G_CALLBACK (on_menu_git_fetch
) /* action callback */
78 "ActionMenuGitRebase", /* Action name */
79 NULL
, /* Stock icon, if any */
80 N_("_Rebase"), /* Display label */
83 NULL
/* action callback */
86 "ActionGitRebaseStart", /* Action name */
87 NULL
, /* Stock icon, if any */
88 N_("_Start..."), /* Display label */
91 G_CALLBACK (on_menu_git_rebase_start
) /* action callback */
94 "ActionGitRebaseContinue", /* Action name */
95 NULL
, /* Stock icon, if any */
96 N_("_Continue"), /* Display label */
99 G_CALLBACK (on_menu_git_rebase_continue
) /* action callback */
102 "ActionGitRebaseSkip", /* Action name */
103 NULL
, /* Stock icon, if any */
104 N_("_Skip"), /* Display label */
105 NULL
, /* short-cut */
107 G_CALLBACK (on_menu_git_rebase_skip
) /* action callback */
110 "ActionGitRebaseAbort", /* Action name */
111 NULL
, /* Stock icon, if any */
112 N_("_Abort"), /* Display label */
113 NULL
, /* short-cut */
115 G_CALLBACK (on_menu_git_rebase_abort
) /* action callback */
118 "ActionGitPull", /* Action name */
119 GTK_STOCK_GO_BACK
, /* Stock icon, if any */
120 N_("_Pull..."), /* Display label */
121 NULL
, /* short-cut */
123 G_CALLBACK (on_menu_git_pull
) /* action callback */
126 "ActionGitUnstageFiles", /* Action name */
127 GTK_STOCK_CANCEL
, /* Stock icon, if any */
128 N_("_Unstage files..."), /* Display label */
129 NULL
, /* short-cut */
131 G_CALLBACK (on_menu_git_unstage
) /* action callback */
134 "ActionGitCheckoutFiles", /* Action name */
135 GTK_STOCK_UNDO
, /* Stock icon, if any */
136 N_("_Check out files..."), /* Display label */
137 NULL
, /* short-cut */
139 G_CALLBACK (on_menu_git_checkout_files
) /* action callback */
142 "ActionGitResolve", /* Action name */
143 GTK_STOCK_PREFERENCES
, /* Stock icon, if any */
144 N_("_Resolve conflicts..."), /* Display label */
145 NULL
, /* short-cut */
147 G_CALLBACK (on_menu_git_resolve
) /* action callback */
150 "ActionGitCreatePatchSeries", /* Action name */
151 GTK_STOCK_DND_MULTIPLE
, /* Stock icon, if any */
152 N_("Create patch series..."), /* Display label */
153 NULL
, /* short-cut */
155 G_CALLBACK (on_menu_git_create_patch_series
) /* action callback */
158 "ActionGitReset", /* Action name */
159 GTK_STOCK_REFRESH
, /* Stock icon, if any */
160 N_("_Reset tree..."), /* Display label */
161 NULL
, /* short-cut */
163 G_CALLBACK (on_menu_git_reset
) /* action callback */
166 "ActionGitRevert", /* Action name */
167 GTK_STOCK_UNDO
, /* Stock icon, if any */
168 N_("_Revert commit..."), /* Display label */
169 NULL
, /* short-cut */
171 G_CALLBACK (on_menu_git_revert
) /* action callback */
174 "ActionMenuGitBisect", /* Action name */
175 NULL
, /* Stock icon, if any */
176 N_("_Bisect"), /* Display label */
177 NULL
, /* short-cut */
179 NULL
/* action callback */
182 "ActionGitBisectStart", /* Action name */
183 GTK_STOCK_MEDIA_PLAY
, /* Stock icon, if any */
184 N_("_Start..."), /* Display label */
185 NULL
, /* short-cut */
187 G_CALLBACK (on_menu_git_bisect_start
) /* action callback */
190 "ActionGitBisectReset", /* Action name */
191 GTK_STOCK_REFRESH
, /* Stock icon, if any */
192 N_("_Reset"), /* Display label */
193 NULL
, /* short-cut */
195 G_CALLBACK (on_menu_git_bisect_reset
) /* action callback */
198 "ActionGitBisectGood", /* Action name */
199 GTK_STOCK_YES
, /* Stock icon, if any */
200 N_("_Good"), /* Display label */
201 NULL
, /* short-cut */
203 G_CALLBACK (on_menu_git_bisect_good
) /* action callback */
206 "ActionGitBisectBad", /* Action name */
207 GTK_STOCK_NO
, /* Stock icon, if any */
208 N_("_Bad"), /* Display label */
209 NULL
, /* short-cut */
211 G_CALLBACK (on_menu_git_bisect_bad
) /* action callback */
214 "ActionGitLog", /* Action name */
215 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
216 N_("_View log..."), /* Display label */
217 NULL
, /* short-cut */
219 G_CALLBACK (on_menu_git_log
) /* action callback */
222 "ActionGitAdd", /* Action name */
223 GTK_STOCK_ADD
, /* Stock icon, if any */
224 N_("_Add..."), /* Display label */
225 NULL
, /* short-cut */
227 G_CALLBACK (on_menu_git_add
) /* action callback */
230 "ActionGitRemove", /* Action name */
231 GTK_STOCK_REMOVE
, /* Stock icon, if any */
232 N_("_Remove..."), /* Display label */
233 NULL
, /* short-cut */
235 G_CALLBACK (on_menu_git_remove
) /* action callback */
238 "ActionGitIgnore", /* Action name */
239 GTK_STOCK_DIALOG_ERROR
, /* Stock icon, if any */
240 N_("_Ignore..."), /* Display label */
241 NULL
, /* short-cut */
243 G_CALLBACK (on_menu_git_ignore
) /* action callback */
247 "ActionGitCreateBranch", /* Action name */
248 NULL
, /* Stock icon, if any */
249 N_("_Create branch..."), /* Display label */
250 NULL
, /* short-cut */
252 G_CALLBACK (on_menu_git_create_branch
) /* action callback */
255 "ActionGitDeleteBranch", /* Action name */
256 GTK_STOCK_DELETE
, /* Stock icon, if any */
257 N_("_Delete branch..."), /* Display label */
258 NULL
, /* short-cut */
260 G_CALLBACK (on_menu_git_delete_branch
) /* action callback */
263 "ActionGitSwitch", /* Action name */
264 GTK_STOCK_JUMP_TO
, /* Stock icon, if any */
265 N_("_Switch to another branch..."), /* Display label */
266 NULL
, /* short-cut */
268 G_CALLBACK (on_menu_git_switch
) /* action callback */
271 "ActionGitMerge", /* Action name */
272 GTK_STOCK_CONVERT
, /* Stock icon, if any */
273 N_("_Merge..."), /* Display label */
274 NULL
, /* short-cut */
276 G_CALLBACK (on_menu_git_merge
) /* action callback */
279 "ActionMenuGitRemoteBranches", /* Action name */
280 GTK_STOCK_NETWORK
, /* Stock icon, if any */
281 N_("_Remote branches"), /* Display label */
282 NULL
, /* short-cut */
284 NULL
/* action callback */
287 "ActionGitRemoteAdd", /* Action name */
288 GTK_STOCK_ADD
, /* Stock icon, if any */
289 N_("_Add..."), /* Display label */
290 NULL
, /* short-cut */
292 G_CALLBACK (on_menu_git_add_remote
) /* action callback */
295 "ActionGitRemoteDelete", /* Action name */
296 GTK_STOCK_DELETE
, /* Stock icon, if any */
297 N_("_Delete..."), /* Display label */
298 NULL
, /* short-cut */
300 G_CALLBACK (on_menu_git_delete_remote
) /* action callback */
303 "ActionGitCreateTag", /* Action name */
304 NULL
, /* Stock icon, if any */
305 N_("_Create tag..."), /* Display label */
306 NULL
, /* short-cut */
308 G_CALLBACK (on_menu_git_create_tag
) /* action callback */
311 "ActionGitDiffUncommitted", /* Action name */
312 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
313 N_("_Diff uncommitted changes"), /* Display label */
314 NULL
, /* short-cut */
316 G_CALLBACK (on_menu_git_diff
) /* action callback */
320 static GtkActionEntry actions_log
[] =
323 "ActionGitLogCommitDiff", /* Action name */
324 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
325 N_("_Show commit diff"), /* Display label */
326 NULL
, /* short-cut */
328 G_CALLBACK (on_log_menu_git_commit_diff
) /* action callback */
331 "ActionGitLogCreateBranch", /* Action name */
332 NULL
, /* Stock icon, if any */
333 N_("_Create branch..."), /* Display label */
334 NULL
, /* short-cut */
336 G_CALLBACK (on_log_menu_git_create_branch
) /* action callback */
339 "ActionGitLogCreateTag", /* Action name */
340 NULL
, /* Stock icon, if any */
341 N_("_Create tag..."), /* Display label */
342 NULL
, /* short-cut */
344 G_CALLBACK (on_log_menu_git_create_tag
) /* action callback */
347 "ActionGitLogReset", /* Action name */
348 GTK_STOCK_REFRESH
, /* Stock icon, if any */
349 N_("_Reset tree..."), /* Display label */
350 NULL
, /* short-cut */
352 G_CALLBACK (on_log_menu_git_reset
) /* action callback */
355 "ActionGitLogRevert", /* Action name */
356 GTK_STOCK_UNDO
, /* Stock icon, if any */
357 N_("_Revert commit..."), /* Display label */
358 NULL
, /* short-cut */
360 G_CALLBACK (on_log_menu_git_revert
) /* action callback */
363 "ActionMenuGitLogBisect", /* Action name */
364 NULL
, /* Stock icon, if any */
365 N_("_Bisect"), /* Display label */
366 NULL
, /* short-cut */
368 NULL
/* action callback */
371 "ActionGitLogBisectGood", /* Action name */
372 GTK_STOCK_YES
, /* Stock icon, if any */
373 N_("_Set good revision"), /* Display label */
374 NULL
, /* short-cut */
376 G_CALLBACK (on_log_menu_git_bisect_good
) /* action callback */
379 "ActionGitLogBisectBad", /* Action name */
380 GTK_STOCK_NO
, /* Stock icon, if any */
381 N_("_Set bad revision"), /* Display label */
382 NULL
, /* short-cut */
384 G_CALLBACK (on_log_menu_git_bisect_bad
) /* action callback */
389 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
390 const GValue
*value
, gpointer user_data
)
393 gchar
*project_root_uri
;
396 GtkAction
*git_menu_action
;
398 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
400 g_free (git_plugin
->project_root_directory
);
401 project_root_uri
= g_value_dup_string (value
);
402 file
= g_file_new_for_uri (project_root_uri
);
403 git_plugin
->project_root_directory
= g_file_get_path (file
);
404 g_object_unref (file
);
406 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
407 git_menu_action
= anjuta_ui_get_action (ui
,
411 gtk_action_set_sensitive (git_menu_action
, TRUE
);
412 gtk_widget_set_sensitive (git_plugin
->log_viewer
, TRUE
);
414 g_free (project_root_uri
);
416 git_plugin
->bisect_file_monitor
= bisect_menus_init (git_plugin
);
420 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
423 GtkAction
*git_menu_action
;
426 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
428 g_free (git_plugin
->project_root_directory
);
429 git_plugin
->project_root_directory
= NULL
;
431 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
436 gtk_action_set_sensitive (git_menu_action
, FALSE
);
437 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
438 git_log_window_clear (git_plugin
);
440 g_file_monitor_cancel (git_plugin
->bisect_file_monitor
);
441 g_object_unref (git_plugin
->bisect_file_monitor
);
445 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
449 IAnjutaEditor
*editor
;
450 GFile
*current_editor_file
;
452 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
453 editor
= g_value_get_object (value
);
455 g_free (git_plugin
->current_editor_filename
);
456 git_plugin
->current_editor_filename
= NULL
;
458 if (IANJUTA_IS_EDITOR (editor
))
460 current_editor_file
= ianjuta_file_get_file (IANJUTA_FILE (editor
),
463 if (current_editor_file
)
465 git_plugin
->current_editor_filename
= g_file_get_path (current_editor_file
);
466 g_object_unref (current_editor_file
);
472 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
476 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
478 g_free (git_plugin
->current_editor_filename
);
479 git_plugin
->current_editor_filename
= NULL
;
483 git_activate_plugin (AnjutaPlugin
*plugin
)
487 GtkAction
*git_menu_action
;
489 DEBUG_PRINT ("Git: Activating Git plugin ...");
491 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
492 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
494 /* Add all our actions */
495 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
498 G_N_ELEMENTS (actions_git
),
499 GETTEXT_PACKAGE
, TRUE
, plugin
);
500 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGitLog",
501 _("Git log operations"),
503 G_N_ELEMENTS (actions_log
),
504 GETTEXT_PACKAGE
, TRUE
, plugin
);
506 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
508 git_plugin
->log_popup_menu
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
),
512 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
513 IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI
,
514 on_project_root_added
,
515 on_project_root_removed
,
518 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
519 IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT
,
525 git_plugin
->log_viewer
= git_log_window_create (git_plugin
);
526 anjuta_shell_add_widget (plugin
->shell
,
527 git_plugin
->log_viewer
,
531 ANJUTA_SHELL_PLACEMENT_CENTER
,
533 g_object_unref (git_plugin
->log_viewer
);
537 /* Git needs a working directory to work with; it can't take full paths,
538 * so make sure that Git can't be used if there's no project opened. */
539 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
544 if (!git_plugin
->project_root_directory
)
546 gtk_action_set_sensitive (git_menu_action
, FALSE
);
547 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
554 git_deactivate_plugin (AnjutaPlugin
*plugin
)
556 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
559 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
561 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
562 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
563 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
565 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
568 anjuta_shell_remove_widget (plugin
->shell
, git_plugin
->log_viewer
, NULL
);
569 gtk_widget_destroy (git_plugin
->log_popup_menu
);
575 git_finalize (GObject
*obj
)
577 /* Finalization codes here */
578 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
582 git_dispose (GObject
*obj
)
584 /* Disposition codes */
585 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
589 git_instance_init (GObject
*obj
)
591 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
596 git_class_init (GObjectClass
*klass
)
598 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
600 parent_class
= g_type_class_peek_parent (klass
);
602 plugin_class
->activate
= git_activate_plugin
;
603 plugin_class
->deactivate
= git_deactivate_plugin
;
604 klass
->finalize
= git_finalize
;
605 klass
->dispose
= git_dispose
;
608 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
609 ANJUTA_SIMPLE_PLUGIN (Git
, git
);