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"
30 #include <glib/gi18n.h>
32 FindTextureDialog g_TexFindDlg;
33 FindTextureDialog& g_dlgFind = g_TexFindDlg;
34 static bool g_bFindActive = true;
36 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 ){
43 g_dlgFind.UpdateData( TRUE );
44 FindReplaceTextures( g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
45 g_dlgFind.m_bSelectedOnly, FALSE, TRUE );
48 static void OnOK( GtkWidget *widget, gpointer data ){
49 g_dlgFind.UpdateData( TRUE );
50 FindReplaceTextures( g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
51 g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE );
55 static void OnClose( GtkWidget *widget, gpointer data ){
59 static void popup_selected( GtkWidget *widget, gpointer data ){
62 gtk_label_get( GTK_LABEL( GTK_BIN( widget )->child ), &str );
63 gtk_entry_set_text( GTK_ENTRY( data ), str );
66 static void find_clicked( GtkWidget *widget, gpointer data ){
67 GtkWidget *menu, *item;
68 menu = gtk_menu_new();
70 for ( int i = 0; i < QERApp_GetActiveShaderCount(); i++ )
72 IShader *pShader = QERApp_ActiveShader_ForIndex( i );
74 item = gtk_menu_item_new_with_label( pShader->getName() );
75 gtk_signal_connect( GTK_OBJECT( item ), "activate", GTK_SIGNAL_FUNC( popup_selected ), data );
76 gtk_widget_show( item );
77 gtk_menu_append( GTK_MENU( menu ), item );
80 gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME );
83 static gint find_focus_in( GtkWidget *widget, GdkEventFocus *event, gpointer data ){
88 static gint replace_focus_in( GtkWidget *widget, GdkEventFocus *event, gpointer data ){
89 g_bFindActive = false;
93 // =============================================================================
94 // FindTextureDialog class
96 FindTextureDialog::FindTextureDialog (){
97 m_bSelectedOnly = FALSE;
104 FindTextureDialog::~FindTextureDialog (){
107 void FindTextureDialog::BuildDialog(){
108 GtkWidget *dlg, *vbox, *hbox, *table, *label;
109 GtkWidget *button, *check, *entry, *arrow;
112 gtk_window_set_title( GTK_WINDOW( dlg ), "Find / Replace Texture(s)" );
113 gtk_window_set_transient_for( GTK_WINDOW( dlg ), GTK_WINDOW( g_pParentWnd->m_pWidget ) );
115 hbox = gtk_hbox_new( FALSE, 5 );
116 gtk_widget_show( hbox );
117 gtk_container_add( GTK_CONTAINER( dlg ), hbox );
118 gtk_container_set_border_width( GTK_CONTAINER( hbox ), 5 );
120 vbox = gtk_vbox_new( FALSE, 5 );
121 gtk_widget_show( vbox );
122 gtk_box_pack_start( GTK_BOX( hbox ), vbox, TRUE, TRUE, 0 );
124 table = gtk_table_new( 2, 3, FALSE );
125 gtk_widget_show( table );
126 gtk_box_pack_start( GTK_BOX( vbox ), table, TRUE, TRUE, 0 );
127 gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
128 gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
130 label = gtk_label_new( "Find:" );
131 gtk_widget_show( label );
132 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 0, 1,
133 (GtkAttachOptions) ( GTK_FILL ),
134 (GtkAttachOptions) ( 0 ), 0, 0 );
135 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
137 label = gtk_label_new( "Replace:" );
138 gtk_widget_show( label );
139 gtk_table_attach( GTK_TABLE( table ), label, 0, 1, 1, 2,
140 (GtkAttachOptions) ( GTK_FILL ),
141 (GtkAttachOptions) ( 0 ), 0, 0 );
142 gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
144 entry = gtk_entry_new();
145 gtk_widget_show( entry );
146 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 0, 1,
147 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
148 (GtkAttachOptions) ( 0 ), 0, 0 );
149 gtk_signal_connect( GTK_OBJECT( entry ), "focus_in_event",
150 GTK_SIGNAL_FUNC( find_focus_in ), NULL );
151 AddDialogData( entry, &m_strFind, DLG_ENTRY_TEXT );
153 button = gtk_button_new();
154 gtk_widget_show( button );
155 gtk_table_attach( GTK_TABLE( table ), button, 2, 3, 0, 1,
156 (GtkAttachOptions) ( GTK_FILL ),
157 (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
158 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
159 GTK_SIGNAL_FUNC( find_clicked ), entry );
161 arrow = gtk_arrow_new( GTK_ARROW_DOWN, GTK_SHADOW_OUT );
162 gtk_widget_show( arrow );
163 gtk_container_add( GTK_CONTAINER( button ), arrow );
165 entry = gtk_entry_new();
166 gtk_widget_show( entry );
167 gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 1, 2,
168 (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
169 (GtkAttachOptions) ( 0 ), 0, 0 );
170 gtk_signal_connect( GTK_OBJECT( entry ), "focus_in_event",
171 GTK_SIGNAL_FUNC( replace_focus_in ), NULL );
172 AddDialogData( entry, &m_strReplace, DLG_ENTRY_TEXT );
174 button = gtk_button_new();
175 gtk_widget_show( button );
176 gtk_table_attach( GTK_TABLE( table ), button, 2, 3, 1, 2,
177 (GtkAttachOptions) ( GTK_FILL ),
178 (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
179 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
180 GTK_SIGNAL_FUNC( find_clicked ), entry );
182 arrow = gtk_arrow_new( GTK_ARROW_DOWN, GTK_SHADOW_OUT );
183 gtk_widget_show( arrow );
184 gtk_container_add( GTK_CONTAINER( button ), arrow );
186 check = gtk_check_button_new_with_label( "Use selected brushes only" );
187 gtk_widget_show( check );
188 gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
189 AddDialogData( check, &m_bSelectedOnly, DLG_CHECK_BOOL );
191 check = gtk_check_button_new_with_label( "Replace everywhere (selected/active), don't test against Find" );
192 gtk_widget_show( check );
193 gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
194 AddDialogData( check, &m_bForce, DLG_CHECK_BOOL );
196 check = gtk_check_button_new_with_label( "Live updates from Texture/Camera windows" );
197 gtk_widget_show( check );
198 gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
199 AddDialogData( check, &m_bLive, DLG_CHECK_BOOL );
201 vbox = gtk_vbox_new( FALSE, 5 );
202 gtk_widget_show( vbox );
203 gtk_box_pack_start( GTK_BOX( hbox ), vbox, TRUE, TRUE, 0 );
205 button = gtk_button_new_with_label( _( "Find" ) );
206 gtk_widget_show( button );
207 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
208 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
209 GTK_SIGNAL_FUNC( OnFind ), NULL );
210 gtk_widget_set_usize( button, 60, -2 );
212 button = gtk_button_new_with_label( _( "OK" ) );
213 gtk_widget_show( button );
214 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
215 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
216 GTK_SIGNAL_FUNC( OnOK ), NULL );
217 gtk_widget_set_usize( button, 60, -2 );
219 button = gtk_button_new_with_label( _( "Apply" ) );
220 gtk_widget_show( button );
221 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
222 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
223 GTK_SIGNAL_FUNC( OnApply ), NULL );
224 gtk_widget_set_usize( button, 60, -2 );
226 button = gtk_button_new_with_label( _( "Close" ) );
227 gtk_widget_show( button );
228 gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
229 gtk_signal_connect( GTK_OBJECT( button ), "clicked",
230 GTK_SIGNAL_FUNC( OnClose ), NULL );
231 gtk_widget_set_usize( button, 60, -2 );
233 gtk_widget_show( dlg );
236 void FindTextureDialog::updateTextures( const char *p ){
238 if ( g_bFindActive ) {
248 bool FindTextureDialog::isOpen(){
249 return ( g_dlgFind.m_pWidget == NULL || GTK_WIDGET_VISIBLE( g_dlgFind.m_pWidget ) == FALSE ) ? false : true;
252 void FindTextureDialog::setFindStr( const char * p ){
253 g_dlgFind.UpdateData( TRUE );
254 if ( g_dlgFind.m_bLive ) {
255 g_dlgFind.m_strFind = p;
256 g_dlgFind.UpdateData( FALSE );
260 void FindTextureDialog::setReplaceStr( const char * p ){
261 g_dlgFind.UpdateData( TRUE );
262 if ( g_dlgFind.m_bLive ) {
263 g_dlgFind.m_strReplace = p;
264 g_dlgFind.UpdateData( FALSE );
268 void FindTextureDialog::show(){