From f893b9a7898a21c9f02f6e1d464ebfac0d58d6f0 Mon Sep 17 00:00:00 2001 From: Garux Date: Sat, 4 Jan 2020 20:05:01 +0300 Subject: [PATCH] * brushexport plugin: add Save button to reexport to recently specified file directly --- contrib/brushexport/callbacks.cpp | 27 ++++++++++++++++++++------- contrib/brushexport/interface.cpp | 10 +++++++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/contrib/brushexport/callbacks.cpp b/contrib/brushexport/callbacks.cpp index 379a21a8..ea1471ff 100644 --- a/contrib/brushexport/callbacks.cpp +++ b/contrib/brushexport/callbacks.cpp @@ -12,7 +12,6 @@ void DestroyWindow(); //! TODO add tooltip for ignore: shader name after last slash, case sensitive // or make insensitive //! TODO add ignore mat on ENTER, del on del -//! TODO add entry with path to save to (to resave faster) //! TODO ignore case in mat name comparison materials_comparator namespace callbacks { @@ -20,16 +19,30 @@ void OnDestroy( GtkWidget* w, gpointer data ){ DestroyWindow(); } -void OnExportClicked( GtkButton* button, gpointer user_data ){ +static std::string s_export_path; + +void OnExportClicked( GtkButton* button, gpointer choose_path ){ GtkWidget* window = lookup_widget( GTK_WIDGET( button ), "w_plugplug2" ); ASSERT_NOTNULL( window ); - const char* cpath = GlobalRadiant().m_pfnFileDialog( window, false, "Save as Obj", 0, 0, false, false, true ); - if ( !cpath ) { + if( choose_path ){ + const char* cpath = GlobalRadiant().m_pfnFileDialog( window, false, "Save as Obj", 0, 0, false, false, true ); + if ( !cpath ) { + return; + } + s_export_path = cpath; + // enable button to reexport with the selected name + GtkWidget* b_export = lookup_widget( GTK_WIDGET( button ), "b_export" ); + ASSERT_NOTNULL( b_export ); + gtk_widget_set_sensitive( b_export, TRUE ); + // add tooltip + std::string tip( "ReExport to " ); + tip.append( s_export_path ); + gtk_widget_set_tooltip_text( b_export, tip.c_str() ); + } + else if( s_export_path.empty() ){ return; } - std::string path( cpath ); - // get ignore list from ui std::set ignore; @@ -95,7 +108,7 @@ void OnExportClicked( GtkButton* button, gpointer user_data ){ const bool weld = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( toggle ) ); // export - ExportSelection( ignore, mode, exportmat, path, limitMatNames, objects, weld ); + ExportSelection( ignore, mode, exportmat, s_export_path, limitMatNames, objects, weld ); } void OnAddMaterial( GtkButton* button, gpointer user_data ){ diff --git a/contrib/brushexport/interface.cpp b/contrib/brushexport/interface.cpp index bbdab214..fba5b5ad 100644 --- a/contrib/brushexport/interface.cpp +++ b/contrib/brushexport/interface.cpp @@ -26,6 +26,7 @@ create_w_plugplug2( void ){ GtkWidget *r_nocollapse; GtkWidget *vbox3; GtkWidget *b_export; + GtkWidget *b_exportAs; GtkWidget *b_close; GtkWidget *vbox2; GtkWidget *label1; @@ -90,6 +91,12 @@ create_w_plugplug2( void ){ gtk_widget_show( b_export ); gtk_box_pack_start( GTK_BOX( vbox3 ), b_export, TRUE, FALSE, 0 ); gtk_container_set_border_width( GTK_CONTAINER( b_export ), 5 ); + gtk_widget_set_sensitive( b_export, FALSE ); + + b_exportAs = gtk_button_new_from_stock( "gtk-save-as" ); + gtk_widget_show( b_exportAs ); + gtk_box_pack_start( GTK_BOX( vbox3 ), b_exportAs, TRUE, FALSE, 0 ); + gtk_container_set_border_width( GTK_CONTAINER( b_exportAs ), 5 ); b_close = gtk_button_new_from_stock( "gtk-cancel" ); gtk_widget_show( b_close ); @@ -150,13 +157,14 @@ create_w_plugplug2( void ){ t_exportmaterials = gtk_check_button_new_with_mnemonic( "Create material information (.mtl file)" ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( t_exportmaterials ), TRUE ); gtk_widget_show( t_exportmaterials ); - gtk_box_pack_end( GTK_BOX( vbox2 ), t_exportmaterials, FALSE, FALSE, 10 ); + gtk_box_pack_end( GTK_BOX( vbox2 ), t_exportmaterials, FALSE, FALSE, 0 ); using namespace callbacks; g_signal_connect( G_OBJECT( w_plugplug2 ), "destroy", G_CALLBACK( OnDestroy ), NULL ); g_signal_connect_swapped( G_OBJECT( b_close ), "clicked", G_CALLBACK( OnDestroy ), NULL ); g_signal_connect( ( gpointer )b_export, "clicked", G_CALLBACK( OnExportClicked ), NULL ); + g_signal_connect( ( gpointer )b_exportAs, "clicked", G_CALLBACK( OnExportClicked ), gpointer( 1 ) ); g_signal_connect( ( gpointer )b_addmaterial, "clicked", G_CALLBACK( OnAddMaterial ), NULL ); g_signal_connect( ( gpointer )b_removematerial, "clicked", G_CALLBACK( OnRemoveMaterial ), NULL );