]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
radiant: use the same shortcuts.ini file for all games
authorThomas Debesse <dev@illwieckz.net>
Mon, 20 Feb 2023 15:36:37 +0000 (16:36 +0100)
committerThomas Debesse <dev@illwieckz.net>
Mon, 20 Feb 2023 15:36:37 +0000 (16:36 +0100)
radiant/commands.cpp
radiant/commands.h
radiant/main.cpp

index 92a2d00c12b69a43e5eb4714695fd6c69fcf6847..3cf44d82943d9d90ec18c559331a7c8a01c7c583 100644 (file)
 #include "gtkutil/messagebox.h"
 #include "gtkmisc.h"
 
+#define NETRADIANT_CUSTOM_FULLY_MERGED 0
+#if NETRADIANT_CUSTOM_FULLY_MERGED
+// For deleting old shortcuts.ini file
+#include "preferences.h"
+#include "unistd.h"
+#endif // NETRADIANT_CUSTOM_FULLY_MERGED
+
 typedef std::pair<Accelerator, int> ShortcutValue; // accelerator, isRegistered
 typedef std::map<CopiedString, ShortcutValue> Shortcuts;
 
@@ -477,9 +484,19 @@ public:
 
 const char* const COMMANDS_VERSION = "1.0-gtk-accelnames";
 
-void SaveCommandMap( const char* path ){
+void DeleteOldCommandMap(){
+#if NETRADIANT_CUSTOM_FULLY_MERGED
+// To enable when NetRadiant and NetRadiant-custom are fully merged together.
+       StringOutputStream path( 256 );
+       path << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << '/';
+       path << "shortcuts.ini";
+       unlink( path.c_str() );
+#endif
+}
+
+void SaveCommandMap(){
        StringOutputStream strINI( 256 );
-       strINI << path << "shortcuts.ini";
+       strINI << SettingsPath_get() << "shortcuts.ini";
 
        TextFileOutputStream file( strINI.c_str() );
        if ( !file.failed() ) {
@@ -503,6 +520,8 @@ public:
                } visitor( file );
                GlobalShortcuts_foreach( visitor );
        }
+       
+       DeleteOldCommandMap();
 }
 
 const char* stringrange_find( const char* first, const char* last, char c ){
@@ -546,9 +565,9 @@ std::size_t count() const {
 }
 };
 
-void LoadCommandMap( const char* path ){
+void LoadCommandMap(){
        StringOutputStream strINI( 256 );
-       strINI << path << "shortcuts.ini";
+       strINI << SettingsPath_get() << "shortcuts.ini";
 
        FILE* f = fopen( strINI.c_str(), "r" );
        if ( f != 0 ) {
index 8c6b9f19063e1a9d272e34c80c654214f1bdb4ae..9e0e9059f4d491afd105cb029f9f3210d58d6163 100644 (file)
@@ -47,8 +47,8 @@ const KeyEvent& GlobalKeyEvents_find( const char* name );
 
 void DoCommandListDlg();
 
-void LoadCommandMap( const char* path );
-void SaveCommandMap( const char* path );
+void LoadCommandMap();
+void SaveCommandMap();
 
 
 #endif
index 6c8ffd037992e5173a564986264232adbd9f2562..87fa8470e1b063da7c2db420a47b2878c2b7ac67 100644 (file)
@@ -490,16 +490,12 @@ void remove_local_pid(){
 }
 
 void user_shortcuts_init(){
-       StringOutputStream path( 256 );
-       path << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << '/';
-       LoadCommandMap( path.c_str() );
-       SaveCommandMap( path.c_str() );
+       LoadCommandMap();
+       SaveCommandMap();
 }
 
 void user_shortcuts_save(){
-       StringOutputStream path( 256 );
-       path << SettingsPath_get() << g_pGameDescription->mGameFile.c_str() << '/';
-       SaveCommandMap( path.c_str() );
+       SaveCommandMap();
 }
 
 /* HACK: If ui::main is not called yet,