mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
Delay the construction of controls is SetWindowPanels until the panel is actually shown (initUI). This makes the program start slightly faster.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1189 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -31,7 +31,12 @@ DECLARE_TYPEOF_COLLECTION(KeywordModeP);
|
||||
|
||||
KeywordsPanel::KeywordsPanel(Window* parent, int id)
|
||||
: SetWindowPanel(parent, id)
|
||||
, menuKeyword(nullptr)
|
||||
{
|
||||
// delayed initialization by initControls()
|
||||
}
|
||||
|
||||
void KeywordsPanel::initControls() {
|
||||
// init controls
|
||||
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||
list = new KeywordList(splitter, ID_KEYWORD_LIST);
|
||||
@@ -118,6 +123,12 @@ KeywordsPanel::~KeywordsPanel() {
|
||||
|
||||
|
||||
void KeywordsPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
// Controls
|
||||
if (!isInitialized()) {
|
||||
wxBusyCursor busy;
|
||||
initControls();
|
||||
onChangeSet();
|
||||
}
|
||||
// Toolbar
|
||||
tb->AddTool(ID_KEYWORD_ADD, _(""), load_resource_tool_image(_("keyword_add")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("add keyword"), _HELP_("add keyword"));
|
||||
tb->AddTool(ID_KEYWORD_REMOVE, _(""), load_resource_tool_image(_("keyword_del")), wxNullBitmap, wxITEM_NORMAL,_TOOLTIP_("remove keyword"),_HELP_("remove keyword"));
|
||||
@@ -138,6 +149,7 @@ void KeywordsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
}
|
||||
|
||||
void KeywordsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
if (!isInitialized()) return;
|
||||
switch (ev.GetId()) {
|
||||
case ID_KEYWORD_PREV: ev.Enable(list->canSelectPrevious()); break;
|
||||
case ID_KEYWORD_NEXT: ev.Enable(list->canSelectNext()); break;
|
||||
@@ -146,6 +158,7 @@ void KeywordsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
}
|
||||
|
||||
void KeywordsPanel::onCommand(int id) {
|
||||
if (!isInitialized()) return;
|
||||
switch (id) {
|
||||
case ID_KEYWORD_PREV:
|
||||
list->selectPrevious();
|
||||
@@ -230,6 +243,7 @@ String KeywordsPanel::runRefScript(int find_i) {
|
||||
|
||||
// determine what control to use for clipboard actions
|
||||
#define CUT_COPY_PASTE(op,return,check) \
|
||||
if (!isInitialized()) return false; \
|
||||
int id = focused_control(this); \
|
||||
if (id == ID_KEYWORD_LIST && keyword ->IsEnabled()) { return list ->op(); } \
|
||||
else if (check) { return false; } \
|
||||
@@ -249,6 +263,7 @@ void KeywordsPanel::doPaste() { CUT_COPY_PASTE(doPaste, return (void), !
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
void KeywordsPanel::onChangeSet() {
|
||||
if (!isInitialized()) return;
|
||||
list->setSet(set);
|
||||
// warning label (depends on game name)
|
||||
fixedL->SetLabel(_LABEL_1_("standard keyword", set->game->short_name));
|
||||
@@ -280,6 +295,7 @@ void KeywordsPanel::onChangeSet() {
|
||||
}
|
||||
|
||||
void KeywordsPanel::onAction(const Action& action, bool undone) {
|
||||
if (!isInitialized()) return;
|
||||
TYPE_CASE(action, ValueAction) {
|
||||
if (!action.card) {
|
||||
{
|
||||
|
||||
@@ -50,6 +50,9 @@ class KeywordsPanel : public SetWindowPanel {
|
||||
/// Find the code to insert based on the ref_scripts for the parameters of the current keyword
|
||||
String runRefScript(int i);
|
||||
|
||||
/// Actual intialization of the controls
|
||||
void initControls();
|
||||
|
||||
// --------------------------------------------------- : Controls
|
||||
wxSplitterWindow* splitter;
|
||||
wxPanel* panel;
|
||||
|
||||
@@ -19,3 +19,7 @@ SetWindowPanel::SetWindowPanel(Window* parent, int id, bool autoTabbing)
|
||||
CardP SetWindowPanel::selectedCard() const {
|
||||
return CardP();
|
||||
}
|
||||
|
||||
bool SetWindowPanel::isInitialized() const {
|
||||
return !GetChildren().IsEmpty();
|
||||
}
|
||||
|
||||
@@ -71,6 +71,10 @@ class SetWindowPanel : public wxPanel, public SetView {
|
||||
virtual void selectCard(const CardP& card) {} ///< Switch the view to another card, can be null
|
||||
virtual void selectFirstCard() {} ///< Switch the view to the first card
|
||||
virtual void selectionChoices(ExportCardSelectionChoices& out) {} ///< Card subsets that can be exported from this panel
|
||||
|
||||
protected:
|
||||
/// Have any controls been created?
|
||||
bool isInitialized() const;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -155,6 +155,10 @@ END_EVENT_TABLE()
|
||||
RandomPackPanel::RandomPackPanel(Window* parent, int id)
|
||||
: SetWindowPanel(parent, id)
|
||||
{
|
||||
// delayed initialization by initControls()
|
||||
}
|
||||
|
||||
void RandomPackPanel::initControls() {
|
||||
// init controls
|
||||
preview = new CardViewer(this, wxID_ANY);
|
||||
card_list = new RandomCardList(this, wxID_ANY);
|
||||
@@ -163,9 +167,9 @@ RandomPackPanel::RandomPackPanel(Window* parent, int id)
|
||||
seed_fixed = new wxRadioButton(this, ID_SEED_FIXED, _BUTTON_("fixed seed"));
|
||||
seed = new wxTextCtrl(this, wxID_ANY);
|
||||
totals = new PackTotalsPanel(this, wxID_ANY);
|
||||
static_cast<SetWindow*>(parent)->setControlStatusText(seed_random, _HELP_("random seed"));
|
||||
static_cast<SetWindow*>(parent)->setControlStatusText(seed_fixed, _HELP_("fixed seed"));
|
||||
static_cast<SetWindow*>(parent)->setControlStatusText(seed, _HELP_("seed"));
|
||||
static_cast<SetWindow*>(GetParent())->setControlStatusText(seed_random, _HELP_("random seed"));
|
||||
static_cast<SetWindow*>(GetParent())->setControlStatusText(seed_fixed, _HELP_("fixed seed"));
|
||||
static_cast<SetWindow*>(GetParent())->setControlStatusText(seed, _HELP_("seed"));
|
||||
// init sizer
|
||||
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
|
||||
s->Add(preview, 0, wxRIGHT, 2);
|
||||
@@ -209,6 +213,7 @@ void RandomPackPanel::onBeforeChangeSet() {
|
||||
}
|
||||
}
|
||||
void RandomPackPanel::onChangeSet() {
|
||||
if (!isInitialized()) return;
|
||||
preview ->setSet(set);
|
||||
card_list->setSet(set);
|
||||
totals ->setGame(set->game);
|
||||
@@ -249,6 +254,7 @@ void RandomPackPanel::onChangeSet() {
|
||||
}
|
||||
|
||||
void RandomPackPanel::storeSettings() {
|
||||
if (!isInitialized()) return;
|
||||
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||
gs.pack_seed_random = seed_random->GetValue();
|
||||
FOR_EACH(i, packs) {
|
||||
@@ -258,13 +264,21 @@ void RandomPackPanel::storeSettings() {
|
||||
|
||||
// ----------------------------------------------------------------------------- : UI
|
||||
|
||||
void RandomPackPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {}
|
||||
void RandomPackPanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
// Init controls?
|
||||
if (!isInitialized()) {
|
||||
wxBusyCursor busy;
|
||||
initControls();
|
||||
onChangeSet();
|
||||
}
|
||||
}
|
||||
|
||||
void RandomPackPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {}
|
||||
|
||||
void RandomPackPanel::onUpdateUI(wxUpdateUIEvent& ev) {}
|
||||
|
||||
void RandomPackPanel::onCommand(int id) {
|
||||
if (!isInitialized()) return;
|
||||
switch (id) {
|
||||
case ID_PACK_AMOUNT: {
|
||||
updateTotals();
|
||||
@@ -339,6 +353,7 @@ void RandomPackPanel::generate() {
|
||||
// ----------------------------------------------------------------------------- : Selection
|
||||
|
||||
CardP RandomPackPanel::selectedCard() const {
|
||||
if (!isInitialized()) return CardP();
|
||||
return card_list->getCard();
|
||||
}
|
||||
|
||||
@@ -352,6 +367,7 @@ void RandomPackPanel::onCardSelect(CardSelectEvent& ev) {
|
||||
}
|
||||
|
||||
void RandomPackPanel::selectionChoices(ExportCardSelectionChoices& out) {
|
||||
if (!isInitialized()) return;
|
||||
out.push_back(new_intrusive2<ExportCardSelectionChoice>(
|
||||
_BUTTON_("export generated packs"),
|
||||
card_list->getCardsPtr()
|
||||
@@ -366,5 +382,5 @@ END_EVENT_TABLE ()
|
||||
|
||||
// ----------------------------------------------------------------------------- : Clipboard
|
||||
|
||||
bool RandomPackPanel::canCopy() const { return card_list->canCopy(); }
|
||||
void RandomPackPanel::doCopy() { card_list->doCopy(); }
|
||||
bool RandomPackPanel::canCopy() const { return isInitialized() && card_list->canCopy(); }
|
||||
void RandomPackPanel::doCopy() { isInitialized() && card_list->doCopy(); }
|
||||
|
||||
@@ -68,6 +68,9 @@ class RandomPackPanel : public SetWindowPanel {
|
||||
|
||||
int total_packs;
|
||||
|
||||
/// Actual intialization of the controls
|
||||
void initControls();
|
||||
|
||||
/// Update the total count of each card type
|
||||
void updateTotals();
|
||||
/// Get a seed value
|
||||
|
||||
@@ -277,8 +277,13 @@ void StatDimensionList::drawItem(DC& dc, int x, int y, size_t item) {
|
||||
|
||||
StatsPanel::StatsPanel(Window* parent, int id)
|
||||
: SetWindowPanel(parent, id)
|
||||
, menuGraph(nullptr)
|
||||
, up_to_date(true), active(false)
|
||||
{
|
||||
// delayed initialization by initControls()
|
||||
}
|
||||
|
||||
void StatsPanel::initControls() {
|
||||
// init controls
|
||||
wxSplitterWindow* splitter;
|
||||
#if USE_SEPARATE_DIMENSION_LISTS
|
||||
@@ -328,6 +333,7 @@ StatsPanel::~StatsPanel() {
|
||||
}
|
||||
|
||||
void StatsPanel::onChangeSet() {
|
||||
if (!isInitialized()) return;
|
||||
card_list->setSet(set);
|
||||
#if USE_SEPARATE_DIMENSION_LISTS
|
||||
for (int i = 0 ; i < 3 ; ++i) dimensions[i]->show(set->game);
|
||||
@@ -336,10 +342,12 @@ void StatsPanel::onChangeSet() {
|
||||
#else
|
||||
categories->show(set->game);
|
||||
#endif
|
||||
card = CardP();
|
||||
onChange();
|
||||
}
|
||||
|
||||
void StatsPanel::onAction(const Action& action, bool undone) {
|
||||
if (!isInitialized()) return;
|
||||
TYPE_CASE_(action, ScriptValueEvent) {
|
||||
// ignore style only stuff
|
||||
} else {
|
||||
@@ -348,6 +356,15 @@ void StatsPanel::onAction(const Action& action, bool undone) {
|
||||
}
|
||||
|
||||
void StatsPanel::initUI (wxToolBar* tb, wxMenuBar* mb) {
|
||||
// Controls
|
||||
if (!isInitialized()) {
|
||||
wxBusyCursor busy;
|
||||
initControls();
|
||||
CardP cur_card = card;
|
||||
onChangeSet();
|
||||
selectCard(cur_card);
|
||||
}
|
||||
// we are active
|
||||
active = true;
|
||||
if (!up_to_date) showCategory();
|
||||
// Toolbar
|
||||
@@ -377,6 +394,7 @@ void StatsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
}
|
||||
|
||||
void StatsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
if (!isInitialized()) return;
|
||||
switch (ev.GetId()) {
|
||||
case ID_GRAPH_PIE: case ID_GRAPH_BAR: case ID_GRAPH_STACK: case ID_GRAPH_SCATTER: case ID_GRAPH_SCATTER_PIE: {
|
||||
GraphType type = (GraphType)(ev.GetId() - ID_GRAPH_PIE);
|
||||
@@ -390,6 +408,7 @@ void StatsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
}
|
||||
|
||||
void StatsPanel::onCommand(int id) {
|
||||
if (!isInitialized()) return;
|
||||
switch (id) {
|
||||
case ID_FIELD_LIST: {
|
||||
onChange();
|
||||
@@ -537,9 +556,12 @@ END_EVENT_TABLE()
|
||||
// ----------------------------------------------------------------------------- : Selection
|
||||
|
||||
CardP StatsPanel::selectedCard() const {
|
||||
if (!isInitialized()) return CardP();
|
||||
return card_list->getCard();
|
||||
}
|
||||
void StatsPanel::selectCard(const CardP& card) {
|
||||
this->card = card;
|
||||
if (!isInitialized()) return;
|
||||
card_list->setCard(card);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,9 +60,12 @@ class StatsPanel : public SetWindowPanel {
|
||||
FilteredCardList* card_list;
|
||||
IconMenu* menuGraph;
|
||||
|
||||
CardP card; ///< Selected card
|
||||
bool up_to_date; ///< Are the graph and card list up to date?
|
||||
bool active; ///< Is this panel selected?
|
||||
|
||||
void initControls();
|
||||
|
||||
void onChange();
|
||||
void onGraphSelect(wxCommandEvent&);
|
||||
void showCategory(const GraphType* prefer_layout = nullptr);
|
||||
|
||||
@@ -23,11 +23,15 @@
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(FieldP);
|
||||
|
||||
// ----------------------------------------------------------------------------- : StylePanel
|
||||
// ----------------------------------------------------------------------------- : StylePanel : initialization
|
||||
|
||||
StylePanel::StylePanel(Window* parent, int id)
|
||||
: SetWindowPanel(parent, id)
|
||||
{
|
||||
// delayed initialization by initControls()
|
||||
}
|
||||
|
||||
void StylePanel::initControls() {
|
||||
// init controls
|
||||
preview = new CardViewer (this, wxID_ANY);
|
||||
list = new PackageList (this, wxID_ANY);
|
||||
@@ -48,7 +52,19 @@ StylePanel::StylePanel(Window* parent, int id)
|
||||
s->SetSizeHints(this);
|
||||
SetSizer(s);
|
||||
}
|
||||
|
||||
void StylePanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
if (!isInitialized()) {
|
||||
wxBusyCursor busy;
|
||||
initControls();
|
||||
CardP cur_card = card;
|
||||
onChangeSet();
|
||||
selectCard(cur_card);
|
||||
}
|
||||
}
|
||||
|
||||
void StylePanel::updateListSize() {
|
||||
if (!isInitialized()) return;
|
||||
// how many columns fit?
|
||||
size_t fit_columns = (size_t)((GetSize().y - 400) / 152);
|
||||
// we only need enough columns to show all items
|
||||
@@ -66,7 +82,10 @@ bool StylePanel::Layout() {
|
||||
return SetWindowPanel::Layout();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : StylePanel
|
||||
|
||||
void StylePanel::onChangeSet() {
|
||||
if (!isInitialized()) return;
|
||||
list->showData<StyleSheet>(set->game->name() + _("-*"));
|
||||
list->select(set->stylesheet->name(), false);
|
||||
editor->setSet(set);
|
||||
@@ -76,6 +95,7 @@ void StylePanel::onChangeSet() {
|
||||
}
|
||||
|
||||
void StylePanel::onAction(const Action& action, bool undone) {
|
||||
if (!isInitialized()) return;
|
||||
TYPE_CASE_(action, ChangeSetStyleAction) {
|
||||
list->select(set->stylesheetFor(card).name(), false);
|
||||
editor->showCard(card);
|
||||
@@ -113,6 +133,7 @@ void StylePanel::onAction(const Action& action, bool undone) {
|
||||
|
||||
void StylePanel::selectCard(const CardP& card) {
|
||||
this->card = card;
|
||||
if (!isInitialized()) return;
|
||||
preview->setCard(card);
|
||||
editor->showStylesheet(set->stylesheetForP(card));
|
||||
editor->showCard(card);
|
||||
@@ -126,6 +147,7 @@ void StylePanel::selectCard(const CardP& card) {
|
||||
|
||||
// determine what control to use for clipboard actions
|
||||
#define CUT_COPY_PASTE(op,return) \
|
||||
if (!isInitialized()) return false; \
|
||||
int id = focused_control(this); \
|
||||
if (id == ID_EDITOR) { return editor->op(); } \
|
||||
else { return false; }
|
||||
|
||||
@@ -26,6 +26,10 @@ class StylePanel : public SetWindowPanel {
|
||||
virtual void onChangeSet();
|
||||
virtual void onAction(const Action&, bool undone);
|
||||
|
||||
// --------------------------------------------------- : UI
|
||||
|
||||
virtual void initUI(wxToolBar*, wxMenuBar*);
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
virtual bool canCut() const;
|
||||
virtual bool canCopy() const;
|
||||
@@ -54,6 +58,9 @@ class StylePanel : public SetWindowPanel {
|
||||
/// Determine the best size for the list of stylesheets based on available space
|
||||
void updateListSize();
|
||||
virtual bool Layout();
|
||||
|
||||
/// Actual intialization of the controls
|
||||
void initControls();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
Reference in New Issue
Block a user