Skip to content

Commit

Permalink
fixed musescore#16042: Show corrupted message before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Eism committed Feb 1, 2023
1 parent 73046e6 commit 0b35d51
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 75 deletions.
41 changes: 27 additions & 14 deletions src/engraving/engravingproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,37 +103,36 @@ bool EngravingProject::readOnly() const

Ret EngravingProject::setupMasterScore(bool forceMode)
{
return doSetupMasterScore(m_masterScore, forceMode);
return doSetupMasterScore(forceMode);
}

Ret EngravingProject::doSetupMasterScore(MasterScore* score, bool forceMode)
Ret EngravingProject::doSetupMasterScore(bool forceMode)
{
TRACEFUNC;

score->createPaddingTable();
score->connectTies();
m_masterScore->createPaddingTable();
m_masterScore->connectTies();

for (Part* p : score->parts()) {
for (Part* p : m_masterScore->parts()) {
p->updateHarmonyChannels(false);
}

score->rebuildMidiMapping();
score->setSoloMute();
m_masterScore->rebuildMidiMapping();
m_masterScore->setSoloMute();

for (Score* s : score->scoreList()) {
for (Score* s : m_masterScore->scoreList()) {
s->setPlaylistDirty();
s->addLayoutFlags(LayoutFlag::FIX_PITCH_VELO);
s->setLayoutAll();
}

score->updateChannel();
score->update();
m_masterScore->updateChannel();
m_masterScore->update();

if (!forceMode) {
return score->sanityCheck();
}
Ret ret = checkCorrupted();
m_isCorruptedUponLoading = !ret;

return make_ok();
return forceMode ? make_ok() : ret;
}

MasterScore* EngravingProject::masterScore() const
Expand All @@ -157,5 +156,19 @@ bool EngravingProject::writeMscz(MscWriter& writer, bool onlySelection, bool cre
m_masterScore->update();
}

m_isCorruptedUponLoading = false;

return ok;
}

bool EngravingProject::isCorruptedUponLoading() const
{
return m_isCorruptedUponLoading;
}

Ret EngravingProject::checkCorrupted() const
{
TRACEFUNC;

return m_masterScore->sanityCheck();
}
7 changes: 6 additions & 1 deletion src/engraving/engravingproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,21 @@ class EngravingProject : public std::enable_shared_from_this<EngravingProject>
Ret loadMscz(const MscReader& msc, bool ignoreVersionError);
bool writeMscz(MscWriter& writer, bool onlySelection, bool createThumbnail);

bool isCorruptedUponLoading() const;
Ret checkCorrupted() const;

private:
friend class MasterScore;

EngravingProject();

void init(const MStyle& style);

Ret doSetupMasterScore(MasterScore* score, bool forceMode);
Ret doSetupMasterScore(bool forceMode);

MasterScore* m_masterScore = nullptr;

bool m_isCorruptedUponLoading = false;
};

using EngravingProjectPtr = std::shared_ptr<EngravingProject>;
Expand Down
7 changes: 5 additions & 2 deletions src/framework/global/types/ret.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ class Ret
EngravingFirst = 2000,
EngravingLast = 2999,

DiagnosticsFirst = 3000,
DiagnosticsLast = 3999
ProjectFirst = 3000,
ProjectLast = 3999,

DiagnosticsFirst = 4000,
DiagnosticsLast = 4999
};

Ret() = default;
Expand Down
4 changes: 4 additions & 0 deletions src/notation/view/internal/undoredomodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ void UndoRedoModel::load()
});
});

context()->currentProjectChanged().onNotify(this, [this]() {
load();
});

emit stackChanged();
}

Expand Down
1 change: 1 addition & 0 deletions src/project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ set(MODULE_SRC
${CMAKE_CURRENT_LIST_DIR}/projectmodule.cpp
${CMAKE_CURRENT_LIST_DIR}/projectmodule.h
${CMAKE_CURRENT_LIST_DIR}/projecttypes.h
${CMAKE_CURRENT_LIST_DIR}/projecterrors.h
${CMAKE_CURRENT_LIST_DIR}/inotationproject.h
${CMAKE_CURRENT_LIST_DIR}/iprojectcreator.h
${CMAKE_CURRENT_LIST_DIR}/inotationreader.h
Expand Down
4 changes: 3 additions & 1 deletion src/project/inotationproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ class INotationProject

virtual void markAsUnsaved() = 0;

virtual void revertChanges() = 0;

virtual ValNt<bool> needSave() const = 0;
virtual bool canSave() const = 0;
virtual Ret canSave() const = 0;

virtual Ret save(const io::path_t& path = io::path_t(), SaveMode saveMode = SaveMode::Save) = 0;
virtual Ret writeToDevice(QIODevice* device) = 0;
Expand Down
24 changes: 20 additions & 4 deletions src/project/internal/notationproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include "io/buffer.h"

#include "libmscore/undo.h"

#include "engraving/engravingproject.h"
#include "engraving/compat/scoreaccess.h"
#include "engraving/compat/mscxcompat.h"
Expand All @@ -38,8 +40,7 @@
#include "notation/notationerrors.h"
#include "projectaudiosettings.h"
#include "projectfileinfoprovider.h"

#include "libmscore/undo.h"
#include "projecterrors.h"

#include "defer.h"
#include "log.h"
Expand Down Expand Up @@ -763,6 +764,11 @@ void NotationProject::markAsUnsaved()
m_masterNotation->masterScore()->setSaved(false);
}

void NotationProject::revertChanges()
{
load(path());
}

mu::ValNt<bool> NotationProject::needSave() const
{
ValNt<bool> needSave;
Expand All @@ -773,9 +779,19 @@ mu::ValNt<bool> NotationProject::needSave() const
return needSave;
}

bool NotationProject::canSave() const
Ret NotationProject::canSave() const
{
return m_masterNotation->hasParts();
if (!m_masterNotation->hasParts()) {
return make_ret(Err::NoPartsError);
}

Ret ret = m_engravingProject->checkCorrupted();
if (!ret) {
Err errorCode = m_engravingProject->isCorruptedUponLoading() ? Err::CorruptionUponOpenningError : Err::CorruptionError;
ret.setCode(static_cast<int>(errorCode));
}

return ret;
}

ProjectMeta NotationProject::metaInfo() const
Expand Down
4 changes: 3 additions & 1 deletion src/project/internal/notationproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class NotationProject : public INotationProject, public async::Asyncable

void markAsUnsaved() override;

void revertChanges() override;

ValNt<bool> needSave() const override;
bool canSave() const override;
Ret canSave() const override;

Ret save(const io::path_t& path = io::path_t(), SaveMode saveMode = SaveMode::Save) override;
Ret writeToDevice(QIODevice* device) override;
Expand Down

0 comments on commit 0b35d51

Please sign in to comment.