Commit d302d206 authored by twanvl's avatar twanvl

added toggle reminder text action;

updated SymbolsInFont when creating 'insert symbol' menu
parent 34c503c7
...@@ -144,8 +144,6 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e ...@@ -144,8 +144,6 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e
// no change // no change
return nullptr; return nullptr;
} else { } else {
// if (name == _("Backspace")) {
// // HACK: put start after end
if (reverse) { if (reverse) {
return new TextValueAction(value, end, start, start+untag(replacement).size(), new_value, action_name); return new TextValueAction(value, end, start, start+untag(replacement).size(), new_value, action_name);
} else { } else {
...@@ -154,6 +152,37 @@ TextValueAction* typing_action(const TextValueP& value, size_t start_i, size_t e ...@@ -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 // ----------------------------------------------------------------------------- : Event
......
...@@ -71,13 +71,29 @@ class TextValueAction : public ValueAction { ...@@ -71,13 +71,29 @@ class TextValueAction : public ValueAction {
String name; 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); 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 /// 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 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 // ----------------------------------------------------------------------------- : Event
/// Notification that a script caused a value to change /// Notification that a script caused a value to change
......
...@@ -323,6 +323,10 @@ RealSize SymbolFont::defaultSymbolSize(Context& ctx, double font_size) { ...@@ -323,6 +323,10 @@ RealSize SymbolFont::defaultSymbolSize(Context& ctx, double font_size) {
wxMenu* SymbolFont::insertSymbolMenu(Context& ctx) { wxMenu* SymbolFont::insertSymbolMenu(Context& ctx) {
if (!processed_insert_symbol_menu && insert_symbol_menu) { if (!processed_insert_symbol_menu && insert_symbol_menu) {
// update all symbol-in-fonts
FOR_EACH_CONST(sym, symbols) {
sym->update(ctx);
}
// Make menu // Make menu
processed_insert_symbol_menu = insert_symbol_menu->makeMenu(ID_INSERT_SYMBOL_MENU_MIN, ctx, *this); processed_insert_symbol_menu = insert_symbol_menu->makeMenu(ID_INSERT_SYMBOL_MENU_MIN, ctx, *this);
} }
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <gui/control/card_editor.hpp> #include <gui/control/card_editor.hpp>
#include <render/value/viewer.hpp> #include <render/value/viewer.hpp>
class IconMenu;
// ----------------------------------------------------------------------------- : ValueEditor // ----------------------------------------------------------------------------- : ValueEditor
/// An editor 'control' for a single value on a card /// An editor 'control' for a single value on a card
...@@ -52,7 +54,7 @@ class ValueEditor { ...@@ -52,7 +54,7 @@ class ValueEditor {
/// a context menu is requested, add extra items to the menu m /// a context menu is requested, add extra items to the menu m
/** return false to suppress menu */ /** 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 /// Get a special menu, events will be sent to onMenu
virtual wxMenu* getMenu(int type) const { return nullptr; } virtual wxMenu* getMenu(int type) const { return nullptr; }
/// A menu item was selected, return true if the command was processed /// A menu item was selected, return true if the command was processed
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include <gui/value/text.hpp> #include <gui/value/text.hpp>
#include <gui/icon_menu.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
#include <data/action/value.hpp> #include <data/action/value.hpp>
#include <util/tagged_string.hpp> #include <util/tagged_string.hpp>
...@@ -221,14 +222,12 @@ void TextValueEditor::onLoseFocus() { ...@@ -221,14 +222,12 @@ void TextValueEditor::onLoseFocus() {
selection_start_i = selection_end_i = 0; 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 // in a keword? => "reminder text" option
size_t kwpos = in_tag(value().value(), _("<kw-"), selection_start_i, selection_start_i); size_t kwpos = in_tag(value().value(), _("<kw-"), selection_start_i, selection_start_i);
if (kwpos != String::npos) { if (kwpos != String::npos) {
Char c = String(value().value()).GetChar(kwpos + 4);
m.AppendSeparator(); m.AppendSeparator();
m.AppendCheckItem(ID_FORMAT_REMINDER, _("&Reminder text"), _("Show or hide reminder text for this keyword")); m.Append(ID_FORMAT_REMINDER, _("reminder"), _MENU_("reminder text"), _HELP_("reminder text"), wxITEM_CHECK);
m.Check(ID_FORMAT_REMINDER, c == _('1') || c == _('A')); // reminder text currently shown
} }
// always show the menu // always show the menu
return true; return true;
...@@ -369,7 +368,7 @@ bool TextValueEditor::canFormat(int type) const { ...@@ -369,7 +368,7 @@ bool TextValueEditor::canFormat(int type) const {
return !style().always_symbol && style().allow_formating && style().symbol_font.valid(); return !style().always_symbol && style().allow_formating && style().symbol_font.valid();
case ID_FORMAT_REMINDER: case ID_FORMAT_REMINDER:
return !style().always_symbol && style().allow_formating && 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: default:
return false; return false;
} }
...@@ -385,7 +384,7 @@ bool TextValueEditor::hasFormat(int type) const { ...@@ -385,7 +384,7 @@ bool TextValueEditor::hasFormat(int type) const {
return in_tag(value().value(), _("<sym"), selection_start_i, selection_end_i) != String::npos; return in_tag(value().value(), _("<sym"), selection_start_i, selection_end_i) != String::npos;
case ID_FORMAT_REMINDER: { case ID_FORMAT_REMINDER: {
const String& v = value().value(); 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()) { if (tag != String::npos && tag + 4 < v.size()) {
Char c = v.GetChar(tag + 4); Char c = v.GetChar(tag + 4);
return c == _('1') || c == _('A'); return c == _('1') || c == _('A');
...@@ -411,6 +410,10 @@ void TextValueEditor::doFormat(int type) { ...@@ -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"))); getSet().actions.add(toggle_format_action(valueP(), _("sym"), selection_start_i, selection_end_i, selection_start, selection_end, _("Symbols")));
break; break;
} }
case ID_FORMAT_REMINDER: {
getSet().actions.add(new TextToggleReminderAction(valueP(), selection_start_i));
break;
}
} }
selection_start = ss; selection_start = ss;
selection_end = se; selection_end = se;
......
...@@ -61,7 +61,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor { ...@@ -61,7 +61,7 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
virtual bool onMotion (const RealPoint& pos, wxMouseEvent&); virtual bool onMotion (const RealPoint& pos, wxMouseEvent&);
virtual bool onMouseWheel(const RealPoint& pos, wxMouseEvent& ev); 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 wxMenu* getMenu(int type) const;
virtual bool onCommand(int); virtual bool onCommand(int);
......
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