From 86235dfc91e5a7c873e67d23053a8c7d041b9860 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 7 Jul 2007 00:55:27 +0000 Subject: [PATCH] Fixed undo issue for combined editor; Added keyword usage statistics git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@516 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/data/card.hpp | 4 ++++ src/data/field.cpp | 2 ++ src/data/field.hpp | 3 +++ src/data/field/text.cpp | 3 ++- src/data/field/text.hpp | 2 +- src/data/keyword.cpp | 20 ++++++++++++++++++++ src/data/keyword.hpp | 6 ++++++ src/gui/control/keyword_list.cpp | 22 ++++++++++++++++++++-- src/gui/control/keyword_list.hpp | 5 +++++ src/script/functions/basic.cpp | 2 ++ src/util/age.hpp | 2 +- 11 files changed, 66 insertions(+), 5 deletions(-) diff --git a/src/data/card.hpp b/src/data/card.hpp index 047b44f5..bce1b091 100644 --- a/src/data/card.hpp +++ b/src/data/card.hpp @@ -16,6 +16,7 @@ class Game; class Dependency; +class Keyword; DECLARE_POINTER_TYPE(Card); DECLARE_POINTER_TYPE(Field); DECLARE_POINTER_TYPE(Value); @@ -50,6 +51,9 @@ class Card : public IntrusivePtrVirtualBase { /// Styling information for a particular stylesheet IndexMap& extraDataFor(const StyleSheet& stylesheet) ; + /// Keyword usage statistics + vector > keyword_usage; + /// Get the identification of this card, an identification is something like a name, title, etc. /** May return "" */ String identification() const; diff --git a/src/data/field.cpp b/src/data/field.cpp index dd781981..c3ce31dd 100644 --- a/src/data/field.cpp +++ b/src/data/field.cpp @@ -199,6 +199,8 @@ StyleListener::~StyleListener() { // ----------------------------------------------------------------------------- : Value +IMPLEMENT_DYNAMIC_ARG(Value*, value_being_updated, nullptr); + Value::~Value() {} IMPLEMENT_REFLECTION_NAMELESS(Value) { diff --git a/src/data/field.hpp b/src/data/field.hpp index 5f26f68b..def5abcd 100644 --- a/src/data/field.hpp +++ b/src/data/field.hpp @@ -29,6 +29,9 @@ class DataViewer; class DataEditor; DECLARE_POINTER_TYPE(ValueViewer); DECLARE_POINTER_TYPE(ValueEditor); +// Value for which script updates are being run +DECLARE_DYNAMIC_ARG(Value*, value_being_updated); + // ----------------------------------------------------------------------------- : Field /// Information on how to store a value diff --git a/src/data/field/text.cpp b/src/data/field/text.cpp index 42fc7cbd..5d97f444 100644 --- a/src/data/field/text.cpp +++ b/src/data/field/text.cpp @@ -119,7 +119,8 @@ String TextValue::toString() const { } bool TextValue::update(Context& ctx) { Value::update(ctx); - WITH_DYNAMIC_ARG(last_update_age, value.isDefault() ? 0 : last_update.get()); + WITH_DYNAMIC_ARG(last_update_age, last_update.get()); + WITH_DYNAMIC_ARG(value_being_updated, this); bool change = field().default_script.invokeOnDefault(ctx, value) | field(). script.invokeOn(ctx, value); if (change) last_update.update(); diff --git a/src/data/field/text.hpp b/src/data/field/text.hpp index c6e6e601..6d46b747 100644 --- a/src/data/field/text.hpp +++ b/src/data/field/text.hpp @@ -92,7 +92,7 @@ class TextStyle : public Style { /// The Value in a TextField class TextValue : public Value { public: - inline TextValue(const TextFieldP& field) : Value(field) {} + inline TextValue(const TextFieldP& field) : Value(field), last_update(1) {} DECLARE_HAS_FIELD(Text) typedef Defaultable ValueType; diff --git a/src/data/keyword.cpp b/src/data/keyword.cpp index c077dab7..ca25a9e2 100644 --- a/src/data/keyword.cpp +++ b/src/data/keyword.cpp @@ -17,6 +17,8 @@ DECLARE_TYPEOF_COLLECTION(KeywordModeP); DECLARE_TYPEOF_COLLECTION(KeywordParamP); DECLARE_TYPEOF_COLLECTION(const Keyword*); DECLARE_POINTER_TYPE(KeywordParamValue); +class Value; +DECLARE_DYNAMIC_ARG(Value*, value_being_updated); // ----------------------------------------------------------------------------- : Reflection @@ -329,6 +331,8 @@ KeywordTrie* KeywordTrie::insertAnyStar() { // ----------------------------------------------------------------------------- : KeywordDatabase +IMPLEMENT_DYNAMIC_ARG(KeywordUsageStatistics*, keyword_usage_statistics, nullptr); + KeywordDatabase::KeywordDatabase() : root(nullptr) {} @@ -440,6 +444,17 @@ String KeywordDatabase::expand(const String& text, Context& ctx) const { assert(combine_script); + // Clean up usage statistics + KeywordUsageStatistics* stat = keyword_usage_statistics(); + Value* stat_key = value_being_updated(); + if (stat && stat_key) { + for (size_t i = stat->size() - 1 ; i + 1 > 0 ; --i) { // loop backwards + if ((*stat)[i].first == stat_key) { + stat->erase(stat->begin() + i); + } + } + } + // Remove all old reminder texts String s = remove_tag_contents(text, _(""); } + // Add to usage statistics + if (stat && stat_key) { + stat->push_back(make_pair(stat_key, kw)); + } + // After keyword s = s.substr(end); untagged = untagged.substr(start_u + len_u); diff --git a/src/data/keyword.hpp b/src/data/keyword.hpp index 9a5ee689..1efd3d0b 100644 --- a/src/data/keyword.hpp +++ b/src/data/keyword.hpp @@ -11,6 +11,7 @@ #include #include