]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/gtkdlgs.cpp
Radiant:
[xonotic/netradiant.git] / radiant / gtkdlgs.cpp
index 7bdea67d7ada63463151199f5e8426723e50769b..3780aecc3370e091fea16f8675426dfe36483925 100644 (file)
@@ -82,6 +82,9 @@
 #include "url.h"
 #include "cmdlib.h"
 
+#include "qerplugin.h"
+#include "os/file.h"
+
 
 
 // =============================================================================
@@ -465,7 +468,7 @@ void DoAbout(){
                                        GtkFrame* frame = create_dialog_frame( 0, GTK_SHADOW_IN );
                                        gtk_box_pack_start( GTK_BOX( vbox2 ), GTK_WIDGET( frame ), FALSE, FALSE, 0 );
                                        {
-                                               GtkImage* image = new_local_image( "logo.bmp" );
+                                               GtkImage* image = new_local_image( "logo.png" );
                                                gtk_widget_show( GTK_WIDGET( image ) );
                                                gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( image ) );
                                        }
@@ -708,12 +711,13 @@ EMessageBoxReturn DoTextureLayout( float *fx, float *fy ){
 // master window widget
 static GtkWidget *text_editor = 0;
 static GtkWidget *text_widget; // slave, text widget from the gtk editor
+static GtkTextBuffer* text_buffer_;
 
 static gint editor_delete( GtkWidget *widget, gpointer data ){
-       if ( gtk_MessageBox( widget, "Close the shader editor ?", "Radiant", eMB_YESNO, eMB_ICONQUESTION ) == eIDNO ) {
+/*     if ( gtk_MessageBox( widget, "Close the shader editor ?", "Radiant", eMB_YESNO, eMB_ICONQUESTION ) == eIDNO ) {
                return TRUE;
        }
-
+*/
        gtk_widget_hide( text_editor );
 
        return TRUE;
@@ -721,23 +725,33 @@ static gint editor_delete( GtkWidget *widget, gpointer data ){
 
 static void editor_save( GtkWidget *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 ) {
                gtk_MessageBox( GTK_WIDGET( data ), "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( GtkWidget *widget, gpointer data ){
-       if ( gtk_MessageBox( text_editor, "Close the shader editor ?", "Radiant", eMB_YESNO, eMB_ICONQUESTION ) == eIDNO ) {
+/*     if ( gtk_MessageBox( text_editor, "Close the shader editor ?", "Radiant", eMB_YESNO, eMB_ICONQUESTION ) == eIDNO ) {
                return;
        }
-
+*/
        gtk_widget_hide( text_editor );
 }
 
@@ -749,7 +763,7 @@ static void CreateGtkTextEditor(){
 
        g_signal_connect( G_OBJECT( dlg ), "delete_event",
                                          G_CALLBACK( editor_delete ), 0 );
-       gtk_window_set_default_size( GTK_WINDOW( dlg ), 600, 300 );
+       gtk_window_set_default_size( GTK_WINDOW( dlg ), 400, 600 );
 
        vbox = gtk_vbox_new( FALSE, 5 );
        gtk_widget_show( vbox );
@@ -790,7 +804,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
 
@@ -815,7 +829,7 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos ){
                gtk_window_set_title( GTK_WINDOW( 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 );
+               gtk_text_buffer_set_text( text_buffer, (char*)buf, length );
 
                old_filename = g_object_get_data( G_OBJECT( text_editor ), "filename" );
                if ( old_filename ) {
@@ -839,12 +853,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
                gtk_widget_queue_draw( text_widget );
 #endif
 
+               text_buffer_ = text_buffer;
                free( buf );
                fclose( f );
        }
@@ -1040,18 +1056,55 @@ EMessageBoxReturn DoShaderInfoDlg( const char* name, const char* filename, char*
 
 #ifdef WIN32
 // 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 ){
 #ifdef WIN32
        if ( g_TextEditor_useWin32Editor ) {
-               globalOutputStream() << "opening file '" << filename << "' (line " << cursorpos << " info ignored)\n";
-               ShellExecute( (HWND)GDK_WINDOW_HWND( GTK_WIDGET( MainFrame_getWindow() )->window ), "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( MainFrame_getWindow() )->window ), "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( MainFrame_getWindow() )->window ), "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
@@ -1071,7 +1124,7 @@ void DoTextEditor( const char* filename, int cursorpos ){
                        return;
                }
        }
-#endif
 
-       DoGtkTextEditor( filename, cursorpos );
+       DoGtkTextEditor( filename, cursorpos, length );
+#endif
 }