1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2000 Naba Kumar, Johannes Schmid
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, Boston, MA 02110-1301 USA
21 #include <libgnomevfs/gnome-vfs-utils.h>
22 #include <libgnomevfs/gnome-vfs.h>
24 #include <libanjuta/anjuta-shell.h>
25 #include <libanjuta/anjuta-preferences.h>
26 #include <libanjuta/anjuta-debug.h>
27 #include <libanjuta/interfaces/ianjuta-file.h>
28 #include <libanjuta/interfaces/ianjuta-document-manager.h>
29 #include <libanjuta/interfaces/ianjuta-file-manager.h>
30 #include <libanjuta/interfaces/ianjuta-project-manager.h>
31 #include <libanjuta/interfaces/ianjuta-preferences.h>
32 #include <libanjuta/interfaces/ianjuta-vcs.h>
35 #include "cvs-actions.h"
36 #include "cvs-interface.h"
38 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-cvs.ui"
39 #define ICON_FILE "anjuta-cvs-plugin-48.png"
41 static gpointer parent_class
;
43 static GtkActionEntry actions_cvs
[] = {
45 "ActionMenuCVS", /* Action name */
46 NULL
, /* Stock icon, if any */
47 N_("_CVS"), /* Display label */
53 "ActionCVSAdd", /* Action name */
54 GTK_STOCK_ADD
, /* Stock icon, if any */
55 N_("_Add"), /* Display label */
57 N_("Add a new file/directory to the CVS tree"), /* Tooltip */
58 G_CALLBACK (on_menu_cvs_add
) /* action callback */
61 "ActionCVSRemove", /* Action name */
62 GTK_STOCK_REMOVE
, /* Stock icon, if any */
63 N_("_Remove"), /* Display label */
65 N_("Remove a file/directory from CVS tree"), /* Tooltip */
66 G_CALLBACK (on_menu_cvs_remove
) /* action callback */
69 "ActionCVSCommit", /* Action name */
70 GTK_STOCK_YES
, /* Stock icon, if any */
71 N_("_Commit"), /* Display label */
73 N_("Commit your changes to the CVS tree"), /* Tooltip */
74 G_CALLBACK (on_menu_cvs_commit
) /* action callback */
77 "ActionCVSUpdate", /* Action name */
78 GTK_STOCK_REFRESH
, /* Stock icon, if any */
79 N_("_Update"), /* Display label */
80 "<control>u", /* short-cut */
81 N_("Sync your local copy with the CVS tree"), /* Tooltip */
82 G_CALLBACK (on_menu_cvs_update
) /* action callback */
85 "ActionCVSDiff", /* Action name */
86 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
87 N_("_Diff"), /* Display label */
89 N_("Show differences between your local copy and the tree"),/*Tooltip*/
90 G_CALLBACK (on_menu_cvs_diff
) /* action callback */
93 "ActionCVSStatus", /* Action name */
94 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
95 N_("_Show Status"), /* Display label */
97 N_("Show the status of a file/directory"), /* Tooltip */
98 G_CALLBACK (on_menu_cvs_status
) /* action callback */
101 "ActionCVSLog", /* Action name */
102 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
103 N_("_Show Log"), /* Display label */
104 NULL
, /* short-cut */
105 N_("Show the log of a file/directory"), /* Tooltip */
106 G_CALLBACK (on_menu_cvs_log
) /* action callback */
109 "ActionCVSImport", /* Action name */
110 GTK_STOCK_ADD
, /* Stock icon, if any */
111 N_("_Import Tree"), /* Display label */
112 NULL
, /* short-cut */
113 N_("Import a new source tree to CVS"), /* Tooltip */
114 G_CALLBACK (on_menu_cvs_import
) /* action callback */
118 static GtkActionEntry popup_actions_cvs
[] = {
120 "ActionPopupCVS", /* Action name */
121 NULL
, /* Stock icon, if any */
122 N_("_CVS"), /* Display label */
123 NULL
, /* short-cut */
128 "ActionPopupCVSCommit", /* Action name */
129 GTK_STOCK_YES
, /* Stock icon, if any */
130 N_("_Commit"), /* Display label */
131 NULL
, /* short-cut */
132 N_("Commit your changes to the CVS tree"), /* Tooltip */
133 G_CALLBACK (on_fm_cvs_commit
) /* action callback */
136 "ActionPopupCVSUpdate", /* Action name */
137 GTK_STOCK_REFRESH
, /* Stock icon, if any */
138 N_("_Update"), /* Display label */
139 NULL
, /* short-cut */
140 N_("Sync your local copy with the CVS tree"), /* Tooltip */
141 G_CALLBACK (on_fm_cvs_update
) /* action callback */
144 "ActionPopupCVSDiff", /* Action name */
145 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
146 N_("_Diff"), /* Display label */
147 NULL
, /* short-cut */
148 N_("Show differences between your local copy and the tree"),/*Tooltip*/
149 G_CALLBACK (on_fm_cvs_diff
) /* action callback */
152 "ActionPopupCVSStatus", /* Action name */
153 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
154 N_("_Show Status"), /* Display label */
155 NULL
, /* short-cut */
156 N_("Show the status of a file/directory"), /* Tooltip */
157 G_CALLBACK (on_fm_cvs_status
) /* action callback */
160 "ActionPopupCVSLog", /* Action name */
161 GTK_STOCK_ZOOM_100
, /* Stock icon, if any */
162 N_("_Show Log"), /* Display label */
163 NULL
, /* short-cut */
164 N_("Show the log of a file/directory"), /* Tooltip */
165 G_CALLBACK (on_fm_cvs_log
) /* action callback */
170 value_added_fm_current_file (AnjutaPlugin
*plugin
, const char *name
,
171 const GValue
*value
, gpointer data
)
174 GtkAction
*cvs_menu_action
;
176 GnomeVFSURI
*cvs_uri
= NULL
;
177 gchar
*cvs_text_uri
= NULL
;
180 GnomeVFSDirectoryHandle
* handle
;
181 GnomeVFSFileInfo info
;
182 GnomeVFSResult result
;
184 GFile
* file
= G_FILE (g_value_get_object (value
));
185 uri
= g_file_get_uri (file
);
186 filename
= gnome_vfs_get_local_path_from_uri (uri
);
187 g_return_if_fail (filename
!= NULL
);
189 CVSPlugin
*cvs_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
190 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
192 if (cvs_plugin
->fm_current_filename
)
193 g_free (cvs_plugin
->fm_current_filename
);
194 cvs_plugin
->fm_current_filename
= filename
;
196 /* Show popup menu if CVS directory exists */
197 cvs_menu_action
= anjuta_ui_get_action (ui
, "ActionGroupPopupCVS", "ActionPopupCVS");
199 /* If a directory is selected we check if it contains a "CVS" directory,
200 if it is a file we check if it's directory contains a "CVS" directory */
201 result
= gnome_vfs_get_file_info(uri
, &info
,
202 GNOME_VFS_FILE_INFO_DEFAULT
);
203 if (result
== GNOME_VFS_OK
)
205 if (info
.type
== GNOME_VFS_FILE_TYPE_DIRECTORY
)
207 cvs_dir
= g_strconcat(uri
, "/CVS", NULL
);
212 cvs_uri
= gnome_vfs_uri_new (uri
);
213 cvs_text_uri
= gnome_vfs_uri_extract_dirname(cvs_uri
);
214 cvs_dir
= g_strconcat(cvs_text_uri
, "/CVS", NULL
);
215 g_free(cvs_text_uri
);
216 gnome_vfs_uri_unref(cvs_uri
);
220 return; /* Strange... */
221 if (gnome_vfs_directory_open(&handle
, cvs_dir
,
222 GNOME_VFS_FILE_INFO_DEFAULT
) == GNOME_VFS_OK
)
225 g_object_set (G_OBJECT (cvs_menu_action
), "sensitive", TRUE
, NULL
);
229 g_object_set (G_OBJECT (cvs_menu_action
), "sensitive", FALSE
, NULL
);
236 value_removed_fm_current_file (AnjutaPlugin
*plugin
,
237 const char *name
, gpointer data
)
242 CVSPlugin
*cvs_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
244 if (cvs_plugin
->fm_current_filename
)
245 g_free (cvs_plugin
->fm_current_filename
);
246 cvs_plugin
->fm_current_filename
= NULL
;
248 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
249 action
= anjuta_ui_get_action (ui
, "ActionGroupPopupCVS", "ActionPopupCVS");
250 g_object_set (G_OBJECT (action
), "sensitive", FALSE
, NULL
);
255 value_added_project_root_uri (AnjutaPlugin
*plugin
, const gchar
*name
,
256 const GValue
*value
, gpointer user_data
)
258 CVSPlugin
*bb_plugin
;
259 const gchar
*root_uri
;
261 bb_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
263 DEBUG_PRINT ("Project added");
265 if (bb_plugin
->project_root_dir
)
266 g_free (bb_plugin
->project_root_dir
);
267 bb_plugin
->project_root_dir
= NULL
;
269 root_uri
= g_value_get_string (value
);
272 bb_plugin
->project_root_dir
=
273 gnome_vfs_get_local_path_from_uri (root_uri
);
274 if (bb_plugin
->project_root_dir
)
276 // update_project_ui (bb_plugin);
282 value_removed_project_root_uri (AnjutaPlugin
*plugin
, const gchar
*name
,
285 CVSPlugin
*bb_plugin
;
287 bb_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
288 if (bb_plugin
->project_root_dir
)
289 g_free (bb_plugin
->project_root_dir
);
290 bb_plugin
->project_root_dir
= NULL
;
291 // update_project_ui (bb_plugin);
295 value_added_current_editor (AnjutaPlugin
*plugin
, const char *name
,
296 const GValue
*value
, gpointer data
)
302 editor
= g_value_get_object (value
);
304 if (!IANJUTA_IS_EDITOR(editor
))
307 CVSPlugin
*cvs_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
308 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
310 if (cvs_plugin
->current_editor_filename
)
311 g_free (cvs_plugin
->current_editor_filename
);
312 cvs_plugin
->current_editor_filename
= NULL
;
314 file
= ianjuta_file_get_file (IANJUTA_FILE (editor
), NULL
);
319 filename
= g_file_get_path (file
);
320 g_return_if_fail (filename
!= NULL
);
321 cvs_plugin
->current_editor_filename
= filename
;
322 g_object_unref (file
);
327 value_removed_current_editor (AnjutaPlugin
*plugin
,
328 const char *name
, gpointer data
)
330 CVSPlugin
*cvs_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
332 if (cvs_plugin
->current_editor_filename
)
333 g_free (cvs_plugin
->current_editor_filename
);
334 cvs_plugin
->current_editor_filename
= NULL
;
336 // update_module_ui (cvs_plugin);
340 activate_plugin (AnjutaPlugin
*plugin
)
343 CVSPlugin
*cvs_plugin
;
345 DEBUG_PRINT ("CVSPlugin: Activating CVS plugin ...");
346 cvs_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
348 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
350 /* Add all our actions */
351 cvs_plugin
->cvs_action_group
=
352 anjuta_ui_add_action_group_entries (ui
, "ActionGroupCVS",
355 G_N_ELEMENTS (actions_cvs
),
356 GETTEXT_PACKAGE
, TRUE
, plugin
);
357 cvs_plugin
->cvs_popup_action_group
=
358 anjuta_ui_add_action_group_entries (ui
, "ActionGroupPopupCVS",
359 _("CVS popup operations"),
361 G_N_ELEMENTS (popup_actions_cvs
),
362 GETTEXT_PACKAGE
, FALSE
, plugin
);
364 cvs_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
367 cvs_plugin
->fm_watch_id
=
368 anjuta_plugin_add_watch (plugin
, IANJUTA_FILE_MANAGER_SELECTED_FILE
,
369 value_added_fm_current_file
,
370 value_removed_fm_current_file
, NULL
);
371 cvs_plugin
->project_watch_id
=
372 anjuta_plugin_add_watch (plugin
, IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI
,
373 value_added_project_root_uri
,
374 value_removed_project_root_uri
, NULL
);
375 cvs_plugin
->editor_watch_id
=
376 anjuta_plugin_add_watch (plugin
, IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT
,
377 value_added_current_editor
,
378 value_removed_current_editor
, NULL
);
383 deactivate_plugin (AnjutaPlugin
*plugin
)
386 CVSPlugin
*cvs_plugin
;
388 DEBUG_PRINT ("CVSPlugin: Dectivating CVS plugin ...");
390 cvs_plugin
= ANJUTA_PLUGIN_CVS (plugin
);
391 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
394 anjuta_plugin_remove_watch (plugin
, cvs_plugin
->fm_watch_id
, TRUE
);
395 anjuta_plugin_remove_watch (plugin
, cvs_plugin
->project_watch_id
, TRUE
);
396 anjuta_plugin_remove_watch (plugin
, cvs_plugin
->editor_watch_id
, TRUE
);
399 anjuta_ui_unmerge (ui
, cvs_plugin
->uiid
);
401 /* Remove action groups */
402 anjuta_ui_remove_action_group (ui
, cvs_plugin
->cvs_action_group
);
403 anjuta_ui_remove_action_group (ui
, cvs_plugin
->cvs_popup_action_group
);
409 finalize (GObject
*obj
)
411 // CVSPlugin *plugin = ANJUTA_PLUGIN_CVS (obj);
412 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
416 dispose (GObject
*obj
)
418 // CVSPlugin *plugin = ANJUTA_PLUGIN_CVS (obj);
419 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
423 cvs_plugin_instance_init (GObject
*obj
)
425 CVSPlugin
*plugin
= ANJUTA_PLUGIN_CVS (obj
);
427 plugin
->executing_command
= FALSE
;
428 plugin
->mesg_view
= NULL
;
429 plugin
->launcher
= NULL
;
430 plugin
->diff_editor
= NULL
;
431 plugin
->fm_current_filename
= NULL
;
432 plugin
->project_root_dir
= NULL
;
433 plugin
->current_editor_filename
= NULL
;
437 cvs_plugin_class_init (GObjectClass
*klass
)
439 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
441 parent_class
= g_type_class_peek_parent (klass
);
443 plugin_class
->activate
= activate_plugin
;
444 plugin_class
->deactivate
= deactivate_plugin
;
445 klass
->dispose
= dispose
;
446 klass
->finalize
= finalize
;
452 ianjuta_cvs_add (IAnjutaVcs
*obj
, const gchar
* filename
,
455 anjuta_cvs_add(ANJUTA_PLUGIN(obj
), filename
, FALSE
, err
);
459 ianjuta_cvs_commit (IAnjutaVcs
*obj
, const gchar
* filename
, const gchar
* log
,
460 gboolean recurse
, GError
**err
)
462 anjuta_cvs_commit (ANJUTA_PLUGIN(obj
), filename
, log
, "", recurse
, err
);
466 ianjuta_cvs_remove (IAnjutaVcs
*obj
, const gchar
* filename
, GError
**err
)
468 anjuta_cvs_remove (ANJUTA_PLUGIN(obj
), filename
, err
);
473 ianjuta_cvs_update (IAnjutaVcs
*obj
, const gchar
* filename
, gboolean recurse
, GError
**err
)
475 anjuta_cvs_update(ANJUTA_PLUGIN(obj
), filename
, recurse
, FALSE
, TRUE
, FALSE
,"", err
);}
478 ianjuta_vcs_iface_init (IAnjutaVcsIface
*iface
)
480 iface
->add
= ianjuta_cvs_add
;
481 iface
->remove
= ianjuta_cvs_remove
;
482 iface
->update
= ianjuta_cvs_update
;
483 iface
->commit
= ianjuta_cvs_commit
;
487 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
489 /* Create the messages preferences page */
491 gxml
= glade_xml_new (GLADE_FILE
, "cvs", NULL
);
492 anjuta_preferences_add_page (prefs
, gxml
, "cvs", _("CVS"), ICON_FILE
);
493 g_object_unref (gxml
);
497 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
499 anjuta_preferences_remove_page(prefs
, _("CVS"));
503 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
505 iface
->merge
= ipreferences_merge
;
506 iface
->unmerge
= ipreferences_unmerge
;
509 ANJUTA_PLUGIN_BEGIN (CVSPlugin
, cvs_plugin
);
510 ANJUTA_PLUGIN_ADD_INTERFACE(ianjuta_vcs
, IANJUTA_TYPE_VCS
);
511 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
514 ANJUTA_SIMPLE_PLUGIN (CVSPlugin
, cvs_plugin
);