* plugins/debug-manager/anjuta-debug-manager.ui,
[anjuta-git-plugin.git] / plugins / debug-manager / locals.c
blob1ba70270d5dd6964e8d763a082a8225c2d234fe2
1 /*
2 locals.c
3 Copyright (C) 2000 Kh. Naba Kumar Singh
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 laterdversion.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
23 #include "locals.h"
25 #include "debug_tree.h"
27 /*#define DEBUG*/
28 #include <libanjuta/anjuta-debug.h>
30 struct _Locals
32 IAnjutaDebugger *debugger;
33 GtkWidget *main_w;
34 DebugTree *debug_tree;
35 AnjutaPlugin *plugin;
38 static void
39 locals_updated (const gpointer data, gpointer user_data, GError *error)
41 const GList *list = (const GList *)data;
42 Locals *locals = (Locals*) user_data;
44 g_return_if_fail (locals != NULL);
46 if (error != NULL)
47 return;
49 if (g_list_length ((GList*)list) < 1)
50 return;
52 debug_tree_replace_list (locals->debug_tree, list);
53 debug_tree_update_all(locals->debug_tree);
56 /* Private functions
57 *---------------------------------------------------------------------------*/
59 static void
60 create_locals_gui (Locals *l)
62 if (l->debug_tree == NULL)
64 l->debug_tree = debug_tree_new (l->plugin);
65 debug_tree_connect (l->debug_tree, l->debugger);
68 if (l->main_w == NULL)
70 /* Create local window */
71 GtkWidget *main_w;
73 main_w = gtk_scrolled_window_new (NULL, NULL);
74 gtk_widget_show (main_w);
75 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (main_w),
76 GTK_POLICY_AUTOMATIC,
77 GTK_POLICY_AUTOMATIC);
78 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (main_w),
79 GTK_SHADOW_IN);
80 gtk_container_add (GTK_CONTAINER (main_w), debug_tree_get_tree_widget (l->debug_tree));
81 gtk_widget_show_all (main_w);
82 l->main_w = main_w;
84 anjuta_shell_add_widget (l->plugin->shell,
85 l->main_w,
86 "AnjutaDebuggerLocals", _("Locals"),
87 "gdb-locals-icon", ANJUTA_SHELL_PLACEMENT_BOTTOM,
88 NULL);
92 static void
93 destroy_locals_gui (Locals *l)
95 if (l->debug_tree != NULL)
97 debug_tree_free (l->debug_tree);
98 l->debug_tree = NULL;
100 if (l->main_w != NULL)
102 gtk_widget_destroy (GTK_WIDGET (l->main_w));
103 l->main_w = NULL;
107 /* Private functions
108 *---------------------------------------------------------------------------*/
110 static void locals_update (Locals *locals)
112 ianjuta_debugger_list_local (locals->debugger, locals_updated, locals, NULL);
115 static void
116 locals_clear (Locals *l)
118 g_return_if_fail (l != NULL);
119 debug_tree_remove_all (l->debug_tree);
122 static void
123 on_program_stopped (Locals *l)
125 locals_update (l);
128 static void
129 on_debugger_started (Locals *l)
131 create_locals_gui (l);
134 static void
135 on_debugger_stopped (Locals *l)
137 locals_clear (l);
138 destroy_locals_gui (l);
141 /* Constructor & Destructor
142 *---------------------------------------------------------------------------*/
144 Locals *
145 locals_new (AnjutaPlugin *plugin, IAnjutaDebugger* debugger)
147 DebugTree *debug_tree;
149 Locals *locals = g_new0 (Locals, 1);
151 debug_tree = debug_tree_new (plugin);
153 locals->debugger = debugger;
154 if (debugger != NULL) g_object_ref (debugger);
155 locals->plugin = plugin;
157 g_signal_connect_swapped (locals->debugger, "debugger-started", G_CALLBACK (on_debugger_started), locals);
158 g_signal_connect_swapped (locals->debugger, "debugger-stopped", G_CALLBACK (on_debugger_stopped), locals);
159 g_signal_connect_swapped (locals->debugger, "program-stopped", G_CALLBACK (on_program_stopped), locals);
161 return locals;
164 void
165 locals_free (Locals *l)
167 g_return_if_fail (l != NULL);
169 /* Destroy gui */
170 destroy_locals_gui (l);
172 /* Disconnect from debugger */
173 if (l->debugger != NULL)
175 g_signal_handlers_disconnect_by_func (l->debugger, G_CALLBACK (on_debugger_started), l);
176 g_signal_handlers_disconnect_by_func (l->debugger, G_CALLBACK (on_debugger_stopped), l);
177 g_signal_handlers_disconnect_by_func (l->debugger, G_CALLBACK (on_program_stopped), l);
178 g_object_unref (l->debugger);
181 g_free (l);