]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/gtkdlgs.cpp
Merge commit 'cac514541c3ae6f72c4c00c19c215ff62a023df4' into garux-merge
[xonotic/netradiant.git] / radiant / gtkdlgs.cpp
index e35159fa2591faf48bf2f248c02fbc32529926e3..53d697f46aec0f24a75f6d10ab5716df9a0187bf 100644 (file)
@@ -49,6 +49,7 @@
 
 #include <gdk/gdkkeysyms.h>
 #include <uilib/uilib.h>
+#include <gtk/gtkspinbutton.h>
 
 #include "os/path.h"
 #include "math/aabb.h"
@@ -70,6 +71,9 @@
 #include "url.h"
 #include "cmdlib.h"
 
+#include "qerplugin.h"
+#include "os/file.h"
+
 
 
 // =============================================================================
@@ -199,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 ){
@@ -210,9 +214,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                window.add(table1);
                {
             auto vbox = create_dialog_vbox( 4 );
-                       gtk_table_attach( table1, vbox , 1, 2, 0, 1,
-                                                         (GtkAttachOptions) ( GTK_FILL ),
-                                                         (GtkAttachOptions) ( GTK_FILL ), 0, 0 );
+            table1.attach(vbox, {1, 2, 0, 1}, {GTK_FILL, GTK_FILL});
                        {
                 auto button = create_dialog_button( "OK", G_CALLBACK( dialog_button_ok ), &modal );
                                vbox.pack_start( button, FALSE, FALSE, 0 );
@@ -224,9 +226,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                }
                {
                        auto frame = create_dialog_frame( "Project settings" );
-                       gtk_table_attach( table1, 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);
@@ -234,9 +234,7 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                                {
                                        auto label = ui::Label( "Select mod" );
                                        label.show();
-                                       gtk_table_attach( table2, 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 );
                                }
                                {
@@ -249,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, 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 );
                                }
@@ -259,17 +255,13 @@ ui::Window ProjectSettingsDialog_construct( ProjectSettingsDialog& dialog, Modal
                                {
                                        auto label = ui::Label( "fs_game" );
                                        label.show();
-                                       gtk_table_attach( table2, 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, 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;
                                }
@@ -277,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, 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);
@@ -287,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, 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;
                                }
@@ -350,7 +338,7 @@ void ProjectSettingsDialog_ok( ProjectSettingsDialog& dialog ){
 }
 
 void DoProjectSettings(){
-       if ( ConfirmModified( "Edit Project Settings" ) ) {
+       //if ( ConfirmModified( "Edit Project Settings" ) ) {
                ModalDialog modal;
                ProjectSettingsDialog dialog;
 
@@ -361,7 +349,7 @@ void DoProjectSettings(){
                }
 
                window.destroy();
-       }
+       //}
 }
 
 // =============================================================================
@@ -369,13 +357,15 @@ 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);
@@ -384,12 +374,39 @@ void DoSides( int type, int axis ){
                        label.show();
                        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();
-                       hbox.pack_start( entry, FALSE, FALSE, 0 );
-                       sides_entry = entry;
-                       gtk_widget_grab_focus( 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;
                }
                {
             auto vbox = create_dialog_vbox( 4 );
@@ -409,9 +426,12 @@ void DoSides( int type, int axis ){
        }
 
        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() ) );
        }
 
        window.destroy();
@@ -432,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() );
@@ -494,6 +514,7 @@ void DoAbout(){
                                {
                     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);
                                }
                                {
                     auto button = create_dialog_button( "Changes", G_CALLBACK( about_button_changelog ), 0 );
@@ -502,6 +523,7 @@ void DoAbout(){
                                {
                     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);
                                }
                        }
                }
@@ -514,49 +536,37 @@ void DoAbout(){
                                {
                                        auto label = ui::Label( "Vendor:" );
                                        label.show();
-                                       gtk_table_attach( table, 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, 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, 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, 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, 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, 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 );
                                }
                        }
@@ -568,10 +578,10 @@ void DoAbout(){
                                        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();
                                        }
                                }
@@ -625,34 +635,26 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
                                {
                                        auto label = ui::Label( "Texture x:" );
                                        label.show();
-                                       gtk_table_attach( table, 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, 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, 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, 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;
                                }
@@ -674,13 +676,13 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
                        }
                }
        }
-       
+
        // 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 );
 
@@ -691,7 +693,7 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
        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;
@@ -706,14 +708,15 @@ 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;
        }
-
+*/
        text_editor.hide();
 
        return TRUE;
@@ -721,23 +724,33 @@ static gint editor_delete( ui::Widget widget, gpointer data ){
 
 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::from(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;
        }
-
+*/
        text_editor.hide();
 }
 
@@ -746,7 +759,7 @@ static void CreateGtkTextEditor(){
 
        dlg.connect( "delete_event",
                                          G_CALLBACK( editor_delete ), 0 );
-       gtk_window_set_default_size( GTK_WINDOW( dlg ), 600, 300 );
+       gtk_window_set_default_size( dlg, 400, 300 );
 
        auto vbox = ui::VBox( FALSE, 5 );
        vbox.show();
@@ -763,7 +776,7 @@ 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();
@@ -774,20 +787,20 @@ static void CreateGtkTextEditor(){
        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();
        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
 
@@ -809,10 +822,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 ) {
@@ -822,6 +835,7 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){
 
                // trying to show later
                text_editor.show();
+               gtk_window_present( GTK_WINDOW( text_editor ) );
 
 #if GDEF_OS_WINDOWS
                ui::process();
@@ -836,12 +850,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);
                }
 
 #if GDEF_OS_WINDOWS
                gtk_widget_queue_draw( text_widget );
 #endif
 
+               text_buffer_ = text_buffer;
                free( buf );
                fclose( f );
        }
@@ -919,7 +935,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 );
 
@@ -928,6 +943,7 @@ 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);
@@ -941,13 +957,11 @@ EMessageBoxReturn DoShaderTagDlg( CopiedString* tag, const char* title ){
                                vbox.pack_start( label, FALSE, FALSE, 0 );
                        }
                        {
-                               auto entry = ui::Entry(ui::New);
+                               auto entry = textentry;
                                entry.show();
                                vbox.pack_start( entry, TRUE, TRUE, 0 );
 
                                gtk_widget_grab_focus( entry  );
-
-                               textentry = entry;
                        }
                }
                {
@@ -1037,18 +1051,55 @@ EMessageBoxReturn DoShaderInfoDlg( const char* name, const char* filename, const
 
 #if GDEF_OS_WINDOWS
 // use the file associations to open files instead of builtin Gtk editor
-bool g_TextEditor_useWin32Editor = true;
+bool g_TextEditor_useWin32Editor = false;
 #else
 // custom shader editor
 bool g_TextEditor_useCustomEditor = false;
 CopiedString g_TextEditor_editorCommand( "" );
 #endif
 
-void DoTextEditor( const char* filename, int cursorpos ){
+void DoTextEditor( const char* filename, int cursorpos, int length ){
 #if GDEF_OS_WINDOWS
        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 );
+               StringOutputStream path( 256 );
+               StringOutputStream modpath( 256 );
+               const char* gamename = GlobalRadiant().getGameName();
+               const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+               const char* enginePath = GlobalRadiant().getEnginePath();
+               path << enginePath << basegame << '/' << filename;
+               modpath << enginePath << gamename << '/' << filename;
+               if ( file_exists( modpath.c_str() ) ){
+                       globalOutputStream() << "opening file '" << modpath.c_str() << "' (line " << cursorpos << " info ignored)\n";
+                       ShellExecute( (HWND)GDK_WINDOW_HWND( gtk_widget_get_window( MainFrame_getWindow() ) ), "open", modpath.c_str(), 0, 0, SW_SHOW );
+               }
+               else if ( file_exists( path.c_str() ) ){
+                       globalOutputStream() << "opening file '" << path.c_str() << "' (line " << cursorpos << " info ignored)\n";
+                       ShellExecute( (HWND)GDK_WINDOW_HWND( gtk_widget_get_window( MainFrame_getWindow() ) ), "open", path.c_str(), 0, 0, SW_SHOW );
+               }
+               else{
+                       globalOutputStream() << "Failed to open '" << filename << "'\nOne sits in .pk3 most likely!\n";
+               }
+               return;
+       }
+       else{
+               StringOutputStream path( 256 );
+               StringOutputStream modpath( 256 );
+               const char* gamename = GlobalRadiant().getGameName();
+               const char* basegame = GlobalRadiant().getRequiredGameDescriptionKeyValue( "basegame" );
+               const char* enginePath = GlobalRadiant().getEnginePath();
+               path << enginePath << basegame << '/' << filename;
+               modpath << enginePath << gamename << '/' << filename;
+               if ( file_exists( modpath.c_str() ) ){
+                       globalOutputStream() << "opening file '" << modpath.c_str() << "' (line " << cursorpos << " info ignored)\n";
+                       DoGtkTextEditor( modpath.c_str(), cursorpos, length );
+               }
+               else if ( file_exists( path.c_str() ) ){
+                       globalOutputStream() << "opening file '" << path.c_str() << "' (line " << cursorpos << " info ignored)\n";
+                       DoGtkTextEditor( path.c_str(), cursorpos, length );
+               }
+               else{
+                       globalOutputStream() << "Failed to open '" << filename << "'\nOne sits in .pk3 most likely!\n";
+               }
                return;
        }
 #else
@@ -1068,7 +1119,7 @@ void DoTextEditor( const char* filename, int cursorpos ){
                        return;
                }
        }
-#endif
 
-       DoGtkTextEditor( filename, cursorpos );
+       DoGtkTextEditor( filename, cursorpos, length );
+#endif
 }