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
|
#include "ModalProgressDialog.h"
#include "i18n.h"
#include "ui/imainframe.h"
#include <wx/frame.h>
namespace wxutil
{
ModalProgressDialog::ModalProgressDialog(const std::string& title, wxWindow* parent) :
wxProgressDialog(title, "", 100, parent != nullptr ? parent : GlobalMainFrame().getWxTopLevelWindow(),
wxPD_CAN_ABORT | wxPD_APP_MODAL | wxPD_AUTO_HIDE)
{}
void ModalProgressDialog::setFraction(double fraction)
{
if (WasCancelled())
{
throw OperationAbortedException(_("Operation cancelled by user"));
}
if (fraction < 0)
{
fraction = 0.0;
}
else if (fraction > 1.0)
{
fraction = 1.0;
}
int newValue = static_cast<int>(fraction * 100);
Update(newValue);
}
void ModalProgressDialog::setText(const std::string& text)
{
// If the aborted flag is set, throw an exception here
if (WasCancelled())
{
throw OperationAbortedException(_("Operation cancelled by user"));
}
Pulse(text);
}
void ModalProgressDialog::setTextAndFraction(const std::string& text, double fraction)
{
if (WasCancelled())
{
throw OperationAbortedException(_("Operation cancelled by user"));
}
if (fraction < 0)
{
fraction = 0.0;
}
else if (fraction > 1.0)
{
fraction = 1.0;
}
int newValue = static_cast<int>(fraction * 100);
Update(newValue, text);
Fit();
}
} // namespace
|