]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/gtkdlgs.cpp
Merge commit 'dd7f4f1689e8ede7580bdfa8e08d0b78d08f5253' into garux-merge
[xonotic/netradiant.git] / radiant / gtkdlgs.cpp
index 3d65f8a6e120ba6043c18c1f6bf045e4fdc5b04c..4e38e3822e18d66c2aea6e20dced9d4f80ba83d3 100644 (file)
@@ -35,6 +35,7 @@
 //
 
 #include "gtkdlgs.h"
+#include "globaldefs.h"
 
 #include <gtk/gtk.h>
 
@@ -48,6 +49,7 @@
 
 #include <gdk/gdkkeysyms.h>
 #include <uilib/uilib.h>
+#include <gtk/gtkspinbutton.h>
 
 #include "os/path.h"
 #include "math/aabb.h"
@@ -69,6 +71,9 @@
 #include "url.h"
 #include "cmdlib.h"
 
+#include "qerplugin.h"
+#include "os/file.h"
+
 
 
 // =============================================================================
@@ -169,7 +174,7 @@ gboolean OnSelchangeComboWhatgame( ui::Widget widget, GameCombo* combo ){
        gamecombo_t gamecombo = gamecombo_for_gamename( gamename );
 
        combo->fsgame_entry.text( gamecombo.fs_game );
-       gtk_widget_set_sensitive( GTK_WIDGET( combo->fsgame_entry ), gamecombo.sensitive );
+       gtk_widget_set_sensitive( combo->fsgame_entry , gamecombo.sensitive );
 
        return FALSE;
 }
@@ -198,7 +203,7 @@ class ProjectSettingsDialog
 {
 public:
 GameCombo game_combo;
-GtkComboBox* gamemode_combo;
+ui::ComboBox gamemode_combo{ui::null};
 };
 
 ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, ModalDialog& modal ){
@@ -208,24 +213,20 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                auto table1 = create_dialog_table( 1, 2, 4, 4, 4 );
                window.add(table1);
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_table_attach( table1, GTK_WIDGET( vbox ), 1, 2, 0, 1,
-                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                         (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+            table1.attach(vbox, {1, 2, 0, 1}, {GTK_FILL, GTK_FILL});
                        {
-                               GtkButton* button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &modal );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &modal );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                        }
                        {
-                               GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &modal );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &modal );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                        }
                }
                {
                        auto frame = create_dialog_frame( "Project settings" );
-                       gtk_table_attach( table1, GTK_WIDGET( frame ), 0, 1, 0, 1,
-                                                         (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                         (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
+            table1.attach(frame, {0, 1, 0, 1}, {GTK_EXPAND | GTK_FILL, GTK_FILL});
                        {
                                auto table2 = create_dialog_table( ( globalMappingMode().do_mapping_mode ) ? 4 : 3, 2, 4, 4, 4 );
                                frame.add(table2);
@@ -233,9 +234,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                                {
                                        auto label = ui::Label( "Select mod" );
                                        label.show();
-                                       gtk_table_attach( table2, GTK_WIDGET( label ), 0, 1, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table2.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 );
                                }
                                {
@@ -248,9 +247,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                                        gtk_combo_box_text_append_text( dialog.game_combo.game_select, globalGameComboConfiguration().custom );
 
                                        dialog.game_combo.game_select.show();
-                                       gtk_table_attach( table2, GTK_WIDGET( dialog.game_combo.game_select ), 1, 2, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table2.attach(dialog.game_combo.game_select, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
 
                                        dialog.game_combo.game_select.connect( "changed", G_CALLBACK( OnSelchangeComboWhatgame ), &dialog.game_combo );
                                }
@@ -258,17 +255,13 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                                {
                                        auto label = ui::Label( "fs_game" );
                                        label.show();
-                                       gtk_table_attach( table2, GTK_WIDGET( label ), 0, 1, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table2.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 );
                                }
                                {
                                        auto entry = ui::Entry(ui::New);
                                        entry.show();
-                                       gtk_table_attach( table2, GTK_WIDGET( entry ), 1, 2, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table2.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
 
                                        dialog.game_combo.fsgame_entry = entry;
                                }
@@ -276,9 +269,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                                if ( globalMappingMode().do_mapping_mode ) {
                                        auto label = ui::Label( "Mapping mode" );
                                        label.show();
-                                       gtk_table_attach( table2, GTK_WIDGET( label ), 0, 1, 3, 4,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table2.attach(label, {0, 1, 3, 4}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 );
 
                                        auto combo = ui::ComboBoxText(ui::New);
@@ -286,9 +277,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                                        gtk_combo_box_text_append_text( combo, globalMappingMode().mp_mapping_mode );
 
                                        combo.show();
-                                       gtk_table_attach( table2, GTK_WIDGET( combo ), 1, 2, 3, 4,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table2.attach(combo, {1, 2, 3, 4}, {GTK_EXPAND | GTK_FILL, 0});
 
                                        dialog.gamemode_combo = combo;
                                }
@@ -302,7 +291,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
 
        gtk_combo_box_set_active( dialog.game_combo.game_select, gamecombo.game );
        dialog.game_combo.fsgame_entry.text( gamecombo.fs_game );
-       gtk_widget_set_sensitive( GTK_WIDGET( dialog.game_combo.fsgame_entry ), gamecombo.sensitive );
+       gtk_widget_set_sensitive( dialog.game_combo.fsgame_entry , gamecombo.sensitive );
 
        if ( globalMappingMode().do_mapping_mode ) {
                const char *gamemode = gamemode_get();
@@ -349,7 +338,7 @@ void ProjectSettingsDialog_ok( ProjectSettingsDialog& dialog ){
 }
 
 void DoProjectSettings(){
-       if ( ConfirmModified( "Edit Project Settings" ) ) {
+       //if ( ConfirmModified( "Edit Project Settings" ) ) {
                ModalDialog modal;
                ProjectSettingsDialog dialog;
 
@@ -359,8 +348,8 @@ void DoProjectSettings(){
                        ProjectSettingsDialog_ok( dialog );
                }
 
-               gtk_widget_destroy( GTK_WIDGET( window ) );
-       }
+               window.destroy();
+       //}
 }
 
 // =============================================================================
@@ -368,52 +357,84 @@ void DoProjectSettings(){
 
 void DoSides( int type, int axis ){
        ModalDialog dialog;
-       GtkEntry* sides_entry;
+       //GtkEntry* sides_entry;
+       GtkWidget* sides_spin;
 
        auto window = MainFrame_getWindow().create_dialog_window("Arbitrary sides", G_CALLBACK(dialog_delete_callback ), &dialog );
 
        auto accel = ui::AccelGroup(ui::New);
        window.add_accel_group( accel );
 
+       auto sides_entry = ui::Entry(ui::New);
        {
                auto hbox = create_dialog_hbox( 4, 4 );
                window.add(hbox);
                {
                        auto label = ui::Label( "Sides:" );
                        label.show();
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                       hbox.pack_start( label, FALSE, FALSE, 0 );
                }
+//             {
+//                     auto entry = sides_entry;
+//                     entry.show();
+//                     hbox.pack_start( entry, FALSE, FALSE, 0 );
+//                     gtk_widget_grab_focus( entry  );
+//             }
                {
-                       auto entry = ui::Entry(ui::New);
-                       entry.show();
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( entry ), FALSE, FALSE, 0 );
-                       sides_entry = entry;
-                       gtk_widget_grab_focus( GTK_WIDGET( entry ) );
+                       GtkAdjustment* adj;
+                       EBrushPrefab BrushPrefabType = (EBrushPrefab)type;
+                       switch ( BrushPrefabType )
+                       {
+                       case eBrushPrism :
+                       case eBrushCone :
+                               adj = GTK_ADJUSTMENT( gtk_adjustment_new( 8, 3, 1022, 1, 10, 0 ) );
+                               break;
+                       case eBrushSphere :
+                               adj = GTK_ADJUSTMENT( gtk_adjustment_new( 8, 3, 31, 1, 10, 0 ) );
+                               break;
+                       case eBrushRock :
+                               adj = GTK_ADJUSTMENT( gtk_adjustment_new( 32, 10, 1000, 1, 10, 0 ) );
+                               break;
+                       default:
+                               adj = GTK_ADJUSTMENT( gtk_adjustment_new( 8, 3, 31, 1, 10, 0 ) );
+                               break;
+                       }
+
+                       GtkWidget* spin = gtk_spin_button_new( adj, 1, 0 );
+                       gtk_widget_show( spin );
+                       gtk_box_pack_start( GTK_BOX( hbox ), spin, FALSE, FALSE, 0 );
+                       gtk_widget_set_size_request( spin, 64, -1 );
+                       gtk_spin_button_set_numeric( GTK_SPIN_BUTTON( spin ), TRUE );
+
+                       sides_spin = spin;
                }
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, TRUE, TRUE, 0 );
                        {
                                auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &dialog );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                                widget_make_default( button );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
                        }
                        {
-                               GtkButton* button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
+                auto button = create_dialog_button( "Cancel", G_CALLBACK( dialog_button_cancel ), &dialog );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
                        }
                }
        }
 
        if ( modal_dialog_show( window, dialog ) == eIDOK ) {
-               const char *str = gtk_entry_get_text( sides_entry );
+//             const char *str = gtk_entry_get_text( sides_entry );
 
-               Scene_BrushConstructPrefab( GlobalSceneGraph(), (EBrushPrefab)type, atoi( str ), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
+//             Scene_BrushConstructPrefab( GlobalSceneGraph(), (EBrushPrefab)type, atoi( str ), TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
+               gtk_spin_button_update ( GTK_SPIN_BUTTON( sides_spin ) );
+               int sides = static_cast<int>( gtk_spin_button_get_value( GTK_SPIN_BUTTON( sides_spin ) ) );
+               Scene_BrushConstructPrefab( GlobalSceneGraph(), (EBrushPrefab)type, sides, TextureBrowser_GetSelectedShader( GlobalTextureBrowser() ) );
        }
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 }
 
 // =============================================================================
@@ -431,7 +452,7 @@ void about_button_credits( ui::Widget widget, gpointer data ){
        OpenURL( cred.c_str() );
 }
 
-void about_button_issues( GtkWidget *widget, gpointer data ){
+void about_button_issues( ui::Widget widget, gpointer data ){
        StringOutputStream cred( 256 );
        cred << "https://gitlab.com/xonotic/netradiant/issues";
        OpenURL( cred.c_str() );
@@ -448,15 +469,15 @@ void DoAbout(){
                window.add(vbox);
 
                {
-                       GtkHBox* hbox = create_dialog_hbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
+            auto hbox = create_dialog_hbox( 4 );
+                       vbox.pack_start( hbox, FALSE, TRUE, 0 );
 
                        {
-                               GtkVBox* vbox2 = create_dialog_vbox( 4 );
-                               gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox2 ), TRUE, FALSE, 0 );
+                auto vbox2 = create_dialog_vbox( 4 );
+                               hbox.pack_start( vbox2, TRUE, FALSE, 0 );
                                {
                                        auto frame = create_dialog_frame( 0, ui::Shadow::IN );
-                                       gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), FALSE, FALSE, 0 );
+                                       vbox2.pack_start( frame, FALSE, FALSE, 0 );
                                        {
                                                auto image = new_local_image( "logo.png" );
                                                image.show();
@@ -478,99 +499,89 @@ void DoAbout(){
                                auto label = ui::Label( label_text );
 
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                               hbox.pack_start( label, FALSE, FALSE, 0 );
                                gtk_misc_set_alignment( GTK_MISC( label ), 1, 0.5 );
                                gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
                        }
 
                        {
-                               GtkVBox* vbox2 = create_dialog_vbox( 4 );
-                               gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox2 ), FALSE, TRUE, 0 );
+                auto vbox2 = create_dialog_vbox( 4 );
+                               hbox.pack_start( vbox2, FALSE, TRUE, 0 );
                                {
-                                       GtkButton* button = create_modal_dialog_button( "OK", ok_button );
-                                       gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                    auto button = create_modal_dialog_button( "OK", ok_button );
+                                       vbox2.pack_start( button, FALSE, FALSE, 0 );
                                }
                                {
-                                       GtkButton* button = create_dialog_button( "Credits", G_CALLBACK( about_button_credits ), 0 );
-                                       gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                    auto button = create_dialog_button( "Credits", G_CALLBACK( about_button_credits ), 0 );
+                                       vbox2.pack_start( button, FALSE, FALSE, 0 );
+                                       gtk_widget_set_sensitive( GTK_WIDGET( button ), FALSE);
                                }
                                {
-                                       GtkButton* button = create_dialog_button( "Changes", G_CALLBACK( about_button_changelog ), 0 );
-                                       gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                    auto button = create_dialog_button( "Changes", G_CALLBACK( about_button_changelog ), 0 );
+                                       vbox2.pack_start( button, FALSE, FALSE, 0 );
                                }
                                {
-                                       GtkButton* button = create_dialog_button( "Issues", G_CALLBACK( about_button_issues ), 0 );
-                                       gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                    auto button = create_dialog_button( "Issues", G_CALLBACK( about_button_issues ), 0 );
+                                       vbox2.pack_start( button, FALSE, FALSE, 0 );
+                                       gtk_widget_set_sensitive( GTK_WIDGET( button ), FALSE);
                                }
                        }
                }
                {
                        auto frame = create_dialog_frame( "OpenGL Properties" );
-                       gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( frame ), FALSE, FALSE, 0 );
+                       vbox.pack_start( frame, FALSE, FALSE, 0 );
                        {
                                auto table = create_dialog_table( 3, 2, 4, 4, 4 );
                                frame.add(table);
                                {
                                        auto label = ui::Label( "Vendor:" );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                                {
                                        auto label = ui::Label( "Version:" );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                                {
                                        auto label = ui::Label( "Renderer:" );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {0, 1, 2, 3}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                                {
                                        auto label = ui::Label( reinterpret_cast<const char*>( glGetString( GL_VENDOR ) ) );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 1, 2, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {1, 2, 0, 1}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                                {
                                        auto label = ui::Label( reinterpret_cast<const char*>( glGetString( GL_VERSION ) ) );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 1, 2, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {1, 2, 1, 2}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                                {
                                        auto label = ui::Label( reinterpret_cast<const char*>( glGetString( GL_RENDERER ) ) );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 1, 2, 2, 3,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {1, 2, 2, 3}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                        }
                        {
                                auto frame = create_dialog_frame( "OpenGL Extensions" );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( frame ), TRUE, TRUE, 0 );
+                               vbox.pack_start( frame, TRUE, TRUE, 0 );
                                {
                                        auto sc_extensions = create_scrolled_window( ui::Policy::AUTOMATIC, ui::Policy::ALWAYS, 4 );
                                        frame.add(sc_extensions);
                                        {
                                                auto text_extensions = ui::TextView(ui::New);
-                                               gtk_text_view_set_editable( GTK_TEXT_VIEW( text_extensions ), FALSE );
+                                               gtk_text_view_set_editable( text_extensions, FALSE );
                                                sc_extensions.add(text_extensions);
                                                text_extensions.text(reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS)));
-                                               gtk_text_view_set_wrap_mode( GTK_TEXT_VIEW( text_extensions ), GTK_WRAP_WORD );
+                                               gtk_text_view_set_wrap_mode( text_extensions, GTK_WRAP_WORD );
                                                text_extensions.show();
                                        }
                                }
@@ -580,7 +591,7 @@ void DoAbout(){
 
        modal_dialog_show( window, dialog );
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 }
 
 // =============================================================================
@@ -606,97 +617,89 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
                auto hbox = create_dialog_hbox( 4, 4 );
                window.add(hbox);
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, TRUE, TRUE, 0 );
                        {
                                auto label = ui::Label( "Texture will be fit across the patch based\n"
                                                                                                                        "on the x and y values given. Values of 1x1\n"
                                                                                                                        "will \"fit\" the texture. 2x2 will repeat\n"
                                                                                                                        "it twice, etc." );
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), TRUE, TRUE, 0 );
+                               vbox.pack_start( label, TRUE, TRUE, 0 );
                                gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
                        }
                        {
                                auto table = create_dialog_table( 2, 2, 4, 4 );
                                table.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( table ), TRUE, TRUE, 0 );
+                               vbox.pack_start( table, TRUE, TRUE, 0 );
                                {
                                        auto label = ui::Label( "Texture x:" );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {0, 1, 0, 1}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                                {
                                        auto label = ui::Label( "Texture y:" );
                                        label.show();
-                                       gtk_table_attach( table, GTK_WIDGET( label ), 0, 1, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(label, {0, 1, 1, 2}, {GTK_FILL, 0});
                                        gtk_misc_set_alignment( GTK_MISC( label ), 0, 0.5 );
                                }
                                {
                                        auto entry = ui::Entry(ui::New);
                                        entry.show();
-                                       gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 0, 1,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(entry, {1, 2, 0, 1}, {GTK_EXPAND | GTK_FILL, 0});
 
                                        x = entry;
                                }
                                {
                                        auto entry = ui::Entry(ui::New);
                                        entry.show();
-                                       gtk_table_attach( table, GTK_WIDGET( entry ), 1, 2, 1, 2,
-                                                                         (GtkAttachOptions) ( GTK_EXPAND | GTK_FILL ),
-                                                                         (GtkAttachOptions) ( 0 ), 0, 0 );
+                    table.attach(entry, {1, 2, 1, 2}, {GTK_EXPAND | GTK_FILL, 0});
 
                                        y = entry;
                                }
                        }
                }
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, FALSE, FALSE, 0 );
                        {
                                auto button = create_modal_dialog_button( "OK", ok_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                                widget_make_default( button );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Return, (GdkModifierType)0, (GtkAccelFlags)0 );
                        }
                        {
-                               GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
+                auto button = create_modal_dialog_button( "Cancel", cancel_button );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel, GDK_KEY_Escape, (GdkModifierType)0, (GtkAccelFlags)0 );
                        }
                }
        }
-       
+
        // Initialize with last used values
        char buf[16];
-       
+
        sprintf( buf, "%f", last_used_texture_layout_scale_x );
        x.text( buf );
-       
+
        sprintf( buf, "%f", last_used_texture_layout_scale_y );
        y.text( buf );
 
        // Set focus after intializing the values
-       gtk_widget_grab_focus( GTK_WIDGET( x ) );
+       gtk_widget_grab_focus(  );
 
        EMessageBoxReturn ret = modal_dialog_show( window, dialog );
        if ( ret == eIDOK ) {
                *fx = static_cast<float>( atof( gtk_entry_get_text( x ) ) );
                *fy = static_cast<float>( atof( gtk_entry_get_text( y ) ) );
-       
+
                // Remember last used values
                last_used_texture_layout_scale_x = *fx;
                last_used_texture_layout_scale_y = *fy;
        }
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 
        return ret;
 }
@@ -705,47 +708,57 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
 // Text Editor dialog
 
 // master window widget
-static ui::Widget text_editor{ui::null};
+static ui::Window text_editor{ui::null};
 static ui::Widget text_widget{ui::null}; // slave, text widget from the gtk editor
+static GtkTextBuffer* text_buffer_;
 
 static gint editor_delete( ui::Widget widget, gpointer data ){
-       if ( widget.alert( "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
+/*     if ( ui::alert( widget.window(), "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
                return TRUE;
        }
-
-       gtk_widget_hide( text_editor );
+*/
+       text_editor.hide();
 
        return TRUE;
 }
 
 static void editor_save( ui::Widget widget, gpointer data ){
        FILE *f = fopen( (char*)g_object_get_data( G_OBJECT( data ), "filename" ), "w" );
-       gpointer text = g_object_get_data( G_OBJECT( data ), "text" );
+       //gpointer text = g_object_get_data( G_OBJECT( data ), "text" );
 
        if ( f == 0 ) {
-               ui::Widget(GTK_WIDGET( data )).alert( "Error saving file !" );
+               ui::alert( ui::Widget::from(data).window(), "Error saving file !" );
                return;
        }
 
-       char *str = gtk_editable_get_chars( GTK_EDITABLE( text ), 0, -1 );
+       /* Obtain iters for the start and end of points of the buffer */
+       GtkTextIter start;
+       GtkTextIter end;
+       gtk_text_buffer_get_start_iter (text_buffer_, &start);
+       gtk_text_buffer_get_end_iter (text_buffer_, &end);
+
+       /* Get the entire buffer text. */
+       char *str = gtk_text_buffer_get_text (text_buffer_, &start, &end, FALSE);
+
+       //char *str = gtk_editable_get_chars( GTK_EDITABLE( text ), 0, -1 );
        fwrite( str, 1, strlen( str ), f );
        fclose( f );
+       g_free (str);
 }
 
 static void editor_close( ui::Widget widget, gpointer data ){
-       if ( text_editor.alert( "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
+/*     if ( ui::alert( text_editor.window(), "Close the shader editor ?", "Radiant", ui::alert_type::YESNO, ui::alert_icon::Question ) == ui::alert_response::NO ) {
                return;
        }
-
-       gtk_widget_hide( text_editor );
+*/
+       text_editor.hide();
 }
 
 static void CreateGtkTextEditor(){
        auto dlg = ui::Window( ui::window_type::TOP );
 
-       dlg.connect( "delete_event",
-                                         G_CALLBACK( editor_delete ), 0 );
-       gtk_window_set_default_size( GTK_WINDOW( dlg ), 600, 300 );
+       dlg.connect( "", G_CALLBACK( editor_delete ), 0 );
+       gtk_window_set_default_size( dlg, 400, 600 );
 
        auto vbox = ui::VBox( FALSE, 5 );
        vbox.show();
@@ -754,7 +767,7 @@ static void CreateGtkTextEditor(){
 
        auto scr = ui::ScrolledWindow(ui::New);
        scr.show();
-       gtk_box_pack_start( GTK_BOX( vbox ), scr, TRUE, TRUE, 0 );
+       vbox.pack_start( scr, TRUE, TRUE, 0 );
        gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( scr ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
        gtk_scrolled_window_set_shadow_type( GTK_SCROLLED_WINDOW( scr ), GTK_SHADOW_IN );
 
@@ -762,31 +775,31 @@ static void CreateGtkTextEditor(){
        scr.add(text);
        text.show();
        g_object_set_data( G_OBJECT( dlg ), "text", (gpointer) text );
-       gtk_text_view_set_editable( GTK_TEXT_VIEW( text ), TRUE );
+       gtk_text_view_set_editable( text, TRUE );
 
        auto hbox = ui::HBox( FALSE, 5 );
        hbox.show();
-       gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( hbox ), FALSE, TRUE, 0 );
+       vbox.pack_start( hbox, FALSE, TRUE, 0 );
 
        auto button = ui::Button( "Close" );
        button.show();
-       gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
+       hbox.pack_end(button, FALSE, FALSE, 0);
        button.connect( "clicked",
                                          G_CALLBACK( editor_close ), dlg );
-       gtk_widget_set_size_request( button, 60, -1 );
+       button.dimensions(60, -1);
 
        button = ui::Button( "Save" );
        button.show();
-       gtk_box_pack_end( GTK_BOX( hbox ), button, FALSE, FALSE, 0 );
+       hbox.pack_end(button, FALSE, FALSE, 0);
        button.connect( "clicked",
                                          G_CALLBACK( editor_save ), dlg );
-       gtk_widget_set_size_request( button, 60, -1 );
+       button.dimensions(60, -1);
 
        text_editor = dlg;
        text_widget = text;
 }
 
-static void DoGtkTextEditor( const char* filename, guint cursorpos ){
+static void DoGtkTextEditor( const char* filename, guint cursorpos, int length ){
        if ( !text_editor ) {
                CreateGtkTextEditor(); // build it the first time we need it
 
@@ -796,7 +809,7 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){
 
        if ( f == 0 ) {
                globalOutputStream() << "Unable to load file " << filename << " in shader editor.\n";
-               gtk_widget_hide( text_editor );
+               text_editor.hide();
        }
        else
        {
@@ -808,10 +821,10 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){
                rewind( f );
                fread( buf, 1, len, f );
 
-               gtk_window_set_title( GTK_WINDOW( text_editor ), filename );
+               gtk_window_set_title( text_editor, filename );
 
-               GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW( text_widget ) );
-               gtk_text_buffer_set_text( text_buffer, (char*)buf, len );
+               auto text_buffer = gtk_text_view_get_buffer(ui::TextView::from(text_widget));
+               gtk_text_buffer_set_text( text_buffer, (char*)buf, length );
 
                old_filename = g_object_get_data( G_OBJECT( text_editor ), "filename" );
                if ( old_filename ) {
@@ -821,10 +834,11 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){
 
                // trying to show later
                text_editor.show();
+               gtk_window_present( GTK_WINDOW( text_editor ) );
 
-#ifdef WIN32
+//#if GDEF_OS_WINDOWS
                ui::process();
-#endif
+//#endif
 
                // only move the cursor if it's not exceeding the size..
                // NOTE: this is erroneous, cursorpos is the offset in bytes, not in characters
@@ -835,12 +849,14 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){
                        // character offset, not byte offset
                        gtk_text_buffer_get_iter_at_offset( text_buffer, &text_iter, cursorpos );
                        gtk_text_buffer_place_cursor( text_buffer, &text_iter );
+                       gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW( text_widget ), &text_iter, 0, TRUE, 0, 0);
                }
 
-#ifdef WIN32
+//#if GDEF_OS_WINDOWS
                gtk_widget_queue_draw( text_widget );
-#endif
+//#endif
 
+               text_buffer_ = text_buffer;
                free( buf );
                fclose( f );
        }
@@ -864,37 +880,37 @@ EMessageBoxReturn DoLightIntensityDlg( int *intensity ){
                auto hbox = create_dialog_hbox( 4, 4 );
                window.add(hbox);
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, TRUE, TRUE, 0 );
                        {
                                auto label = ui::Label( "ESC for default, ENTER to validate" );
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                               vbox.pack_start( label, FALSE, FALSE, 0 );
                        }
                        {
                                auto entry = ui::Entry(ui::New);
                                entry.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
+                               vbox.pack_start( entry, TRUE, TRUE, 0 );
 
-                               gtk_widget_grab_focus( GTK_WIDGET( entry ) );
+                               gtk_widget_grab_focus( entry  );
 
                                intensity_entry = entry;
                        }
                }
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, FALSE, FALSE, 0 );
 
                        {
                                auto button = create_modal_dialog_button( "OK", ok_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                                widget_make_default( button );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
+                               gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
                        }
                        {
-                               GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
+                auto button = create_modal_dialog_button( "Cancel", cancel_button );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
                        }
                }
        }
@@ -908,7 +924,7 @@ EMessageBoxReturn DoLightIntensityDlg( int *intensity ){
                *intensity = atoi( gtk_entry_get_text( intensity_entry ) );
        }
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 
        return ret;
 }
@@ -918,7 +934,6 @@ EMessageBoxReturn DoLightIntensityDlg( int *intensity ){
 
 EMessageBoxReturn DoShaderTagDlg( CopiedString* tag, const char* title ){
        ModalDialog dialog;
-       GtkEntry* textentry;
        ModalDialogButton ok_button( dialog, eIDOK );
        ModalDialogButton cancel_button( dialog, eIDCANCEL );
 
@@ -927,42 +942,41 @@ EMessageBoxReturn DoShaderTagDlg( CopiedString* tag, const char* title ){
        auto accel_group = ui::AccelGroup(ui::New);
        window.add_accel_group( accel_group );
 
+       auto textentry = ui::Entry(ui::New);
        {
                auto hbox = create_dialog_hbox( 4, 4 );
                window.add(hbox);
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), TRUE, TRUE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, TRUE, TRUE, 0 );
                        {
                                //GtkLabel* label = GTK_LABEL(gtk_label_new("Enter one ore more tags separated by spaces"));
                                auto label = ui::Label( "ESC to cancel, ENTER to validate" );
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                               vbox.pack_start( label, FALSE, FALSE, 0 );
                        }
                        {
-                               auto entry = ui::Entry(ui::New);
+                               auto entry = textentry;
                                entry.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( entry ), TRUE, TRUE, 0 );
-
-                               gtk_widget_grab_focus( GTK_WIDGET( entry ) );
+                               vbox.pack_start( entry, TRUE, TRUE, 0 );
 
-                               textentry = entry;
+                               gtk_widget_grab_focus( entry  );
                        }
                }
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, FALSE, FALSE, 0 );
 
                        {
                                auto button = create_modal_dialog_button( "OK", ok_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                                widget_make_default( button );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
+                               gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
                        }
                        {
-                               GtkButton* button = create_modal_dialog_button( "Cancel", cancel_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
+                auto button = create_modal_dialog_button( "Cancel", cancel_button );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
+                               gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Escape, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
                        }
                }
        }
@@ -972,7 +986,7 @@ EMessageBoxReturn DoShaderTagDlg( CopiedString* tag, const char* title ){
                *tag = gtk_entry_get_text( textentry );
        }
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 
        return ret;
 }
@@ -990,84 +1004,116 @@ EMessageBoxReturn DoShaderInfoDlg( const char* name, const char* filename, const
                auto hbox = create_dialog_hbox( 4, 4 );
                window.add(hbox);
                {
-                       GtkVBox* vbox = create_dialog_vbox( 4 );
-                       gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( vbox ), FALSE, FALSE, 0 );
+            auto vbox = create_dialog_vbox( 4 );
+                       hbox.pack_start( vbox, FALSE, FALSE, 0 );
                        {
                                auto label = ui::Label( "The selected shader" );
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                               vbox.pack_start( label, FALSE, FALSE, 0 );
                        }
                        {
                                auto label = ui::Label( name );
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                               vbox.pack_start( label, FALSE, FALSE, 0 );
                        }
                        {
                                auto label = ui::Label( "is located in file" );
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                               vbox.pack_start( label, FALSE, FALSE, 0 );
                        }
                        {
                                auto label = ui::Label( filename );
                                label.show();
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( label ), FALSE, FALSE, 0 );
+                               vbox.pack_start( label, FALSE, FALSE, 0 );
                        }
                        {
                                auto button = create_modal_dialog_button( "OK", ok_button );
-                               gtk_box_pack_start( GTK_BOX( vbox ), GTK_WIDGET( button ), FALSE, FALSE, 0 );
+                               vbox.pack_start( button, FALSE, FALSE, 0 );
                                widget_make_default( button );
-                               gtk_widget_add_accelerator( GTK_WIDGET( button ), "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
+                               gtk_widget_add_accelerator( button , "clicked", accel_group, GDK_KEY_Return, (GdkModifierType)0, GTK_ACCEL_VISIBLE );
                        }
                }
        }
 
        EMessageBoxReturn ret = modal_dialog_show( window, dialog );
 
-       gtk_widget_destroy( GTK_WIDGET( window ) );
+       window.destroy();
 
        return ret;
 }
 
 
 
-#ifdef WIN32
+#if GDEF_OS_WINDOWS
 #include <gdk/gdkwin32.h>
 #endif
 
-#ifdef WIN32
-// use the file associations to open files instead of builtin Gtk editor
-bool g_TextEditor_useWin32Editor = true;
-#else
-// custom shader editor
-bool g_TextEditor_useCustomEditor = false;
 CopiedString g_TextEditor_editorCommand( "" );
-#endif
 
-void DoTextEditor( const char* filename, int cursorpos ){
-#ifdef WIN32
-       if ( g_TextEditor_useWin32Editor ) {
-               globalOutputStream() << "opening file '" << filename << "' (line " << cursorpos << " info ignored)\n";
-               ShellExecute( (HWND)GDK_WINDOW_HWND( gtk_widget_get_window( MainFrame_getWindow() ) ), "open", filename, 0, 0, SW_SHOW );
-               return;
+void DoTextEditor( const char* filename, int cursorpos, int length, bool external_editor ){
+       //StringOutputStream paths[4]( 256 );
+       StringOutputStream paths[4] = { StringOutputStream(256) };
+       StringOutputStream* goodpath = 0;
+
+       const char* gamename = GlobalRadiant().getGameName();
+       const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+       const char* enginePath = GlobalRadiant().getEnginePath();
+       const char* homeEnginePath = g_qeglobals.m_userEnginePath.c_str();
+
+       paths[0] << homeEnginePath << gamename << '/' << filename;
+       paths[1] << enginePath << gamename << '/' << filename;
+       paths[2] << homeEnginePath << basegame << '/' << filename;
+       paths[3] << enginePath << basegame << '/' << filename;
+
+       for ( std::size_t i = 0; i < 4; ++i ){
+               if ( file_exists( paths[i].c_str() ) ){
+                       goodpath = &paths[i];
+                       break;
+               }
        }
+
+       if( goodpath ){
+               globalOutputStream() << "opening file '" << goodpath->c_str() << "' (line " << cursorpos << " info ignored)\n";
+               if( external_editor ){
+                       if( g_TextEditor_editorCommand.empty() ){
+#ifdef WIN32
+                               ShellExecute( (HWND)GDK_WINDOW_HWND( GTK_WIDGET( MainFrame_getWindow() )->window ), 0, goodpath->c_str(), 0, 0, SW_SHOWNORMAL );
+//                             SHELLEXECUTEINFO ShExecInfo;
+//                             ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
+//                             ShExecInfo.fMask = 0;
+//                             ShExecInfo.hwnd = (HWND)GDK_WINDOW_HWND( GTK_WIDGET( MainFrame_getWindow() )->window );
+//                             ShExecInfo.lpVerb = NULL;
+//                             ShExecInfo.lpFile = goodpath->c_str();
+//                             ShExecInfo.lpParameters = NULL;
+//                             ShExecInfo.lpDirectory = NULL;
+//                             ShExecInfo.nShow = SW_SHOWNORMAL;
+//                             ShExecInfo.hInstApp = NULL;
+//                             ShellExecuteEx(&ShExecInfo);
 #else
-       // check if a custom editor is set
-       if ( g_TextEditor_useCustomEditor && !g_TextEditor_editorCommand.empty() ) {
-               StringOutputStream strEditCommand( 256 );
-               strEditCommand << g_TextEditor_editorCommand.c_str() << " \"" << filename << "\"";
-
-               globalOutputStream() << "Launching: " << strEditCommand.c_str() << "\n";
-               // note: linux does not return false if the command failed so it will assume success
-               if ( Q_Exec( 0, const_cast<char*>( strEditCommand.c_str() ), 0, true, false ) == false ) {
-                       globalOutputStream() << "Failed to execute " << strEditCommand.c_str() << ", using default\n";
+                               globalOutputStream() << "Failed to open '" << goodpath->c_str() << "'\nSet Shader Editor Command in preferences\n";
+#endif
+                       }
+                       else{
+                               StringOutputStream strEditCommand( 256 );
+                               strEditCommand << g_TextEditor_editorCommand.c_str() << " \"" << goodpath->c_str() << "\"";
+
+                               globalOutputStream() << "Launching: " << strEditCommand.c_str() << "\n";
+                               // note: linux does not return false if the command failed so it will assume success
+                               if ( Q_Exec( 0, const_cast<char*>( strEditCommand.c_str() ), 0, true, false ) == false ) {
+                                       globalOutputStream() << "Failed to execute " << strEditCommand.c_str() << "\n";
+                               }
+                               else
+                               {
+                                       // the command (appeared) to run successfully, no need to do anything more
+                                       return;
+                               }
+                       }
                }
-               else
-               {
-                       // the command (appeared) to run successfully, no need to do anything more
-                       return;
+               else{
+                       DoGtkTextEditor( goodpath->c_str(), cursorpos, length );
                }
        }
-#endif
-
-       DoGtkTextEditor( filename, cursorpos );
+       else{
+               globalOutputStream() << "Failed to open '" << filename << "'\nOne sits in .pk3 most likely!\n";
+       }
 }