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"
32 shutdown (AnjutaTestShell
*shell
)
34 anjuta_plugin_manager_unload_all_plugins (shell
->plugin_manager
);
39 on_delete_event (GtkWidget
*window
, GdkEvent
*event
, gpointer data
)
41 shutdown (ANJUTA_TEST_SHELL (window
));
46 on_exit_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
52 on_preferences_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
54 GtkWidget
*preferences_dialog
;
56 preferences_dialog
= anjuta_preferences_get_dialog (shell
->preferences
);
58 g_signal_connect_swapped (G_OBJECT (preferences_dialog
),
60 G_CALLBACK (gtk_widget_destroy
),
63 gtk_window_set_transient_for (GTK_WINDOW (preferences_dialog
),
66 gtk_widget_show (preferences_dialog
);
70 on_shortcuts_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
72 GtkWidget
*win
, *accel_editor
;
74 accel_editor
= anjuta_ui_get_accel_editor (ANJUTA_UI (shell
->ui
));
75 win
= gtk_dialog_new_with_buttons (_("Anjuta Plugins"), GTK_WINDOW (shell
),
76 GTK_DIALOG_DESTROY_WITH_PARENT
,
77 GTK_STOCK_CLOSE
, GTK_STOCK_CANCEL
, NULL
);
78 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG(win
))), accel_editor
, TRUE
, TRUE
, 0);
79 gtk_window_set_default_size (GTK_WINDOW (win
), 500, 400);
80 gtk_dialog_run (GTK_DIALOG (win
));
81 gtk_widget_destroy (win
);
84 static GtkActionEntry action_entries
[] = {
85 { "ActionMenuFile", NULL
, N_("_File")},
86 { "ActionMenuEdit", NULL
, N_("_Edit")},
87 { "ActionMenuView", NULL
, N_("_View")},
88 { "ActionMenuSettings", NULL
, N_("_Settings")},
89 { "ActionMenuHelp", NULL
, N_("_Help")},
95 N_("Quit Anjuta Test Shell"),
96 G_CALLBACK (on_exit_activate
)
99 "ActionSettingsPreferences",
100 GTK_STOCK_PROPERTIES
,
101 N_("_Preferences..."),
104 G_CALLBACK (on_preferences_activate
)
107 "ActionSettingsShortcuts",
109 N_("C_ustomize shortcuts"),
111 N_("Customize shortcuts associated with menu items"),
112 G_CALLBACK (on_shortcuts_activate
)
116 static gpointer parent_class
= NULL
;
119 on_add_merge_widget (GtkUIManager
*merge
, GtkWidget
*widget
,
120 GtkWidget
*ui_container
)
122 DEBUG_PRINT ("%s", "Adding UI item...");
123 gtk_box_pack_start (GTK_BOX ((ANJUTA_TEST_SHELL (ui_container
))->box
),
124 widget
, FALSE
, FALSE
, 0);
128 anjuta_test_shell_new (void)
130 AnjutaTestShell
*shell
;
132 shell
= ANJUTA_TEST_SHELL (g_object_new (ANJUTA_TYPE_TEST_SHELL
,
133 "title", "Anjuta Shell",
135 return GTK_WIDGET (shell
);
139 anjuta_test_shell_instance_init (AnjutaTestShell
*shell
)
142 GList
*plugins_dirs
= NULL
;
144 shell
->values
= g_hash_table_new (g_str_hash
, g_str_equal
);
145 shell
->widgets
= g_hash_table_new (g_str_hash
, g_str_equal
);
147 shell
->box
= gtk_vbox_new (FALSE
, 0);
148 gtk_widget_show (shell
->box
);
149 gtk_container_add (GTK_CONTAINER (shell
), shell
->box
);
152 shell
->status
= ANJUTA_STATUS (anjuta_status_new ());
153 gtk_widget_show (GTK_WIDGET (shell
->status
));
154 gtk_box_pack_end (GTK_BOX (shell
->box
), GTK_WIDGET (shell
->status
),
157 /* Initialize plugins */
158 plugins_dirs
= g_list_prepend (plugins_dirs
, PACKAGE_PLUGIN_DIR
);
159 shell
->plugin_manager
= anjuta_plugin_manager_new (G_OBJECT (shell
),
162 g_list_free (plugins_dirs
);
164 plugins
= anjuta_plugin_manager_get_plugins_page (shell
->plugin_manager
);
165 gtk_box_pack_end (GTK_BOX (shell
->box
), plugins
, TRUE
, TRUE
, 0);
167 /* Preferencesnces */
168 shell
->preferences
= ANJUTA_PREFERENCES (anjuta_preferences_new (shell
->plugin_manager
));
171 shell
->ui
= anjuta_ui_new ();
172 gtk_window_add_accel_group (GTK_WINDOW (shell
),
173 anjuta_ui_get_accel_group (shell
->ui
));
174 g_signal_connect (G_OBJECT (shell
->ui
),
175 "add_widget", G_CALLBACK (on_add_merge_widget
),
178 /*gtk_window_add_accel_group (GTK_WINDOW (shell),
179 anjuta_ui_get_accel_group (shell->ui));*/
180 /* Register actions */
181 anjuta_ui_add_action_group_entries (shell
->ui
, "ActionGroupTestShell",
182 _("Test shell action group"),
184 G_N_ELEMENTS (action_entries
),
185 GETTEXT_PACKAGE
, TRUE
, shell
);
187 shell
->merge_id
= anjuta_ui_merge (shell
->ui
, UI_FILE
);
189 gtk_window_set_default_size (GTK_WINDOW (shell
), 300, 400);
193 anjuta_test_shell_add_value (AnjutaShell
*shell
,
199 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
201 anjuta_shell_remove_value (shell
, name
, error
);
203 copy
= g_new0 (GValue
, 1);
204 g_value_init (copy
, value
->g_type
);
205 g_value_copy (value
, copy
);
207 g_hash_table_insert (window
->values
, g_strdup (name
), copy
);
208 g_signal_emit_by_name (shell
, "value_added", name
, copy
);
212 anjuta_test_shell_get_value (AnjutaShell
*shell
,
218 AnjutaTestShell
*s
= ANJUTA_TEST_SHELL (shell
);
220 val
= g_hash_table_lookup (s
->values
, name
);
223 if (!value
->g_type
) {
224 g_value_init (value
, val
->g_type
);
226 g_value_copy (val
, value
);
229 *error
= g_error_new (ANJUTA_SHELL_ERROR
,
230 ANJUTA_SHELL_ERROR_DOESNT_EXIST
,
231 _("Value doesn't exist"));
237 anjuta_test_shell_iconify_dockable_widget (AnjutaShell
*shell
,
241 /* Not implemented. */
246 anjuta_test_shell_hide_dockable_widget (AnjutaShell
*shell
,
250 /* Not implemented. */
255 anjuta_test_shell_show_dockable_widget (AnjutaShell
*shell
,
259 /* Not implemented. */
264 anjuta_test_shell_maximize_widget (AnjutaShell
*shell
,
265 const char *widget_name
,
268 /* Not implemented. */
273 anjuta_test_shell_unmaximize (AnjutaShell
*shell
,
276 /* Not implemented. */
281 anjuta_test_shell_add_widget (AnjutaShell
*shell
,
285 const char *stock_id
,
286 AnjutaShellPlacement placement
,
290 GtkWidget
*client_win
;
291 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
293 g_return_if_fail (w
!= NULL
);
295 // anjuta_shell_add (shell, name, G_TYPE_FROM_INSTANCE (w), w, NULL);
297 g_hash_table_insert (window
->widgets
, g_strdup (name
), w
);
298 client_win
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
299 gtk_container_add (GTK_CONTAINER (client_win
), w
);
300 gtk_widget_show_all (client_win
);
304 remove_from_widgets_hash (gpointer key
, gpointer value
, gpointer data
)
307 // AnjutaShell *shell;
309 // shell = g_object_get_data (G_OBJECT (value), "__temp_shell__");
310 // anjuta_shell_remove_value (shell, key, NULL);
318 anjuta_test_shell_remove_widget (AnjutaShell
*shell
,
323 GtkWidget
*client_win
;
324 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
325 g_return_if_fail (w
!= NULL
);
327 // old_size = g_hash_table_size (window->widgets);
328 // g_object_set_data (G_OBJECT (w), "__temp_shell__", shell);
329 g_hash_table_foreach_steal (window
->widgets
, remove_from_widgets_hash
, w
);
330 // if (old_size != g_hash_table_size (window->widgets))
332 client_win
= gtk_widget_get_toplevel (w
);
333 gtk_container_remove (GTK_CONTAINER (client_win
), w
);
334 gtk_widget_destroy (client_win
);
338 static AnjutaPluginManager
*
339 anjuta_test_shell_get_plugin_manager (AnjutaShell
*shell
, GError
**error
)
341 return ANJUTA_TEST_SHELL(shell
)->plugin_manager
;
345 anjuta_test_shell_present_widget (AnjutaShell
*shell
,
349 GtkWidget
*client_win
;
350 // AnjutaTestShell *window = ANJUTA_TEST_SHELL (shell);
352 g_return_if_fail (w
!= NULL
);
354 client_win
= gtk_widget_get_toplevel (w
);
355 gtk_window_present (GTK_WINDOW (client_win
));
359 anjuta_test_shell_remove_value (AnjutaShell
*shell
,
366 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
368 if (g_hash_table_lookup_extended (window
->widgets
, name
,
369 (gpointer
*)&key
, (gpointer
*)&w
)) {
370 GtkWidget
*client_win
;
371 client_win
= gtk_widget_get_toplevel (w
);
372 gtk_container_remove (GTK_CONTAINER (client_win
), w
);
373 gtk_widget_destroy (client_win
);
377 if (g_hash_table_lookup_extended (window
->values
, name
,
378 (gpointer
*)&key
, (gpointer
*)&value
)) {
379 g_hash_table_remove (window
->values
, name
);
380 g_signal_emit_by_name (window
, "value_removed", name
);
381 g_value_unset (value
);
387 anjuta_test_shell_get_object (AnjutaShell
*shell
, const char *iface_name
,
390 return anjuta_plugin_manager_get_plugin (ANJUTA_TEST_SHELL (shell
)->plugin_manager
,
395 anjuta_test_shell_get_status (AnjutaShell
*shell
, GError
**error
)
397 return ANJUTA_TEST_SHELL (shell
)->status
;
401 anjuta_test_shell_get_ui (AnjutaShell
*shell
, GError
**error
)
403 return ANJUTA_TEST_SHELL (shell
)->ui
;
406 static AnjutaPreferences
*
407 anjuta_test_shell_get_preferences (AnjutaShell
*shell
, GError
**error
)
409 return ANJUTA_TEST_SHELL (shell
)->preferences
;
413 anjuta_test_shell_dispose (GObject
*widget
)
416 G_OBJECT_CLASS (parent_class
)->dispose (widget
);
420 anjuta_test_shell_finalize (GObject
*widget
)
422 AnjutaTestShell
*shell
= ANJUTA_TEST_SHELL (widget
);
424 g_hash_table_destroy (shell
->values
);
425 g_hash_table_destroy (shell
->widgets
);
427 G_OBJECT_CLASS (parent_class
)->finalize (widget
);
431 anjuta_test_shell_class_init (AnjutaTestShellClass
*class)
433 GObjectClass
*object_class
;
434 GtkWidgetClass
*widget_class
;
436 parent_class
= g_type_class_peek_parent (class);
437 object_class
= (GObjectClass
*) class;
438 widget_class
= (GtkWidgetClass
*) class;
439 object_class
->dispose
= anjuta_test_shell_dispose
;
440 object_class
->finalize
= anjuta_test_shell_finalize
;
444 anjuta_shell_iface_init (AnjutaShellIface
*iface
)
446 iface
->add_widget_full
= anjuta_test_shell_add_widget
;
447 iface
->remove_widget
= anjuta_test_shell_remove_widget
;
448 iface
->present_widget
= anjuta_test_shell_present_widget
;
449 iface
->iconify_dockable_widget
= anjuta_test_shell_iconify_dockable_widget
;
450 iface
->hide_dockable_widget
= anjuta_test_shell_hide_dockable_widget
;
451 iface
->show_dockable_widget
= anjuta_test_shell_show_dockable_widget
;
452 iface
->maximize_widget
= anjuta_test_shell_maximize_widget
;
453 iface
->unmaximize
= anjuta_test_shell_unmaximize
;
454 iface
->add_value
= anjuta_test_shell_add_value
;
455 iface
->get_value
= anjuta_test_shell_get_value
;
456 iface
->remove_value
= anjuta_test_shell_remove_value
;
457 iface
->get_object
= anjuta_test_shell_get_object
;
458 iface
->get_status
= anjuta_test_shell_get_status
;
459 iface
->get_ui
= anjuta_test_shell_get_ui
;
460 iface
->get_preferences
= anjuta_test_shell_get_preferences
;
461 iface
->get_plugin_manager
= anjuta_test_shell_get_plugin_manager
;
464 ANJUTA_TYPE_BEGIN(AnjutaTestShell
, anjuta_test_shell
, GTK_TYPE_WINDOW
);
465 ANJUTA_TYPE_ADD_INTERFACE(anjuta_shell
, ANJUTA_TYPE_SHELL
);
469 main (int argc
, char *argv
[])
473 bindtextdomain (PACKAGE
, PACKAGE_LOCALE_DIR
);
474 bind_textdomain_codeset(PACKAGE
, "UTF-8");
475 textdomain (PACKAGE
);
479 gtk_init (&argc
, &argv
);
480 g_set_application_name (_("Anjuta Shell Test"));
481 gtk_window_set_default_icon_name ("anjuta-shell");
482 gtk_window_set_auto_startup_notification(FALSE
);
484 shell
= anjuta_test_shell_new ();
485 g_signal_connect (G_OBJECT (shell
), "delete-event",
486 G_CALLBACK (on_delete_event
), NULL
);
487 gtk_widget_show_all (GTK_WIDGET (shell
));