clipboard functions for keywords

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@358 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-05-13 22:16:58 +00:00
parent 0e6e349295
commit 3702ff5846
12 changed files with 179 additions and 34 deletions
+3 -3
View File
@@ -18,14 +18,14 @@ DECLARE_TYPEOF_COLLECTION(KeywordModeP);
// ----------------------------------------------------------------------------- : Add Keyword
AddKeywordAction::AddKeywordAction(Adding, Set& set)
: KeywordListAction(set), adding(true), keyword(new Keyword())
AddKeywordAction::AddKeywordAction(Adding, Set& set, const KeywordP& keyword)
: KeywordListAction(set), adding(true), keyword(keyword ? keyword : new_intrusive<Keyword>())
, keyword_id(set.keywords.size())
{
// find default mode
FOR_EACH(mode, set.game->keyword_modes) {
if (mode->is_default) {
keyword->mode = mode->name;
this->keyword->mode = mode->name;
break;
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ enum Removing {REMOVE};
/// Adding or removing a keyword from a set
class AddKeywordAction : public KeywordListAction {
public:
AddKeywordAction(Adding, Set& set);
AddKeywordAction(Adding, Set& set, const KeywordP& keyword = KeywordP());
AddKeywordAction(Removing, Set& set, const KeywordP& keyword);
virtual String getName(bool to_undo) const;
+41
View File
@@ -11,6 +11,7 @@
#include <data/card.hpp>
#include <data/set.hpp>
#include <data/game.hpp>
#include <data/keyword.hpp>
#include <util/io/package.hpp>
#include <script/scriptable.hpp>
#include <wx/sstream.h>
@@ -74,6 +75,46 @@ CardP CardDataObject::getCard(const SetP& set) {
else return card;
}
// ----------------------------------------------------------------------------- : KeywordDataObject
/// A wrapped keyword for storing on the clipboard
struct WrappedKeyword {
Game* expected_game;
String game_name;
KeywordP keyword;
DECLARE_REFLECTION();
};
IMPLEMENT_REFLECTION(WrappedKeyword) {
REFLECT(game_name);
if (game_name == expected_game->name()) {
WITH_DYNAMIC_ARG(game_for_reading, expected_game);
REFLECT(keyword);
}
}
wxDataFormat KeywordDataObject::format = _("application/x-mse-keyword");
KeywordDataObject::KeywordDataObject(const SetP& set, const KeywordP& keyword) {
WrappedKeyword data = { set->game.get(), set->game->name(), keyword };
SetText(serialize_for_clipboard(*set, data));
SetFormat(format);
}
KeywordDataObject::KeywordDataObject() {
SetFormat(format);
}
KeywordP KeywordDataObject::getKeyword(const SetP& set) {
KeywordP keyword(new Keyword());
WrappedKeyword data = { set->game.get(), set->game->name(), keyword};
deserialize_from_clipboard(data, *set, GetText());
if (data.game_name != set->game->name()) return KeywordP(); // Keyword is from a different game
else return keyword;
}
// ----------------------------------------------------------------------------- : Card on clipboard
CardOnClipboard::CardOnClipboard(const SetP& set, const CardP& card) {
+17
View File
@@ -14,6 +14,7 @@
DECLARE_POINTER_TYPE(Set);
DECLARE_POINTER_TYPE(Card);
DECLARE_POINTER_TYPE(Keyword);
// ----------------------------------------------------------------------------- : CardDataObject
@@ -31,6 +32,22 @@ class CardDataObject : public wxTextDataObject {
CardP getCard(const SetP& set);
};
// ----------------------------------------------------------------------------- : KeywordDataObject
/// The data format for keywords on the clipboard
class KeywordDataObject : public wxTextDataObject {
public:
/// Name of the format of MSE keywords
static wxDataFormat format;
KeywordDataObject();
/// Store a keyword
KeywordDataObject(const SetP& set, const KeywordP& card);
/// Retrieve a keyword, only if it is made with the same game as set
KeywordP getKeyword(const SetP& set);
};
// ----------------------------------------------------------------------------- : Card on clipboard
/// A DataObject for putting a card on the clipboard, in multiple formats