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 */
388 static GtkActionEntry actions_fm
[] =
391 "ActionMenuGitFM", /* Action name */
392 NULL
, /* Stock icon, if any */
393 N_("_Git"), /* Display label */
394 NULL
, /* short-cut */
396 NULL
/* action callback */
399 "ActionGitFMLog", /* Action name */
400 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
401 N_("_View log..."), /* Display label */
402 NULL
, /* short-cut */
404 G_CALLBACK (on_fm_git_log
) /* action callback */
407 "ActionGitFMAdd", /* Action name */
408 GTK_STOCK_ADD
, /* Stock icon, if any */
409 N_("_Add..."), /* Display label */
410 NULL
, /* short-cut */
412 G_CALLBACK (on_fm_git_add
) /* action callback */
415 "ActionGitFMRemove", /* Action name */
416 GTK_STOCK_REMOVE
, /* Stock icon, if any */
417 N_("_Remove..."), /* Display label */
418 NULL
, /* short-cut */
420 G_CALLBACK (on_fm_git_remove
) /* action callback */
425 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
426 const GValue
*value
, gpointer user_data
)
429 gchar
*project_root_uri
;
432 GtkAction
*git_menu_action
;
433 GtkAction
*git_fm_menu_action
;
435 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
437 g_free (git_plugin
->project_root_directory
);
438 project_root_uri
= g_value_dup_string (value
);
439 file
= g_file_new_for_uri (project_root_uri
);
440 git_plugin
->project_root_directory
= g_file_get_path (file
);
441 g_object_unref (file
);
443 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
444 git_menu_action
= anjuta_ui_get_action (ui
,
447 git_fm_menu_action
= anjuta_ui_get_action (ui
,
451 gtk_action_set_sensitive (git_menu_action
, TRUE
);
452 gtk_action_set_sensitive (git_fm_menu_action
, TRUE
);
453 gtk_widget_set_sensitive (git_plugin
->log_viewer
, TRUE
);
455 g_free (project_root_uri
);
457 git_plugin
->bisect_file_monitor
= bisect_menus_init (git_plugin
);
461 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
465 GtkAction
*git_menu_action
;
466 GtkAction
*git_fm_menu_action
;
469 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
471 g_free (git_plugin
->project_root_directory
);
472 git_plugin
->project_root_directory
= NULL
;
474 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
476 git_menu_action
= anjuta_ui_get_action (ui
,
479 git_fm_menu_action
= anjuta_ui_get_action (ui
,
483 gtk_action_set_sensitive (git_menu_action
, FALSE
);
484 gtk_action_set_sensitive (git_fm_menu_action
, FALSE
);
485 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
486 git_log_window_clear (git_plugin
);
488 g_file_monitor_cancel (git_plugin
->bisect_file_monitor
);
489 g_object_unref (git_plugin
->bisect_file_monitor
);
493 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
497 IAnjutaEditor
*editor
;
498 GFile
*current_editor_file
;
500 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
501 editor
= g_value_get_object (value
);
503 g_free (git_plugin
->current_editor_filename
);
504 git_plugin
->current_editor_filename
= NULL
;
506 if (IANJUTA_IS_EDITOR (editor
))
508 current_editor_file
= ianjuta_file_get_file (IANJUTA_FILE (editor
),
511 if (current_editor_file
)
513 git_plugin
->current_editor_filename
= g_file_get_path (current_editor_file
);
514 g_object_unref (current_editor_file
);
520 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
524 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
526 g_free (git_plugin
->current_editor_filename
);
527 git_plugin
->current_editor_filename
= NULL
;
531 on_fm_file_added (AnjutaPlugin
*plugin
, const char *name
,
532 const GValue
*value
, gpointer data
)
537 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
539 g_free (git_plugin
->current_fm_filename
);
541 file
= G_FILE (g_value_get_object (value
));
542 git_plugin
->current_fm_filename
= g_file_get_path (file
);
546 on_fm_file_removed (AnjutaPlugin
*plugin
, const char *name
, gpointer data
)
550 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
552 g_free (git_plugin
->current_fm_filename
);
553 git_plugin
->current_fm_filename
= NULL
;
557 git_activate_plugin (AnjutaPlugin
*plugin
)
561 GtkAction
*git_menu_action
;
562 GtkAction
*git_fm_menu_action
;
564 DEBUG_PRINT ("Git: Activating Git plugin ...");
566 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
567 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
569 /* Add all our actions */
570 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
573 G_N_ELEMENTS (actions_git
),
574 GETTEXT_PACKAGE
, TRUE
, plugin
);
575 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGitLog",
576 _("Git log operations"),
578 G_N_ELEMENTS (actions_log
),
579 GETTEXT_PACKAGE
, TRUE
, plugin
);
580 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGitFM",
581 _("Git FM operations"),
583 G_N_ELEMENTS (actions_fm
),
584 GETTEXT_PACKAGE
, TRUE
, plugin
);
586 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
588 git_plugin
->log_popup_menu
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
),
592 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
593 IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI
,
594 on_project_root_added
,
595 on_project_root_removed
,
598 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
599 IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT
,
604 git_plugin
->fm_watch_id
= anjuta_plugin_add_watch (plugin
,
605 IANJUTA_FILE_MANAGER_SELECTED_FILE
,
611 git_plugin
->log_viewer
= git_log_window_create (git_plugin
);
612 anjuta_shell_add_widget (plugin
->shell
,
613 git_plugin
->log_viewer
,
617 ANJUTA_SHELL_PLACEMENT_CENTER
,
619 g_object_unref (git_plugin
->log_viewer
);
623 /* Git needs a working directory to work with; it can't take full paths,
624 * so make sure that Git can't be used if there's no project opened. */
625 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
629 git_fm_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
634 if (!git_plugin
->project_root_directory
)
636 gtk_action_set_sensitive (git_menu_action
, FALSE
);
637 gtk_action_set_sensitive (git_fm_menu_action
, FALSE
);
638 gtk_widget_set_sensitive (git_plugin
->log_viewer
, FALSE
);
645 git_deactivate_plugin (AnjutaPlugin
*plugin
)
647 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
650 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
652 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
653 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
654 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
656 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
658 anjuta_plugin_remove_watch (plugin
, git_plugin
->fm_watch_id
,
661 g_free (git_plugin
->project_root_directory
);
662 g_free (git_plugin
->current_editor_filename
);
663 g_free (git_plugin
->current_fm_filename
);
665 anjuta_shell_remove_widget (plugin
->shell
, git_plugin
->log_viewer
, NULL
);
666 gtk_widget_destroy (git_plugin
->log_popup_menu
);
672 git_finalize (GObject
*obj
)
674 /* Finalization codes here */
675 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
679 git_dispose (GObject
*obj
)
681 /* Disposition codes */
682 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
686 git_instance_init (GObject
*obj
)
688 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
693 git_class_init (GObjectClass
*klass
)
695 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
697 parent_class
= g_type_class_peek_parent (klass
);
699 plugin_class
->activate
= git_activate_plugin
;
700 plugin_class
->deactivate
= git_deactivate_plugin
;
701 klass
->finalize
= git_finalize
;
702 klass
->dispose
= git_dispose
;
705 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
706 ANJUTA_SIMPLE_PLUGIN (Git
, git
);