Merge pull request #4428 from lioncash/event

DolphinWX: Move common wxUpdateUIEvent functions to WxEventUtils
This commit is contained in:
Mat M 2016-11-08 17:11:16 -05:00 committed by GitHub
commit e05553acfc
6 changed files with 85 additions and 98 deletions

View File

@ -240,10 +240,6 @@ private:
void OnReloadThemeBitmaps(wxCommandEvent& event); void OnReloadThemeBitmaps(wxCommandEvent& event);
void OnReloadGameList(wxCommandEvent& event); void OnReloadGameList(wxCommandEvent& event);
void OnEnableMenuItemIfCoreInitialized(wxUpdateUIEvent& event);
void OnEnableMenuItemIfCoreUninitialized(wxUpdateUIEvent& event);
void OnEnableMenuItemIfCorePaused(wxUpdateUIEvent& event);
void OnEnableMenuItemIfCPUCanStep(wxUpdateUIEvent& event);
void OnUpdateInterpreterMenuItem(wxUpdateUIEvent& event); void OnUpdateInterpreterMenuItem(wxUpdateUIEvent& event);
void OnOpen(wxCommandEvent& event); // File menu void OnOpen(wxCommandEvent& event); // File menu

View File

@ -74,6 +74,7 @@
#include "DolphinWX/NetPlay/NetWindow.h" #include "DolphinWX/NetPlay/NetWindow.h"
#include "DolphinWX/TASInputDlg.h" #include "DolphinWX/TASInputDlg.h"
#include "DolphinWX/WXInputBase.h" #include "DolphinWX/WXInputBase.h"
#include "DolphinWX/WxEventUtils.h"
#include "DolphinWX/WxUtils.h" #include "DolphinWX/WxUtils.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
@ -206,46 +207,42 @@ void CFrame::BindDebuggerMenuBarEvents()
void CFrame::BindDebuggerMenuBarUpdateEvents() void CFrame::BindDebuggerMenuBarUpdateEvents()
{ {
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCPUCanStep, this, IDM_STEP); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_STEP);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCPUCanStep, this, IDM_STEPOUT); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_STEPOUT);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCPUCanStep, this, IDM_STEPOVER); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_STEPOVER);
Bind(wxEVT_UPDATE_UI, &CFrame::OnUpdateInterpreterMenuItem, this, IDM_INTERPRETER); Bind(wxEVT_UPDATE_UI, &CFrame::OnUpdateInterpreterMenuItem, this, IDM_INTERPRETER);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_LS_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_LS_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_LSLXZ_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_LSLXZ_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_LSLWZ_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_LSLWZ_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_LSLBZX_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_LSLBZX_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_LSF_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_LSF_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_LSP_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_LSP_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_FP_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_FP_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_I_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_I_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_P_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_P_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_JIT_SR_OFF); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_JIT_SR_OFF);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCorePaused, this, IDM_CLEAR_CODE_CACHE); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCorePaused, IDM_CLEAR_CODE_CACHE);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_SEARCH_INSTRUCTION); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_SEARCH_INSTRUCTION);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_CLEAR_SYMBOLS); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_CLEAR_SYMBOLS);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_SCAN_FUNCTIONS); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_SCAN_FUNCTIONS);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_LOAD_MAP_FILE); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_LOAD_MAP_FILE);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_SAVEMAPFILE); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_SAVEMAPFILE);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_LOAD_MAP_FILE_AS); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_LOAD_MAP_FILE_AS);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_SAVE_MAP_FILE_AS); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_SAVE_MAP_FILE_AS);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_LOAD_BAD_MAP_FILE); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_LOAD_BAD_MAP_FILE);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_SAVE_MAP_FILE_WITH_CODES);
IDM_SAVE_MAP_FILE_WITH_CODES); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_CREATE_SIGNATURE_FILE);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_APPEND_SIGNATURE_FILE);
IDM_CREATE_SIGNATURE_FILE); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_COMBINE_SIGNATURE_FILES);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_RENAME_SYMBOLS);
IDM_APPEND_SIGNATURE_FILE); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_USE_SIGNATURE_FILE);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreInitialized, IDM_PATCH_HLE_FUNCTIONS);
IDM_COMBINE_SIGNATURE_FILES);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_RENAME_SYMBOLS);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_USE_SIGNATURE_FILE);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreInitialized, this, IDM_PATCH_HLE_FUNCTIONS);
Bind(wxEVT_UPDATE_UI, &CFrame::OnEnableMenuItemIfCoreUninitialized, this, IDM_JIT_NO_BLOCK_CACHE); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreUninitialized, IDM_JIT_NO_BLOCK_CACHE);
} }
wxToolBar* CFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) wxToolBar* CFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
@ -1065,29 +1062,9 @@ void CFrame::OnReloadGameList(wxCommandEvent& WXUNUSED(event))
UpdateGameList(); UpdateGameList();
} }
void CFrame::OnEnableMenuItemIfCoreInitialized(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() != Core::CORE_UNINITIALIZED);
}
void CFrame::OnEnableMenuItemIfCoreUninitialized(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() == Core::CORE_UNINITIALIZED);
}
void CFrame::OnEnableMenuItemIfCorePaused(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() == Core::CORE_PAUSE);
}
void CFrame::OnEnableMenuItemIfCPUCanStep(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() != Core::CORE_UNINITIALIZED && CPU::IsStepping());
}
void CFrame::OnUpdateInterpreterMenuItem(wxUpdateUIEvent& event) void CFrame::OnUpdateInterpreterMenuItem(wxUpdateUIEvent& event)
{ {
OnEnableMenuItemIfCorePaused(event); WxEventUtils::OnEnableIfCorePaused(event);
if (GetMenuBar()->FindItem(IDM_INTERPRETER)->IsChecked()) if (GetMenuBar()->FindItem(IDM_INTERPRETER)->IsChecked())
return; return;

View File

@ -8,8 +8,8 @@
#include <utility> #include <utility>
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/CPU.h"
#include "DolphinWX/Globals.h" #include "DolphinWX/Globals.h"
#include "DolphinWX/WxEventUtils.h"
#include "DolphinWX/WxUtils.h" #include "DolphinWX/WxUtils.h"
wxDEFINE_EVENT(DOLPHIN_EVT_RELOAD_TOOLBAR_BITMAPS, wxCommandEvent); wxDEFINE_EVENT(DOLPHIN_EVT_RELOAD_TOOLBAR_BITMAPS, wxCommandEvent);
@ -38,42 +38,20 @@ void MainToolBar::BindEvents()
void MainToolBar::BindMainButtonEvents() void MainToolBar::BindMainButtonEvents()
{ {
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreNotRunning, this, wxID_OPEN); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning, wxID_OPEN);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreNotRunning, this, wxID_REFRESH); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreNotRunning, wxID_REFRESH);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreRunningOrPaused, this, IDM_STOP); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreRunningOrPaused, IDM_STOP);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreRunningOrPaused, this, IDM_TOGGLE_FULLSCREEN); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreRunningOrPaused, IDM_TOGGLE_FULLSCREEN);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreRunningOrPaused, this, IDM_SCREENSHOT); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCoreRunningOrPaused, IDM_SCREENSHOT);
} }
void MainToolBar::BindDebuggerButtonEvents() void MainToolBar::BindDebuggerButtonEvents()
{ {
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_STEP); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_STEP);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_STEPOVER); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_STEPOVER);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_STEPOUT); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_STEPOUT);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_SKIP); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_SKIP);
Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCorePaused, this, IDM_SETPC); Bind(wxEVT_UPDATE_UI, &WxEventUtils::OnEnableIfCPUCanStep, IDM_SETPC);
}
void MainToolBar::OnUpdateIfCoreNotRunning(wxUpdateUIEvent& event)
{
event.Enable(!Core::IsRunning());
}
void MainToolBar::OnUpdateIfCorePaused(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() == Core::CORE_PAUSE);
}
void MainToolBar::OnUpdateIfCoreRunningOrPaused(wxUpdateUIEvent& event)
{
const auto state = Core::GetState();
event.Enable(state == Core::CORE_RUN || state == Core::CORE_PAUSE);
}
void MainToolBar::OnUpdateIfCPUCanStep(wxUpdateUIEvent& event)
{
event.Enable(Core::IsRunning() && CPU::IsStepping());
} }
void MainToolBar::OnReloadBitmaps(wxCommandEvent& WXUNUSED(event)) void MainToolBar::OnReloadBitmaps(wxCommandEvent& WXUNUSED(event))

View File

@ -53,11 +53,6 @@ private:
void BindMainButtonEvents(); void BindMainButtonEvents();
void BindDebuggerButtonEvents(); void BindDebuggerButtonEvents();
void OnUpdateIfCoreNotRunning(wxUpdateUIEvent&);
void OnUpdateIfCorePaused(wxUpdateUIEvent&);
void OnUpdateIfCoreRunningOrPaused(wxUpdateUIEvent&);
void OnUpdateIfCPUCanStep(wxUpdateUIEvent&);
void OnReloadBitmaps(wxCommandEvent&); void OnReloadBitmaps(wxCommandEvent&);
void InitializeBitmaps(); void InitializeBitmaps();

View File

@ -6,15 +6,48 @@
#include <wx/event.h> #include <wx/event.h>
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/CPU.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
namespace WxEventUtils namespace WxEventUtils
{ {
void OnEnableIfCoreInitialized(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() != Core::CORE_UNINITIALIZED);
}
void OnEnableIfCoreUninitialized(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() == Core::CORE_UNINITIALIZED);
}
void OnEnableIfCoreRunning(wxUpdateUIEvent& event)
{
event.Enable(Core::IsRunning());
}
void OnEnableIfCoreNotRunning(wxUpdateUIEvent& event) void OnEnableIfCoreNotRunning(wxUpdateUIEvent& event)
{ {
event.Enable(!Core::IsRunning()); event.Enable(!Core::IsRunning());
} }
void OnEnableIfCorePaused(wxUpdateUIEvent& event)
{
event.Enable(Core::GetState() == Core::CORE_PAUSE);
}
void OnEnableIfCoreRunningOrPaused(wxUpdateUIEvent& event)
{
const auto state = Core::GetState();
event.Enable(state == Core::CORE_RUN || state == Core::CORE_PAUSE);
}
void OnEnableIfCPUCanStep(wxUpdateUIEvent& event)
{
event.Enable(Core::IsRunning() && CPU::IsStepping());
}
void OnEnableIfNetplayNotRunning(wxUpdateUIEvent& event) void OnEnableIfNetplayNotRunning(wxUpdateUIEvent& event)
{ {
event.Enable(!NetPlay::IsNetPlayRunning()); event.Enable(!NetPlay::IsNetPlayRunning());

View File

@ -12,6 +12,14 @@ class wxUpdateUIEvent;
namespace WxEventUtils namespace WxEventUtils
{ {
void OnEnableIfCoreInitialized(wxUpdateUIEvent&);
void OnEnableIfCoreUninitialized(wxUpdateUIEvent&);
void OnEnableIfCoreRunning(wxUpdateUIEvent&);
void OnEnableIfCoreNotRunning(wxUpdateUIEvent&); void OnEnableIfCoreNotRunning(wxUpdateUIEvent&);
void OnEnableIfCorePaused(wxUpdateUIEvent&);
void OnEnableIfCoreRunningOrPaused(wxUpdateUIEvent&);
void OnEnableIfCPUCanStep(wxUpdateUIEvent&);
void OnEnableIfNetplayNotRunning(wxUpdateUIEvent&); void OnEnableIfNetplayNotRunning(wxUpdateUIEvent&);
} // namespace WxEventUtils } // namespace WxEventUtils