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
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!18Implement the VivyDocument specification
......@@ -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