]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/gtkdlgs.cpp
Merge commit 'dd7f4f1689e8ede7580bdfa8e08d0b78d08f5253' into garux-merge
[xonotic/netradiant.git] / radiant / gtkdlgs.cpp
index 476e189f81af041ae8761d204d9b4e5bdb8b5540..4e38e3822e18d66c2aea6e20dced9d4f80ba83d3 100644 (file)
@@ -836,9 +836,9 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos, int length )
                text_editor.show();
                gtk_window_present( GTK_WINDOW( text_editor ) );
 
-#if GDEF_OS_WINDOWS
+//#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
@@ -852,9 +852,9 @@ static void DoGtkTextEditor( const char* filename, guint cursorpos, int length )
                        gtk_text_view_scroll_to_iter( GTK_TEXT_VIEW( text_widget ), &text_iter, 0, TRUE, 0, 0);
                }
 
-#if GDEF_OS_WINDOWS
+//#if GDEF_OS_WINDOWS
                gtk_widget_queue_draw( text_widget );
-#endif
+//#endif
 
                text_buffer_ = text_buffer;
                free( buf );
@@ -1048,77 +1048,72 @@ EMessageBoxReturn DoShaderInfoDlg( const char* name, const char* filename, const
 #include <gdk/gdkwin32.h>
 #endif
 
-#if GDEF_OS_WINDOWS
-// use the file associations to open files instead of builtin Gtk editor
-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, int length ){
-#if GDEF_OS_WINDOWS
-       if ( g_TextEditor_useWin32Editor ) {
-               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 );
+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;
                }
-               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 );
+
+       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
+                               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{
-                       globalOutputStream() << "Failed to open '" << filename << "'\nOne sits in .pk3 most likely!\n";
+                       DoGtkTextEditor( goodpath->c_str(), cursorpos, length );
                }
-               return;
        }
-#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";
-               }
-               else
-               {
-                       // the command (appeared) to run successfully, no need to do anything more
-                       return;
-               }
+       else{
+               globalOutputStream() << "Failed to open '" << filename << "'\nOne sits in .pk3 most likely!\n";
        }
-
-       DoGtkTextEditor( filename, cursorpos, length );
-#endif
 }