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
041c87a7
Commit
041c87a7
authored
May 18, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Copy/pasting multiple cards
parent
b7fd8888
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
46 deletions
+79
-46
src/data/format/clipboard.cpp
src/data/format/clipboard.cpp
+39
-25
src/data/format/clipboard.hpp
src/data/format/clipboard.hpp
+9
-8
src/gui/control/card_list.cpp
src/gui/control/card_list.cpp
+30
-12
src/gui/value/image.cpp
src/gui/value/image.cpp
+1
-1
No files found.
src/data/format/clipboard.cpp
View file @
041c87a7
...
...
@@ -39,50 +39,62 @@ void deserialize_from_clipboard(T& object, Package& package, const String& data)
// ----------------------------------------------------------------------------- : CardDataObject
/// A wrapped card for storing on the clipboard
struct
WrappedCard
{
Game
*
expected_game
;
String
game_name
;
CardP
card
;
/// A wrapped card
s
for storing on the clipboard
struct
WrappedCard
s
{
Game
*
expected_game
;
String
game_name
;
vector
<
CardP
>
cards
;
DECLARE_REFLECTION
();
};
IMPLEMENT_REFLECTION
(
WrappedCard
)
{
IMPLEMENT_REFLECTION
(
WrappedCard
s
)
{
REFLECT
(
game_name
);
if
(
game_name
==
expected_game
->
name
())
{
WITH_DYNAMIC_ARG
(
game_for_reading
,
expected_game
);
REFLECT
(
card
);
REFLECT
(
card
s
);
}
}
wxDataFormat
Card
DataObject
::
format
=
_
(
"application/x-mse-card
"
);
wxDataFormat
Card
sDataObject
::
format
=
_
(
"application/x-mse-cards
"
);
CardDataObject
::
CardDataObject
(
const
SetP
&
set
,
const
CardP
&
card
)
{
WrappedCard
data
=
{
set
->
game
.
get
(),
set
->
game
->
name
(),
card
};
bool
has_styling
=
card
->
has_styling
&&
!
card
->
stylesheet
;
if
(
has_styling
)
{
// set the stylsheet, so when deserializing we know whos style options we are reading
card
->
stylesheet
=
set
->
stylesheet
;
CardsDataObject
::
CardsDataObject
(
const
SetP
&
set
,
const
vector
<
CardP
>&
cards
)
{
// set the stylesheet, so when deserializing we know whos style options we are reading
bool
*
has_styling
=
new
bool
[
cards
.
size
()];
for
(
size_t
i
=
0
;
i
<
cards
.
size
()
;
++
i
)
{
has_styling
[
i
]
=
cards
[
i
]
->
has_styling
&&
!
cards
[
i
]
->
stylesheet
;
if
(
has_styling
[
i
])
{
cards
[
i
]
->
stylesheet
=
set
->
stylesheet
;
}
}
WrappedCards
data
=
{
set
->
game
.
get
(),
set
->
game
->
name
(),
cards
};
SetText
(
serialize_for_clipboard
(
*
set
,
data
));
if
(
has_styling
)
{
card
->
stylesheet
=
StyleSheetP
();
// restore card
// restore cards
for
(
size_t
i
=
0
;
i
<
cards
.
size
()
;
++
i
)
{
if
(
has_styling
[
i
])
{
cards
[
i
]
->
stylesheet
=
StyleSheetP
();
}
}
SetFormat
(
format
);
delete
[]
has_styling
;
}
Card
DataObject
::
Card
DataObject
()
{
Card
sDataObject
::
Cards
DataObject
()
{
SetFormat
(
format
);
}
CardP
CardDataObject
::
getCard
(
const
SetP
&
set
)
{
CardP
card
(
new
Card
(
*
set
->
game
));
WrappedCard
data
=
{
set
->
game
.
get
(),
set
->
game
->
name
(),
card
};
bool
CardsDataObject
::
getCards
(
const
SetP
&
set
,
vector
<
CardP
>&
out
)
{
WrappedCards
data
=
{
set
->
game
.
get
(),
set
->
game
->
name
()
};
deserialize_from_clipboard
(
data
,
*
set
,
GetText
());
if
(
data
.
game_name
!=
set
->
game
->
name
())
return
CardP
();
// Card is from a different game
else
return
card
;
if
(
data
.
cards
.
empty
())
return
false
;
if
(
data
.
game_name
==
set
->
game
->
name
())
{
// Cards are from the same game
out
=
data
.
cards
;
return
true
;
}
else
{
return
false
;
}
}
// ----------------------------------------------------------------------------- : KeywordDataObject
...
...
@@ -127,12 +139,14 @@ KeywordP KeywordDataObject::getKeyword(const SetP& set) {
// ----------------------------------------------------------------------------- : Card on clipboard
Card
OnClipboard
::
CardOnClipboard
(
const
SetP
&
set
,
const
CardP
&
card
)
{
Card
sOnClipboard
::
CardsOnClipboard
(
const
SetP
&
set
,
const
vector
<
CardP
>&
cards
)
{
// Conversion to text format
// TODO
//Add( new TextDataObject(_("card")))
// Conversion to bitmap format
Add
(
new
wxBitmapDataObject
(
export_bitmap
(
set
,
card
)));
if
(
cards
.
size
()
==
1
)
{
Add
(
new
wxBitmapDataObject
(
export_bitmap
(
set
,
cards
[
0
])));
}
// Conversion to serialized card format
Add
(
new
Card
DataObject
(
set
,
card
),
true
);
Add
(
new
Card
sDataObject
(
set
,
cards
),
true
);
}
src/data/format/clipboard.hpp
View file @
041c87a7
...
...
@@ -19,17 +19,18 @@ DECLARE_POINTER_TYPE(Keyword);
// ----------------------------------------------------------------------------- : CardDataObject
/// The data format for cards on the clipboard
class
CardDataObject
:
public
wxTextDataObject
{
class
Card
s
DataObject
:
public
wxTextDataObject
{
public:
/// Name of the format of MSE cards
static
wxDataFormat
format
;
CardDataObject
();
Card
s
DataObject
();
/// Store a card
Card
DataObject
(
const
SetP
&
set
,
const
CardP
&
card
);
Card
sDataObject
(
const
SetP
&
set
,
const
vector
<
CardP
>&
cards
);
/// Retrieve a card, only if it is made with the same game as set
CardP
getCard
(
const
SetP
&
set
);
/// Retrieve the cards, only if it is made with the same game as set
/** Return true if the cards are correctly retrieved, and there is at least one card */
bool
getCards
(
const
SetP
&
set
,
vector
<
CardP
>&
out
);
};
// ----------------------------------------------------------------------------- : KeywordDataObject
...
...
@@ -50,10 +51,10 @@ class KeywordDataObject : public wxTextDataObject {
// ----------------------------------------------------------------------------- : Card on clipboard
/// A DataObject for putting
a card
on the clipboard, in multiple formats
class
CardOnClipboard
:
public
wxDataObjectComposite
{
/// A DataObject for putting
one or more cards
on the clipboard, in multiple formats
class
Card
s
OnClipboard
:
public
wxDataObjectComposite
{
public:
Card
OnClipboard
(
const
SetP
&
set
,
const
CardP
&
card
);
Card
sOnClipboard
(
const
SetP
&
set
,
const
vector
<
CardP
>&
cards
);
};
// ----------------------------------------------------------------------------- : EOF
...
...
src/gui/control/card_list.cpp
View file @
041c87a7
...
...
@@ -132,13 +132,23 @@ void CardListBase::sendEvent() {
bool
CardListBase
::
canCopy
()
const
{
return
!!
selected_item
;
}
bool
CardListBase
::
canCut
()
const
{
return
canCopy
()
&&
allowModify
();
}
bool
CardListBase
::
canPaste
()
const
{
return
allowModify
()
&&
wxTheClipboard
->
IsSupported
(
CardDataObject
::
format
);
return
allowModify
()
&&
wxTheClipboard
->
IsSupported
(
Card
s
DataObject
::
format
);
}
bool
CardListBase
::
doCopy
()
{
if
(
!
canCopy
())
return
false
;
// cards to copy
vector
<
CardP
>
cards_to_copy
;
long
count
=
GetItemCount
();
for
(
long
pos
=
0
;
pos
<
count
;
++
pos
)
{
if
(
IsSelected
(
pos
))
{
cards_to_copy
.
push_back
(
getCard
(
pos
));
}
}
if
(
cards_to_copy
.
empty
())
return
false
;
// put on clipboard
if
(
!
wxTheClipboard
->
Open
())
return
false
;
bool
ok
=
wxTheClipboard
->
SetData
(
new
Card
OnClipboard
(
set
,
getCard
()
));
// ignore result
bool
ok
=
wxTheClipboard
->
SetData
(
new
Card
sOnClipboard
(
set
,
cards_to_copy
));
// ignore result
wxTheClipboard
->
Close
();
return
ok
;
}
...
...
@@ -153,22 +163,30 @@ bool CardListBase::doPaste() {
// get data
if
(
!
canPaste
())
return
false
;
if
(
!
wxTheClipboard
->
Open
())
return
false
;
CardDataObject
data
;
Card
s
DataObject
data
;
bool
ok
=
wxTheClipboard
->
GetData
(
data
);
wxTheClipboard
->
Close
();
if
(
!
ok
)
return
false
;
// get cards
vector
<
CardP
>
new_cards
;
ok
=
data
.
getCards
(
set
,
new_cards
);
if
(
!
ok
)
return
false
;
// add card to set
CardP
card
=
data
.
getCard
(
set
);
if
(
card
)
{
set
->
actions
.
add
(
new
AddCardAction
(
ADD
,
*
set
,
card
));
return
true
;
}
else
{
return
false
;
}
set
->
actions
.
add
(
new
AddCardAction
(
ADD
,
*
set
,
new_cards
));
return
true
;
}
bool
CardListBase
::
doDelete
()
{
//vector<>
set
->
actions
.
add
(
new
AddCardAction
(
REMOVE
,
*
set
,
getCard
()));
// cards to delete
vector
<
CardP
>
cards_to_delete
;
long
count
=
GetItemCount
();
for
(
long
pos
=
0
;
pos
<
count
;
++
pos
)
{
if
(
IsSelected
(
pos
))
{
cards_to_delete
.
push_back
(
getCard
(
pos
));
}
}
if
(
cards_to_delete
.
empty
())
return
false
;
// delete cards
set
->
actions
.
add
(
new
AddCardAction
(
REMOVE
,
*
set
,
cards_to_delete
));
return
true
;
}
...
...
src/gui/value/image.cpp
View file @
041c87a7
...
...
@@ -61,7 +61,7 @@ bool ImageValueEditor::canCopy() const {
bool
ImageValueEditor
::
canPaste
()
const
{
return
wxTheClipboard
->
IsSupported
(
wxDF_BITMAP
)
&&
!
wxTheClipboard
->
IsSupported
(
CardDataObject
::
format
);
// we don't want to (accidentally) paste card images
!
wxTheClipboard
->
IsSupported
(
Card
s
DataObject
::
format
);
// we don't want to (accidentally) paste card images
}
bool
ImageValueEditor
::
doCopy
()
{
...
...
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