From c9e9df95acfe40c66e3089c422c3923b9194776a Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 2 Jun 2015 22:04:23 +0200 Subject: [PATCH] Show default keyboard shortcuts in the menu next to Save State and Load State. I can't figure out how to get the keycodes that have been modified by PCSX2_keys.ini, but this should give a decent base. I think you would just need to call AppendKeycodeNamesToMenuOptions again after GlobalAccels has been updated correctly, if I'm understanding this right, but I couldn't get it to work. --- pcsx2/gui/MainFrame.cpp | 22 ++++++++++++++++++++++ pcsx2/gui/MainFrame.h | 1 + 2 files changed, 23 insertions(+) diff --git a/pcsx2/gui/MainFrame.cpp b/pcsx2/gui/MainFrame.cpp index 337818be20..a09c4a3f4b 100644 --- a/pcsx2/gui/MainFrame.cpp +++ b/pcsx2/gui/MainFrame.cpp @@ -24,6 +24,9 @@ #include +#include +#include "AppAccelerators.h" + #include "svnrev.h" // ------------------------------------------------------------------------ @@ -530,6 +533,7 @@ MainEmuFrame::MainEmuFrame(wxWindow* parent, const wxString& title) ApplyCoreStatus(); ApplySettings(); + AppendKeycodeNamesToMenuOptions(); } MainEmuFrame::~MainEmuFrame() throw() @@ -696,6 +700,24 @@ void MainEmuFrame::CommitPreset_noTrigger() g_Conf->EmuOptions.EnablePatches = menubar.IsChecked( MenuId_EnablePatches ); } +static void AppendShortcutToMenuOption( wxMenuItem& item, const char* id ) { + // this is NOT how a dictionary works but it has like 30 entries so this should still perform okay + auto* dict = &wxGetApp().GlobalAccels; + for ( auto it = ( *dict )->begin(); it != ( *dict )->end(); ++it ) { + if ( strcmp( it->second->Id, id ) == 0 ) { + wxString text = item.GetItemLabel(); + size_t tabPos = text.rfind( L'\t' ); + KeyAcceleratorCode keycode( (wxKeyCode)it->first ); + item.SetItemLabel( text.Mid( 0, tabPos ) + L"\t" + keycode.ToString() ); + } + } +} + +void MainEmuFrame::AppendKeycodeNamesToMenuOptions() { + AppendShortcutToMenuOption( *m_menuSys.FindChildItem( MenuId_Sys_LoadStates ), "States_DefrostCurrentSlot" ); + AppendShortcutToMenuOption( *m_menuSys.FindChildItem( MenuId_Sys_SaveStates ), "States_FreezeCurrentSlot" ); +} + // ------------------------------------------------------------------------ // "Extensible" Plugin Menus diff --git a/pcsx2/gui/MainFrame.h b/pcsx2/gui/MainFrame.h index f153ccada7..71d75da5a2 100644 --- a/pcsx2/gui/MainFrame.h +++ b/pcsx2/gui/MainFrame.h @@ -150,6 +150,7 @@ public: void ApplyConfigToGui( AppConfig& configToApply, int flags=0 ); //flags are: AppConfig::APPLY_CONFIG_FROM_PRESET and (currently unused) AppConfig::APPLY_CONFIG_MANUALLY PROPAGATE void CommitPreset_noTrigger(); + void AppendKeycodeNamesToMenuOptions(); protected: void DoGiveHelp(const wxString& text, bool show);