OpenToonz - An open-source full-featured 2D animation creation software
C
enhance studio palette searching
shun-iwasawa3bb469e82047
diff --git a/toonz/sources/include/toonz/studiopalette.h b/toonz/sources/include/toonz/studiopalette.hindex dfa350a5a..90c295082 100644--- a/toonz/sources/include/toonz/studiopalette.h+++ b/toonz/sources/include/toonz/studiopalette.h@@ -107,6 +107,9 @@ public:void save(const TFilePath &path, TPalette *palette);+ void removeEntry(const std::wstring paletteId);+ void addEntry(const std::wstring paletteId, const TFilePath &path);+private:StudioPalette();TFilePath m_root;diff --git a/toonz/sources/toonzlib/studiopalette.cpp b/toonz/sources/toonzlib/studiopalette.cppindex 625c3bf02..5a9a959ce 100644--- a/toonz/sources/toonzlib/studiopalette.cpp+++ b/toonz/sources/toonzlib/studiopalette.cpp@@ -20,6 +20,8 @@#include <sys/timeb.h>#include <string.h>+#include <QSettings>+//===================================================================//-------------------------------------------------------------------@@ -143,6 +145,10 @@ TFilePath searchPalette(TFilePath path, std::wstring paletteId) {bool studioPaletteHasBeenReferred = false;static std::map<std::wstring, TFilePath> table;+// table loaded from the cache. verify once before storing in the table+static std::map<std::wstring, TFilePath> table_cached;++const std::string pathTableFileName = "palette_paths.ini";//-------------------------------------------------------------------} // namespace@@ -174,6 +180,19 @@ StudioPalette::StudioPalette() {} catch (...) {}}++ // 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());+ }}//-------------------------------------------------------------------@@ -263,6 +282,7 @@ void StudioPalette::movePalette(const TFilePath &dstPath,}std::wstring id = readPaletteGlobalName(dstPath);table.erase(id);+ removeEntry(id);FolderListenerManager::instance()->notifyFolderChanged(dstPath.getParentDir());notifyMove(dstPath, srcPath);@@ -489,9 +509,26 @@ static void foobar(std::wstring paletteId) { table.erase(paletteId); }TFilePath StudioPalette::getPalettePath(std::wstring paletteId) {std::map<std::wstring, TFilePath>::iterator it = table.find(paletteId);if (it != table.end()) return it->second;- TFilePath fp = searchPalette(m_root, paletteId);- if (fp == TFilePath()) {- fp = searchPalette(getProjectPalettesRoot(), paletteId);+ TFilePath fp;+ // not found in the verified table, then check for the cached table+ it = table_cached.find(paletteId);+ // found in the cached table+ if (it != table_cached.end()) {+ fp = it->second;+ // verify if cached path is correct+ if (fp.getType() != "tpl" ||+ readPaletteGlobalName(it->second) != paletteId) {+ fp = TFilePath();+ // erase the entry+ it = table_cached.erase(it);+ removeEntry(paletteId);+ }+ }+ if (fp.isEmpty()) {+ fp = searchPalette(m_root, paletteId);+ if (fp.isEmpty()) fp = searchPalette(getProjectPalettesRoot(), paletteId);++ addEntry(paletteId, fp);}table[paletteId] = fp;return fp;@@ -544,7 +581,7 @@ bool StudioPalette::updateLinkedColors(TPalette *palette) {it = table.find(paletteId);TPalette *spPalette = 0;if (it == table.end()) {- spPalette = StudioPalette::instance()->getPalette(paletteId);+ spPalette = getPalette(paletteId);if (!spPalette) continue;table[paletteId] = spPalette;// spPalette->release();@@ -670,3 +707,37 @@ void StudioPalette::notifyPaletteChange(const TFilePath &palette) {it != m_listeners.end(); ++it)(*it)->onStudioPaletteChange(palette);}++//-------------------------------------------------------------------++void StudioPalette::removeEntry(const std::wstring paletteId) {+ 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);+ if (tableSettings.contains(QString::fromStdWString(paletteId))) {+ tableSettings.remove(QString::fromStdWString(paletteId));+ break;+ }+ }+}++//-------------------------------------------------------------------++void StudioPalette::addEntry(const std::wstring paletteId,+ const TFilePath &path) {+ TFilePath rootFps[2] = {m_root, getProjectPalettesRoot()};+ for (auto rootFp : rootFps) {+ if (rootFp.isEmpty()) continue;+ if (!rootFp.isAncestorOf(path)) continue;++ TFilePath tablePath = rootFp + pathTableFileName;+ QSettings tableSettings(QString::fromStdWString(tablePath.getWideString()),+ QSettings::IniFormat);+ QString pathValue = (path - rootFp).getQString();+ tableSettings.setValue(QString::fromStdWString(paletteId), pathValue);+ }+}\ No newline at end of filediff --git a/toonz/sources/toonzqt/styleselection.cpp b/toonz/sources/toonzqt/styleselection.cppindex 26d95b672..8a5d799ad 100644--- a/toonz/sources/toonzqt/styleselection.cpp+++ b/toonz/sources/toonzqt/styleselection.cpp@@ -1793,7 +1793,7 @@ void TStyleSelection::getBackOriginalStyle() {} elsespPalette = palIt->second.getPointer();- // j is StudioPaletteID+ // j is StyleIDint j = std::stoi(gname.substr(k + 1));if (spPalette && 0 <= j && j < spPalette->getStyleCount()) {