OpenToonz - An open-source full-featured 2D animation creation software
C
fix studio palette caching
shun-iwasawa73c7bb351041
diff --git a/toonz/sources/include/toonz/studiopalette.h b/toonz/sources/include/toonz/studiopalette.hindex 90c295082..bbbf38c0a 100644--- a/toonz/sources/include/toonz/studiopalette.h+++ b/toonz/sources/include/toonz/studiopalette.h@@ -4,7 +4,8 @@#define STUDIOPALETTE_INCLUDED#include "tpalette.h"-//#include "tfilepath.h"+#include "toonz/tproject.h"+// #include "tfilepath.h"#undef DVAPI#undef DVVAR@@ -20,7 +21,9 @@ class TPalette;class TImage;class TColorStyle;-class DVAPI StudioPalette { // singleton; methods can throw exceptions+class DVAPI StudioPalette+ : public TProjectManager::Listener { // singleton; methods can throw+ // exceptionspublic:class Listener {public:@@ -110,6 +113,10 @@ public:void removeEntry(const std::wstring paletteId);void addEntry(const std::wstring paletteId, const TFilePath &path);+ // TProjectManager::Listener+ void onProjectSwitched() override;+ void onProjectChanged() override;+private:StudioPalette();TFilePath m_root;diff --git a/toonz/sources/toonzlib/studiopalette.cpp b/toonz/sources/toonzlib/studiopalette.cppindex b655f11a8..039bb1649 100644--- a/toonz/sources/toonzlib/studiopalette.cpp+++ b/toonz/sources/toonzlib/studiopalette.cpp@@ -180,18 +180,9 @@ StudioPalette::StudioPalette() {}}- // load [global id] - [path] table file- TFilePath rootFps[2] = {m_root, getProjectPalettesRoot()};- for (auto rootFp : rootFps) {- if (rootFp.isEmpty()) continue;- TFilePath tablePath = rootFp + pathTableFileName;- if (!TFileStatus(tablePath).doesExist()) continue;- QSettings tableSettings(QString::fromStdWString(tablePath.getWideString()),- QSettings::IniFormat);- for (auto key : tableSettings.allKeys())- table_cached[key.toStdWString()] =- rootFp + TFilePath(tableSettings.value(key, "").toString());- }+ TProjectManager *pm = TProjectManager::instance();+ pm->addListener(this);+ onProjectSwitched();}//-------------------------------------------------------------------@@ -739,4 +730,24 @@ void StudioPalette::addEntry(const std::wstring paletteId,QString pathValue = (path - rootFp).getQString();tableSettings.setValue(QString::fromStdWString(paletteId), pathValue);}-}\ No newline at end of file+}++//-------------------------------------------------------------------++void StudioPalette::onProjectSwitched() {+ table_cached.clear();+ // load [global id] - [path] table file+ TFilePath rootFps[2] = {m_root, getProjectPalettesRoot()};+ for (auto rootFp : rootFps) {+ if (rootFp.isEmpty()) continue;+ TFilePath tablePath = rootFp + pathTableFileName;+ if (!TFileStatus(tablePath).doesExist()) continue;+ QSettings tableSettings(QString::fromStdWString(tablePath.getWideString()),+ QSettings::IniFormat);+ for (auto key : tableSettings.allKeys())+ table_cached[key.toStdWString()] =+ rootFp + TFilePath(tableSettings.value(key, "").toString());+ }+}++void StudioPalette::onProjectChanged() { onProjectSwitched(); }\ No newline at end of file