mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-11 05:07:00 -04:00
Allow multiple cards to be selected in a card list,
Allow card actions to add/remove multiple cards. not yet: actually use these multicard actions. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@853 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -41,7 +41,7 @@ DEFINE_EVENT_TYPE(EVENT_CARD_ACTIVATE);
|
||||
vector<CardListBase*> CardListBase::card_lists;
|
||||
|
||||
CardListBase::CardListBase(Window* parent, int id, long additional_style)
|
||||
: ItemList(parent, id, additional_style)
|
||||
: ItemList(parent, id, additional_style, true)
|
||||
{
|
||||
// add to the list of card lists
|
||||
card_lists.push_back(this);
|
||||
@@ -62,38 +62,36 @@ void CardListBase::onChangeSet() {
|
||||
|
||||
void CardListBase::onAction(const Action& action, bool undone) {
|
||||
TYPE_CASE(action, AddCardAction) {
|
||||
if (undone) {
|
||||
if (action.action.adding != undone) {
|
||||
// select the new cards
|
||||
focusNone();
|
||||
selectItem(action.action.steps.front().item, false, true);
|
||||
refreshList();
|
||||
if (!allowModify()) {
|
||||
// Let some other card list else do the selecting
|
||||
return;
|
||||
}
|
||||
selectItemPos(GetItemCount() - 1, true);
|
||||
FOR_EACH_CONST(s, action.action.steps) focusItem(s.item); // focus all the new cards
|
||||
} else {
|
||||
// select the new card
|
||||
selectItem(action.card, false /*list will be refreshed anyway*/, true);
|
||||
refreshList();
|
||||
}
|
||||
}
|
||||
TYPE_CASE(action, RemoveCardAction) {
|
||||
if (undone) {
|
||||
// select the re-added card
|
||||
selectItem(action.card, false /*list will be refreshed anyway*/, true);
|
||||
refreshList();
|
||||
} else {
|
||||
long pos = selected_item_pos;
|
||||
refreshList();
|
||||
if (!allowModify()) {
|
||||
// Let some other card list else do the selecting
|
||||
return;
|
||||
}
|
||||
if (action.card == selected_item) {
|
||||
// select the next card, if not possible, select the last
|
||||
if (pos + 1 < GetItemCount()) {
|
||||
selectItemPos(pos, true);
|
||||
} else {
|
||||
selectItemPos(GetItemCount() - 1, true);
|
||||
long pos = -1;
|
||||
// adjust focus for all the removed cards
|
||||
//FOR_EACH_CONST(s, action.action.steps) focusItem(s.item, false);
|
||||
long count = GetItemCount();
|
||||
long delta = 0;
|
||||
for (long i = 0 ; i < count ; ++i) {
|
||||
if (delta < (long)action.action.steps.size() && getItem(i) == action.action.steps[delta].item) {
|
||||
Select(i - delta, false);
|
||||
delta++;
|
||||
} else if (delta > 0) {
|
||||
Select(i - delta, IsSelected(i));
|
||||
}
|
||||
if (pos == -1 && IsSelected(i - delta)) pos = i - delta;
|
||||
}
|
||||
if (pos == -1) pos = selected_item_pos; // select next item if selection would become empty
|
||||
refreshList();
|
||||
if (!allowModify()) {
|
||||
// Let some other card list do the selecting, otherwise we get conflicting events
|
||||
return;
|
||||
}
|
||||
if (selected_item_pos == -1) {
|
||||
// selected item was deleted, select something else
|
||||
selectItemPos(pos, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -105,7 +103,7 @@ void CardListBase::onAction(const Action& action, bool undone) {
|
||||
// reselect the current card, it has moved
|
||||
selected_item_pos = (long)action.card_id1 == selected_item_pos ? (long)action.card_id2 : (long)action.card_id1;
|
||||
// select the right card
|
||||
selectCurrentItem();
|
||||
focusSelectedItem();
|
||||
}
|
||||
RefreshItem((long)action.card_id1);
|
||||
RefreshItem((long)action.card_id2);
|
||||
@@ -148,7 +146,7 @@ bool CardListBase::doCut() {
|
||||
// cut = copy + delete
|
||||
if (!canCut()) return false;
|
||||
if (!doCopy()) return false;
|
||||
set->actions.add(new RemoveCardAction(*set, getCard()));
|
||||
doDelete();
|
||||
return true;
|
||||
}
|
||||
bool CardListBase::doPaste() {
|
||||
@@ -162,12 +160,17 @@ bool CardListBase::doPaste() {
|
||||
// add card to set
|
||||
CardP card = data.getCard(set);
|
||||
if (card) {
|
||||
set->actions.add(new AddCardAction(*set, card));
|
||||
set->actions.add(new AddCardAction(ADD, *set, card));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool CardListBase::doDelete() {
|
||||
//vector<>
|
||||
set->actions.add(new AddCardAction(REMOVE, *set, getCard()));
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Building the list
|
||||
|
||||
@@ -310,7 +313,7 @@ void CardListBase::onSelectColumns(wxCommandEvent&) {
|
||||
|
||||
void CardListBase::onChar(wxKeyEvent& ev) {
|
||||
if (ev.GetKeyCode() == WXK_DELETE && allowModify()) {
|
||||
set->actions.add(new RemoveCardAction(*set, getCard()));
|
||||
doDelete();
|
||||
} else if (ev.GetKeyCode() == WXK_TAB) {
|
||||
// send a navigation event to our parent, to select another control
|
||||
// we need this because tabs are not handled on the cards panel
|
||||
|
||||
@@ -71,6 +71,7 @@ class CardListBase : public ItemList, public SetView {
|
||||
bool doCut();
|
||||
bool doCopy();
|
||||
bool doPaste();
|
||||
bool doDelete();
|
||||
|
||||
// --------------------------------------------------- : Set actions
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : ItemList
|
||||
|
||||
ItemList::ItemList(Window* parent, int id, long additional_style)
|
||||
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | wxLC_SINGLE_SEL)
|
||||
ItemList::ItemList(Window* parent, int id, long additional_style, bool multi_sel)
|
||||
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | (multi_sel ? 0 : wxLC_SINGLE_SEL))
|
||||
, selected_item_pos(-1)
|
||||
, sort_by_column(-1), sort_ascending(true)
|
||||
{
|
||||
@@ -52,21 +52,23 @@ void ItemList::selectItem(const VoidP& item, bool focus, bool event) {
|
||||
selected_item = item;
|
||||
if (event) sendEvent();
|
||||
findSelectedItemPos();
|
||||
if (focus) {
|
||||
selectCurrentItem();
|
||||
}
|
||||
if (focus) focusSelectedItem();
|
||||
}
|
||||
|
||||
void ItemList::selectItemPos(long pos, bool focus) {
|
||||
if (selected_item_pos == pos && !focus) return; // this item is already selected
|
||||
void ItemList::selectItemPos(long pos, bool focus, bool force_focus) {
|
||||
VoidP item;
|
||||
if ((size_t)pos < sorted_list.size()) {
|
||||
// only if there is something to select
|
||||
selectItem(getItem(pos), false, true);
|
||||
item = getItem(pos);
|
||||
} else if (!sorted_list.empty()) {
|
||||
item = sorted_list.back();
|
||||
} else {
|
||||
selectItem(VoidP(), false, true);
|
||||
// clear selection
|
||||
}
|
||||
selected_item_pos = pos;
|
||||
if (focus) selectCurrentItem();
|
||||
if (item != selected_item) {
|
||||
selectItem(item, false, true);
|
||||
}
|
||||
//!selected_item_pos = pos;
|
||||
if (focus) focusSelectedItem(force_focus);
|
||||
}
|
||||
|
||||
void ItemList::findSelectedItemPos() {
|
||||
@@ -80,18 +82,33 @@ void ItemList::findSelectedItemPos() {
|
||||
}
|
||||
}
|
||||
}
|
||||
void ItemList::selectCurrentItem() {
|
||||
void ItemList::focusSelectedItem(bool force_focus) {
|
||||
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 {
|
||||
} else if (selected_item_pos != GetFocusedItem() || force_focus) {
|
||||
Select(selected_item_pos);
|
||||
Focus (selected_item_pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
void ItemList::focusNone() {
|
||||
long count = GetItemCount();
|
||||
for (long pos = 0 ; pos < count ; ++pos) {
|
||||
Select(pos, false);
|
||||
}
|
||||
}
|
||||
void ItemList::focusItem(const VoidP& item, bool focus) {
|
||||
long count = GetItemCount();
|
||||
for (long pos = 0 ; pos < count ; ++pos) {
|
||||
if (getItem(pos) == item) {
|
||||
Select(pos, focus);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ItemList : Building the list
|
||||
|
||||
@@ -124,7 +141,7 @@ void ItemList::refreshList() {
|
||||
if (item_count == 0) Refresh();
|
||||
// (re)select current item
|
||||
findSelectedItemPos();
|
||||
selectCurrentItem();
|
||||
focusSelectedItem();
|
||||
}
|
||||
|
||||
void ItemList::sortBy(long column, bool ascending) {
|
||||
|
||||
@@ -17,10 +17,14 @@
|
||||
/// A generic list of items
|
||||
/** The list is shown in report mode, and allows sorting.
|
||||
* Currently used for cards and keywords.
|
||||
*
|
||||
* Terminology:
|
||||
* selected item = a single item in the variable selected_item
|
||||
* focused items = items that are drawn as selected in the control
|
||||
*/
|
||||
class ItemList : public wxListView {
|
||||
public:
|
||||
ItemList(Window* parent, int id, long additional_style = 0);
|
||||
ItemList(Window* parent, int id, long additional_style = 0, bool multi_sel = false);
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
|
||||
@@ -72,15 +76,20 @@ class ItemList : public wxListView {
|
||||
|
||||
/// 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).
|
||||
* This should 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);
|
||||
void selectItemPos(long pos, bool focus, bool force_focus = false);
|
||||
/// Find the position for the selected_item
|
||||
void findSelectedItemPos();
|
||||
/// Actually select the card at selected_item_pos in the control
|
||||
void selectCurrentItem();
|
||||
/// Actually select the item at selected_item_pos in the control
|
||||
/** if force_focus == true, then the item is highlighted again if it already is focused. */
|
||||
void focusSelectedItem(bool force_focus = false);
|
||||
/// Deselect everything in the control
|
||||
void focusNone();
|
||||
/// Actually select a certain item in the control
|
||||
void focusItem(const VoidP& item, bool focus = true);
|
||||
|
||||
// --------------------------------------------------- : Data
|
||||
VoidP selected_item; ///< The currently selected item
|
||||
|
||||
@@ -57,10 +57,10 @@ void KeywordList::onChangeSet() {
|
||||
}
|
||||
|
||||
void KeywordList::onAction(const Action& action, bool undone) {
|
||||
TYPE_CASE(action, AddKeywordAction) {
|
||||
/*TYPE_CASE(action, AddKeywordAction) {
|
||||
if (action.adding != undone) {
|
||||
// select the new keyword
|
||||
selectItem(action.keyword, false /*list will be refreshed anyway*/, true);
|
||||
selectItem(action.keyword, false /*list will be refreshed anyway* /, true);
|
||||
refreshList();
|
||||
} else {
|
||||
long pos = selected_item_pos;
|
||||
@@ -74,7 +74,7 @@ void KeywordList::onAction(const Action& action, bool undone) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/ // TODO!!!
|
||||
TYPE_CASE(action, ValueAction) {
|
||||
if (!action.card) {
|
||||
KeywordTextValue* value = dynamic_cast<KeywordTextValue*>(action.valueP.get());
|
||||
@@ -117,7 +117,7 @@ bool KeywordList::doCut() {
|
||||
// cut = copy + delete
|
||||
if (!canCut()) return false;
|
||||
if (!doCopy()) return false;
|
||||
set->actions.add(new AddKeywordAction(REMOVE, *set, getKeyword()));
|
||||
doDelete();
|
||||
return true;
|
||||
}
|
||||
bool KeywordList::doPaste() {
|
||||
@@ -137,6 +137,10 @@ bool KeywordList::doPaste() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
bool KeywordList::doDelete() {
|
||||
set->actions.add(new AddKeywordAction(REMOVE, *set, getKeyword()));
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : KeywordListBase : for ItemList
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ class KeywordList : public ItemList, public SetView {
|
||||
bool doCut();
|
||||
bool doCopy();
|
||||
bool doPaste();
|
||||
bool doDelete();
|
||||
|
||||
// --------------------------------------------------- : The keywords
|
||||
protected:
|
||||
|
||||
Reference in New Issue
Block a user