A half-step towards disentangling the dialog class from the help system...

*wthout* losing help buttons this time.
This commit is contained in:
Eric S. Raymond 2007-07-06 20:14:03 +00:00
parent 6d2e26c743
commit ec1813d9bb
4 changed files with 25 additions and 10 deletions

View file

@ -83,14 +83,14 @@ std::vector<std::string> empty_string_vector;
struct help_handler : public hotkey::command_executor
{
help_handler(display& disp, const std::string& topic) : disp_(disp), topic_(topic)
help_handler(display& disp, const std::string& topic, void (*help_hook)(display &, const std::string) = NULL) : disp_(disp), topic_(topic), help_hook_(help_hook)
{}
private:
void show_help()
{
if(topic_.empty() == false) {
help::show_help(disp_,topic_);
help_hook_(disp_,topic_);
}
}
@ -101,6 +101,7 @@ private:
display& disp_;
std::string topic_;
void (*help_hook_)(display & display, const std::string topic);
};
} //end anonymous namespace
@ -282,7 +283,7 @@ int dialog::show()
const dialog_manager manager;
const events::resize_lock prevent_resizing;
help_handler helper(disp_,help_button_.topic());
help_handler helper(disp_,help_button_.topic(), help::button_help);
hotkey::basic_handler help_dispatcher(&disp_,&helper);
//draw

View file

@ -183,20 +183,24 @@ public:
//Constructor & destructor
//dialog - throws button::error() if standard buttons fail to initialize
// throws utils::invalid_utf8_exception() if message is invalid
dialog(display &disp, const std::string& title="", const std::string& message="",
const DIALOG_TYPE type=MESSAGE,
const struct style *dialog_style=&default_style,
const std::string& help_topic=no_help);
dialog(display &disp,
const std::string& title="",
const std::string& message="",
const DIALOG_TYPE type=MESSAGE,
const struct style *dialog_style=&default_style,
const std::string& help_topic=no_help);
virtual ~dialog();
//Adding components - the dialog will manage the memory of these widgets,
//therefore do not attempt to reference its widgets after destroying it
//Adding components - the dialog will manage the memory of
//these widgets, therefore do not attempt to reference its
//widgets after destroying it
void set_image(dialog_image *const img) { delete image_; image_ = img; }
void set_image(surface surf, const std::string &caption="");
void set_menu(menu *const m) { if(menu_ != empty_menu) delete menu_; menu_ = m; }
void set_menu(const std::vector<std::string> & menu_items, menu::sorter* sorter=NULL);
//add_pane - preview panes are not currently memory managed (for backwards compat)
//add_pane - preview panes are not currently memory managed
//(for backwards compatibility)
void add_pane(preview_pane *const pp) { preview_panes_.push_back(pp); }
void set_panes(std::vector<preview_pane*> panes) { preview_panes_ = panes; }
void set_textbox(dialog_textbox *const box) {
@ -273,6 +277,8 @@ private:
std::vector<dialog_button*> standard_buttons_;
std::vector<dialog_button*> extra_buttons_;
std::vector<button*> frame_buttons_;
const std::string topic_;
void (*help_hook_)(display &, const std::string);
help_button help_button_;
dialog_textbox *text_widget_;
dialog_frame *frame_;

View file

@ -2592,6 +2592,11 @@ void show_help(display &disp, std::string show_topic, int xloc, int yloc)
show_help(disp, toplevel, show_topic, xloc, yloc);
}
void button_help(display &disp, const std::string show_topic)
{
show_help(disp, show_topic);
}
/// Open a help dialog using a toplevel other than the default.
void show_help(display &disp, const section &toplevel_sec, const std::string show_topic,
int xloc, int yloc)

View file

@ -40,6 +40,9 @@ void show_help(display &disp, const section &toplevel, const std::string show_to
/// will be shown if show_topic is the empty string.
void show_help(display &disp, const std::string show_topic="", int xloc=-1, int yloc=-1);
// Exists to be passed into button handlers as a (resolved) function
void button_help(display &disp, const std::string show_topic);
} // End namespace help.
#endif