Commit eb29499a authored by twanvl's avatar twanvl

Working on the keywords panel;

Correct styling data now shown on style panel
parent 66275038
...@@ -160,7 +160,7 @@ void KeywordReminderTextValue::highlight(const String& code) { ...@@ -160,7 +160,7 @@ void KeywordReminderTextValue::highlight(const String& code) {
size_t end = code.find_first_not_of(_("0123456789"), pos + 5); size_t end = code.find_first_not_of(_("0123456789"), pos + 5);
if (end == String::npos) end = code.size(); if (end == String::npos) end = code.size();
String param = code.substr(pos, end-pos); String param = code.substr(pos, end-pos);
new_value += _("<") + param + _(">") + param + _("</") + param + _(">"); new_value += _("<ref-") + param + _(">") + param + _("</ref-") + param + _(">");
pos = end; pos = end;
} else { } else {
new_value += c; new_value += c;
......
...@@ -115,20 +115,24 @@ FakeTextValue::FakeTextValue(const TextFieldP& field, String* underlying, bool e ...@@ -115,20 +115,24 @@ FakeTextValue::FakeTextValue(const TextFieldP& field, String* underlying, bool e
{} {}
void FakeTextValue::store() { void FakeTextValue::store() {
if (editable) { if (underlying) {
*underlying = untagged ? untag(value) : value; if (editable) {
} else { *underlying = untagged ? untag(value) : value;
retrieve(); } else {
retrieve();
}
} }
} }
void FakeTextValue::retrieve() { void FakeTextValue::retrieve() {
value.assign(untagged ? escape(*underlying) : *underlying); if (underlying) {
value.assign(untagged ? escape(*underlying) : *underlying);
} else {
value.assign(wxEmptyString);
}
} }
void FakeTextValue::onAction(Action& a, bool undone) { void FakeTextValue::onAction(Action& a, bool undone) {
if (underlying) { store();
store();
}
} }
bool FakeTextValue::equals(const Value* that) { bool FakeTextValue::equals(const Value* that) {
......
...@@ -52,7 +52,7 @@ void read_compat(Reader& tag, Keyword* k) { ...@@ -52,7 +52,7 @@ void read_compat(Reader& tag, Keyword* k) {
k->match += separator.substr(start + 1, end - start - 1); k->match += separator.substr(start + 1, end - start - 1);
} }
if (!parameter.empty()) { if (!parameter.empty()) {
k->match += _("<param>") + parameter + _("</param>"); k->match += _("<atom-param>") + parameter + _("</atom-param>");
} }
} }
...@@ -120,7 +120,7 @@ void Keyword::prepare(const vector<KeywordParamP>& param_types, bool force) { ...@@ -120,7 +120,7 @@ void Keyword::prepare(const vector<KeywordParamP>& param_types, bool force) {
// Parse the 'match' string // Parse the 'match' string
for (size_t i = 0 ; i < match.size() ;) { for (size_t i = 0 ; i < match.size() ;) {
Char c = match.GetChar(i); Char c = match.GetChar(i);
if (is_substr(match, i, _("<param"))) { if (is_substr(match, i, _("<atom-param"))) {
// parameter, determine type... // parameter, determine type...
size_t start = skip_tag(match, i), end = match_close_tag(match, i); size_t start = skip_tag(match, i), end = match_close_tag(match, i);
String type = match.substr(start, end-start); String type = match.substr(start, end-start);
...@@ -237,7 +237,7 @@ void KeywordDatabase::add(const Keyword& kw) { ...@@ -237,7 +237,7 @@ void KeywordDatabase::add(const Keyword& kw) {
KeywordTrie* cur = root->insertAnyStar(); KeywordTrie* cur = root->insertAnyStar();
for (size_t i = 0 ; i < kw.match.size() ;) { for (size_t i = 0 ; i < kw.match.size() ;) {
Char c = kw.match.GetChar(i); Char c = kw.match.GetChar(i);
if (is_substr(kw.match, i, _("<param"))) { if (is_substr(kw.match, i, _("<atom-param"))) {
// tag, parameter, match anything // tag, parameter, match anything
cur = cur->insertAnyStar(); cur = cur->insertAnyStar();
i = match_close_tag_end(kw.match, i); i = match_close_tag_end(kw.match, i);
......
...@@ -58,7 +58,7 @@ class Keyword { ...@@ -58,7 +58,7 @@ class Keyword {
String keyword; ///< The keyword, only for human use String keyword; ///< The keyword, only for human use
String rules; ///< Rules/explanation String rules; ///< Rules/explanation
String match; ///< String to match, <param> tags are used for parameters String match; ///< String to match, <atom-param> tags are used for parameters
vector<KeywordParamP> parameters; ///< The types of parameters vector<KeywordParamP> parameters; ///< The types of parameters
StringScript reminder; ///< Reminder text of the keyword StringScript reminder; ///< Reminder text of the keyword
String mode; ///< Mode of use, can be used by scripts (only gives the name) String mode; ///< Mode of use, can be used by scripts (only gives the name)
......
...@@ -99,8 +99,8 @@ void KeywordList::onAction(const Action& action, bool undone) { ...@@ -99,8 +99,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,
_("<param>"), _("")), _("<atom-param>"), _("")),
_("</param>"), _("")) _("</atom-param>"), _(""))
); );
} }
......
...@@ -91,6 +91,7 @@ void NativeLookEditor::resizeViewers() { ...@@ -91,6 +91,7 @@ void NativeLookEditor::resizeViewers() {
} }
void NativeLookEditor::onInit() { void NativeLookEditor::onInit() {
DataEditor::onInit();
// Give viewers a chance to show/hide controls (scrollbar) when selecting other editors // Give viewers a chance to show/hide controls (scrollbar) when selecting other editors
FOR_EACH_EDITOR { FOR_EACH_EDITOR {
e->onShow(true); e->onShow(true);
...@@ -191,7 +192,6 @@ StylingEditor::StylingEditor(Window* parent, int id, long style) ...@@ -191,7 +192,6 @@ StylingEditor::StylingEditor(Window* parent, int id, long style)
{} {}
void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) { void StylingEditor::showStylesheet(const StyleSheetP& stylesheet) {
this->stylesheet = stylesheet;
setStyles(set->stylesheet, stylesheet->styling_style); setStyles(set->stylesheet, stylesheet->styling_style);
setData(set->stylingDataFor(*stylesheet)); setData(set->stylingDataFor(*stylesheet));
} }
......
...@@ -72,8 +72,6 @@ class StylingEditor : public NativeLookEditor { ...@@ -72,8 +72,6 @@ class StylingEditor : public NativeLookEditor {
protected: protected:
virtual void onChangeSet(); virtual void onChangeSet();
private:
StyleSheetP stylesheet; ///< The stylesheet for which we are showing the styling data
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -12,12 +12,15 @@ ...@@ -12,12 +12,15 @@
#include <gui/icon_menu.hpp> #include <gui/icon_menu.hpp>
#include <gui/util.hpp> #include <gui/util.hpp>
#include <data/keyword.hpp> #include <data/keyword.hpp>
#include <data/game.hpp>
#include <data/action/value.hpp> #include <data/action/value.hpp>
#include <data/action/keyword.hpp> #include <data/action/keyword.hpp>
#include <data/field/text.hpp> #include <data/field/text.hpp>
#include <util/window_id.hpp> #include <util/window_id.hpp>
#include <wx/listctrl.h> #include <wx/listctrl.h>
#include <wx/splitter.h> #include <wx/splitter.h>
#include <wx/statline.h>
#include <wx/artprov.h>
// ----------------------------------------------------------------------------- : KeywordsPanel // ----------------------------------------------------------------------------- : KeywordsPanel
...@@ -32,25 +35,42 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id) ...@@ -32,25 +35,42 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
match = new TextCtrl(panel, wxID_ANY, false); match = new TextCtrl(panel, wxID_ANY, false);
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);
fixed = new wxStaticText(panel, wxID_ANY, _("This is a standard $game keyword, you can not edit it. ")
_("If you make a copy of the keyword your copy will take precedent."));
errors = new wxStaticText(panel, wxID_ANY, _("")); errors = new wxStaticText(panel, wxID_ANY, _(""));
// warning about fixed keywords
fixedL = new wxStaticText(panel, wxID_ANY, _(""));
wxStaticBitmap* fixedI = new wxStaticBitmap(panel, wxID_ANY, wxArtProvider::GetBitmap(wxART_WARNING));
fixed = new wxBoxSizer(wxVERTICAL);
wxSizer* s0 = new wxBoxSizer(wxHORIZONTAL);
s0->Add(fixedI, 0, wxALIGN_CENTER | wxRIGHT, 10);
s0->Add(fixedL, 0, wxALIGN_CENTER_VERTICAL);
fixed->Add(new wxStaticLine(panel), 0, wxEXPAND | wxBOTTOM, 8);
fixed->Add(s0, 0, wxALL & ~wxTOP | wxALIGN_CENTER, 8);
fixed->Add(new wxStaticLine(panel), 0, wxEXPAND | wxBOTTOM, 8);
// init sizer for panel // init sizer for panel
sp = new wxBoxSizer(wxVERTICAL); sp = new wxBoxSizer(wxVERTICAL);
sp->Add(fixed, 0, wxALL, 6); sp->Add(fixed, 0, wxEXPAND); sp->Show(fixed,false);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Keyword:")), 0, wxALL, 6); wxSizer* s1 = new wxBoxSizer(wxVERTICAL);
sp->Add(keyword, 0, wxEXPAND | wxALL & ~wxTOP, 6); s1->Add(new wxStaticText(panel, wxID_ANY, _("Keyword:")), 0);
wxSizer* s2 = new wxStaticBoxSizer(wxVERTICAL, panel, _("Match")); s1->Add(keyword, 0, wxEXPAND | wxTOP, 2);
s2->Add(new wxStaticText(panel, wxID_ANY, _("Keyword format:")), 0, wxALL, 6); sp->Add(s1, 0, wxEXPAND | wxLEFT, 2);
s2->Add(match, 0, wxEXPAND | wxALL & ~wxTOP, 6); sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
s2->Add(new wxStaticText(panel, wxID_ANY, _("Parameters:")), 0, wxALL, 6); wxSizer* s2 = new wxBoxSizer(wxVERTICAL);
sp->Add(s2, 0, wxEXPAND | wxALL, 6); s2->Add(new wxStaticText(panel, wxID_ANY, _("Match:")), 0);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Reminder:")), 0, wxALL, 6); s2->Add(match, 0, wxEXPAND | wxTOP, 2);
sp->Add(reminder, 1, wxEXPAND | wxALL & ~wxTOP, 6); s2->Add(new wxStaticText(panel, wxID_ANY, _("Parameters:")), 0, wxTOP, 6);
sp->Add(errors, 0, wxALL & ~wxTOP, 6); sp->Add(s2, 0, wxEXPAND | wxLEFT, 2);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Example:")), 0, wxALL, 6); sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
sp->Add(new wxStaticText(panel, wxID_ANY, _("Rules:")), 0, wxALL, 6); wxSizer* s3 = new wxBoxSizer(wxVERTICAL);
sp->Add(rules, 1, wxEXPAND | wxALL & ~wxTOP, 6); s3->Add(new wxStaticText(panel, wxID_ANY, _("Reminder:")), 0);
s3->Add(reminder, 1, wxEXPAND | wxTOP, 2);
s3->Add(errors, 0, wxEXPAND | wxTOP, 4);
s3->Add(new wxStaticText(panel, wxID_ANY, _("Example:")), 0, wxTOP, 6);
sp->Add(s3, 1, wxEXPAND | wxLEFT, 2);
sp->Add(new wxStaticLine(panel), 0, wxEXPAND | wxTOP | wxBOTTOM, 8);
wxSizer* s4 = new wxBoxSizer(wxVERTICAL);
s4->Add(new wxStaticText(panel, wxID_ANY, _("Rules:")), 0);
s4->Add(rules, 1, wxEXPAND | wxTOP, 2);
sp->Add(s4, 1, wxEXPAND | wxLEFT, 2);
panel->SetSizer(sp); panel->SetSizer(sp);
// init splitter // init splitter
splitter->SetMinimumPaneSize(100); splitter->SetMinimumPaneSize(100);
...@@ -135,6 +155,8 @@ void KeywordsPanel::onCommand(int id) { ...@@ -135,6 +155,8 @@ void KeywordsPanel::onCommand(int id) {
void KeywordsPanel::onChangeSet() { void KeywordsPanel::onChangeSet() {
list->setSet(set); list->setSet(set);
// warning label (depends on game name)
fixedL->SetLabel(format_string(_LABEL_("standard keyword"), set->game->short_name));
// init text controls // init text controls
keyword ->setSet(set); keyword ->setSet(set);
keyword ->getStyle().font.size = 16; keyword ->getStyle().font.size = 16;
...@@ -169,17 +191,14 @@ void KeywordsPanel::onAction(const Action& action, bool undone) { ...@@ -169,17 +191,14 @@ void KeywordsPanel::onAction(const Action& action, bool undone) {
void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) { void KeywordsPanel::onKeywordSelect(KeywordSelectEvent& ev) {
if (ev.keyword) { if (ev.keyword) {
Keyword& kw = *ev.keyword; Keyword& kw = *ev.keyword;
//sp->Show(fixed, kw.fixed); sp->Show(fixed, kw.fixed);
fixed->SetLabel(kw.fixed ? _("This is a standard $game keyword, you can not edit it. ")
_("If you make a copy of the keyword your copy will take precedent.")
: _(""));
Layout();
keyword ->setValue(new_shared5<KeywordTextValue> (keyword->getFieldP(), &kw, &kw.keyword, !kw.fixed, true)); keyword ->setValue(new_shared5<KeywordTextValue> (keyword->getFieldP(), &kw, &kw.keyword, !kw.fixed, true));
match ->setValue(new_shared4<KeywordTextValue> (match->getFieldP(), &kw, &kw.match, !kw.fixed)); match ->setValue(new_shared4<KeywordTextValue> (match->getFieldP(), &kw, &kw.match, !kw.fixed));
rules ->setValue(new_shared4<KeywordTextValue> (rules->getFieldP(), &kw, &kw.rules, !kw.fixed)); rules ->setValue(new_shared4<KeywordTextValue> (rules->getFieldP(), &kw, &kw.rules, !kw.fixed));
shared_ptr<KeywordReminderTextValue> reminder_value(new KeywordReminderTextValue(reminder->getFieldP(), &kw, !kw.fixed)); shared_ptr<KeywordReminderTextValue> reminder_value(new KeywordReminderTextValue(reminder->getFieldP(), &kw, !kw.fixed));
reminder->setValue(reminder_value); reminder->setValue(reminder_value);
errors->SetLabel(reminder_value->errors); errors->SetLabel(reminder_value->errors);
sp->Layout();
} else { } else {
keyword ->setValue(nullptr); keyword ->setValue(nullptr);
match ->setValue(nullptr); match ->setValue(nullptr);
......
...@@ -49,8 +49,16 @@ class KeywordsPanel : public SetWindowPanel { ...@@ -49,8 +49,16 @@ class KeywordsPanel : public SetWindowPanel {
TextCtrl* reminder; TextCtrl* reminder;
TextCtrl* rules; TextCtrl* rules;
IconMenu* menuKeyword; IconMenu* menuKeyword;
wxStaticText* fixed; wxStaticText* fixedL;
wxSizer* fixed;
wxStaticText* errors; wxStaticText* errors;
/// Controls to edit a parameter
struct ParamEditor {
wxStaticText* label;
wxChoice* type;
bool shown;
};
vector<ParamEditor> params;
// --------------------------------------------------- : Events // --------------------------------------------------- : Events
void onKeywordSelect(KeywordSelectEvent& ev); void onKeywordSelect(KeywordSelectEvent& ev);
......
...@@ -53,10 +53,12 @@ void StylePanel::onChangeSet() { ...@@ -53,10 +53,12 @@ void StylePanel::onChangeSet() {
void StylePanel::onAction(const Action& action, bool undone) { void StylePanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, ChangeSetStyleAction) { TYPE_CASE_(action, ChangeSetStyleAction) {
list->select(set->stylesheetFor(card)->name(), false); list->select(set->stylesheetFor(card)->name(), false);
editor->showStylesheet(set->stylesheetFor(card));
} }
TYPE_CASE(action, ChangeCardStyleAction) { TYPE_CASE(action, ChangeCardStyleAction) {
if (action.card == card) { if (action.card == card) {
list->select(set->stylesheetFor(card)->name(), false); list->select(set->stylesheetFor(card)->name(), false);
editor->showStylesheet(set->stylesheetFor(card));
} }
} }
use_for_all->Enable(card && card->stylesheet); use_for_all->Enable(card && card->stylesheet);
...@@ -67,6 +69,7 @@ void StylePanel::onAction(const Action& action, bool undone) { ...@@ -67,6 +69,7 @@ void StylePanel::onAction(const Action& action, bool undone) {
void StylePanel::selectCard(const CardP& card) { void StylePanel::selectCard(const CardP& card) {
this->card = card; this->card = card;
preview->setCard(card); preview->setCard(card);
editor->showStylesheet(set->stylesheetFor(card));
list->select(set->stylesheetFor(card)->name(), false); list->select(set->stylesheetFor(card)->name(), false);
use_for_all->Enable(card && card->stylesheet); use_for_all->Enable(card && card->stylesheet);
} }
......
...@@ -57,7 +57,7 @@ double TextElements::scaleStep() const { ...@@ -57,7 +57,7 @@ double TextElements::scaleStep() const {
return m; return m;
} }
// Colors for <param> tags // Colors for <atom-param> tags
Color param_colors[] = Color param_colors[] =
{ Color(0,170,0) { Color(0,170,0)
, Color(0,0,200) , Color(0,0,200)
...@@ -109,19 +109,19 @@ struct TextElementsFromString { ...@@ -109,19 +109,19 @@ struct TextElementsFromString {
else if (is_substr(text, tag_start, _("</code"))) code -= 1; else if (is_substr(text, tag_start, _("</code"))) code -= 1;
else if (is_substr(text, tag_start, _( "<ref-param"))) { else if (is_substr(text, tag_start, _( "<ref-param"))) {
// determine the param being referenced // determine the param being referenced
// from a tag <param123> // from a tag <ref-param123>
if (pos != String::npos) { if (pos != String::npos) {
String ref = text.substr(tag_start + 6, pos - tag_start - 7); String ref = text.substr(tag_start + 10, pos - tag_start - 11);
long ref_n; long ref_n;
if (ref.ToLong(&ref_n)) { if (ref.ToLong(&ref_n)) {
param_id = ref_n; param_id = (ref_n - 1)%param_colors_count + param_colors_count;
} }
} }
param_ref += 1; param_ref += 1;
} }
else if (is_substr(text, tag_start, _("</ref-param"))) param_ref -= 1; else if (is_substr(text, tag_start, _("</ref-param"))) param_ref -= 1;
else if (is_substr(text, tag_start, _( "<param"))) param += 1; else if (is_substr(text, tag_start, _( "<atom-param"))) param += 1;
else if (is_substr(text, tag_start, _("</param"))) param -= 1; else if (is_substr(text, tag_start, _("</atom-param"))) param -= 1;
else if (is_substr(text, tag_start, _( "<line"))) line += 1; else if (is_substr(text, tag_start, _( "<line"))) line += 1;
else if (is_substr(text, tag_start, _("</line"))) line -= 1; else if (is_substr(text, tag_start, _("</line"))) line -= 1;
else if (is_substr(text, tag_start, _("<atom"))) { else if (is_substr(text, tag_start, _("<atom"))) {
......
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