Commit cb5ddba4 authored by twanvl's avatar twanvl

Added 'card' to value actions, this fixes a bug where extra fields get updated...

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.
parent d9322d44
...@@ -39,8 +39,8 @@ inline void swap_value(MultipleChoiceValue& a, MultipleChoiceValue::ValueType& b ...@@ -39,8 +39,8 @@ inline void swap_value(MultipleChoiceValue& a, MultipleChoiceValue::ValueType& b
template <typename T, bool ALLOW_MERGE> template <typename T, bool ALLOW_MERGE>
class SimpleValueAction : public ValueAction { class SimpleValueAction : public ValueAction {
public: public:
inline SimpleValueAction(const intrusive_ptr<T>& value, const typename T::ValueType& new_value) inline SimpleValueAction(const Card* card, const intrusive_ptr<T>& value, const typename T::ValueType& new_value)
: ValueAction(value), new_value(new_value) : ValueAction(card, value), new_value(new_value)
{} {}
virtual void perform(bool to_undo) { virtual void perform(bool to_undo) {
...@@ -64,20 +64,20 @@ class SimpleValueAction : public ValueAction { ...@@ -64,20 +64,20 @@ class SimpleValueAction : public ValueAction {
typename T::ValueType new_value; typename T::ValueType new_value;
}; };
ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<ChoiceValue, true> (value, new_value); } ValueAction* value_action(const Card* card, const ChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<ChoiceValue, true> (card, value, new_value); }
ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value) { return new SimpleValueAction<ColorValue, true> (value, new_value); } ValueAction* value_action(const Card* card, const ColorValueP& value, const Defaultable<Color>& new_value) { return new SimpleValueAction<ColorValue, true> (card, value, new_value); }
ValueAction* value_action(const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction<ImageValue, false>(value, new_value); } ValueAction* value_action(const Card* card, const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction<ImageValue, false>(card, value, new_value); }
ValueAction* value_action(const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction<SymbolValue, false>(value, new_value); } ValueAction* value_action(const Card* card, const SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction<SymbolValue, false>(card, value, new_value); }
ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change) { ValueAction* value_action(const Card* card, const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change) {
MultipleChoiceValue::ValueType v = { new_value, last_change }; MultipleChoiceValue::ValueType v = { new_value, last_change };
return new SimpleValueAction<MultipleChoiceValue, false>(value, v); return new SimpleValueAction<MultipleChoiceValue, false>(card, value, v);
} }
// ----------------------------------------------------------------------------- : Text // ----------------------------------------------------------------------------- : Text
TextValueAction::TextValueAction(const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name) TextValueAction::TextValueAction(const Card* card, const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name)
: ValueAction(value) : ValueAction(card, value)
, selection_start(start), selection_end(end), new_selection_end(new_end) , selection_start(start), selection_end(end), new_selection_end(new_end)
, new_value(new_value) , new_value(new_value)
, name(name) , name(name)
...@@ -107,7 +107,7 @@ TextValue& TextValueAction::value() const { ...@@ -107,7 +107,7 @@ TextValue& TextValueAction::value() const {
} }
TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name) { TextValueAction* toggle_format_action(const Card* card, const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name) {
if (start > end) { if (start > end) {
swap(start, end); swap(start, end);
swap(start_i, end_i); swap(start_i, end_i);
...@@ -140,11 +140,11 @@ TextValueAction* toggle_format_action(const TextValueP& value, const String& tag ...@@ -140,11 +140,11 @@ TextValueAction* toggle_format_action(const TextValueP& value, const String& tag
if (value->value() == new_value) { if (value->value() == new_value) {
return nullptr; // no changes return nullptr; // no changes
} else { } else {
return new TextValueAction(value, start, end, end, new_value, action_name); return new TextValueAction(card, value, start, end, end, new_value, action_name);
} }
} }
TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name) { TextValueAction* typing_action(const Card* card, const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name) {
bool reverse = start > end; bool reverse = start > end;
if (reverse) { if (reverse) {
swap(start, end); swap(start, end);
...@@ -156,17 +156,17 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e ...@@ -156,17 +156,17 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e
return nullptr; return nullptr;
} else { } else {
if (reverse) { if (reverse) {
return new TextValueAction(value, end, start, start+untag(replacement).size(), new_value, action_name); return new TextValueAction(card, value, end, start, start+untag(replacement).size(), new_value, action_name);
} else { } else {
return new TextValueAction(value, start, end, start+untag(replacement).size(), new_value, action_name); return new TextValueAction(card, value, start, end, start+untag(replacement).size(), new_value, action_name);
} }
} }
} }
// ----------------------------------------------------------------------------- : Reminder text // ----------------------------------------------------------------------------- : Reminder text
TextToggleReminderAction::TextToggleReminderAction(const TextValueP& value, size_t pos_in) TextToggleReminderAction::TextToggleReminderAction(const Card* card, const TextValueP& value, size_t pos_in)
: ValueAction(value) : ValueAction(card, value)
{ {
pos = in_tag(value->value(), _("<kw-"), pos_in, pos_in); pos = in_tag(value->value(), _("<kw-"), pos_in, pos_in);
if (pos == String::npos) { if (pos == String::npos) {
......
...@@ -34,28 +34,29 @@ DECLARE_POINTER_TYPE(SymbolValue); ...@@ -34,28 +34,29 @@ DECLARE_POINTER_TYPE(SymbolValue);
/// An Action the changes a Value /// An Action the changes a Value
class ValueAction : public Action { class ValueAction : public Action {
public: public:
inline ValueAction(const ValueP& value) : valueP(value) {} inline ValueAction(const Card* card, const ValueP& value) : card(card), valueP(value) {}
virtual String getName(bool to_undo) const; virtual String getName(bool to_undo) const;
const ValueP valueP; ///< The modified value const ValueP valueP; ///< The modified value
const Card* card; ///< The card the value is on, or null if it is not a card value
}; };
// ----------------------------------------------------------------------------- : Simple // ----------------------------------------------------------------------------- : Simple
/// Action that updates a Value to a new value /// Action that updates a Value to a new value
ValueAction* value_action(const ChoiceValueP& value, const Defaultable<String>& new_value); ValueAction* value_action(const Card* card, const ChoiceValueP& value, const Defaultable<String>& new_value);
ValueAction* value_action(const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change); ValueAction* value_action(const Card* card, const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change);
ValueAction* value_action(const ColorValueP& value, const Defaultable<Color>& new_value); ValueAction* value_action(const Card* card, const ColorValueP& value, const Defaultable<Color>& new_value);
ValueAction* value_action(const ImageValueP& value, const FileName& new_value); ValueAction* value_action(const Card* card, const ImageValueP& value, const FileName& new_value);
ValueAction* value_action(const SymbolValueP& value, const FileName& new_value); ValueAction* value_action(const Card* card, const SymbolValueP& value, const FileName& new_value);
// ----------------------------------------------------------------------------- : Text // ----------------------------------------------------------------------------- : Text
/// An action that changes a TextValue /// An action that changes a TextValue
class TextValueAction : public ValueAction { class TextValueAction : public ValueAction {
public: public:
TextValueAction(const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name); TextValueAction(const Card* card, const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name);
virtual String getName(bool to_undo) const; virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo); virtual void perform(bool to_undo);
...@@ -74,18 +75,18 @@ class TextValueAction : public ValueAction { ...@@ -74,18 +75,18 @@ class TextValueAction : public ValueAction {
}; };
/// Action for toggling some formating tag on or off in some range /// Action for toggling some formating tag on or off in some range
TextValueAction* toggle_format_action(const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name); TextValueAction* toggle_format_action(const Card* card, const TextValueP& value, const String& tag, size_t start_i, size_t end_i, size_t start, size_t end, const String& action_name);
/// Typing in a TextValue, replace the selection [start...end) with replacement /// Typing in a TextValue, replace the selection [start...end) with replacement
/** start and end are cursor positions, start_i and end_i are indices*/ /** start and end are cursor positions, start_i and end_i are indices*/
TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name); TextValueAction* typing_action(const Card* card, const TextValueP& value, size_t start_i, size_t end_i, size_t start, size_t end, const String& replacement, const String& action_name);
// ----------------------------------------------------------------------------- : Reminder text // ----------------------------------------------------------------------------- : Reminder text
/// Toggle reminder text for a keyword on or off /// Toggle reminder text for a keyword on or off
class TextToggleReminderAction : public ValueAction { class TextToggleReminderAction : public ValueAction {
public: public:
TextToggleReminderAction(const TextValueP& value, size_t pos); TextToggleReminderAction(const Card* card, const TextValueP& value, size_t pos);
virtual String getName(bool to_undo) const; virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo); virtual void perform(bool to_undo);
...@@ -101,7 +102,7 @@ class TextToggleReminderAction : public ValueAction { ...@@ -101,7 +102,7 @@ class TextToggleReminderAction : public ValueAction {
/// A TextValueAction without the start and end stuff /// A TextValueAction without the start and end stuff
class SimpleTextValueAction : public ValueAction { class SimpleTextValueAction : public ValueAction {
public: public:
SimpleTextValueAction(const TextValueP& value, const Defaultable<String>& new_value); SimpleTextValueAction(const Card* card, const TextValueP& value, const Defaultable<String>& new_value);
virtual void perform(bool to_undo); virtual void perform(bool to_undo);
bool merge(const SimpleTextValueAction& action); bool merge(const SimpleTextValueAction& action);
private: private:
......
...@@ -113,9 +113,8 @@ void CardListBase::onAction(const Action& action, bool undone) { ...@@ -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 // No refresh needed, a ScriptValueEvent is only generated in response to a ValueAction
return; return;
} }
TYPE_CASE_(action, ValueAction) { TYPE_CASE(action, ValueAction) {
refreshList(); if (action.card) refreshList();
return;
} }
} }
......
...@@ -75,10 +75,12 @@ void KeywordList::onAction(const Action& action, bool undone) { ...@@ -75,10 +75,12 @@ void KeywordList::onAction(const Action& action, bool undone) {
} }
} }
TYPE_CASE(action, ValueAction) { TYPE_CASE(action, ValueAction) {
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get()); if (!action.card) {
if (value) { KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
// this is indeed an action on a keyword, refresh if (value) {
refreshList(); // this is indeed an action on a keyword, refresh
refreshList();
}
} }
} }
TYPE_CASE_(action, ChangeKeywordModeAction) { TYPE_CASE_(action, ChangeKeywordModeAction) {
......
...@@ -280,18 +280,20 @@ void KeywordsPanel::onChangeSet() { ...@@ -280,18 +280,20 @@ void KeywordsPanel::onChangeSet() {
void KeywordsPanel::onAction(const Action& action, bool undone) { void KeywordsPanel::onAction(const Action& action, bool undone) {
TYPE_CASE(action, ValueAction) { TYPE_CASE(action, ValueAction) {
{ if (!action.card) {
KeywordReminderTextValue* value = dynamic_cast<KeywordReminderTextValue*>(action.valueP.get()); {
if (value && &value->keyword == list->getKeyword().get()) { KeywordReminderTextValue* value = dynamic_cast<KeywordReminderTextValue*>(action.valueP.get());
// the current keyword's reminder text changed if (value && &value->keyword == list->getKeyword().get()) {
errors->SetLabel(value->errors); // the current keyword's reminder text changed
errors->SetLabel(value->errors);
}
} }
} {
{ KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get()); if (value && value->underlying == &list->getKeyword()->match) {
if (value && value->underlying == &list->getKeyword()->match) { // match string changes, maybe there are parameters now
// match string changes, maybe there are parameters now ref_param->Enable(!value->keyword.fixed && !value->keyword.parameters.empty());
ref_param->Enable(!value->keyword.fixed && !value->keyword.parameters.empty()); }
} }
} }
} }
......
...@@ -73,12 +73,14 @@ void StylePanel::onAction(const Action& action, bool undone) { ...@@ -73,12 +73,14 @@ void StylePanel::onAction(const Action& action, bool undone) {
} }
TYPE_CASE(action, ValueAction) { TYPE_CASE(action, ValueAction) {
// is it a styling action? // is it a styling action?
const StyleSheet& s = set->stylesheetFor(card); if (!action.card) {
FOR_EACH_CONST(f, s.styling_fields) { const StyleSheet& s = set->stylesheetFor(card);
if (action.valueP->fieldP == f) { FOR_EACH_CONST(f, s.styling_fields) {
// refresh the viewer if (action.valueP->fieldP == f) {
preview->redraw(); // refresh the viewer
return; preview->redraw();
return;
}
} }
} }
} }
......
...@@ -264,8 +264,10 @@ void SetWindow::onChangeSet() { ...@@ -264,8 +264,10 @@ void SetWindow::onChangeSet() {
void SetWindow::onAction(const Action& action, bool undone) { void SetWindow::onAction(const Action& action, bool undone) {
TYPE_CASE(action, ValueAction) { TYPE_CASE(action, ValueAction) {
if (set->data.contains(action.valueP) && action.valueP->fieldP->identifying) { if (!action.card) {
updateTitle(); if (set->data.contains(action.valueP) && action.valueP->fieldP->identifying) {
updateTitle();
}
} }
} }
/* TYPE_CASE_(action, DisplayChangeAction) { /* TYPE_CASE_(action, DisplayChangeAction) {
......
...@@ -35,8 +35,8 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename) { ...@@ -35,8 +35,8 @@ SymbolWindow::SymbolWindow(Window* parent, const String& filename) {
init(parent, symbol); init(parent, symbol);
} }
SymbolWindow::SymbolWindow(Window* parent, const SymbolValueP& value, const SetP& set) SymbolWindow::SymbolWindow(Window* parent, const SetP& set, const Card* card, const SymbolValueP& value)
: value(value), set(set) : value(value), card(card), set(set)
{ {
// attempt to load symbol // attempt to load symbol
SymbolP symbol; SymbolP symbol;
...@@ -236,7 +236,7 @@ void SymbolWindow::onFileStore(wxCommandEvent& ev) { ...@@ -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 FileName new_filename = set->newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
Writer writer(set->openOut(new_filename)); Writer writer(set->openOut(new_filename));
writer.handle(control->getSymbol()); writer.handle(control->getSymbol());
set->actions.add(value_action(value, new_filename)); set->actions.add(value_action(card, value, new_filename));
} }
} }
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include <wx/listctrl.h> #include <wx/listctrl.h>
class SymbolControl; class SymbolControl;
//%%class SymbolPartList;
class SymbolPartList; class SymbolPartList;
class Card;
DECLARE_POINTER_TYPE(SymbolValue); DECLARE_POINTER_TYPE(SymbolValue);
DECLARE_POINTER_TYPE(Set); DECLARE_POINTER_TYPE(Set);
...@@ -29,7 +29,7 @@ class SymbolWindow : public Frame { ...@@ -29,7 +29,7 @@ class SymbolWindow : public Frame {
/// Construct a SymbolWindow showing a symbol from a file /// Construct a SymbolWindow showing a symbol from a file
SymbolWindow(Window* parent, const String& filename); SymbolWindow(Window* parent, const String& filename);
/// Construct a SymbolWindow showing a symbol value in a set /// 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: private:
// --------------------------------------------------- : Children // --------------------------------------------------- : Children
...@@ -42,6 +42,7 @@ class SymbolWindow : public Frame { ...@@ -42,6 +42,7 @@ class SymbolWindow : public Frame {
// when editing a symbol field // when editing a symbol field
SymbolValueP value; SymbolValueP value;
const Card* card;
SetP set; SetP set;
// --------------------------------------------------- : Event handling // --------------------------------------------------- : Event handling
......
...@@ -307,5 +307,5 @@ void ChoiceValueEditor::determineSize(bool) { ...@@ -307,5 +307,5 @@ void ChoiceValueEditor::determineSize(bool) {
} }
void ChoiceValueEditor::change(const Defaultable<String>& c) { void ChoiceValueEditor::change(const Defaultable<String>& c) {
getSet().actions.add(value_action(valueP(), c)); perform(value_action(card(), valueP(), c));
} }
...@@ -149,7 +149,7 @@ void ColorValueEditor::determineSize(bool) { ...@@ -149,7 +149,7 @@ void ColorValueEditor::determineSize(bool) {
} }
void ColorValueEditor::change(const Defaultable<Color>& c) { void ColorValueEditor::change(const Defaultable<Color>& c) {
getSet().actions.add(value_action(valueP(), c)); perform(value_action(card(), valueP(), c));
} }
void ColorValueEditor::changeCustom() { void ColorValueEditor::changeCustom() {
Color c = wxGetColourFromUser(0, value().value()); Color c = wxGetColourFromUser(0, value().value());
......
...@@ -133,9 +133,14 @@ class ValueEditor { ...@@ -133,9 +133,14 @@ class ValueEditor {
virtual ValueEditor* getEditor() { return this; } \ virtual ValueEditor* getEditor() { return this; } \
virtual void redraw(); \ virtual void redraw(); \
private: \ private: \
/** Retrieve the parent editor object */ \
inline DataEditor& editor() const { \ inline DataEditor& editor() const { \
return static_cast<DataEditor&>(viewer); \ 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: public:
#define IMPLEMENT_VALUE_EDITOR(Type) \ #define IMPLEMENT_VALUE_EDITOR(Type) \
......
...@@ -48,7 +48,7 @@ void ImageValueEditor::sliceImage(const Image& image) { ...@@ -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 FileName new_image_file = getSet().newFileName(field().name,_("")); // a new unique name in the package
Image img = s.getImage(); Image img = s.getImage();
img.SaveFile(getSet().nameOut(new_image_file), img.HasAlpha() ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_JPEG); 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() { ...@@ -88,7 +88,7 @@ bool ImageValueEditor::doPaste() {
} }
bool ImageValueEditor::doDelete() { bool ImageValueEditor::doDelete() {
getSet().actions.add(value_action(valueP(), FileName())); perform(value_action(card(), valueP(), FileName()));
return true; return true;
} }
......
...@@ -173,9 +173,9 @@ void MultipleChoiceValueEditor::toggle(int id) { ...@@ -173,9 +173,9 @@ void MultipleChoiceValueEditor::toggle(int id) {
if (i == id) toggled_choice = choice; if (i == id) toggled_choice = choice;
} }
// store value // store value
getSet().actions.add(value_action(valueP(), new_value, toggled_choice)); perform(value_action(card(), valueP(), new_value, toggled_choice));
} }
void MultipleChoiceValueEditor::toggleDefault() { 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()), _("")));
} }
...@@ -92,7 +92,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) { ...@@ -92,7 +92,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
// edit // edit
button_down = -2; button_down = -2;
viewer.redraw(*this); viewer.redraw(*this);
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet()); SymbolWindow* wnd = new SymbolWindow(nullptr, viewer.getSet(), card(), valueP());
wnd->Show(); wnd->Show();
return true; return true;
} else if (button_down == 1) { } else if (button_down == 1) {
...@@ -109,7 +109,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) { ...@@ -109,7 +109,7 @@ bool SymbolValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
bool SymbolValueEditor::onLeftDClick(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 // 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(); wnd->Show();
return true; return true;
} }
......
...@@ -563,21 +563,6 @@ wxMenu* TextValueEditor::getMenu(int type) const { ...@@ -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 // ----------------------------------------------------------------------------- : Drawing
void TextValueEditor::draw(RotatedDC& dc) { void TextValueEditor::draw(RotatedDC& dc) {
...@@ -783,19 +768,19 @@ void TextValueEditor::doFormat(int type) { ...@@ -783,19 +768,19 @@ void TextValueEditor::doFormat(int type) {
size_t ss = selection_start, se = selection_end; size_t ss = selection_start, se = selection_end;
switch (type) { switch (type) {
case ID_FORMAT_BOLD: { 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; break;
} }
case ID_FORMAT_ITALIC: { 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; break;
} }
case ID_FORMAT_SYMBOL: { 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; break;
} }
case ID_FORMAT_REMINDER: { case ID_FORMAT_REMINDER: {
getSet().actions.add(new TextToggleReminderAction(valueP(), selection_start_i)); perform(new TextToggleReminderAction(card(), valueP(), selection_start_i));
break; break;
} }
} }
...@@ -908,7 +893,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String& ...@@ -908,7 +893,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
fixSelection(); fixSelection();
// execute the action before adding it to the stack, // execute the action before adding it to the stack,
// because we want to run scripts before action listeners see the action // 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) { if (!action) {
// nothing changes, but move the selection anyway // nothing changes, but move the selection anyway
moveSelection(TYPE_CURSOR, selection_end); moveSelection(TYPE_CURSOR, selection_end);
...@@ -919,7 +904,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String& ...@@ -919,7 +904,7 @@ void TextValueEditor::replaceSelection(const String& replacement, const String&
size_t expected_cursor = min(selection_start, selection_end) + untag(replacement).size(); size_t expected_cursor = min(selection_start, selection_end) + untag(replacement).size();
// perform the action // perform the action
// NOTE: this calls our onAction, invalidating the text viewer and moving the selection around the new text // 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 // move cursor
{ {
String real_value = untag_for_cursor(value().value()); String real_value = untag_for_cursor(value().value());
......
...@@ -192,12 +192,14 @@ void DataViewer::onAction(const Action& action, bool undone) { ...@@ -192,12 +192,14 @@ void DataViewer::onAction(const Action& action, bool undone) {
return; return;
} }
TYPE_CASE(action, ValueAction) { TYPE_CASE(action, ValueAction) {
FOR_EACH(v, viewers) { if (action.card == card.get()) {
if (v->getValue()->equals( action.valueP.get() )) { FOR_EACH(v, viewers) {
// refresh the viewer if (v->getValue()->equals( action.valueP.get() )) {
v->onAction(action, undone); // refresh the viewer
onChange(); v->onAction(action, undone);
return; onChange();
return;
}
} }
} }
} }
......
...@@ -57,7 +57,7 @@ class DataViewer : public SetView { ...@@ -57,7 +57,7 @@ class DataViewer : public SetView {
Context& getContext() const; Context& getContext() const;
/// The rotation to use /// The rotation to use
virtual Rotation getRotation() const; virtual Rotation getRotation() const;
/// The card we are viewing /// The card we are viewing, can be null
inline const CardP& getCard() const { return card; } inline const CardP& getCard() const { return card; }
/// Invalidate and redraw (the area of) a single value viewer /// Invalidate and redraw (the area of) a single value viewer
virtual void redraw(const ValueViewer&) {} virtual void redraw(const ValueViewer&) {}
......
...@@ -151,29 +151,39 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) { ...@@ -151,29 +151,39 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
void SetScriptManager::onAction(const Action& action, bool undone) { void SetScriptManager::onAction(const Action& action, bool undone) {
TYPE_CASE(action, ValueAction) { TYPE_CASE(action, ValueAction) {
// is it a keyword's fake value? if (action.card) {
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get()); #ifdef USE_INTRUSIVE_PTR
if (value) { // we can just turn the Card* into a CardP
if (value->underlying == &value->keyword.match) { updateValue(*action.valueP, CardP(const_cast<Card*>(action.card)));
// script return;
Context& ctx = getContext(set.stylesheet); #else
value->update(ctx); // find the affected card
// changed the 'match' string of a keyword, rebuild database and regex so matching is correct FOR_EACH(card, set.cards) {
value->keyword.prepare(set.game->keyword_parameter_types, true); if (card->data.contains(action.valueP)) {
set.keyword_db.clear(); updateValue(*action.valueP, card);
} return;
delay |= DELAY_KEYWORDS; }
return; }
} assert(false);
// find the affected card #endif
FOR_EACH(card, set.cards) { } else {
if (card->data.contains(action.valueP)) { // is it a keyword's fake value?
updateValue(*action.valueP, card); KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
if (value) {
if (value->underlying == &value->keyword.match) {
// script
Context& ctx = getContext(set.stylesheet);
value->update(ctx);
// changed the 'match' string of a keyword, rebuild database and regex so matching is correct
value->keyword.prepare(set.game->keyword_parameter_types, true);
set.keyword_db.clear();
}
delay |= DELAY_KEYWORDS;
return; return;
} }
// a set or styling value
updateValue(*action.valueP, CardP());
} }
// not a card value
updateValue(*action.valueP, CardP());
} }
TYPE_CASE_(action, ScriptValueEvent) { TYPE_CASE_(action, ScriptValueEvent) {
return; // Don't go into an infinite loop because of our own events return; // Don't go into an infinite loop because of our own events
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment