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 signal_editor_signal_activated_cb (GladeSignalEditor
* seditor
,
113 IAnjutaEditor
* current_editor
;
114 GladeWidget
*gwidget
= glade_signal_editor_get_widget (seditor
);
115 GladeProject
*project
= glade_widget_get_project (gwidget
);
116 gchar
*path
= glade_project_get_path (project
);
118 IAnjutaDocumentManager
*docman
;
119 IAnjutaDocument
*doc
;
121 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
122 IAnjutaDocumentManager
, NULL
);
126 doc
= ianjuta_document_manager_get_current_document (docman
, NULL
);
130 if (!IANJUTA_IS_EDITOR (doc
))
133 current_editor
= IANJUTA_EDITOR (doc
);
138 g_signal_emit_by_name (G_OBJECT (current_editor
), "glade-callback-add",
139 G_OBJECT_TYPE_NAME (glade_widget_get_object (gwidget
)),
140 glade_signal_get_name (signal
),
141 glade_signal_get_handler (signal
),
142 glade_signal_get_userdata (signal
),
143 glade_signal_get_swapped (signal
)?"1":"0",
144 glade_signal_get_after (signal
)?"1":"0",
149 on_signal_editor_created (GladeApp
* app
,
150 GladeSignalEditor
* seditor
,
153 glade_signal_editor_enable_dnd (seditor
, TRUE
);
155 g_signal_connect (seditor
, "signal-activated",
156 G_CALLBACK (signal_editor_signal_activated_cb
),
161 on_api_help (GladeEditor
* editor
,
168 AnjutaPlugin
* aplugin
= ANJUTA_PLUGIN(plugin
);
169 AnjutaShell
* shell
= aplugin
->shell
;
172 help
= anjuta_shell_get_interface(shell
, IAnjutaHelp
, NULL
);
174 /* No API Help Plugin */
180 ianjuta_help_search(help
, search
, NULL
);
184 glade_do_close (GladePlugin
*plugin
, GladeProject
*project
)
186 glade_app_remove_project (project
);
190 on_document_destroy (GtkWidget
* document
, GladePlugin
*plugin
)
192 GladeProject
*project
;
194 DEBUG_PRINT ("%s", "Destroying Document");
196 if (plugin
->priv
->destroying
)
201 project
= glade_design_view_get_project(GLADE_DESIGN_VIEW(document
));
207 glade_do_close (plugin
, project
);
209 plugin
->priv
->file_count
--;
210 if (plugin
->priv
->file_count
<= 0)
211 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
213 on_pointer_mode_changed (project
, NULL
, plugin
);
217 on_document_mapped (GtkWidget
* doc
, GladePlugin
* plugin
)
219 GladeProject
* project
= glade_design_view_get_project (GLADE_DESIGN_VIEW (doc
));
220 GladeEditor
* editor
= GLADE_EDITOR (plugin
->priv
->editor
);
221 GList
* glade_obj_node
;
222 GList
* list
= g_list_copy ((GList
*)glade_project_get_objects (project
));
225 gboolean first
= TRUE
;
227 /* Select the all windows in the project, select the first */
228 for (glade_obj_node
= list
;
229 glade_obj_node
!= NULL
;
230 glade_obj_node
= g_list_next (glade_obj_node
))
232 GObject
*glade_obj
= G_OBJECT (glade_obj_node
->data
);
233 GladeWidget
* glade_widget
= glade_widget_get_from_gobject (glade_obj
);
234 if (glade_widget
== glade_widget_get_toplevel (glade_widget
))
236 glade_project_widget_visibility_changed (project
, glade_widget
, TRUE
);
237 glade_editor_load_widget (editor
, glade_widget
);
241 glade_project_selection_set (project
, glade_obj
, TRUE
);
248 /* Only do this on first map */
249 g_signal_handlers_disconnect_by_func (doc
, G_CALLBACK (on_document_mapped
),
254 on_shell_destroy (AnjutaShell
* shell
, GladePlugin
*glade_plugin
)
256 glade_plugin
->priv
->destroying
= TRUE
;
260 register_stock_icons (AnjutaPlugin
*plugin
)
262 static gboolean registered
= FALSE
;
268 /* Register stock icons */
269 BEGIN_REGISTER_ICON (plugin
);
270 REGISTER_ICON_FULL ("anjuta-glade-plugin",
271 "glade-plugin-icon");
272 REGISTER_ICON_FULL ("anjuta-glade-widgets",
273 "glade-plugin-widgets");
274 REGISTER_ICON_FULL ("anjuta-glade-palette",
275 "glade-plugin-palette");
280 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
281 AnjutaSession
*session
, GladePlugin
*plugin
)
283 GList
*files
, *docwids
, *node
;
284 /* GtkTreeModel *model;
287 IAnjutaDocumentManager
*docman
;
289 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
292 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN(plugin
)->shell
,
293 IAnjutaDocumentManager
, NULL
);
294 docwids
= ianjuta_document_manager_get_doc_widgets (docman
, NULL
);
297 files
= anjuta_session_get_string_list (session
, "File Loader", "Files");
299 files
= g_list_reverse (files
);
300 for (node
= docwids
; node
!= NULL
; node
= g_list_next (node
))
302 if (ANJUTA_IS_DESIGN_DOCUMENT (node
->data
))
305 file
= ianjuta_file_get_file (IANJUTA_FILE (node
->data
), NULL
);
308 files
= g_list_prepend (files
, anjuta_session_get_relative_uri_from_file (session
, file
, NULL
));
309 g_object_unref (file
);
310 /* uri is not freed here */
314 g_list_free (docwids
);
317 files
= g_list_reverse (files
);
318 anjuta_session_set_string_list (session
, "File Loader", "Files", files
);
319 g_list_foreach (files
, (GFunc
)g_free
, NULL
);
326 glade_plugin_selection_changed (GladeProject
*project
,
329 GladeWidget
*glade_widget
= NULL
;
331 if (glade_project_get_has_selection (project
))
336 list
= glade_project_selection_get (project
);
338 for (node
= list
; node
!= NULL
; node
= g_list_next (node
))
340 glade_widget
= glade_widget_get_from_gobject (G_OBJECT (node
->data
));
341 glade_widget_show (glade_widget
);
343 glade_editor_load_widget (GLADE_EDITOR (plugin
->priv
->editor
), glade_widget
);
346 glade_editor_load_widget (GLADE_EDITOR (plugin
->priv
->editor
), NULL
);
350 glade_plugin_add_project (GladePlugin
*glade_plugin
, GladeProject
*project
)
353 GladePluginPriv
*priv
;
354 IAnjutaDocumentManager
* docman
=
355 anjuta_shell_get_interface(ANJUTA_PLUGIN(glade_plugin
)->shell
,
356 IAnjutaDocumentManager
, NULL
);
358 g_return_if_fail (GLADE_IS_PROJECT (project
));
360 priv
= glade_plugin
->priv
;
362 /* Create document */
363 view
= anjuta_design_document_new(glade_plugin
, project
);
364 g_signal_connect (view
, "destroy",
365 G_CALLBACK (on_document_destroy
), glade_plugin
);
366 g_signal_connect (view
, "map", G_CALLBACK (on_document_mapped
), glade_plugin
);
367 gtk_widget_show (view
);
368 g_object_set_data (G_OBJECT (project
), "design_view", view
);
370 /* Change view components */
371 glade_palette_set_project (GLADE_PALETTE (priv
->palette
), project
);
374 g_signal_connect (project
, "selection-changed",
375 G_CALLBACK (glade_plugin_selection_changed
),
380 ianjuta_document_manager_add_document (docman
, IANJUTA_DOCUMENT (view
), NULL
);
384 add_glade_member (GladeWidget
*widget
,
385 AnjutaPlugin
*plugin
)
387 IAnjutaEditor
* current_editor
;
388 IAnjutaDocumentManager
*docman
;
389 GladeProject
*project
= glade_widget_get_project (widget
);
390 gchar
*path
= glade_project_get_path (project
);
391 gchar
*widget_name
= glade_widget_get_name (widget
);
392 gchar
*widget_typename
= G_OBJECT_TYPE_NAME (glade_widget_get_object(widget
));
393 IAnjutaDocument
*doc
;
395 docman
= anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin
)->shell
,
396 IAnjutaDocumentManager
, NULL
);
400 doc
= ianjuta_document_manager_get_current_document (docman
, NULL
);
404 if (!IANJUTA_IS_EDITOR (doc
))
407 current_editor
= IANJUTA_EDITOR (doc
);
412 g_signal_emit_by_name (G_OBJECT (current_editor
), "glade-member-add",
413 widget_typename
, widget_name
, path
);
417 inspector_item_activated_cb (GladeInspector
*inspector
,
418 AnjutaPlugin
*plugin
)
420 GList
*items
= glade_inspector_get_selected_items (inspector
);
422 g_assert (GLADE_IS_WIDGET (items
->data
) && (items
->next
== NULL
));
424 /* switch to this widget in the workspace */
425 for (item
= items
; item
!= NULL
; item
= g_list_next (item
))
427 glade_widget_hide (GLADE_WIDGET (item
->data
));
428 glade_widget_show (GLADE_WIDGET (item
->data
));
429 add_glade_member (item
->data
, plugin
);
436 on_selector_button_toggled (GtkToggleToolButton
* button
, GladePlugin
*plugin
)
438 GladeProject
*active_project
= glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
));
440 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
)))
442 glade_project_set_add_item (active_project
, NULL
);
443 glade_project_set_pointer_mode (active_project
, GLADE_POINTER_SELECT
);
446 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), TRUE
);
450 on_drag_resize_button_toggled (GtkToggleToolButton
*button
,
453 GladeProject
*active_project
= glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
));
455 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
)))
456 glade_project_set_pointer_mode (active_project
, GLADE_POINTER_DRAG_RESIZE
);
458 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), TRUE
);
463 on_pointer_mode_changed (GladeProject
*project
,
467 GladeProject
*active_project
= glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
));
471 gtk_widget_set_sensitive (plugin
->priv
->selector_toggle
, FALSE
);
472 gtk_widget_set_sensitive (plugin
->priv
->resize_toggle
, FALSE
);
475 else if (active_project
!= project
)
478 gtk_widget_set_sensitive (plugin
->priv
->selector_toggle
, TRUE
);
479 gtk_widget_set_sensitive (plugin
->priv
->resize_toggle
, TRUE
);
481 g_signal_handlers_block_by_func (plugin
->priv
->selector_toggle
,
482 on_selector_button_toggled
, plugin
);
483 g_signal_handlers_block_by_func (plugin
->priv
->resize_toggle
,
484 on_drag_resize_button_toggled
, plugin
);
486 if (glade_project_get_pointer_mode (project
) == GLADE_POINTER_SELECT
)
488 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), TRUE
);
489 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), FALSE
);
491 else if (glade_project_get_pointer_mode (project
) == GLADE_POINTER_DRAG_RESIZE
)
493 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), TRUE
);
494 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), FALSE
);
498 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->resize_toggle
), FALSE
);
499 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin
->priv
->selector_toggle
), FALSE
);
502 g_signal_handlers_unblock_by_func (plugin
->priv
->selector_toggle
,
503 on_selector_button_toggled
, plugin
);
504 g_signal_handlers_unblock_by_func (plugin
->priv
->resize_toggle
,
505 on_drag_resize_button_toggled
, plugin
);
508 /* Progress callbacks */
510 glade_plugin_parse_began (GladeProject
*project
,
513 AnjutaStatus
*status
= anjuta_shell_get_status (ANJUTA_PLUGIN(plugin
)->shell
,
515 anjuta_status_busy_push (status
);
516 plugin
->priv
->add_ticks
= TRUE
;
520 glade_plugin_parse_finished (GladeProject
*project
,
521 AnjutaPlugin
*plugin
)
523 AnjutaStatus
*status
= anjuta_shell_get_status (ANJUTA_PLUGIN(plugin
)->shell
,
525 GladePlugin
* gplugin
= ANJUTA_PLUGIN_GLADE (plugin
);
526 anjuta_status_busy_pop (status
);
528 glade_inspector_set_project (GLADE_INSPECTOR (gplugin
->priv
->inspector
), project
);
532 glade_plugin_load_progress (GladeProject
*project
,
535 AnjutaPlugin
*plugin
)
537 GladePlugin
*glade_plugin
= ANJUTA_PLUGIN_GLADE (plugin
);
538 AnjutaStatus
*status
= anjuta_shell_get_status (plugin
->shell
,
542 static GdkPixbuf
* icon
= NULL
;
546 icon
= gtk_icon_theme_load_icon (gtk_icon_theme_get_default(),
548 GTK_ICON_SIZE_BUTTON
,
553 if (glade_plugin
->priv
->add_ticks
)
555 glade_plugin
->priv
->add_ticks
= FALSE
;
556 anjuta_status_progress_add_ticks (status
, total_ticks
);
559 project_name
= glade_project_get_name (project
);
560 text
= g_strdup_printf ("Loading %s…", project_name
);
561 anjuta_status_progress_tick (status
,
565 g_free (project_name
);
569 create_selector_tool_button ()
576 g_build_filename (glade_app_get_pixmaps_dir (), "selector.png", NULL
);
577 image
= gtk_image_new_from_file (image_path
);
580 button
= gtk_toggle_button_new ();
581 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
583 gtk_button_set_image (GTK_BUTTON (button
), image
);
585 gtk_widget_set_tooltip_text (button
,
586 _("Select widgets in the workspace"));
588 gtk_widget_show (button
);
589 gtk_widget_show (image
);
595 create_drag_resize_tool_button ()
602 g_build_filename (glade_app_get_pixmaps_dir (), "drag-resize.png", NULL
);
603 image
= gtk_image_new_from_file (image_path
);
606 button
= gtk_toggle_button_new ();
607 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button
), TRUE
);
609 gtk_button_set_image (GTK_BUTTON (button
), image
);
611 gtk_widget_set_tooltip_text (button
,
612 _("Drag and resize widgets in the workspace"));
614 gtk_widget_show (button
);
615 gtk_widget_show (image
);
621 activate_plugin (AnjutaPlugin
*plugin
)
623 GladePlugin
*glade_plugin
;
624 GladePluginPriv
*priv
;
625 AnjutaStatus
* status
;
626 GtkWidget
* button_box
;
628 DEBUG_PRINT ("%s", "GladePlugin: Activating Glade plugin…");
630 glade_plugin
= ANJUTA_PLUGIN_GLADE (plugin
);
632 status
= anjuta_shell_get_status (plugin
->shell
, NULL
);
633 priv
= glade_plugin
->priv
;
635 register_stock_icons (plugin
);
637 anjuta_status_busy_push (status
);
638 anjuta_status_set (status
, "%s", _("Loading Glade…"));
640 priv
->app
= glade_app_get ();
643 priv
->app
= glade_app_new ();
646 glade_app_set_window (GTK_WIDGET (ANJUTA_PLUGIN(plugin
)->shell
));
648 priv
->inspector
= glade_inspector_new ();
650 g_signal_connect (priv
->inspector
, "item-activated",
651 G_CALLBACK (inspector_item_activated_cb
),
654 priv
->paned
= gtk_paned_new (GTK_ORIENTATION_VERTICAL
);
656 priv
->editor
= GTK_WIDGET(glade_editor_new());
658 priv
->palette
= glade_palette_new();
659 priv
->palette_box
= gtk_vbox_new (FALSE
, 5);
660 priv
->selector_toggle
= create_selector_tool_button ();
661 priv
->resize_toggle
= create_drag_resize_tool_button ();
662 button_box
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 0);
663 gtk_box_pack_start (GTK_BOX (button_box
),
664 priv
->selector_toggle
,
666 gtk_box_pack_start (GTK_BOX (button_box
),
669 gtk_box_pack_start (GTK_BOX (priv
->palette_box
),
672 gtk_box_pack_start (GTK_BOX (priv
->palette_box
),
677 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv
->selector_toggle
),
679 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv
->resize_toggle
),
682 g_signal_connect (G_OBJECT (priv
->selector_toggle
), "toggled",
683 G_CALLBACK (on_selector_button_toggled
), plugin
);
684 g_signal_connect (G_OBJECT (priv
->resize_toggle
), "toggled",
685 G_CALLBACK (on_drag_resize_button_toggled
), plugin
);
688 glade_palette_set_show_selector_button (GLADE_PALETTE (priv
->palette
),
691 gtk_paned_add1 (GTK_PANED(priv
->paned
), priv
->inspector
);
692 gtk_paned_add2 (GTK_PANED(priv
->paned
), priv
->editor
);
694 gtk_widget_show_all (priv
->paned
);
696 anjuta_status_busy_pop (status
);
698 g_signal_connect(plugin
->shell
, "destroy",
699 G_CALLBACK(on_shell_destroy
), plugin
);
701 g_signal_connect(priv
->app
, "doc-search",
702 G_CALLBACK(on_api_help
), plugin
);
704 g_signal_connect(priv
->app
, "signal-editor-created",
705 G_CALLBACK(on_signal_editor_created
), plugin
);
707 gtk_widget_show (priv
->palette
);
708 gtk_widget_show (priv
->editor
);
709 gtk_widget_show (priv
->inspector
);
712 anjuta_shell_add_widget (anjuta_plugin_get_shell (ANJUTA_PLUGIN (plugin
)),
714 "AnjutaGladeTree", _("Widgets"),
715 "glade-plugin-widgets",
716 ANJUTA_SHELL_PLACEMENT_RIGHT
, NULL
);
717 anjuta_shell_add_widget (anjuta_plugin_get_shell (ANJUTA_PLUGIN (plugin
)),
719 "AnjutaGladePalette", _("Palette"),
720 "glade-plugin-palette",
721 ANJUTA_SHELL_PLACEMENT_LEFT
, NULL
);
722 /* Connect to save session */
723 g_signal_connect (G_OBJECT (plugin
->shell
), "save_session",
724 G_CALLBACK (on_session_save
), plugin
);
726 /* Watch documents */
727 glade_plugin
->priv
->editor_watch_id
=
728 anjuta_plugin_add_watch (plugin
, IANJUTA_DOCUMENT_MANAGER_CURRENT_DOCUMENT
,
729 value_added_current_editor
,
730 value_removed_current_editor
, NULL
);
736 deactivate_plugin (AnjutaPlugin
*plugin
)
738 GladePluginPriv
*priv
;
740 priv
= ANJUTA_PLUGIN_GLADE (plugin
)->priv
;
742 DEBUG_PRINT ("%s", "GladePlugin: Dectivating Glade plugin…");
744 if (glade_app_get_projects ())
746 /* Cannot deactivate plugin if there are still files open */
751 /* Disconnect signals */
752 g_signal_handlers_disconnect_by_func (plugin
->shell
,
753 G_CALLBACK (on_shell_destroy
),
756 g_signal_handlers_disconnect_by_func (plugin
->shell
,
757 G_CALLBACK (on_session_save
), plugin
);
759 g_signal_handlers_disconnect_by_func (priv
->app
,
760 G_CALLBACK(on_api_help
), plugin
);
763 anjuta_shell_remove_widget (anjuta_plugin_get_shell (plugin
),
766 anjuta_shell_remove_widget (anjuta_plugin_get_shell (plugin
),
771 priv
->action_group
= NULL
;
779 glade_plugin_dispose (GObject
*obj
)
781 /* GladePlugin *plugin = ANJUTA_PLUGIN_GLADE (obj); */
783 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
787 glade_plugin_finalize (GObject
*obj
)
789 GladePlugin
*plugin
= ANJUTA_PLUGIN_GLADE (obj
);
790 g_free (plugin
->priv
);
791 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
795 glade_plugin_instance_init (GObject
*obj
)
797 GladePluginPriv
*priv
;
798 GladePlugin
*plugin
= ANJUTA_PLUGIN_GLADE (obj
);
800 plugin
->priv
= (GladePluginPriv
*) g_new0 (GladePluginPriv
, 1);
802 priv
->destroying
= FALSE
;
803 priv
->file_count
= 0;
804 priv
->add_ticks
= FALSE
;
806 DEBUG_PRINT ("%s", "Intializing Glade plugin");
810 glade_plugin_class_init (GObjectClass
*klass
)
812 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
814 parent_class
= g_type_class_peek_parent (klass
);
816 plugin_class
->activate
= activate_plugin
;
817 plugin_class
->deactivate
= deactivate_plugin
;
818 klass
->dispose
= glade_plugin_dispose
;
819 klass
->finalize
= glade_plugin_finalize
;
823 ifile_open (IAnjutaFile
*ifile
, GFile
* file
, GError
**err
)
825 AnjutaPlugin
* plugin
= ANJUTA_PLUGIN (ifile
);
826 GladePluginPriv
*priv
;
827 GladeProject
*project
;
829 IAnjutaDocumentManager
* docman
;
830 GList
* docwids
, *node
;
832 g_return_if_fail (file
!= NULL
);
834 priv
= ANJUTA_PLUGIN_GLADE (ifile
)->priv
;
836 filename
= g_file_get_path (file
);
839 gchar
* uri
= g_file_get_parse_name(file
);
840 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
841 _("Not local file: %s"), uri
);
842 if (priv
->file_count
<= 0)
843 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
849 docman
= anjuta_shell_get_interface(ANJUTA_PLUGIN(ifile
)->shell
, IAnjutaDocumentManager
,
851 docwids
= ianjuta_document_manager_get_doc_widgets (docman
, NULL
);
854 for (node
= docwids
; node
!= NULL
; node
= g_list_next (node
))
856 if (ANJUTA_IS_DESIGN_DOCUMENT (node
->data
))
859 cur_file
= ianjuta_file_get_file (IANJUTA_FILE (node
->data
), NULL
);
862 if (g_file_equal (file
, cur_file
))
864 ianjuta_document_manager_set_current_document (docman
,
865 IANJUTA_DOCUMENT (node
->data
), NULL
);
866 g_object_unref (file
);
869 g_object_unref (file
);
873 g_list_free (docwids
);
876 project
= glade_project_new ();
877 g_signal_connect (project
, "parse-began",
878 G_CALLBACK (glade_plugin_parse_began
), plugin
);
879 g_signal_connect (project
, "parse-finished",
880 G_CALLBACK (glade_plugin_parse_finished
), plugin
);
881 g_signal_connect (project
, "load-progress",
882 G_CALLBACK (glade_plugin_load_progress
), plugin
);
883 if (!glade_project_load_from_file (project
, filename
))
885 gchar
* name
= g_file_get_parse_name (file
);
886 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
887 _("Could not open %s"), name
);
888 if (priv
->file_count
<= 0)
889 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
896 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (ifile
), project
);
898 anjuta_shell_present_widget (ANJUTA_PLUGIN (ifile
)->shell
, priv
->paned
, NULL
);
902 ifile_get_file (IAnjutaFile
* ifile
, GError
** e
)
904 GladePlugin
* plugin
= (GladePlugin
*) ifile
;
906 glade_project_get_path(glade_inspector_get_project(GLADE_INSPECTOR (plugin
->priv
->inspector
)));
907 GFile
* file
= g_file_new_for_path (path
);
912 ifile_iface_init(IAnjutaFileIface
*iface
)
914 iface
->open
= ifile_open
;
915 iface
->get_file
= ifile_get_file
;
919 iwizard_activate (IAnjutaWizard
*iwizard
, GError
**err
)
921 GladePluginPriv
*priv
;
922 GladeProject
*project
;
924 priv
= ANJUTA_PLUGIN_GLADE (iwizard
)->priv
;
926 project
= glade_project_new ();
929 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (iwizard
)->shell
),
930 _("Could not create a new glade project."));
933 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (iwizard
), project
);
934 anjuta_shell_present_widget (ANJUTA_PLUGIN (iwizard
)->shell
,
935 priv
->palette_box
, NULL
);
939 iwizard_iface_init(IAnjutaWizardIface
*iface
)
941 iface
->activate
= iwizard_activate
;
944 ANJUTA_PLUGIN_BEGIN (GladePlugin
, glade_plugin
);
945 ANJUTA_PLUGIN_ADD_INTERFACE (ifile
, IANJUTA_TYPE_FILE
);
946 ANJUTA_PLUGIN_ADD_INTERFACE (iwizard
, IANJUTA_TYPE_WIZARD
);
949 ANJUTA_SIMPLE_PLUGIN (GladePlugin
, glade_plugin
);