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;
130 ui::Widget button, check, entry;
132 ui::Window dlg = ui::Window(create_floating_window( "Find / Replace Texture(s)", m_parent ));
134 hbox = ui::HBox( FALSE, 5 );
136 gtk_container_add( GTK_CONTAINER( dlg ), GTK_WIDGET( hbox ) );
137 gtk_container_set_border_width( GTK_CONTAINER( hbox ), 5 );
139 vbox = ui::VBox( FALSE, 5 );
141 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
143 table = ui::Table( 2, 2, FALSE );
145 gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
146 gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
147 gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
149 label = ui::Label( "Find:" );
151 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
152 (GtkAttachOptions) ( GTK_FILL ),
153 (GtkAttachOptions) ( 0 ), 0, 0 );
154 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
156 label = ui::Label( "Replace:" );
158 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2,
159 (GtkAttachOptions) ( GTK_FILL ),
160 (GtkAttachOptions) ( 0 ), 0, 0 );
161 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
165 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 0, 1,
166 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
167 (GtkAttachOptions) ( 0 ), 0, 0 );
168 g_signal_connect( G_OBJECT( entry ), "focus_in_event",
169 G_CALLBACK( find_focus_in ), 0 );
170 AddDialogData( *GTK_ENTRY( entry ), m_strFind );
171 GlobalTextureEntryCompletion::instance().connect( GTK_ENTRY( entry ) );
175 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 1, 2,
176 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
177 (GtkAttachOptions) ( 0 ), 0, 0 );
178 g_signal_connect( G_OBJECT( entry ), "focus_in_event",
179 G_CALLBACK( replace_focus_in ), 0 );
180 AddDialogData( *GTK_ENTRY( entry ), m_strReplace );
181 GlobalTextureEntryCompletion::instance().connect( GTK_ENTRY( entry ) );
183 check = ui::CheckButton( "Within selected brushes only" );
185 gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
186 AddDialogData( *GTK_TOGGLE_BUTTON( check ), m_bSelectedOnly );
188 vbox = ui::VBox( FALSE, 5 );
190 gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
192 button = ui::Button( "Apply" );
194 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
195 g_signal_connect( G_OBJECT( button ), "clicked",
196 G_CALLBACK( OnApply ), 0 );
197 gtk_widget_set_size_request( button, 60, -1 );
199 button = ui::Button( "Close" );
201 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
202 g_signal_connect( G_OBJECT( button ), "clicked",
203 G_CALLBACK( OnClose ), 0 );
204 gtk_widget_set_size_request( button, 60, -1 );
209 void FindTextureDialog::updateTextures( const char* name ){
211 if ( g_bFindActive ) {
212 setFindStr( name + 9 );
216 setReplaceStr( name + 9 );
221 bool FindTextureDialog::isOpen(){
222 return gtk_widget_get_visible( g_FindTextureDialog.GetWidget() ) == TRUE;
225 void FindTextureDialog::setFindStr( const char* name ){
226 g_FindTextureDialog.exportData();
227 g_FindTextureDialog.m_strFind = name;
228 g_FindTextureDialog.importData();
231 void FindTextureDialog::setReplaceStr( const char* name ){
232 g_FindTextureDialog.exportData();
233 g_FindTextureDialog.m_strReplace = name;
234 g_FindTextureDialog.importData();
237 void FindTextureDialog::show(){
238 g_FindTextureDialog.ShowDlg();
242 void FindTextureDialog_constructWindow( ui::Window main_window ){
243 g_FindTextureDialog.constructWindow( main_window );
246 void FindTextureDialog_destroyWindow(){
247 g_FindTextureDialog.destroyWindow();
250 bool FindTextureDialog_isOpen(){
251 return g_FindTextureDialog.isOpen();
254 void FindTextureDialog_selectTexture( const char* name ){
255 g_FindTextureDialog.updateTextures( name );
258 void FindTextureDialog_Construct(){
259 GlobalCommands_insert( "FindReplaceTextures", FindTextureDialog::ShowCaller() );
262 void FindTextureDialog_Destroy(){