1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
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
23 #if (GLADEUI_VERSION <= 302)
26 # if (GLADEUI_VERSION <= 314)
28 # include <glade-design-view.h>
29 # else /* Since 3.1.5 */
30 # include <gladeui/glade.h>
31 # include <gladeui/glade-design-view.h>
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>
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
54 GtkActionGroup
*action_group
;
57 #if (GLADEUI_VERSION > 302)
58 GtkWidget
*design_notebook
;
61 GtkWidget
*projects_combo
;
71 glade_update_ui (GladeApp
*app
, GladePlugin
*plugin
)
73 #if (GLADEUI_VERSION >= 330)
74 GladeCommand
*undo_item
;
75 GladeCommand
*redo_item
;
77 GList
*prev_redo_item
;
81 const gchar
*undo_description
= NULL
;
82 const gchar
*redo_description
= NULL
;
83 GladeProject
*project
;
90 project
= glade_app_get_project ();
98 #if (GLADEUI_VERSION >= 330)
99 undo_item
= glade_project_next_undo_item(project
);
100 redo_item
= glade_project_next_redo_item(project
);
102 undo_description
= undo_item
->description
;
104 redo_description
= redo_item
->description
;
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
;
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
);
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
);
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
);
150 while (gtk_tree_model_iter_next (model
, &iter
));
154 /* Action callbacks */
156 on_copy_activated (GtkAction
*action
, GladePlugin
*plugin
)
158 glade_app_command_copy ();
162 on_cut_activated (GtkAction
*action
, GladePlugin
*plugin
)
164 glade_app_command_cut ();
168 on_paste_activated (GtkAction
*action
, GladePlugin
*plugin
)
170 glade_app_command_paste (NULL
);
174 on_delete_activated (GtkAction
*action
, GladePlugin
*plugin
)
176 glade_app_command_delete ();
180 on_undo_activated (GtkAction
*action
, GladePlugin
*plugin
)
182 glade_app_command_undo ();
186 on_redo_activated (GtkAction
*action
, GladePlugin
*plugin
)
188 glade_app_command_redo ();
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
));
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"));
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
));
218 anjuta_status_set (status
, _("Glade project '%s' saved"), project
->name
);
223 on_save_activated (GtkAction
*action
, GladePlugin
*plugin
)
225 GladeProject
*project
;
226 GtkWidget
*filechooser
;
229 project
= glade_app_get_project ();
231 #if (GLADEUI_VERSION >= 330)
232 if (glade_project_get_path(project
) != NULL
) {
234 if (project
->path
!= NULL
) {
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
),
243 anjuta_status_set (status
, _("Glade project '%s' saved"),
244 glade_project_get_name(project
));
246 if (glade_project_save (project
, project
->path
, NULL
)) {
247 anjuta_status_set (status
, _("Glade project '%s' saved"),
251 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN(plugin
)->shell
),
252 _("Invalid glade file name"));
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
);
270 glade_save (plugin
, project
, path
);
275 on_save_as_activated (GtkAction
*action
, GladePlugin
*plugin
)
277 GladeProject
*project
;
278 GtkWidget
*filechooser
;
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
);
295 glade_save (plugin
, project
, path
);
300 glade_confirm_close_project (GladePlugin
*plugin
, GladeProject
*project
)
304 gboolean close
= FALSE
;
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
));
318 msg
= g_strdup_printf (string
, project
->name
);
321 dialog
= gtk_message_dialog_new (GTK_WINDOW (ANJUTA_PLUGIN (plugin
)->shell
),
323 GTK_MESSAGE_QUESTION
,
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
));
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
),
352 if (project
->path
!= NULL
)
354 close
= glade_project_save (project
, project
->path
, NULL
);
359 GtkWidget
*filechooser
;
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
);
374 glade_save (plugin
, project
, path
);
379 case GTK_RESPONSE_NO
:
382 case GTK_RESPONSE_CANCEL
:
383 case GTK_RESPONSE_DELETE_EVENT
:
387 g_assert_not_reached ();
391 gtk_widget_destroy (dialog
);
396 on_api_help (GladeEditor
* editor
,
402 gchar
*book_comm
= NULL
, *page_comm
= NULL
;
405 AnjutaPlugin
* aplugin
= ANJUTA_PLUGIN(plugin
);
406 AnjutaShell
* shell
= aplugin
->shell
;
409 help
= anjuta_shell_get_interface(shell
, IAnjutaHelp
, NULL
);
411 /* No API Help Plugin */
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
);
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
),
439 gtk_widget_destroy (design_view
);
441 glade_app_remove_project (project
);
445 on_close_activated (GtkAction
*action
, GladePlugin
*plugin
)
447 GladeProject
*project
;
452 project
= glade_app_get_project ();
456 /* if (gtk_tree_model_iter_n_children (model, NULL) <= 0) */
457 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
461 #if (GLADEUI_VERSION >= 330)
462 if (glade_project_get_has_unsaved_changes (project
))
464 if (project
->changed
)
467 close
= glade_confirm_close_project (plugin
, project
);
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
);
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
));
495 on_glade_project_changed (GtkComboBox
*combo
, GladePlugin
*plugin
)
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
;
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
),
516 gtk_notebook_set_current_page (GTK_NOTEBOOK (plugin
->priv
->design_notebook
),
518 # if (GLADEUI_VERSION >= 330)
519 glade_inspector_set_project (GLADE_INSPECTOR (plugin
->priv
->inspector
), project
);
526 /* Action definitions */
527 static GtkActionEntry actions
[] = {
542 N_("Undo last action"),
543 G_CALLBACK (on_undo_activated
)
550 N_("Redo last undone action"),
551 G_CALLBACK (on_redo_activated
)
559 G_CALLBACK (on_cut_activated
)
566 N_("Copy selection"),
567 G_CALLBACK (on_copy_activated
)
574 N_("Paste selection"),
575 G_CALLBACK (on_paste_activated
)
582 N_("Delete selection"),
583 G_CALLBACK (on_delete_activated
)
586 "ActionGladeShowClipboard",
588 N_("_Show Clipboard"),
590 N_("Show clipboard"),
591 G_CALLBACK (on_show_clipbard_activated
)
598 N_("Save glade project"),
599 G_CALLBACK (on_save_activated
)
606 N_("Save as glade project"),
607 G_CALLBACK (on_save_as_activated
)
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);
626 register_stock_icons (AnjutaPlugin
*plugin
)
629 GtkIconFactory
*icon_factory
;
630 GtkIconSet
*icon_set
;
632 static gboolean registered
= FALSE
;
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");
646 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
647 AnjutaSession
*session
, GladePlugin
*plugin
)
653 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
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
))
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
))
673 #if (GLADEUI_VERSION >= 330)
674 uri
= gnome_vfs_get_uri_from_local_path
675 (glade_project_get_path(project
));
677 uri
= gnome_vfs_get_uri_from_local_path (project
->path
);
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
);
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.
697 on_shell_destroy (AnjutaShell
*shell
, GladePlugin
*glade_plugin
)
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)
718 glade_plugin_add_project (GladePlugin
*glade_plugin
, GladeProject
*project
)
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);
736 glade_plugin_add_project (GladePlugin
*glade_plugin
, GladeProject
*project
)
738 glade_app_add_project (project
);
742 #if (GLADEUI_VERSION >= 330)
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
));
758 activate_plugin (AnjutaPlugin
*plugin
)
761 GladePlugin
*glade_plugin
;
762 GladePluginPriv
*priv
;
763 // GtkAction *action;
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
);
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
),
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
,
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
),
807 priv
->inspector
= glade_project_view_new ();
810 priv
->inspector
= glade_project_view_new (GLADE_PROJECT_VIEW_TREE
);
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
));
819 gtk_box_pack_start (GTK_BOX (priv
->view_box
), GTK_WIDGET (priv
->inspector
),
822 gtk_widget_show_all (priv
->view_box
);
823 gtk_notebook_set_scrollable (GTK_NOTEBOOK (glade_app_get_editor ()->notebook
),
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
);
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 */
850 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGlade",
851 _("Glade operations"),
853 G_N_ELEMENTS (actions
),
854 GETTEXT_PACKAGE
, TRUE
,
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
);
868 gtk_widget_show (GTK_WIDGET (glade_app_get_palette ()));
869 gtk_widget_show (GTK_WIDGET (glade_app_get_editor ()));
872 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin
)->shell
,
873 GTK_WIDGET (priv
->view_box
),
874 "AnjutaGladeTree", _("Widgets"),
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"),
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"),
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"),
892 ANJUTA_SHELL_PLACEMENT_CENTER
, NULL
);
894 /* Connect to save session */
895 g_signal_connect (G_OBJECT (plugin
->shell
), "save_session",
896 G_CALLBACK (on_session_save
), plugin
);
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
),
918 g_signal_handlers_disconnect_by_func (G_OBJECT (priv
->gpw
),
919 G_CALLBACK (glade_update_ui
),
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
),
929 anjuta_shell_remove_widget (plugin
->shell
,
930 GTK_WIDGET (glade_app_get_palette ()),
932 anjuta_shell_remove_widget (plugin
->shell
,
933 GTK_WIDGET (glade_app_get_editor ()),
935 anjuta_shell_remove_widget (plugin
->shell
,
936 GTK_WIDGET (priv
->view_box
),
938 #if (GLADEUI_VERSION > 302)
939 anjuta_shell_remove_widget (plugin
->shell
,
940 GTK_WIDGET (priv
->design_notebook
),
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 */
955 priv
->action_group
= NULL
;
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
));
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
));
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);
987 DEBUG_PRINT ("Intializing Glade plugin");
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
;
1004 ifile_open (IAnjutaFile
*ifile
, const gchar
*uri
, GError
**err
)
1006 GladePluginPriv
*priv
;
1007 GladeProject
*project
;
1008 GtkListStore
*store
;
1012 g_return_if_fail (uri
!= NULL
);
1014 priv
= ANJUTA_PLUGIN_GLADE (ifile
)->priv
;
1016 filename
= gnome_vfs_get_local_path_from_uri (uri
);
1019 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
1020 _("Not local file: %s"), uri
);
1023 #if (GLADEUI_VERSION >= 330)
1024 project
= glade_project_load (filename
);
1026 project
= glade_project_open (filename
);
1031 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
1032 _("Could not open: %s"), uri
);
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);
1041 gtk_list_store_set (store
, &iter
, NAME_COL
, project
->name
,
1042 PROJECT_COL
, project
, -1);
1044 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (ifile
), project
);
1045 anjuta_shell_present_widget (ANJUTA_PLUGIN (ifile
)->shell
, priv
->view_box
, NULL
);
1049 ifile_iface_init(IAnjutaFileIface
*iface
)
1051 iface
->open
= ifile_open
;
1055 iwizard_activate (IAnjutaWizard
*iwizard
, GError
**err
)
1057 GladePluginPriv
*priv
;
1058 GladeProject
*project
;
1059 GtkListStore
*store
;
1062 priv
= ANJUTA_PLUGIN_GLADE (iwizard
)->priv
;
1064 #if (GLADEUI_VERSION >= 330)
1065 project
= glade_project_new ();
1067 project
= glade_project_new (TRUE
);
1071 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (iwizard
)->shell
),
1072 _("Could not create a new glade project."));
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);
1081 gtk_list_store_set (store
, &iter
, NAME_COL
, project
->name
,
1082 PROJECT_COL
, project
, -1);
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
);
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
);
1100 ANJUTA_SIMPLE_PLUGIN (GladePlugin
, glade_plugin
);