Skip to content

Commit

Permalink
[New] Key bindings with IT-like and FT2-like note entry (but otherwis…
Browse files Browse the repository at this point in the history
…e identical keyboard shortcuts) can now be applied directly from the keyboard settings dialog, without the need for external keymap files.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22201 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 16, 2024
1 parent 58e4f7d commit e6f8878
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 25 deletions.
213 changes: 199 additions & 14 deletions mptrack/CommandSet.cpp

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions mptrack/CommandSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,14 @@ struct KeyCommand
};


enum class KeyboardPreset
{
MPT,
IT,
FT2,
};


enum RuleID
{
krPreventDuplicate,
Expand Down Expand Up @@ -1241,7 +1249,7 @@ class CCommandSet
CommandID FindCmd(uint32 uid) const;
bool KeyCombinationConflict(KeyCombination kc1, KeyCombination kc2, bool checkEventConflict = true) const;

void ApplyDefaultKeybindings(const Version onlyCommandsAfterVersion = {});
void ApplyDefaultKeybindings(KeyboardPreset preset, const Version onlyCommandsAfterVersion = {});

public:
CCommandSet();
Expand Down Expand Up @@ -1272,12 +1280,12 @@ class CCommandSet
bool SaveFile(const mpt::PathString &filename);
bool LoadFile(const mpt::PathString &filename);
bool LoadFile(std::istream &iStrm, const mpt::ustring &filenameDescription);
void LoadDefaultKeymap();
void LoadDefaultKeymap(KeyboardPreset preset = KeyboardPreset::MPT);

static bool MustBeModifierKey(CommandID id);

protected:
const CModSpecifications *m_oldSpecs = nullptr;
const CModSpecifications *m_currentModSpecs = nullptr;
KeyCommand m_commands[kcNumCommands];
std::bitset<kCtxMaxInputContexts> m_isParentContext[kCtxMaxInputContexts];
std::bitset<kNumRules> m_enforceRule;
Expand Down
21 changes: 16 additions & 5 deletions mptrack/KeyConfigDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ BEGIN_MESSAGE_MAP(COptionsKeyboard, CPropertyPage)
ON_COMMAND(IDC_NOTESREPEAT, &COptionsKeyboard::OnNotesRepeat)
ON_COMMAND(IDC_NONOTESREPEAT, &COptionsKeyboard::OnNoNotesRepeat)
ON_COMMAND(IDC_RESTORE_KEYMAP, &COptionsKeyboard::OnRestoreDefaultKeymap)
ON_COMMAND(ID_KEYPRESET_IT, &COptionsKeyboard::OnRestoreITKeymap)
ON_COMMAND(ID_KEYPRESET_FT2, &COptionsKeyboard::OnRestoreFT2Keymap)
ON_EN_CHANGE(IDC_FIND, &COptionsKeyboard::OnSearchTermChanged)
ON_EN_SETFOCUS(IDC_FINDHOTKEY, &COptionsKeyboard::OnClearHotKey)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_COMMAND_LIST, &COptionsKeyboard::OnCommandKeySelChanged)
Expand All @@ -173,6 +175,7 @@ void COptionsKeyboard::DoDataExchange(CDataExchange *pDX)
DDX_Control(pDX, IDC_FIND, m_eFind);
DDX_Control(pDX, IDC_STATIC1, m_warnIconCtl);
DDX_Control(pDX, IDC_KEYREPORT, m_warnText);
DDX_Control(pDX, IDC_RESTORE_KEYMAP, m_restoreDefaultButton);
}


Expand Down Expand Up @@ -208,6 +211,14 @@ BOOL COptionsKeyboard::OnInitDialog()
m_cmbCategory.SetCurSel(0);
UpdateDialog();

CMenu *splitButtonMenu = new CMenu{};
if(splitButtonMenu->CreatePopupMenu())
{
splitButtonMenu->AppendMenu(MF_STRING, ID_KEYPRESET_IT, _T("&Impulse Tracker style"));
splitButtonMenu->AppendMenu(MF_STRING, ID_KEYPRESET_FT2, _T("&Fast Tracker style"));
m_restoreDefaultButton.SetDropDownMenu(splitButtonMenu); // takes ownership of menu pointer
}

m_eCustHotKey.SetOwner(*this);
m_eFindHotKey.SetOwner(*this);

Expand Down Expand Up @@ -1059,10 +1070,10 @@ void COptionsKeyboard::OnNoNotesRepeat()

void COptionsKeyboard::ForceUpdateGUI(bool updateAllKeys)
{
m_forceUpdate = true; // m_nCurKeyChoice and m_nCurHotKey haven't changed, yet we still want to update.
int ntmpChoice = m_curKeyChoice; // next call will overwrite m_nCurKeyChoice
m_forceUpdate = true; // m_curKeyChoice and m_curCommand haven't changed, yet we still want to update.
int curChoice = m_curKeyChoice; // next call will overwrite m_curKeyChoice
OnCommandKeySelChanged(); // update keychoice list
m_cmbKeyChoice.SetCurSel(ntmpChoice); // select fresh keychoice (thus restoring m_nCurKeyChoice)
m_cmbKeyChoice.SetCurSel(curChoice); // select fresh keychoice (thus restoring m_curKeyChoice)
OnKeyChoiceSelect(); // update key data
OnSettingsChanged(); // Enable "apply" button

Expand All @@ -1081,11 +1092,11 @@ void COptionsKeyboard::ForceUpdateGUI(bool updateAllKeys)
}


void COptionsKeyboard::OnRestoreDefaultKeymap()
void COptionsKeyboard::RestoreKeymap(KeyboardPreset preset)
{
if(Reporting::Confirm("Discard all custom changes and restore default key configuration?", false, true, this) == cnfYes)
{
m_localCmdSet->LoadDefaultKeymap();
m_localCmdSet->LoadDefaultKeymap(preset);
ForceUpdateGUI(true);
}
}
Expand Down
8 changes: 6 additions & 2 deletions mptrack/KeyConfigDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "openmpt/all/BuildSettings.hpp"
#include "CListCtrl.h"
#include "InputHandler.h"
#include "CommandSet.h"

OPENMPT_NAMESPACE_BEGIN

Expand Down Expand Up @@ -79,6 +79,7 @@ class COptionsKeyboard: public CPropertyPage
CStatic m_warnIconCtl, m_warnText;
CEdit m_eFind;
CEdit m_eChordWaitTime;
CSplitButton m_restoreDefaultButton;
HICON m_infoIcon = nullptr, m_warnIcon = nullptr;

CString m_lastWarning;
Expand Down Expand Up @@ -116,6 +117,7 @@ class COptionsKeyboard: public CPropertyPage
void EnableKeyChoice(bool enable);

void UpdateWarning(CString text = {}, bool notify = false);
void RestoreKeymap(KeyboardPreset preset);

afx_msg LRESULT OnDPIChangedAfterParent(WPARAM, LPARAM);
afx_msg void UpdateDialog();
Expand All @@ -135,7 +137,9 @@ class COptionsKeyboard: public CPropertyPage
afx_msg void OnRestoreKeyChoice();
afx_msg void OnLoad();
afx_msg void OnSave();
afx_msg void OnRestoreDefaultKeymap();
afx_msg void OnRestoreDefaultKeymap() { RestoreKeymap(KeyboardPreset::MPT); }
afx_msg void OnRestoreITKeymap() { RestoreKeymap(KeyboardPreset::IT); }
afx_msg void OnRestoreFT2Keymap() { RestoreKeymap(KeyboardPreset::FT2); }
afx_msg void OnClearHotKey();
afx_msg void OnClearSearch();
afx_msg void OnEnableFindHotKey();
Expand Down
3 changes: 2 additions & 1 deletion mptrack/mptrack.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,8 @@ BEGIN
EDITTEXT IDC_CHORDDETECTWAITTIME,252,246,30,12,ES_AUTOHSCROLL | ES_NUMBER
PUSHBUTTON "&Import Key Map...",IDC_LOAD,6,264,72,13
PUSHBUTTON "&Export Key Map...",IDC_SAVE,84,264,72,13
PUSHBUTTON "Restore default &configuration",IDC_RESTORE_KEYMAP,162,264,120,12
CONTROL "Restore default &configuration",IDC_RESTORE_KEYMAP,
"Button",BS_SPLITBUTTON | WS_TABSTOP,162,264,120,12
END

IDD_OPTIONS_COLORS DIALOGEX 0, 0, 286, 282
Expand Down
2 changes: 2 additions & 0 deletions mptrack/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,8 @@
#define ID_MAINBAR_SHOW_GLOBALVOLUME 36041
#define ID_MAINBAR_SHOW_VUMETER 36042
#define ID_TREEVIEW_ON_LEFT 36043
#define ID_KEYPRESET_IT 36044
#define ID_KEYPRESET_FT2 36045
#define ID_SELECTINST 36100
// From here: Command range [ID_SELECTINST, ID_SELECTINST + MAX_INSTRUMENTS]
#define ID_PLUG_RECORDAUTOMATION 37003
Expand Down

0 comments on commit e6f8878

Please sign in to comment.