From: Thomas Debesse Date: Mon, 20 Feb 2023 15:36:37 +0000 (+0100) Subject: radiant: use the same shortcuts.ini file for all games X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=29ebf0ce08f46674be77ded41c895b5554adc384;p=xonotic%2Fnetradiant.git radiant: use the same shortcuts.ini file for all games --- diff --git a/radiant/commands.cpp b/radiant/commands.cpp index 92a2d00c..3cf44d82 100644 --- a/radiant/commands.cpp +++ b/radiant/commands.cpp @@ -31,6 +31,13 @@ #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 ShortcutValue; // accelerator, isRegistered typedef std::map 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 ) { diff --git a/radiant/commands.h b/radiant/commands.h index 8c6b9f19..9e0e9059 100644 --- a/radiant/commands.h +++ b/radiant/commands.h @@ -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 diff --git a/radiant/main.cpp b/radiant/main.cpp index 6c8ffd03..87fa8470 100644 --- a/radiant/main.cpp +++ b/radiant/main.cpp @@ -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,