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"
31 FindTextureDialog g_TexFindDlg;
32 FindTextureDialog& g_dlgFind = g_TexFindDlg;
33 static bool g_bFindActive = true;
35 static void OnApply(GtkWidget *widget, gpointer data)
37 g_dlgFind.UpdateData(TRUE);
38 FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
39 g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE);
42 static void OnFind(GtkWidget *widget, gpointer data)
44 g_dlgFind.UpdateData(TRUE);
45 FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
46 g_dlgFind.m_bSelectedOnly, FALSE, TRUE);
49 static void OnOK(GtkWidget *widget, gpointer data)
51 g_dlgFind.UpdateData(TRUE);
52 FindReplaceTextures(g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
53 g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE);
57 static void OnClose(GtkWidget *widget, gpointer data)
62 static void popup_selected (GtkWidget *widget, gpointer data)
66 gtk_label_get (GTK_LABEL (GTK_BIN (widget)->child), &str);
67 gtk_entry_set_text (GTK_ENTRY (data), str);
70 static void find_clicked (GtkWidget *widget, gpointer data)
72 GtkWidget *menu, *item;
73 menu = gtk_menu_new ();
75 for (int i = 0; i < QERApp_GetActiveShaderCount (); i++)
77 IShader *pShader = QERApp_ActiveShader_ForIndex (i);
79 item = gtk_menu_item_new_with_label (pShader->getName ());
80 gtk_signal_connect (GTK_OBJECT (item), "activate", GTK_SIGNAL_FUNC (popup_selected), data);
81 gtk_widget_show (item);
82 gtk_menu_append (GTK_MENU (menu), item);
85 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME);
88 static gint find_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data)
94 static gint replace_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data)
96 g_bFindActive = false;
100 // =============================================================================
101 // FindTextureDialog class
103 FindTextureDialog::FindTextureDialog ()
105 m_bSelectedOnly = FALSE;
112 FindTextureDialog::~FindTextureDialog ()
116 void FindTextureDialog::BuildDialog ()
118 GtkWidget *dlg, *vbox, *hbox, *table, *label;
119 GtkWidget *button, *check, *entry, *arrow;
122 gtk_window_set_title (GTK_WINDOW (dlg), "Find / Replace Texture(s)");
123 gtk_window_set_transient_for (GTK_WINDOW (dlg), GTK_WINDOW (g_pParentWnd->m_pWidget));
125 hbox = gtk_hbox_new (FALSE, 5);
126 gtk_widget_show (hbox);
127 gtk_container_add (GTK_CONTAINER (dlg), hbox);
128 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
130 vbox = gtk_vbox_new (FALSE, 5);
131 gtk_widget_show (vbox);
132 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
134 table = gtk_table_new (2, 3, FALSE);
135 gtk_widget_show (table);
136 gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);
137 gtk_table_set_row_spacings (GTK_TABLE (table), 5);
138 gtk_table_set_col_spacings (GTK_TABLE (table), 5);
140 label = gtk_label_new ("Find:");
141 gtk_widget_show (label);
142 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
143 (GtkAttachOptions) (GTK_FILL),
144 (GtkAttachOptions) (0), 0, 0);
145 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
147 label = gtk_label_new ("Replace:");
148 gtk_widget_show (label);
149 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
150 (GtkAttachOptions) (GTK_FILL),
151 (GtkAttachOptions) (0), 0, 0);
152 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
154 entry = gtk_entry_new ();
155 gtk_widget_show (entry);
156 gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 0, 1,
157 (GtkAttachOptions) (GTK_EXPAND|GTK_FILL),
158 (GtkAttachOptions) (0), 0, 0);
159 gtk_signal_connect (GTK_OBJECT (entry), "focus_in_event",
160 GTK_SIGNAL_FUNC (find_focus_in), NULL);
161 AddDialogData (entry, &m_strFind, DLG_ENTRY_TEXT);
163 button = gtk_button_new ();
164 gtk_widget_show (button);
165 gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
166 (GtkAttachOptions) (GTK_FILL),
167 (GtkAttachOptions) (GTK_FILL), 0, 0);
168 gtk_signal_connect (GTK_OBJECT (button), "clicked",
169 GTK_SIGNAL_FUNC (find_clicked), entry);
171 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
172 gtk_widget_show (arrow);
173 gtk_container_add (GTK_CONTAINER (button), arrow);
175 entry = gtk_entry_new ();
176 gtk_widget_show (entry);
177 gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 1, 2,
178 (GtkAttachOptions) (GTK_EXPAND|GTK_FILL),
179 (GtkAttachOptions) (0), 0, 0);
180 gtk_signal_connect (GTK_OBJECT (entry), "focus_in_event",
181 GTK_SIGNAL_FUNC (replace_focus_in), NULL);
182 AddDialogData (entry, &m_strReplace, DLG_ENTRY_TEXT);
184 button = gtk_button_new ();
185 gtk_widget_show (button);
186 gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
187 (GtkAttachOptions) (GTK_FILL),
188 (GtkAttachOptions) (GTK_FILL), 0, 0);
189 gtk_signal_connect (GTK_OBJECT (button), "clicked",
190 GTK_SIGNAL_FUNC (find_clicked), entry);
192 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
193 gtk_widget_show (arrow);
194 gtk_container_add (GTK_CONTAINER (button), arrow);
196 check = gtk_check_button_new_with_label ("Use selected brushes only");
197 gtk_widget_show (check);
198 gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
199 AddDialogData (check, &m_bSelectedOnly, DLG_CHECK_BOOL);
201 check = gtk_check_button_new_with_label ("Replace everywhere (selected/active), don't test against Find");
202 gtk_widget_show (check);
203 gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
204 AddDialogData (check, &m_bForce, DLG_CHECK_BOOL);
206 check = gtk_check_button_new_with_label ("Live updates from Texture/Camera windows");
207 gtk_widget_show (check);
208 gtk_box_pack_start (GTK_BOX (vbox), check, TRUE, TRUE, 0);
209 AddDialogData (check, &m_bLive, DLG_CHECK_BOOL);
211 vbox = gtk_vbox_new (FALSE, 5);
212 gtk_widget_show (vbox);
213 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
215 button = gtk_button_new_with_label( "Find" );
216 gtk_widget_show( button );
217 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
218 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
219 GTK_SIGNAL_FUNC( OnFind ), NULL );
220 gtk_widget_set_usize( button, 60, -2 );
222 button = gtk_button_new_with_label ("OK");
223 gtk_widget_show (button);
224 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
225 gtk_signal_connect (GTK_OBJECT (button), "clicked",
226 GTK_SIGNAL_FUNC (OnOK), NULL);
227 gtk_widget_set_usize (button, 60, -2);
229 button = gtk_button_new_with_label ("Apply");
230 gtk_widget_show (button);
231 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
232 gtk_signal_connect (GTK_OBJECT (button), "clicked",
233 GTK_SIGNAL_FUNC (OnApply), NULL);
234 gtk_widget_set_usize (button, 60, -2);
236 button = gtk_button_new_with_label ("Close");
237 gtk_widget_show (button);
238 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
239 gtk_signal_connect (GTK_OBJECT (button), "clicked",
240 GTK_SIGNAL_FUNC (OnClose), NULL);
241 gtk_widget_set_usize (button, 60, -2);
243 gtk_widget_show (dlg);
246 void FindTextureDialog::updateTextures(const char *p)
261 bool FindTextureDialog::isOpen()
263 return (g_dlgFind.m_pWidget == NULL || GTK_WIDGET_VISIBLE (g_dlgFind.m_pWidget) == FALSE) ? false : true;
266 void FindTextureDialog::setFindStr(const char * p)
268 g_dlgFind.UpdateData(TRUE);
269 if (g_dlgFind.m_bLive)
271 g_dlgFind.m_strFind = p;
272 g_dlgFind.UpdateData(FALSE);
276 void FindTextureDialog::setReplaceStr(const char * p)
278 g_dlgFind.UpdateData(TRUE);
279 if (g_dlgFind.m_bLive)
281 g_dlgFind.m_strReplace = p;
282 g_dlgFind.UpdateData(FALSE);
286 void FindTextureDialog::show()
288 g_dlgFind.ShowDlg ();