implemented clipboard handling for cards

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@83 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-11-20 18:51:11 +00:00
parent 3cbf2577c1
commit 23abbedcbd
46 changed files with 433 additions and 70 deletions
+1
View File
@@ -15,6 +15,7 @@
template <> void GetDefaultMember::handle(const Char* const& v) { value = toScript(v); }
template <> void GetDefaultMember::handle(const String& v) { value = toScript(v); }
template <> void GetDefaultMember::handle(const FileName& v) { value = toScript(v); }
template <> void GetDefaultMember::handle(const int& v) { value = toScript(v); }
template <> void GetDefaultMember::handle(const unsigned int& v) { value = toScript((int)v); }
template <> void GetDefaultMember::handle(const double& v) { value = toScript(v); }
+25
View File
@@ -18,6 +18,9 @@ DECLARE_TYPEOF(Package::FileInfos);
// ----------------------------------------------------------------------------- : Package : outside
IMPLEMENT_DYNAMIC_ARG(Package*, writing_package, nullptr);
IMPLEMENT_DYNAMIC_ARG(Package*, clipboard_package, nullptr);
Package::Package()
: zipStream (nullptr)
, fileStream(nullptr)
@@ -219,6 +222,13 @@ String Package::newFileName(const String& prefix, const String& suffix) {
}
}
void Package::referenceFile(const String& file) {
if (file.empty()) return;
FileInfos::iterator it = files.find(file);
if (it == files.end()) throw InternalError(_("referencing a nonexistant file"));
it->second.keep = true;
}
String Package::absoluteName(const String& file) {
assert(wxThread::IsMain());
FileInfos::iterator it = files.find(toStandardName(file));
@@ -236,6 +246,21 @@ String Package::absoluteName(const String& file) {
return filename+_("\1")+file;
}
}
// Open a file that is in some package
InputStreamP Package::openAbsoluteFile(const String& name) {
size_t pos = name.find_first_of(_('\1'));
if (pos == String::npos) {
// temp or dir file
shared_ptr<wxFileInputStream> f = new_shared1<wxFileInputStream>(name);
if (!f->IsOk()) throw FileNotFoundError(_("<unknown>"), name);
return f;
} else {
// packaged file, always in zip format
Package p;
p.open(name.substr(0, pos));
return p.openIn( name.substr(pos + 1));
}
}
// ----------------------------------------------------------------------------- : Package : private
+7
View File
@@ -10,11 +10,18 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/reflect.hpp>
#include <util/dynamic_arg.hpp>
class Package;
class wxFileInputStream;
class wxZipInputStream;
class wxZipEntry;
/// The package that is currently being written to
DECLARE_DYNAMIC_ARG(Package*, writing_package);
/// The package that is being put onto/read from the clipboard
DECLARE_DYNAMIC_ARG(Package*, clipboard_package);
// ----------------------------------------------------------------------------- : Package
/// A package is a container for files. On disk it is either a directory or a zip file.
+22 -1
View File
@@ -190,7 +190,6 @@ template <> void Reader::handle(double& d) {
template <> void Reader::handle(bool& b) {
b = (value==_("true") || value==_("1") || value==_("yes"));
}
// ----------------------------------------------------------------------------- : Handling less basic util types
template <> void Reader::handle(Vector2D& vec) {
@@ -205,3 +204,25 @@ template <> void Reader::handle(Color& col) {
col.Set(r, g, b);
}
}
template <> void Reader::handle(FileName& f) {
if (clipboard_package()) {
String str; handle(str);
if (!str.empty()) {
// copy file into current package
try {
String packaged_name = clipboard_package()->newFileName(_("image"),_("")); // a new unique name in the package, assume it's an image
OutputStreamP out = clipboard_package()->openOut(packaged_name);
InputStreamP in = Package::openAbsoluteFile(str);
out->Write(*in); // copy
f.assign(packaged_name);
} catch (Error) {
// ignore errors
}
} else {
f.assign(str);
}
} else {
handle(static_cast<String&>(f));
}
}
+17
View File
@@ -10,6 +10,7 @@
#include <util/vector2d.hpp>
#include <util/error.hpp>
#include <util/version.hpp>
#include <util/io/package.hpp>
// ----------------------------------------------------------------------------- : Writer
@@ -115,3 +116,19 @@ template <> void Writer::handle(const Vector2D& vec) {
template <> void Writer::handle(const Color& col) {
handle(String::Format(_("rgb(%u,%u,%u)"), col.Red(), col.Green(), col.Blue()));
}
template <> void Writer::handle(const FileName& value) {
if (clipboard_package() && !value.empty()) {
// use absolute names on clipboard
try {
handle(clipboard_package()->absoluteName(value));
} catch (const Error&) {
// ignore errors
}
} else {
handle(static_cast<const String&>(value));
if (writing_package()) {
writing_package()->referenceFile(value);
}
}
}
+3
View File
@@ -65,5 +65,8 @@ typedef unsigned int UInt;
/// Null pointer
#define nullptr 0
/// A string standing for a filename, has different behaviour when reading/writing
class FileName : public String {};
// ----------------------------------------------------------------------------- : EOF
#endif
+3
View File
@@ -138,6 +138,9 @@ enum ChildMenuID {
// CardList
, ID_SELECT_COLUMNS = 3001
// Statistics
, ID_FIELD_LIST = 3101
};