mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
split ItemList from CardList, this class can also be used to list keywords
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@229 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+29
-47
@@ -14,8 +14,7 @@ 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(KeywordParamP);
|
DECLARE_TYPEOF_COLLECTION(KeywordParamP);
|
||||||
DECLARE_TYPEOF_COLLECTION(KeywordExpansionP);
|
DECLARE_TYPEOF_COLLECTION(const Keyword*);
|
||||||
DECLARE_TYPEOF_COLLECTION(const KeywordExpansion*);
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Reflection
|
// ----------------------------------------------------------------------------- : Reflection
|
||||||
|
|
||||||
@@ -29,41 +28,33 @@ IMPLEMENT_REFLECTION(KeywordMode) {
|
|||||||
REFLECT(name);
|
REFLECT(name);
|
||||||
REFLECT(description);
|
REFLECT(description);
|
||||||
}
|
}
|
||||||
IMPLEMENT_REFLECTION(KeywordExpansion) {
|
|
||||||
REFLECT(match);
|
|
||||||
REFLECT(reminder);
|
|
||||||
}
|
|
||||||
|
|
||||||
// backwards compatability
|
// backwards compatability
|
||||||
template <typename T> void read_compat(T&, const Keyword*) {}
|
template <typename T> void read_compat(T&, const Keyword*) {}
|
||||||
void read_compat(Reader& tag, Keyword* k) {
|
void read_compat(Reader& tag, Keyword* k) {
|
||||||
String separator, parameter, reminder;
|
if (!k->match.empty()) return;
|
||||||
|
String separator, parameter;
|
||||||
REFLECT(separator);
|
REFLECT(separator);
|
||||||
REFLECT(parameter);
|
REFLECT(parameter);
|
||||||
REFLECT(reminder);
|
// create a match string from the keyword
|
||||||
if (!separator.empty() || !parameter.empty() || !reminder.empty()) {
|
k->match = k->keyword;
|
||||||
// old style keyword declaration, no separate expansion
|
size_t start = separator.find_first_of('[');
|
||||||
KeywordExpansionP e(new KeywordExpansion);
|
size_t end = separator.find_first_of(']');
|
||||||
e->match = k->keyword;
|
if (start != String::npos && end != String::npos) {
|
||||||
size_t start = separator.find_first_of('[');
|
k->match += separator.substr(start + 1, end - start - 1);
|
||||||
size_t end = separator.find_first_of(']');
|
}
|
||||||
if (start != String::npos && end != String::npos) {
|
if (!parameter.empty()) {
|
||||||
e->match += separator.substr(start + 1, end - start - 1);
|
k->match += _("<param>") + parameter + _("</param>");
|
||||||
}
|
|
||||||
if (!parameter.empty()) {
|
|
||||||
e->match += _("<param>") + parameter + _("</param>");
|
|
||||||
}
|
|
||||||
e->reminder.set(reminder);
|
|
||||||
k->expansions.push_back(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPLEMENT_REFLECTION(Keyword) {
|
IMPLEMENT_REFLECTION(Keyword) {
|
||||||
REFLECT(keyword);
|
REFLECT(keyword);
|
||||||
read_compat(tag, this);
|
read_compat(tag, this);
|
||||||
REFLECT(expansions);
|
REFLECT(match);
|
||||||
|
REFLECT(reminder);
|
||||||
REFLECT(rules);
|
REFLECT(rules);
|
||||||
// REFLECT(mode);
|
REFLECT(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +103,7 @@ String regex_escape(Char c) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeywordExpansion::prepare(const vector<KeywordParamP>& param_types, bool force) {
|
void Keyword::prepare(const vector<KeywordParamP>& param_types, bool force) {
|
||||||
if (!force && matchRe.IsValid()) return;
|
if (!force && matchRe.IsValid()) return;
|
||||||
parameters.clear();
|
parameters.clear();
|
||||||
// Prepare regex
|
// Prepare regex
|
||||||
@@ -159,9 +150,9 @@ class KeywordTrie {
|
|||||||
KeywordTrie();
|
KeywordTrie();
|
||||||
~KeywordTrie();
|
~KeywordTrie();
|
||||||
|
|
||||||
map<Char, KeywordTrie*> children; ///< children after a given character (owned)
|
map<Char, KeywordTrie*> children; ///< children after a given character (owned)
|
||||||
KeywordTrie* on_any_star; ///< children on /.*/ (owned or this)
|
KeywordTrie* on_any_star; ///< children on /.*/ (owned or this)
|
||||||
vector<const KeywordExpansion*> finished; ///< keywords expansions that end in this node
|
vector<const Keyword*> finished; ///< keywordss that end in this node
|
||||||
|
|
||||||
/// Insert nodes representing the given character
|
/// Insert nodes representing the given character
|
||||||
/** return the node where the evaluation will be after matching the character */
|
/** return the node where the evaluation will be after matching the character */
|
||||||
@@ -228,41 +219,32 @@ void KeywordDatabase::add(const vector<KeywordP>& kws) {
|
|||||||
add(*kw);
|
add(*kw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void KeywordDatabase::add(const Keyword& kw) {
|
|
||||||
FOR_EACH_CONST(e, kw.expansions) {
|
|
||||||
add(*e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void KeywordDatabase::add(const KeywordExpansion& e) {
|
void KeywordDatabase::add(const Keyword& kw) {
|
||||||
|
if (kw.match.empty()) return; // can't handle empty keywords
|
||||||
if (!root) {
|
if (!root) {
|
||||||
root = new KeywordTrie;
|
root = new KeywordTrie;
|
||||||
root->on_any_star = root;
|
root->on_any_star = root;
|
||||||
}
|
}
|
||||||
KeywordTrie* cur = root->insertAnyStar();
|
KeywordTrie* cur = root->insertAnyStar();
|
||||||
for (size_t i = 0 ; i < e.match.size() ;) {
|
for (size_t i = 0 ; i < kw.match.size() ;) {
|
||||||
Char c = e.match.GetChar(i);
|
Char c = kw.match.GetChar(i);
|
||||||
if (is_substr(e.match, i, _("<param"))) {
|
if (is_substr(kw.match, i, _("<param"))) {
|
||||||
// tag, parameter, match anything
|
// tag, parameter, match anything
|
||||||
cur = cur->insertAnyStar();
|
cur = cur->insertAnyStar();
|
||||||
i = match_close_tag_end(e.match, i);
|
i = match_close_tag_end(kw.match, i);
|
||||||
} else {
|
} else {
|
||||||
cur = cur->insert(c);
|
cur = cur->insert(c);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// now cur is the trie after matching the keyword anywhere in the input text
|
// now cur is the trie after matching the keyword anywhere in the input text
|
||||||
cur->finished.push_back(&e);
|
cur->finished.push_back(&kw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeywordDatabase::prepare_parameters(const vector<KeywordParamP>& ps, const vector<KeywordP>& kws) {
|
void KeywordDatabase::prepare_parameters(const vector<KeywordParamP>& ps, const vector<KeywordP>& kws) {
|
||||||
FOR_EACH_CONST(kw, kws) {
|
FOR_EACH_CONST(kw, kws) {
|
||||||
prepare_parameters(ps, *kw);
|
kw->prepare(ps);
|
||||||
}
|
|
||||||
}
|
|
||||||
void KeywordDatabase::prepare_parameters(const vector<KeywordParamP>& ps, const Keyword& kw) {
|
|
||||||
FOR_EACH_CONST(e, kw.expansions) {
|
|
||||||
e->prepare(ps);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,7 +293,7 @@ String KeywordDatabase::expand(const String& text,
|
|||||||
while (!s.empty()) {
|
while (!s.empty()) {
|
||||||
vector<KeywordTrie*> current; // current location(s) in the trie
|
vector<KeywordTrie*> current; // current location(s) in the trie
|
||||||
vector<KeywordTrie*> next; // location(s) after this step
|
vector<KeywordTrie*> next; // location(s) after this step
|
||||||
set<const KeywordExpansion*> used; // keywords already investigated
|
set<const Keyword*> used; // keywords already investigated
|
||||||
current.push_back(root);
|
current.push_back(root);
|
||||||
closure(current);
|
closure(current);
|
||||||
char expand_type = 'a'; // is the keyword expanded? From <kw-?> tag
|
char expand_type = 'a'; // is the keyword expanded? From <kw-?> tag
|
||||||
@@ -355,7 +337,7 @@ String KeywordDatabase::expand(const String& text,
|
|||||||
// are we done?
|
// are we done?
|
||||||
FOR_EACH(n, current) {
|
FOR_EACH(n, current) {
|
||||||
FOR_EACH(f, n->finished) {
|
FOR_EACH(f, n->finished) {
|
||||||
const KeywordExpansion* kw = f;
|
const Keyword* kw = f;
|
||||||
if (used.insert(kw).second) {
|
if (used.insert(kw).second) {
|
||||||
// we have found a possible match, which we have not seen before
|
// we have found a possible match, which we have not seen before
|
||||||
assert(kw->matchRe.IsValid());
|
assert(kw->matchRe.IsValid());
|
||||||
|
|||||||
+4
-20
@@ -14,7 +14,6 @@
|
|||||||
#include <wx/regex.h>
|
#include <wx/regex.h>
|
||||||
|
|
||||||
DECLARE_POINTER_TYPE(KeywordParam);
|
DECLARE_POINTER_TYPE(KeywordParam);
|
||||||
DECLARE_POINTER_TYPE(KeywordExpansion);
|
|
||||||
DECLARE_POINTER_TYPE(KeywordMode);
|
DECLARE_POINTER_TYPE(KeywordMode);
|
||||||
DECLARE_POINTER_TYPE(Keyword);
|
DECLARE_POINTER_TYPE(Keyword);
|
||||||
class KeywordTrie;
|
class KeywordTrie;
|
||||||
@@ -45,9 +44,11 @@ class KeywordMode {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Keyword expansion
|
// ----------------------------------------------------------------------------- : Keyword expansion
|
||||||
|
|
||||||
/// A way to use a keyword
|
/// A keyword for a set or a game
|
||||||
class KeywordExpansion {
|
class Keyword {
|
||||||
public:
|
public:
|
||||||
|
String keyword; ///< The keyword, only for human use
|
||||||
|
String rules; ///< Rules/explanation
|
||||||
String match; ///< String to match, <param> tags are used for parameters
|
String match; ///< String to match, <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
|
||||||
@@ -58,7 +59,6 @@ class KeywordExpansion {
|
|||||||
* captures 2,4,... capture the parameters
|
* captures 2,4,... capture the parameters
|
||||||
*/
|
*/
|
||||||
wxRegEx matchRe;
|
wxRegEx matchRe;
|
||||||
//% . Default is the mode of the Keyword.
|
|
||||||
|
|
||||||
/// 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
|
||||||
@@ -70,19 +70,6 @@ class KeywordExpansion {
|
|||||||
DECLARE_REFLECTION();
|
DECLARE_REFLECTION();
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Keyword
|
|
||||||
|
|
||||||
/// A keyword for a set or a game
|
|
||||||
class Keyword {
|
|
||||||
public:
|
|
||||||
String keyword; ///< The keyword
|
|
||||||
vector<KeywordExpansionP> expansions; ///< Expansions, i.e. ways to use this keyword
|
|
||||||
String rules; ///< Rules/explanation
|
|
||||||
// String mode; ///< Mode of use, can be used by scripts (only gives the name)
|
|
||||||
|
|
||||||
DECLARE_REFLECTION();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Using keywords
|
// ----------------------------------------------------------------------------- : Using keywords
|
||||||
|
|
||||||
@@ -99,12 +86,9 @@ class KeywordDatabase {
|
|||||||
void add(const vector<KeywordP>&);
|
void add(const vector<KeywordP>&);
|
||||||
/// Add a keyword to be matched
|
/// Add a keyword to be matched
|
||||||
void add(const Keyword&);
|
void add(const Keyword&);
|
||||||
/// Add an expansion of a keyword to be matched
|
|
||||||
void add(const KeywordExpansion&);
|
|
||||||
|
|
||||||
/// Prepare the parameters and match regex for a list of keywords
|
/// Prepare the parameters and match regex for a list of keywords
|
||||||
static void prepare_parameters(const vector<KeywordParamP>&, const vector<KeywordP>&);
|
static void prepare_parameters(const vector<KeywordParamP>&, const vector<KeywordP>&);
|
||||||
static void prepare_parameters(const vector<KeywordParamP>&, const Keyword&);
|
|
||||||
|
|
||||||
/// Clear the database
|
/// Clear the database
|
||||||
void clear();
|
void clear();
|
||||||
|
|||||||
+53
-179
@@ -36,14 +36,8 @@ DEFINE_EVENT_TYPE(EVENT_CARD_SELECT);
|
|||||||
// ----------------------------------------------------------------------------- : CardListBase
|
// ----------------------------------------------------------------------------- : CardListBase
|
||||||
|
|
||||||
CardListBase::CardListBase(Window* parent, int id, long additional_style)
|
CardListBase::CardListBase(Window* parent, int id, long additional_style)
|
||||||
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | wxLC_SINGLE_SEL)
|
: ItemList(parent, id, additional_style)
|
||||||
{
|
{}
|
||||||
// create image list
|
|
||||||
wxImageList* il = new wxImageList(18,14);
|
|
||||||
il->Add(load_resource_image(_("sort_asc")), Color(255,0,255));
|
|
||||||
il->Add(load_resource_image(_("sort_desc")), Color(255,0,255));
|
|
||||||
AssignImageList(il, wxIMAGE_LIST_SMALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
CardListBase::~CardListBase() {
|
CardListBase::~CardListBase() {
|
||||||
storeColumns();
|
storeColumns();
|
||||||
@@ -64,44 +58,44 @@ void CardListBase::onAction(const Action& action, bool undone) {
|
|||||||
// Let some other card list else do the selecting
|
// Let some other card list else do the selecting
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectCardPos((long)sorted_card_list.size() - 1, true);
|
selectItemPos(GetItemCount() - 1, true);
|
||||||
} else {
|
} else {
|
||||||
// select the new card
|
// select the new card
|
||||||
selectCard(action.card, false /*list will be refreshed anyway*/, true);
|
selectItem(action.card, false /*list will be refreshed anyway*/, true);
|
||||||
refreshList();
|
refreshList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TYPE_CASE(action, RemoveCardAction) {
|
TYPE_CASE(action, RemoveCardAction) {
|
||||||
if (undone) {
|
if (undone) {
|
||||||
// select the re-added card
|
// select the re-added card
|
||||||
selectCard(action.card, false /*list will be refreshed anyway*/, true);
|
selectItem(action.card, false /*list will be refreshed anyway*/, true);
|
||||||
refreshList();
|
refreshList();
|
||||||
} else {
|
} else {
|
||||||
long pos = selected_card_pos;
|
long pos = selected_item_pos;
|
||||||
refreshList();
|
refreshList();
|
||||||
if (!allowModify()) {
|
if (!allowModify()) {
|
||||||
// Let some other card list else do the selecting
|
// Let some other card list else do the selecting
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (action.card == selected_card) {
|
if (action.card == selected_item) {
|
||||||
// select the next card, if not possible, select the last
|
// select the next card, if not possible, select the last
|
||||||
if ((size_t)pos + 1 < sorted_card_list.size()) {
|
if (pos + 1 < GetItemCount()) {
|
||||||
selectCardPos(pos, true);
|
selectItemPos(pos, true);
|
||||||
} else {
|
} else {
|
||||||
selectCardPos((long)sorted_card_list.size() - 1, true);
|
selectItemPos(GetItemCount() - 1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TYPE_CASE(action, ReorderCardsAction) {
|
TYPE_CASE(action, ReorderCardsAction) {
|
||||||
if (sort_criterium) return; // nothing changes for us
|
if (sort_by_column >= 0) return; // nothing changes for us
|
||||||
if ((long)action.card_id1 == selected_card_pos || (long)action.card_id2 == selected_card_pos) {
|
if ((long)action.card_id1 == selected_item_pos || (long)action.card_id2 == selected_item_pos) {
|
||||||
// Selected card has moved; also move in the sorted card list
|
// Selected card has moved; also move in the sorted card list
|
||||||
swap(sorted_card_list[action.card_id1],sorted_card_list[action.card_id2]);
|
swap(sorted_list[action.card_id1], sorted_list[action.card_id2]);
|
||||||
// reselect the current card, it has moved
|
// reselect the current card, it has moved
|
||||||
selected_card_pos = (long)action.card_id1 == selected_card_pos ? (long)action.card_id2 : (long)action.card_id1;
|
selected_item_pos = (long)action.card_id1 == selected_item_pos ? (long)action.card_id2 : (long)action.card_id1;
|
||||||
// select the right card
|
// select the right card
|
||||||
selectCurrentCard();
|
selectCurrentItem();
|
||||||
}
|
}
|
||||||
RefreshItem((long)action.card_id1);
|
RefreshItem((long)action.card_id1);
|
||||||
RefreshItem((long)action.card_id2);
|
RefreshItem((long)action.card_id2);
|
||||||
@@ -116,83 +110,19 @@ void CardListBase::onAction(const Action& action, bool undone) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector<CardP>& CardListBase::getCards() const {
|
void CardListBase::getItems(vector<VoidP>& out) const {
|
||||||
return set->cards;
|
FOR_EACH(c, set->cards) {
|
||||||
}
|
out.push_back(c);
|
||||||
const CardP& CardListBase::getCard(long pos) const {
|
|
||||||
return sorted_card_list[pos];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : CardListBase : Selection
|
|
||||||
|
|
||||||
bool CardListBase::canSelectPrevious() const {
|
|
||||||
return selected_card_pos - 1 >= 0;
|
|
||||||
}
|
|
||||||
bool CardListBase::canSelectNext() const {
|
|
||||||
return selected_card_pos >= 0 && static_cast<size_t>(selected_card_pos + 1) < sorted_card_list.size();
|
|
||||||
}
|
|
||||||
void CardListBase::selectPrevious() {
|
|
||||||
assert(selected_card_pos >= 1);
|
|
||||||
selectCardPos(selected_card_pos - 1, true);
|
|
||||||
}
|
|
||||||
void CardListBase::selectNext() {
|
|
||||||
assert(selected_card_pos + 1 < (long)sorted_card_list.size());
|
|
||||||
selectCardPos(selected_card_pos + 1, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : CardListBase : Selection (private)
|
|
||||||
|
|
||||||
void CardListBase::selectCard(const CardP& card, bool focus, bool event) {
|
|
||||||
selected_card = card;
|
|
||||||
if (event) {
|
|
||||||
CardSelectEvent ev(card);
|
|
||||||
ProcessEvent(ev);
|
|
||||||
}
|
|
||||||
findSelectedCardPos();
|
|
||||||
if (focus) {
|
|
||||||
selectCurrentCard();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void CardListBase::sendEvent() {
|
||||||
void CardListBase::selectCardPos(long pos, bool focus) {
|
CardSelectEvent ev(getCard());
|
||||||
if (selected_card_pos == pos && !focus) return; // this card is already selected
|
ProcessEvent(ev);
|
||||||
if ((size_t)pos < sorted_card_list.size()) {
|
|
||||||
// only if there is something to select
|
|
||||||
selectCard(getCard(pos), false, true);
|
|
||||||
} else {
|
|
||||||
selectCard(CardP(), false, true);
|
|
||||||
}
|
|
||||||
selected_card_pos = pos;
|
|
||||||
if (focus) selectCurrentCard();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardListBase::findSelectedCardPos() {
|
|
||||||
// find the position of the selected card
|
|
||||||
long count = GetItemCount();
|
|
||||||
selected_card_pos = -1;
|
|
||||||
for (long pos = 0 ; pos < count ; ++pos) {
|
|
||||||
if (getCard(pos) == selected_card) {
|
|
||||||
selected_card_pos = pos;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void CardListBase::selectCurrentCard() {
|
|
||||||
if (GetItemCount() > 0) {
|
|
||||||
if (selected_card_pos == -1 || (size_t)selected_card_pos > sorted_card_list.size()) {
|
|
||||||
// deselect currently selected item, if any
|
|
||||||
long sel = GetFirstSelected();
|
|
||||||
Select(sel, false);
|
|
||||||
} else {
|
|
||||||
Select(selected_card_pos);
|
|
||||||
Focus(selected_card_pos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : CardListBase : Clipboard
|
// ----------------------------------------------------------------------------- : CardListBase : Clipboard
|
||||||
|
|
||||||
bool CardListBase::canCopy() const { return !!selected_card; }
|
bool CardListBase::canCopy() const { return !!selected_item; }
|
||||||
bool CardListBase::canCut() const { return canCopy() && allowModify(); }
|
bool CardListBase::canCut() const { return canCopy() && allowModify(); }
|
||||||
bool CardListBase::canPaste() const {
|
bool CardListBase::canPaste() const {
|
||||||
return allowModify() && wxTheClipboard->IsSupported(CardDataObject::format);
|
return allowModify() && wxTheClipboard->IsSupported(CardDataObject::format);
|
||||||
@@ -201,7 +131,7 @@ bool CardListBase::canPaste() const {
|
|||||||
bool CardListBase::doCopy() {
|
bool CardListBase::doCopy() {
|
||||||
if (!canCopy()) return false;
|
if (!canCopy()) return false;
|
||||||
if (!wxTheClipboard->Open()) return false;
|
if (!wxTheClipboard->Open()) return false;
|
||||||
bool ok = wxTheClipboard->SetData(new CardOnClipboard(set, selected_card)); // ignore result
|
bool ok = wxTheClipboard->SetData(new CardOnClipboard(set, getCard())); // ignore result
|
||||||
wxTheClipboard->Close();
|
wxTheClipboard->Close();
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@@ -209,7 +139,7 @@ bool CardListBase::doCut() {
|
|||||||
// cut = copy + delete
|
// cut = copy + delete
|
||||||
if (!canCut()) return false;
|
if (!canCut()) return false;
|
||||||
if (!doCopy()) return false;
|
if (!doCopy()) return false;
|
||||||
set->actions.add(new RemoveCardAction(*set, selected_card));
|
set->actions.add(new RemoveCardAction(*set, getCard()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool CardListBase::doPaste() {
|
bool CardListBase::doPaste() {
|
||||||
@@ -233,37 +163,23 @@ bool CardListBase::doPaste() {
|
|||||||
// ----------------------------------------------------------------------------- : CardListBase : Building the list
|
// ----------------------------------------------------------------------------- : CardListBase : Building the list
|
||||||
|
|
||||||
// Comparison object for comparing cards
|
// Comparison object for comparing cards
|
||||||
struct CardListBase::CardComparer {
|
bool CardListBase::compareItems(void* a, void* b) const {
|
||||||
CardComparer(CardListBase& cl) : cl(cl) {}
|
FieldP sort_field = column_fields[sort_by_column];
|
||||||
CardListBase& cl; // 'this' pointer
|
ValueP va = reinterpret_cast<Card*>(a)->data[sort_field];
|
||||||
// Compare two cards using the current criterium and order
|
ValueP vb = reinterpret_cast<Card*>(b)->data[sort_field];
|
||||||
bool operator () (const CardP& a, const CardP& b) {
|
if (sort_ascending) {
|
||||||
ValueP va = a->data[cl.sort_criterium];
|
if (!va || !vb) return va < vb; // got to do something, compare pointers
|
||||||
ValueP vb = b->data[cl.sort_criterium];
|
return smart_less( va->toString() , vb->toString() );
|
||||||
if (cl.sort_ascending) {
|
} else {
|
||||||
if (!va || !vb) return va < vb; // got to do something, compare pointers
|
if (!va || !vb) return vb < va;
|
||||||
return smart_less( va->toString() , vb->toString() );
|
return smart_less( vb->toString() , va->toString() );
|
||||||
} else {
|
|
||||||
if (!va || !vb) return vb < va;
|
|
||||||
return smart_less( vb->toString() , va->toString() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
void CardListBase::sortList() {
|
|
||||||
sorted_card_list.clear();
|
|
||||||
FOR_EACH_CONST(card, getCards()) {
|
|
||||||
sorted_card_list.push_back(card);
|
|
||||||
}
|
|
||||||
if (sort_criterium) {
|
|
||||||
sort(sorted_card_list.begin(), sorted_card_list.end(), CardComparer(*this));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardListBase::rebuild() {
|
void CardListBase::rebuild() {
|
||||||
ClearAll();
|
ClearAll();
|
||||||
column_fields.clear();
|
column_fields.clear();
|
||||||
selected_card_pos = -1;
|
selected_item_pos = -1;
|
||||||
onRebuild();
|
onRebuild();
|
||||||
// determine column order
|
// determine column order
|
||||||
map<int,FieldP> new_column_fields;
|
map<int,FieldP> new_column_fields;
|
||||||
@@ -290,36 +206,23 @@ void CardListBase::rebuild() {
|
|||||||
// determine sort settings
|
// determine sort settings
|
||||||
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
sort_ascending = gs.sort_cards_ascending;
|
sort_ascending = gs.sort_cards_ascending;
|
||||||
sort_criterium = FieldP();
|
sort_by_column = -1;
|
||||||
int i = 0;
|
long i = 0;
|
||||||
FOR_EACH(f, column_fields) {
|
FOR_EACH(f, column_fields) {
|
||||||
if (f->name == gs.sort_cards_by) {
|
if (f->name == gs.sort_cards_by) {
|
||||||
// we are sorting by this column, store the field
|
// we are sorting by this column
|
||||||
sort_criterium = f;
|
sort_by_column = i;
|
||||||
// and display an arrow in the header
|
// and display an arrow in the header
|
||||||
wxListItem li;
|
wxListItem li;
|
||||||
li.m_mask = wxLIST_MASK_IMAGE;
|
li.m_mask = wxLIST_MASK_IMAGE;
|
||||||
li.m_image = sort_ascending ? 0 : 1; // arrow up/down
|
li.m_image = sort_ascending ? 0 : 1; // arrow up/down
|
||||||
SetColumn(i, li);
|
SetColumn(i, li);
|
||||||
}
|
}
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
refreshList();
|
refreshList();
|
||||||
// select a card if possible
|
// select a card if possible
|
||||||
selectCardPos(0, true);
|
selectItemPos(0, true);
|
||||||
}
|
|
||||||
|
|
||||||
void CardListBase::refreshList() {
|
|
||||||
// ensure correct list size
|
|
||||||
long items = (long) getCards().size();
|
|
||||||
SetItemCount(items);
|
|
||||||
// (re)sort the list
|
|
||||||
sortList();
|
|
||||||
// refresh
|
|
||||||
RefreshItems(0, items - 1);
|
|
||||||
if (items == 0) Refresh();
|
|
||||||
// select
|
|
||||||
findSelectedCardPos();
|
|
||||||
selectCurrentCard();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChoiceStyleP CardListBase::findColorStyle() {
|
ChoiceStyleP CardListBase::findColorStyle() {
|
||||||
@@ -344,8 +247,8 @@ void CardListBase::storeColumns() {
|
|||||||
}
|
}
|
||||||
// store sorting
|
// store sorting
|
||||||
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
if (sort_criterium) gs.sort_cards_by = sort_criterium->name;
|
if (sort_by_column >= 0) gs.sort_cards_by = column_fields.at(sort_by_column)->name;
|
||||||
else gs.sort_cards_by = wxEmptyString;
|
else gs.sort_cards_by = wxEmptyString;
|
||||||
gs.sort_cards_ascending = sort_ascending;
|
gs.sort_cards_ascending = sort_ascending;
|
||||||
}
|
}
|
||||||
void CardListBase::selectColumns() {
|
void CardListBase::selectColumns() {
|
||||||
@@ -381,31 +284,6 @@ wxListItemAttr* CardListBase::OnGetItemAttr(long pos) const {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : CardListBase : Window events
|
// ----------------------------------------------------------------------------- : CardListBase : Window events
|
||||||
|
|
||||||
void CardListBase::onColumnClick(wxListEvent& ev) {
|
|
||||||
FieldP new_sort_criterium = column_fields[ev.GetColumn()];
|
|
||||||
if (sort_criterium == new_sort_criterium) {
|
|
||||||
if (sort_ascending) {
|
|
||||||
sort_ascending = false; // 2nd click on same column -> sort descending
|
|
||||||
} else {
|
|
||||||
new_sort_criterium.reset(); // 3rd click on same column -> don't sort
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sort_ascending = true;
|
|
||||||
}
|
|
||||||
// Change image in column header
|
|
||||||
int i = 0;
|
|
||||||
FOR_EACH(f, column_fields) {
|
|
||||||
if (f == new_sort_criterium) {
|
|
||||||
SetColumnImage(i, sort_ascending ? 0 : 1); // arrow up/down
|
|
||||||
} else if (f == sort_criterium) {
|
|
||||||
ClearColumnImage(i);
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
sort_criterium = new_sort_criterium;
|
|
||||||
refreshList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardListBase::onColumnRightClick(wxListEvent&) {
|
void CardListBase::onColumnRightClick(wxListEvent&) {
|
||||||
// show menu
|
// show menu
|
||||||
wxMenu* m = new wxMenu;
|
wxMenu* m = new wxMenu;
|
||||||
@@ -417,13 +295,9 @@ void CardListBase::onSelectColumns(wxCommandEvent&) {
|
|||||||
selectColumns();
|
selectColumns();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardListBase::onItemFocus(wxListEvent& ev) {
|
|
||||||
selectCardPos(ev.GetIndex(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardListBase::onChar(wxKeyEvent& ev) {
|
void CardListBase::onChar(wxKeyEvent& ev) {
|
||||||
if (ev.GetKeyCode() == WXK_DELETE && allowModify()) {
|
if (ev.GetKeyCode() == WXK_DELETE && allowModify()) {
|
||||||
set->actions.add(new RemoveCardAction(*set, selected_card));
|
set->actions.add(new RemoveCardAction(*set, getCard()));
|
||||||
} else if (ev.GetKeyCode() == WXK_TAB) {
|
} else if (ev.GetKeyCode() == WXK_TAB) {
|
||||||
// send a navigation event to our parent, to select another control
|
// send a navigation event to our parent, to select another control
|
||||||
// we need this because tabs are not handled on the cards panel
|
// we need this because tabs are not handled on the cards panel
|
||||||
@@ -437,17 +311,17 @@ void CardListBase::onChar(wxKeyEvent& ev) {
|
|||||||
|
|
||||||
void CardListBase::onDrag(wxMouseEvent& ev) {
|
void CardListBase::onDrag(wxMouseEvent& ev) {
|
||||||
if (!allowModify()) return;
|
if (!allowModify()) return;
|
||||||
if (ev.Dragging() && selected_card && !sort_criterium) {
|
if (ev.Dragging() && selected_item && sort_by_column < 0) {
|
||||||
// reorder card list
|
// reorder card list
|
||||||
int flags;
|
int flags;
|
||||||
long item = HitTest(ev.GetPosition(), flags);
|
long item = HitTest(ev.GetPosition(), flags);
|
||||||
if (flags & wxLIST_HITTEST_ONITEM) {
|
if (flags & wxLIST_HITTEST_ONITEM) {
|
||||||
if (item > 0) EnsureVisible(item-1);
|
if (item > 0) EnsureVisible(item-1);
|
||||||
if (item < GetItemCount()-1) EnsureVisible(item+1);
|
if (item < GetItemCount()-1) EnsureVisible(item+1);
|
||||||
findSelectedCardPos();
|
findSelectedItemPos();
|
||||||
if (item != selected_card_pos) {
|
if (item != selected_item_pos) {
|
||||||
// move card in the set
|
// move card in the set
|
||||||
set->actions.add(new ReorderCardsAction(*set, item, selected_card_pos));
|
set->actions.add(new ReorderCardsAction(*set, item, selected_item_pos));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -456,12 +330,12 @@ void CardListBase::onDrag(wxMouseEvent& ev) {
|
|||||||
void CardListBase::onContextMenu(wxContextMenuEvent&) {
|
void CardListBase::onContextMenu(wxContextMenuEvent&) {
|
||||||
if (allowModify()) {
|
if (allowModify()) {
|
||||||
IconMenu m;
|
IconMenu m;
|
||||||
m.Append(wxID_CUT, _("cut"), _("Cu&t"), _("Move the selected card to the clipboard"));
|
m.Append(wxID_CUT, _("cut"), _CONTEXT_MENU_("cut"), _HELP_("cut card"));
|
||||||
m.Append(wxID_COPY, _("copy"), _("&Copy"), _("Place the selected card on the clipboard"));
|
m.Append(wxID_COPY, _("copy"), _CONTEXT_MENU_("copy"), _HELP_("copy card"));
|
||||||
m.Append(wxID_PASTE, _("paste"), _("&Paste"), _("Inserts the card from the clipboard"));
|
m.Append(wxID_PASTE, _("paste"), _CONTEXT_MENU_("paste"), _HELP_("paste card"));
|
||||||
m.AppendSeparator();
|
m.AppendSeparator();
|
||||||
m.Append(ID_CARD_ADD, _("card_add"), _("&Add Card"), _("Add a new, blank, card to this set"));
|
m.Append(ID_CARD_ADD, _("card_add"), _CONTEXT_MENU_("add card"), _HELP_("add card"));
|
||||||
m.Append(ID_CARD_REMOVE,_("card_del"), _("&Remove Select Card"), _("Delete the selected card from this set"));
|
m.Append(ID_CARD_REMOVE,_("card_del"), _CONTEXT_MENU_("remove card"), _HELP_("remove card"));
|
||||||
PopupMenu(&m);
|
PopupMenu(&m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@
|
|||||||
// ----------------------------------------------------------------------------- : Includes
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
#include <util/prec.hpp>
|
#include <util/prec.hpp>
|
||||||
|
#include <gui/control/item_list.hpp>
|
||||||
#include <data/set.hpp>
|
#include <data/set.hpp>
|
||||||
#include <wx/listctrl.h>
|
|
||||||
|
|
||||||
DECLARE_POINTER_TYPE(ChoiceStyle);
|
DECLARE_POINTER_TYPE(ChoiceStyle);
|
||||||
DECLARE_POINTER_TYPE(Field);
|
DECLARE_POINTER_TYPE(Field);
|
||||||
@@ -39,27 +39,18 @@ struct CardSelectEvent : public wxCommandEvent {
|
|||||||
/* This class allows the cards to be sorted, and has a _('currentCard'), the selected card
|
/* This class allows the cards to be sorted, and has a _('currentCard'), the selected card
|
||||||
* when a card is selected, it raises a CardSelectEvent, that will propage to the parent window.
|
* when a card is selected, it raises a CardSelectEvent, that will propage to the parent window.
|
||||||
*
|
*
|
||||||
* Note: (long) pos refers to position in the sorted_card_list,
|
* Note: (long) pos refers to position in the sorted_list,
|
||||||
* (size_t) index refers to the index in the actual card list (as returned by getCards).
|
* (size_t) index refers to the index in the actual card list.
|
||||||
*/
|
*/
|
||||||
class CardListBase : public wxListView, public SetView {
|
class CardListBase : public ItemList, public SetView {
|
||||||
public:
|
public:
|
||||||
CardListBase(Window* parent, int id, long additional_style = 0);
|
CardListBase(Window* parent, int id, long additional_style = 0);
|
||||||
~CardListBase();
|
~CardListBase();
|
||||||
|
|
||||||
// --------------------------------------------------- : Selection
|
// --------------------------------------------------- : Selection
|
||||||
|
|
||||||
inline CardP getCard() const { return selected_card; }
|
inline CardP getCard() const { return static_pointer_cast<Card>(selected_item); }
|
||||||
inline void setCard(const CardP& card) { selectCard(card, true, false); }
|
inline void setCard(const CardP& card) { selectItem(card, true, false); }
|
||||||
|
|
||||||
/// Is there a previous card to select?
|
|
||||||
bool canSelectPrevious() const;
|
|
||||||
/// Is there a next card to select?
|
|
||||||
bool canSelectNext() const;
|
|
||||||
/// Move the selection to the previous card (if possible)
|
|
||||||
void selectPrevious();
|
|
||||||
/// Move the selection to the next card (if possible)
|
|
||||||
void selectNext();
|
|
||||||
|
|
||||||
// --------------------------------------------------- : Clipboard
|
// --------------------------------------------------- : Clipboard
|
||||||
|
|
||||||
@@ -79,10 +70,10 @@ class CardListBase : public wxListView, public SetView {
|
|||||||
|
|
||||||
// --------------------------------------------------- : The cards
|
// --------------------------------------------------- : The cards
|
||||||
protected:
|
protected:
|
||||||
/// What cards should be shown?
|
/// Get a list of all cards
|
||||||
virtual const vector<CardP>& getCards() const;
|
virtual void getItems(vector<VoidP>& out) const;
|
||||||
/// Return the card at the given position in the sorted card list
|
/// Return the card at the given position in the sorted card list
|
||||||
const CardP& getCard(long pos) const;
|
inline CardP getCard(long pos) const { return static_pointer_cast<Card>(getItem(pos)); }
|
||||||
|
|
||||||
/// Rebuild the card list (clear all vectors and fill them again)
|
/// Rebuild the card list (clear all vectors and fill them again)
|
||||||
void rebuild();
|
void rebuild();
|
||||||
@@ -91,6 +82,11 @@ class CardListBase : public wxListView, public SetView {
|
|||||||
/// Can the card list be modified?
|
/// Can the card list be modified?
|
||||||
virtual bool allowModify() const { return false; }
|
virtual bool allowModify() const { return false; }
|
||||||
|
|
||||||
|
/// Send an 'item selected' event for the currently selected item (selected_item)
|
||||||
|
virtual void sendEvent();
|
||||||
|
/// Compare cards
|
||||||
|
virtual bool compareItems(void* a, void* b) const;
|
||||||
|
|
||||||
// --------------------------------------------------- : Item 'events'
|
// --------------------------------------------------- : Item 'events'
|
||||||
|
|
||||||
/// Get the text of an item in a specific column
|
/// Get the text of an item in a specific column
|
||||||
@@ -103,37 +99,13 @@ class CardListBase : public wxListView, public SetView {
|
|||||||
virtual wxListItemAttr* OnGetItemAttr(long pos) const;
|
virtual wxListItemAttr* OnGetItemAttr(long pos) const;
|
||||||
|
|
||||||
// --------------------------------------------------- : Data
|
// --------------------------------------------------- : Data
|
||||||
protected:
|
|
||||||
CardP selected_card; ///< The currently selected card, or -1 if no card is selected
|
|
||||||
long selected_card_pos;///< Position of the selected card in the sorted_card_list
|
|
||||||
private:
|
private:
|
||||||
// display stuff
|
// display stuff
|
||||||
ChoiceStyleP color_style; ///< Style (and field) to use for text color (optional)
|
ChoiceStyleP color_style; ///< Style (and field) to use for text color (optional)
|
||||||
vector<FieldP> column_fields; ///< The field to use for each column (by column index)
|
vector<FieldP> column_fields; ///< The field to use for each column (by column index)
|
||||||
// sorted list stuff
|
|
||||||
vector<CardP> sorted_card_list; ///< Sorted list of cards, can be considered a map: pos->card
|
|
||||||
FieldP sort_criterium; ///< Field to sort by
|
|
||||||
bool sort_ascending; ///< Sort order
|
|
||||||
|
|
||||||
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
mutable wxListItemAttr item_attr; // for OnGetItemAttr
|
||||||
|
|
||||||
/// Select a card, send an event to the parent
|
|
||||||
/** If focus then the card is also focused and selected in the actual control.
|
|
||||||
* This should abviously not be done when the card is selected because it was selected (leading to a loop).
|
|
||||||
*/
|
|
||||||
void selectCard(const CardP& card, bool focus, bool event);
|
|
||||||
/// Select a card at the specified position
|
|
||||||
void selectCardPos(long pos, bool focus);
|
|
||||||
/// Find the position for the selected_card
|
|
||||||
void findSelectedCardPos();
|
|
||||||
/// Actually select the card at selected_card_pos in the control
|
|
||||||
void selectCurrentCard();
|
|
||||||
|
|
||||||
/// Sorts the list by the current sorting criterium
|
|
||||||
void sortList();
|
|
||||||
struct CardComparer; // for comparing cards
|
|
||||||
/// Refresh the card list (resort, refresh and reselect current item)
|
|
||||||
void refreshList();
|
|
||||||
/// Find the field that determines the color, if any.
|
/// Find the field that determines the color, if any.
|
||||||
/** Note: Uses only fields from the set's default style */
|
/** Note: Uses only fields from the set's default style */
|
||||||
ChoiceStyleP findColorStyle();
|
ChoiceStyleP findColorStyle();
|
||||||
@@ -148,10 +120,8 @@ class CardListBase : public wxListView, public SetView {
|
|||||||
// --------------------------------------------------- : Window events
|
// --------------------------------------------------- : Window events
|
||||||
DECLARE_EVENT_TABLE();
|
DECLARE_EVENT_TABLE();
|
||||||
|
|
||||||
void onColumnClick (wxListEvent& ev);
|
|
||||||
void onColumnRightClick(wxListEvent& ev);
|
void onColumnRightClick(wxListEvent& ev);
|
||||||
void onSelectColumns (wxCommandEvent& ev);
|
void onSelectColumns (wxCommandEvent& ev);
|
||||||
void onItemFocus (wxListEvent& ev);
|
|
||||||
void onChar (wxKeyEvent& ev);
|
void onChar (wxKeyEvent& ev);
|
||||||
void onDrag (wxMouseEvent& ev);
|
void onDrag (wxMouseEvent& ev);
|
||||||
void onContextMenu (wxContextMenuEvent&);
|
void onContextMenu (wxContextMenuEvent&);
|
||||||
|
|||||||
@@ -16,21 +16,16 @@ FilteredCardList::FilteredCardList(Window* parent, int id, long style)
|
|||||||
: CardListBase(parent, id, style)
|
: CardListBase(parent, id, style)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const vector<CardP>& FilteredCardList::getCards() const {
|
|
||||||
return cards;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FilteredCardList::setFilter(const CardListFilterP& filter) {
|
void FilteredCardList::setFilter(const CardListFilterP& filter) {
|
||||||
this->filter = filter;
|
this->filter = filter;
|
||||||
rebuild();
|
rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilteredCardList::onRebuild() {
|
void FilteredCardList::getItems(vector<VoidP>& out) const {
|
||||||
cards.clear();
|
|
||||||
if (filter) {
|
if (filter) {
|
||||||
FOR_EACH(c, set->cards) {
|
FOR_EACH(c, set->cards) {
|
||||||
if (filter->keep(c)) {
|
if (filter->keep(c)) {
|
||||||
cards.push_back(c);
|
out.push_back(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,13 +36,10 @@ class FilteredCardList : public CardListBase {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Get only the subset of the cards
|
/// Get only the subset of the cards
|
||||||
virtual const vector<CardP>& getCards() const;
|
virtual void getItems(vector<VoidP>& out) const;
|
||||||
/// Rebuild the filtered card list
|
|
||||||
virtual void onRebuild();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CardListFilterP filter; ///< Filter with which this.cards is made
|
CardListFilterP filter; ///< Filter with which this.cards is made
|
||||||
vector<CardP> cards; ///< The cards that are shown
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,162 @@
|
|||||||
|
//+----------------------------------------------------------------------------+
|
||||||
|
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||||
|
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||||
|
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||||
|
//+----------------------------------------------------------------------------+
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
|
#include <gui/control/item_list.hpp>
|
||||||
|
#include <gui/util.hpp>
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ItemList
|
||||||
|
|
||||||
|
ItemList::ItemList(Window* parent, int id, long additional_style)
|
||||||
|
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | wxLC_SINGLE_SEL)
|
||||||
|
{
|
||||||
|
// create image list
|
||||||
|
wxImageList* il = new wxImageList(18,14);
|
||||||
|
il->Add(load_resource_image(_("sort_asc")), Color(255,0,255));
|
||||||
|
il->Add(load_resource_image(_("sort_desc")), Color(255,0,255));
|
||||||
|
AssignImageList(il, wxIMAGE_LIST_SMALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ItemList : Selection
|
||||||
|
|
||||||
|
bool ItemList::canSelectPrevious() const {
|
||||||
|
return selected_item_pos - 1 >= 0;
|
||||||
|
}
|
||||||
|
bool ItemList::canSelectNext() const {
|
||||||
|
return selected_item_pos >= 0 && static_cast<size_t>(selected_item_pos + 1) < sorted_list.size();
|
||||||
|
}
|
||||||
|
void ItemList::selectPrevious() {
|
||||||
|
assert(selected_item_pos >= 1);
|
||||||
|
selectItemPos(selected_item_pos - 1, true);
|
||||||
|
}
|
||||||
|
void ItemList::selectNext() {
|
||||||
|
assert(selected_item_pos + 1 < (long)sorted_list.size());
|
||||||
|
selectItemPos(selected_item_pos + 1, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ItemList : Selection (private)
|
||||||
|
|
||||||
|
void ItemList::selectItem(const VoidP& item, bool focus, bool event) {
|
||||||
|
selected_item = item;
|
||||||
|
if (event) sendEvent();
|
||||||
|
findSelectedItemPos();
|
||||||
|
if (focus) {
|
||||||
|
selectCurrentItem();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemList::selectItemPos(long pos, bool focus) {
|
||||||
|
if (selected_item_pos == pos && !focus) return; // this item is already selected
|
||||||
|
if ((size_t)pos < sorted_list.size()) {
|
||||||
|
// only if there is something to select
|
||||||
|
selectItem(getItem(pos), false, true);
|
||||||
|
} else {
|
||||||
|
selectItem(VoidP(), false, true);
|
||||||
|
}
|
||||||
|
selected_item_pos = pos;
|
||||||
|
if (focus) selectCurrentItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemList::findSelectedItemPos() {
|
||||||
|
// find the position of the selected item
|
||||||
|
long count = GetItemCount();
|
||||||
|
selected_item_pos = -1;
|
||||||
|
for (long pos = 0 ; pos < count ; ++pos) {
|
||||||
|
if (getItem(pos) == selected_item) {
|
||||||
|
selected_item_pos = pos;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ItemList::selectCurrentItem() {
|
||||||
|
if (GetItemCount() > 0) {
|
||||||
|
if (selected_item_pos == -1 || (size_t)selected_item_pos > sorted_list.size()) {
|
||||||
|
// deselect currently selected item, if any
|
||||||
|
long sel = GetFirstSelected();
|
||||||
|
Select(sel, false);
|
||||||
|
} else {
|
||||||
|
Select(selected_item_pos);
|
||||||
|
Focus (selected_item_pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ItemList : Building the list
|
||||||
|
|
||||||
|
// Comparison object for comparing items
|
||||||
|
struct ItemList::ItemComparer {
|
||||||
|
ItemComparer(ItemList& list) : list(list) {}
|
||||||
|
ItemList& list; // 'this' pointer
|
||||||
|
// Compare two items using the current criterium and order
|
||||||
|
bool operator () (const VoidP& a, const VoidP& b) {
|
||||||
|
return list.compareItems(a.get(), b.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void ItemList::refreshList() {
|
||||||
|
// Get all items
|
||||||
|
sorted_list.clear();
|
||||||
|
getItems(sorted_list);
|
||||||
|
long item_count = (long)sorted_list.size();
|
||||||
|
SetItemCount(item_count);
|
||||||
|
// Sort the list
|
||||||
|
if (sort_by_column >= 0) {
|
||||||
|
sort(sorted_list.begin(), sorted_list.end(), ItemComparer(*this));
|
||||||
|
}
|
||||||
|
// refresh
|
||||||
|
RefreshItems(0, item_count - 1);
|
||||||
|
if (item_count == 0) Refresh();
|
||||||
|
// (re)select current item
|
||||||
|
findSelectedItemPos();
|
||||||
|
selectCurrentItem();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemList::sortBy(long column, bool ascending) {
|
||||||
|
// Change image in column header
|
||||||
|
long count = GetColumnCount();
|
||||||
|
for (long i = 0 ; i < count ; ++i) {
|
||||||
|
if (i == column) {
|
||||||
|
SetColumnImage(i, sort_ascending ? 0 : 1); // arrow up/down
|
||||||
|
} else if (i == sort_by_column) {
|
||||||
|
ClearColumnImage(i);
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
// sort list
|
||||||
|
sort_by_column = column;
|
||||||
|
sort_ascending = ascending;
|
||||||
|
refreshList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ItemList : Window events
|
||||||
|
|
||||||
|
void ItemList::onColumnClick(wxListEvent& ev) {
|
||||||
|
long new_sort_by_column = ev.GetColumn();
|
||||||
|
if (sort_by_column == new_sort_by_column) {
|
||||||
|
if (sort_ascending) {
|
||||||
|
sort_ascending = false; // 2nd click on same column -> sort descending
|
||||||
|
} else if (mustSort()) {
|
||||||
|
sort_ascending = true; // 3rd click on same column -> sort ascending again
|
||||||
|
} else {
|
||||||
|
new_sort_by_column = -1; // 3rd click on same column -> don't sort
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sort_ascending = true;
|
||||||
|
}
|
||||||
|
sortBy(new_sort_by_column, sort_ascending);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemList::onItemFocus(wxListEvent& ev) {
|
||||||
|
selectItemPos(ev.GetIndex(), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ItemList : Event table
|
||||||
|
|
||||||
|
BEGIN_EVENT_TABLE(ItemList, wxListView)
|
||||||
|
EVT_LIST_COL_CLICK (wxID_ANY, ItemList::onColumnClick)
|
||||||
|
EVT_LIST_ITEM_FOCUSED (wxID_ANY, ItemList::onItemFocus)
|
||||||
|
END_EVENT_TABLE ()
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
//+----------------------------------------------------------------------------+
|
||||||
|
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||||
|
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||||
|
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||||
|
//+----------------------------------------------------------------------------+
|
||||||
|
|
||||||
|
#ifndef HEADER_GUI_CONTROL_ITEM_LIST
|
||||||
|
#define HEADER_GUI_CONTROL_ITEM_LIST
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : Includes
|
||||||
|
|
||||||
|
#include <util/prec.hpp>
|
||||||
|
#include <wx/listctrl.h>
|
||||||
|
|
||||||
|
typedef shared_ptr<void> VoidP;
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : ItemList
|
||||||
|
|
||||||
|
/// A generic list of items
|
||||||
|
/** The list is shown in report mode, and allows sorting.
|
||||||
|
* Currently used for cards and keywords.
|
||||||
|
*/
|
||||||
|
class ItemList : public wxListView {
|
||||||
|
public:
|
||||||
|
ItemList(Window* parent, int id, long additional_style = 0);
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Selection
|
||||||
|
|
||||||
|
/// Is there a previous item to select?
|
||||||
|
bool canSelectPrevious() const;
|
||||||
|
/// Is there a next item to select?
|
||||||
|
bool canSelectNext() const;
|
||||||
|
/// Move the selection to the previous item (if possible)
|
||||||
|
void selectPrevious();
|
||||||
|
/// Move the selection to the next item (if possible)
|
||||||
|
void selectNext();
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Virtual interface
|
||||||
|
protected:
|
||||||
|
/// Get a list of all items
|
||||||
|
virtual void getItems(vector<VoidP>& out) const = 0;
|
||||||
|
|
||||||
|
/// Send an 'item selected' event for the currently selected item (selected_item)
|
||||||
|
virtual void sendEvent() = 0;
|
||||||
|
|
||||||
|
/// Is sorting required?
|
||||||
|
virtual bool mustSort() const { return false; }
|
||||||
|
/// Compare two items for <
|
||||||
|
virtual bool compareItems(void* a, void* b) const = 0;
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Protected interface
|
||||||
|
/// Return the card at the given position in the sorted list
|
||||||
|
inline const VoidP& getItem(long pos) const { return sorted_list[pos]; }
|
||||||
|
/// Sort by the given column
|
||||||
|
void sortBy(long column, bool ascending);
|
||||||
|
/// Refresh the card list (resort, refresh and reselect current item)
|
||||||
|
void refreshList();
|
||||||
|
|
||||||
|
/// Select an item, send an event to the parent
|
||||||
|
/** If focus then the item is also focused and selected in the actual control.
|
||||||
|
* This should abviously not be done when the item is selected because it was focused (leading to a loop).
|
||||||
|
*/
|
||||||
|
void selectItem(const VoidP& item, bool focus, bool event);
|
||||||
|
/// Select a item at the specified position
|
||||||
|
void selectItemPos(long pos, bool focus);
|
||||||
|
/// Find the position for the selected_item
|
||||||
|
void findSelectedItemPos();
|
||||||
|
/// Actually select the card at selected_item_pos in the control
|
||||||
|
void selectCurrentItem();
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Data
|
||||||
|
VoidP selected_item; ///< The currently selected item
|
||||||
|
long selected_item_pos; ///< Position of the selected item in the sorted_list, or -1 if no card is selected
|
||||||
|
bool sort_ascending; ///< Sort order
|
||||||
|
long sort_by_column; ///< Column to use for sorting, or -1 if not sorted
|
||||||
|
vector<VoidP> sorted_list; ///< Sorted list of items, can be considered a map: pos->item
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct ItemComparer; // for comparing items
|
||||||
|
|
||||||
|
// --------------------------------------------------- : Window events
|
||||||
|
DECLARE_EVENT_TABLE();
|
||||||
|
|
||||||
|
void onColumnClick(wxListEvent& ev);
|
||||||
|
void onItemFocus (wxListEvent& ev);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------- : EOF
|
||||||
|
#endif
|
||||||
@@ -26,7 +26,7 @@ SelectCardList::SelectCardList(Window* parent, int id, long additional_style)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SelectCardList::selectAll() {
|
void SelectCardList::selectAll() {
|
||||||
FOR_EACH_CONST(c, getCards()) {
|
FOR_EACH_CONST(c, set->cards) {
|
||||||
selected.insert(c);
|
selected.insert(c);
|
||||||
}
|
}
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
@@ -61,25 +61,25 @@ void SelectCardList::toggle(const CardP& card) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SelectCardList::onKeyDown(wxKeyEvent& ev) {
|
void SelectCardList::onKeyDown(wxKeyEvent& ev) {
|
||||||
if (selected_card_pos == -1 || !selected_card) {
|
if (selected_item_pos == -1 || !selected_item) {
|
||||||
// no selection
|
// no selection
|
||||||
ev.Skip();
|
ev.Skip();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (ev.GetKeyCode()) {
|
switch (ev.GetKeyCode()) {
|
||||||
case WXK_SPACE: {
|
case WXK_SPACE: {
|
||||||
toggle(selected_card);
|
toggle(getCard());
|
||||||
RefreshItem(selected_card_pos);
|
RefreshItem(selected_item_pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WXK_NUMPAD_ADD: case '+': {
|
case WXK_NUMPAD_ADD: case '+': {
|
||||||
selected.insert(selected_card);
|
selected.insert(getCard());
|
||||||
RefreshItem(selected_card_pos);
|
RefreshItem(selected_item_pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WXK_NUMPAD_SUBTRACT: case '-': {
|
case WXK_NUMPAD_SUBTRACT: case '-': {
|
||||||
selected.erase(selected_card);
|
selected.erase(getCard());
|
||||||
RefreshItem(selected_card_pos);
|
RefreshItem(selected_item_pos);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
+288
-248
@@ -531,18 +531,6 @@
|
|||||||
<Filter
|
<Filter
|
||||||
Name="control"
|
Name="control"
|
||||||
Filter="">
|
Filter="">
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\card_editor.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\card_editor.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\card_viewer.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\card_viewer.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\gui\control\gallery_list.cpp">
|
RelativePath=".\gui\control\gallery_list.cpp">
|
||||||
</File>
|
</File>
|
||||||
@@ -555,24 +543,12 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath=".\gui\control\graph.hpp">
|
RelativePath=".\gui\control\graph.hpp">
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\native_look_editor.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\native_look_editor.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\gui\control\package_list.cpp">
|
RelativePath=".\gui\control\package_list.cpp">
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\gui\control\package_list.hpp">
|
RelativePath=".\gui\control\package_list.hpp">
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\text_ctrl.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\gui\control\text_ctrl.hpp">
|
|
||||||
</File>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="card_list"
|
Name="card_list"
|
||||||
Filter="">
|
Filter="">
|
||||||
@@ -607,6 +583,50 @@
|
|||||||
RelativePath=".\gui\control\select_card_list.hpp">
|
RelativePath=".\gui\control\select_card_list.hpp">
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="other lists"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\item_list.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\item_list.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\keyword_list.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\keyword_list.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="editor"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\card_editor.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\card_editor.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\card_viewer.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\card_viewer.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\native_look_editor.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\native_look_editor.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\text_ctrl.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\gui\control\text_ctrl.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="symbol"
|
Name="symbol"
|
||||||
@@ -1190,66 +1210,6 @@
|
|||||||
<Filter
|
<Filter
|
||||||
Name="data"
|
Name="data"
|
||||||
Filter="">
|
Filter="">
|
||||||
<File
|
|
||||||
RelativePath=".\data\card.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\card.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\game.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\game.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\set.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\set.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\settings.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\settings.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\stylesheet.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\stylesheet.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\symbol.cpp">
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Unicode|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Profile Unicode|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Unicode fast build|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\data\symbol.hpp">
|
|
||||||
</File>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="action"
|
Name="action"
|
||||||
Filter="">
|
Filter="">
|
||||||
@@ -1683,85 +1643,74 @@
|
|||||||
RelativePath=".\data\symbol_font.hpp">
|
RelativePath=".\data\symbol_font.hpp">
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="base"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\card.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\card.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\game.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\game.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\set.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\set.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\settings.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\settings.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\stylesheet.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\stylesheet.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\symbol.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Unicode|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Profile Unicode|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Unicode fast build|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\data\symbol.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="util"
|
Name="util"
|
||||||
Filter="">
|
Filter="">
|
||||||
<File
|
|
||||||
RelativePath=".\util\atomic.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\dynamic_arg.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\error.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\error.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\for_each.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\order_cache.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\platform.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\prec.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\reflect.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\rotation.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\rotation.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\smart_ptr.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\string.cpp">
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Unicode|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Profile Unicode|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Unicode fast build|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\string.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\tagged_string.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\tagged_string.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\util\window_id.hpp">
|
|
||||||
</File>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="io"
|
Name="io"
|
||||||
Filter="">
|
Filter="">
|
||||||
@@ -1935,6 +1884,85 @@
|
|||||||
RelativePath=".\util\version.hpp">
|
RelativePath=".\util\version.hpp">
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="base"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\atomic.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\dynamic_arg.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\error.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\error.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\for_each.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\order_cache.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\platform.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\prec.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\reflect.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\rotation.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\rotation.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\smart_ptr.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\string.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Unicode|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Profile Unicode|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Unicode fast build|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\string.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\tagged_string.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\tagged_string.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\util\window_id.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="gfx"
|
Name="gfx"
|
||||||
@@ -2114,93 +2142,6 @@
|
|||||||
<Filter
|
<Filter
|
||||||
Name="script"
|
Name="script"
|
||||||
Filter="">
|
Filter="">
|
||||||
<File
|
|
||||||
RelativePath=".\script\context.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\context.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\dependency.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\dependency.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\image.cpp">
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Debug Unicode|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Unicode|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Profile Unicode|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
<FileConfiguration
|
|
||||||
Name="Release Unicode fast build|Win32">
|
|
||||||
<Tool
|
|
||||||
Name="VCCLCompilerTool"
|
|
||||||
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
|
||||||
</FileConfiguration>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\image.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\parser.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\parser.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\script.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\script.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\script_manager.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\script_manager.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\scriptable.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\scriptable.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\to_value.hpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\value.cpp">
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\script\value.hpp">
|
|
||||||
</File>
|
|
||||||
<Filter
|
<Filter
|
||||||
Name="functions"
|
Name="functions"
|
||||||
Filter="">
|
Filter="">
|
||||||
@@ -2298,6 +2239,105 @@
|
|||||||
RelativePath=".\script\functions\util.hpp">
|
RelativePath=".\script\functions\util.hpp">
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="base"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\script.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\script.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\to_value.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\value.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\value.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="parse_eval"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\context.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\context.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\dependency.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\dependency.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\parser.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\parser.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="use"
|
||||||
|
Filter="">
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\image.cpp">
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Debug Unicode|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Unicode|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Profile Unicode|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
<FileConfiguration
|
||||||
|
Name="Release Unicode fast build|Win32">
|
||||||
|
<Tool
|
||||||
|
Name="VCCLCompilerTool"
|
||||||
|
ObjectFile="$(IntDir)/$(InputName)3.obj"/>
|
||||||
|
</FileConfiguration>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\image.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\script_manager.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\script_manager.hpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\scriptable.cpp">
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\script\scriptable.hpp">
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter
|
<Filter
|
||||||
Name="render"
|
Name="render"
|
||||||
@@ -2836,10 +2876,10 @@
|
|||||||
RelativePath="..\conversion-todo.txt">
|
RelativePath="..\conversion-todo.txt">
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\data\nl.mse-locale\locale">
|
RelativePath="..\data\en.mse-locale\locale">
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\data\en.mse-locale\locale">
|
RelativePath="..\data\nl.mse-locale\locale">
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\main.cpp">
|
RelativePath=".\main.cpp">
|
||||||
|
|||||||
+10
-8
@@ -60,7 +60,7 @@ String tr(const StyleSheet&, const String& key, const String& def);
|
|||||||
String tr(const SymbolFont&, const String& key, const String& def);
|
String tr(const SymbolFont&, const String& key, const String& def);
|
||||||
|
|
||||||
|
|
||||||
/// A localized string for menus/toolbar buttons
|
/// A localized string for menus
|
||||||
#define _MENU_(s) tr(LOCALE_CAT_MENU, _(s))
|
#define _MENU_(s) tr(LOCALE_CAT_MENU, _(s))
|
||||||
/// A localized string for help/statusbar text
|
/// A localized string for help/statusbar text
|
||||||
#define _HELP_(s) tr(LOCALE_CAT_HELP, _(s))
|
#define _HELP_(s) tr(LOCALE_CAT_HELP, _(s))
|
||||||
@@ -81,21 +81,23 @@ String tr(const SymbolFont&, const String& key, const String& def);
|
|||||||
/// A localized string for error messages
|
/// A localized string for error messages
|
||||||
#define _ERROR_(s) tr(LOCALE_CAT_ERROR, _(s))
|
#define _ERROR_(s) tr(LOCALE_CAT_ERROR, _(s))
|
||||||
|
|
||||||
/// A localized string for menus/toolbar buttons, with 1 argument (printf style)
|
/// A localized string for menus, with 1 argument (printf style)
|
||||||
#define _MENU_1_(s,a) format_string(tr(LOCALE_CAT_MENU, _(s)), a)
|
#define _MENU_1_(s,a) format_string(_MENU_(s), a)
|
||||||
|
/// A localized string for context menus, contains no "\tshortcut"
|
||||||
|
#define _CONTEXT_MENU_(s) remove_shortcut(_MENU_(s))
|
||||||
|
|
||||||
/// A localized string for tooltip text, with 1 argument (printf style)
|
/// A localized string for tooltip text, with 1 argument (printf style)
|
||||||
#define _HELP_1_(s,a) format_string(tr(LOCALE_CAT_HELP, _(s)), a)
|
#define _HELP_1_(s,a) format_string(_HELP_(s), a)
|
||||||
|
|
||||||
/// A localized string for tooltip text, with 1 argument (printf style)
|
/// A localized string for tooltip text, with 1 argument (printf style)
|
||||||
#define _TOOLTIP_1_(s,a) format_string(tr(LOCALE_CAT_TOOLTIP, _(s)), a)
|
#define _TOOLTIP_1_(s,a) format_string(_TOOLTIP_(s), a)
|
||||||
|
|
||||||
/// A localized string for error messages, with 1 argument (printf style)
|
/// A localized string for error messages, with 1 argument (printf style)
|
||||||
#define _ERROR_1_(s,a) format_string(tr(LOCALE_CAT_ERROR, _(s)), a)
|
#define _ERROR_1_(s,a) format_string(_ERROR_(s), a)
|
||||||
/// A localized string for error messages, with 2 argument (printf style)
|
/// A localized string for error messages, with 2 argument (printf style)
|
||||||
#define _ERROR_2_(s,a,b) format_string(tr(LOCALE_CAT_ERROR, _(s)), a, b)
|
#define _ERROR_2_(s,a,b) format_string(_ERROR_(s), a, b)
|
||||||
/// A localized string for error messages, with 3 argument (printf style)
|
/// A localized string for error messages, with 3 argument (printf style)
|
||||||
#define _ERROR_3_(s,a,b,c) format_string(tr(LOCALE_CAT_ERROR, _(s)), a, b, c)
|
#define _ERROR_3_(s,a,b,c) format_string(_ERROR_(s), a, b, c)
|
||||||
|
|
||||||
/// Format a string
|
/// Format a string
|
||||||
/** Equivalent to sprintf / String::Format, but allows strings to be passed as arguments (gcc)
|
/** Equivalent to sprintf / String::Format, but allows strings to be passed as arguments (gcc)
|
||||||
|
|||||||
@@ -166,6 +166,12 @@ String singular_form(const String& str) {
|
|||||||
return str.substr(0, str.size() - 1);
|
return str.substr(0, str.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String remove_shortcut(const String& str) {
|
||||||
|
size_t tab = str.find_last_of(_('\t'));
|
||||||
|
if (tab == String::npos) return str;
|
||||||
|
else return str.substr(0, tab);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Comparing / finding
|
// ----------------------------------------------------------------------------- : Comparing / finding
|
||||||
|
|
||||||
bool smart_less(const String& as, const String& bs) {
|
bool smart_less(const String& as, const String& bs) {
|
||||||
|
|||||||
@@ -118,6 +118,11 @@ String cannocial_name_form(const String&);
|
|||||||
*/
|
*/
|
||||||
String singular_form(const String&);
|
String singular_form(const String&);
|
||||||
|
|
||||||
|
/// Remove a shortcut from a menu string
|
||||||
|
/** e.g. "Cut\tCtrl+X" --> "Cut"
|
||||||
|
*/
|
||||||
|
String remove_shortcut(const String&);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : Comparing / finding
|
// ----------------------------------------------------------------------------- : Comparing / finding
|
||||||
|
|
||||||
/// Compare two strings, is the first less than the first?
|
/// Compare two strings, is the first less than the first?
|
||||||
|
|||||||
Reference in New Issue
Block a user