2 Copyright (C) 1999-2006 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)
28 #include "findtexturedialog.h"
32 #include "debugging/debugging.h"
36 #include "gtkutil/window.h"
37 #include "stream/stringstream.h"
42 #include "textureentry.h"
46 class FindTextureDialog : public Dialog
49 static void setReplaceStr( const char* name );
50 static void setFindStr( const char* name );
53 typedef FreeCaller<void(), &FindTextureDialog::show> ShowCaller;
54 static void updateTextures( const char* name );
57 virtual ~FindTextureDialog();
58 ui::Window BuildDialog();
60 void constructWindow( ui::Window parent ){
70 CopiedString m_strFind;
71 CopiedString m_strReplace;
74 FindTextureDialog g_FindTextureDialog;
75 static bool g_bFindActive = true;
79 void FindTextureDialog_apply(){
80 StringOutputStream find( 256 );
81 StringOutputStream replace( 256 );
83 find << "textures/" << g_FindTextureDialog.m_strFind.c_str();
84 replace << "textures/" << g_FindTextureDialog.m_strReplace.c_str();
85 FindReplaceTextures( find.c_str(), replace.c_str(), g_FindTextureDialog.m_bSelectedOnly );
88 static void OnApply( ui::Widget widget, gpointer data ){
89 g_FindTextureDialog.exportData();
90 FindTextureDialog_apply();
93 static void OnFind( ui::Widget widget, gpointer data ){
94 g_FindTextureDialog.exportData();
95 FindTextureDialog_apply();
98 static void OnOK( ui::Widget widget, gpointer data ){
99 g_FindTextureDialog.exportData();
100 FindTextureDialog_apply();
101 g_FindTextureDialog.HideDlg();
104 static void OnClose( ui::Widget widget, gpointer data ){
105 g_FindTextureDialog.HideDlg();
109 static gint find_focus_in( ui::Widget widget, GdkEventFocus *event, gpointer data ){
110 g_bFindActive = true;
114 static gint replace_focus_in( ui::Widget widget, GdkEventFocus *event, gpointer data ){
115 g_bFindActive = false;
120 // =============================================================================
121 // FindTextureDialog class
123 FindTextureDialog::FindTextureDialog(){
124 m_bSelectedOnly = FALSE;
127 FindTextureDialog::~FindTextureDialog(){
130 ui::Window FindTextureDialog::BuildDialog(){
131 ui::Widget label{ui::null};
132 ui::Widget button{ui::null};
133 ui::Entry entry{ui::null};
135 auto dlg = ui::Window(create_floating_window( "Find / Replace Texture(s)", m_parent ));
137 auto hbox = ui::HBox( FALSE, 5 );
140 gtk_container_set_border_width( GTK_CONTAINER( hbox ), 5 );
142 auto vbox = ui::VBox( FALSE, 5 );
144 hbox.pack_start( vbox, TRUE, TRUE, 0 );
146 auto table = ui::Table(2, 2, FALSE);
148 vbox.pack_start( table, TRUE, TRUE, 0 );
149 gtk_table_set_row_spacings(table, 5);
150 gtk_table_set_col_spacings(table, 5);
152 label = ui::Label( "Find:" );
154 table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
155 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
157 label = ui::Label( "Replace:" );
159 table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
160 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
162 entry = ui::Entry(ui::New);
164 table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
165 entry.connect( "focus_in_event",
166 G_CALLBACK( find_focus_in ), 0 );
167 AddDialogData( entry, m_strFind );
168 GlobalTextureEntryCompletion::instance().connect( entry );
170 entry = ui::Entry(ui::New);
172 table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
173 entry.connect( "focus_in_event",
174 G_CALLBACK( replace_focus_in ), 0 );
175 AddDialogData( entry, m_strReplace );
176 GlobalTextureEntryCompletion::instance().connect( entry );
178 auto check = ui::CheckButton( "Within selected brushes only" );
180 vbox.pack_start( check, TRUE, TRUE, 0 );
181 AddDialogData( check, m_bSelectedOnly );
183 vbox = ui::VBox( FALSE, 5 );
185 hbox.pack_start( vbox, FALSE, FALSE, 0 );
187 button = ui::Button( "Apply" );
189 vbox.pack_start( button, FALSE, FALSE, 0 );
190 button.connect( "clicked",
191 G_CALLBACK( OnApply ), 0 );
192 button.dimensions(60, -1);
194 button = ui::Button( "Close" );
196 vbox.pack_start( button, FALSE, FALSE, 0 );
197 button.connect( "clicked",
198 G_CALLBACK( OnClose ), 0 );
199 button.dimensions(60, -1);
204 void FindTextureDialog::updateTextures( const char* name ){
206 if ( g_bFindActive ) {
207 setFindStr( name + 9 );
211 setReplaceStr( name + 9 );
216 bool FindTextureDialog::isOpen(){
217 return g_FindTextureDialog.GetWidget().visible();
220 void FindTextureDialog::setFindStr( const char* name ){
221 g_FindTextureDialog.exportData();
222 g_FindTextureDialog.m_strFind = name;
223 g_FindTextureDialog.importData();
226 void FindTextureDialog::setReplaceStr( const char* name ){
227 g_FindTextureDialog.exportData();
228 g_FindTextureDialog.m_strReplace = name;
229 g_FindTextureDialog.importData();
232 void FindTextureDialog::show(){
233 g_FindTextureDialog.ShowDlg();
237 void FindTextureDialog_constructWindow( ui::Window main_window ){
238 g_FindTextureDialog.constructWindow( main_window );
241 void FindTextureDialog_destroyWindow(){
242 g_FindTextureDialog.destroyWindow();
245 bool FindTextureDialog_isOpen(){
246 return g_FindTextureDialog.isOpen();
249 void FindTextureDialog_selectTexture( const char* name ){
250 g_FindTextureDialog.updateTextures( name );
253 void FindTextureDialog_Construct(){
254 GlobalCommands_insert( "FindReplaceTextures", FindTextureDialog::ShowCaller() );
257 void FindTextureDialog_Destroy(){