1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2000 Naba Kumar
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 *Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <libanjuta/anjuta-shell.h>
22 #include <libanjuta/anjuta-debug.h>
23 #include <libanjuta/interfaces/ianjuta-file.h>
24 #include <libanjuta/interfaces/ianjuta-file-savable.h>
25 #include <libanjuta/interfaces/ianjuta-wizard.h>
26 #include <libanjuta/interfaces/ianjuta-help.h>
27 #include <libanjuta/interfaces/ianjuta-document-manager.h>
30 #include "anjuta-design-document.h"
32 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-glade.xml"
34 static gpointer parent_class
;
36 /* This is variable required from libdevhelp */
37 gchar
*geometry
= NULL
;
39 struct _GladePluginPriv
42 GtkActionGroup
*action_group
;
51 GtkWidget
*palette_box
;
55 GtkWidget
*selector_toggle
;
56 GtkWidget
*resize_toggle
;
58 /* File count, disable plugin when NULL */
72 on_pointer_mode_changed (GladeProject
*project
,
77 value_added_current_editor (AnjutaPlugin
*plugin
, const char *name
,
78 const GValue
*value
, gpointer data
)
80 GladePlugin
* glade_plugin
= ANJUTA_PLUGIN_GLADE(plugin
);
81 GladePluginPriv
* priv
= glade_plugin
->priv
;
83 editor
= g_value_get_object (value
);
84 if (ANJUTA_IS_DESIGN_DOCUMENT(editor
))
86 AnjutaDesignDocument
* view
= ANJUTA_DESIGN_DOCUMENT(editor
);
87 GladeProject
* project
= glade_design_view_get_project(GLADE_DESIGN_VIEW(view
));
88 if (!view
->is_project_added
)
90 glade_app_add_project (project
);
91 g_signal_connect (G_OBJECT (project
), "notify::pointer-mode",
92 G_CALLBACK (on_pointer_mode_changed
), glade_plugin
);
93 view
->is_project_added
= TRUE
;
95 /* Change view components */
96 glade_palette_set_project (GLADE_PALETTE (priv
->palette
), project
);
97 glade_inspector_set_project (GLADE_INSPECTOR (priv
->inspector
), project
);
102 value_removed_current_editor (AnjutaPlugin
*plugin
,
103 const char *name
, gpointer data
)
109 on_signal_editor_created (GladeApp
* app
,
110 GladeSignalEditor
* seditor
,
113 glade_signal_editor_enable_dnd (seditor
, TRUE
);
117 on_api_help (GladeEditor
* editor
,
124 AnjutaPlugin
* aplugin
= ANJUTA_PLUGIN(plugin
);
125 AnjutaShell
* shell
= aplugin
->shell
;
128 help
= anjuta_shell_get_interface(shell
, IAnjutaHelp
, NULL
);
130 /* No API Help Plugin */
136 ianjuta_help_search(help
, search
, NULL
);
140 glade_do_close (GladePlugin
*plugin
, GladeProject
*project
)
142 glade_app_remove_project (project
);
146 on_document_destroy (GtkWidget
* document
, GladePlugin
*plugin
)
148 GladeProject
*project
;
150 DEBUG_PRINT ("%s", "Destroying Document");
152 if (plugin
->priv
->destroying
)
157 project
= glade_design_view_get_project(GLADE_DESIGN_VIEW(document
));
163 glade_do_close (plugin
, project
);
165 plugin
->priv
->file_count
--;
166 if (plugin
->priv
->file_count
<= 0)
167 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
169 on_pointer_mode_changed (project
, NULL
, plugin
);
173 on_document_mapped (GtkWidget
* doc
, GladePlugin
* plugin
)
175 GladeProject
* project
= glade_design_view_get_project (GLADE_DESIGN_VIEW (doc
));
176 GladeEditor
* editor
= GLADE_EDITOR (plugin
->priv
->editor
);
177 GList
* glade_obj_node
;
178 GList
* list
= g_list_copy ((GList
*)glade_project_get_objects (project
));
181 gboolean first
= TRUE
;
183 /* Select the all windows in the project, select the first */
184 for (glade_obj_node
= list
;
185 glade_obj_node
!= NULL
;
186 glade_obj_node
= g_list_next (glade_obj_node
))
188 GObject
*glade_obj
= G_OBJECT (glade_obj_node
->data
);
189 GladeWidget
* glade_widget
= glade_widget_get_from_gobject (glade_obj
);
190 if (glade_widget
== glade_widget_get_toplevel (glade_widget
))
192 glade_project_widget_visibility_changed (project
, glade_widget
, TRUE
);
193 glade_editor_load_widget (editor
, glade_widget
);
197 glade_project_selection_set (project
, glade_obj
, TRUE
);
204 /* Only do this on first map */
205 g_signal_handlers_disconnect_by_func (doc
, G_CALLBACK (on_document_mapped
),
210 on_shell_destroy (AnjutaShell
* shell
, GladePlugin
*glade_plugin
)
212 glade_plugin
->priv
->destroying
= TRUE
;
216 register_stock_icons (AnjutaPlugin
*plugin
)
218 static gboolean registered
= FALSE
;
224 /* Register stock icons */
225 BEGIN_REGISTER_ICON (plugin
);
226 REGISTER_ICON_FULL ("anjuta-glade-plugin",
227 "glade-plugin-icon");
228 REGISTER_ICON_FULL ("anjuta-glade-widgets",
229 "glade-plugin-widgets");
230 REGISTER_ICON_FULL ("anjuta-glade-palette",
231 "glade-plugin-palette");
236 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
237 AnjutaSession
*session
, GladePlugin
*plugin
)
239 GList
*files
, *docwids
, *node
;
240 /* GtkTreeModel *model;
243 IAnjutaDocumentManager
*docman
;
245 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
248 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN(plugin
)->shell
,
249 IAnjutaDocumentManager
, NULL
);
250 docwids
= ianjuta_document_manager_get_doc_widgets (docman
, NULL
);
253 files
= anjuta_session_get_string_list (session
, "File Loader", "Files");
255 files
= g_list_reverse (files
);
256 for (node
= docwids
; node
!= NULL
; node
= g_list_next (node
))
258 if (ANJUTA_IS_DESIGN_DOCUMENT (node
->data
))
261 file
= ianjuta_file_get_file (IANJUTA_FILE (node
->data
), NULL
);
264 files
= g_list_prepend (files
, anjuta_session_get_relative_uri_from_file (session
, file
, NULL
));
265 g_object_unref (file
);
266 /* uri is not freed here */
270 g_list_free (docwids
);
273 files
= g_list_reverse (files
);
274 anjuta_session_set_string_list (session
, "File Loader", "Files", files
);
275 g_list_foreach (files
, (GFunc
)g_free
, NULL
);
282 glade_plugin_selection_changed (GladeProject
*project
,
285 GladeWidget
*glade_widget
= NULL
;
287 if (glade_project_get_has_selection (project
))
292 list
= glade_project_selection_get (project
);
294 for (node
= list
; node
!= NULL
; node
= g_list_next (node
))
296 glade_widget
= glade_widget_get_from_gobject (G_OBJECT (node
->data
));
297 glade_widget_show (glade_widget
);
299 glade_editor_load_widget (GLADE_EDITOR (plugin
->priv
->editor
), glade_widget
);
302 glade_editor_load_widget (GLADE_EDITOR (plugin
->priv
->editor
), NULL
);
306 glade_plugin_add_project (GladePlugin
*glade_plugin
, GladeProject
*project
)
309 GladePluginPriv
*priv
;
310 IAnjutaDocumentManager
* docman
=
311 anjuta_shell_get_interface(ANJUTA_PLUGIN(glade_plugin
)->shell
,
312 IAnjutaDocumentManager
, NULL
);
314 g_return_if_fail (GLADE_IS_PROJECT (project
));
316 priv
= glade_plugin
->priv
;
318 /* Create document */
319 view
= anjuta_design_document_new(glade_plugin
, project
);
320 g_signal_connect (view
, "destroy",
321 G_CALLBACK (on_document_destroy
), glade_plugin
);
322 g_signal_connect (view
, "map", G_CALLBACK (on_document_mapped
), glade_plugin
);
323 gtk_widget_show (view
);
324 g_object_set_data (G_OBJECT (project
), "design_view", view
);
326 /* Change view components */
327 glade_palette_set_project (GLADE_PALETTE (priv
->palette
), project
);
330 g_signal_connect (project
, "selection-changed",
331 G_CALLBACK (glade_plugin_selection_changed
),
336 ianjuta_document_manager_add_document (docman
, IANJUTA_DOCUMENT(view
), NULL
);
340 add_glade_member (GladeWidget
*widget
,
341 AnjutaPlugin
*plugin
)
343 IAnjutaDocumentManager
*docman
;
344 GladeProject
*project
= glade_widget_get_project (widget
);
345 gchar
*path
= glade_project_get_path (project
);
346 gchar
*widget_name
= glade_widget_get_name (widget
);
347 gchar
*widget_typename
= G_OBJECT_TYPE_NAME (glade_widget_get_object(widget
));
351 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
352 IAnjutaDocumentManager
, NULL
);
356 docs
= ianjuta_document_manager_get_doc_widgets (docman
, NULL
);
359 for (item
= docs
; item
!= NULL
; item
= g_list_next (item
))
361 IAnjutaDocument
*curr_doc
= IANJUTA_DOCUMENT(item
->data
);
362 if (!IANJUTA_IS_EDITOR (curr_doc
)) continue;
364 g_signal_emit_by_name (G_OBJECT (curr_doc
), "glade-member-add",
365 widget_typename
, widget_name
, path
);
370 inspector_item_activated_cb (GladeInspector
*inspector
,
371 AnjutaPlugin
*plugin
)
373 GList
*items
= glade_inspector_get_selected_items (inspector
);
375 g_assert (GLADE_IS_WIDGET (items
->data
) && (items
->next
== NULL
));
377 /* switch to this widget in the workspace */
378 for (item
= items
; item
!= NULL
; item
= g_list_next (item
))
380 glade_widget_hide (GLADE_WIDGET (item
->data
));
381 glade_widget_show (GLADE_WIDGET (item
->data
));
382 add_glade_member (item
->data
, plugin
);
389 on_selector_button_toggled (GtkToggleToolButton
* button
, GladePlugin
*plugin
)
391 GladeProject
*active_project
= glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
));
393 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
)))
395 glade_project_set_add_item (active_project
, NULL
);
396 glade_project_set_pointer_mode (active_project
, GLADE_POINTER_SELECT
);
399 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), TRUE
);
403 on_drag_resize_button_toggled (GtkToggleToolButton
*button
,
406 GladeProject
*active_project
= glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
));
408 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
)))
409 glade_project_set_pointer_mode (active_project
, GLADE_POINTER_DRAG_RESIZE
);
411 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), TRUE
);
416 on_pointer_mode_changed (GladeProject
*project
,
420 GladeProject
*active_project
= glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
));
424 gtk_widget_set_sensitive (plugin
->priv
->selector_toggle
, FALSE
);
425 gtk_widget_set_sensitive (plugin
->priv
->resize_toggle
, FALSE
);
428 else if (active_project
!= project
)
431 gtk_widget_set_sensitive (plugin
->priv
->selector_toggle
, TRUE
);
432 gtk_widget_set_sensitive (plugin
->priv
->resize_toggle
, TRUE
);
434 g_signal_handlers_block_by_func (plugin
->priv
->selector_toggle
,
435 on_selector_button_toggled
, plugin
);
436 g_signal_handlers_block_by_func (plugin
->priv
->resize_toggle
,
437 on_drag_resize_button_toggled
, plugin
);
439 if (glade_project_get_pointer_mode (project
) == GLADE_POINTER_SELECT
)
441 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), TRUE
);
442 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), FALSE
);
444 else if (glade_project_get_pointer_mode (project
) == GLADE_POINTER_DRAG_RESIZE
)
446 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), TRUE
);
447 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), FALSE
);
451 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), FALSE
);
452 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), FALSE
);
455 g_signal_handlers_unblock_by_func (plugin
->priv
->selector_toggle
,
456 on_selector_button_toggled
, plugin
);
457 g_signal_handlers_unblock_by_func (plugin
->priv
->resize_toggle
,
458 on_drag_resize_button_toggled
, plugin
);
461 /* Progress callbacks */
463 glade_plugin_parse_began (GladeProject
*project
,
466 AnjutaStatus
*status
= anjuta_shell_get_status (ANJUTA_PLUGIN(plugin
)->shell
,
468 anjuta_status_busy_push (status
);
469 plugin
->priv
->add_ticks
= TRUE
;
473 glade_plugin_parse_finished (GladeProject
*project
,
474 AnjutaPlugin
*plugin
)
476 AnjutaStatus
*status
= anjuta_shell_get_status (ANJUTA_PLUGIN(plugin
)->shell
,
478 GladePlugin
* gplugin
= ANJUTA_PLUGIN_GLADE (plugin
);
479 anjuta_status_busy_pop (status
);
481 glade_inspector_set_project (GLADE_INSPECTOR (gplugin
->priv
->inspector
), project
);
485 glade_plugin_load_progress (GladeProject
*project
,
488 AnjutaPlugin
*plugin
)
490 GladePlugin
*glade_plugin
= ANJUTA_PLUGIN_GLADE (plugin
);
491 AnjutaStatus
*status
= anjuta_shell_get_status (plugin
->shell
,
495 static GdkPixbuf
* icon
= NULL
;
499 icon
= gtk_icon_theme_load_icon (gtk_icon_theme_get_default(),
501 GTK_ICON_SIZE_BUTTON
,
506 if (glade_plugin
->priv
->add_ticks
)
508 glade_plugin
->priv
->add_ticks
= FALSE
;
509 anjuta_status_progress_add_ticks (status
, total_ticks
);
512 project_name
= glade_project_get_name (project
);
513 text
= g_strdup_printf ("Loading %s…", project_name
);
514 anjuta_status_progress_tick (status
,
518 g_free (project_name
);
522 create_selector_tool_button ()
529 g_build_filename (glade_app_get_pixmaps_dir (), "selector.png", NULL
);
530 image
= gtk_image_new_from_file (image_path
);
533 button
= gtk_toggle_button_new ();
534 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
536 gtk_button_set_image (GTK_BUTTON (button
), image
);
538 gtk_widget_set_tooltip_text (button
,
539 _("Select widgets in the workspace"));
541 gtk_widget_show (button
);
542 gtk_widget_show (image
);
548 create_drag_resize_tool_button ()
555 g_build_filename (glade_app_get_pixmaps_dir (), "drag-resize.png", NULL
);
556 image
= gtk_image_new_from_file (image_path
);
559 button
= gtk_toggle_button_new ();
560 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
562 gtk_button_set_image (GTK_BUTTON (button
), image
);
564 gtk_widget_set_tooltip_text (button
,
565 _("Drag and resize widgets in the workspace"));
567 gtk_widget_show (button
);
568 gtk_widget_show (image
);
574 activate_plugin (AnjutaPlugin
*plugin
)
576 GladePlugin
*glade_plugin
;
577 GladePluginPriv
*priv
;
578 AnjutaStatus
* status
;
579 GtkWidget
* button_box
;
581 DEBUG_PRINT ("%s", "GladePlugin: Activating Glade plugin…");
583 glade_plugin
= ANJUTA_PLUGIN_GLADE (plugin
);
585 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
586 priv
= glade_plugin
->priv
;
588 register_stock_icons (plugin
);
590 anjuta_status_busy_push (status
);
591 anjuta_status_set (status
, "%s", _("Loading Glade…"));
593 priv
->app
= glade_app_get ();
596 priv
->app
= glade_app_new ();
599 glade_app_set_window (GTK_WIDGET (ANJUTA_PLUGIN(plugin
)->shell
));
601 priv
->inspector
= glade_inspector_new ();
603 g_signal_connect (priv
->inspector
, "item-activated",
604 G_CALLBACK (inspector_item_activated_cb
),
607 priv
->paned
= gtk_paned_new (GTK_ORIENTATION_VERTICAL
);
609 priv
->editor
= GTK_WIDGET(glade_editor_new());
611 priv
->palette
= glade_palette_new();
612 priv
->palette_box
= gtk_vbox_new (FALSE
, 5);
613 priv
->selector_toggle
= create_selector_tool_button ();
614 priv
->resize_toggle
= create_drag_resize_tool_button ();
615 button_box
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
616 gtk_box_pack_start (GTK_BOX (button_box
),
617 priv
->selector_toggle
,
619 gtk_box_pack_start (GTK_BOX (button_box
),
622 gtk_box_pack_start (GTK_BOX (priv
->palette_box
),
625 gtk_box_pack_start (GTK_BOX (priv
->palette_box
),
630 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv
->selector_toggle
),
632 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv
->resize_toggle
),
635 g_signal_connect (G_OBJECT (priv
->selector_toggle
), "toggled",
636 G_CALLBACK (on_selector_button_toggled
), plugin
);
637 g_signal_connect (G_OBJECT (priv
->resize_toggle
), "toggled",
638 G_CALLBACK (on_drag_resize_button_toggled
), plugin
);
641 glade_palette_set_show_selector_button (GLADE_PALETTE (priv
->palette
),
644 gtk_paned_add1 (GTK_PANED(priv
->paned
), priv
->inspector
);
645 gtk_paned_add2 (GTK_PANED(priv
->paned
), priv
->editor
);
647 gtk_widget_show_all (priv
->paned
);
649 anjuta_status_busy_pop (status
);
651 g_signal_connect(plugin
->shell
, "destroy",
652 G_CALLBACK(on_shell_destroy
), plugin
);
654 g_signal_connect(priv
->app
, "doc-search",
655 G_CALLBACK(on_api_help
), plugin
);
657 g_signal_connect(priv
->app
, "signal-editor-created",
658 G_CALLBACK(on_signal_editor_created
), plugin
);
660 gtk_widget_show (priv
->palette
);
661 gtk_widget_show (priv
->editor
);
662 gtk_widget_show (priv
->inspector
);
665 anjuta_shell_add_widget (anjuta_plugin_get_shell (ANJUTA_PLUGIN (plugin
)),
667 "AnjutaGladeTree", _("Widgets"),
668 "glade-plugin-widgets",
669 ANJUTA_SHELL_PLACEMENT_RIGHT
, NULL
);
670 anjuta_shell_add_widget (anjuta_plugin_get_shell (ANJUTA_PLUGIN (plugin
)),
672 "AnjutaGladePalette", _("Palette"),
673 "glade-plugin-palette",
674 ANJUTA_SHELL_PLACEMENT_LEFT
, NULL
);
675 /* Connect to save session */
676 g_signal_connect (G_OBJECT (plugin
->shell
), "save_session",
677 G_CALLBACK (on_session_save
), plugin
);
679 /* Watch documents */
680 glade_plugin
->priv
->editor_watch_id
=
681 anjuta_plugin_add_watch (plugin
, IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT
,
682 value_added_current_editor
,
683 value_removed_current_editor
, NULL
);
689 deactivate_plugin (AnjutaPlugin
*plugin
)
691 GladePluginPriv
*priv
;
693 priv
= ANJUTA_PLUGIN_GLADE (plugin
)->priv
;
695 DEBUG_PRINT ("%s", "GladePlugin: Dectivating Glade plugin…");
697 if (glade_app_get_projects ())
699 /* Cannot deactivate plugin if there are still files open */
704 /* Disconnect signals */
705 g_signal_handlers_disconnect_by_func (plugin
->shell
,
706 G_CALLBACK (on_shell_destroy
),
709 g_signal_handlers_disconnect_by_func (plugin
->shell
,
710 G_CALLBACK (on_session_save
), plugin
);
712 g_signal_handlers_disconnect_by_func (priv
->app
,
713 G_CALLBACK(on_api_help
), plugin
);
716 anjuta_shell_remove_widget (anjuta_plugin_get_shell (plugin
),
719 anjuta_shell_remove_widget (anjuta_plugin_get_shell (plugin
),
724 priv
->action_group
= NULL
;
732 glade_plugin_dispose (GObject
*obj
)
734 /* GladePlugin *plugin = ANJUTA_PLUGIN_GLADE (obj); */
736 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
740 glade_plugin_finalize (GObject
*obj
)
742 GladePlugin
*plugin
= ANJUTA_PLUGIN_GLADE (obj
);
743 g_free (plugin
->priv
);
744 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
748 glade_plugin_instance_init (GObject
*obj
)
750 GladePluginPriv
*priv
;
751 GladePlugin
*plugin
= ANJUTA_PLUGIN_GLADE (obj
);
753 plugin
->priv
= (GladePluginPriv
*) g_new0 (GladePluginPriv
, 1);
755 priv
->destroying
= FALSE
;
756 priv
->file_count
= 0;
757 priv
->add_ticks
= FALSE
;
759 DEBUG_PRINT ("%s", "Intializing Glade plugin");
763 glade_plugin_class_init (GObjectClass
*klass
)
765 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
767 parent_class
= g_type_class_peek_parent (klass
);
769 plugin_class
->activate
= activate_plugin
;
770 plugin_class
->deactivate
= deactivate_plugin
;
771 klass
->dispose
= glade_plugin_dispose
;
772 klass
->finalize
= glade_plugin_finalize
;
776 ifile_open (IAnjutaFile
*ifile
, GFile
* file
, GError
**err
)
778 AnjutaPlugin
* plugin
= ANJUTA_PLUGIN (ifile
);
779 GladePluginPriv
*priv
;
780 GladeProject
*project
;
782 IAnjutaDocumentManager
* docman
;
783 GList
* docwids
, *node
;
785 g_return_if_fail (file
!= NULL
);
787 priv
= ANJUTA_PLUGIN_GLADE (ifile
)->priv
;
789 filename
= g_file_get_path (file
);
792 gchar
* uri
= g_file_get_parse_name(file
);
793 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
794 _("Not local file: %s"), uri
);
795 if (priv
->file_count
<= 0)
796 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
802 docman
= anjuta_shell_get_interface(ANJUTA_PLUGIN(ifile
)->shell
, IAnjutaDocumentManager
,
804 docwids
= ianjuta_document_manager_get_doc_widgets (docman
, NULL
);
807 for (node
= docwids
; node
!= NULL
; node
= g_list_next (node
))
809 if (ANJUTA_IS_DESIGN_DOCUMENT (node
->data
))
812 cur_file
= ianjuta_file_get_file (IANJUTA_FILE (node
->data
), NULL
);
815 if (g_file_equal (file
, cur_file
))
817 ianjuta_document_manager_set_current_document (docman
,
818 IANJUTA_DOCUMENT (node
->data
), NULL
);
819 g_object_unref (file
);
822 g_object_unref (file
);
826 g_list_free (docwids
);
829 project
= glade_project_new ();
830 g_signal_connect (project
, "parse-began",
831 G_CALLBACK (glade_plugin_parse_began
), plugin
);
832 g_signal_connect (project
, "parse-finished",
833 G_CALLBACK (glade_plugin_parse_finished
), plugin
);
834 g_signal_connect (project
, "load-progress",
835 G_CALLBACK (glade_plugin_load_progress
), plugin
);
836 if (!glade_project_load_from_file (project
, filename
))
838 gchar
* name
= g_file_get_parse_name (file
);
839 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
840 _("Could not open %s"), name
);
841 if (priv
->file_count
<= 0)
842 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
849 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (ifile
), project
);
851 anjuta_shell_present_widget (ANJUTA_PLUGIN (ifile
)->shell
, priv
->paned
, NULL
);
855 ifile_get_file (IAnjutaFile
* ifile
, GError
** e
)
857 GladePlugin
* plugin
= (GladePlugin
*) ifile
;
859 glade_project_get_path(glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
)));
860 GFile
* file
= g_file_new_for_path (path
);
865 ifile_iface_init(IAnjutaFileIface
*iface
)
867 iface
->open
= ifile_open
;
868 iface
->get_file
= ifile_get_file
;
872 iwizard_activate (IAnjutaWizard
*iwizard
, GError
**err
)
874 GladePluginPriv
*priv
;
875 GladeProject
*project
;
877 priv
= ANJUTA_PLUGIN_GLADE (iwizard
)->priv
;
879 project
= glade_project_new ();
882 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (iwizard
)->shell
),
883 _("Could not create a new glade project."));
886 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (iwizard
), project
);
887 anjuta_shell_present_widget (ANJUTA_PLUGIN (iwizard
)->shell
,
888 priv
->palette_box
, NULL
);
892 iwizard_iface_init(IAnjutaWizardIface
*iface
)
894 iface
->activate
= iwizard_activate
;
897 ANJUTA_PLUGIN_BEGIN (GladePlugin
, glade_plugin
);
898 ANJUTA_PLUGIN_ADD_INTERFACE (ifile
, IANJUTA_TYPE_FILE
);
899 ANJUTA_PLUGIN_ADD_INTERFACE (iwizard
, IANJUTA_TYPE_WIZARD
);
902 ANJUTA_SIMPLE_PLUGIN (GladePlugin
, glade_plugin
);