Make the hotkey dialog close when the escape key is pressed. I commit this as an example of how all dialogs should be set up. The buttons used to close the dialog should use wxID_OK or wxID_CANCEL. Alternatively you can use SetEscapeId or SetAffirmativeId to set the escape id to the id you use.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7350 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2011-03-15 13:38:52 +00:00
parent 27142fafe0
commit 1e46f069c2
3 changed files with 18 additions and 36 deletions

View File

@ -1062,12 +1062,11 @@ void CConfigMain::DisplaySettingsChanged(wxCommandEvent& event)
break;
case ID_HOTKEY_CONFIG:
{
HotkeyConfigDialog *m_HotkeyDialog = new HotkeyConfigDialog(this);
m_HotkeyDialog->ShowModal();
m_HotkeyDialog->Destroy();
// Update the GUI in case menu accelerators were changed
main_frame->UpdateGUI();
HotkeyConfigDialog m_HotkeyDialog(this);
m_HotkeyDialog.ShowModal();
}
// Update the GUI in case menu accelerators were changed
main_frame->UpdateGUI();
break;
}
}

View File

@ -22,10 +22,10 @@
BEGIN_EVENT_TABLE(HotkeyConfigDialog,wxDialog)
EVT_CLOSE(HotkeyConfigDialog::OnClose)
EVT_BUTTON(ID_CLOSE, HotkeyConfigDialog::CloseClick)
EVT_BUTTON(wxID_OK, HotkeyConfigDialog::CloseClick)
EVT_COMMAND_RANGE(0, NUM_HOTKEYS - 1,
wxEVT_COMMAND_BUTTON_CLICKED, HotkeyConfigDialog::OnButtonClick)
EVT_TIMER(IDTM_BUTTON, HotkeyConfigDialog::OnButtonTimer)
EVT_TIMER(wxID_ANY, HotkeyConfigDialog::OnButtonTimer)
END_EVENT_TABLE()
HotkeyConfigDialog::HotkeyConfigDialog(wxWindow *parent, wxWindowID id, const wxString &title,
@ -35,7 +35,7 @@ HotkeyConfigDialog::HotkeyConfigDialog(wxWindow *parent, wxWindowID id, const wx
CreateHotkeyGUIControls();
#if wxUSE_TIMER
m_ButtonMappingTimer = new wxTimer(this, IDTM_BUTTON);
m_ButtonMappingTimer = new wxTimer(this, wxID_ANY);
g_Pressed = 0;
g_Modkey = 0;
ClickedButton = NULL;
@ -46,26 +46,19 @@ HotkeyConfigDialog::HotkeyConfigDialog(wxWindow *parent, wxWindowID id, const wx
HotkeyConfigDialog::~HotkeyConfigDialog()
{
if (m_ButtonMappingTimer)
delete m_ButtonMappingTimer;
delete m_ButtonMappingTimer;
}
void HotkeyConfigDialog::OnClose(wxCloseEvent& WXUNUSED (event))
void HotkeyConfigDialog::OnClose(wxCloseEvent& WXUNUSED(event))
{
if (m_ButtonMappingTimer)
m_ButtonMappingTimer->Stop();
m_ButtonMappingTimer->Stop();
EndModal(wxID_CLOSE);
}
void HotkeyConfigDialog::CloseClick(wxCommandEvent& event)
void HotkeyConfigDialog::CloseClick(wxCommandEvent& WXUNUSED(event))
{
switch(event.GetId())
{
case ID_CLOSE:
Close();
break;
}
Close();
}
// Save keyboard key mapping
@ -300,10 +293,9 @@ void HotkeyConfigDialog::CreateHotkeyGUIControls(void)
Page->SetSizer(sPage);
}
m_Close = new wxButton(this, ID_CLOSE, _("Close"));
wxBoxSizer* sButtons = new wxBoxSizer(wxHORIZONTAL);
sButtons->AddStretchSpacer();
sButtons->Add(m_Close, 0, (wxLEFT), 5);
sButtons->Add(new wxButton(this, wxID_OK, _("Close")), 0, (wxLEFT), 5);
wxBoxSizer *sMainSizer = new wxBoxSizer(wxVERTICAL);
sMainSizer->Add(Notebook, 0, wxEXPAND | wxALL, 5);

View File

@ -44,29 +44,21 @@ class HotkeyConfigDialog : public wxDialog
const wxString &title = _("Hotkey Configuration"),
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE | wxWANTS_CHARS);
long style = wxDEFAULT_DIALOG_STYLE);
virtual ~HotkeyConfigDialog();
wxTimer *m_ButtonMappingTimer;
private:
DECLARE_EVENT_TABLE();
enum
{
ID_CLOSE = 1000,
IDTM_BUTTON, // Timer
ID_APPLY
};
wxString OldLabel;
wxButton *m_Close, *m_Apply, *ClickedButton,
wxButton *ClickedButton,
*m_Button_Hotkeys[NUM_HOTKEYS];
wxRadioButton *m_Radio_FSPause[5];
wxTimer *m_ButtonMappingTimer;
void OnClose(wxCloseEvent& event);
void CloseClick(wxCommandEvent& event);
void CloseClick(wxCommandEvent& WXUNUSED(event));
void OnButtonTimer(wxTimerEvent& WXUNUSED(event)) { DoGetButtons(GetButtonWaitingID); }
void OnButtonClick(wxCommandEvent& event);
void OnKeyDown(wxKeyEvent& event);
@ -74,7 +66,6 @@ class HotkeyConfigDialog : public wxDialog
void CreateHotkeyGUIControls(void);
void SetButtonText(int id, const wxString &keystr, const wxString &modkeystr = wxString());
wxString GetButtonText(int id);
void DoGetButtons(int id);
void EndGetButtons(void);