Added 'card' to value actions, this fixes a bug where extra fields get updated with the wrong context, and it should also speed things up.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@673 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-09-09 00:39:01 +00:00
parent 03cd9dcfb8
commit fc44560238
19 changed files with 126 additions and 115 deletions
+2 -3
View File
@@ -113,9 +113,8 @@ void CardListBase::onAction(const Action& action, bool undone) {
// No refresh needed, a ScriptValueEvent is only generated in response to a ValueAction
return;
}
TYPE_CASE_(action, ValueAction) {
refreshList();
return;
TYPE_CASE(action, ValueAction) {
if (action.card) refreshList();
}
}
+6 -4
View File
@@ -75,10 +75,12 @@ void KeywordList::onAction(const Action& action, bool undone) {
}
}
TYPE_CASE(action, ValueAction) {
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
if (value) {
// this is indeed an action on a keyword, refresh
refreshList();
if (!action.card) {
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
if (value) {
// this is indeed an action on a keyword, refresh
refreshList();
}
}
}
TYPE_CASE_(action, ChangeKeywordModeAction) {
+13 -11
View File
@@ -280,18 +280,20 @@ void KeywordsPanel::onChangeSet() {
void KeywordsPanel::onAction(const Action& action, bool undone) {
TYPE_CASE(action, ValueAction) {
{
KeywordReminderTextValue* value = dynamic_cast<KeywordReminderTextValue*>(action.valueP.get());
if (value && &value->keyword == list->getKeyword().get()) {
// the current keyword's reminder text changed
errors->SetLabel(value->errors);
if (!action.card) {
{
KeywordReminderTextValue* value = dynamic_cast<KeywordReminderTextValue*>(action.valueP.get());
if (value && &value->keyword == list->getKeyword().get()) {
// the current keyword's reminder text changed
errors->SetLabel(value->errors);
}
}
}
{
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
if (value && value->underlying == &list->getKeyword()->match) {
// match string changes, maybe there are parameters now
ref_param->Enable(!value->keyword.fixed && !value->keyword.parameters.empty());
{
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
if (value && value->underlying == &list->getKeyword()->match) {
// match string changes, maybe there are parameters now
ref_param->Enable(!value->keyword.fixed && !value->keyword.parameters.empty());
}
}
}
}
+8 -6
View File
@@ -73,12 +73,14 @@ void StylePanel::onAction(const Action& action, bool undone) {
}
TYPE_CASE(action, ValueAction) {
// is it a styling action?
const StyleSheet& s = set->stylesheetFor(card);
FOR_EACH_CONST(f, s.styling_fields) {
if (action.valueP->fieldP == f) {
// refresh the viewer
preview->redraw();
return;
if (!action.card) {
const StyleSheet& s = set->stylesheetFor(card);
FOR_EACH_CONST(f, s.styling_fields) {
if (action.valueP->fieldP == f) {
// refresh the viewer
preview->redraw();
return;
}
}
}
}
+4 -2
View File
@@ -264,8 +264,10 @@ void SetWindow::onChangeSet() {
void SetWindow::onAction(const Action& action, bool undone) {
TYPE_CASE(action, ValueAction) {
if (set->data.contains(action.valueP) && action.valueP->fieldP->identifying) {
updateTitle();
if (!action.card) {
if (set->data.contains(action.valueP) && action.valueP->fieldP->identifying) {
updateTitle();
}
}
}
/* TYPE_CASE_(action, DisplayChangeAction) {
+3 -3
View File
@@ -35,8 +35,8 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename) {
init(parent, symbol);
}
SymbolWindow::SymbolWindow(Window* parent, const SymbolValueP& value, const SetP& set)
: value(value), set(set)
SymbolWindow::SymbolWindow(Window* parent, const SetP& set, const Card* card, const SymbolValueP& value)
: value(value), card(card), set(set)
{
// attempt to load symbol
SymbolP symbol;
@@ -236,7 +236,7 @@ void SymbolWindow::onFileStore(wxCommandEvent& ev) {
FileName new_filename = set->newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
Writer writer(set->openOut(new_filename));
writer.handle(control->getSymbol());
set->actions.add(value_action(value, new_filename));
set->actions.add(value_action(card, value, new_filename));
}
}
+3 -2
View File
@@ -14,8 +14,8 @@
#include <wx/listctrl.h>
class SymbolControl;
//%%class SymbolPartList;
class SymbolPartList;
class Card;
DECLARE_POINTER_TYPE(SymbolValue);
DECLARE_POINTER_TYPE(Set);
@@ -29,7 +29,7 @@ class SymbolWindow : public Frame {
/// Construct a SymbolWindow showing a symbol from a file
SymbolWindow(Window* parent, const String& filename);
/// Construct a SymbolWindow showing a symbol value in a set
SymbolWindow(Window* parent, const SymbolValueP& value, const SetP& set);
SymbolWindow(Window* parent, const SetP& set, const Card* card, const SymbolValueP& value);
private:
// --------------------------------------------------- : Children
@@ -42,6 +42,7 @@ class SymbolWindow : public Frame {
// when editing a symbol field
SymbolValueP value;
const Card* card;
SetP set;
// --------------------------------------------------- : Event handling
+1 -1
View File
@@ -307,5 +307,5 @@ void ChoiceValueEditor::determineSize(bool) {
}
void ChoiceValueEditor::change(const Defaultable<String>& c) {
getSet().actions.add(value_action(valueP(), c));
perform(value_action(card(), valueP(), c));
}
+1 -1
View File
@@ -149,7 +149,7 @@ void ColorValueEditor::determineSize(bool) {
}
void ColorValueEditor::change(const Defaultable<Color>& c) {
getSet().actions.add(value_action(valueP(), c));
perform(value_action(card(), valueP(), c));
}
void ColorValueEditor::changeCustom() {
Color c = wxGetColourFromUser(0, value().value());
+5
View File
@@ -133,9 +133,14 @@ class ValueEditor {
virtual ValueEditor* getEditor() { return this; } \
virtual void redraw(); \
private: \
/** Retrieve the parent editor object */ \
inline DataEditor& editor() const { \
return static_cast<DataEditor&>(viewer); \
} \
/** Card this editor is on, or nullptr */ \
inline const Card* card() const { return viewer.getCard().get(); } \
/** Perform an action */ \
void perform(Action* a) { getSet().actions.add(a); } \
public:
#define IMPLEMENT_VALUE_EDITOR(Type) \
+2 -2
View File
@@ -48,7 +48,7 @@ void ImageValueEditor::sliceImage(const Image& image) {
FileName new_image_file = getSet().newFileName(field().name,_("")); // a new unique name in the package
Image img = s.getImage();
img.SaveFile(getSet().nameOut(new_image_file), img.HasAlpha() ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_JPEG);
getSet().actions.add(value_action(valueP(), new_image_file));
perform(value_action(card(), valueP(), new_image_file));
}
}
@@ -88,7 +88,7 @@ bool ImageValueEditor::doPaste() {
}
bool ImageValueEditor::doDelete() {
getSet().actions.add(value_action(valueP(), FileName()));
perform(value_action(card(), valueP(), FileName()));
return true;
}
+2 -2
View File
@@ -173,9 +173,9 @@ void MultipleChoiceValueEditor::toggle(int id) {
if (i == id) toggled_choice = choice;
}
// store value
getSet().actions.add(value_action(valueP(), new_value, toggled_choice));
perform(value_action(card(), valueP(), new_value, toggled_choice));
}
void MultipleChoiceValueEditor::toggleDefault() {
getSet().actions.add(value_action(valueP(), Defaultable<String>(value().value(), !value().value.isDefault()), _("")));
perform(value_action(card(), valueP(), Defaultable<String>(value().value(), !value().value.isDefault()), _("")));
}
+2 -2
View File
@@ -92,7 +92,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
// edit
button_down = -2;
viewer.redraw(*this);
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet());
SymbolWindow* wnd = new SymbolWindow(nullptr, viewer.getSet(), card(), valueP());
wnd->Show();
return true;
} else if (button_down == 1) {
@@ -109,7 +109,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
bool SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
// Use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet());
SymbolWindow* wnd = new SymbolWindow(nullptr, viewer.getSet(), card(), valueP());
wnd->Show();
return true;
}
+6 -21
View File
@@ -563,21 +563,6 @@ wxMenu* TextValueEditor::getMenu(int type) const {
}
}
/*
/// TODO : move to doFormat
void TextValueEditor::onMenu(wxCommandEvent& ev) {
if (ev.GetId() == ID_FORMAT_REMINDER) {
// toggle reminder text
size_t kwpos = in_tag(value().value(), _("<kw-"), selection_start_i, selection_start_i);
if (kwpos != String::npos) {
// getSet().actions.add(new TextToggleReminderAction(value, kwpos));
}
} else {
ev.Skip();
}
}
*/
// ----------------------------------------------------------------------------- : Drawing
void TextValueEditor::draw(RotatedDC& dc) {
@@ -783,19 +768,19 @@ void TextValueEditor::doFormat(int type) {
size_t ss = selection_start, se = selection_end;
switch (type) {
case ID_FORMAT_BOLD: {
getSet().actions.add(toggle_format_action(valueP(), _("b"), selection_start_i, selection_end_i, selection_start, selection_end, _("Bold")));
perform(toggle_format_action(card(), valueP(), _("b"), selection_start_i, selection_end_i, selection_start, selection_end, _("Bold")));
break;
}
case ID_FORMAT_ITALIC: {
getSet().actions.add(toggle_format_action(valueP(), _("i"), selection_start_i, selection_end_i, selection_start, selection_end, _("Italic")));
perform(toggle_format_action(card(), valueP(), _("i"), selection_start_i, selection_end_i, selection_start, selection_end, _("Italic")));
break;
}
case ID_FORMAT_SYMBOL: {
getSet().actions.add(toggle_format_action(valueP(), _("sym"), selection_start_i, selection_end_i, selection_start, selection_end, _("Symbols")));
perform(toggle_format_action(card(), valueP(), _("sym"), selection_start_i, selection_end_i, selection_start, selection_end, _("Symbols")));
break;
}
case ID_FORMAT_REMINDER: {
getSet().actions.add(new TextToggleReminderAction(valueP(), selection_start_i));
perform(new TextToggleReminderAction(card(), valueP(), selection_start_i));
break;
}
}
@@ -908,7 +893,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
fixSelection();
// execute the action before adding it to the stack,
// because we want to run scripts before action listeners see the action
TextValueAction* action = typing_action(valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name);
TextValueAction* action = typing_action(card(), valueP(), selection_start_i, selection_end_i, select_on_undo ? selection_start : selection_end, selection_end, replacement, name);
if (!action) {
// nothing changes, but move the selection anyway
moveSelection(TYPE_CURSOR, selection_end);
@@ -919,7 +904,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
size_t expected_cursor = min(selection_start, selection_end) + untag(replacement).size();
// perform the action
// NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text
getSet().actions.add(action);
perform(action);
// move cursor
{
String real_value = untag_for_cursor(value().value());