Use LocalFileName class for file names inside a package.

This commit is contained in:
Twan van Laarhoven
2020-04-29 23:57:36 +02:00
parent f92c09e87a
commit a1d54f36fc
19 changed files with 143 additions and 93 deletions
+7 -7
View File
@@ -50,10 +50,10 @@ ImageFieldP ImageCardList::findImageField() {
/// A request for a thumbnail of a card image
class CardThumbnailRequest : public ThumbnailRequest {
public:
CardThumbnailRequest(ImageCardList* parent, const String& filename)
CardThumbnailRequest(ImageCardList* parent, const LocalFileName& filename)
: ThumbnailRequest(
parent,
_("card") + parent->set->absoluteFilename() + _("-") + filename,
_("card") + parent->set->absoluteFilename() + _("-") + filename.toStringForKey(),
wxDateTime::Now()) // TODO: Find mofication time of card image
, filename(filename)
{}
@@ -78,23 +78,23 @@ class CardThumbnailRequest : public ThumbnailRequest {
if (img.Ok()) {
wxImageList* il = parent->GetImageList(wxIMAGE_LIST_SMALL);
int id = il->Add(wxBitmap(img));
parent->thumbnails.insert(make_pair(filename, id));
parent->thumbnails.insert(make_pair(filename.toStringForKey(), id));
parent->Refresh(false);
}
}
virtual bool threadSafe() const {return true;}
private:
String filename;
private:
LocalFileName filename;
};
int ImageCardList::OnGetItemImage(long pos) const {
if (image_field) {
// Image = thumbnail of first image field of card
ImageValue& val = static_cast<ImageValue&>(*getCard(pos)->data[image_field]);
if (!val.filename) return -1; // no image
if (val.filename.empty()) return -1; // no image
// is there already a thumbnail?
map<String,int>::const_iterator it = thumbnails.find(val.filename);
map<String,int>::const_iterator it = thumbnails.find(val.filename.toStringForKey());
if (it != thumbnails.end()) {
return it->second;
} else {
+1 -1
View File
@@ -252,7 +252,7 @@ void SymbolWindow::onFileStore(wxCommandEvent& ev) {
if (performer) {
SymbolValueP value = static_pointer_cast<SymbolValue>(performer->value);
Package& package = performer->getLocalPackage();
FileName new_filename = package.newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
LocalFileName new_filename = package.newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
auto stream = package.openOut(new_filename);
Writer writer(*stream, file_version_symbol);
writer.handle(control->getSymbol());
+2 -2
View File
@@ -45,7 +45,7 @@ void ImageValueEditor::sliceImage(const Image& image) {
// clicked ok?
if (s.ShowModal() == wxID_OK) {
// store the image into the set
FileName new_image_file = getLocalPackage().newFileName(field().name,_("")); // a new unique name in the package
LocalFileName new_image_file = getLocalPackage().newFileName(field().name,_("")); // a new unique name in the package
Image img = s.getImage();
img.SaveFile(getLocalPackage().nameOut(new_image_file), wxBITMAP_TYPE_PNG); // always use PNG images, see #69. Disk space is cheap anyway.
addAction(value_action(valueP(), new_image_file));
@@ -88,7 +88,7 @@ bool ImageValueEditor::doPaste() {
}
bool ImageValueEditor::doDelete() {
addAction(value_action(valueP(), FileName()));
addAction(value_action(valueP(), LocalFileName()));
return true;
}