Updated Spanish translation
[anjuta-git-plugin.git] / plugins / glade / plugin.c
blob23f1819b93418ce421b9ec1356c11bdc02cc1b7e
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 plugin.c
4 Copyright (C) 2000 Naba Kumar
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <config.h>
23 #if (GLADEUI_VERSION <= 302)
24 # include <glade.h>
25 #else
26 # if (GLADEUI_VERSION <= 314)
27 # include <glade.h>
28 # include <glade-design-view.h>
29 # else /* Since 3.1.5 */
30 # include <gladeui/glade.h>
31 # include <gladeui/glade-design-view.h>
32 # endif
33 #endif
35 #include <libgnomevfs/gnome-vfs-utils.h>
36 #include <libanjuta/anjuta-shell.h>
37 #include <libanjuta/anjuta-debug.h>
38 #include <libanjuta/interfaces/ianjuta-file.h>
39 #include <libanjuta/interfaces/ianjuta-wizard.h>
40 #include <libanjuta/interfaces/ianjuta-help.h>
42 #include "plugin.h"
44 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-glade.ui"
46 static gpointer parent_class;
48 /* This is variable required from libdevhelp */
49 gchar *geometry = NULL;
51 struct _GladePluginPriv
53 gint uiid;
54 GtkActionGroup *action_group;
55 GladeApp *gpw;
56 GtkWidget *inspector;
57 #if (GLADEUI_VERSION > 302)
58 GtkWidget *design_notebook;
59 #endif
60 GtkWidget *view_box;
61 GtkWidget *projects_combo;
64 enum {
65 NAME_COL,
66 PROJECT_COL,
67 N_COLUMNS
70 static void
71 glade_update_ui (GladeApp *app, GladePlugin *plugin)
73 #if (GLADEUI_VERSION >= 330)
74 GladeCommand *undo_item;
75 GladeCommand *redo_item;
76 #else
77 GList *prev_redo_item;
78 GList *undo_item;
79 GList *redo_item;
80 #endif
81 const gchar *undo_description = NULL;
82 const gchar *redo_description = NULL;
83 GladeProject *project;
84 GtkAction *action;
85 gchar buffer[512];
86 AnjutaUI *ui;
87 GtkTreeModel *model;
88 GtkTreeIter iter;;
90 project = glade_app_get_project ();
91 if (!project)
93 undo_item = NULL;
94 redo_item = NULL;
96 else
98 #if (GLADEUI_VERSION >= 330)
99 undo_item = glade_project_next_undo_item(project);
100 redo_item = glade_project_next_redo_item(project);
101 if (undo_item)
102 undo_description = undo_item->description;
103 if (redo_item)
104 redo_description = redo_item->description;
105 #else
106 undo_item = prev_redo_item = project->prev_redo_item;
107 redo_item = (prev_redo_item == NULL) ? project->undo_stack : prev_redo_item->next;
108 if (undo_item && undo_item->data)
109 undo_description = GLADE_COMMAND (undo_item->data)->description;
110 if (redo_item && redo_item->data)
111 redo_description = GLADE_COMMAND (redo_item->data)->description;
112 #endif
114 ui = anjuta_shell_get_ui (ANJUTA_PLUGIN (plugin)->shell, NULL);
115 action = anjuta_ui_get_action (ui, "ActionGroupGlade", "ActionGladeUndo");
116 if (undo_description)
118 snprintf (buffer, 512, _("_Undo: %s"), undo_description);
119 g_object_set (G_OBJECT (action), "sensitive", TRUE, "label", buffer, NULL);
121 else
123 g_object_set (G_OBJECT (action), "sensitive", FALSE, "label", _("_Undo"), NULL);
125 action = anjuta_ui_get_action (ui, "ActionGroupGlade", "ActionGladeRedo");
126 if (redo_description)
128 snprintf (buffer, 512, _("_Redo: %s"), redo_description);
129 g_object_set (G_OBJECT (action), "sensitive", TRUE, "label", buffer, NULL);
131 else
133 g_object_set (G_OBJECT (action), "sensitive", FALSE, "label", _("_Redo"), NULL);
136 /* Update current project */
137 model = gtk_combo_box_get_model (GTK_COMBO_BOX (plugin->priv->projects_combo));
138 if (gtk_tree_model_get_iter_first (model, &iter))
142 GladeProject *project;
143 gtk_tree_model_get (model, &iter, PROJECT_COL, &project, -1);
144 if (project == glade_app_get_project ())
146 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (plugin->priv->projects_combo), &iter);
147 break;
150 while (gtk_tree_model_iter_next (model, &iter));
154 /* Action callbacks */
155 static void
156 on_copy_activated (GtkAction *action, GladePlugin *plugin)
158 glade_app_command_copy ();
161 static void
162 on_cut_activated (GtkAction *action, GladePlugin *plugin)
164 glade_app_command_cut ();
167 static void
168 on_paste_activated (GtkAction *action, GladePlugin *plugin)
170 glade_app_command_paste (NULL);
173 static void
174 on_delete_activated (GtkAction *action, GladePlugin *plugin)
176 glade_app_command_delete ();
179 static void
180 on_undo_activated (GtkAction *action, GladePlugin *plugin)
182 glade_app_command_undo ();
185 static void
186 on_redo_activated (GtkAction *action, GladePlugin *plugin)
188 glade_app_command_redo ();
191 static void
192 on_show_clipbard_activated (GtkAction *action, GladePlugin *plugin)
194 GtkWidget *clipboard_view;
196 clipboard_view = glade_app_get_clipboard_view ();
197 gtk_widget_show_all (clipboard_view);
198 gtk_window_present (GTK_WINDOW (clipboard_view));
201 static void
202 glade_save (GladePlugin *plugin, GladeProject *project, const gchar *path)
204 AnjutaStatus *status;
206 status = anjuta_shell_get_status (ANJUTA_PLUGIN(plugin)->shell, NULL);
207 if (!glade_project_save (project, path, NULL))
209 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell),
210 _("Invalid glade file name"));
211 return;
213 // FIXME: gpw_refresh_project_entry (gpw, project);
214 #if (GLADEUI_VERSION >= 330)
215 anjuta_status_set (status, _("Glade project '%s' saved"),
216 glade_project_get_name(project));
217 #else
218 anjuta_status_set (status, _("Glade project '%s' saved"), project->name);
219 #endif
222 static void
223 on_save_activated (GtkAction *action, GladePlugin *plugin)
225 GladeProject *project;
226 GtkWidget *filechooser;
227 gchar *path = NULL;
229 project = glade_app_get_project ();
231 #if (GLADEUI_VERSION >= 330)
232 if (glade_project_get_path(project) != NULL) {
233 #else
234 if (project->path != NULL) {
235 #endif
236 AnjutaStatus *status;
238 status = anjuta_shell_get_status (ANJUTA_PLUGIN(plugin)->shell, NULL);
240 #if (GLADEUI_VERSION >= 330)
241 if (glade_project_save (project, glade_project_get_path(project),
242 NULL)) {
243 anjuta_status_set (status, _("Glade project '%s' saved"),
244 glade_project_get_name(project));
245 #else
246 if (glade_project_save (project, project->path, NULL)) {
247 anjuta_status_set (status, _("Glade project '%s' saved"),
248 project->name);
249 #endif
250 } else {
251 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell),
252 _("Invalid glade file name"));
254 return;
257 /* If instead we dont have a path yet, fire up a file selector */
258 filechooser = glade_util_file_dialog_new (_("Save glade file..."),
259 GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
260 GLADE_FILE_DIALOG_ACTION_SAVE);
262 if (gtk_dialog_run (GTK_DIALOG(filechooser)) == GTK_RESPONSE_OK)
263 path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
265 gtk_widget_destroy (filechooser);
267 if (!path)
268 return;
270 glade_save (plugin, project, path);
271 g_free (path);
274 static void
275 on_save_as_activated (GtkAction *action, GladePlugin *plugin)
277 GladeProject *project;
278 GtkWidget *filechooser;
279 gchar *path = NULL;
281 project = glade_app_get_project ();
283 filechooser = glade_util_file_dialog_new (_("Save glade file as..."),
284 GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
285 GLADE_FILE_DIALOG_ACTION_SAVE);
287 if (gtk_dialog_run (GTK_DIALOG(filechooser)) == GTK_RESPONSE_OK)
288 path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
290 gtk_widget_destroy (filechooser);
292 if (!path)
293 return;
295 glade_save (plugin, project, path);
296 g_free (path);
299 static gboolean
300 glade_confirm_close_project (GladePlugin *plugin, GladeProject *project)
302 GladeApp *gpw;
303 GtkWidget *dialog;
304 gboolean close = FALSE;
305 gchar *msg, *string;
306 gint ret;
308 g_return_val_if_fail (GLADE_IS_PROJECT (project), FALSE);
310 gpw = plugin->priv->gpw;
311 string = g_strdup_printf(
312 "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
313 _("Save changes to glade project \"%s\" before closing?"),
314 _("Your changes will be lost if you don't save them."));
315 #if (GLADEUI_VERSION >= 330)
316 msg = g_strdup_printf (string, glade_project_get_name(project));
317 #else
318 msg = g_strdup_printf (string, project->name);
319 #endif
320 g_free(string);
321 dialog = gtk_message_dialog_new (GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
322 GTK_DIALOG_MODAL,
323 GTK_MESSAGE_QUESTION,
324 GTK_BUTTONS_NONE,
325 msg);
326 g_free(msg);
328 gtk_label_set_use_markup (GTK_LABEL (GTK_MESSAGE_DIALOG (dialog)->label), TRUE);
330 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
331 _("_Close without Saving"), GTK_RESPONSE_NO,
332 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
333 GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL);
335 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
337 ret = gtk_dialog_run (GTK_DIALOG (dialog));
338 switch (ret) {
339 case GTK_RESPONSE_YES:
340 /* if YES we save the project: note we cannot use gpw_save_cb
341 * since it saves the current project, while the modified
342 * project we are saving may be not the current one.
344 #if (GLADEUI_VERSION >= 330)
345 if (glade_project_get_path(project) != NULL)
347 close = glade_project_save (project,
348 glade_project_get_path(project),
349 NULL);
351 #else
352 if (project->path != NULL)
354 close = glade_project_save (project, project->path, NULL);
356 #endif
357 else
359 GtkWidget *filechooser;
360 gchar *path = NULL;
362 filechooser = glade_util_file_dialog_new (_("Save glade project..."),
363 GTK_WINDOW (ANJUTA_PLUGIN (plugin)->shell),
364 GLADE_FILE_DIALOG_ACTION_SAVE);
366 if (gtk_dialog_run (GTK_DIALOG(filechooser)) == GTK_RESPONSE_OK)
367 path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser));
369 gtk_widget_destroy (filechooser);
371 if (!path)
372 break;
374 glade_save (plugin, project, path);
375 g_free (path);
376 close = FALSE;
378 break;
379 case GTK_RESPONSE_NO:
380 close = TRUE;
381 break;
382 case GTK_RESPONSE_CANCEL:
383 case GTK_RESPONSE_DELETE_EVENT:
384 close = FALSE;
385 break;
386 default:
387 g_assert_not_reached ();
388 close = FALSE;
391 gtk_widget_destroy (dialog);
392 return close;
395 static void
396 on_api_help (GladeEditor* editor,
397 const gchar* book,
398 const gchar* page,
399 const gchar* search,
400 GladePlugin* plugin)
402 gchar *book_comm = NULL, *page_comm = NULL;
403 gchar *string;
405 AnjutaPlugin* aplugin = ANJUTA_PLUGIN(plugin);
406 AnjutaShell* shell = aplugin->shell;
407 IAnjutaHelp* help;
409 help = anjuta_shell_get_interface(shell, IAnjutaHelp, NULL);
411 /* No API Help Plugin */
412 if (help == NULL)
413 return;
415 if (book) book_comm = g_strdup_printf ("book:%s ", book);
416 if (page) page_comm = g_strdup_printf ("page:%s ", page);
418 string = g_strdup_printf ("%s%s%s",
419 book_comm ? book_comm : "",
420 page_comm ? page_comm : "",
421 search ? search : "");
423 ianjuta_help_search(help, string, NULL);
425 g_free (string);
428 static void
429 glade_do_close (GladePlugin *plugin, GladeProject *project)
431 #if (GLADEUI_VERSION > 302)
432 GtkWidget *design_view;
434 design_view = g_object_get_data (G_OBJECT (project), "design_view");
435 gtk_notebook_remove_page (GTK_NOTEBOOK (plugin->priv->design_notebook),
436 gtk_notebook_page_num (GTK_NOTEBOOK
437 (plugin->priv->design_notebook),
438 design_view));
439 gtk_widget_destroy (design_view);
440 #endif
441 glade_app_remove_project (project);
444 static void
445 on_close_activated (GtkAction *action, GladePlugin *plugin)
447 GladeProject *project;
448 gboolean close;
449 GtkTreeModel *model;
450 GtkTreeIter iter;
452 project = glade_app_get_project ();
454 if (!project)
456 /* if (gtk_tree_model_iter_n_children (model, NULL) <= 0) */
457 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin));
458 return;
461 #if (GLADEUI_VERSION >= 330)
462 if (glade_project_get_has_unsaved_changes (project))
463 #else
464 if (project->changed)
465 #endif
467 close = glade_confirm_close_project (plugin, project);
468 if (!close)
469 return;
472 /* Remove project from our list */
473 model = gtk_combo_box_get_model (GTK_COMBO_BOX (plugin->priv->projects_combo));
474 if (gtk_tree_model_get_iter_first (model, &iter))
478 GladeProject *project_node;
480 gtk_tree_model_get (model, &iter, PROJECT_COL, &project_node, -1);
481 if (project == project_node)
483 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
484 break;
487 while (gtk_tree_model_iter_next (model, &iter));
489 glade_do_close (plugin, project);
490 if (gtk_tree_model_iter_n_children (model, NULL) <= 0)
491 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin));
494 static void
495 on_glade_project_changed (GtkComboBox *combo, GladePlugin *plugin)
497 GtkTreeModel *model;
498 GtkTreeIter iter;
500 model = gtk_combo_box_get_model (GTK_COMBO_BOX (plugin->priv->projects_combo));
501 if (gtk_combo_box_get_active_iter (combo, &iter))
503 GladeProject *project;
505 #if (GLADEUI_VERSION > 302)
506 GtkWidget *design_view;
507 gint design_pagenum;
508 #endif
509 gtk_tree_model_get (model, &iter, PROJECT_COL, &project, -1);
510 glade_app_set_project (project);
512 #if (GLADEUI_VERSION > 302)
513 design_view = g_object_get_data (G_OBJECT (project), "design_view");
514 design_pagenum = gtk_notebook_page_num (GTK_NOTEBOOK (plugin->priv->design_notebook),
515 design_view);
516 gtk_notebook_set_current_page (GTK_NOTEBOOK (plugin->priv->design_notebook),
517 design_pagenum);
518 # if (GLADEUI_VERSION >= 330)
519 glade_inspector_set_project (GLADE_INSPECTOR (plugin->priv->inspector), project);
520 # endif
522 #endif
526 /* Action definitions */
527 static GtkActionEntry actions[] = {
528 /* Go menu */
530 "ActionMenuGlade",
531 NULL,
532 N_("_Glade"),
533 NULL,
534 NULL,
535 NULL
538 "ActionGladeUndo",
539 GTK_STOCK_UNDO,
540 N_("_Undo"),
541 NULL,
542 N_("Undo last action"),
543 G_CALLBACK (on_undo_activated)
546 "ActionGladeRedo",
547 GTK_STOCK_REDO,
548 N_("_Redo"),
549 NULL,
550 N_("Redo last undone action"),
551 G_CALLBACK (on_redo_activated)
554 "ActionGladeCut",
555 GTK_STOCK_CUT,
556 N_("Cu_t"),
557 NULL,
558 N_("Cut selection"),
559 G_CALLBACK (on_cut_activated)
562 "ActionGladeCopy",
563 GTK_STOCK_COPY,
564 N_("_Copy"),
566 N_("Copy selection"),
567 G_CALLBACK (on_copy_activated)
570 "ActionGladePaste",
571 GTK_STOCK_PASTE,
572 N_("_Paste"),
574 N_("Paste selection"),
575 G_CALLBACK (on_paste_activated)
578 "ActionGladeDelete",
579 GTK_STOCK_DELETE,
580 N_("_Delete"),
582 N_("Delete selection"),
583 G_CALLBACK (on_delete_activated)
586 "ActionGladeShowClipboard",
587 NULL,
588 N_("_Show Clipboard"),
589 NULL,
590 N_("Show clipboard"),
591 G_CALLBACK (on_show_clipbard_activated)
594 "ActionGladeSave",
595 GTK_STOCK_SAVE,
596 N_("_Save"),
598 N_("Save glade project"),
599 G_CALLBACK (on_save_activated)
602 "ActionGladeSaveAs",
603 GTK_STOCK_SAVE_AS,
604 N_("Save _As..."),
606 N_("Save as glade project"),
607 G_CALLBACK (on_save_as_activated)
610 "ActionGladeClose",
611 GTK_STOCK_CLOSE,
612 N_("Clos_e"),
614 N_("Close current glade project"),
615 G_CALLBACK (on_close_activated)
619 #define REGISTER_ICON(icon, stock_id) \
620 pixbuf = gdk_pixbuf_new_from_file (icon, NULL); \
621 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf); \
622 gtk_icon_factory_add (icon_factory, stock_id, icon_set); \
623 g_object_unref (pixbuf);
625 static void
626 register_stock_icons (AnjutaPlugin *plugin)
628 AnjutaUI *ui;
629 GtkIconFactory *icon_factory;
630 GtkIconSet *icon_set;
631 GdkPixbuf *pixbuf;
632 static gboolean registered = FALSE;
634 if (registered)
635 return;
636 registered = TRUE;
638 /* Register stock icons */
639 ui = anjuta_shell_get_ui (plugin->shell, NULL);
640 icon_factory = anjuta_ui_get_icon_factory (ui);
641 REGISTER_ICON (PACKAGE_PIXMAPS_DIR"/anjuta-glade-plugin.png",
642 "glade-plugin-icon");
645 static void
646 on_session_save (AnjutaShell *shell, AnjutaSessionPhase phase,
647 AnjutaSession *session, GladePlugin *plugin)
649 GList *files;
650 GtkTreeModel *model;
651 GtkTreeIter iter;
653 if (phase != ANJUTA_SESSION_PHASE_NORMAL)
654 return;
656 files = anjuta_session_get_string_list (session, "File Loader", "Files");
657 files = g_list_reverse (files);
659 model = gtk_combo_box_get_model (GTK_COMBO_BOX (plugin->priv->projects_combo));
660 if (gtk_tree_model_get_iter_first (model, &iter))
664 gchar *uri;
665 GladeProject *project;
666 gtk_tree_model_get (model, &iter, PROJECT_COL, &project, -1);
667 #if (GLADEUI_VERSION >= 330)
668 if (glade_project_get_path(project))
669 #else
670 if (project->path)
671 #endif
673 #if (GLADEUI_VERSION >= 330)
674 uri = gnome_vfs_get_uri_from_local_path
675 (glade_project_get_path(project));
676 #else
677 uri = gnome_vfs_get_uri_from_local_path (project->path);
678 #endif
679 if (uri)
680 files = g_list_prepend (files, uri);
681 /* URI is not freed here */
684 while (gtk_tree_model_iter_next (model, &iter));
686 files = g_list_reverse (files);
687 anjuta_session_set_string_list (session, "File Loader", "Files", files);
688 g_list_foreach (files, (GFunc)g_free, NULL);
689 g_list_free (files);
692 /* FIXME: Glade does not allow destroying its (singleton) widgets.
693 * Make sure they are removed when the application is destroyed
694 * without the plugin unloaded.
696 static void
697 on_shell_destroy (AnjutaShell *shell, GladePlugin *glade_plugin)
699 GtkWidget *wid;
700 GtkWidget *parent;
702 /* Remove widgets before the container destroyes them */
703 wid = GTK_WIDGET (glade_app_get_palette ());
704 parent = gtk_widget_get_parent (wid);
705 gtk_container_remove (GTK_CONTAINER (parent), wid);
707 wid = GTK_WIDGET (glade_app_get_editor ());
708 parent = gtk_widget_get_parent (wid);
709 gtk_container_remove (GTK_CONTAINER (parent), wid);
711 wid = GTK_WIDGET (glade_plugin->priv->view_box);
712 parent = gtk_widget_get_parent (wid);
713 gtk_container_remove (GTK_CONTAINER (parent), wid);
716 #if (GLADEUI_VERSION > 302)
717 static void
718 glade_plugin_add_project (GladePlugin *glade_plugin, GladeProject *project)
720 GtkWidget *view;
721 GladePluginPriv *priv;
723 g_return_if_fail (GLADE_IS_PROJECT (project));
725 priv = glade_plugin->priv;
726 view = glade_design_view_new (project);
727 gtk_widget_show (view);
728 g_object_set_data (G_OBJECT (project), "design_view", view);
729 glade_app_add_project (project);
731 gtk_notebook_append_page (GTK_NOTEBOOK (priv->design_notebook), GTK_WIDGET (view), NULL);
732 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->design_notebook), -1);
734 #else
735 static void
736 glade_plugin_add_project (GladePlugin *glade_plugin, GladeProject *project)
738 glade_app_add_project (project);
740 #endif
742 #if (GLADEUI_VERSION >= 330)
743 static void
744 inspector_item_activated_cb (GladeInspector *inspector,
745 AnjutaPlugin *plugin)
747 GList *item = glade_inspector_get_selected_items (inspector);
748 g_assert (GLADE_IS_WIDGET (item->data) && (item->next == NULL));
750 /* switch to this widget in the workspace */
751 glade_widget_show (GLADE_WIDGET (item->data));
753 g_list_free (item);
755 #endif
757 static gboolean
758 activate_plugin (AnjutaPlugin *plugin)
760 AnjutaUI *ui;
761 GladePlugin *glade_plugin;
762 GladePluginPriv *priv;
763 // GtkAction *action;
764 GtkListStore *store;
765 GtkCellRenderer *renderer;
767 DEBUG_PRINT ("GladePlugin: Activating Glade plugin...");
769 glade_plugin = ANJUTA_PLUGIN_GLADE (plugin);
771 ui = anjuta_shell_get_ui (plugin->shell, NULL);
772 priv = glade_plugin->priv;
774 register_stock_icons (plugin);
776 if (!priv->gpw)
778 priv->gpw = g_object_new(GLADE_TYPE_APP, NULL);
780 glade_app_set_window (GTK_WIDGET (ANJUTA_PLUGIN(plugin)->shell));
781 glade_app_set_transient_parent (GTK_WINDOW (ANJUTA_PLUGIN(plugin)->shell));
783 /* Create a view for us */
784 priv->view_box = gtk_vbox_new (FALSE, 0);
785 store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING,
786 G_TYPE_POINTER, NULL);
788 priv->projects_combo = gtk_combo_box_new ();
789 renderer = gtk_cell_renderer_text_new ();
790 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->projects_combo),
791 renderer, TRUE);
792 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->projects_combo),
793 renderer, "text", NAME_COL, NULL);
794 gtk_combo_box_set_model (GTK_COMBO_BOX (priv->projects_combo),
795 GTK_TREE_MODEL (store));
796 g_object_unref (G_OBJECT (store));
797 gtk_box_pack_start (GTK_BOX (priv->view_box), priv->projects_combo,
798 FALSE, FALSE, 0);
799 #if (GLADEUI_VERSION > 302)
800 # if (GLADEUI_VERSION >= 330)
801 priv->inspector = glade_inspector_new ();
803 g_signal_connect (priv->inspector, "item-activated",
804 G_CALLBACK (inspector_item_activated_cb),
805 plugin);
806 # else
807 priv->inspector = glade_project_view_new ();
808 # endif
809 #else
810 priv->inspector = glade_project_view_new (GLADE_PROJECT_VIEW_TREE);
811 #endif
813 #if (GLADEUI_VERSION < 330)
814 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->inspector),
815 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
817 glade_app_add_project_view (GLADE_PROJECT_VIEW (priv->inspector));
818 #endif
819 gtk_box_pack_start (GTK_BOX (priv->view_box), GTK_WIDGET (priv->inspector),
820 TRUE, TRUE, 0);
822 gtk_widget_show_all (priv->view_box);
823 gtk_notebook_set_scrollable (GTK_NOTEBOOK (glade_app_get_editor ()->notebook),
824 TRUE);
825 gtk_notebook_popup_enable (GTK_NOTEBOOK (glade_app_get_editor ()->notebook));
828 #if (GLADEUI_VERSION > 302)
829 /* Create design_notebook */
830 priv->design_notebook = gtk_notebook_new ();
831 gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->design_notebook), FALSE);
832 gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->design_notebook), FALSE);
833 gtk_widget_show (priv->design_notebook);
834 #endif
837 g_signal_connect (G_OBJECT (priv->projects_combo), "changed",
838 G_CALLBACK (on_glade_project_changed), plugin);
839 g_signal_connect (G_OBJECT (priv->gpw), "update-ui",
840 G_CALLBACK (glade_update_ui), plugin);
842 g_signal_connect(G_OBJECT(glade_app_get_editor()), "gtk-doc-search",
843 G_CALLBACK(on_api_help), plugin);
845 g_signal_connect(G_OBJECT(plugin->shell), "destroy",
846 G_CALLBACK(on_shell_destroy), plugin);
848 /* Add action group */
849 priv->action_group =
850 anjuta_ui_add_action_group_entries (ui, "ActionGroupGlade",
851 _("Glade operations"),
852 actions,
853 G_N_ELEMENTS (actions),
854 GETTEXT_PACKAGE, TRUE,
855 glade_plugin);
856 /* Add UI */
857 priv->uiid = anjuta_ui_merge (ui, UI_FILE);
859 /* FIXME: Glade doesn't want to die these widget, so
860 * hold a permenent refs on them
862 g_object_ref (glade_app_get_palette ());
863 g_object_ref (glade_app_get_editor ());
864 g_object_ref (priv->view_box);
865 #if (GLADEUI_VERSION > 302)
866 g_object_ref (priv->design_notebook);
867 #endif
868 gtk_widget_show (GTK_WIDGET (glade_app_get_palette ()));
869 gtk_widget_show (GTK_WIDGET (glade_app_get_editor ()));
871 /* Add widgets */
872 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin)->shell,
873 GTK_WIDGET (priv->view_box),
874 "AnjutaGladeTree", _("Widgets"),
875 "glade-plugin-icon",
876 ANJUTA_SHELL_PLACEMENT_LEFT, NULL);
877 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin)->shell,
878 GTK_WIDGET (glade_app_get_palette ()),
879 "AnjutaGladePalette", _("Palette"),
880 "glade-plugin-icon",
881 ANJUTA_SHELL_PLACEMENT_LEFT, NULL);
882 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin)->shell,
883 GTK_WIDGET (glade_app_get_editor ()),
884 "AnjutaGladeEditor", _("Properties"),
885 "glade-plugin-icon",
886 ANJUTA_SHELL_PLACEMENT_CENTER, NULL);
887 #if (GLADEUI_VERSION > 302)
888 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin)->shell,
889 GTK_WIDGET (priv->design_notebook),
890 "AnjutaGladeDesigner", _("Designer"),
891 "glade-plugin-icon",
892 ANJUTA_SHELL_PLACEMENT_CENTER, NULL);
893 #endif
894 /* Connect to save session */
895 g_signal_connect (G_OBJECT (plugin->shell), "save_session",
896 G_CALLBACK (on_session_save), plugin);
897 return TRUE;
900 static gboolean
901 deactivate_plugin (AnjutaPlugin *plugin)
903 GladePluginPriv *priv;
905 priv = ANJUTA_PLUGIN_GLADE (plugin)->priv;
907 AnjutaUI *ui = anjuta_shell_get_ui (plugin->shell, NULL);
909 DEBUG_PRINT ("GladePlugin: Dectivating Glade plugin...");
911 /* Disconnect signals */
912 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin->shell),
913 G_CALLBACK (on_session_save), plugin);
915 g_signal_handlers_disconnect_by_func (G_OBJECT (priv->projects_combo),
916 G_CALLBACK (on_glade_project_changed),
917 plugin);
918 g_signal_handlers_disconnect_by_func (G_OBJECT (priv->gpw),
919 G_CALLBACK (glade_update_ui),
920 plugin);
922 g_signal_handlers_disconnect_by_func (G_OBJECT(glade_app_get_editor()),
923 G_CALLBACK(on_api_help), plugin);
925 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin->shell),
926 G_CALLBACK (on_shell_destroy),
927 plugin);
928 /* Remove widgets */
929 anjuta_shell_remove_widget (plugin->shell,
930 GTK_WIDGET (glade_app_get_palette ()),
931 NULL);
932 anjuta_shell_remove_widget (plugin->shell,
933 GTK_WIDGET (glade_app_get_editor ()),
934 NULL);
935 anjuta_shell_remove_widget (plugin->shell,
936 GTK_WIDGET (priv->view_box),
937 NULL);
938 #if (GLADEUI_VERSION > 302)
939 anjuta_shell_remove_widget (plugin->shell,
940 GTK_WIDGET (priv->design_notebook),
941 NULL);
942 #endif
944 /* Remove UI */
945 anjuta_ui_unmerge (ui, priv->uiid);
947 /* Remove action group */
948 anjuta_ui_remove_action_group (ui, priv->action_group);
950 /* FIXME: Don't destroy glade, since it doesn't want to */
951 /* g_object_unref (G_OBJECT (priv->gpw)); */
952 /* priv->gpw = NULL */
954 priv->uiid = 0;
955 priv->action_group = NULL;
956 priv->gpw = NULL;
958 return TRUE;
961 static void
962 glade_plugin_dispose (GObject *obj)
964 /* GladePlugin *plugin = ANJUTA_PLUGIN_GLADE (obj); */
966 /* FIXME: Glade widgets should be destroyed */
967 GNOME_CALL_PARENT (G_OBJECT_CLASS, dispose, (obj));
970 static void
971 glade_plugin_finalize (GObject *obj)
973 GladePlugin *plugin = ANJUTA_PLUGIN_GLADE (obj);
974 g_free (plugin->priv);
975 GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (obj));
978 static void
979 glade_plugin_instance_init (GObject *obj)
981 GladePluginPriv *priv;
982 GladePlugin *plugin = ANJUTA_PLUGIN_GLADE (obj);
984 plugin->priv = (GladePluginPriv *) g_new0 (GladePluginPriv, 1);
985 priv = plugin->priv;
987 DEBUG_PRINT ("Intializing Glade plugin");
990 static void
991 glade_plugin_class_init (GObjectClass *klass)
993 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
995 parent_class = g_type_class_peek_parent (klass);
997 plugin_class->activate = activate_plugin;
998 plugin_class->deactivate = deactivate_plugin;
999 klass->dispose = glade_plugin_dispose;
1000 klass->dispose = glade_plugin_finalize;
1003 static void
1004 ifile_open (IAnjutaFile *ifile, const gchar *uri, GError **err)
1006 GladePluginPriv *priv;
1007 GladeProject *project;
1008 GtkListStore *store;
1009 GtkTreeIter iter;
1010 gchar *filename;
1012 g_return_if_fail (uri != NULL);
1014 priv = ANJUTA_PLUGIN_GLADE (ifile)->priv;
1016 filename = gnome_vfs_get_local_path_from_uri (uri);
1017 if (!filename)
1019 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile)->shell),
1020 _("Not local file: %s"), uri);
1021 return;
1023 #if (GLADEUI_VERSION >= 330)
1024 project = glade_project_load (filename);
1025 #else
1026 project = glade_project_open (filename);
1027 #endif
1028 g_free (filename);
1029 if (!project)
1031 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile)->shell),
1032 _("Could not open: %s"), uri);
1033 return;
1035 store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (priv->projects_combo)));
1036 gtk_list_store_append (store, &iter);
1037 #if (GLADEUI_VERSION >= 330)
1038 gtk_list_store_set (store, &iter, NAME_COL, glade_project_get_name(project),
1039 PROJECT_COL, project, -1);
1040 #else
1041 gtk_list_store_set (store, &iter, NAME_COL, project->name,
1042 PROJECT_COL, project, -1);
1043 #endif
1044 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (ifile), project);
1045 anjuta_shell_present_widget (ANJUTA_PLUGIN (ifile)->shell, priv->view_box, NULL);
1048 static void
1049 ifile_iface_init(IAnjutaFileIface *iface)
1051 iface->open = ifile_open;
1054 static void
1055 iwizard_activate (IAnjutaWizard *iwizard, GError **err)
1057 GladePluginPriv *priv;
1058 GladeProject *project;
1059 GtkListStore *store;
1060 GtkTreeIter iter;
1062 priv = ANJUTA_PLUGIN_GLADE (iwizard)->priv;
1064 #if (GLADEUI_VERSION >= 330)
1065 project = glade_project_new ();
1066 #else
1067 project = glade_project_new (TRUE);
1068 #endif
1069 if (!project)
1071 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (iwizard)->shell),
1072 _("Could not create a new glade project."));
1073 return;
1075 store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (priv->projects_combo)));
1076 gtk_list_store_append (store, &iter);
1077 #if (GLADEUI_VERSION >= 330)
1078 gtk_list_store_set (store, &iter, NAME_COL, glade_project_get_name(project),
1079 PROJECT_COL, project, -1);
1080 #else
1081 gtk_list_store_set (store, &iter, NAME_COL, project->name,
1082 PROJECT_COL, project, -1);
1083 #endif
1084 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (iwizard), project);
1085 anjuta_shell_present_widget (ANJUTA_PLUGIN (iwizard)->shell,
1086 GTK_WIDGET (glade_app_get_palette ()), NULL);
1089 static void
1090 iwizard_iface_init(IAnjutaWizardIface *iface)
1092 iface->activate = iwizard_activate;
1095 ANJUTA_PLUGIN_BEGIN (GladePlugin, glade_plugin);
1096 ANJUTA_PLUGIN_ADD_INTERFACE (ifile, IANJUTA_TYPE_FILE);
1097 ANJUTA_PLUGIN_ADD_INTERFACE (iwizard, IANJUTA_TYPE_WIZARD);
1098 ANJUTA_PLUGIN_END;
1100 ANJUTA_SIMPLE_PLUGIN (GladePlugin, glade_plugin);