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"
26 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
28 static gpointer parent_class
;
30 static GtkActionEntry actions_git
[] = {
32 "ActionMenuGit", /* Action name */
33 NULL
, /* Stock icon, if any */
34 N_("_Git"), /* Display label */
37 NULL
/* action callback */
40 "ActionGitCommit", /* Action name */
41 GTK_STOCK_YES
, /* Stock icon, if any */
42 N_("_Commit..."), /* Display label */
45 G_CALLBACK (on_menu_git_commit
) /* action callback */
48 "ActionGitDiffUncommitted", /* Action name */
49 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
50 N_("_Diff uncommitted changes"), /* Display label */
53 G_CALLBACK (on_menu_git_diff
) /* action callback */
58 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
59 const GValue
*value
, gpointer user_data
)
62 gchar
*project_root_uri
;
63 GtkAction
*git_menu_action
;
65 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
67 g_free (git_plugin
->project_root_directory
);
68 project_root_uri
= g_value_dup_string (value
);
69 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
71 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
76 gtk_action_set_sensitive (git_menu_action
, TRUE
);
78 g_free (project_root_uri
);
82 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
85 GtkAction
*git_menu_action
;
88 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
90 g_free (git_plugin
->project_root_directory
);
91 git_plugin
->project_root_directory
= NULL
;
93 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
98 gtk_action_set_sensitive (git_menu_action
, FALSE
);
102 git_activate_plugin (AnjutaPlugin
*plugin
)
106 GtkAction
*git_menu_action
108 DEBUG_PRINT ("Git: Activating Git plugin ...");
110 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
111 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
113 /* Add all our actions */
114 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
117 G_N_ELEMENTS (actions_git
),
118 GETTEXT_PACKAGE
, TRUE
, plugin
);
119 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
122 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
124 on_project_root_added
,
125 on_project_root_removed
,
128 /* Git needs a working directory to work with; it can't take full paths,
129 * so make sure that Git can't be used if there's no project opened. */
130 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
135 gtk_action_set_sensitive (git_menu_action
, FALSE
);
141 git_deactivate_plugin (AnjutaPlugin
*plugin
)
143 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
146 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
148 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
149 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
150 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
157 git_finalize (GObject
*obj
)
159 /* Finalization codes here */
160 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
164 git_dispose (GObject
*obj
)
166 /* Disposition codes */
167 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
171 git_instance_init (GObject
*obj
)
173 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
178 git_class_init (GObjectClass
*klass
)
180 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
182 parent_class
= g_type_class_peek_parent (klass
);
184 plugin_class
->activate
= git_activate_plugin
;
185 plugin_class
->deactivate
= git_deactivate_plugin
;
186 klass
->finalize
= git_finalize
;
187 klass
->dispose
= git_dispose
;
190 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
191 ANJUTA_SIMPLE_PLUGIN (Git
, git
);