mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 13:06:59 -04:00
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
This commit is contained in:
@@ -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(), _("<kw-"), pos_in, pos_in);
|
||||
if (pos == String::npos) {
|
||||
throw InternalError(_("TextToggleReminderAction: not in <kw- tag"));
|
||||
}
|
||||
Char c = 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<TextValue&>(*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; // </kw-c>
|
||||
}
|
||||
value.last_update.update();
|
||||
value.onAction(*this, to_undo); // notify value
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event
|
||||
|
||||
|
||||
@@ -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 "<kw-"
|
||||
bool enable; ///< Should the reminder text be turned on or off?
|
||||
Char old; ///< Old value of the <kw- tag
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : Event
|
||||
|
||||
/// Notification that a script caused a value to change
|
||||
|
||||
@@ -323,6 +323,10 @@ RealSize SymbolFont::defaultSymbolSize(Context& ctx, double font_size) {
|
||||
|
||||
wxMenu* SymbolFont::insertSymbolMenu(Context& ctx) {
|
||||
if (!processed_insert_symbol_menu && insert_symbol_menu) {
|
||||
// update all symbol-in-fonts
|
||||
FOR_EACH_CONST(sym, symbols) {
|
||||
sym->update(ctx);
|
||||
}
|
||||
// Make menu
|
||||
processed_insert_symbol_menu = insert_symbol_menu->makeMenu(ID_INSERT_SYMBOL_MENU_MIN, ctx, *this);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <gui/control/card_editor.hpp>
|
||||
#include <render/value/viewer.hpp>
|
||||
|
||||
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
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <gui/value/text.hpp>
|
||||
#include <gui/icon_menu.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/action/value.hpp>
|
||||
#include <util/tagged_string.hpp>
|
||||
@@ -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(), _("<kw-"), selection_start_i, selection_start_i);
|
||||
if (kwpos != String::npos) {
|
||||
Char c = String(value().value()).GetChar(kwpos + 4);
|
||||
m.AppendSeparator();
|
||||
m.AppendCheckItem(ID_FORMAT_REMINDER, _("&Reminder text"), _("Show or hide reminder text for this keyword"));
|
||||
m.Check(ID_FORMAT_REMINDER, c == _('1') || c == _('A')); // reminder text currently shown
|
||||
m.Append(ID_FORMAT_REMINDER, _("reminder"), _MENU_("reminder text"), _HELP_("reminder text"), wxITEM_CHECK);
|
||||
}
|
||||
// always show the menu
|
||||
return true;
|
||||
@@ -369,7 +368,7 @@ bool TextValueEditor::canFormat(int type) const {
|
||||
return !style().always_symbol && style().allow_formating && style().symbol_font.valid();
|
||||
case ID_FORMAT_REMINDER:
|
||||
return !style().always_symbol && style().allow_formating &&
|
||||
in_tag(value().value(), _("<kw"), selection_start_i, selection_end_i) != String::npos;
|
||||
in_tag(value().value(), _("<kw"), selection_start_i, selection_start_i) != String::npos;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -385,7 +384,7 @@ bool TextValueEditor::hasFormat(int type) const {
|
||||
return in_tag(value().value(), _("<sym"), selection_start_i, selection_end_i) != String::npos;
|
||||
case ID_FORMAT_REMINDER: {
|
||||
const String& v = value().value();
|
||||
size_t tag = in_tag(v, _("<kw"), selection_start_i, selection_end_i);
|
||||
size_t tag = in_tag(v, _("<kw"), selection_start_i, selection_start_i);
|
||||
if (tag != String::npos && tag + 4 < v.size()) {
|
||||
Char c = v.GetChar(tag + 4);
|
||||
return c == _('1') || c == _('A');
|
||||
@@ -411,6 +410,10 @@ void TextValueEditor::doFormat(int type) {
|
||||
getSet().actions.add(toggle_format_action(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));
|
||||
break;
|
||||
}
|
||||
}
|
||||
selection_start = ss;
|
||||
selection_end = se;
|
||||
|
||||
@@ -61,7 +61,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
|
||||
virtual bool onMotion (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onMouseWheel(const RealPoint& pos, wxMouseEvent& ev);
|
||||
|
||||
virtual bool onContextMenu(wxMenu& m, wxContextMenuEvent&);
|
||||
virtual bool onContextMenu(IconMenu& m, wxContextMenuEvent&);
|
||||
virtual wxMenu* getMenu(int type) const;
|
||||
virtual bool onCommand(int);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user