Skip to content

Commit

Permalink
Close dialogs if desired before dispatching actions (which may reopen…
Browse files Browse the repository at this point in the history
… dialogs)
  • Loading branch information
slouken committed Dec 1, 2012
1 parent 5d61707 commit a4db4c3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions screenlib/UIDialogButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ UIDialogButton::OnClick()
static_cast<UIDialog*>(panel)->SetDialogStatus(m_statusID);
}

UIElementButton::OnClick();

// Hide before doing the action (which may change the current panel)
if (m_closeDialog && panel) {
GetUI()->HidePanel(panel);
}

UIElementButton::OnClick();
}
6 changes: 6 additions & 0 deletions screenlib/UIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ UIManager::GetCurrentPanel()
return NULL;
}

bool
UIManager::IsShown(UIPanel *panel) const
{
return (panel && m_visible.find(panel));
}

void
UIManager::ShowPanel(UIPanel *panel)
{
Expand Down
1 change: 1 addition & 0 deletions screenlib/UIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class UIManager : public UIArea, public UIFontInterface, public UIImageInterface
m_panels.remove(panel);
}

bool IsShown(UIPanel *panel) const;
void ShowPanel(UIPanel *panel);
void ShowPanel(const char *name) {
ShowPanel(GetPanel(name));
Expand Down
7 changes: 6 additions & 1 deletion screenlib/UIPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ UIPanel::Action(UIBaseElement *sender, const char *action)
}

// Dialogs pass actions to their parents
UIPanel *panel = m_ui->GetPrevPanel(this);
UIPanel *panel;
if (m_ui->IsShown(this)) {
panel = m_ui->GetPrevPanel(this);
} else {
panel = m_ui->GetCurrentPanel();
}
if (panel) {
panel->Action(sender, action);
} else {
Expand Down
2 changes: 1 addition & 1 deletion utils/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class array
array() : m_len(0), m_max(1), m_data((T*)malloc(sizeof(T))) { }
~array() { free(m_data); }

bool find(const T& item) {
bool find(const T& item) const {
for (unsigned i = 0; i < m_len; ++i) {
if (m_data[i] == item) {
return true;
Expand Down

0 comments on commit a4db4c3

Please sign in to comment.