From f530cd7244baf487049dea83df85ce26656deaca Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 19 Apr 2007 14:04:50 +0000 Subject: [PATCH] added toggle reminder text action; updated SymbolsInFont when creating 'insert symbol' menu git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@266 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/action/value.cpp | 33 +++++++++++++++++++++++++++++++-- src/data/action/value.hpp | 18 +++++++++++++++++- src/data/symbol_font.cpp | 4 ++++ src/gui/value/editor.hpp | 4 +++- src/gui/value/text.cpp | 15 +++++++++------ src/gui/value/text.hpp | 2 +- 6 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/data/action/value.cpp b/src/data/action/value.cpp index 25ca3f47..1fceaf7e 100644 --- a/src/data/action/value.cpp +++ b/src/data/action/value.cpp @@ -144,8 +144,6 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e // no change return nullptr; } else { -// if (name == _("Backspace")) { -// // HACK: put start after end if (reverse) { return new TextValueAction(value, end, start, start+untag(replacement).size(), new_value, action_name); } else { @@ -154,6 +152,37 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e } } +// ----------------------------------------------------------------------------- : Reminder text + +TextToggleReminderAction::TextToggleReminderAction(const TextValueP& value, size_t pos_in) + : ValueAction(value) +{ + pos = in_tag(value->value(), _("value().GetChar(pos + 4); + enable = !(c == _('1') || c == _('A')); // if it was not enabled, then enable it + old = enable ? _('1') : _('0'); +} +String TextToggleReminderAction::getName(bool to_undo) const { + return enable ? _("Show reminder text") : _("Hide reminder text"); +} + +void TextToggleReminderAction::perform(bool to_undo) { + TextValue& value = static_cast(*valueP); + String& val = value.value.mutate(); + assert(pos + 4 < val.size()); + size_t end = match_close_tag(val, pos); + Char& c = val[pos + 4]; + swap(c, old); + if (end != String::npos && end + 5 < val.size()) { + val[end + 5] = c; // + } + value.last_update.update(); + value.onAction(*this, to_undo); // notify value +} + // ----------------------------------------------------------------------------- : Event diff --git a/src/data/action/value.hpp b/src/data/action/value.hpp index 8a9486f1..2ddc32da 100644 --- a/src/data/action/value.hpp +++ b/src/data/action/value.hpp @@ -71,13 +71,29 @@ class TextValueAction : public ValueAction { String name; }; -/// Action for toggleing 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); /// 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); +// ----------------------------------------------------------------------------- : Reminder text + +/// Toggle reminder text for a keyword on or off +class TextToggleReminderAction : public ValueAction { + public: + TextToggleReminderAction(const TextValueP& value, size_t pos); + + virtual String getName(bool to_undo) const; + virtual void perform(bool to_undo); + + private: + size_t pos; ///< Position of "update(ctx); + } // Make menu processed_insert_symbol_menu = insert_symbol_menu->makeMenu(ID_INSERT_SYMBOL_MENU_MIN, ctx, *this); } diff --git a/src/gui/value/editor.hpp b/src/gui/value/editor.hpp index a5daa7a3..ddb139fe 100644 --- a/src/gui/value/editor.hpp +++ b/src/gui/value/editor.hpp @@ -13,6 +13,8 @@ #include #include +class IconMenu; + // ----------------------------------------------------------------------------- : ValueEditor /// An editor 'control' for a single value on a card @@ -52,7 +54,7 @@ class ValueEditor { /// a context menu is requested, add extra items to the menu m /** return false to suppress menu */ - virtual bool onContextMenu(wxMenu& m, wxContextMenuEvent& ev) { return true; } + virtual bool onContextMenu(IconMenu& m, wxContextMenuEvent& ev) { return true; } /// Get a special menu, events will be sent to onMenu virtual wxMenu* getMenu(int type) const { return nullptr; } /// A menu item was selected, return true if the command was processed diff --git a/src/gui/value/text.cpp b/src/gui/value/text.cpp index ec9359e7..7cf47b3f 100644 --- a/src/gui/value/text.cpp +++ b/src/gui/value/text.cpp @@ -7,6 +7,7 @@ // ----------------------------------------------------------------------------- : Includes #include +#include #include #include #include @@ -221,14 +222,12 @@ void TextValueEditor::onLoseFocus() { selection_start_i = selection_end_i = 0; } -bool TextValueEditor::onContextMenu(wxMenu& m, wxContextMenuEvent& ev) { +bool TextValueEditor::onContextMenu(IconMenu& m, wxContextMenuEvent& ev) { // in a keword? => "reminder text" option size_t kwpos = in_tag(value().value(), _("