]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/mainframe.cpp
radiant: code to make radiant able to restart itself
[xonotic/netradiant.git] / radiant / mainframe.cpp
index d84fe69fbfa02201b0179fbe6f44d3682d883f46..663ca30374b3ef35e8144f0b7b02890afaa0ee6c 100644 (file)
 #include "referencecache.h"
 #include "texwindow.h"
 
+#if GDEF_OS_WINDOWS
+#include <process.h>
+#else
+#include <spawn.h>
+#endif
+
+#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
+/* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
+#define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) g_object_set_data( G_OBJECT( window ), "glwidget", G_OBJECT( widget ) )
+#else
+#define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget)
+#endif
 
 struct layout_globals_t
 {
@@ -438,12 +450,18 @@ void setPakPath( int num, const char* path ){
 }
 
 
-// App Path
+// executable file path (full path)
+CopiedString g_strAppFilePath;
 
-CopiedString g_strAppPath;                 ///< holds the full path of the executable
+// directory paths
+CopiedString g_strAppPath; 
 CopiedString g_strLibPath;
 CopiedString g_strDataPath;
 
+const char* AppFilePath_get(){
+       return g_strAppFilePath.c_str();
+}
+
 const char* AppPath_get(){
        return g_strAppPath.c_str();
 }
@@ -3091,6 +3109,8 @@ void MainFrame::Create(){
                        }
                        CamWnd_setParent( *m_pCamWnd, window );
 
+                       WORKAROUND_GOBJECT_SET_GLWIDGET( window, CamWnd_getWidget( *m_pCamWnd ) );
+
                        g_floating_windows.push_back( window );
                }
 
@@ -3110,6 +3130,8 @@ void MainFrame::Create(){
                        }
                        XY_Top_Shown_Construct( window );
 
+                       WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXYWnd->GetWidget() );
+
                        g_floating_windows.push_back( window );
                }
 
@@ -3129,6 +3151,8 @@ void MainFrame::Create(){
 
                        XZ_Front_Shown_Construct( window );
 
+                       WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXZWnd->GetWidget() );
+
                        g_floating_windows.push_back( window );
                }
 
@@ -3148,12 +3172,16 @@ void MainFrame::Create(){
 
                        YZ_Side_Shown_Construct( window );
 
+                       WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pYZWnd->GetWidget() );
+
                        g_floating_windows.push_back( window );
                }
 
                {
                        auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) );
                        g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
+
+                       WORKAROUND_GOBJECT_SET_GLWIDGET( GroupDialog_getWindow(), TextureBrowser_getGLWidget() );
                }
 
                GroupDialog_show();
@@ -3187,6 +3215,8 @@ void MainFrame::Create(){
                {
             auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) );
                        g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() );
+
+                       WORKAROUND_GOBJECT_SET_GLWIDGET( window, TextureBrowser_getGLWidget() );
                }
        }
 
@@ -3592,3 +3622,44 @@ void GLWindow_Construct(){
 
 void GLWindow_Destroy(){
 }
+
+void Radiant_Restart(){
+       // preferences are expected to be already saved in any way
+       // this is just to be sure and be future proof
+       Preferences_Save();
+
+       // this asks user for saving if map is modified
+       // user can chose to not save, it's ok
+       ConfirmModified( "Restart " RADIANT_NAME );
+
+       int status;
+
+       char *argv[ 3 ];
+       char exe_file[ 256 ];
+       char map_file[ 256 ];
+       bool with_map = false;
+
+       strncpy( exe_file, g_strAppFilePath.c_str(), 256 );
+
+       if ( !Map_Unnamed( g_map ) ) {
+               strncpy( map_file, Map_Name( g_map ), 256 );
+               with_map = true;
+       }
+
+       argv[ 0 ] = exe_file;
+       argv[ 1 ] = with_map ? map_file : NULL;
+       argv[ 2 ] = NULL;
+
+#if GDEF_OS_WINDOWS
+       status = !_spawnvpe( P_NOWAIT, exe_file, argv, environ );
+#else
+       pid_t pid;
+
+       status = posix_spawn( &pid, exe_file, NULL, NULL, argv, environ );
+#endif
+
+       // quit if radiant successfully started
+       if ( status == 0 ) {
+               gtk_main_quit();
+       }
+}