mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
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:
+17
-17
@@ -39,8 +39,8 @@ inline void swap_value(MultipleChoiceValue& a, MultipleChoiceValue::ValueType& b
|
||||
template <typename T, bool ALLOW_MERGE>
|
||||
class SimpleValueAction : public ValueAction {
|
||||
public:
|
||||
inline SimpleValueAction(const intrusive_ptr<T>& value, const typename T::ValueType& new_value)
|
||||
: ValueAction(value), new_value(new_value)
|
||||
inline SimpleValueAction(const Card* card, const intrusive_ptr<T>& value, const typename T::ValueType& new_value)
|
||||
: ValueAction(card, value), new_value(new_value)
|
||||
{}
|
||||
|
||||
virtual void perform(bool to_undo) {
|
||||
@@ -64,20 +64,20 @@ class SimpleValueAction : public ValueAction {
|
||||
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 ColorValueP& value, const Defaultable<Color>& new_value) { return new SimpleValueAction<ColorValue, true> (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 SymbolValueP& value, const FileName& new_value) { return new SimpleValueAction<SymbolValue, false>(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 ChoiceValueP& value, const Defaultable<String>& new_value) { return new SimpleValueAction<ChoiceValue, true> (card, 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 Card* card, const ImageValueP& value, const FileName& new_value) { return new SimpleValueAction<ImageValue, false>(card, 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 Card* card, const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& 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
|
||||
|
||||
TextValueAction::TextValueAction(const TextValueP& value, size_t start, size_t end, size_t new_end, const Defaultable<String>& new_value, const String& name)
|
||||
: ValueAction(value)
|
||||
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(card, value)
|
||||
, selection_start(start), selection_end(end), new_selection_end(new_end)
|
||||
, new_value(new_value)
|
||||
, name(name)
|
||||
@@ -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) {
|
||||
swap(start, end);
|
||||
swap(start_i, end_i);
|
||||
@@ -140,11 +140,11 @@ TextValueAction* toggle_format_action(const TextValueP& value, const String& tag
|
||||
if (value->value() == new_value) {
|
||||
return nullptr; // no changes
|
||||
} 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;
|
||||
if (reverse) {
|
||||
swap(start, end);
|
||||
@@ -156,17 +156,17 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e
|
||||
return nullptr;
|
||||
} else {
|
||||
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 {
|
||||
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
|
||||
|
||||
TextToggleReminderAction::TextToggleReminderAction(const TextValueP& value, size_t pos_in)
|
||||
: ValueAction(value)
|
||||
TextToggleReminderAction::TextToggleReminderAction(const Card* card, const TextValueP& value, size_t pos_in)
|
||||
: ValueAction(card, value)
|
||||
{
|
||||
pos = in_tag(value->value(), _("<kw-"), pos_in, pos_in);
|
||||
if (pos == String::npos) {
|
||||
|
||||
+12
-11
@@ -34,28 +34,29 @@ DECLARE_POINTER_TYPE(SymbolValue);
|
||||
/// An Action the changes a Value
|
||||
class ValueAction : public Action {
|
||||
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;
|
||||
|
||||
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
|
||||
|
||||
/// Action that updates a Value to a new value
|
||||
ValueAction* value_action(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 ColorValueP& value, const Defaultable<Color>& new_value);
|
||||
ValueAction* value_action(const ImageValueP& value, const FileName& new_value);
|
||||
ValueAction* value_action(const SymbolValueP& value, const FileName& new_value);
|
||||
ValueAction* value_action(const Card* card, const ChoiceValueP& value, const Defaultable<String>& new_value);
|
||||
ValueAction* value_action(const Card* card, const MultipleChoiceValueP& value, const Defaultable<String>& new_value, const String& last_change);
|
||||
ValueAction* value_action(const Card* card, const ColorValueP& value, const Defaultable<Color>& new_value);
|
||||
ValueAction* value_action(const Card* card, const ImageValueP& value, const FileName& new_value);
|
||||
ValueAction* value_action(const Card* card, const SymbolValueP& value, const FileName& new_value);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Text
|
||||
|
||||
/// An action that changes a TextValue
|
||||
class TextValueAction : public ValueAction {
|
||||
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 void perform(bool to_undo);
|
||||
@@ -74,18 +75,18 @@ class TextValueAction : public ValueAction {
|
||||
};
|
||||
|
||||
/// 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
|
||||
/** 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
|
||||
|
||||
/// Toggle reminder text for a keyword on or off
|
||||
class TextToggleReminderAction : public ValueAction {
|
||||
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 void perform(bool to_undo);
|
||||
@@ -101,7 +102,7 @@ class TextToggleReminderAction : public ValueAction {
|
||||
/// A TextValueAction without the start and end stuff
|
||||
class SimpleTextValueAction : public ValueAction {
|
||||
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);
|
||||
bool merge(const SimpleTextValueAction& action);
|
||||
private:
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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) \
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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()), _("")));
|
||||
}
|
||||
|
||||
@@ -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
@@ -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());
|
||||
|
||||
@@ -192,12 +192,14 @@ void DataViewer::onAction(const Action& action, bool undone) {
|
||||
return;
|
||||
}
|
||||
TYPE_CASE(action, ValueAction) {
|
||||
FOR_EACH(v, viewers) {
|
||||
if (v->getValue()->equals( action.valueP.get() )) {
|
||||
// refresh the viewer
|
||||
v->onAction(action, undone);
|
||||
onChange();
|
||||
return;
|
||||
if (action.card == card.get()) {
|
||||
FOR_EACH(v, viewers) {
|
||||
if (v->getValue()->equals( action.valueP.get() )) {
|
||||
// refresh the viewer
|
||||
v->onAction(action, undone);
|
||||
onChange();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class DataViewer : public SetView {
|
||||
Context& getContext() const;
|
||||
/// The rotation to use
|
||||
virtual Rotation getRotation() const;
|
||||
/// The card we are viewing
|
||||
/// The card we are viewing, can be null
|
||||
inline const CardP& getCard() const { return card; }
|
||||
/// Invalidate and redraw (the area of) a single value viewer
|
||||
virtual void redraw(const ValueViewer&) {}
|
||||
|
||||
@@ -151,29 +151,39 @@ void SetScriptManager::initDependencies(Context& ctx, StyleSheet& stylesheet) {
|
||||
|
||||
void SetScriptManager::onAction(const Action& action, bool undone) {
|
||||
TYPE_CASE(action, ValueAction) {
|
||||
// is it a keyword's fake value?
|
||||
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;
|
||||
}
|
||||
// find the affected card
|
||||
FOR_EACH(card, set.cards) {
|
||||
if (card->data.contains(action.valueP)) {
|
||||
updateValue(*action.valueP, card);
|
||||
if (action.card) {
|
||||
#ifdef USE_INTRUSIVE_PTR
|
||||
// we can just turn the Card* into a CardP
|
||||
updateValue(*action.valueP, CardP(const_cast<Card*>(action.card)));
|
||||
return;
|
||||
#else
|
||||
// find the affected card
|
||||
FOR_EACH(card, set.cards) {
|
||||
if (card->data.contains(action.valueP)) {
|
||||
updateValue(*action.valueP, card);
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert(false);
|
||||
#endif
|
||||
} else {
|
||||
// is it a keyword's fake value?
|
||||
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;
|
||||
}
|
||||
// a set or styling value
|
||||
updateValue(*action.valueP, CardP());
|
||||
}
|
||||
// not a card value
|
||||
updateValue(*action.valueP, CardP());
|
||||
}
|
||||
TYPE_CASE_(action, ScriptValueEvent) {
|
||||
return; // Don't go into an infinite loop because of our own events
|
||||
|
||||
Reference in New Issue
Block a user