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
+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());