Skip to content

Commit e1ac828

Browse files
committed
disable buttons in obvious cases
1 parent 8e5681a commit e1ac828

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

src/mpc-hc/PPageToolBar.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,59 @@ BEGIN_MESSAGE_MAP(CPPageToolBar, CMPCThemePPageBase)
133133
ON_BN_CLICKED(IDC_BUTTON5, &CPPageToolBar::MoveUp)
134134
ON_BN_CLICKED(IDC_BUTTON6, &CPPageToolBar::MoveDown)
135135
ON_BN_CLICKED(IDC_BUTTON1, &CPPageToolBar::DefaultButtons)
136+
ON_UPDATE_COMMAND_UI(IDC_BUTTON3, OnUpdateLeft)
137+
ON_UPDATE_COMMAND_UI(IDC_BUTTON4, OnUpdateRight)
138+
ON_UPDATE_COMMAND_UI(IDC_BUTTON5, OnUpdateUp)
139+
ON_UPDATE_COMMAND_UI(IDC_BUTTON6, OnUpdateDown)
136140
END_MESSAGE_MAP()
137141

142+
void CPPageToolBar::OnUpdateLeft(CCmdUI* pCmdUI) {
143+
CPlayerToolBar& tb = AfxGetMainFrame()->m_wndToolBar;
144+
CToolBarCtrl& tbctrl = tb.GetToolBarCtrl();
145+
auto supportedButtons = tb.GetSupportedSvgButtons();
146+
147+
int selectedRowLeft = m_list_active.GetSelectionMark();
148+
int selectedRowRight = m_list_inactive.GetSelectionMark();
149+
150+
if (IsValidInsertPos(selectedRowLeft) && -1 != selectedRowRight) {
151+
pCmdUI->Enable(true);
152+
} else {
153+
pCmdUI->Enable(false);
154+
}
155+
}
156+
157+
bool CPPageToolBar::LeftSelectedButtonLocked() {
158+
CPlayerToolBar& tb = AfxGetMainFrame()->m_wndToolBar;
159+
CToolBarCtrl& tbctrl = tb.GetToolBarCtrl();
160+
auto supportedButtons = tb.GetSupportedSvgButtons();
161+
162+
int selectedRowLeft = m_list_active.GetSelectionMark();
163+
164+
bool enable = false;
165+
if (-1 != selectedRowLeft) {
166+
int tidCommand = (int)m_list_active.GetItemData(selectedRowLeft);
167+
if (supportedButtons.count(tidCommand) == 0 || supportedButtons[tidCommand].positionLocked) {
168+
enable = false;
169+
} else {
170+
enable = true;
171+
}
172+
}
173+
return enable;
174+
}
175+
176+
void CPPageToolBar::OnUpdateRight(CCmdUI* pCmdUI) {
177+
pCmdUI->Enable(LeftSelectedButtonLocked());
178+
}
179+
180+
void CPPageToolBar::OnUpdateUp(CCmdUI* pCmdUI) {
181+
pCmdUI->Enable(LeftSelectedButtonLocked());
182+
}
183+
184+
void CPPageToolBar::OnUpdateDown(CCmdUI* pCmdUI) {
185+
pCmdUI->Enable(LeftSelectedButtonLocked());
186+
}
187+
188+
138189
bool CPPageToolBar::InsertButton(int beforeID, int buttonID) {
139190
CPlayerToolBar& tb = AfxGetMainFrame()->m_wndToolBar;
140191
CToolBarCtrl& tbctrl = tb.GetToolBarCtrl();
@@ -175,6 +226,7 @@ bool CPPageToolBar::IsValidInsertPos(int destRow) {
175226
if (destRow == -1 || destRow >= m_list_active.GetItemCount()) {
176227
return false;
177228
}
229+
178230
//avoid inserting between two locked rows, or before first locked or after last locked
179231

180232
CPlayerToolBar& tb = AfxGetMainFrame()->m_wndToolBar;

src/mpc-hc/PPageToolBar.h

+5
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,17 @@ class CPPageToolBar : public CMPCThemePPageBase
5555
CImage arrow;
5656

5757
virtual void DoDataExchange(CDataExchange* pDX) override;
58+
void OnUpdateLeft(CCmdUI* pCmdUI);
59+
void OnUpdateRight(CCmdUI* pCmdUI);
60+
void OnUpdateUp(CCmdUI* pCmdUI);
61+
void OnUpdateDown(CCmdUI* pCmdUI);
5862
void LoadToolBarButtons();
5963
virtual BOOL OnInitDialog() override;
6064
virtual BOOL OnApply() override;
6165
bool InsertButton(int beforeID, int buttonID);
6266
bool DeleteButton(int buttonID);
6367
bool IsValidInsertPos(int destRow);
68+
bool LeftSelectedButtonLocked();
6469
bool MoveButton(CMPCThemePlayerListCtrl& srcList, CMPCThemePlayerListCtrl& dstList);
6570
bool OrderButton(ButtonPosition pos);
6671

0 commit comments

Comments
 (0)