small changes in preparation for modifications of the file choosing dialogs

(with the eventual goal to reduce code duplication and allow generic
folder creation/traversal)

removes some warnings from the editor code.
This commit is contained in:
Patrick Parker 2006-07-23 06:57:08 +00:00
parent e95c0a7de2
commit bda6efd1cc
4 changed files with 38 additions and 19 deletions

View file

@ -261,7 +261,7 @@ int dialog::show(int xloc, int yloc)
if(!done()) {
refresh();
}
action();
action(dp_info);
} while(!done());
return result();
@ -693,14 +693,8 @@ int dialog_button::action(dialog_process_info &info) {
menu &menu = *(parent_->get_menu());
dialog_button_action::RESULT res = handler_->button_pressed(menu.selection());
if(res == DELETE_ITEM) {
info.first_time = true;
menu.erase_item(menu.selection());
if(menu.nitems() == 0) {
return CLOSE_DIALOG;
}
} else if(res == CLOSE_DIALOG) {
return CLOSE_DIALOG;
if(res == DELETE_ITEM || res == CLOSE_DIALOG) {
return res;
}
//reset button-tracking flags so that if the action displays a dialog, a button-press
@ -713,6 +707,26 @@ int dialog_button::action(dialog_process_info &info) {
return simple_result_;
}
void dialog::action(dialog_process_info& info)
{
//default way of handling a "delete item" request
if(result() == DELETE_ITEM) {
menu &m = *(get_menu());
m.erase_item(m.selection());
if(m.nitems() == 0) {
set_result(CLOSE_DIALOG);
} else {
set_result(CONTINUE_DIALOG);
info.first_time = true;
}
}
//support for old-style dialog actions
if(!done() && action_ != NULL) {
set_result(action_->do_action());
}
}
int standard_dialog_button::action(dialog_process_info &/*info*/) {
//if the menu is not used, then return the index of the
//button pressed, otherwise return the index of the menu

View file

@ -187,6 +187,7 @@ public:
bool done() const { return (result_ != CONTINUE_DIALOG); }
const std::string textbox_text() const { return text_widget_->text();}
const bool option_checked(unsigned int option_index=0);
display& get_display() { return disp_; }
//Backwards compatibility
//set_action - deprecated, subclass dialog instead and override action()
@ -196,11 +197,8 @@ protected:
void set_result(const int result) { result_ = result; }
//action - invoked at the end of the dialog-processing loop
virtual void action() {
if(!done() && action_ != NULL) {
set_result(action_->do_action());
}
}
virtual void action(dialog_process_info &dp_info);
//refresh - forces the display to refresh
void refresh();

View file

@ -1347,10 +1347,10 @@ void map_editor::main_loop() {
while (abort_ == DONT_ABORT) {
int mousex, mousey;
const int scroll_speed = preferences::scroll_speed();
const int mouse_flags = SDL_GetMouseState(&mousex,&mousey);
const bool l_button_down = mouse_flags & SDL_BUTTON_LMASK;
const bool r_button_down = mouse_flags & SDL_BUTTON_RMASK;
const bool m_button_down = mouse_flags & SDL_BUTTON_MMASK;
Uint8 mouse_flags = SDL_GetMouseState(&mousex,&mousey);
const bool l_button_down = (0 == (mouse_flags & SDL_BUTTON_LMASK));
const bool r_button_down = (0 == (mouse_flags & SDL_BUTTON_RMASK));
const bool m_button_down = (0 == (mouse_flags & SDL_BUTTON_MMASK));
const gamemap::location cur_hex = gui_.hex_clicked_on(mousex,mousey);
if (cur_hex != selected_hex_) {

View file

@ -36,7 +36,14 @@ namespace gui
extern const int ButtonHPadding;
extern const int ButtonVPadding;
enum DIALOG_RESULT { DELETE_ITEM=-4, ESCAPE_DIALOG=-3, CONTINUE_DIALOG=-2, CLOSE_DIALOG=-1};
enum DIALOG_RESULT {
CREATE_ITEM =-5,
DELETE_ITEM=-4,
ESCAPE_DIALOG=-3,
CONTINUE_DIALOG=-2,
CLOSE_DIALOG=-1
/* results (0..N) reserved for standard button indeces */
};
bool in_dialog();