1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "confirm_save_dialog.h"
ConfirmSaveDialog::ConfirmSaveDialog(mforms::Form *owner,
const std::string &window_title,
const std::string &caption)
: mforms::Form(owner), _box(false), _checkboxes(false), _item_count(0)
{
set_title(window_title);
set_name("save_dialog");
set_content(&_box);
_box.set_padding(25);
_box.set_spacing(12);
_caption.set_style(mforms::BigBoldStyle);
_caption.set_text(caption);
_box.add(&_caption, false, true);
_box.add(&_scroller, true, true);
_scroller.add(&_checkboxes);
_checkboxes.set_spacing(8);
_checkboxes.set_padding(8);
{
mforms::Box *bbox= mforms::manage(new mforms::Box(true));
bbox->set_spacing(12);
_box.add(bbox, false, true);
mforms::Button *discard= mforms::manage(new mforms::Button());
_review_button.set_text(("Review Changes"));
_cancel_button.set_text(("Cancel"));
discard->set_text(("Discard Changes"));
scoped_connect(discard->signal_clicked(),boost::bind(&ConfirmSaveDialog::discard_clicked, this));
#ifdef __APPLE__
bbox->add(discard, false, true);
bbox->add_end(&_review_button, false, true);
bbox->add_end(&_cancel_button, false, true);
#else
bbox->add_end(&_cancel_button, false, true);
bbox->add_end(discard, false, true);
bbox->add_end(&_review_button, false, true);
#endif
}
_result= ReviewChanges;
set_size(500, 300);
center();
}
void ConfirmSaveDialog::discard_clicked()
{
_result= DiscardChanges;
end_modal(true);
}
void ConfirmSaveDialog::add_item(const std::string &group, const std::string &name)
{
if (_last_group != group)
{
_last_group= group;
mforms::Label *label= mforms::manage(new mforms::Label(group));
_checkboxes.add(label, false, true);
}
add_item(name);
}
void ConfirmSaveDialog::add_item(const std::string &name)
{
mforms::Label *cb = mforms::manage(new mforms::Label(name));
if (_last_group.empty())
cb->set_text(name);
else
cb->set_text(" "+name);
_item_count++;
_checkboxes.add(cb, false, true);
}
ConfirmSaveDialog::Result ConfirmSaveDialog::run()
{
if (!mforms::Form::run_modal(&_review_button, &_cancel_button))
return Cancel;
return _result;
}
|