Editing of keywords

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@255 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-04-13 23:59:42 +00:00
parent 1be1304c94
commit 7b45f6f69e
15 changed files with 326 additions and 79 deletions
+48 -5
View File
@@ -10,6 +10,8 @@
#include <data/set.hpp>
#include <data/game.hpp>
#include <data/keyword.hpp>
#include <data/action/value.hpp>
#include <data/action/keyword.hpp>
#include <util/tagged_string.hpp>
#include <gfx/gfx.hpp>
@@ -47,8 +49,49 @@ void KeywordList::onChangeSet() {
}
void KeywordList::onAction(const Action& action, bool undone) {
//TYPE_CASE(action, AddKeywordAction) {
//}
TYPE_CASE(action, AddKeywordAction) {
if (undone) {
long pos = selected_item_pos;
refreshList();
if (action.keyword == selected_item) {
// select the next keyword, if not possible, select the last
if (pos + 1 < GetItemCount()) {
selectItemPos(pos, true);
} else {
selectItemPos(GetItemCount() - 1, true);
}
}
} else {
// select the new keyword
selectItem(action.keyword, false /*list will be refreshed anyway*/, true);
refreshList();
}
}
TYPE_CASE(action, RemoveKeywordAction) {
if (undone) {
// select the re-added keyword
selectItem(action.keyword, false /*list will be refreshed anyway*/, true);
refreshList();
} else {
long pos = selected_item_pos;
refreshList();
if (action.keyword == selected_item) {
// select the next keyword, if not possible, select the last
if (pos + 1 < GetItemCount()) {
selectItemPos(pos, true);
} else {
selectItemPos(GetItemCount() - 1, true);
}
}
}
}
TYPE_CASE(action, ValueAction) {
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
if (value) {
// this is indeed an action on a keyword, refresh
refreshList();
}
}
}
// ----------------------------------------------------------------------------- : KeywordListBase : for ItemList
@@ -83,8 +126,8 @@ bool KeywordList::compareItems(void* a, void* b) const {
case 1: return ka.match < kb.match;
case 2: return ka.mode < kb.mode;
//case 3:
//case 4:
default: // TODO: 3 and 4
case 4: return ka.reminder.getUnparsed() < kb.reminder.getUnparsed();
default: // TODO: 3
return ka.keyword < kb.keyword;
}
}
@@ -98,7 +141,7 @@ String KeywordList::OnGetItemText (long pos, long col) const {
case 1: return match_string(kw);
case 2: return kw.mode;
case 3: return _("TODO");
case 4: return _("TODO");
case 4: return kw.reminder.getUnparsed();
default: return wxEmptyString;
}
}
+11 -28
View File
@@ -40,6 +40,10 @@ TextField& TextCtrl::getField() {
assert(!viewers.empty());
return static_cast<TextField&>(*viewers.front()->getField());
}
TextFieldP TextCtrl::getFieldP() {
assert(!viewers.empty());
return static_pointer_cast<TextField>(viewers.front()->getField());
}
void TextCtrl::updateSize() {
wxSize cs = GetClientSize();
Style& style = getStyle();
@@ -49,36 +53,15 @@ void TextCtrl::updateSize() {
}
void TextCtrl::setValue(String* value, bool untagged) {
if (value != this->value) {
this->value = value;
// create a new value, for a different underlying actual value
ValueViewer& viewer = *viewers.front();
TextValueP new_value(new FakeTextValue(static_pointer_cast<TextField>(viewer.getField()), this->value, untagged));
viewer.setValue(new_value);
updateSize();
valueChanged();
}
setValue(new_shared4<FakeTextValue>(getFieldP(), value, true, untagged));
}
void TextCtrl::valueChanged() {
if (!viewers.empty()) {
TextValue& tv = static_cast<TextValue&>(*viewers.front()->getValue());
tv.value.assign(value ? String(*value) : String(wxEmptyString));
viewers.front()->onValueChange();
}
void TextCtrl::setValue(const FakeTextValueP& value) {
value->retrieve();
viewers.front()->setValue(value);
updateSize();
onChange();
}
void TextCtrl::onAction(const Action& action, bool undone) {
DataEditor::onAction(action, undone);
/*
TYPE_CASE(action, TextValueAction) {
FakeTextValue& tv = static_cast<FakeTextValue&>(*viewers.front()->getValue());
if (tv.equals(action.valueP.get())) {
// the value has changed
if (value) *value = tv.value();
}
}
*/
}
void TextCtrl::onChangeSet() {
DataEditor::onChangeSet();
// initialize
@@ -86,7 +69,7 @@ void TextCtrl::onChangeSet() {
// create a field, style and value
TextFieldP field(new TextField);
TextStyleP style(new TextStyle(field));
TextValueP value(new FakeTextValue(field, nullptr, false));
TextValueP value(new FakeTextValue(field, nullptr, false, false));
// set stuff
field->index = 0;
field->multi_line = multi_line;
+10 -7
View File
@@ -12,8 +12,9 @@
#include <util/prec.hpp>
#include <gui/control/card_editor.hpp>
class TextField;
class TextStyle;
DECLARE_POINTER_TYPE(TextField);
DECLARE_POINTER_TYPE(FakeTextValue);
// ----------------------------------------------------------------------------- : TextCtrl
@@ -31,16 +32,20 @@ class TextCtrl : public DataEditor {
TextCtrl(Window* parent, int id, bool multi_line, long style = 0);
/// Set the value that is being edited
/** value can be a nullptr*/
void setValue(String* value, bool untagged = false);
/// Notification that the value has changed outside this control
void valueChanged();
/// Set the value that is being edited
void setValue(const FakeTextValueP& value);
/// Update the size, for example after changing the style
void updateSize();
/// Get access to the field used by the control
TextField& getField();
/// Get access to the field used by the control
TextFieldP getFieldP();
/// Get access to the style used by the control
TextStyle& getStyle();
/// Update the size, for example after changing the style
void updateSize();
/// Uses a native look
virtual bool nativeLook() const { return true; }
@@ -49,8 +54,6 @@ class TextCtrl : public DataEditor {
virtual void draw(DC& dc);
/// When an action is received, change the underlying value
virtual void onAction(const Action&, bool undone);
virtual void onChangeSet();
protected: