Implemented some basic diff support.
[anjuta-git-plugin.git] / plugins / git / plugin.c
blobe7b953ed512c0fa87df394f5aeca940ff0c64099
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"
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 */
34 NULL, /* short-cut */
35 NULL, /* Tooltip */
36 NULL /* action callback */
39 "ActionGitDiffUncommitted", /* Action name */
40 GTK_STOCK_ZOOM_100, /* Stock icon, if any */
41 N_("_Diff uncommitted changes"), /* Display label */
42 NULL, /* short-cut */
43 NULL, /* Tooltip */
44 G_CALLBACK (on_menu_git_diff) /* action callback */
48 static void
49 on_project_root_added (AnjutaPlugin *plugin, const gchar *name,
50 const GValue *value, gpointer user_data)
52 Git *git_plugin;
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,
63 NULL),
64 "ActionGroupGit",
65 "ActionMenuGit");
67 gtk_action_set_sensitive (git_menu_action, TRUE);
69 g_free (project_root_uri);
72 static void
73 on_project_root_removed (AnjutaPlugin *plugin, const gchar *name,
74 gpointer user_data)
76 GtkAction *git_menu_action;
77 Git *git_plugin;
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,
85 NULL),
86 "ActionGroupGit",
87 "ActionMenuGit");
89 gtk_action_set_sensitive (git_menu_action, FALSE);
92 static gboolean
93 git_activate_plugin (AnjutaPlugin *plugin)
95 AnjutaUI *ui;
96 Git *git_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",
106 _("Git operations"),
107 actions_git,
108 G_N_ELEMENTS (actions_git),
109 GETTEXT_PACKAGE, TRUE, plugin);
110 git_plugin->uiid = anjuta_ui_merge (ui, UI_FILE);
112 /* Add watches */
113 git_plugin->project_root_watch_id = anjuta_plugin_add_watch (plugin,
114 "project_root_uri",
115 on_project_root_added,
116 on_project_root_removed,
117 NULL);
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,
122 NULL),
123 "ActionGroupGit",
124 "ActionMenuGit");
126 gtk_action_set_sensitive (git_menu_action, FALSE);
128 return TRUE;
131 static gboolean
132 git_deactivate_plugin (AnjutaPlugin *plugin)
134 AnjutaUI *ui = anjuta_shell_get_ui (plugin->shell, NULL);
135 Git *git_plugin;
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,
142 TRUE);
144 return TRUE;
147 static void
148 git_finalize (GObject *obj)
150 /* Finalization codes here */
151 G_OBJECT_CLASS (parent_class)->finalize (obj);
154 static void
155 git_dispose (GObject *obj)
157 /* Disposition codes */
158 G_OBJECT_CLASS (parent_class)->dispose (obj);
161 static void
162 git_instance_init (GObject *obj)
164 Git *plugin = ANJUTA_PLUGIN_GIT (obj);
165 plugin->uiid = 0;
168 static void
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);