Skip to content
Extraits de code Groupes Projets
Vérifiée Valider b60127ec rédigé par Kubat's avatar Kubat
Parcourir les fichiers

LIB: Re-add the rename operation, now can have save, rename and copy on documents

parent e1f21e25
Branches
Aucune étiquette associée trouvée
1 requête de fusion!18Implement the VivyDocument specification
...@@ -77,6 +77,7 @@ protected: ...@@ -77,6 +77,7 @@ protected:
public: public:
virtual void copy(const QString &) = 0; virtual void copy(const QString &) = 0;
virtual void rename(const QString &) = 0;
virtual void save() = 0; virtual void save() = 0;
QString getName() const noexcept { return name; } QString getName() const noexcept { return name; }
......
...@@ -233,30 +233,60 @@ VivyDocument::detectDocumentType(const QFileInfo &file, Capabilities *ableType) ...@@ -233,30 +233,60 @@ VivyDocument::detectDocumentType(const QFileInfo &file, Capabilities *ableType)
void void
VivyDocument::copy(const QString &newName) VivyDocument::copy(const QString &newName)
{ {
const QString newNameWithExtension = const QFileInfo newPath = computeFileInfo(newName);
(newName.right(fileSuffix.size()) == fileSuffix) ? newName : newName + "." + fileSuffix;
const QFileInfo newPath(documentLocation, newNameWithExtension);
// Rename + create the disk on disk as it's a memory document // Rename + create the disk on disk as it's a memory document
if (documentOptions & MemoryDocumentCreation) { if (documentOptions & MemoryDocumentCreation)
return saveMemoryFile(newPath);
// Compute new paths, the document is really on disk initially
else {
qDebug() << "Renaming a real file";
copyWith(newPath, [=, this]() noexcept -> void {
documentLocation = newPath.dir();
documentName = newPath.baseName(); documentName = newPath.baseName();
documentLocation = newPath.absoluteDir(); });
documentOptions = static_cast<Options>(documentOptions & (~MemoryDocumentCreation));
qDebug().nospace() << "Renaming a memory file => create it on disk with { "
<< documentLocation << ", " << documentName << " }";
save();
} }
}
void
VivyDocument::rename(const QString &newName)
{
const QFileInfo newPath = computeFileInfo(newName);
// Rename + create the disk on disk as it's a memory document
if (documentOptions & MemoryDocumentCreation)
return saveMemoryFile(newPath);
// Compute new paths, the document is really on disk initially // Compute new paths, the document is really on disk initially
else { else {
qDebug() << "Renaming a real file"; qDebug() << "Renaming a real file";
copyWith(newPath, [=, this]() noexcept -> void { renameWith(newPath, [=, this]() noexcept -> void {
documentLocation = newPath.dir(); documentLocation = newPath.dir();
documentName = newPath.baseName(); documentName = newPath.baseName();
}); });
} }
} }
QFileInfo
VivyDocument::computeFileInfo(const QString &newName) const noexcept
{
const QString newNameWithExtension =
(newName.right(fileSuffix.size()) == fileSuffix) ? newName : newName + "." + fileSuffix;
return QFileInfo(documentLocation, newNameWithExtension);
}
void
VivyDocument::saveMemoryFile(const QFileInfo &newPath)
{
documentName = newPath.baseName();
documentLocation = newPath.absoluteDir();
documentOptions = static_cast<Options>(documentOptions & (~MemoryDocumentCreation));
qDebug().nospace() << "Renaming a memory file => create it on disk with { " << documentLocation
<< ", " << documentName << " }";
save();
}
std::shared_ptr<AudioSubDocument> std::shared_ptr<AudioSubDocument>
VivyDocument::getAudioSubDocument() const noexcept VivyDocument::getAudioSubDocument() const noexcept
{ {
......
...@@ -68,6 +68,9 @@ private: ...@@ -68,6 +68,9 @@ private:
static bool detectDocumentType(const QFileInfo &file, Capabilities *) noexcept; static bool detectDocumentType(const QFileInfo &file, Capabilities *) noexcept;
void addDocumentType(Capabilities) noexcept; void addDocumentType(Capabilities) noexcept;
void saveMemoryFile(const QFileInfo &);
QFileInfo computeFileInfo(const QString &) const noexcept;
QJsonDocument getSaveJsonDocumentFile() const; QJsonDocument getSaveJsonDocumentFile() const;
void loadSaveJsonDocumentFile(const QJsonDocument &); void loadSaveJsonDocumentFile(const QJsonDocument &);
...@@ -81,6 +84,7 @@ public: ...@@ -81,6 +84,7 @@ public:
explicit VivyDocument(const QString &name, Options opt = NoOption); explicit VivyDocument(const QString &name, Options opt = NoOption);
void copy(const QString &) override; void copy(const QString &) override;
void rename(const QString &) override;
void save() override; void save() override;
bool loadSubDocument(const QString &) noexcept; bool loadSubDocument(const QString &) noexcept;
bool loadSubDocument(const QString &, Capabilities) noexcept; bool loadSubDocument(const QString &, Capabilities) noexcept;
......
...@@ -22,6 +22,14 @@ ScriptDocument::copy(const QString &newName) ...@@ -22,6 +22,14 @@ ScriptDocument::copy(const QString &newName)
copyWith(newPath, [=, this]() noexcept { name = newName; }); copyWith(newPath, [=, this]() noexcept { name = newName; });
} }
void
ScriptDocument::rename(const QString &newName)
{
/* Compute new paths */
const QFileInfo newPath(newName);
renameWith(newPath, [=, this]() noexcept { name = newName; });
}
void void
ScriptDocument::save() ScriptDocument::save()
{ {
......
...@@ -16,6 +16,7 @@ public: ...@@ -16,6 +16,7 @@ public:
explicit ScriptDocument(const QString &name); explicit ScriptDocument(const QString &name);
void copy(const QString &) override; void copy(const QString &) override;
void rename(const QString &) override;
void save() override; void save() override;
void attachTextDocument(const QTextDocument *const) noexcept; void attachTextDocument(const QTextDocument *const) noexcept;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter