]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Merge branch 'illwieckz/lastmodelfolder' fix !85
authorThomas Debesse <dev@illwieckz.net>
Tue, 2 Oct 2018 23:28:25 +0000 (01:28 +0200)
committerThomas Debesse <dev@illwieckz.net>
Tue, 2 Oct 2018 23:28:25 +0000 (01:28 +0200)
radiant/entity.cpp
radiant/map.cpp

index 797927d069eeb4a6a6cd7b62f12547bc7a96636a..375e54d61f99fb3e2433c429a6434ae8fa0bbcbf 100644 (file)
@@ -40,6 +40,8 @@
 #include "select.h"
 #include "map.h"
 #include "preferences.h"
+#include "preferencesystem.h"
+#include "stringio.h"
 #include "gtkdlgs.h"
 #include "mainframe.h"
 #include "qe3.h"
@@ -536,20 +538,32 @@ void Entity_setColour()
     }
 }
 
-const char *misc_model_dialog(ui::Widget parent)
-{
-    StringOutputStream buffer(1024);
-
-    buffer << g_qeglobals.m_userGamePath.c_str() << "models/";
+CopiedString g_strLastModelFolder = "";
 
-    if (!file_readable(buffer.c_str())) {
-        // just go to fsmain
-        buffer.clear();
-        buffer << g_qeglobals.m_userGamePath.c_str() << "/";
+const char *getLastModelFolderPath()
+{
+    if (g_strLastModelFolder.empty()) {
+        GlobalPreferenceSystem().registerPreference("LastModelFolder", make_property_string(g_strLastModelFolder));
+        if (g_strLastModelFolder.empty()) {
+            StringOutputStream buffer(1024);
+            buffer << g_qeglobals.m_userGamePath.c_str() << "models/";
+            if (!file_readable(buffer.c_str())) {
+                // just go to fsmain
+                buffer.clear();
+                buffer << g_qeglobals.m_userGamePath.c_str() << "/";
+            }
+            g_strLastModelFolder = buffer.c_str();
+        }
     }
+    return g_strLastModelFolder.c_str();
+}
+
+const char *misc_model_dialog(ui::Widget parent)
+{
+    const char *filename = parent.file_dialog(TRUE, "Choose Model", getLastModelFolderPath(), ModelLoader::Name());
 
-    const char *filename = parent.file_dialog(TRUE, "Choose Model", buffer.c_str(), ModelLoader::Name());
-    if (filename != 0) {
+    if (filename != NULL) {
+        g_strLastModelFolder = g_path_get_dirname(filename);
         // use VFS to get the correct relative path
         const char *relative = path_make_relative(filename, GlobalFileSystem().findRoot(filename));
         if (relative == filename) {
@@ -603,9 +617,6 @@ void Entity_constructMenu(ui::Menu menu)
 }
 
 
-#include "preferencesystem.h"
-#include "stringio.h"
-
 void Entity_Construct()
 {
     GlobalCommands_insert("EntityColor", makeCallbackF(Entity_setColour), Accelerator('K'));
index 2cecfe3cd81bc572af7b0c7299a69ac487ba6bdd..9b8e7f90b0abc6d746480f34148aae6b7c35ce53 100644 (file)
@@ -59,6 +59,7 @@ MapModules &ReferenceAPI_getMapModules();
 #include "cmdlib.h"
 #include "stream/textfilestream.h"
 #include "os/path.h"
+#include "os/file.h"
 #include "uniquenames.h"
 #include "modulesystem/singletonmodule.h"
 #include "modulesystem/moduleregistry.h"
@@ -988,7 +989,7 @@ public:
     }
 };
 
-CopiedString g_strLastFolder = "";
+CopiedString g_strLastMapFolder = "";
 
 /*
    ================
@@ -1002,7 +1003,7 @@ void Map_LoadFile(const char *filename)
     ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Map");
 
     MRU_AddFile(filename);
-    g_strLastFolder = g_path_get_dirname(filename);
+    g_strLastMapFolder = g_path_get_dirname(filename);
 
     {
         ScopeTimer timer("map load");
@@ -1596,7 +1597,7 @@ bool Map_ImportFile(const char *filename)
 {
     ScopeDisableScreenUpdates disableScreenUpdates("Processing...", "Loading Map");
 
-    g_strLastFolder = g_path_get_dirname(filename);
+    g_strLastMapFolder = g_path_get_dirname(filename);
 
     bool success = false;
 
@@ -1940,30 +1941,36 @@ const char *getMapsPath()
     return g_mapsPath.c_str();
 }
 
-const char *getLastFolderPath()
+const char *getLastMapFolderPath()
 {
-    if (g_strLastFolder.empty()) {
-        GlobalPreferenceSystem().registerPreference("LastFolder", make_property_string(g_strLastFolder));
-        if (g_strLastFolder.empty()) {
-            g_strLastFolder = g_qeglobals.m_userGamePath;
+    if (g_strLastMapFolder.empty()) {
+        GlobalPreferenceSystem().registerPreference("LastMapFolder", make_property_string(g_strLastMapFolder));
+        if (g_strLastMapFolder.empty()) {
+            StringOutputStream buffer(1024);
+            buffer << getMapsPath();
+            if (!file_readable(buffer.c_str())) {
+                buffer.clear();
+                buffer << g_qeglobals.m_userGamePath.c_str() << "/";
+            }
+            g_strLastMapFolder = buffer.c_str();
         }
     }
-    return g_strLastFolder.c_str();
+    return g_strLastMapFolder.c_str();
 }
 
 const char *map_open(const char *title)
 {
-    return MainFrame_getWindow().file_dialog(TRUE, title, getLastFolderPath(), MapFormat::Name(), true, false, false);
+    return MainFrame_getWindow().file_dialog(TRUE, title, getLastMapFolderPath(), MapFormat::Name(), true, false, false);
 }
 
 const char *map_import(const char *title)
 {
-    return MainFrame_getWindow().file_dialog(TRUE, title, getLastFolderPath(), MapFormat::Name(), false, true, false);
+    return MainFrame_getWindow().file_dialog(TRUE, title, getLastMapFolderPath(), MapFormat::Name(), false, true, false);
 }
 
 const char *map_save(const char *title)
 {
-    return MainFrame_getWindow().file_dialog(FALSE, title, getLastFolderPath(), MapFormat::Name(), false, false, true);
+    return MainFrame_getWindow().file_dialog(FALSE, title, getLastMapFolderPath(), MapFormat::Name(), false, false, true);
 }
 
 void OpenMap()
@@ -1997,7 +2004,7 @@ bool Map_SaveAs()
     const char *filename = map_save("Save Map");
 
     if (filename != NULL) {
-        g_strLastFolder = g_path_get_dirname(filename);
+        g_strLastMapFolder = g_path_get_dirname(filename);
         MRU_AddFile(filename);
         Map_Rename(filename);
         return Map_Save();
@@ -2024,7 +2031,7 @@ void ExportMap()
     const char *filename = map_save("Export Selection");
 
     if (filename != NULL) {
-        g_strLastFolder = g_path_get_dirname(filename);
+        g_strLastMapFolder = g_path_get_dirname(filename);
         Map_SaveSelected(filename);
     }
 }
@@ -2034,7 +2041,7 @@ void SaveRegion()
     const char *filename = map_save("Export Region");
 
     if (filename != NULL) {
-        g_strLastFolder = g_path_get_dirname(filename);
+        g_strLastMapFolder = g_path_get_dirname(filename);
         Map_SaveRegion(filename);
     }
 }