mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Selection in cardlist is correctly moved when changes are made;
cuting/copying/pasting/deleting multiple cards now works. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@888 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -60,8 +60,15 @@ void CardListBase::onChangeSet() {
|
||||
rebuild();
|
||||
}
|
||||
|
||||
struct Freezer{
|
||||
Window* window;
|
||||
Freezer(Window* window) : window(window) { window->Freeze(); }
|
||||
~Freezer() { window->Thaw(); }
|
||||
};
|
||||
|
||||
void CardListBase::onAction(const Action& action, bool undone) {
|
||||
TYPE_CASE(action, AddCardAction) {
|
||||
Freezer freeze(this);
|
||||
if (action.action.adding != undone) {
|
||||
// select the new cards
|
||||
focusNone();
|
||||
@@ -69,21 +76,8 @@ void CardListBase::onAction(const Action& action, bool undone) {
|
||||
refreshList();
|
||||
FOR_EACH_CONST(s, action.action.steps) focusItem(s.item); // focus all the new cards
|
||||
} else {
|
||||
long pos = -1;
|
||||
long pos = selected_item_pos;
|
||||
// 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
|
||||
@@ -129,11 +123,14 @@ void CardListBase::sendEvent() {
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Clipboard
|
||||
|
||||
bool CardListBase::canCopy() const { return !!selected_item; }
|
||||
bool CardListBase::canCut() const { return canCopy() && allowModify(); }
|
||||
bool CardListBase::canCut() const { return canDelete(); }
|
||||
bool CardListBase::canCopy() const { return focusCount() > 0; }
|
||||
bool CardListBase::canPaste() const {
|
||||
return allowModify() && wxTheClipboard->IsSupported(CardsDataObject::format);
|
||||
}
|
||||
bool CardListBase::canDelete() const {
|
||||
return allowModify() && focusCount() > 0; // TODO: check for selection?
|
||||
}
|
||||
|
||||
bool CardListBase::doCopy() {
|
||||
if (!canCopy()) return false;
|
||||
@@ -152,13 +149,6 @@ bool CardListBase::doCopy() {
|
||||
wxTheClipboard->Close();
|
||||
return ok;
|
||||
}
|
||||
bool CardListBase::doCut() {
|
||||
// cut = copy + delete
|
||||
if (!canCut()) return false;
|
||||
if (!doCopy()) return false;
|
||||
doDelete();
|
||||
return true;
|
||||
}
|
||||
bool CardListBase::doPaste() {
|
||||
// get data
|
||||
if (!canPaste()) return false;
|
||||
|
||||
@@ -64,11 +64,11 @@ class CardListBase : public ItemList, public SetView {
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
bool canCut() const;
|
||||
bool canCopy() const;
|
||||
bool canPaste() const;
|
||||
bool canCut() const;
|
||||
bool canCopy() const;
|
||||
bool canPaste() const;
|
||||
bool canDelete() const;
|
||||
// Try to perform a clipboard operation, return success
|
||||
bool doCut();
|
||||
bool doCopy();
|
||||
bool doPaste();
|
||||
bool doDelete();
|
||||
|
||||
@@ -46,6 +46,14 @@ void ItemList::selectFirst() {
|
||||
selectItemPos(0, true);
|
||||
}
|
||||
|
||||
bool ItemList::doCut() {
|
||||
// cut = copy + delete
|
||||
if (!canCut()) return false;
|
||||
if (!doCopy()) return false;
|
||||
doDelete();
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ItemList : Selection (private)
|
||||
|
||||
void ItemList::selectItem(const VoidP& item, bool focus, bool event) {
|
||||
@@ -109,6 +117,14 @@ void ItemList::focusItem(const VoidP& item, bool focus) {
|
||||
}
|
||||
}
|
||||
}
|
||||
long ItemList::focusCount() const {
|
||||
long count = GetItemCount();
|
||||
long focused = 0;
|
||||
for (long pos = 0 ; pos < count ; ++pos) {
|
||||
if (const_cast<ItemList*>(this)->IsSelected(pos)) focused++;
|
||||
}
|
||||
return focused;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : ItemList : Building the list
|
||||
|
||||
@@ -127,6 +143,7 @@ struct ItemList::ItemComparer {
|
||||
};
|
||||
|
||||
void ItemList::refreshList() {
|
||||
Freeze();
|
||||
// Get all items
|
||||
sorted_list.clear();
|
||||
getItems(sorted_list);
|
||||
@@ -141,7 +158,9 @@ void ItemList::refreshList() {
|
||||
if (item_count == 0) Refresh();
|
||||
// (re)select current item
|
||||
findSelectedItemPos();
|
||||
focusSelectedItem();
|
||||
focusNone();
|
||||
focusSelectedItem(true);
|
||||
Thaw();
|
||||
}
|
||||
|
||||
void ItemList::sortBy(long column, bool ascending) {
|
||||
|
||||
@@ -46,7 +46,7 @@ class ItemList : public wxListView {
|
||||
virtual bool canPaste() const { return false; }
|
||||
virtual bool canDelete() const { return false; }
|
||||
// Try to perform a clipboard operation, return success
|
||||
virtual bool doCut() { return false; }
|
||||
virtual bool doCut();
|
||||
virtual bool doCopy() { return false; }
|
||||
virtual bool doPaste() { return false; }
|
||||
virtual bool doDelete() { return false; }
|
||||
@@ -90,6 +90,8 @@ class ItemList : public wxListView {
|
||||
void focusNone();
|
||||
/// Actually select a certain item in the control
|
||||
void focusItem(const VoidP& item, bool focus = true);
|
||||
/// Count the number of focused items
|
||||
long focusCount() const;
|
||||
|
||||
// --------------------------------------------------- : Data
|
||||
VoidP selected_item; ///< The currently selected item
|
||||
|
||||
@@ -168,7 +168,7 @@ void CardsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
break;
|
||||
}
|
||||
case ID_CARD_ADD_MULT: ev.Enable(false); break; // not implemented
|
||||
case ID_CARD_REMOVE: ev.Enable(set->cards.size() > 1); break;
|
||||
case ID_CARD_REMOVE: ev.Enable(card_list->canDelete()); break;
|
||||
case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: case ID_FORMAT_REMINDER: {
|
||||
if (focused_control(this) == ID_EDITOR) {
|
||||
ev.Enable(editor->canFormat(ev.GetId()));
|
||||
|
||||
Reference in New Issue
Block a user