1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 * Copyright (C) 2004 Fernando Herrera <fherrera@onirica.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
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 GNU
13 * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "gconf-search.h"
20 #include "gconf-search-dialog.h"
21 #include "gconf-editor-window.h"
22 #include "gconf-tree-model.h"
23 #include "gconf-list-model.h"
24 #include "gedit-output-window.h"
25 #include <gconf/gconf-client.h>
27 #include <glib/gi18n.h>
30 #include "gconf-stock-icons.h"
32 G_DEFINE_TYPE(GConfSearchDialog, gconf_search_dialog, GTK_TYPE_DIALOG)
35 gconf_search_dialog_response (GtkDialog *dialog, gint response_id)
37 gtk_widget_destroy (GTK_WIDGET (dialog));
41 gconf_search_dialog_class_init (GConfSearchDialogClass *klass)
43 GtkDialogClass *dialog_class;
45 dialog_class = (GtkDialogClass *)klass;
47 dialog_class->response = gconf_search_dialog_response;
52 gconf_search_not_found_dialog (GConfSearchDialog *dialog)
54 GtkWidget *not_found_dialog;
56 not_found_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
57 GTK_DIALOG_DESTROY_WITH_PARENT,
60 _("Pattern not found"));
61 gtk_dialog_run (GTK_DIALOG (not_found_dialog));
62 gtk_widget_destroy (GTK_WIDGET (not_found_dialog));
66 gconf_search_entry_changed (GtkEntry *entry, GConfSearchDialog *dialog)
68 gboolean find_sensitive;
71 text = gtk_entry_get_text (GTK_ENTRY (entry));
72 find_sensitive = text != NULL && text[0] != '\0';
74 gtk_widget_set_sensitive (dialog->search_button, find_sensitive);
78 gconf_search_dialog_search (GtkWidget *button, GConfSearchDialog *dialog)
80 GConfEditorWindow *window;
86 window = g_object_get_data (G_OBJECT (dialog), "editor-window");
87 gedit_output_window_clear (GEDIT_OUTPUT_WINDOW (window->output_window));
88 window->output_window_type = GCONF_EDITOR_WINDOW_OUTPUT_WINDOW_SEARCH;
90 pattern = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->entry)));
92 cursor = gdk_cursor_new (GDK_WATCH);
93 gdk_window_set_cursor (GTK_WIDGET (dialog)->window, cursor);
94 gdk_cursor_unref (cursor);
95 gdk_display_flush (gtk_widget_get_display (GTK_WIDGET (dialog)));
97 res = gconf_tree_model_build_match_list (GCONF_TREE_MODEL (window->tree_model),
98 GEDIT_OUTPUT_WINDOW (window->output_window),
100 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->search_in_keys)),
101 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->search_in_values)),
106 if (dialog != NULL) {
108 g_signal_handlers_disconnect_by_func (dialog->entry,
109 G_CALLBACK (gconf_search_entry_changed), dialog);
110 g_signal_handlers_disconnect_by_func (dialog->search_button,
111 G_CALLBACK (gconf_search_dialog_search), dialog);
113 gdk_window_set_cursor (GTK_WIDGET (dialog)->window, NULL);
114 gdk_display_flush (gtk_widget_get_display (GTK_WIDGET (dialog)));
117 gtk_widget_destroy (GTK_WIDGET (dialog));
119 gconf_search_not_found_dialog (dialog);
125 gconf_search_dialog_init (GConfSearchDialog *dialog)
131 gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
132 gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
133 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
134 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 2);
136 hbox = gtk_hbox_new (FALSE, 12);
137 vbox = gtk_vbox_new (FALSE, 6);
138 gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
140 gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
142 gtk_window_set_title (GTK_WINDOW (dialog), _("Find"));
144 label = gtk_label_new_with_mnemonic (_("_Search for: "));
146 dialog->entry = gtk_entry_new ();
147 g_signal_connect (dialog->entry, "changed",
148 G_CALLBACK (gconf_search_entry_changed), dialog);
149 gtk_label_set_mnemonic_widget (GTK_LABEL(label), GTK_WIDGET(dialog->entry));
151 dialog->search_button = gtk_button_new_from_stock (GTK_STOCK_FIND);
152 gtk_widget_set_sensitive (dialog->search_button, FALSE);
153 g_signal_connect (dialog->search_button, "clicked",
154 G_CALLBACK (gconf_search_dialog_search), dialog);
156 GTK_WIDGET_SET_FLAGS(dialog->search_button, GTK_CAN_DEFAULT);
157 gtk_window_set_default(GTK_WINDOW(dialog), dialog->search_button);
158 gtk_entry_set_activates_default(GTK_ENTRY(dialog->entry), TRUE);
160 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
161 gtk_box_pack_start (GTK_BOX (hbox), dialog->entry, FALSE, FALSE, 0);
163 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
165 dialog->search_in_keys = gtk_check_button_new_with_mnemonic (_("Search also in key _names"));
166 gtk_box_pack_start (GTK_BOX (vbox), dialog->search_in_keys, TRUE, TRUE, 0);
168 dialog->search_in_values = gtk_check_button_new_with_mnemonic (_("Search also in key _values"));
169 gtk_box_pack_start (GTK_BOX (vbox), dialog->search_in_values, TRUE, TRUE, 0);
171 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), vbox, TRUE, TRUE, 0);
172 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->action_area), dialog->search_button, TRUE, TRUE, 0);
173 gtk_widget_show_all (GTK_DIALOG(dialog)->action_area);
174 gtk_widget_show_all (vbox);
176 gtk_widget_show_all (hbox);
180 gconf_search_dialog_new (GtkWindow *parent)
184 dialog = g_object_new (GCONF_TYPE_SEARCH_DIALOG, NULL);
185 g_object_set_data (G_OBJECT (dialog), "editor-window", parent);
186 gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
187 gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);