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"
30 #include "debugging/debugging.h"
34 #include "gtkutil/window.h"
35 #include "stream/stringstream.h"
40 #include "textureentry.h"
44 class FindTextureDialog : public Dialog
47 static void setReplaceStr( const char* name );
48 static void setFindStr( const char* name );
51 typedef FreeCaller<&FindTextureDialog::show> ShowCaller;
52 static void updateTextures( const char* name );
55 virtual ~FindTextureDialog();
56 ui::Window BuildDialog();
58 void constructWindow( ui::Window parent ){
68 CopiedString m_strFind;
69 CopiedString m_strReplace;
72 FindTextureDialog g_FindTextureDialog;
73 static bool g_bFindActive = true;
77 void FindTextureDialog_apply(){
78 StringOutputStream find( 256 );
79 StringOutputStream replace( 256 );
81 find << "textures/" << g_FindTextureDialog.m_strFind.c_str();
82 replace << "textures/" << g_FindTextureDialog.m_strReplace.c_str();
83 FindReplaceTextures( find.c_str(), replace.c_str(), g_FindTextureDialog.m_bSelectedOnly );
86 static void OnApply( ui::Widget widget, gpointer data ){
87 g_FindTextureDialog.exportData();
88 FindTextureDialog_apply();
91 static void OnFind( GtkWidget* widget, gpointer data ){
92 g_FindTextureDialog.exportData();
93 FindTextureDialog_apply();
96 static void OnOK( GtkWidget* widget, gpointer data ){
97 g_FindTextureDialog.exportData();
98 FindTextureDialog_apply();
99 g_FindTextureDialog.HideDlg();
102 static void OnClose( ui::Widget widget, gpointer data ){
103 g_FindTextureDialog.HideDlg();
107 static gint find_focus_in( ui::Widget widget, GdkEventFocus *event, gpointer data ){
108 g_bFindActive = true;
112 static gint replace_focus_in( ui::Widget widget, GdkEventFocus *event, gpointer data ){
113 g_bFindActive = false;
118 // =============================================================================
119 // FindTextureDialog class
121 FindTextureDialog::FindTextureDialog(){
122 m_bSelectedOnly = FALSE;
125 FindTextureDialog::~FindTextureDialog(){
128 ui::Window FindTextureDialog::BuildDialog(){
129 ui::Widget vbox, hbox, table, label;
131 ui::Entry entry{nullptr};
133 auto dlg = ui::Window(create_floating_window( "Find / Replace Texture(s)", m_parent ));
135 hbox = ui::HBox( FALSE, 5 );
138 gtk_container_set_border_width( GTK_CONTAINER( hbox ), 5 );
140 vbox = ui::VBox( FALSE, 5 );
142 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
144 table = ui::Table( 2, 2, FALSE );
146 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
147 gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
148 gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
150 label = ui::Label( "Find:" );
152 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
153 (GtkAttachOptions) ( GTK_FILL ),
154 (GtkAttachOptions) ( 0 ), 0, 0 );
155 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
157 label = ui::Label( "Replace:" );
159 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2,
160 (GtkAttachOptions) ( GTK_FILL ),
161 (GtkAttachOptions) ( 0 ), 0, 0 );
162 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
166 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 0, 1,
167 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
168 (GtkAttachOptions) ( 0 ), 0, 0 );
169 g_signal_connect( G_OBJECT( entry ), "focus_in_event",
170 G_CALLBACK( find_focus_in ), 0 );
171 AddDialogData( *GTK_ENTRY(entry), m_strFind );
172 GlobalTextureEntryCompletion::instance().connect( entry );
176 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 1, 2,
177 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
178 (GtkAttachOptions) ( 0 ), 0, 0 );
179 g_signal_connect( G_OBJECT( entry ), "focus_in_event",
180 G_CALLBACK( replace_focus_in ), 0 );
181 AddDialogData( *GTK_ENTRY(entry), m_strReplace );
182 GlobalTextureEntryCompletion::instance().connect( entry );
184 auto check = ui::CheckButton( "Within selected brushes only" );
186 gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
187 AddDialogData( *GTK_TOGGLE_BUTTON(check), m_bSelectedOnly );
189 vbox = ui::VBox( FALSE, 5 );
191 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
193 button = ui::Button( "Apply" );
195 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
196 g_signal_connect( G_OBJECT( button ), "clicked",
197 G_CALLBACK( OnApply ), 0 );
198 gtk_widget_set_size_request( button, 60, -1 );
200 button = ui::Button( "Close" );
202 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
203 g_signal_connect( G_OBJECT( button ), "clicked",
204 G_CALLBACK( OnClose ), 0 );
205 gtk_widget_set_size_request( button, 60, -1 );
210 void FindTextureDialog::updateTextures( const char* name ){
212 if ( g_bFindActive ) {
213 setFindStr( name + 9 );
217 setReplaceStr( name + 9 );
222 bool FindTextureDialog::isOpen(){
223 return gtk_widget_get_visible( g_FindTextureDialog.GetWidget() ) == TRUE;
226 void FindTextureDialog::setFindStr( const char* name ){
227 g_FindTextureDialog.exportData();
228 g_FindTextureDialog.m_strFind = name;
229 g_FindTextureDialog.importData();
232 void FindTextureDialog::setReplaceStr( const char* name ){
233 g_FindTextureDialog.exportData();
234 g_FindTextureDialog.m_strReplace = name;
235 g_FindTextureDialog.importData();
238 void FindTextureDialog::show(){
239 g_FindTextureDialog.ShowDlg();
243 void FindTextureDialog_constructWindow( ui::Window main_window ){
244 g_FindTextureDialog.constructWindow( main_window );
247 void FindTextureDialog_destroyWindow(){
248 g_FindTextureDialog.destroyWindow();
251 bool FindTextureDialog_isOpen(){
252 return g_FindTextureDialog.isOpen();
255 void FindTextureDialog_selectTexture( const char* name ){
256 g_FindTextureDialog.updateTextures( name );
259 void FindTextureDialog_Construct(){
260 GlobalCommands_insert( "FindReplaceTextures", FindTextureDialog::ShowCaller() );
263 void FindTextureDialog_Destroy(){