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"
30 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
32 static gpointer parent_class
;
34 static GtkActionEntry actions_git
[] = {
36 "ActionMenuGit", /* Action name */
37 NULL
, /* Stock icon, if any */
38 N_("_Git"), /* Display label */
41 NULL
/* action callback */
44 "ActionGitCommit", /* Action name */
45 GTK_STOCK_YES
, /* Stock icon, if any */
46 N_("_Commit..."), /* Display label */
49 G_CALLBACK (on_menu_git_commit
) /* action callback */
52 "ActionGitResolve", /* Action name */
53 GTK_STOCK_PREFERENCES
, /* Stock icon, if any */
54 N_("_Resolve Conflicts..."), /* Display label */
57 G_CALLBACK (on_menu_git_resolve
) /* action callback */
60 "ActionGitAdd", /* Action name */
61 GTK_STOCK_ADD
, /* Stock icon, if any */
62 N_("_Add..."), /* Display label */
65 G_CALLBACK (on_menu_git_add
) /* action callback */
68 "ActionGitRemove", /* Action name */
69 GTK_STOCK_REMOVE
, /* Stock icon, if any */
70 N_("_Remove..."), /* Display label */
73 G_CALLBACK (on_menu_git_remove
) /* action callback */
76 "ActionGitMerge", /* Action name */
77 GTK_STOCK_CONVERT
, /* Stock icon, if any */
78 N_("_Merge..."), /* Display label */
81 G_CALLBACK (on_menu_git_merge
) /* action callback */
84 "ActionGitDiffUncommitted", /* Action name */
85 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
86 N_("_Diff uncommitted changes"), /* Display label */
89 G_CALLBACK (on_menu_git_diff
) /* action callback */
94 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
95 const GValue
*value
, gpointer user_data
)
98 gchar
*project_root_uri
;
99 GtkAction
*git_menu_action
;
101 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
103 g_free (git_plugin
->project_root_directory
);
104 project_root_uri
= g_value_dup_string (value
);
105 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
107 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
112 gtk_action_set_sensitive (git_menu_action
, TRUE
);
114 g_free (project_root_uri
);
118 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
121 GtkAction
*git_menu_action
;
124 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
126 g_free (git_plugin
->project_root_directory
);
127 git_plugin
->project_root_directory
= NULL
;
129 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
134 gtk_action_set_sensitive (git_menu_action
, FALSE
);
138 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
142 gchar
*current_editor_uri
;
143 IAnjutaEditor
*editor
;
145 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
146 editor
= g_value_get_object (value
);
148 if (IANJUTA_IS_EDITOR (editor
))
150 g_free (git_plugin
->current_editor_filename
);
151 current_editor_uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
152 git_plugin
->current_editor_filename
= gnome_vfs_get_local_path_from_uri (current_editor_uri
);
157 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
161 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
163 g_free (git_plugin
->current_editor_filename
);
164 git_plugin
->current_editor_filename
= NULL
;
168 git_activate_plugin (AnjutaPlugin
*plugin
)
172 GtkAction
*git_menu_action
174 DEBUG_PRINT ("Git: Activating Git plugin ...");
176 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
177 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
179 /* Add all our actions */
180 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
183 G_N_ELEMENTS (actions_git
),
184 GETTEXT_PACKAGE
, TRUE
, plugin
);
185 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
188 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
190 on_project_root_added
,
191 on_project_root_removed
,
194 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
195 "document_manager_current_editor",
200 /* Git needs a working directory to work with; it can't take full paths,
201 * so make sure that Git can't be used if there's no project opened. */
202 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
207 gtk_action_set_sensitive (git_menu_action
, FALSE
);
213 git_deactivate_plugin (AnjutaPlugin
*plugin
)
215 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
218 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
220 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
221 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
222 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
224 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
231 git_finalize (GObject
*obj
)
233 /* Finalization codes here */
234 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
238 git_dispose (GObject
*obj
)
240 /* Disposition codes */
241 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
245 git_instance_init (GObject
*obj
)
247 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
252 git_class_init (GObjectClass
*klass
)
254 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
256 parent_class
= g_type_class_peek_parent (klass
);
258 plugin_class
->activate
= git_activate_plugin
;
259 plugin_class
->deactivate
= git_deactivate_plugin
;
260 klass
->finalize
= git_finalize
;
261 klass
->dispose
= git_dispose
;
264 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
265 ANJUTA_SIMPLE_PLUGIN (Git
, git
);