Integrate adding files with the file manager
[anjuta-git-plugin.git] / plugins / valgrind / vgsearchbar.c
blobcd2fbd618cfa7130f9a1046a0d619d61217a78e6
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2003 Ximian, Inc. (www.ximian.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <glib/gi18n.h>
30 #include "vgsearchbar.h"
31 #include "vgmarshal.h"
33 enum {
34 SEARCH,
35 CLEAR,
36 LAST_SIGNAL
39 static int search_bar_signals[LAST_SIGNAL] = { 0, };
42 static void vg_search_bar_class_init (VgSearchBarClass *klass);
43 static void vg_search_bar_init (VgSearchBar *bar);
44 static void vg_search_bar_destroy (GtkObject *obj);
45 static void vg_search_bar_finalize (GObject *obj);
47 static void search_bar_set_menu_items (VgSearchBar *bar, VgSearchBarItem *items);
50 static GtkHBoxClass *parent_class = NULL;
53 GType
54 vg_search_bar_get_type (void)
56 static GType type = 0;
58 if (!type) {
59 static const GTypeInfo info = {
60 sizeof (VgSearchBarClass),
61 NULL, /* base_class_init */
62 NULL, /* base_class_finalize */
63 (GClassInitFunc) vg_search_bar_class_init,
64 NULL, /* class_finalize */
65 NULL, /* class_data */
66 sizeof (VgSearchBar),
67 0, /* n_preallocs */
68 (GInstanceInitFunc) vg_search_bar_init,
71 type = g_type_register_static (GTK_TYPE_HBOX, "VgSearchBar", &info, 0);
74 return type;
77 static void
78 vg_search_bar_class_init (VgSearchBarClass *klass)
80 GObjectClass *object_class = G_OBJECT_CLASS (klass);
81 GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
83 parent_class = g_type_class_ref (GTK_TYPE_VBOX);
85 object_class->finalize = vg_search_bar_finalize;
86 gtk_object_class->destroy = vg_search_bar_destroy;
88 /* virtual methods */
89 klass->set_menu_items = search_bar_set_menu_items;
91 /* signals */
92 search_bar_signals[SEARCH] =
93 g_signal_new ("search",
94 G_OBJECT_CLASS_TYPE (object_class),
95 G_SIGNAL_RUN_LAST,
96 G_STRUCT_OFFSET (VgSearchBarClass, search),
97 NULL, NULL,
98 vg_marshal_NONE__INT,
99 G_TYPE_NONE, 1, G_TYPE_INT);
101 search_bar_signals[CLEAR] =
102 g_signal_new ("clear",
103 G_OBJECT_CLASS_TYPE (object_class),
104 G_SIGNAL_RUN_LAST,
105 G_STRUCT_OFFSET (VgSearchBarClass, clear),
106 NULL, NULL,
107 vg_marshal_NONE__NONE,
108 G_TYPE_NONE, 0);
112 static void
113 entry_activate (GtkEntry *entry, VgSearchBar *bar)
115 g_signal_emit (bar, search_bar_signals[SEARCH], 0, bar->item_id);
118 static void
119 clear_clicked (GtkWidget *widget, VgSearchBar *bar)
121 gtk_entry_set_text (bar->entry, "");
122 gtk_option_menu_set_history (bar->menu, 0);
123 g_signal_emit (bar, search_bar_signals[CLEAR], 0);
126 static void
127 vg_search_bar_init (VgSearchBar *bar)
129 GtkWidget *widget;
131 gtk_box_set_spacing (GTK_BOX(bar), 6);
133 bar->item_id = -1;
135 bar->menu = GTK_OPTION_MENU (widget = gtk_option_menu_new ());
136 gtk_widget_show (widget);
137 gtk_box_pack_start (GTK_BOX (bar), widget, FALSE, FALSE, 0);
139 bar->entry = GTK_ENTRY (widget = gtk_entry_new ());
140 gtk_widget_show (widget);
141 gtk_box_pack_start (GTK_BOX (bar), widget, TRUE, TRUE, 0);
142 g_signal_connect (bar->entry, "activate", G_CALLBACK (entry_activate), bar);
144 bar->clear = widget = gtk_button_new_from_stock (GTK_STOCK_CLEAR);
145 gtk_widget_show (widget);
146 gtk_box_pack_start (GTK_BOX (bar), widget, FALSE, FALSE, 0);
147 g_signal_connect (bar->clear, "clicked", G_CALLBACK (clear_clicked), bar);
150 static void
151 vg_search_bar_finalize (GObject *obj)
153 G_OBJECT_CLASS (parent_class)->finalize (obj);
156 static void
157 vg_search_bar_destroy (GtkObject *obj)
159 GTK_OBJECT_CLASS (parent_class)->destroy (obj);
163 GtkWidget *
164 vg_search_bar_new (void)
166 return g_object_new (VG_TYPE_SEARCH_BAR, NULL);
170 static void
171 item_activate (GtkMenuItem *item, VgSearchBar *bar)
173 bar->item_id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "item_id"));
176 static void
177 search_bar_set_menu_items (VgSearchBar *bar, VgSearchBarItem *items)
179 GtkWidget *menu, *item;
180 int i;
182 g_return_if_fail (VG_IS_SEARCH_BAR (bar));
183 g_return_if_fail (items != NULL);
185 menu = gtk_menu_new ();
186 bar->item_id = items->id;
188 for (i = 0; items[i].label != NULL; i++) {
189 item = gtk_menu_item_new_with_label (_(items[i].label));
190 g_object_set_data (G_OBJECT (item), "item_id", GINT_TO_POINTER (items[i].id));
191 g_signal_connect (item, "activate", G_CALLBACK (item_activate), bar);
192 gtk_widget_show (item);
194 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
197 gtk_option_menu_set_menu (bar->menu, menu);
198 gtk_option_menu_set_history (bar->menu, 0);
202 void
203 vg_search_bar_set_menu_items (VgSearchBar *bar, VgSearchBarItem *items)
205 g_return_if_fail (VG_IS_SEARCH_BAR (bar));
206 g_return_if_fail (items != NULL);
208 VG_SEARCH_BAR_GET_CLASS (bar)->set_menu_items (bar, items);
211 const char *
212 vg_search_bar_get_text (VgSearchBar *bar)
214 g_return_val_if_fail (VG_IS_SEARCH_BAR (bar), NULL);
216 return gtk_entry_get_text (bar->entry);