Skip to content

Commit

Permalink
GUI2/Modeless Dialog: minor cleanup, implement a TODO
Browse files Browse the repository at this point in the history
* Use a unique_ptr for the window member.
* Made use of the new remove_from_window_stack function (its impl was copied from this code)
* Only attempt ows removal if window display mode is modeless (since if mode is tooltip, no
  ptr was added to the list anyway.

# Conflicts:
#	src/gui/dialogs/modeless_dialog.cpp
  • Loading branch information
Vultraz committed Jul 30, 2017
1 parent e724bdf commit db44561
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 6 additions & 12 deletions src/gui/dialogs/modeless_dialog.cpp
Expand Up @@ -43,14 +43,14 @@ void modeless_dialog::show(CVideo& video,

hide();

window_ = build_window(video);
window_.reset(build_window(video));

post_build(*window_);

pre_show(*window_);

if(allow_interaction) {
open_window_stack.push_back(window_);
open_window_stack.push_back(window_.get());
window_->show_non_modal();
} else {
window_->show_tooltip(/*auto_close_time*/);
Expand All @@ -60,19 +60,13 @@ void modeless_dialog::show(CVideo& video,
void modeless_dialog::hide()
{
if(window_) {
// Possible TODO: Only run through this loop if the window's show_mode_ == modal
// (For some reason, non-modal windows still have show_mode_ = modal.)
// Don't bother if show_mode_ == tooltip, because in that case we didn't add it anyway.
for(auto iter = open_window_stack.rbegin(); iter != open_window_stack.rend(); iter++) {
if(*iter == window_) {
open_window_stack.erase(std::next(iter).base());
break;
}
if(window_->mode() == window::modeless) {
remove_from_window_stack(window_.get());
}

window_->undraw();
delete window_;
window_ = nullptr;
}
window_.reset(nullptr); }
}

window* modeless_dialog::build_window(CVideo& video) const
Expand Down
3 changes: 2 additions & 1 deletion src/gui/dialogs/modeless_dialog.hpp
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <memory>
#include <string>

class CVideo;
Expand Down Expand Up @@ -84,7 +85,7 @@ class modeless_dialog

private:
/** The window, used in show. */
window* window_;
std::unique_ptr<window> window_;

/** The id of the window to build. */
virtual const std::string& window_id() const = 0;
Expand Down

0 comments on commit db44561

Please sign in to comment.