diff --git a/toonz/sources/toonzlib/studiopalette.cpp b/toonz/sources/toonzlib/studiopalette.cpp index 20b0729..9964a7c 100644 --- a/toonz/sources/toonzlib/studiopalette.cpp +++ b/toonz/sources/toonzlib/studiopalette.cpp @@ -579,6 +579,13 @@ void StudioPalette::setStylesGlobalNames(TPalette *palette) { //------------------------------------------------------------------- void StudioPalette::save(const TFilePath &path, TPalette *palette) { + TFileStatus fs(path); + if (!fs.isWritable()) { + throw TSystemException(path, + "The studio palette cannot be saved: it is a read " + "only studio palette."); + } + TOStream os(path); std::map attr; attr["name"] = ::to_string(palette->getGlobalName()); diff --git a/toonz/sources/toonzlib/txshpalettelevel.cpp b/toonz/sources/toonzlib/txshpalettelevel.cpp index e24db02..13da70f 100644 --- a/toonz/sources/toonzlib/txshpalettelevel.cpp +++ b/toonz/sources/toonzlib/txshpalettelevel.cpp @@ -101,6 +101,11 @@ void TXshPaletteLevel::load() { void TXshPaletteLevel::save() { TFilePath path = getScene()->decodeFilePath(m_path); if (TSystem::doesExistFileOrLevel(path) && m_palette) { + TFileStatus fs(path); + if (!fs.isWritable()) { + throw TSystemException( + path, "The palette cannot be saved: it is a read only palette."); + } TOStream os(path); os << m_palette; } diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cpp index ddb8ace..333d2e0 100644 --- a/toonz/sources/toonzqt/paletteviewer.cpp +++ b/toonz/sources/toonzqt/paletteviewer.cpp @@ -22,6 +22,7 @@ // TnzCore includes #include "tconvert.h" +#include "tsystem.h" // Qt includes #include @@ -894,8 +895,15 @@ void PaletteViewer::saveStudioPalette() { int ret = DVGui::MsgBox(question, QObject::tr("Overwrite"), QObject::tr("Don't Overwrite"), 0); if (ret == 2 || ret == 0) return; - StudioPalette::instance()->save(palettePath, palette); - palette->setDirtyFlag(false); + try { + StudioPalette::instance()->save(palettePath, palette); + palette->setDirtyFlag(false); + } catch (TSystemException se) { + QApplication::restoreOverrideCursor(); + DVGui::warning(QString::fromStdWString(se.getMessage())); + return; + } catch (...) { + } } } return;