From 8b2aa64d7e4a47093e268c07f08be82a2425ce9e Mon Sep 17 00:00:00 2001 From: avihal Date: Sun, 11 Sep 2011 22:13:02 +0000 Subject: [PATCH] UI: Keyboard shortcuts overrides via PCSX2_keys.ini Keys combination can be: "alt-" and/or "ctrl-" and/or "shift-" and ( F1-F12 or KP_0-KP_9 or SPECIAL1-SPECIAL20 ) Where: Fn is function key n KP_n is numpad number n SPECIALn is hardware button n (whatever that means...) Examples: FullscreenToggle=alt-ctrl-f12 GSwindow_CycleAspectRatio=KP_0 See full configurable strings at the first comment. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4917 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/PathDefs.h | 1 + pcsx2/gui/AppAccelerators.h | 10 ++++++++++ pcsx2/gui/AppConfig.cpp | 11 +++++++++++ pcsx2/gui/AppConfig.h | 2 ++ pcsx2/gui/GlobalCommands.cpp | 24 +++++++++++++++++++++--- 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/pcsx2/PathDefs.h b/pcsx2/PathDefs.h index e249d834c1..35fe2c8eb0 100644 --- a/pcsx2/PathDefs.h +++ b/pcsx2/PathDefs.h @@ -80,6 +80,7 @@ namespace PathDefs namespace FilenameDefs { extern wxFileName GetUiConfig(); + extern wxFileName GetUiKeysConfig(); extern wxFileName GetVmConfig(); extern wxFileName GetUsermodeConfig(); extern const wxFileName& Memcard( uint port, uint slot ); diff --git a/pcsx2/gui/AppAccelerators.h b/pcsx2/gui/AppAccelerators.h index 479fa2122e..673fef7bc1 100644 --- a/pcsx2/gui/AppAccelerators.h +++ b/pcsx2/gui/AppAccelerators.h @@ -39,6 +39,16 @@ struct KeyAcceleratorCode KeyAcceleratorCode() : val32( 0 ) {} KeyAcceleratorCode( const wxKeyEvent& evt ); + + //grab event attributes only + KeyAcceleratorCode( const wxAcceleratorEntry& right) + { + val32 = 0; + keycode = right.GetKeyCode(); + if( right.GetFlags() & wxACCEL_ALT ) Alt(); + if( right.GetFlags() & wxACCEL_CMD ) Cmd(); + if( right.GetFlags() & wxACCEL_SHIFT ) Shift(); + } KeyAcceleratorCode( wxKeyCode code ) { diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index 14f08bc5d5..8878a21777 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -336,6 +336,11 @@ namespace FilenameDefs return pxGetAppName() + L"_ui.ini"; } + wxFileName GetUiKeysConfig() + { + return pxGetAppName() + L"_keys.ini"; + } + wxFileName GetVmConfig() { return pxGetAppName() + L"_vm.ini"; @@ -412,6 +417,12 @@ wxString GetUiSettingsFilename() return GetSettingsFolder().Combine( fname ).GetFullPath(); } +wxString GetUiKeysFilename() +{ + wxFileName fname( FilenameDefs::GetUiKeysConfig() ); + return GetSettingsFolder().Combine( fname ).GetFullPath(); +} + wxString AppConfig::FullpathToBios() const { return Path::Combine( Folders.Bios, BaseFilenames.Bios ); } wxString AppConfig::FullpathToMcd( uint slot ) const diff --git a/pcsx2/gui/AppConfig.h b/pcsx2/gui/AppConfig.h index d66d9763e7..d14484ddcc 100644 --- a/pcsx2/gui/AppConfig.h +++ b/pcsx2/gui/AppConfig.h @@ -63,6 +63,8 @@ extern wxDirName ThemesFolder; extern wxDirName GetSettingsFolder(); extern wxString GetVmSettingsFilename(); extern wxString GetUiSettingsFilename(); +extern wxString GetUiKeysFilename(); + extern wxDirName GetLogFolder(); enum InstallationModeType diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index f99e20d92c..a72f942642 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -55,8 +55,8 @@ wxString KeyAcceleratorCode::ToString() const return wxAcceleratorEntry( (cmd ? wxACCEL_CMD : 0) | - (shift ? wxACCEL_CMD : 0) | - (alt ? wxACCEL_CMD : 0), + (shift ? wxACCEL_SHIFT : 0) | + (alt ? wxACCEL_ALT : 0), keycode ).ToString(); } @@ -530,8 +530,26 @@ AcceleratorDictionary::AcceleratorDictionary() AcceleratorDictionary::~AcceleratorDictionary() throw() {} -void AcceleratorDictionary::Map( const KeyAcceleratorCode& acode, const char *searchfor ) +void AcceleratorDictionary::Map( const KeyAcceleratorCode& _acode, const char *searchfor ) { + // Search override mapping at ini file + KeyAcceleratorCode acode = _acode; + wxString overrideStr; + wxAcceleratorEntry codeParser; //Provides string parsing capabilities + wxFileConfig cfg(L"", L"", L"" , GetUiKeysFilename(), wxCONFIG_USE_GLOBAL_FILE ); + if( cfg.Read( wxString::FromUTF8(searchfor), &overrideStr) ) + { + overrideStr = wxString(L"\t") + overrideStr; + if( codeParser.FromString( overrideStr ) ) // needs a '\t' prefix (originally used for wxMenu accelerators parsing)... + { + //ini file contains alternative parsable key combination for current 'searchfor'. + acode = codeParser; + Console.WriteLn(Color_StrongGreen, L"Overriding '%s': assigning %s (instead of %s)", + fromUTF8( searchfor ).c_str(), acode.ToString().c_str(), _acode.ToString().c_str()); + } + } + // End of overrides section + const GlobalCommandDescriptor* result = NULL; TryGetValue( acode.val32, result );