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>
30 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-shell.ui"
33 shutdown (AnjutaTestShell
*shell
)
35 anjuta_plugin_manager_unload_all_plugins (shell
->plugin_manager
);
40 on_delete_event (GtkWidget
*window
, GdkEvent
*event
, gpointer data
)
42 shutdown (ANJUTA_TEST_SHELL (window
));
47 on_exit_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
53 on_preferences_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
55 GtkWidget
*preferences_dialog
;
57 preferences_dialog
= anjuta_preferences_get_dialog (shell
->preferences
);
59 g_signal_connect_swapped (G_OBJECT (preferences_dialog
),
61 G_CALLBACK (gtk_widget_destroy
),
64 gtk_window_set_transient_for (GTK_WINDOW (preferences_dialog
),
67 gtk_widget_show (preferences_dialog
);
71 on_shortcuts_activate (GtkAction
*action
, AnjutaTestShell
*shell
)
73 GtkWidget
*win
, *accel_editor
;
75 accel_editor
= anjuta_ui_get_accel_editor (ANJUTA_UI (shell
->ui
));
76 win
= gtk_dialog_new_with_buttons (_("Anjuta Plugins"), GTK_WINDOW (shell
),
77 GTK_DIALOG_DESTROY_WITH_PARENT
,
78 GTK_STOCK_CLOSE
, GTK_STOCK_CANCEL
, NULL
);
79 gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG(win
)->vbox
), accel_editor
);
80 gtk_window_set_default_size (GTK_WINDOW (win
), 500, 400);
81 gtk_dialog_run (GTK_DIALOG (win
));
82 gtk_widget_destroy (win
);
85 static GtkActionEntry action_entries
[] = {
86 { "ActionMenuFile", NULL
, N_("_File")},
87 { "ActionMenuEdit", NULL
, N_("_Edit")},
88 { "ActionMenuView", NULL
, N_("_View")},
89 { "ActionMenuSettings", NULL
, N_("_Settings")},
90 { "ActionMenuHelp", NULL
, N_("_Help")},
96 N_("Quit Anjuta Test Shell"),
97 G_CALLBACK (on_exit_activate
)
100 "ActionSettingsPreferences",
101 GTK_STOCK_PROPERTIES
,
102 N_("_Preferences..."),
105 G_CALLBACK (on_preferences_activate
)
108 "ActionSettingsShortcuts",
110 N_("C_ustomize shortcuts"),
112 N_("Customize shortcuts associated with menu items"),
113 G_CALLBACK (on_shortcuts_activate
)
117 static gpointer parent_class
= NULL
;
120 on_add_merge_widget (GtkUIManager
*merge
, GtkWidget
*widget
,
121 GtkWidget
*ui_container
)
123 DEBUG_PRINT ("Adding UI item...");
124 gtk_box_pack_start (GTK_BOX ((ANJUTA_TEST_SHELL (ui_container
))->box
),
125 widget
, FALSE
, FALSE
, 0);
129 anjuta_test_shell_new (void)
131 AnjutaTestShell
*shell
;
133 shell
= ANJUTA_TEST_SHELL (g_object_new (ANJUTA_TYPE_TEST_SHELL
,
134 "title", "Anjuta Shell",
136 return GTK_WIDGET (shell
);
140 anjuta_test_shell_instance_init (AnjutaTestShell
*shell
)
143 GList
*plugins_dirs
= NULL
;
145 shell
->values
= g_hash_table_new (g_str_hash
, g_str_equal
);
146 shell
->widgets
= g_hash_table_new (g_str_hash
, g_str_equal
);
148 shell
->box
= gtk_vbox_new (FALSE
, 0);
149 gtk_widget_show (shell
->box
);
150 gtk_container_add (GTK_CONTAINER (shell
), shell
->box
);
153 shell
->status
= ANJUTA_STATUS (anjuta_status_new ());
154 gtk_widget_show (GTK_WIDGET (shell
->status
));
155 gtk_box_pack_end (GTK_BOX (shell
->box
), GTK_WIDGET (shell
->status
),
158 /* Initialize plugins */
159 plugins_dirs
= g_list_prepend (plugins_dirs
, PACKAGE_PLUGIN_DIR
);
160 shell
->plugin_manager
= anjuta_plugin_manager_new (G_OBJECT (shell
),
163 g_list_free (plugins_dirs
);
165 plugins
= anjuta_plugin_manager_get_plugins_page (shell
->plugin_manager
);
166 gtk_box_pack_end_defaults (GTK_BOX (shell
->box
), plugins
);
168 /* Preferencesnces */
169 shell
->preferences
= ANJUTA_PREFERENCES (anjuta_preferences_new (shell
->plugin_manager
));
172 shell
->ui
= anjuta_ui_new ();
173 gtk_window_add_accel_group (GTK_WINDOW (shell
),
174 anjuta_ui_get_accel_group (shell
->ui
));
175 g_signal_connect (G_OBJECT (shell
->ui
),
176 "add_widget", G_CALLBACK (on_add_merge_widget
),
179 /*gtk_window_add_accel_group (GTK_WINDOW (shell),
180 anjuta_ui_get_accel_group (shell->ui));*/
181 /* Register actions */
182 anjuta_ui_add_action_group_entries (shell
->ui
, "ActionGroupTestShell",
183 _("Test shell action group"),
185 G_N_ELEMENTS (action_entries
),
186 GETTEXT_PACKAGE
, TRUE
, shell
);
188 shell
->merge_id
= anjuta_ui_merge (shell
->ui
, UI_FILE
);
190 gtk_window_set_default_size (GTK_WINDOW (shell
), 300, 400);
194 anjuta_test_shell_add_value (AnjutaShell
*shell
,
200 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
202 anjuta_shell_remove_value (shell
, name
, error
);
204 copy
= g_new0 (GValue
, 1);
205 g_value_init (copy
, value
->g_type
);
206 g_value_copy (value
, copy
);
208 g_hash_table_insert (window
->values
, g_strdup (name
), copy
);
209 g_signal_emit_by_name (shell
, "value_added", name
, copy
);
213 anjuta_test_shell_get_value (AnjutaShell
*shell
,
219 AnjutaTestShell
*s
= ANJUTA_TEST_SHELL (shell
);
221 val
= g_hash_table_lookup (s
->values
, name
);
224 if (!value
->g_type
) {
225 g_value_init (value
, val
->g_type
);
227 g_value_copy (val
, value
);
230 *error
= g_error_new (ANJUTA_SHELL_ERROR
,
231 ANJUTA_SHELL_ERROR_DOESNT_EXIST
,
232 _("Value doesn't exist"));
238 anjuta_test_shell_add_widget (AnjutaShell
*shell
,
242 const char *stock_id
,
243 AnjutaShellPlacement placement
,
247 GtkWidget
*client_win
;
248 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
250 g_return_if_fail (w
!= NULL
);
252 // anjuta_shell_add (shell, name, G_TYPE_FROM_INSTANCE (w), w, NULL);
254 g_hash_table_insert (window
->widgets
, g_strdup (name
), w
);
255 client_win
= gtk_window_new (GTK_WINDOW_TOPLEVEL
);
256 gtk_container_add (GTK_CONTAINER (client_win
), w
);
257 gtk_widget_show_all (client_win
);
261 remove_from_widgets_hash (gpointer key
, gpointer value
, gpointer data
)
264 // AnjutaShell *shell;
266 // shell = g_object_get_data (G_OBJECT (value), "__temp_shell__");
267 // anjuta_shell_remove_value (shell, key, NULL);
275 anjuta_test_shell_remove_widget (AnjutaShell
*shell
,
280 GtkWidget
*client_win
;
281 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
282 g_return_if_fail (w
!= NULL
);
284 // old_size = g_hash_table_size (window->widgets);
285 // g_object_set_data (G_OBJECT (w), "__temp_shell__", shell);
286 g_hash_table_foreach_steal (window
->widgets
, remove_from_widgets_hash
, w
);
287 // if (old_size != g_hash_table_size (window->widgets))
289 client_win
= gtk_widget_get_toplevel (w
);
290 gtk_container_remove (GTK_CONTAINER (client_win
), w
);
291 gtk_widget_destroy (client_win
);
295 static AnjutaPluginManager
*
296 anjuta_test_shell_get_plugin_manager (AnjutaShell
*shell
, GError
**error
)
298 return ANJUTA_TEST_SHELL(shell
)->plugin_manager
;
302 anjuta_test_shell_present_widget (AnjutaShell
*shell
,
306 GtkWidget
*client_win
;
307 // AnjutaTestShell *window = ANJUTA_TEST_SHELL (shell);
309 g_return_if_fail (w
!= NULL
);
311 client_win
= gtk_widget_get_toplevel (w
);
312 gtk_window_present (GTK_WINDOW (client_win
));
316 anjuta_test_shell_remove_value (AnjutaShell
*shell
,
323 AnjutaTestShell
*window
= ANJUTA_TEST_SHELL (shell
);
325 if (g_hash_table_lookup_extended (window
->widgets
, name
,
326 (gpointer
*)&key
, (gpointer
*)&w
)) {
327 GtkWidget
*client_win
;
328 client_win
= gtk_widget_get_toplevel (w
);
329 gtk_container_remove (GTK_CONTAINER (client_win
), w
);
330 gtk_widget_destroy (client_win
);
334 if (g_hash_table_lookup_extended (window
->values
, name
,
335 (gpointer
*)&key
, (gpointer
*)&value
)) {
336 g_hash_table_remove (window
->values
, name
);
337 g_signal_emit_by_name (window
, "value_removed", name
);
338 g_value_unset (value
);
344 anjuta_test_shell_get_object (AnjutaShell
*shell
, const char *iface_name
,
347 return anjuta_plugin_manager_get_plugin (ANJUTA_TEST_SHELL (shell
)->plugin_manager
,
352 anjuta_test_shell_get_status (AnjutaShell
*shell
, GError
**error
)
354 return ANJUTA_TEST_SHELL (shell
)->status
;
358 anjuta_test_shell_get_ui (AnjutaShell
*shell
, GError
**error
)
360 return ANJUTA_TEST_SHELL (shell
)->ui
;
363 static AnjutaPreferences
*
364 anjuta_test_shell_get_preferences (AnjutaShell
*shell
, GError
**error
)
366 return ANJUTA_TEST_SHELL (shell
)->preferences
;
370 anjuta_test_shell_dispose (GObject
*widget
)
373 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (widget
));
377 anjuta_test_shell_finalize (GObject
*widget
)
379 AnjutaTestShell
*shell
= ANJUTA_TEST_SHELL (widget
);
381 g_hash_table_destroy (shell
->values
);
382 g_hash_table_destroy (shell
->widgets
);
384 GNOME_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (widget
));
388 anjuta_test_shell_class_init (AnjutaTestShellClass
*class)
390 GObjectClass
*object_class
;
391 GtkWidgetClass
*widget_class
;
393 parent_class
= g_type_class_peek_parent (class);
394 object_class
= (GObjectClass
*) class;
395 widget_class
= (GtkWidgetClass
*) class;
396 object_class
->dispose
= anjuta_test_shell_dispose
;
397 object_class
->finalize
= anjuta_test_shell_finalize
;
401 anjuta_shell_iface_init (AnjutaShellIface
*iface
)
403 iface
->add_widget_full
= anjuta_test_shell_add_widget
;
404 iface
->remove_widget
= anjuta_test_shell_remove_widget
;
405 iface
->present_widget
= anjuta_test_shell_present_widget
;
406 iface
->add_value
= anjuta_test_shell_add_value
;
407 iface
->get_value
= anjuta_test_shell_get_value
;
408 iface
->remove_value
= anjuta_test_shell_remove_value
;
409 iface
->get_object
= anjuta_test_shell_get_object
;
410 iface
->get_status
= anjuta_test_shell_get_status
;
411 iface
->get_ui
= anjuta_test_shell_get_ui
;
412 iface
->get_preferences
= anjuta_test_shell_get_preferences
;
413 iface
->get_plugin_manager
= anjuta_test_shell_get_plugin_manager
;
416 ANJUTA_TYPE_BEGIN(AnjutaTestShell
, anjuta_test_shell
, GTK_TYPE_WINDOW
);
417 ANJUTA_TYPE_ADD_INTERFACE(anjuta_shell
, ANJUTA_TYPE_SHELL
);
421 main (int argc
, char *argv
[])
424 GnomeProgram
*program
;
426 // GList* command_args;
429 bindtextdomain (PACKAGE
, PACKAGE_LOCALE_DIR
);
430 bind_textdomain_codeset(PACKAGE
, "UTF-8");
431 textdomain (PACKAGE
);
434 data_dir
= g_strdup (PACKAGE_DATA_DIR
);
435 data_dir
[strlen (data_dir
) - strlen (PACKAGE
) - 1] = '\0';
437 /* Initialize gnome program */
438 program
= gnome_program_init ("Anjuta Test Shell", VERSION
,
439 LIBGNOMEUI_MODULE
, argc
, argv
,
440 GNOME_PARAM_POPT_TABLE
, NULL
,
441 GNOME_PARAM_HUMAN_READABLE_NAME
,
442 _("Anjuta test shell"),
443 GNOME_PARAM_APP_DATADIR
, data_dir
,
447 shell
= anjuta_test_shell_new ();
448 g_signal_connect (G_OBJECT (shell
), "delete-event",
449 G_CALLBACK (on_delete_event
), NULL
);
450 gtk_widget_show_all (GTK_WIDGET (shell
));