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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <libgnomevfs/gnome-vfs-utils.h>
24 #include <libanjuta/anjuta-shell.h>
25 #include <libanjuta/anjuta-debug.h>
26 #include <libanjuta/interfaces/ianjuta-file.h>
27 #include <libanjuta/interfaces/ianjuta-file-savable.h>
28 #include <libanjuta/interfaces/ianjuta-wizard.h>
29 #include <libanjuta/interfaces/ianjuta-help.h>
30 #include <libanjuta/interfaces/ianjuta-document-manager.h>
33 #include "anjuta-design-document.h"
35 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-glade.ui"
37 static gpointer parent_class
;
39 /* This is variable required from libdevhelp */
40 gchar
*geometry
= NULL
;
42 struct _GladePluginPriv
45 GtkActionGroup
*action_group
;
49 GtkWidget
*projects_combo
;
61 value_added_current_editor (AnjutaPlugin
*plugin
, const char *name
,
62 const GValue
*value
, gpointer data
)
64 GladePlugin
* glade_plugin
= ANJUTA_PLUGIN_GLADE(plugin
);
66 editor
= g_value_get_object (value
);
67 if (ANJUTA_IS_DESIGN_DOCUMENT(editor
))
69 AnjutaDesignDocument
* view
= ANJUTA_DESIGN_DOCUMENT(editor
);
70 GladeProject
* project
= glade_design_view_get_project(GLADE_DESIGN_VIEW(view
));
71 /* Update current project */
74 gtk_combo_box_get_model (GTK_COMBO_BOX (glade_plugin
->priv
->projects_combo
));
75 if (gtk_tree_model_get_iter_first (model
, &iter
))
79 GladeProject
*cur_project
;
80 gtk_tree_model_get (model
, &iter
, PROJECT_COL
, &cur_project
, -1);
81 if (project
== cur_project
)
83 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (glade_plugin
->priv
->projects_combo
), &iter
);
84 glade_app_set_project(project
);
88 while (gtk_tree_model_iter_next (model
, &iter
));
94 value_removed_current_editor (AnjutaPlugin
*plugin
,
95 const char *name
, gpointer data
)
101 glade_update_ui (GladeApp
*app
, GladePlugin
*plugin
)
105 IAnjutaDocument
* doc
;
106 IAnjutaDocumentManager
* docman
=
107 anjuta_shell_get_interface(ANJUTA_PLUGIN(plugin
)->shell
,
108 IAnjutaDocumentManager
, NULL
);
110 /* Update current project */
111 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (plugin
->priv
->projects_combo
));
112 if (gtk_tree_model_get_iter_first (model
, &iter
))
116 GladeProject
*project
;
117 gtk_tree_model_get (model
, &iter
, PROJECT_COL
, &project
, -1);
118 if (project
== glade_app_get_project ())
120 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (plugin
->priv
->projects_combo
), &iter
);
124 while (gtk_tree_model_iter_next (model
, &iter
));
126 /* Emit IAnjutaDocument signal */
127 doc
= ianjuta_document_manager_get_current_document(docman
, NULL
);
128 if (doc
&& ANJUTA_IS_DESIGN_DOCUMENT(doc
))
130 gboolean dirty
= ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE(doc
), NULL
);
131 g_signal_emit_by_name (G_OBJECT(doc
), "update_ui");
132 g_signal_emit_by_name (G_OBJECT(doc
), "save_point", !dirty
);
138 on_api_help (GladeEditor
* editor
,
144 gchar
*book_comm
= NULL
, *page_comm
= NULL
;
147 AnjutaPlugin
* aplugin
= ANJUTA_PLUGIN(plugin
);
148 AnjutaShell
* shell
= aplugin
->shell
;
151 help
= anjuta_shell_get_interface(shell
, IAnjutaHelp
, NULL
);
153 /* No API Help Plugin */
157 if (book
) book_comm
= g_strdup_printf ("book:%s ", book
);
158 if (page
) page_comm
= g_strdup_printf ("page:%s ", page
);
160 string
= g_strdup_printf ("%s%s%s",
161 book_comm
? book_comm
: "",
162 page_comm
? page_comm
: "",
163 search
? search
: "");
165 ianjuta_help_search(help
, string
, NULL
);
171 glade_do_close (GladePlugin
*plugin
, GladeProject
*project
)
173 glade_app_remove_project (project
);
177 on_close_activated (GtkWidget
* document
, GladePlugin
*plugin
)
179 GladeProject
*project
;
183 DEBUG_PRINT(__FUNCTION__
);
185 if (plugin
->priv
->destroying
)
190 project
= glade_design_view_get_project(GLADE_DESIGN_VIEW(document
));
197 /* Remove project from our list */
198 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (plugin
->priv
->projects_combo
));
199 if (gtk_tree_model_get_iter_first (model
, &iter
))
203 GladeProject
*project_node
;
205 gtk_tree_model_get (model
, &iter
, PROJECT_COL
, &project_node
, -1);
206 if (project
== project_node
)
208 gtk_list_store_remove (GTK_LIST_STORE (model
), &iter
);
212 while (gtk_tree_model_iter_next (model
, &iter
));
214 glade_do_close (plugin
, project
);
216 if (gtk_tree_model_iter_n_children (model
, NULL
) <= 0)
217 anjuta_plugin_deactivate (ANJUTA_PLUGIN (plugin
));
219 DEBUG_PRINT(__FUNCTION__
);
223 on_shell_destroy (AnjutaShell
* shell
, GladePlugin
*glade_plugin
)
225 glade_plugin
->priv
->destroying
= TRUE
;
229 on_glade_project_changed (GtkComboBox
*combo
, GladePlugin
*plugin
)
233 IAnjutaDocumentManager
* docman
=
234 anjuta_shell_get_interface(ANJUTA_PLUGIN(plugin
)->shell
,
235 IAnjutaDocumentManager
, NULL
);
237 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (plugin
->priv
->projects_combo
));
238 if (gtk_combo_box_get_active_iter (combo
, &iter
))
240 GladeProject
*project
;
242 GtkWidget
*design_view
;
243 gtk_tree_model_get (model
, &iter
, PROJECT_COL
, &project
, -1);
244 glade_app_set_project (project
);
246 design_view
= g_object_get_data (G_OBJECT (project
), "design_view");
247 ianjuta_document_manager_set_current_document(docman
, IANJUTA_DOCUMENT(design_view
), NULL
);
249 # if (GLADEUI_VERSION >= 330)
250 glade_inspector_set_project (GLADE_INSPECTOR (plugin
->priv
->inspector
), project
);
257 register_stock_icons (AnjutaPlugin
*plugin
)
259 static gboolean registered
= FALSE
;
265 /* Register stock icons */
266 BEGIN_REGISTER_ICON (plugin
);
267 REGISTER_ICON (PACKAGE_PIXMAPS_DIR
"/anjuta-glade-plugin.png",
268 "glade-plugin-icon");
273 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
274 AnjutaSession
*session
, GladePlugin
*plugin
)
280 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
283 files
= anjuta_session_get_string_list (session
, "File Loader", "Files");
284 files
= g_list_reverse (files
);
286 model
= gtk_combo_box_get_model (GTK_COMBO_BOX (plugin
->priv
->projects_combo
));
287 if (gtk_tree_model_get_iter_first (model
, &iter
))
292 GladeProject
*project
;
293 gtk_tree_model_get (model
, &iter
, PROJECT_COL
, &project
, -1);
294 #if (GLADEUI_VERSION >= 330)
295 if (glade_project_get_path(project
))
300 #if (GLADEUI_VERSION >= 330)
301 uri
= gnome_vfs_get_uri_from_local_path
302 (glade_project_get_path(project
));
304 uri
= gnome_vfs_get_uri_from_local_path (project
->path
);
307 files
= g_list_prepend (files
, uri
);
308 /* URI is not freed here */
311 while (gtk_tree_model_iter_next (model
, &iter
));
313 files
= g_list_reverse (files
);
314 anjuta_session_set_string_list (session
, "File Loader", "Files", files
);
315 g_list_foreach (files
, (GFunc
)g_free
, NULL
);
320 glade_plugin_add_project (GladePlugin
*glade_plugin
, GladeProject
*project
)
323 GladePluginPriv
*priv
;
324 IAnjutaDocumentManager
* docman
=
325 anjuta_shell_get_interface(ANJUTA_PLUGIN(glade_plugin
)->shell
,
326 IAnjutaDocumentManager
, NULL
);
328 g_return_if_fail (GLADE_IS_PROJECT (project
));
330 priv
= glade_plugin
->priv
;
331 view
= anjuta_design_document_new(glade_plugin
, project
);
332 g_signal_connect(G_OBJECT(view
), "destroy", G_CALLBACK(on_close_activated
), glade_plugin
);
333 gtk_widget_show (view
);
334 g_object_set_data (G_OBJECT (project
), "design_view", view
);
335 glade_app_add_project (project
);
337 ianjuta_document_manager_add_document(docman
, IANJUTA_DOCUMENT(view
), NULL
);
340 #if (GLADEUI_VERSION >= 330)
342 inspector_item_activated_cb (GladeInspector
*inspector
,
343 AnjutaPlugin
*plugin
)
345 GList
*item
= glade_inspector_get_selected_items (inspector
);
346 g_assert (GLADE_IS_WIDGET (item
->data
) && (item
->next
== NULL
));
348 /* switch to this widget in the workspace */
349 glade_widget_show (GLADE_WIDGET (item
->data
));
356 activate_plugin (AnjutaPlugin
*plugin
)
359 GladePlugin
*glade_plugin
;
360 GladePluginPriv
*priv
;
361 // GtkAction *action;
363 GtkCellRenderer
*renderer
;
365 DEBUG_PRINT ("GladePlugin: Activating Glade plugin...");
367 glade_plugin
= ANJUTA_PLUGIN_GLADE (plugin
);
369 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
370 priv
= glade_plugin
->priv
;
372 register_stock_icons (plugin
);
376 priv
->gpw
= g_object_new(GLADE_TYPE_APP
, NULL
);
378 glade_app_set_window (GTK_WIDGET (ANJUTA_PLUGIN(plugin
)->shell
));
379 glade_app_set_transient_parent (GTK_WINDOW (ANJUTA_PLUGIN(plugin
)->shell
));
381 /* Create a view for us */
382 priv
->view_box
= gtk_vbox_new (FALSE
, 0);
383 store
= gtk_list_store_new (N_COLUMNS
, G_TYPE_STRING
,
384 G_TYPE_POINTER
, NULL
);
386 priv
->projects_combo
= gtk_combo_box_new ();
387 renderer
= gtk_cell_renderer_text_new ();
388 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv
->projects_combo
),
390 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv
->projects_combo
),
391 renderer
, "text", NAME_COL
, NULL
);
392 gtk_combo_box_set_model (GTK_COMBO_BOX (priv
->projects_combo
),
393 GTK_TREE_MODEL (store
));
394 g_object_unref (G_OBJECT (store
));
395 gtk_box_pack_start (GTK_BOX (priv
->view_box
), priv
->projects_combo
,
398 #if (GLADEUI_VERSION >= 330)
399 priv
->inspector
= glade_inspector_new ();
401 g_signal_connect (priv
->inspector
, "item-activated",
402 G_CALLBACK (inspector_item_activated_cb
),
405 priv
->inspector
= glade_project_view_new ();
408 #if (GLADEUI_VERSION < 330)
409 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv
->inspector
),
410 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
412 glade_app_add_project_view (GLADE_PROJECT_VIEW (priv
->inspector
));
414 gtk_box_pack_start (GTK_BOX (priv
->view_box
), GTK_WIDGET (priv
->inspector
),
417 gtk_widget_show_all (priv
->view_box
);
418 gtk_notebook_set_scrollable (GTK_NOTEBOOK (glade_app_get_editor ()->notebook
),
420 gtk_notebook_popup_enable (GTK_NOTEBOOK (glade_app_get_editor ()->notebook
));
423 g_signal_connect(G_OBJECT(plugin
->shell
), "destroy",
424 G_CALLBACK(on_shell_destroy
), plugin
);
426 g_signal_connect (G_OBJECT (priv
->projects_combo
), "changed",
427 G_CALLBACK (on_glade_project_changed
), plugin
);
428 g_signal_connect (G_OBJECT (priv
->gpw
), "update-ui",
429 G_CALLBACK (glade_update_ui
), plugin
);
431 g_signal_connect(G_OBJECT(glade_app_get_editor()), "gtk-doc-search",
432 G_CALLBACK(on_api_help
), plugin
);
434 /* FIXME: Glade doesn't want to die these widget, so
435 * hold a permenent refs on them
437 g_object_ref (glade_app_get_palette ());
438 g_object_ref (glade_app_get_editor ());
439 g_object_ref (priv
->view_box
);
441 gtk_widget_show (GTK_WIDGET (glade_app_get_palette ()));
442 gtk_widget_show (GTK_WIDGET (glade_app_get_editor ()));
445 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin
)->shell
,
446 GTK_WIDGET (priv
->view_box
),
447 "AnjutaGladeTree", _("Widgets"),
449 ANJUTA_SHELL_PLACEMENT_LEFT
, NULL
);
450 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin
)->shell
,
451 GTK_WIDGET (glade_app_get_palette ()),
452 "AnjutaGladePalette", _("Palette"),
454 ANJUTA_SHELL_PLACEMENT_LEFT
, NULL
);
455 anjuta_shell_add_widget (ANJUTA_PLUGIN (plugin
)->shell
,
456 GTK_WIDGET (glade_app_get_editor ()),
457 "AnjutaGladeEditor", _("Properties"),
459 ANJUTA_SHELL_PLACEMENT_CENTER
, NULL
);
460 /* Connect to save session */
461 g_signal_connect (G_OBJECT (plugin
->shell
), "save_session",
462 G_CALLBACK (on_session_save
), plugin
);
464 /* Watch documents */
465 glade_plugin
->priv
->editor_watch_id
=
466 anjuta_plugin_add_watch (plugin
, "document_manager_current_editor",
467 value_added_current_editor
,
468 value_removed_current_editor
, NULL
);
474 deactivate_plugin (AnjutaPlugin
*plugin
)
476 GladePluginPriv
*priv
;
478 priv
= ANJUTA_PLUGIN_GLADE (plugin
)->priv
;
480 DEBUG_PRINT ("GladePlugin: Dectivating Glade plugin...");
482 /* Disconnect signals */
483 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
484 G_CALLBACK (on_shell_destroy
),
487 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
488 G_CALLBACK (on_session_save
), plugin
);
490 g_signal_handlers_disconnect_by_func (G_OBJECT (priv
->projects_combo
),
491 G_CALLBACK (on_glade_project_changed
),
493 g_signal_handlers_disconnect_by_func (G_OBJECT (priv
->gpw
),
494 G_CALLBACK (glade_update_ui
),
497 g_signal_handlers_disconnect_by_func (G_OBJECT(glade_app_get_editor()),
498 G_CALLBACK(on_api_help
), plugin
);
501 anjuta_shell_remove_widget (plugin
->shell
,
502 GTK_WIDGET (glade_app_get_palette ()),
504 anjuta_shell_remove_widget (plugin
->shell
,
505 GTK_WIDGET (glade_app_get_editor ()),
507 anjuta_shell_remove_widget (plugin
->shell
,
508 GTK_WIDGET (priv
->view_box
),
510 /* FIXME: Don't destroy glade, since it doesn't want to */
511 /* g_object_unref (G_OBJECT (priv->gpw)); */
512 /* priv->gpw = NULL */
515 priv
->action_group
= NULL
;
522 glade_plugin_dispose (GObject
*obj
)
524 /* GladePlugin *plugin = ANJUTA_PLUGIN_GLADE (obj); */
526 /* FIXME: Glade widgets should be destroyed */
527 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
531 glade_plugin_finalize (GObject
*obj
)
533 GladePlugin
*plugin
= ANJUTA_PLUGIN_GLADE (obj
);
534 g_free (plugin
->priv
);
535 GNOME_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (obj
));
539 glade_plugin_instance_init (GObject
*obj
)
541 GladePluginPriv
*priv
;
542 GladePlugin
*plugin
= ANJUTA_PLUGIN_GLADE (obj
);
544 plugin
->priv
= (GladePluginPriv
*) g_new0 (GladePluginPriv
, 1);
546 priv
->destroying
= FALSE
;
548 DEBUG_PRINT ("Intializing Glade plugin");
552 glade_plugin_class_init (GObjectClass
*klass
)
554 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
556 parent_class
= g_type_class_peek_parent (klass
);
558 plugin_class
->activate
= activate_plugin
;
559 plugin_class
->deactivate
= deactivate_plugin
;
560 klass
->dispose
= glade_plugin_dispose
;
561 klass
->dispose
= glade_plugin_finalize
;
564 gchar
* glade_get_filename(GladePlugin
*plugin
)
566 #if (GLADEUI_VERSION >= 330)
567 return glade_project_get_name(glade_app_get_project());
569 GladeProject
* project
= glade_app_get_project();
571 return project
->name
;
578 ifile_open (IAnjutaFile
*ifile
, const gchar
*uri
, GError
**err
)
580 GladePluginPriv
*priv
;
581 GladeProject
*project
;
585 IAnjutaDocumentManager
* docman
;
589 g_return_if_fail (uri
!= NULL
);
591 priv
= ANJUTA_PLUGIN_GLADE (ifile
)->priv
;
593 filename
= gnome_vfs_get_local_path_from_uri (uri
);
596 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
597 _("Not local file: %s"), uri
);
601 docman
= anjuta_shell_get_interface(ANJUTA_PLUGIN(ifile
)->shell
, IAnjutaDocumentManager
,
603 docs
= ianjuta_document_manager_get_documents(docman
, NULL
);
604 for (cur_doc
= docs
; cur_doc
!= NULL
; cur_doc
= g_list_next(cur_doc
))
606 if (ANJUTA_IS_DESIGN_DOCUMENT(cur_doc
->data
))
609 cur_uri
= ianjuta_file_get_uri (IANJUTA_FILE (cur_doc
->data
), NULL
);
612 DEBUG_PRINT("%s = %s", uri
, cur_uri
);
613 if (g_str_equal (uri
, cur_uri
))
615 ianjuta_document_manager_set_current_document (docman
,
616 IANJUTA_DOCUMENT (cur_doc
->data
), NULL
);
625 #if (GLADEUI_VERSION >= 330)
626 project
= glade_project_load (filename
);
628 project
= glade_project_open (filename
);
633 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (ifile
)->shell
),
634 _("Could not open: %s"), uri
);
637 store
= GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (priv
->projects_combo
)));
638 gtk_list_store_append (store
, &iter
);
639 #if (GLADEUI_VERSION >= 330)
640 gtk_list_store_set (store
, &iter
, NAME_COL
, glade_project_get_name(project
),
641 PROJECT_COL
, project
, -1);
643 gtk_list_store_set (store
, &iter
, NAME_COL
, project
->name
,
644 PROJECT_COL
, project
, -1);
646 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (ifile
), project
);
647 anjuta_shell_present_widget (ANJUTA_PLUGIN (ifile
)->shell
, priv
->view_box
, NULL
);
651 ifile_get_uri (IAnjutaFile
* file
, GError
** e
)
653 #if (GLADEUI_VERSION >= 330)
654 const gchar
* path
= glade_project_get_path(glade_app_get_project());
656 return gnome_vfs_get_uri_from_local_path(path
);
660 GladeProject
* project
= glade_app_get_project();
661 if (project
&& project
->path
)
662 return project
->path
;
669 ifile_iface_init(IAnjutaFileIface
*iface
)
671 iface
->open
= ifile_open
;
672 iface
->get_uri
= ifile_get_uri
;
676 iwizard_activate (IAnjutaWizard
*iwizard
, GError
**err
)
678 GladePluginPriv
*priv
;
679 GladeProject
*project
;
683 priv
= ANJUTA_PLUGIN_GLADE (iwizard
)->priv
;
685 #if (GLADEUI_VERSION >= 330)
686 project
= glade_project_new ();
688 project
= glade_project_new (TRUE
);
692 anjuta_util_dialog_warning (GTK_WINDOW (ANJUTA_PLUGIN (iwizard
)->shell
),
693 _("Could not create a new glade project."));
696 store
= GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (priv
->projects_combo
)));
697 gtk_list_store_append (store
, &iter
);
698 #if (GLADEUI_VERSION >= 330)
699 gtk_list_store_set (store
, &iter
, NAME_COL
, glade_project_get_name(project
),
700 PROJECT_COL
, project
, -1);
702 gtk_list_store_set (store
, &iter
, NAME_COL
, project
->name
,
703 PROJECT_COL
, project
, -1);
705 glade_plugin_add_project (ANJUTA_PLUGIN_GLADE (iwizard
), project
);
706 anjuta_shell_present_widget (ANJUTA_PLUGIN (iwizard
)->shell
,
707 GTK_WIDGET (glade_app_get_palette ()), NULL
);
711 iwizard_iface_init(IAnjutaWizardIface
*iface
)
713 iface
->activate
= iwizard_activate
;
716 ANJUTA_PLUGIN_BEGIN (GladePlugin
, glade_plugin
);
717 ANJUTA_PLUGIN_ADD_INTERFACE (ifile
, IANJUTA_TYPE_FILE
);
718 ANJUTA_PLUGIN_ADD_INTERFACE (iwizard
, IANJUTA_TYPE_WIZARD
);
721 ANJUTA_SIMPLE_PLUGIN (GladePlugin
, glade_plugin
);