Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 8f0d32b0 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 b31b51b5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Ce commit fait partie de la requête de fusion !18. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
......@@ -77,6 +77,7 @@ protected:
public:
virtual void copy(const QString &) = 0;
virtual void rename(const QString &) = 0;
virtual void save() = 0;
QString getName() const noexcept { return name; }
......
......@@ -233,30 +233,60 @@ VivyDocument::detectDocumentType(const QFileInfo &file, Capabilities *ableType)
void
VivyDocument::copy(const QString &newName)
{
const QString newNameWithExtension =
(newName.right(fileSuffix.size()) == fileSuffix) ? newName : newName + "." + fileSuffix;
const QFileInfo newPath(documentLocation, newNameWithExtension);
const QFileInfo newPath = computeFileInfo(newName);
// 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();
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
else {
qDebug() << "Renaming a real file";
copyWith(newPath, [=, this]() noexcept -> void {
renameWith(newPath, [=, this]() noexcept -> void {
documentLocation = newPath.dir();
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>
VivyDocument::getAudioSubDocument() const noexcept
{
......
......@@ -68,6 +68,9 @@ private:
static bool detectDocumentType(const QFileInfo &file, Capabilities *) noexcept;
void addDocumentType(Capabilities) noexcept;
void saveMemoryFile(const QFileInfo &);
QFileInfo computeFileInfo(const QString &) const noexcept;
QJsonDocument getSaveJsonDocumentFile() const;
void loadSaveJsonDocumentFile(const QJsonDocument &);
......@@ -81,6 +84,7 @@ public:
explicit VivyDocument(const QString &name, Options opt = NoOption);
void copy(const QString &) override;
void rename(const QString &) override;
void save() override;
bool loadSubDocument(const QString &) noexcept;
bool loadSubDocument(const QString &, Capabilities) noexcept;
......
......@@ -22,6 +22,14 @@ ScriptDocument::copy(const QString &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
ScriptDocument::save()
{
......
......@@ -16,6 +16,7 @@ public:
explicit ScriptDocument(const QString &name);
void copy(const QString &) override;
void rename(const QString &) override;
void save() override;
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