Implement commit support.
[anjuta-git-plugin.git] / plugins / git / plugin.c
blob1edf4516b95795f533d3374705ed8ae65f15aa7a
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 plugin.c
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
22 #include "plugin.h"
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 */
35 NULL, /* short-cut */
36 NULL, /* Tooltip */
37 NULL /* action callback */
40 "ActionGitCommit", /* Action name */
41 GTK_STOCK_YES, /* Stock icon, if any */
42 N_("_Commit..."), /* Display label */
43 NULL, /* short-cut */
44 NULL, /* Tooltip */
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 */
51 NULL, /* short-cut */
52 NULL, /* Tooltip */
53 G_CALLBACK (on_menu_git_diff) /* action callback */
57 static void
58 on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
59 const GValue *value, gpointer user_data)
61 Git *git_plugin;
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,
72 NULL),
73 "ActionGroupGit",
74 "ActionMenuGit");
76 gtk_action_set_sensitive (git_menu_action, TRUE);
78 g_free (project_root_uri);
81 static void
82 on_project_root_removed (AnjutaPlugin *plugin, const gchar *name,
83 gpointer user_data)
85 GtkAction *git_menu_action;
86 Git *git_plugin;
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,
94 NULL),
95 "ActionGroupGit",
96 "ActionMenuGit");
98 gtk_action_set_sensitive (git_menu_action, FALSE);
101 static gboolean
102 git_activate_plugin (AnjutaPlugin *plugin)
104 AnjutaUI *ui;
105 Git *git_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",
115 _("Git operations"),
116 actions_git,
117 G_N_ELEMENTS (actions_git),
118 GETTEXT_PACKAGE, TRUE, plugin);
119 git_plugin->uiid = anjuta_ui_merge (ui, UI_FILE);
121 /* Add watches */
122 git_plugin->project_root_watch_id = anjuta_plugin_add_watch (plugin,
123 "project_root_uri",
124 on_project_root_added,
125 on_project_root_removed,
126 NULL);
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,
131 NULL),
132 "ActionGroupGit",
133 "ActionMenuGit");
135 gtk_action_set_sensitive (git_menu_action, FALSE);
137 return TRUE;
140 static gboolean
141 git_deactivate_plugin (AnjutaPlugin *plugin)
143 AnjutaUI *ui = anjuta_shell_get_ui (plugin->shell, NULL);
144 Git *git_plugin;
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,
151 TRUE);
153 return TRUE;
156 static void
157 git_finalize (GObject *obj)
159 /* Finalization codes here */
160 G_OBJECT_CLASS (parent_class)->finalize (obj);
163 static void
164 git_dispose (GObject *obj)
166 /* Disposition codes */
167 G_OBJECT_CLASS (parent_class)->dispose (obj);
170 static void
171 git_instance_init (GObject *obj)
173 Git *plugin = ANJUTA_PLUGIN_GIT (obj);
174 plugin->uiid = 0;
177 static void
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);