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<&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( GtkWidget* widget, gpointer data ){
94 g_FindTextureDialog.exportData();
95 FindTextureDialog_apply();
98 static void OnOK( GtkWidget* 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 vbox{ui::null}, hbox{ui::null}, table{ui::null}, 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 hbox = ui::HBox( FALSE, 5 );
140 gtk_container_set_border_width( GTK_CONTAINER( hbox ), 5 );
142 vbox = ui::VBox( FALSE, 5 );
144 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
146 table = ui::Table( 2, 2, FALSE );
148 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
149 gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
150 gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
152 label = ui::Label( "Find:" );
154 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
155 (GtkAttachOptions) ( GTK_FILL ),
156 (GtkAttachOptions) ( 0 ), 0, 0 );
157 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
159 label = ui::Label( "Replace:" );
161 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2,
162 (GtkAttachOptions) ( GTK_FILL ),
163 (GtkAttachOptions) ( 0 ), 0, 0 );
164 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
166 entry = ui::Entry(ui::New);
168 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 0, 1,
169 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
170 (GtkAttachOptions) ( 0 ), 0, 0 );
171 entry.connect( "focus_in_event",
172 G_CALLBACK( find_focus_in ), 0 );
173 AddDialogData( *GTK_ENTRY(entry), m_strFind );
174 GlobalTextureEntryCompletion::instance().connect( entry );
176 entry = ui::Entry(ui::New);
178 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 1, 2,
179 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
180 (GtkAttachOptions) ( 0 ), 0, 0 );
181 entry.connect( "focus_in_event",
182 G_CALLBACK( replace_focus_in ), 0 );
183 AddDialogData( *GTK_ENTRY(entry), m_strReplace );
184 GlobalTextureEntryCompletion::instance().connect( entry );
186 auto check = ui::CheckButton( "Within selected brushes only" );
188 gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
189 AddDialogData( *GTK_TOGGLE_BUTTON(check), m_bSelectedOnly );
191 vbox = ui::VBox( FALSE, 5 );
193 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
195 button = ui::Button( "Apply" );
197 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
198 button.connect( "clicked",
199 G_CALLBACK( OnApply ), 0 );
200 gtk_widget_set_size_request( button, 60, -1 );
202 button = ui::Button( "Close" );
204 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
205 button.connect( "clicked",
206 G_CALLBACK( OnClose ), 0 );
207 gtk_widget_set_size_request( button, 60, -1 );
212 void FindTextureDialog::updateTextures( const char* name ){
214 if ( g_bFindActive ) {
215 setFindStr( name + 9 );
219 setReplaceStr( name + 9 );
224 bool FindTextureDialog::isOpen(){
225 return g_FindTextureDialog.GetWidget().visible();
228 void FindTextureDialog::setFindStr( const char* name ){
229 g_FindTextureDialog.exportData();
230 g_FindTextureDialog.m_strFind = name;
231 g_FindTextureDialog.importData();
234 void FindTextureDialog::setReplaceStr( const char* name ){
235 g_FindTextureDialog.exportData();
236 g_FindTextureDialog.m_strReplace = name;
237 g_FindTextureDialog.importData();
240 void FindTextureDialog::show(){
241 g_FindTextureDialog.ShowDlg();
245 void FindTextureDialog_constructWindow( ui::Window main_window ){
246 g_FindTextureDialog.constructWindow( main_window );
249 void FindTextureDialog_destroyWindow(){
250 g_FindTextureDialog.destroyWindow();
253 bool FindTextureDialog_isOpen(){
254 return g_FindTextureDialog.isOpen();
257 void FindTextureDialog_selectTexture( const char* name ){
258 g_FindTextureDialog.updateTextures( name );
261 void FindTextureDialog_Construct(){
262 GlobalCommands_insert( "FindReplaceTextures", FindTextureDialog::ShowCaller() );
265 void FindTextureDialog_Destroy(){