Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
2b333fc9
Commit
2b333fc9
authored
Oct 20, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added 'undone' parameter to onAction
parent
53783d4c
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
93 additions
and
55 deletions
+93
-55
src/data/action/set.cpp
src/data/action/set.cpp
+3
-5
src/data/action/set.hpp
src/data/action/set.hpp
+7
-7
src/data/set.hpp
src/data/set.hpp
+1
-1
src/data/symbol.hpp
src/data/symbol.hpp
+1
-1
src/gui/control/card_list.cpp
src/gui/control/card_list.cpp
+57
-20
src/gui/control/card_list.hpp
src/gui/control/card_list.hpp
+4
-4
src/gui/set/cards_panel.cpp
src/gui/set/cards_panel.cpp
+2
-2
src/gui/set/cards_panel.hpp
src/gui/set/cards_panel.hpp
+2
-2
src/gui/set/panel.hpp
src/gui/set/panel.hpp
+2
-2
src/gui/set/window.cpp
src/gui/set/window.cpp
+1
-1
src/gui/set/window.hpp
src/gui/set/window.hpp
+1
-1
src/gui/symbol/control.cpp
src/gui/symbol/control.cpp
+1
-1
src/gui/symbol/control.hpp
src/gui/symbol/control.hpp
+1
-1
src/gui/symbol/part_list.cpp
src/gui/symbol/part_list.cpp
+1
-1
src/gui/symbol/part_list.hpp
src/gui/symbol/part_list.hpp
+1
-1
src/util/action_stack.cpp
src/util/action_stack.cpp
+5
-3
src/util/action_stack.hpp
src/util/action_stack.hpp
+3
-2
No files found.
src/data/action/set.cpp
View file @
2b333fc9
...
...
@@ -39,12 +39,10 @@ void AddCardAction::perform(bool to_undo) {
RemoveCardAction
::
RemoveCardAction
(
Set
&
set
,
const
CardP
&
card
)
:
CardListAction
(
set
),
card
(
card
)
{
// find the card_id of the card we want to remove
vector
<
CardP
>::
iterator
it
=
find
(
set
.
cards
.
begin
(),
set
.
cards
.
end
(),
card
);
if
(
it
!=
set
.
cards
.
end
())
{
card_id
=
it
-
set
.
cards
.
begin
();
}
else
{
,
card_id
(
find
(
set
.
cards
.
begin
(),
set
.
cards
.
end
(),
card
)
-
set
.
cards
.
begin
())
{
if
(
card_id
>=
set
.
cards
.
size
())
{
throw
InternalError
(
_
(
"Card to remove not found in set"
));
}
}
...
...
src/data/action/set.hpp
View file @
2b333fc9
...
...
@@ -40,8 +40,8 @@ class AddCardAction : public CardListAction {
virtual
String
getName
(
bool
to_undo
)
const
;
virtual
void
perform
(
bool
to_undo
);
private:
CardP
card
;
///< The new card
//
private:
const
CardP
card
;
///< The new card
};
// ----------------------------------------------------------------------------- : Remove card
...
...
@@ -54,9 +54,9 @@ class RemoveCardAction : public CardListAction {
virtual
String
getName
(
bool
to_undo
)
const
;
virtual
void
perform
(
bool
to_undo
);
private:
CardP
card
;
///< The removed card
size_t
card_id
;
///< Position of the card in the set
//
private:
const
CardP
card
;
///< The removed card
const
size_t
card_id
;
///< Position of the card in the set
};
// ----------------------------------------------------------------------------- : Reorder cards
...
...
@@ -69,8 +69,8 @@ class ReorderCardsAction : public CardListAction {
virtual
String
getName
(
bool
to_undo
)
const
;
virtual
void
perform
(
bool
to_undo
);
private:
size_t
card_id1
,
card_id2
;
///< Positions of the two cards to swap
//
private:
const
size_t
card_id1
,
card_id2
;
///< Positions of the two cards to swap
};
// ----------------------------------------------------------------------------- : EOF
...
...
src/data/set.hpp
View file @
2b333fc9
...
...
@@ -55,7 +55,7 @@ class Set : public Packaged {
// ----------------------------------------------------------------------------- : SetView
/// A 'view' of a Set, is notified when the Set is updated
/** To listen to events, derived classes should override onAction(const Action&)
/** To listen to events, derived classes should override onAction(const Action&
, bool undone
)
*/
class
SetView
:
public
ActionListener
{
public:
...
...
src/data/symbol.hpp
View file @
2b333fc9
...
...
@@ -166,7 +166,7 @@ class Symbol {
// ----------------------------------------------------------------------------- : SymbolView
/// A 'view' of a symbol, is notified when the symbol is updated
/** To listen to events, derived classes should override onAction(const Action&)
/** To listen to events, derived classes should override onAction(const Action&
, bool undone
)
*/
class
SymbolView
:
public
ActionListener
{
public:
...
...
src/gui/control/card_list.cpp
View file @
2b333fc9
...
...
@@ -13,6 +13,7 @@
#include <data/set.hpp>
#include <data/card.hpp>
#include <data/settings.hpp>
#include <data/action/set.hpp>
#include <util/window_id.hpp>
DECLARE_TYPEOF_COLLECTION
(
CardP
);
...
...
@@ -47,8 +48,44 @@ void CardListBase::onBeforeChangeSet() {
void
CardListBase
::
onChangeSet
()
{
rebuild
();
}
void
CardListBase
::
onAction
(
const
Action
&
action
)
{
// TODO
void
CardListBase
::
onAction
(
const
Action
&
action
,
bool
undone
)
{
TYPE_CASE
(
action
,
AddCardAction
)
{
// select the new card
selectCard
(
action
.
card
,
false
/*list will be refreshed anyway*/
);
refreshList
();
}
TYPE_CASE
(
action
,
RemoveCardAction
)
{
if
(
undone
)
{
// select the re-added card
selectCard
(
action
.
card
,
false
/*list will be refreshed anyway*/
);
refreshList
();
}
else
{
long
pos
=
selected_card_pos
;
refreshList
();
if
(
action
.
card
==
selected_card
)
{
// select the next card, if not possible, select the last
if
((
size_t
)
pos
+
1
<
sorted_card_list
.
size
())
{
selectCardPos
(
pos
,
true
);
}
else
{
selectCardPos
((
long
)
sorted_card_list
.
size
()
-
1
,
true
);
}
}
}
}
TYPE_CASE
(
action
,
ReorderCardsAction
)
{
if
(
sort_criterium
)
return
;
// nothing changes for us
if
((
long
)
action
.
card_id1
==
selected_card_pos
||
(
long
)
action
.
card_id2
==
selected_card_pos
)
{
// Selected card has moved; also move in the sorted card list
swap
(
sorted_card_list
[
action
.
card_id1
]
,
sorted_card_list
[
action
.
card_id2
]);
// 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
;
// select the right card
selectCurrentCard
();
}
RefreshItem
((
long
)
action
.
card_id1
);
RefreshItem
((
long
)
action
.
card_id2
);
}
}
vector
<
CardP
>&
CardListBase
::
getCards
()
const
{
...
...
@@ -58,16 +95,18 @@ vector<CardP>& CardListBase::getCards() const {
// ----------------------------------------------------------------------------- : CardListBase : Selection
bool
CardListBase
::
canSelectPrevious
()
const
{
return
selected_card_pos
+
1
>=
0
;
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
()
{
// TODO
assert
(
selected_card_pos
>=
1
);
selectCardPos
(
selected_card_pos
-
1
,
true
);
}
void
CardListBase
::
selectNext
()
{
// TODO
assert
(
selected_card_pos
+
1
<
(
long
)
sorted_card_list
.
size
());
selectCardPos
(
selected_card_pos
+
1
,
true
);
}
// ----------------------------------------------------------------------------- : CardListBase : Selection (private)
...
...
@@ -81,19 +120,19 @@ void CardListBase::selectCard(const CardP& card, bool focus) {
selectCurrentCard
();
}
}
/*
void CardListBase::selectCardPos(
size_t pos, bool focus = true, bool force = false
) {
if (selected
CardPos == pos && !force
) return; // this card is already selected
if (
pos < sortedCardL
ist.size()) {
void
CardListBase
::
selectCardPos
(
long
pos
,
bool
focus
)
{
if
(
selected
_card_pos
==
pos
&&
!
focus
)
return
;
// this card is already selected
if
(
(
size_t
)
pos
<
sorted_card_l
ist
.
size
())
{
// only if there is something to select
selectCard(
getCard(pos)
, false);
selectCard
(
sorted_card_list
[
pos
]
,
false
);
}
else
{
selectCard
(
CardP
(),
false
);
}
selected
CardPos = Long(pos)
;
if (focus)
selectCurrentCard();
selected
_card_pos
=
pos
;
if
(
focus
)
selectCurrentCard
();
}
*/
void
CardListBase
::
findSelectedCardPos
()
{
// find the position of the selected card
long
count
=
GetItemCount
();
...
...
@@ -107,7 +146,7 @@ void CardListBase::findSelectedCardPos() {
}
void
CardListBase
::
selectCurrentCard
()
{
if
(
GetItemCount
()
>
0
)
{
if
(
selected_card_pos
==
-
1
)
{
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
);
...
...
@@ -190,9 +229,7 @@ void CardListBase::rebuild() {
}
refreshList
();
// select a card if possible
// if (!getCards().empty()) {
// selectCardPos(0, true);
// }
selectCardPos
(
0
,
true
);
}
void
CardListBase
::
refreshList
()
{
...
...
@@ -273,7 +310,7 @@ 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
sort_ascending
=
false
;
// 2nd click on same column -> sort descending
}
else
{
new_sort_criterium
.
reset
();
// 3rd click on same column -> don't sort
}
...
...
@@ -306,12 +343,12 @@ void CardListBase::onSelectColumns(wxCommandEvent&) {
}
void
CardListBase
::
onItemFocus
(
wxListEvent
&
ev
)
{
//
selectCardPos(ev.GetIndex(), false);
selectCardPos
(
ev
.
GetIndex
(),
false
);
}
void
CardListBase
::
onChar
(
wxKeyEvent
&
ev
)
{
if
(
ev
.
GetKeyCode
()
==
WXK_DELETE
)
{
// set->actions.add(new_shared2<RemoveCardAction>(set.get(),
card));
set
->
actions
.
add
(
new
RemoveCardAction
(
*
set
,
selected_
card
));
}
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
...
...
src/gui/control/card_list.hpp
View file @
2b333fc9
...
...
@@ -50,7 +50,7 @@ class CardListBase : public wxListView, public SetView {
// --------------------------------------------------- : Selection
inline
CardP
getCard
()
const
{
return
selected_card
;
}
inline
void
setCard
(
const
CardP
&
card
)
{
selectCard
(
card
);
}
inline
void
setCard
(
const
CardP
&
card
)
{
selectCard
(
card
,
true
);
}
/// Is there a previous card to select?
bool
canSelectPrevious
()
const
;
...
...
@@ -74,7 +74,7 @@ class CardListBase : public wxListView, public SetView {
virtual
void
onBeforeChangeSet
();
virtual
void
onChangeSet
();
virtual
void
onAction
(
const
Action
&
);
virtual
void
onAction
(
const
Action
&
,
bool
undone
);
// --------------------------------------------------- : The cards
protected:
...
...
@@ -113,9 +113,9 @@ class CardListBase : public wxListView, public SetView {
/** 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
=
false
);
void
selectCard
(
const
CardP
&
card
,
bool
focus
);
/// Select a card at the specified position
void
selectCardPos
(
long
pos
);
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
...
...
src/gui/set/cards_panel.cpp
View file @
2b333fc9
...
...
@@ -186,11 +186,11 @@ void CardsPanel::onCommand(int id) {
// ----------------------------------------------------------------------------- : Actions
bool
CardsPanel
::
wantsToHandle
(
const
Action
&
)
const
{
bool
CardsPanel
::
wantsToHandle
(
const
Action
&
,
bool
undone
)
const
{
return
false
;
}
void
CardsPanel
::
onAction
(
const
Action
&
action
)
{
void
CardsPanel
::
onAction
(
const
Action
&
action
,
bool
undo
)
{
// TODO
}
...
...
src/gui/set/cards_panel.hpp
View file @
2b333fc9
...
...
@@ -34,8 +34,8 @@ class CardsPanel : public SetWindowPanel {
// --------------------------------------------------- : Actions
virtual
bool
wantsToHandle
(
const
Action
&
)
const
;
virtual
void
onAction
(
const
Action
&
);
virtual
bool
wantsToHandle
(
const
Action
&
,
bool
undone
)
const
;
virtual
void
onAction
(
const
Action
&
,
bool
undone
);
virtual
void
onRenderSettingsChange
();
private:
void
updateSize
();
...
...
src/gui/set/panel.hpp
View file @
2b333fc9
...
...
@@ -46,9 +46,9 @@ class SetWindowPanel : public wxPanel, public SetView {
// --------------------------------------------------- : Actions/Events
/// Should return true if this panel wants to get focus to show an action
virtual
bool
wantsToHandle
(
const
Action
&
)
const
{
return
false
;
}
virtual
bool
wantsToHandle
(
const
Action
&
,
bool
undone
)
const
{
return
false
;
}
/// Handle an action that changes the current set
virtual
void
onAction
(
const
Action
&
)
{}
virtual
void
onAction
(
const
Action
&
,
bool
undone
)
{}
/// The settings for rendering cards have changed, refresh card viewers/editors
virtual
void
onRenderSettingsChange
()
{}
...
...
src/gui/set/window.cpp
View file @
2b333fc9
...
...
@@ -234,7 +234,7 @@ void SetWindow::onChangeSet() {
fixMinWindowSize
();
}
void
SetWindow
::
onAction
(
const
Action
&
action
)
{
void
SetWindow
::
onAction
(
const
Action
&
action
,
bool
undone
)
{
// TYPE_CASE_(action, SetStyleChange) {
// // The style changed, maybe also the size of the viewer
// Layout();
...
...
src/gui/set/window.hpp
View file @
2b333fc9
...
...
@@ -80,7 +80,7 @@ class SetWindow : public wxFrame, public SetView {
/// We want to respond to set changes
virtual
void
onChangeSet
();
/// Actions that change the set
virtual
void
onAction
(
const
Action
&
);
virtual
void
onAction
(
const
Action
&
,
bool
undone
);
private:
/// A different card has been selected
...
...
src/gui/symbol/control.cpp
View file @
2b333fc9
...
...
@@ -68,7 +68,7 @@ void SymbolControl::onExtraTool(wxCommandEvent& ev) {
if
(
editor
)
editor
->
onCommand
(
ev
.
GetId
());
}
void
SymbolControl
::
onAction
(
const
Action
&
action
)
{
void
SymbolControl
::
onAction
(
const
Action
&
action
,
bool
undone
)
{
TYPE_CASE_
(
action
,
SymbolPartAction
)
{
Refresh
(
false
);
}
...
...
src/gui/symbol/control.hpp
View file @
2b333fc9
...
...
@@ -28,7 +28,7 @@ class SymbolControl : public wxControl, public SymbolViewer {
virtual
void
onChangeSymbol
();
virtual
void
onAction
(
const
Action
&
);
virtual
void
onAction
(
const
Action
&
,
bool
undone
);
// Forward command to editor
void
onExtraTool
(
wxCommandEvent
&
ev
);
...
...
src/gui/symbol/part_list.cpp
View file @
2b333fc9
...
...
@@ -39,7 +39,7 @@ void SymbolPartList::onChangeSymbol() {
update
();
}
void
SymbolPartList
::
onAction
(
const
Action
&
action
)
{
void
SymbolPartList
::
onAction
(
const
Action
&
action
,
bool
undone
)
{
TYPE_CASE
(
action
,
ReorderSymbolPartsAction
)
{
if
(
selected
==
(
long
)
action
.
part_id1
)
{
selectItem
((
long
)
action
.
part_id2
);
...
...
src/gui/symbol/part_list.hpp
View file @
2b333fc9
...
...
@@ -39,7 +39,7 @@ class SymbolPartList : public wxListCtrl, public SymbolView {
void
onChangeSymbol
();
/// Event handler for changes to the symbol
virtual
void
onAction
(
const
Action
&
a
);
virtual
void
onAction
(
const
Action
&
a
,
bool
undone
);
protected:
/// Get the text of an item
...
...
src/util/action_stack.cpp
View file @
2b333fc9
...
...
@@ -29,7 +29,7 @@ void ActionStack::add(Action* action, bool allow_merge) {
if
(
!
action
)
return
;
// no action
action
->
perform
(
false
);
// TODO: delete action if perform throws
redo_actions
.
clear
();
tellListeners
(
*
action
);
tellListeners
(
*
action
,
false
);
// try to merge?
if
(
allow_merge
&&
!
undo_actions
.
empty
()
&&
undo_actions
.
back
()
->
merge
(
action
))
{
// merged with top undo action
...
...
@@ -43,6 +43,7 @@ void ActionStack::undo() {
assert
(
canUndo
());
Action
*
action
=
undo_actions
.
back
();
action
->
perform
(
true
);
tellListeners
(
*
action
,
true
);
// move to redo stack
undo_actions
.
pop_back
();
redo_actions
.
push_back
(
action
);
...
...
@@ -51,6 +52,7 @@ void ActionStack::redo() {
assert
(
canRedo
());
Action
*
action
=
redo_actions
.
back
();
action
->
perform
(
false
);
tellListeners
(
*
action
,
false
);
// move to undo stack
redo_actions
.
pop_back
();
undo_actions
.
push_back
(
action
);
...
...
@@ -103,6 +105,6 @@ void ActionStack::removeListener(ActionListener* listener) {
listeners
.
end
()
);
}
void
ActionStack
::
tellListeners
(
const
Action
&
action
)
{
FOR_EACH
(
l
,
listeners
)
l
->
onAction
(
action
);
void
ActionStack
::
tellListeners
(
const
Action
&
action
,
bool
undone
)
{
FOR_EACH
(
l
,
listeners
)
l
->
onAction
(
action
,
undone
);
}
src/util/action_stack.hpp
View file @
2b333fc9
...
...
@@ -47,7 +47,8 @@ class Action {
/// Base class/interface for objects that listen to actions
class
ActionListener
{
public:
virtual
void
onAction
(
const
Action
&
a
)
=
0
;
/// Notification that an action a has been performed or undone
virtual
void
onAction
(
const
Action
&
a
,
bool
undone
)
=
0
;
};
// ----------------------------------------------------------------------------- : Action stack
...
...
@@ -98,7 +99,7 @@ class ActionStack {
/// Remove an action listener
void
removeListener
(
ActionListener
*
listener
);
/// Tell all listeners about an action
void
tellListeners
(
const
Action
&
);
void
tellListeners
(
const
Action
&
,
bool
undone
);
private:
/// Actions to be undone
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment