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"
29 #include "git-switch-dialog.h"
31 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui"
33 static gpointer parent_class
;
35 static GtkActionEntry actions_git
[] = {
37 "ActionMenuGit", /* Action name */
38 NULL
, /* Stock icon, if any */
39 N_("_Git"), /* Display label */
42 NULL
/* action callback */
45 "ActionGitCommit", /* Action name */
46 GTK_STOCK_YES
, /* Stock icon, if any */
47 N_("_Commit..."), /* Display label */
50 G_CALLBACK (on_menu_git_commit
) /* action callback */
53 "ActionGitResolve", /* Action name */
54 GTK_STOCK_PREFERENCES
, /* Stock icon, if any */
55 N_("_Resolve Conflicts..."), /* Display label */
58 G_CALLBACK (on_menu_git_resolve
) /* action callback */
61 "ActionGitAdd", /* Action name */
62 GTK_STOCK_ADD
, /* Stock icon, if any */
63 N_("_Add..."), /* Display label */
66 G_CALLBACK (on_menu_git_add
) /* action callback */
69 "ActionGitRemove", /* Action name */
70 GTK_STOCK_REMOVE
, /* Stock icon, if any */
71 N_("_Remove..."), /* Display label */
74 G_CALLBACK (on_menu_git_remove
) /* action callback */
77 "ActionGitSwitch", /* Action name */
78 GTK_STOCK_JUMP_TO
, /* Stock icon, if any */
79 N_("_Switch to another branch..."), /* Display label */
82 G_CALLBACK (on_menu_git_switch
) /* action callback */
85 "ActionGitMerge", /* Action name */
86 GTK_STOCK_CONVERT
, /* Stock icon, if any */
87 N_("_Merge..."), /* Display label */
90 G_CALLBACK (on_menu_git_merge
) /* action callback */
93 "ActionGitDiffUncommitted", /* Action name */
94 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
95 N_("_Diff uncommitted changes"), /* Display label */
98 G_CALLBACK (on_menu_git_diff
) /* action callback */
103 on_project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
104 const GValue
*value
, gpointer user_data
)
107 gchar
*project_root_uri
;
108 GtkAction
*git_menu_action
;
110 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
112 g_free (git_plugin
->project_root_directory
);
113 project_root_uri
= g_value_dup_string (value
);
114 git_plugin
->project_root_directory
= gnome_vfs_get_local_path_from_uri (project_root_uri
);
116 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
121 gtk_action_set_sensitive (git_menu_action
, TRUE
);
123 g_free (project_root_uri
);
127 on_project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
130 GtkAction
*git_menu_action
;
133 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
135 g_free (git_plugin
->project_root_directory
);
136 git_plugin
->project_root_directory
= NULL
;
138 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
143 gtk_action_set_sensitive (git_menu_action
, FALSE
);
147 on_editor_added (AnjutaPlugin
*plugin
, const gchar
*name
, const GValue
*value
,
151 gchar
*current_editor_uri
;
152 IAnjutaEditor
*editor
;
154 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
155 editor
= g_value_get_object (value
);
157 if (IANJUTA_IS_EDITOR (editor
))
159 g_free (git_plugin
->current_editor_filename
);
160 current_editor_uri
= ianjuta_file_get_uri (IANJUTA_FILE (editor
), NULL
);
161 git_plugin
->current_editor_filename
= gnome_vfs_get_local_path_from_uri (current_editor_uri
);
166 on_editor_removed (AnjutaPlugin
*plugin
, const gchar
*name
, gpointer user_data
)
170 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
172 g_free (git_plugin
->current_editor_filename
);
173 git_plugin
->current_editor_filename
= NULL
;
177 git_activate_plugin (AnjutaPlugin
*plugin
)
181 GtkAction
*git_menu_action
183 DEBUG_PRINT ("Git: Activating Git plugin ...");
185 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
186 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
188 /* Add all our actions */
189 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGit",
192 G_N_ELEMENTS (actions_git
),
193 GETTEXT_PACKAGE
, TRUE
, plugin
);
194 git_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
197 git_plugin
->project_root_watch_id
= anjuta_plugin_add_watch (plugin
,
199 on_project_root_added
,
200 on_project_root_removed
,
203 git_plugin
->editor_watch_id
= anjuta_plugin_add_watch (plugin
,
204 "document_manager_current_editor",
209 /* Git needs a working directory to work with; it can't take full paths,
210 * so make sure that Git can't be used if there's no project opened. */
211 git_menu_action
= anjuta_ui_get_action (anjuta_shell_get_ui (plugin
->shell
,
216 gtk_action_set_sensitive (git_menu_action
, FALSE
);
222 git_deactivate_plugin (AnjutaPlugin
*plugin
)
224 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
227 git_plugin
= ANJUTA_PLUGIN_GIT (plugin
);
229 DEBUG_PRINT ("Git: Dectivating Git plugin ...");
230 anjuta_ui_unmerge (ui
, git_plugin
->uiid
);
231 anjuta_plugin_remove_watch (plugin
, git_plugin
->project_root_watch_id
,
233 anjuta_plugin_remove_watch (plugin
, git_plugin
->editor_watch_id
,
240 git_finalize (GObject
*obj
)
242 /* Finalization codes here */
243 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
247 git_dispose (GObject
*obj
)
249 /* Disposition codes */
250 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
254 git_instance_init (GObject
*obj
)
256 Git
*plugin
= ANJUTA_PLUGIN_GIT (obj
);
261 git_class_init (GObjectClass
*klass
)
263 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
265 parent_class
= g_type_class_peek_parent (klass
);
267 plugin_class
->activate
= git_activate_plugin
;
268 plugin_class
->deactivate
= git_deactivate_plugin
;
269 klass
->finalize
= git_finalize
;
270 klass
->dispose
= git_dispose
;
273 ANJUTA_PLUGIN_BOILERPLATE (Git
, git
);
274 ANJUTA_SIMPLE_PLUGIN (Git
, git
);