]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/gtkdlgs.cpp
Merge commit 'b681f28130ff2e9789253eff1c1d41163e427eaa' into master-merge
[xonotic/netradiant.git] / radiant / gtkdlgs.cpp
index d88431bd706030c54913ce5bd3ade05bd65fe57f..9b6eb2d816ae638c622112282300cf74dec218ae 100644 (file)
@@ -40,7 +40,6 @@
 #include <gtk/gtk.h>
 
 #include "debugging/debugging.h"
-#include "version.h"
 #include "aboutmsg.h"
 
 #include "igl.h"
@@ -70,6 +69,9 @@
 #include "url.h"
 #include "cmdlib.h"
 
+#include "qerplugin.h"
+#include "os/file.h"
+
 
 
 // =============================================================================
@@ -334,7 +336,7 @@ void ProjectSettingsDialog_ok( ProjectSettingsDialog& dialog ){
 }
 
 void DoProjectSettings(){
-       if ( ConfirmModified( "Edit Project Settings" ) ) {
+       //if ( ConfirmModified( "Edit Project Settings" ) ) {
                ModalDialog modal;
                ProjectSettingsDialog dialog;
 
@@ -345,7 +347,7 @@ void DoProjectSettings(){
                }
 
                window.destroy();
-       }
+       //}
 }
 
 // =============================================================================
@@ -353,13 +355,13 @@ void DoProjectSettings(){
 
 void DoSides( int type, int axis ){
        ModalDialog dialog;
-       GtkEntry* sides_entry;
 
        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);
@@ -369,10 +371,9 @@ void DoSides( int type, int axis ){
                        hbox.pack_start( label, FALSE, FALSE, 0 );
                }
                {
-                       auto entry = ui::Entry(ui::New);
+                       auto entry = sides_entry;
                        entry.show();
                        hbox.pack_start( entry, FALSE, FALSE, 0 );
-                       sides_entry = entry;
                        gtk_widget_grab_focus( entry  );
                }
                {
@@ -422,11 +423,24 @@ void about_button_issues( ui::Widget widget, gpointer data ){
        OpenURL( cred.c_str() );
 }
 
+static void AddParagraph( ui::VBox vbox, const char* text, bool use_markup ){
+       auto label = ui::Label( text );
+       gtk_label_set_use_markup( GTK_LABEL( label ), use_markup );
+       gtk_misc_set_alignment( GTK_MISC( label ), 0, 0 );
+       gtk_label_set_justify( label, GTK_JUSTIFY_LEFT );
+       label.show();
+       vbox.pack_start( label, TRUE, TRUE, 0 );
+}
+
+static void AddParagraph( ui::VBox vbox, const char* text ){
+       AddParagraph( vbox, text, false );
+}
+
 void DoAbout(){
        ModalDialog dialog;
        ModalDialogButton ok_button( dialog, eIDOK );
 
-       auto window = MainFrame_getWindow().create_modal_dialog_window("About NetRadiant", dialog );
+       auto window = MainFrame_getWindow().create_modal_dialog_window("About " RADIANT_NAME, dialog );
 
        {
                auto vbox = create_dialog_vbox( 4, 4 );
@@ -434,11 +448,11 @@ void DoAbout(){
 
                {
             auto hbox = create_dialog_hbox( 4 );
-                       vbox.pack_start( hbox, FALSE, TRUE, 0 );
+                       vbox.pack_start( hbox, FALSE, FALSE, 0 );
 
                        {
                 auto vbox2 = create_dialog_vbox( 4 );
-                               hbox.pack_start( vbox2, TRUE, FALSE, 0 );
+                               hbox.pack_start( vbox2, FALSE, FALSE, 5 );
                                {
                                        auto frame = create_dialog_frame( 0, ui::Shadow::IN );
                                        vbox2.pack_start( frame, FALSE, FALSE, 0 );
@@ -451,29 +465,44 @@ void DoAbout(){
                        }
 
                        {
-                               char const *label_text = "NetRadiant " RADIANT_VERSION "\n"
-                                                                               __DATE__ "\n\n"
-                                        RADIANT_ABOUTMSG "\n\n"
-                                                                               "This program is free software\n"
-                                                                               "licensed under the GNU GPL.\n\n"
-                                                                               "NetRadiant is unsupported, however\n"
-                                                                               "you may report your problems at\n"
-                                                                               "https://gitlab.com/xonotic/netradiant/issues";
-
-                               auto label = ui::Label( label_text );
-
-                               label.show();
-                               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 );
+                               // HACK: that may not be related to font size
+                               auto about_vbox = ui::VBox( FALSE, 5 );
+                               about_vbox.show();
+                               hbox.pack_start( about_vbox, FALSE, FALSE, 0 );
+
+                               AddParagraph( about_vbox,
+                                       RADIANT_NAME " " RADIANT_VERSION_STRING " (" __DATE__ ")\n"
+                                       RADIANT_ABOUTMSG );
+                               AddParagraph( about_vbox,
+                                       "Get news and latest build at "
+                                       "<a href='https://netradiant.gitlab.io/'>"
+                                               "netradiant.gitlab.io"
+                                       "</a>\n"
+                                       "Please report your issues at "
+                                       "<a href='https://gitlab.com/xonotic/netradiant/issues'>"
+                                               "gitlab.com/xonotic/netradiant/issues"
+                                       "</a>\n"
+                                       "The team cannot provide support for custom builds.", true );
+                               AddParagraph( about_vbox,
+                                       RADIANT_NAME " is a community project maintained by "
+                                       "<a href='https://xonotic.org'>"
+                                               "Xonotic"
+                                       "</a>\n"
+                                       "and developed with help from "
+                                       "<a href='https://netradiant.gitlab.io/page/about/'>"
+                                               "other game projects"
+                                       "</a> and individuals. ", true );
+                               AddParagraph( about_vbox,
+                                       "This program is free software licensed under the GNU GPL." );
                        }
 
                        {
                 auto vbox2 = create_dialog_vbox( 4 );
-                               hbox.pack_start( vbox2, FALSE, TRUE, 0 );
+                               hbox.pack_start( vbox2, TRUE, TRUE, 0 );
                                {
                     auto button = create_modal_dialog_button( "OK", ok_button );
                                        vbox2.pack_start( button, FALSE, FALSE, 0 );
+                                       gtk_widget_grab_focus( GTK_WIDGET( button ) );
                                }
                                {
                     auto button = create_dialog_button( "Credits", G_CALLBACK( about_button_credits ), 0 );
@@ -638,13 +667,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 );
 
@@ -655,7 +684,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;
@@ -672,12 +701,13 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
 // master window widget
 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.window().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;
@@ -685,23 +715,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).window().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.window().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();
 }
 
@@ -710,7 +750,7 @@ static void CreateGtkTextEditor(){
 
        dlg.connect( "delete_event",
                                          G_CALLBACK( editor_delete ), 0 );
-       gtk_window_set_default_size( dlg, 600, 300 );
+       gtk_window_set_default_size( dlg, 400, 300 );
 
        auto vbox = ui::VBox( FALSE, 5 );
        vbox.show();
@@ -751,7 +791,7 @@ static void CreateGtkTextEditor(){
        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
 
@@ -776,7 +816,7 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){
                gtk_window_set_title( text_editor, filename );
 
                auto text_buffer = gtk_text_view_get_buffer(ui::TextView::from(text_widget));
-               gtk_text_buffer_set_text( text_buffer, (char*)buf, len );
+               gtk_text_buffer_set_text( text_buffer, (char*)buf, length );
 
                old_filename = g_object_get_data( G_OBJECT( text_editor ), "filename" );
                if ( old_filename ) {
@@ -800,12 +840,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 );
        }
@@ -883,7 +925,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 );
 
@@ -892,6 +933,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);
@@ -905,13 +947,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;
                        }
                }
                {
@@ -1001,18 +1041,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 << "\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 << "\n";
+               }
                return;
        }
 #else
@@ -1032,7 +1109,7 @@ void DoTextEditor( const char* filename, int cursorpos ){
                        return;
                }
        }
-#endif
 
-       DoGtkTextEditor( filename, cursorpos );
+       DoGtkTextEditor( filename, cursorpos, length );
+#endif
 }