1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) 2004 Naba Kumar <naba@gnome.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc., 59
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <libanjuta/anjuta-shell.h>
25 #include <libanjuta/anjuta-utils.h>
26 #include <libanjuta/anjuta-debug.h>
29 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-shell.ui"
31 #define PREF_SCHEMA "org.gnome.anjuta"
34 shutdown (AnjutaTestShell
*shell
)
36 anjuta_plugin_manager_unload_all_plugins (shell
->plugin_manager
);
41 on_delete_event (GtkWidget
*window
, GdkEvent
*event
, gpointer data
)
43 shutdown (ANJUTA_TEST_SHELL (window
));
48 on_exit_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
54 on_preferences_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
56 GtkWidget
*preferences_dialog
;
58 preferences_dialog
= anjuta_preferences_get_dialog (shell
->preferences
);
60 g_signal_connect_swapped (G_OBJECT (preferences_dialog
),
62 G_CALLBACK (gtk_widget_destroy
),
65 gtk_window_set_transient_for (GTK_WINDOW (preferences_dialog
),
68 gtk_widget_show (preferences_dialog
);
72 on_shortcuts_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
74 GtkWidget
*win
, *accel_editor
;
76 accel_editor
= anjuta_ui_get_accel_editor (ANJUTA_UI (shell
->ui
));
77 win
= gtk_dialog_new_with_buttons (_("Anjuta Plugins"), GTK_WINDOW (shell
),
78 GTK_DIALOG_DESTROY_WITH_PARENT
,
79 GTK_STOCK_CLOSE
, GTK_STOCK_CANCEL
, NULL
);
80 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG(win
))), accel_editor
, TRUE
, TRUE
, 0);
81 gtk_window_set_default_size (GTK_WINDOW (win
), 500, 400);
82 gtk_dialog_run (GTK_DIALOG (win
));
83 gtk_widget_destroy (win
);
86 static GtkActionEntry action_entries
[] = {
87 { "ActionMenuFile", NULL
, N_("_File")},
88 { "ActionMenuEdit", NULL
, N_("_Edit")},
89 { "ActionMenuView", NULL
, N_("_View")},
90 { "ActionMenuSettings", NULL
, N_("_Settings")},
91 { "ActionMenuHelp", NULL
, N_("_Help")},
97 N_("Quit Anjuta Test Shell"),
98 G_CALLBACK (on_exit_activate
)
101 "ActionSettingsPreferences",
102 GTK_STOCK_PROPERTIES
,
103 N_("_Preferences..."),
106 G_CALLBACK (on_preferences_activate
)
109 "ActionSettingsShortcuts",
111 N_("C_ustomize shortcuts"),
113 N_("Customize shortcuts associated with menu items"),
114 G_CALLBACK (on_shortcuts_activate
)
118 static gpointer parent_class
= NULL
;
121 on_add_merge_widget (GtkUIManager
*merge
, GtkWidget
*widget
,
122 GtkWidget
*ui_container
)
124 DEBUG_PRINT ("%s", "Adding UI item...");
125 gtk_box_pack_start (GTK_BOX ((ANJUTA_TEST_SHELL (ui_container
))->box
),
126 widget
, FALSE
, FALSE
, 0);
130 anjuta_test_shell_new (void)
132 AnjutaTestShell
*shell
;
134 shell
= ANJUTA_TEST_SHELL (g_object_new (ANJUTA_TYPE_TEST_SHELL
,
135 "title", "Anjuta Shell",
137 return GTK_WIDGET (shell
);
141 anjuta_test_shell_instance_init (AnjutaTestShell
*shell
)
144 GList
*plugins_dirs
= NULL
;
146 shell
->values
= g_hash_table_new (g_str_hash
, g_str_equal
);
147 shell
->widgets
= g_hash_table_new (g_str_hash
, g_str_equal
);
149 shell
->box
= gtk_vbox_new (FALSE
, 0);
150 gtk_widget_show (shell
->box
);
151 gtk_container_add (GTK_CONTAINER (shell
), shell
->box
);
154 shell
->status
= ANJUTA_STATUS (anjuta_status_new ());
155 gtk_widget_show (GTK_WIDGET (shell
->status
));
156 gtk_box_pack_end (GTK_BOX (shell
->box
), GTK_WIDGET (shell
->status
),
159 /* Initialize plugins */
160 plugins_dirs
= g_list_prepend (plugins_dirs
, PACKAGE_PLUGIN_DIR
);
161 shell
->plugin_manager
= anjuta_plugin_manager_new (G_OBJECT (shell
),
164 g_list_free (plugins_dirs
);
166 plugins
= anjuta_plugin_manager_get_plugins_page (shell
->plugin_manager
);
167 gtk_box_pack_end (GTK_BOX (shell
->box
), plugins
, TRUE
, TRUE
, 0);
169 /* Preferencesnces */
170 shell
->preferences
= ANJUTA_PREFERENCES (anjuta_preferences_new (shell
->plugin_manager
, PREF_SCHEMA
));
173 shell
->ui
= anjuta_ui_new ();
174 gtk_window_add_accel_group (GTK_WINDOW (shell
),
175 anjuta_ui_get_accel_group (shell
->ui
));
176 g_signal_connect (G_OBJECT (shell
->ui
),
177 "add_widget", G_CALLBACK (on_add_merge_widget
),
180 /*gtk_window_add_accel_group (GTK_WINDOW (shell),
181 anjuta_ui_get_accel_group (shell->ui));*/
182 /* Register actions */
183 anjuta_ui_add_action_group_entries (shell
->ui
, "ActionGroupTestShell",
184 _("Test shell action group"),
186 G_N_ELEMENTS (action_entries
),
187 GETTEXT_PACKAGE
, TRUE
, shell
);
189 shell
->merge_id
= anjuta_ui_merge (shell
->ui
, UI_FILE
);
191 gtk_window_set_default_size (GTK_WINDOW (shell
), 300, 400);
195 anjuta_test_shell_add_value (AnjutaShell
*shell
,
201 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
203 anjuta_shell_remove_value (shell
, name
, error
);
205 copy
= g_new0 (GValue
, 1);
206 g_value_init (copy
, value
->g_type
);
207 g_value_copy (value
, copy
);
209 g_hash_table_insert (window
->values
, g_strdup (name
), copy
);
210 g_signal_emit_by_name (shell
, "value_added", name
, copy
);
214 anjuta_test_shell_get_value (AnjutaShell
*shell
,
220 AnjutaTestShell
*s
= ANJUTA_TEST_SHELL (shell
);
222 val
= g_hash_table_lookup (s
->values
, name
);
225 if (!value
->g_type
) {
226 g_value_init (value
, val
->g_type
);
228 g_value_copy (val
, value
);
231 *error
= g_error_new (ANJUTA_SHELL_ERROR
,
232 ANJUTA_SHELL_ERROR_DOESNT_EXIST
,
233 _("Value doesn't exist"));
239 anjuta_test_shell_iconify_dockable_widget (AnjutaShell
*shell
,
243 /* Not implemented. */
248 anjuta_test_shell_hide_dockable_widget (AnjutaShell
*shell
,
252 /* Not implemented. */
257 anjuta_test_shell_show_dockable_widget (AnjutaShell
*shell
,
261 /* Not implemented. */
266 anjuta_test_shell_maximize_widget (AnjutaShell
*shell
,
267 const char *widget_name
,
270 /* Not implemented. */
275 anjuta_test_shell_unmaximize (AnjutaShell
*shell
,
278 /* Not implemented. */
283 anjuta_test_shell_add_widget (AnjutaShell
*shell
,
287 const char *stock_id
,
288 AnjutaShellPlacement placement
,
292 GtkWidget
*client_win
;
293 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
295 g_return_if_fail (w
!= NULL
);
297 // anjuta_shell_add (shell, name, G_TYPE_FROM_INSTANCE (w), w, NULL);
299 g_hash_table_insert (window
->widgets
, g_strdup (name
), w
);
300 client_win
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
301 gtk_container_add (GTK_CONTAINER (client_win
), w
);
302 gtk_widget_show_all (client_win
);
306 remove_from_widgets_hash (gpointer key
, gpointer value
, gpointer data
)
309 // AnjutaShell *shell;
311 // shell = g_object_get_data (G_OBJECT (value), "__temp_shell__");
312 // anjuta_shell_remove_value (shell, key, NULL);
320 anjuta_test_shell_remove_widget (AnjutaShell
*shell
,
325 GtkWidget
*client_win
;
326 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
327 g_return_if_fail (w
!= NULL
);
329 // old_size = g_hash_table_size (window->widgets);
330 // g_object_set_data (G_OBJECT (w), "__temp_shell__", shell);
331 g_hash_table_foreach_steal (window
->widgets
, remove_from_widgets_hash
, w
);
332 // if (old_size != g_hash_table_size (window->widgets))
334 client_win
= gtk_widget_get_toplevel (w
);
335 gtk_container_remove (GTK_CONTAINER (client_win
), w
);
336 gtk_widget_destroy (client_win
);
340 static AnjutaPluginManager
*
341 anjuta_test_shell_get_plugin_manager (AnjutaShell
*shell
, GError
**error
)
343 return ANJUTA_TEST_SHELL(shell
)->plugin_manager
;
347 anjuta_test_shell_present_widget (AnjutaShell
*shell
,
351 GtkWidget
*client_win
;
352 // AnjutaTestShell *window = ANJUTA_TEST_SHELL (shell);
354 g_return_if_fail (w
!= NULL
);
356 client_win
= gtk_widget_get_toplevel (w
);
357 gtk_window_present (GTK_WINDOW (client_win
));
361 anjuta_test_shell_remove_value (AnjutaShell
*shell
,
368 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
370 if (g_hash_table_lookup_extended (window
->widgets
, name
,
371 (gpointer
*)&key
, (gpointer
*)&w
)) {
372 GtkWidget
*client_win
;
373 client_win
= gtk_widget_get_toplevel (w
);
374 gtk_container_remove (GTK_CONTAINER (client_win
), w
);
375 gtk_widget_destroy (client_win
);
379 if (g_hash_table_lookup_extended (window
->values
, name
,
380 (gpointer
*)&key
, (gpointer
*)&value
)) {
381 g_hash_table_remove (window
->values
, name
);
382 g_signal_emit_by_name (window
, "value_removed", name
);
383 g_value_unset (value
);
389 anjuta_test_shell_get_object (AnjutaShell
*shell
, const char *iface_name
,
392 return anjuta_plugin_manager_get_plugin (ANJUTA_TEST_SHELL (shell
)->plugin_manager
,
397 anjuta_test_shell_get_status (AnjutaShell
*shell
, GError
**error
)
399 return ANJUTA_TEST_SHELL (shell
)->status
;
403 anjuta_test_shell_get_ui (AnjutaShell
*shell
, GError
**error
)
405 return ANJUTA_TEST_SHELL (shell
)->ui
;
408 static AnjutaPreferences
*
409 anjuta_test_shell_get_preferences (AnjutaShell
*shell
, GError
**error
)
411 return ANJUTA_TEST_SHELL (shell
)->preferences
;
415 anjuta_test_shell_dispose (GObject
*widget
)
418 G_OBJECT_CLASS (parent_class
)->dispose (widget
);
422 anjuta_test_shell_finalize (GObject
*widget
)
424 AnjutaTestShell
*shell
= ANJUTA_TEST_SHELL (widget
);
426 g_hash_table_destroy (shell
->values
);
427 g_hash_table_destroy (shell
->widgets
);
429 G_OBJECT_CLASS (parent_class
)->finalize (widget
);
433 anjuta_test_shell_class_init (AnjutaTestShellClass
*class)
435 GObjectClass
*object_class
;
436 GtkWidgetClass
*widget_class
;
438 parent_class
= g_type_class_peek_parent (class);
439 object_class
= (GObjectClass
*) class;
440 widget_class
= (GtkWidgetClass
*) class;
441 object_class
->dispose
= anjuta_test_shell_dispose
;
442 object_class
->finalize
= anjuta_test_shell_finalize
;
446 anjuta_shell_iface_init (AnjutaShellIface
*iface
)
448 iface
->add_widget_full
= anjuta_test_shell_add_widget
;
449 iface
->remove_widget
= anjuta_test_shell_remove_widget
;
450 iface
->present_widget
= anjuta_test_shell_present_widget
;
451 iface
->iconify_dockable_widget
= anjuta_test_shell_iconify_dockable_widget
;
452 iface
->hide_dockable_widget
= anjuta_test_shell_hide_dockable_widget
;
453 iface
->show_dockable_widget
= anjuta_test_shell_show_dockable_widget
;
454 iface
->maximize_widget
= anjuta_test_shell_maximize_widget
;
455 iface
->unmaximize
= anjuta_test_shell_unmaximize
;
456 iface
->add_value
= anjuta_test_shell_add_value
;
457 iface
->get_value
= anjuta_test_shell_get_value
;
458 iface
->remove_value
= anjuta_test_shell_remove_value
;
459 iface
->get_object
= anjuta_test_shell_get_object
;
460 iface
->get_status
= anjuta_test_shell_get_status
;
461 iface
->get_ui
= anjuta_test_shell_get_ui
;
462 iface
->get_preferences
= anjuta_test_shell_get_preferences
;
463 iface
->get_plugin_manager
= anjuta_test_shell_get_plugin_manager
;
466 ANJUTA_TYPE_BEGIN(AnjutaTestShell
, anjuta_test_shell
, GTK_TYPE_WINDOW
);
467 ANJUTA_TYPE_ADD_INTERFACE(anjuta_shell
, ANJUTA_TYPE_SHELL
);
471 main (int argc
, char *argv
[])
475 bindtextdomain (PACKAGE
, PACKAGE_LOCALE_DIR
);
476 bind_textdomain_codeset(PACKAGE
, "UTF-8");
477 textdomain (PACKAGE
);
481 gtk_init (&argc
, &argv
);
482 g_set_application_name (_("Anjuta Shell Test"));
483 gtk_window_set_default_icon_name ("anjuta-shell");
484 gtk_window_set_auto_startup_notification(FALSE
);
486 shell
= anjuta_test_shell_new ();
487 g_signal_connect (G_OBJECT (shell
), "delete-event",
488 G_CALLBACK (on_delete_event
), NULL
);
489 gtk_widget_show_all (GTK_WIDGET (shell
));