Commit e8d4342d authored by twanvl's avatar twanvl

Added ChangeKeywordModeAction;

Hopefully fixed the 'Invalid multibyte character' build error on linux (I was using left/right-angle-brackets in string constants);
Fixed 'cost' keywords;
parent e7819c56
...@@ -153,16 +153,9 @@ init script: ...@@ -153,16 +153,9 @@ init script:
# step 1 : remove all automatic tags # step 1 : remove all automatic tags
tag_remove_rule(tag: "<sym-auto>") + tag_remove_rule(tag: "<sym-auto>") +
tag_remove_rule(tag: "<i-auto>") + tag_remove_rule(tag: "<i-auto>") +
# # step 2 : reminder text for keywords # step 2 : reminder text for keywords
# keyword_rule(
# expand_reminder_game: { set.automatic_reminder_text == "yes" },
# expand_reminder_set: { set.automatic_reminder_text != "no" },
# before: " (",
# after: ")",
# fix_english: true
# ) +
expand_keywords_rule( expand_keywords_rule(
default_expand: { set.automatic_reminder_text == "yes" }, default_expand: { contains(match:mode, set.automatic_reminder_text, match:mode) },
combine: { "{keyword}<atom-reminder><i> ({reminder})</i></atom-reminder>" } combine: { "{keyword}<atom-reminder><i> ({reminder})</i></atom-reminder>" }
) + ) +
# step 3a : expand shortcut words ~ and CARDNAME # step 3a : expand shortcut words ~ and CARDNAME
...@@ -899,8 +892,6 @@ keyword mode: ...@@ -899,8 +892,6 @@ keyword mode:
name: custom name: custom
description: Custom keywords description: Custom keywords
keyword parameter type:
name: no parameter
keyword parameter type: keyword parameter type:
name: mana name: mana
match: [XYZ0-9WUBRGS/]+ match: [XYZ0-9WUBRGS/]+
...@@ -909,7 +900,7 @@ keyword parameter type: ...@@ -909,7 +900,7 @@ keyword parameter type:
name: cost name: cost
#insert as: word #insert as: word
match: [XYZ0-9WUBRGS/]+|[^(.,\n]|([XYZ0-9WUBRGS/]+,)?[^(.,\n]* match: [XYZ0-9WUBRGS/]+|[^(.,\n]|([XYZ0-9WUBRGS/]+,)?[^(.,\n]*
script: "<sym-auto>{mana_sort()}</sym-auto>" # TODO : DEBUG #script: "<sym-auto>{mana_sort()}</sym-auto>" # TODO : DEBUG
keyword parameter type: keyword parameter type:
name: number name: number
match: [XYZ0-9]+ match: [XYZ0-9]+
......
...@@ -190,3 +190,17 @@ void KeywordReminderTextValue::highlight(const String& code, const vector<Script ...@@ -190,3 +190,17 @@ void KeywordReminderTextValue::highlight(const String& code, const vector<Script
// set // set
value = new_value; value = new_value;
} }
// ----------------------------------------------------------------------------- : Changing keywords : mode
ChangeKeywordModeAction::ChangeKeywordModeAction(Keyword& keyword, const String& new_mode)
: keyword(keyword), mode(new_mode)
{}
String ChangeKeywordModeAction::getName(bool to_undo) const {
return _("Keyword mode");
}
void ChangeKeywordModeAction::perform(bool to_undo) {
swap(keyword.mode, mode);
}
...@@ -99,7 +99,15 @@ class KeywordReminderTextValue : public KeywordTextValue { ...@@ -99,7 +99,15 @@ class KeywordReminderTextValue : public KeywordTextValue {
/// Changing the mode of a keyword /// Changing the mode of a keyword
class ChangeKeywordModeAction : public Action { class ChangeKeywordModeAction : public Action {
public:
ChangeKeywordModeAction(Keyword& keyword, const String& new_mode);
virtual String getName(bool to_undo) const;
virtual void perform(bool to_undo);
//private:
Keyword& keyword;
String mode;
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -13,6 +13,7 @@ class KeywordTrie; ...@@ -13,6 +13,7 @@ class KeywordTrie;
DECLARE_TYPEOF(map<Char COMMA KeywordTrie*>); DECLARE_TYPEOF(map<Char COMMA KeywordTrie*>);
DECLARE_TYPEOF_COLLECTION(KeywordTrie*); DECLARE_TYPEOF_COLLECTION(KeywordTrie*);
DECLARE_TYPEOF_COLLECTION(KeywordP); DECLARE_TYPEOF_COLLECTION(KeywordP);
DECLARE_TYPEOF_COLLECTION(KeywordModeP);
DECLARE_TYPEOF_COLLECTION(KeywordParamP); DECLARE_TYPEOF_COLLECTION(KeywordParamP);
DECLARE_TYPEOF_COLLECTION(const Keyword*); DECLARE_TYPEOF_COLLECTION(const Keyword*);
...@@ -66,6 +67,23 @@ IMPLEMENT_REFLECTION(Keyword) { ...@@ -66,6 +67,23 @@ IMPLEMENT_REFLECTION(Keyword) {
} }
size_t Keyword::findMode(const vector<KeywordModeP>& modes) const {
// find
size_t id = 0;
FOR_EACH_CONST(m, modes) {
if (mode == m->name) return id;
++id;
}
// default
id = 0;
FOR_EACH_CONST(m, modes) {
if (m->is_default) return id;
++id;
}
// not found
return 0;
}
// ----------------------------------------------------------------------------- : Regex stuff // ----------------------------------------------------------------------------- : Regex stuff
/// Make sure the given regex does no capturing /// Make sure the given regex does no capturing
...@@ -291,6 +309,7 @@ String KeywordDatabase::expand(const String& text, ...@@ -291,6 +309,7 @@ String KeywordDatabase::expand(const String& text,
s = remove_tag_contents(s, _("<atom-keyword>")); // OLD, TODO: REMOVEME s = remove_tag_contents(s, _("<atom-keyword>")); // OLD, TODO: REMOVEME
s = remove_tag_contents(s, _("<atom-kwpph>")); s = remove_tag_contents(s, _("<atom-kwpph>"));
s = remove_tag(s, _("<keyword-param")); s = remove_tag(s, _("<keyword-param"));
s = remove_tag(s, _("<param-"));
String untagged = untag_no_escape(s); String untagged = untag_no_escape(s);
if (!root) return s; if (!root) return s;
...@@ -386,6 +405,8 @@ String KeywordDatabase::expand(const String& text, ...@@ -386,6 +405,8 @@ String KeywordDatabase::expand(const String& text,
ctx.setVariable(_("input"), to_script(part)); ctx.setVariable(_("input"), to_script(part));
param = kwp.script.invoke(ctx)->toString(); param = kwp.script.invoke(ctx)->toString();
} }
part = _("<param-") + kwp.name + _(">") + part + _("</param-") + kwp.name + _(">");
param = _("<param-") + kwp.name + _(">") + param + _("</param-") + kwp.name + _(">");
ctx.setVariable(String(_("param")) << (int)(j/2), to_script(param)); ctx.setVariable(String(_("param")) << (int)(j/2), to_script(param));
} }
total += part; total += part;
......
...@@ -70,6 +70,10 @@ class Keyword { ...@@ -70,6 +70,10 @@ class Keyword {
wxRegEx matchRe; wxRegEx matchRe;
bool fixed; ///< Is this keyword uneditable? (true for game keywods, false for set keywords) bool fixed; ///< Is this keyword uneditable? (true for game keywods, false for set keywords)
/// Find the index of the mode in a list of possibilities.
/** Returns the default if not found and 0 if there is no default */
size_t findMode(const vector<KeywordModeP>& modes) const;
/// Prepare the expansion: (re)generate matchRe and the list of parameters. /// Prepare the expansion: (re)generate matchRe and the list of parameters.
/** Throws when there is an error in the input /** Throws when there is an error in the input
* @param param_types A list of all parameter types. * @param param_types A list of all parameter types.
......
...@@ -92,6 +92,9 @@ void KeywordList::onAction(const Action& action, bool undone) { ...@@ -92,6 +92,9 @@ void KeywordList::onAction(const Action& action, bool undone) {
refreshList(); refreshList();
} }
} }
TYPE_CASE_(action, ChangeKeywordModeAction) {
refreshList();
}
} }
// ----------------------------------------------------------------------------- : KeywordListBase : for ItemList // ----------------------------------------------------------------------------- : KeywordListBase : for ItemList
...@@ -99,8 +102,8 @@ void KeywordList::onAction(const Action& action, bool undone) { ...@@ -99,8 +102,8 @@ void KeywordList::onAction(const Action& action, bool undone) {
String match_string(const Keyword& a) { String match_string(const Keyword& a) {
return untag(replace_all(replace_all( return untag(replace_all(replace_all(
a.match, a.match,
_("<atom-param>"), _("")), _("<atom-param>"), LEFT_ANGLE_BRACKET),
_("</atom-param>"), _("")) _("</atom-param>"), RIGHT_ANGLE_BRACKET)
); );
} }
......
...@@ -28,7 +28,11 @@ Rotation TextCtrl::getRotation() const { ...@@ -28,7 +28,11 @@ Rotation TextCtrl::getRotation() const {
void TextCtrl::draw(DC& dc) { void TextCtrl::draw(DC& dc) {
RotatedDC rdc(dc, getRotation(), QUALITY_LOW); RotatedDC rdc(dc, getRotation(), QUALITY_LOW);
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); if (viewers.empty() || !static_cast<FakeTextValue&>(*viewers.front()->getValue()).editable) {
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
} else {
DataViewer::draw(rdc, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
}
} }
......
...@@ -39,7 +39,7 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id) ...@@ -39,7 +39,7 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
reminder = new TextCtrl(panel, wxID_ANY, true); // allow multiline for wordwrap reminder = new TextCtrl(panel, wxID_ANY, true); // allow multiline for wordwrap
rules = new TextCtrl(panel, wxID_ANY, true); rules = new TextCtrl(panel, wxID_ANY, true);
errors = new wxStaticText(panel, wxID_ANY, _("")); errors = new wxStaticText(panel, wxID_ANY, _(""));
mode = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr); mode = new wxChoice(panel, ID_KEYWORD_MODE, wxDefaultPosition, wxDefaultSize, 0, nullptr);
add_param = new wxButton(panel, ID_KEYWORD_ADD_PARAM, _("Insert Parameter")); add_param = new wxButton(panel, ID_KEYWORD_ADD_PARAM, _("Insert Parameter"));
// warning about fixed keywords // warning about fixed keywords
fixedL = new wxStaticText(panel, wxID_ANY, _("")); fixedL = new wxStaticText(panel, wxID_ANY, _(""));
...@@ -159,12 +159,19 @@ void KeywordsPanel::onCommand(int id) { ...@@ -159,12 +159,19 @@ void KeywordsPanel::onCommand(int id) {
break; break;
case ID_KEYWORD_ADD_PARAM: { case ID_KEYWORD_ADD_PARAM: {
wxMenu param_menu; wxMenu param_menu;
int id = ID_PARAM_TYPE_MIN;
FOR_EACH(p, set->game->keyword_parameter_types) { FOR_EACH(p, set->game->keyword_parameter_types) {
param_menu.Append(wxID_ANY, p->name); param_menu.Append(id++, p->name);
} }
add_param->PopupMenu(&param_menu, 0, add_param->GetSize().y); add_param->PopupMenu(&param_menu, 0, add_param->GetSize().y);
break; break;
} }
default:
if (id >= ID_PARAM_TYPE_MIN && id < ID_PARAM_TYPE_MAX) {
// add parameter
KeywordParamP param = set->game->keyword_parameter_types.at(id - ID_PARAM_TYPE_MIN);
}
} }
} }
...@@ -198,6 +205,7 @@ void KeywordsPanel::onChangeSet() { ...@@ -198,6 +205,7 @@ void KeywordsPanel::onChangeSet() {
FOR_EACH(m, set->game->keyword_modes) { FOR_EACH(m, set->game->keyword_modes) {
mode->Append(m->name); mode->Append(m->name);
} }
mode ->Enable(false);
// re-layout // re-layout
panel->Layout(); panel->Layout();
} }
...@@ -210,6 +218,12 @@ void KeywordsPanel::onAction(const Action& action, bool undone) { ...@@ -210,6 +218,12 @@ void KeywordsPanel::onAction(const Action& action, bool undone) {
errors->SetLabel(value->errors); errors->SetLabel(value->errors);
} }
} }
TYPE_CASE(action, ChangeKeywordModeAction) {
if (&action.keyword == list->getKeyword().get()) {
// the current keyword's mode changed
mode->SetSelection((int)list->getKeyword()->findMode(set->game->keyword_modes));
}
}
} }
void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) { void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
...@@ -223,7 +237,8 @@ void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) { ...@@ -223,7 +237,8 @@ void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
reminder->setValue(reminder_value); reminder->setValue(reminder_value);
errors->SetLabel(reminder_value->errors); errors->SetLabel(reminder_value->errors);
add_param->Enable(!kw.fixed && !set->game->keyword_parameter_types.empty()); add_param->Enable(!kw.fixed && !set->game->keyword_parameter_types.empty());
mode->SetStringSelection(kw.mode); mode ->Enable(!kw.fixed && !set->game->keyword_modes.empty());
mode->SetSelection((int)kw.findMode(set->game->keyword_modes));
sp->Layout(); sp->Layout();
} else { } else {
keyword ->setValue(nullptr); keyword ->setValue(nullptr);
...@@ -235,6 +250,16 @@ void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) { ...@@ -235,6 +250,16 @@ void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
} }
} }
void KeywordsPanel::onModeChange(wxCommandEvent& ev) {
if (!list->getKeyword()) return;
int sel = mode->GetSelection();
if (sel >= 0 && (size_t)sel < set->game->keyword_modes.size()) {
set->actions.add(new ChangeKeywordModeAction(*list->getKeyword(), set->game->keyword_modes[sel]->name));
}
}
BEGIN_EVENT_TABLE(KeywordsPanel, wxPanel) BEGIN_EVENT_TABLE(KeywordsPanel, wxPanel)
EVT_KEYWORD_SELECT(wxID_ANY, KeywordsPanel::onKeywordSelect) EVT_KEYWORD_SELECT(wxID_ANY, KeywordsPanel::onKeywordSelect)
EVT_CHOICE (ID_KEYWORD_MODE, KeywordsPanel::onModeChange)
END_EVENT_TABLE() END_EVENT_TABLE()
...@@ -64,6 +64,7 @@ class KeywordsPanel : public SetWindowPanel { ...@@ -64,6 +64,7 @@ class KeywordsPanel : public SetWindowPanel {
// --------------------------------------------------- : Events // --------------------------------------------------- : Events
void onKeywordSelect(KeywordSelectEvent& ev); void onKeywordSelect(KeywordSelectEvent& ev);
void onModeChange(wxCommandEvent& ev);
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -174,7 +174,7 @@ struct TextElementsFromString { ...@@ -174,7 +174,7 @@ struct TextElementsFromString {
line > 0 ? BREAK_LINE : BREAK_HARD); line > 0 ? BREAK_LINE : BREAK_HARD);
} }
if (bracket) { if (bracket) {
e->content = String(_("")) + c + _(""); e->content = String(LEFT_ANGLE_BRACKET) + c + RIGHT_ANGLE_BRACKET;
} else { } else {
e->content = c; e->content = c;
} }
......
...@@ -60,6 +60,15 @@ const Char BYTE_ORDER_MARK[] = IF_UNICODE(L"\xFEFF", "\xEF\xBB\xBF"); ...@@ -60,6 +60,15 @@ const Char BYTE_ORDER_MARK[] = IF_UNICODE(L"\xFEFF", "\xEF\xBB\xBF");
/// Writes a string to an output stream, encoded as UTF8 /// Writes a string to an output stream, encoded as UTF8
void writeUTF8(wxTextOutputStream& stream, const String& str); void writeUTF8(wxTextOutputStream& stream, const String& str);
/// Some constants we like to use
#ifdef UNICODE
#define LEFT_ANGLE_BRACKET _("\x2039")
#define RIGHT_ANGLE_BRACKET _("\x203A")
#else
#define LEFT_ANGLE_BRACKET _("<")
#define RIGHT_ANGLE_BRACKET _(">")
#endif
// ----------------------------------------------------------------------------- : Char functions // ----------------------------------------------------------------------------- : Char functions
// Character set tests // Character set tests
......
...@@ -99,17 +99,14 @@ enum ChildMenuID { ...@@ -99,17 +99,14 @@ enum ChildMenuID {
, ID_CARD_ROTATE_90 , ID_CARD_ROTATE_90
, ID_CARD_ROTATE_180 , ID_CARD_ROTATE_180
, ID_CARD_ROTATE_270 , ID_CARD_ROTATE_270
// CardList
// On cards panel , ID_SELECT_COLUMNS
, ID_COLLAPSE_NOTES
// Keyword menu // Keyword menu
, ID_KEYWORD_ADD = 1101 , ID_KEYWORD_ADD = 1101
, ID_KEYWORD_REMOVE , ID_KEYWORD_REMOVE
, ID_KEYWORD_PREV , ID_KEYWORD_PREV
, ID_KEYWORD_NEXT , ID_KEYWORD_NEXT
, ID_KEYWORD_ADD_PARAM
, ID_KEYWORD_REF_PARAM
// Format menu // Format menu
, ID_FORMAT_BOLD = 1201 , ID_FORMAT_BOLD = 1201
...@@ -150,15 +147,22 @@ enum ChildMenuID { ...@@ -150,15 +147,22 @@ enum ChildMenuID {
, ID_SHAPE_STAR , ID_SHAPE_STAR
, ID_SHAPE_MAX , ID_SHAPE_MAX
, ID_SIDES , ID_SIDES
// CardList
, ID_SELECT_COLUMNS = 3001
// Statistics // On cards panel
, ID_FIELD_LIST = 3101 , ID_COLLAPSE_NOTES = 3001
// Style panel
, ID_STYLE_USE_FOR_ALL = 3011
// Keywords panel
, ID_KEYWORD_ADD_PARAM = 3021
, ID_KEYWORD_REF_PARAM
, ID_KEYWORD_MODE
, ID_PARAM_TYPE_MIN = 3101
, ID_PARAM_TYPE_MAX = 3199
// Style // Statistics panel
, ID_STYLE_USE_FOR_ALL = 3201 , ID_FIELD_LIST = 3031
// SymbolFont (Format menu) // SymbolFont (Format menu)
, ID_INSERT_SYMBOL_MENU_MIN = 3301 , ID_INSERT_SYMBOL_MENU_MIN = 3301
......
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