/*
- Copyright (C) 1999-2007 id Software, Inc. and contributors.
+ Copyright (C) 1999-2006 Id Software, Inc. and contributors.
For a list of contributors, see the accompanying CONTRIBUTORS file.
This file is part of GtkRadiant.
// Leonardo Zide (leo@lokigames.com)
//
-#include "stdafx.h"
#include "findtexturedialog.h"
-#include <glib/gi18n.h>
-FindTextureDialog g_TexFindDlg;
-FindTextureDialog& g_dlgFind = g_TexFindDlg;
-static bool g_bFindActive = true;
-
-static void OnApply( GtkWidget *widget, gpointer data ){
- g_dlgFind.UpdateData( TRUE );
- FindReplaceTextures( g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
- g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE );
+#include "debugging/debugging.h"
+
+#include "ishaders.h"
+
+#include <gtk/gtkhbox.h>
+#include <gtk/gtkentry.h>
+#include <gtk/gtkvbox.h>
+#include <gtk/gtkframe.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtktable.h>
+#include <gtk/gtkbutton.h>
+#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkcheckbutton.h>
+#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkarrow.h>
+
+#include "gtkutil/window.h"
+#include "stream/stringstream.h"
+
+#include "commands.h"
+#include "dialog.h"
+#include "select.h"
+#include "textureentry.h"
+
+
+
+class FindTextureDialog : public Dialog
+{
+public:
+static void setReplaceStr( const char* name );
+static void setFindStr( const char* name );
+static bool isOpen();
+static void show();
+typedef FreeCaller<&FindTextureDialog::show> ShowCaller;
+static void updateTextures( const char* name );
+
+FindTextureDialog();
+virtual ~FindTextureDialog();
+GtkWindow* BuildDialog();
+
+void constructWindow( GtkWindow* parent ){
+ m_parent = parent;
+ Create();
}
-
-static void OnFind( GtkWidget *widget, gpointer data ){
- g_dlgFind.UpdateData( TRUE );
- FindReplaceTextures( g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
- g_dlgFind.m_bSelectedOnly, FALSE, TRUE );
+void destroyWindow(){
+ Destroy();
}
-static void OnOK( GtkWidget *widget, gpointer data ){
- g_dlgFind.UpdateData( TRUE );
- FindReplaceTextures( g_dlgFind.m_strFind, g_dlgFind.m_strReplace,
- g_dlgFind.m_bSelectedOnly, g_dlgFind.m_bForce, FALSE );
- g_dlgFind.HideDlg();
-}
-static void OnClose( GtkWidget *widget, gpointer data ){
- g_dlgFind.HideDlg();
-}
+bool m_bSelectedOnly;
+CopiedString m_strFind;
+CopiedString m_strReplace;
+};
+
+FindTextureDialog g_FindTextureDialog;
+static bool g_bFindActive = true;
-static void popup_selected( GtkWidget *widget, gpointer data ){
- gchar *str;
+namespace
+{
+void FindTextureDialog_apply(){
+ StringOutputStream find( 256 );
+ StringOutputStream replace( 256 );
- gtk_label_get( GTK_LABEL( GTK_BIN( widget )->child ), &str );
- gtk_entry_set_text( GTK_ENTRY( data ), str );
+ find << "textures/" << g_FindTextureDialog.m_strFind.c_str();
+ replace << "textures/" << g_FindTextureDialog.m_strReplace.c_str();
+ FindReplaceTextures( find.c_str(), replace.c_str(), g_FindTextureDialog.m_bSelectedOnly );
}
-static void find_clicked( GtkWidget *widget, gpointer data ){
- GtkWidget *menu, *item;
- menu = gtk_menu_new();
+static void OnApply( GtkWidget* widget, gpointer data ){
+ g_FindTextureDialog.exportData();
+ FindTextureDialog_apply();
+}
- for ( int i = 0; i < QERApp_GetActiveShaderCount(); i++ )
- {
- IShader *pShader = QERApp_ActiveShader_ForIndex( i );
+static void OnFind( GtkWidget* widget, gpointer data ){
+ g_FindTextureDialog.exportData();
+ FindTextureDialog_apply();
+}
- item = gtk_menu_item_new_with_label( pShader->getName() );
- gtk_signal_connect( GTK_OBJECT( item ), "activate", GTK_SIGNAL_FUNC( popup_selected ), data );
- gtk_widget_show( item );
- gtk_menu_append( GTK_MENU( menu ), item );
- }
+static void OnOK( GtkWidget* widget, gpointer data ){
+ g_FindTextureDialog.exportData();
+ FindTextureDialog_apply();
+ g_FindTextureDialog.HideDlg();
+}
- gtk_menu_popup( GTK_MENU( menu ), NULL, NULL, NULL, NULL, 1, GDK_CURRENT_TIME );
+static void OnClose( GtkWidget* widget, gpointer data ){
+ g_FindTextureDialog.HideDlg();
}
-static gint find_focus_in( GtkWidget *widget, GdkEventFocus *event, gpointer data ){
+
+static gint find_focus_in( GtkWidget* widget, GdkEventFocus *event, gpointer data ){
g_bFindActive = true;
return FALSE;
}
-static gint replace_focus_in( GtkWidget *widget, GdkEventFocus *event, gpointer data ){
+static gint replace_focus_in( GtkWidget* widget, GdkEventFocus *event, gpointer data ){
g_bFindActive = false;
return FALSE;
}
+}
// =============================================================================
// FindTextureDialog class
-FindTextureDialog::FindTextureDialog (){
+FindTextureDialog::FindTextureDialog(){
m_bSelectedOnly = FALSE;
- m_strFind = "";
- m_strReplace = "";
- m_bForce = FALSE;
- m_bLive = TRUE;
}
-FindTextureDialog::~FindTextureDialog (){
+FindTextureDialog::~FindTextureDialog(){
}
-void FindTextureDialog::BuildDialog(){
- GtkWidget *dlg, *vbox, *hbox, *table, *label;
- GtkWidget *button, *check, *entry, *arrow;
+GtkWindow* FindTextureDialog::BuildDialog(){
+ GtkWidget* vbox, *hbox, *table, *label;
+ GtkWidget* button, *check, *entry;
- dlg = m_pWidget;
- gtk_window_set_title( GTK_WINDOW( dlg ), "Find / Replace Texture(s)" );
- gtk_window_set_transient_for( GTK_WINDOW( dlg ), GTK_WINDOW( g_pParentWnd->m_pWidget ) );
+ GtkWindow* dlg = create_floating_window( "Find / Replace Texture(s)", m_parent );
hbox = gtk_hbox_new( FALSE, 5 );
gtk_widget_show( hbox );
- gtk_container_add( GTK_CONTAINER( dlg ), hbox );
+ gtk_container_add( GTK_CONTAINER( dlg ), GTK_WIDGET( hbox ) );
gtk_container_set_border_width( GTK_CONTAINER( hbox ), 5 );
vbox = gtk_vbox_new( FALSE, 5 );
gtk_widget_show( vbox );
- gtk_box_pack_start( GTK_BOX( hbox ), vbox, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
- table = gtk_table_new( 2, 3, FALSE );
+ table = gtk_table_new( 2, 2, FALSE );
gtk_widget_show( table );
- gtk_box_pack_start( GTK_BOX( vbox ), table, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
gtk_table_set_row_spacings( GTK_TABLE( table ), 5 );
gtk_table_set_col_spacings( GTK_TABLE( table ), 5 );
gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 0, 1,
(GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
(GtkAttachOptions) ( 0 ), 0, 0 );
- gtk_signal_connect( GTK_OBJECT( entry ), "focus_in_event",
- GTK_SIGNAL_FUNC( find_focus_in ), NULL );
- AddDialogData( entry, &m_strFind, DLG_ENTRY_TEXT );
-
- button = gtk_button_new();
- gtk_widget_show( button );
- gtk_table_attach( GTK_TABLE( table ), button, 2, 3, 0, 1,
- (GtkAttachOptions) ( GTK_FILL ),
- (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
- gtk_signal_connect( GTK_OBJECT( button ), "clicked",
- GTK_SIGNAL_FUNC( find_clicked ), entry );
-
- arrow = gtk_arrow_new( GTK_ARROW_DOWN, GTK_SHADOW_OUT );
- gtk_widget_show( arrow );
- gtk_container_add( GTK_CONTAINER( button ), arrow );
+ g_signal_connect( G_OBJECT( entry ), "focus_in_event",
+ G_CALLBACK( find_focus_in ), 0 );
+ AddDialogData( *GTK_ENTRY( entry ), m_strFind );
+ GlobalTextureEntryCompletion::instance().connect( GTK_ENTRY( entry ) );
entry = gtk_entry_new();
gtk_widget_show( entry );
gtk_table_attach( GTK_TABLE( table ), entry, 1, 2, 1, 2,
(GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
(GtkAttachOptions) ( 0 ), 0, 0 );
- gtk_signal_connect( GTK_OBJECT( entry ), "focus_in_event",
- GTK_SIGNAL_FUNC( replace_focus_in ), NULL );
- AddDialogData( entry, &m_strReplace, DLG_ENTRY_TEXT );
-
- button = gtk_button_new();
- gtk_widget_show( button );
- gtk_table_attach( GTK_TABLE( table ), button, 2, 3, 1, 2,
- (GtkAttachOptions) ( GTK_FILL ),
- (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
- gtk_signal_connect( GTK_OBJECT( button ), "clicked",
- GTK_SIGNAL_FUNC( find_clicked ), entry );
-
- arrow = gtk_arrow_new( GTK_ARROW_DOWN, GTK_SHADOW_OUT );
- gtk_widget_show( arrow );
- gtk_container_add( GTK_CONTAINER( button ), arrow );
-
- check = gtk_check_button_new_with_label( "Use selected brushes only" );
- gtk_widget_show( check );
- gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
- AddDialogData( check, &m_bSelectedOnly, DLG_CHECK_BOOL );
-
- check = gtk_check_button_new_with_label( "Replace everywhere (selected/active), don't test against Find" );
- gtk_widget_show( check );
- gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
- AddDialogData( check, &m_bForce, DLG_CHECK_BOOL );
+ g_signal_connect( G_OBJECT( entry ), "focus_in_event",
+ G_CALLBACK( replace_focus_in ), 0 );
+ AddDialogData( *GTK_ENTRY( entry ), m_strReplace );
+ GlobalTextureEntryCompletion::instance().connect( GTK_ENTRY( entry ) );
- check = gtk_check_button_new_with_label( "Live updates from Texture/Camera windows" );
+ check = gtk_check_button_new_with_label( "Within selected brushes only" );
gtk_widget_show( check );
gtk_box_pack_start( GTK_BOX( vbox ), check, TRUE, TRUE, 0 );
- AddDialogData( check, &m_bLive, DLG_CHECK_BOOL );
+ AddDialogData( *GTK_TOGGLE_BUTTON( check ), m_bSelectedOnly );
vbox = gtk_vbox_new( FALSE, 5 );
gtk_widget_show( vbox );
- gtk_box_pack_start( GTK_BOX( hbox ), vbox, TRUE, TRUE, 0 );
+ gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
- button = gtk_button_new_with_label( _( "Find" ) );
+ button = gtk_button_new_with_label( "Apply" );
gtk_widget_show( button );
gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
- gtk_signal_connect( GTK_OBJECT( button ), "clicked",
- GTK_SIGNAL_FUNC( OnFind ), NULL );
+ g_signal_connect( G_OBJECT( button ), "clicked",
+ G_CALLBACK( OnApply ), 0 );
gtk_widget_set_usize( button, 60, -2 );
- button = gtk_button_new_with_label( _( "OK" ) );
+ button = gtk_button_new_with_label( "Close" );
gtk_widget_show( button );
gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
- gtk_signal_connect( GTK_OBJECT( button ), "clicked",
- GTK_SIGNAL_FUNC( OnOK ), NULL );
+ g_signal_connect( G_OBJECT( button ), "clicked",
+ G_CALLBACK( OnClose ), 0 );
gtk_widget_set_usize( button, 60, -2 );
- button = gtk_button_new_with_label( _( "Apply" ) );
- gtk_widget_show( button );
- gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
- gtk_signal_connect( GTK_OBJECT( button ), "clicked",
- GTK_SIGNAL_FUNC( OnApply ), NULL );
- gtk_widget_set_usize( button, 60, -2 );
-
- button = gtk_button_new_with_label( _( "Close" ) );
- gtk_widget_show( button );
- gtk_box_pack_start( GTK_BOX( vbox ), button, FALSE, FALSE, 0 );
- gtk_signal_connect( GTK_OBJECT( button ), "clicked",
- GTK_SIGNAL_FUNC( OnClose ), NULL );
- gtk_widget_set_usize( button, 60, -2 );
-
- gtk_widget_show( dlg );
+ return dlg;
}
-void FindTextureDialog::updateTextures( const char *p ){
+void FindTextureDialog::updateTextures( const char* name ){
if ( isOpen() ) {
if ( g_bFindActive ) {
- setFindStr( p );
+ setFindStr( name + 9 );
}
else
{
- setReplaceStr( p );
+ setReplaceStr( name + 9 );
}
}
}
bool FindTextureDialog::isOpen(){
- return ( g_dlgFind.m_pWidget == NULL || GTK_WIDGET_VISIBLE( g_dlgFind.m_pWidget ) == FALSE ) ? false : true;
+ return GTK_WIDGET_VISIBLE( g_FindTextureDialog.GetWidget() ) == TRUE;
}
-void FindTextureDialog::setFindStr( const char * p ){
- g_dlgFind.UpdateData( TRUE );
- if ( g_dlgFind.m_bLive ) {
- g_dlgFind.m_strFind = p;
- g_dlgFind.UpdateData( FALSE );
- }
+void FindTextureDialog::setFindStr( const char* name ){
+ g_FindTextureDialog.exportData();
+ g_FindTextureDialog.m_strFind = name;
+ g_FindTextureDialog.importData();
}
-void FindTextureDialog::setReplaceStr( const char * p ){
- g_dlgFind.UpdateData( TRUE );
- if ( g_dlgFind.m_bLive ) {
- g_dlgFind.m_strReplace = p;
- g_dlgFind.UpdateData( FALSE );
- }
+void FindTextureDialog::setReplaceStr( const char* name ){
+ g_FindTextureDialog.exportData();
+ g_FindTextureDialog.m_strReplace = name;
+ g_FindTextureDialog.importData();
}
void FindTextureDialog::show(){
- g_dlgFind.ShowDlg();
+ g_FindTextureDialog.ShowDlg();
+}
+
+
+void FindTextureDialog_constructWindow( GtkWindow* main_window ){
+ g_FindTextureDialog.constructWindow( main_window );
+}
+
+void FindTextureDialog_destroyWindow(){
+ g_FindTextureDialog.destroyWindow();
+}
+
+bool FindTextureDialog_isOpen(){
+ return g_FindTextureDialog.isOpen();
+}
+
+void FindTextureDialog_selectTexture( const char* name ){
+ g_FindTextureDialog.updateTextures( name );
+}
+
+void FindTextureDialog_Construct(){
+ GlobalCommands_insert( "FindReplaceTextures", FindTextureDialog::ShowCaller() );
+}
+
+void FindTextureDialog_Destroy(){
}