2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant 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 GtkRadiant 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 GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 // Find/Replace textures dialogs
25 // Leonardo Zide (leo@lokigames.com)
29 #include "findtexturedialog.h"
30 #include <glib/gi18n.h>
32 FindTextureDialog g_TexFindDlg;
33 FindTextureDialog& g_dlgFind = g_TexFindDlg;
34 static bool g_bFindActive = true;
36 static void OnApply(GtkWidget *widget, gpointer data)
38 g_dlgFind.UpdateData(TRUE);
39 FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
40 g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE);
43 static void OnFind(GtkWidget *widget, gpointer data)
45 g_dlgFind.UpdateData(TRUE);
46 FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
47 g_dlgFind.m_bSelectedOnly, FALSE, TRUE);
50 static void OnOK(GtkWidget *widget, gpointer data)
52 g_dlgFind.UpdateData(TRUE);
53 FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
54 g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE);
58 static void OnClose(GtkWidget *widget, gpointer data)
63 static void popup_selected (GtkWidget *widget, gpointer data)
67 gtk_label_get (GTK_LABEL (GTK_BIN (widget)->child), &str);
68 gtk_entry_set_text (GTK_ENTRY (data), str);
71 static void find_clicked (GtkWidget *widget, gpointer data)
73 GtkWidget *menu, *item;
74 menu = gtk_menu_new ();
76 for (int i = 0; i < QERApp_GetActiveShaderCount (); i++)
78 IShader *pShader = QERApp_ActiveShader_ForIndex (i);
80 item = gtk_menu_item_new_with_label (pShader->getName ());
81 gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (popup_selected), data);
82 gtk_widget_show (item);
83 gtk_menu_append (GTK_MENU (menu), item);
86 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME);
89 static gint find_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data)
95 static gint replace_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data)
97 g_bFindActive = false;
101 // =============================================================================
102 // FindTextureDialog class
104 FindTextureDialog::FindTextureDialog ()
106 m_bSelectedOnly = FALSE;
113 FindTextureDialog::~FindTextureDialog ()
117 void FindTextureDialog::BuildDialog ()
119 GtkWidget *dlg, *vbox, *hbox, *table, *label;
120 GtkWidget *button, *check, *entry, *arrow;
123 gtk_window_set_title (GTK_WINDOW (dlg), "Find / Replace Texture(s)");
124 gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (g_pParentWnd->m_pWidget));
126 hbox = gtk_hbox_new (FALSE, 5);
127 gtk_widget_show (hbox);
128 gtk_container_add (GTK_CONTAINER (dlg), hbox);
129 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
131 vbox = gtk_vbox_new (FALSE, 5);
132 gtk_widget_show (vbox);
133 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
135 table = gtk_table_new (2, 3, FALSE);
136 gtk_widget_show (table);
137 gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
138 gtk_table_set_row_spacings (GTK_TABLE (table), 5);
139 gtk_table_set_col_spacings (GTK_TABLE (table), 5);
141 label = gtk_label_new ("Find:");
142 gtk_widget_show (label);
143 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
144 (GtkAttachOptions) (GTK_FILL),
145 (GtkAttachOptions) (0), 0, 0);
146 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
148 label = gtk_label_new ("Replace:");
149 gtk_widget_show (label);
150 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
151 (GtkAttachOptions) (GTK_FILL),
152 (GtkAttachOptions) (0), 0, 0);
153 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
155 entry = gtk_entry_new ();
156 gtk_widget_show (entry);
157 gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
158 (GtkAttachOptions) (GTK_EXPAND|GTK_FILL),
159 (GtkAttachOptions) (0), 0, 0);
160 gtk_signal_connect (GTK_OBJECT (entry), "focus_in_event",
161 GTK_SIGNAL_FUNC (find_focus_in), NULL);
162 AddDialogData (entry, &m_strFind, DLG_ENTRY_TEXT);
164 button = gtk_button_new ();
165 gtk_widget_show (button);
166 gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
167 (GtkAttachOptions) (GTK_FILL),
168 (GtkAttachOptions) (GTK_FILL), 0, 0);
169 gtk_signal_connect (GTK_OBJECT (button), "clicked",
170 GTK_SIGNAL_FUNC (find_clicked), entry);
172 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
173 gtk_widget_show (arrow);
174 gtk_container_add (GTK_CONTAINER (button), arrow);
176 entry = gtk_entry_new ();
177 gtk_widget_show (entry);
178 gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2,
179 (GtkAttachOptions) (GTK_EXPAND|GTK_FILL),
180 (GtkAttachOptions) (0), 0, 0);
181 gtk_signal_connect (GTK_OBJECT (entry), "focus_in_event",
182 GTK_SIGNAL_FUNC (replace_focus_in), NULL);
183 AddDialogData (entry, &m_strReplace, DLG_ENTRY_TEXT);
185 button = gtk_button_new ();
186 gtk_widget_show (button);
187 gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
188 (GtkAttachOptions) (GTK_FILL),
189 (GtkAttachOptions) (GTK_FILL), 0, 0);
190 gtk_signal_connect (GTK_OBJECT (button), "clicked",
191 GTK_SIGNAL_FUNC (find_clicked), entry);
193 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
194 gtk_widget_show (arrow);
195 gtk_container_add (GTK_CONTAINER (button), arrow);
197 check = gtk_check_button_new_with_label ("Use selected brushes only");
198 gtk_widget_show (check);
199 gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
200 AddDialogData (check, &m_bSelectedOnly, DLG_CHECK_BOOL);
202 check = gtk_check_button_new_with_label ("Replace everywhere (selected/active), don't test against Find");
203 gtk_widget_show (check);
204 gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
205 AddDialogData (check, &m_bForce, DLG_CHECK_BOOL);
207 check = gtk_check_button_new_with_label ("Live updates from Texture/Camera windows");
208 gtk_widget_show (check);
209 gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
210 AddDialogData (check, &m_bLive, DLG_CHECK_BOOL);
212 vbox = gtk_vbox_new (FALSE, 5);
213 gtk_widget_show (vbox);
214 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
216 button = gtk_button_new_with_label( _("Find") );
217 gtk_widget_show( button );
218 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
219 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
220 GTK_SIGNAL_FUNC( OnFind ), NULL );
221 gtk_widget_set_usize( button, 60, -2 );
223 button = gtk_button_new_with_label (_("OK"));
224 gtk_widget_show (button);
225 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
226 gtk_signal_connect (GTK_OBJECT (button), "clicked",
227 GTK_SIGNAL_FUNC (OnOK), NULL);
228 gtk_widget_set_usize (button, 60, -2);
230 button = gtk_button_new_with_label (_("Apply"));
231 gtk_widget_show (button);
232 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
233 gtk_signal_connect (GTK_OBJECT (button), "clicked",
234 GTK_SIGNAL_FUNC (OnApply), NULL);
235 gtk_widget_set_usize (button, 60, -2);
237 button = gtk_button_new_with_label (_("Close"));
238 gtk_widget_show (button);
239 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
240 gtk_signal_connect (GTK_OBJECT (button), "clicked",
241 GTK_SIGNAL_FUNC (OnClose), NULL);
242 gtk_widget_set_usize (button, 60, -2);
244 gtk_widget_show (dlg);
247 void FindTextureDialog::updateTextures(const char *p)
262 bool FindTextureDialog::isOpen()
264 return (g_dlgFind.m_pWidget == NULL || GTK_WIDGET_VISIBLE (g_dlgFind.m_pWidget) == FALSE) ? false : true;
267 void FindTextureDialog::setFindStr(const char * p)
269 g_dlgFind.UpdateData(TRUE);
270 if (g_dlgFind.m_bLive)
272 g_dlgFind.m_strFind = p;
273 g_dlgFind.UpdateData(FALSE);
277 void FindTextureDialog::setReplaceStr(const char * p)
279 g_dlgFind.UpdateData(TRUE);
280 if (g_dlgFind.m_bLive)
282 g_dlgFind.m_strReplace = p;
283 g_dlgFind.UpdateData(FALSE);
287 void FindTextureDialog::show()
289 g_dlgFind.ShowDlg ();