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"
25 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
27 static gpointer parent_class
;
29 static GtkActionEntry actions_git
[] = {
31 "ActionMenuGit", /* Action name */
32 NULL
, /* Stock icon, if any */
33 N_("_Git"), /* Display label */
36 NULL
/* action callback */
39 "ActionGitDiffUncommitted", /* Action name */
40 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
41 N_("_Diff uncommitted changes"), /* Display label */
44 G_CALLBACK (on_menu_git_diff
) /* action callback */
49 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
50 const GValue
*value
, gpointer user_data
)
53 gchar
*project_root_uri
;
54 GtkAction
*git_menu_action
;
56 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
58 g_free (git_plugin
->project_root_directory
);
59 project_root_uri
= g_value_dup_string (value
);
60 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
62 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
67 gtk_action_set_sensitive (git_menu_action
, TRUE
);
69 g_free (project_root_uri
);
73 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
76 GtkAction
*git_menu_action
;
79 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
81 g_free (git_plugin
->project_root_directory
);
82 git_plugin
->project_root_directory
= NULL
;
84 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
89 gtk_action_set_sensitive (git_menu_action
, FALSE
);
93 git_activate_plugin (AnjutaPlugin
*plugin
)
97 GtkAction
*git_menu_action
99 DEBUG_PRINT ("Git: Activating Git plugin ...");
101 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
102 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
104 /* Add all our actions */
105 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
108 G_N_ELEMENTS (actions_git
),
109 GETTEXT_PACKAGE
, TRUE
, plugin
);
110 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
113 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
115 on_project_root_added
,
116 on_project_root_removed
,
119 /* Git needs a working directory to work with; it can't take full paths,
120 * so make sure that Git can't be used if there's no project opened. */
121 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
126 gtk_action_set_sensitive (git_menu_action
, FALSE
);
132 git_deactivate_plugin (AnjutaPlugin
*plugin
)
134 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
137 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
139 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
140 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
141 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
148 git_finalize (GObject
*obj
)
150 /* Finalization codes here */
151 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
155 git_dispose (GObject
*obj
)
157 /* Disposition codes */
158 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
162 git_instance_init (GObject
*obj
)
164 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
169 git_class_init (GObjectClass
*klass
)
171 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
173 parent_class
= g_type_class_peek_parent (klass
);
175 plugin_class
->activate
= git_activate_plugin
;
176 plugin_class
->deactivate
= git_deactivate_plugin
;
177 klass
->finalize
= git_finalize
;
178 klass
->dispose
= git_dispose
;
181 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
182 ANJUTA_SIMPLE_PLUGIN (Git
, git
);