Centralize handling of modal error display.

This commit is contained in:
Jared Boone 2016-05-17 09:33:16 -07:00
parent 682a1706a3
commit 6a3cd4c144
4 changed files with 16 additions and 2 deletions

View File

@ -140,7 +140,7 @@ AnalogAudioView::AnalogAudioView(
};
record_view.on_error = [&nav](std::string message) {
nav.push<ModalMessageView>(message);
nav.display_error(message);
};
audio::output::start();

View File

@ -71,7 +71,7 @@ CaptureAppView::CaptureAppView(NavigationView& nav) {
record_view.set_sampling_rate(sampling_rate / 8);
record_view.on_error = [&nav](std::string message) {
nav.push<ModalMessageView>(message);
nav.display_error(message);
};
}

View File

@ -117,6 +117,10 @@ View* NavigationView::push_view(std::unique_ptr<View> new_view) {
}
void NavigationView::pop() {
if( view() == modal_view ) {
modal_view = nullptr;
}
// Can't pop last item from stack.
if( view_stack.size() > 1 ) {
free_view();
@ -127,6 +131,13 @@ void NavigationView::pop() {
}
}
void NavigationView::display_error(const std::string& message) {
/* If a modal view is already visible, don't display another */
if( !modal_view ) {
modal_view = push<ModalMessageView>(message);
}
}
void NavigationView::free_view() {
remove_child(view());
}

View File

@ -102,10 +102,13 @@ public:
void pop();
void display_error(const std::string& message);
void focus() override;
private:
std::vector<std::unique_ptr<View>> view_stack;
Widget* modal_view { nullptr };
Widget* view() const;