OpenToonz - An open-source full-featured 2D animation creation software
C
Display and save default raster palettes
Rodney3b65d2986b09
diff --git a/LICENSE.txt b/LICENSE.txtindex d837fe774..fe02697de 100644--- a/LICENSE.txt+++ b/LICENSE.txt@@ -1,15 +1,12 @@Some of code in this repository is derived from thirdparty libraries.For files in the "thirdparty" directory: Please consult with the licenses in the appropriate READMEs or source codes.For files in the "stuff/library/mypaint brushes" directory: Please see the licenses in stuff/library/mypaint brushes/Licenses.txt.+For portions adapted from Tahoma2D: Please see the notices in stuff/doc/Tahoma2D-LICENSE.txt.- - - - - - - - - - - - - - - -OpenToonz-Portions adapted from Tahoma2D's vector alignment commands and panel:-Copyright (c) 2016 - 2023, John Dancel (manongjohn)-All rights reserved.-All contributions by DWANGO:Copyright (c) 2016 - 2026, DWANGO Co., Ltd.All rights reserved.diff --git a/stuff/doc/Tahoma2D-LICENSE.txt b/stuff/doc/Tahoma2D-LICENSE.txtnew file mode 100644index 000000000..81324b217--- /dev/null+++ b/stuff/doc/Tahoma2D-LICENSE.txt@@ -0,0 +1,32 @@+Tahoma2D adaptation notices+==========================++These notices are preserved from the adapted Tahoma2D code. Individual+contribution history is also recorded in Git authorship and co-author metadata.+The main OpenToonz LICENSE.txt retains the standard project-wide notices.++Sources:+- Vector alignment commands and panel: https://github.com/tahoma2d/tahoma2d+- Raster default palette support: https://github.com/tahoma2d/tahoma2d/pull/95++Portions adapted from Tahoma2D's vector alignment commands and panel:+Copyright (c) 2016 - 2023, John Dancel (manongjohn)+All rights reserved.++Portions adapted from Tahoma's raster default palette support:+Copyright (c) 2016 - 2020, the respective contributors.+All rights reserved.++LICENSE++BSD 3-Clause "New" or "Revised" License++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.diff --git a/toonz/sources/include/toonz/fullcolorpalette.h b/toonz/sources/include/toonz/fullcolorpalette.hindex 30280cda4..9f5e7217e 100644--- a/toonz/sources/include/toonz/fullcolorpalette.h+++ b/toonz/sources/include/toonz/fullcolorpalette.h@@ -33,8 +33,11 @@ public:static FullColorPalette *instance();~FullColorPalette();void clear();+ bool getDirtyFlag() const;TPalette *getPalette(ToonzScene *scene);void savePalette(ToonzScene *scene);+ TFilePath getDefaultPalettePath() const;+ void saveAsDefault(TPalette *palette);bool isFullColorPalette(TPalette *palette) { return m_palette == palette; }const TFilePath getPath() const { return m_fullcolorPalettePath; }};diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cppindex 65ca7b960..104760854 100644--- a/toonz/sources/toonz/iocommand.cpp+++ b/toonz/sources/toonz/iocommand.cpp@@ -1267,6 +1267,10 @@ bool IoCmd::saveSceneIfNeeded(QString msg) {SceneResources resources(scene, 0);resources.getDirtyResources(dirtyResources);}+ if (FullColorPalette::instance()->getDirtyFlag()) {+ dirtyResources << QStringLiteral("Raster Drawing Palette.tpl");+ dirtyResources.removeDuplicates();+ }if (!dirtyResources.empty()) {// show up to 5 items@@ -1294,7 +1298,7 @@ bool IoCmd::saveSceneIfNeeded(QString msg) {return false;} else if (ret == 1) {// save non scene files- IoCmd::saveNonSceneFiles();+ if (!IoCmd::saveNonSceneFiles()) return false;} else if (ret == 2) {// do nothing and continue}@@ -1328,6 +1332,9 @@ void IoCmd::newScene() {// while switching scenesapp->getCurrentLevel()->setLevel(nullptr);+ // An empty raster column can have a palette without a current level.+ app->getPaletteController()->getCurrentLevelPalette()->setPalette(nullptr);+IconGenerator::instance()->clearRequests();IconGenerator::instance()->clearSceneIcons();ImageManager::instance()->clear();@@ -1837,7 +1844,9 @@ bool IoCmd::saveNonSceneFiles(int flags) {try {result = resources.save(scene->getScenePath(), !isAutosave);if (result) resources.updatePaths();+ FullColorPalette::instance()->savePalette(scene);} catch (...) {+ result = false;if (!isAutosave)DVGui::error(QObject::tr("Couldn't save all scene resources."));}@@ -2004,11 +2013,15 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,// while switching scenesapp->getCurrentLevel()->setLevel(nullptr);+ app->getPaletteController()->getCurrentLevelPalette()->setPalette(nullptr);+TUndoManager::manager()->reset();IconGenerator::instance()->clearRequests();IconGenerator::instance()->clearSceneIcons();ImageManager::instance()->clear();+ FullColorPalette::instance()->clear();+CacheFxCommand::instance()->onNewScene();#ifdef USE_SQLITE_HDPOOL@@ -3440,13 +3453,20 @@ public:void execute() override {TXshLevel *level = TApp::instance()->getCurrentLevel()->getLevel();- if (!level) {+ TPalette *rasterPalette = TApp::instance()+ ->getPaletteController()+ ->getCurrentLevelPalette()+ ->getPalette();+ const bool emptyRasterPalette =+ !level && rasterPalette &&+ FullColorPalette::instance()->isFullColorPalette(rasterPalette);+ if (!level && !emptyRasterPalette) {DVGui::warning("No current level.");return;}- TXshSimpleLevel *sl = level->getSimpleLevel();- TXshPaletteLevel *pl = level->getPaletteLevel();- if (!sl && !pl) {+ TXshSimpleLevel *sl = level ? level->getSimpleLevel() : nullptr;+ TXshPaletteLevel *pl = level ? level->getPaletteLevel() : nullptr;+ if (!sl && !pl && !emptyRasterPalette) {DVGui::warning("Current level has no palette.");return;}@@ -3455,7 +3475,10 @@ public:TPalette *palette;TFilePath palettePath;/*- SimpleLevelの場合 -*/- if (sl) {+ if (emptyRasterPalette) {+ palette = rasterPalette;+ palettePath = FullColorPalette::instance()->getPath();+ } else if (sl) {palette = sl->getPalette();if (!palette) {DVGui::warning("No current palette");@@ -3502,17 +3525,25 @@ public:palettePath = scene->decodeFilePath(palettePath);}- if (sl && sl->getPath().getType() == "pli")- sl->save(palettePath, TFilePath(), true);- else if (sl && sl->getType() & FULLCOLOR_TYPE)- FullColorPalette::instance()->savePalette(scene);- else- StudioPalette::instance()->save(palettePath, palette);+ try {+ if (sl && sl->getPath().getType() == "pli")+ sl->save(palettePath, TFilePath(), true);+ else if (emptyRasterPalette || (sl && sl->getType() & FULLCOLOR_TYPE))+ FullColorPalette::instance()->savePalette(scene);+ else+ StudioPalette::instance()->save(palettePath, palette);+ } catch (const TException &e) {+ DVGui::warning(QObject::tr("Could not save the palette.\n%1")+ .arg(QString::fromStdWString(e.getMessage())));+ return;+ }/*- Dirtyフラグの変更 -*/if (sl)sl->getPalette()->setDirtyFlag(false);else if (pl)pl->getPalette()->setDirtyFlag(false);+ else if (emptyRasterPalette)+ palette->setDirtyFlag(false);if (Preferences::instance()->getBoolValue(resetUndoOnSavingLevel))TUndoManager::manager()->reset();@@ -3524,6 +3555,53 @@ public:}} overwritePaletteCommandHandler;+//=============================================================================+// Save the shared raster palette as the global default+//-----------------------------------------------------------------------------+class SaveAsDefaultRasterPaletteCommandHandler final : public MenuItemHandler {+public:+ SaveAsDefaultRasterPaletteCommandHandler()+ : MenuItemHandler(MI_SaveAsDefaultRasterPalette) {}++ void execute() override {+ TApp *app = TApp::instance();+ TPaletteP palette(app->getCurrentPalette()->getPalette());+ FullColorPalette *fullColorPalette = FullColorPalette::instance();+ TXshLevel *level = app->getCurrentLevel()->getLevel();+ if (!palette || palette->isCleanupPalette() ||+ !fullColorPalette->isFullColorPalette(palette.getPointer()) ||+ palette.getPointer() != app->getPaletteController()+ ->getCurrentLevelPalette()+ ->getPalette() ||+ (level && level->getType() != OVL_XSHLEVEL)) {+ DVGui::warning(QObject::tr("Select a raster drawing palette first."));+ return;+ }++ const TFilePath path = fullColorPalette->getDefaultPalettePath();+ QString question = QObject::tr(+ "Save the current raster drawing palette as the global default?\n\n"+ "Projects with their own raster palette will keep using it.");+ if (TSystem::doesExistFileOrLevel(path))+ question +=+ QObject::tr("\n\nThis will overwrite %1.").arg(path.getQString());+ if (DVGui::MsgBox(question, QObject::tr("Save"), QObject::tr("Cancel"),+ 0) != 1)+ return;++ try {+ fullColorPalette->saveAsDefault(palette.getPointer());+ StudioPalette::instance()->notifyTreeChange();+ } catch (const TException &e) {+ DVGui::warning(+ QObject::tr("Could not save the default raster palette.\n%1")+ .arg(QString::fromStdWString(e.getMessage())));+ } catch (...) {+ DVGui::warning(QObject::tr("Could not save the default raster palette."));+ }+ }+} saveAsDefaultRasterPaletteCommandHandler;+//=============================================================================// Save scene and levels//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cppindex b7d2736db..bf998d088 100644--- a/toonz/sources/toonz/mainwindow.cpp+++ b/toonz/sources/toonz/mainwindow.cpp@@ -2890,6 +2890,9 @@ void MainWindow::defineActions() {QT_TR_NOOP("&Save Palette As..."), "", "saveas");createRightClickMenuAction(MI_OverwritePalette, QT_TR_NOOP("&Save Palette"),"", "save");+ createRightClickMenuAction(MI_SaveAsDefaultRasterPalette,+ QT_TR_NOOP("Save As Default Raster Palette..."),+ "");createRightClickMenuAction(MI_RegeneratePreview,QT_TR_NOOP("&Regenerate Preview"), "");createRightClickMenuAction(MI_RegenerateFramePr,diff --git a/toonz/sources/toonz/menubarcommandids.h b/toonz/sources/toonz/menubarcommandids.hindex f4d6a7dd6..042e494c5 100644--- a/toonz/sources/toonz/menubarcommandids.h+++ b/toonz/sources/toonz/menubarcommandids.h@@ -38,6 +38,7 @@#define MI_ExportAllLevels "MI_ExportAllLevels"#define MI_SavePaletteAs "MI_SavePaletteAs"#define MI_OverwritePalette "MI_OverwritePalette"+#define MI_SaveAsDefaultRasterPalette "MI_SaveAsDefaultRasterPalette"#define MI_LoadColorModel "MI_LoadColorModel"#define MI_ImportMagpieFile "MI_ImportMagpieFile"#define MI_NewNoteLevel "MI_NewNoteLevel"diff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cppindex 2101eaaef..3427cc4ab 100644--- a/toonz/sources/toonz/preferencespopup.cpp+++ b/toonz/sources/toonz/preferencespopup.cpp@@ -2857,6 +2857,9 @@ void PreferencesPopup::onChange() {return;if (m_onEditedFuncMap.contains(id)) (this->*m_onEditedFuncMap[id])();+ if (id == DefLevelType || id == EnableAutocreation)+ TApp::instance()->getCurrentScene()->notifyPreferenceChanged(+ id == DefLevelType ? "DefLevelType" : "EnableAutocreation");}//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/tapp.cpp b/toonz/sources/toonz/tapp.cppindex f6b2be271..e2fe99d8b 100644--- a/toonz/sources/toonz/tapp.cpp+++ b/toonz/sources/toonz/tapp.cpp@@ -47,6 +47,7 @@#include "toonz/tcamera.h"#include "toonz/preferences.h"#include "toonz/txshsoundcolumn.h"+#include "toonz/fullcolorpalette.h"// TnzCore includes#include "tbigmemorymanager.h"@@ -64,6 +65,7 @@#include <QCoreApplication>#include <QApplication>#include <QDesktopWidget>+#include <algorithm>//===================================================================@@ -131,6 +133,11 @@ TApp::TApp()&TApp::onSceneSwitched);connect(m_currentScene, &TSceneHandle::sceneChanged, this,&TApp::onSceneChanged);+ connect(m_currentScene, &TSceneHandle::preferenceChanged, this,+ [this](const QString &name) {+ if (name == "DefLevelType" || name == "EnableAutocreation")+ updateXshLevel();+ });connect(m_currentXsheet, &TXsheetHandle::xsheetSwitched, this,&TApp::onXsheetSwitched);connect(m_currentFrame, &TFrameHandle::frameSwitched, this,@@ -328,6 +335,8 @@ void TApp::updateXshLevel() {int frame = m_currentFrame->getFrame();int column = m_currentColumn->getColumnIndex();TXsheet *xsheet = m_currentXsheet->getXsheet();+ if (!xsheet) return;+ TXshColumn *xshColumn = column >= 0 ? xsheet->getColumn(column) : nullptr;// sound column caseif (xsheet->getColumn(column) &&@@ -351,12 +360,14 @@ void TApp::updateXshLevel() {}}+ TPalette *currentPalette =+ m_paletteController->getCurrentPalette()->getPalette();+ const bool editingCleanup =+ currentPalette && currentPalette->isCleanupPalette();m_currentLevel->setLevel(xl);// level could be the same, but palette could have changedif (xl && xl->getSimpleLevel()) {- TPalette *currentPalette =- m_paletteController->getCurrentPalette()->getPalette();int styleIndex =m_paletteController->getCurrentLevelPalette()->getStyleIndex();@@ -365,17 +376,49 @@ void TApp::updateXshLevel() {// If the new selected level is an OVL and the current palette is a// cleanup palette, then set the current handle to the cleanup palette.- if (xl->getType() == OVL_XSHLEVEL && currentPalette &&- currentPalette->isCleanupPalette())-+ if (xl->getType() == OVL_XSHLEVEL && editingCleanup)m_paletteController->editCleanupPalette();} else if (xl && xl->getPaletteLevel()) {int styleIndex =m_paletteController->getCurrentLevelPalette()->getStyleIndex();m_paletteController->getCurrentLevelPalette()->setPalette(xl->getPaletteLevel()->getPalette(), styleIndex);- } else- m_paletteController->getCurrentLevelPalette()->setPalette(0);+ } else {+ TPalette *rasterPalette = nullptr;+ Preferences *preferences = Preferences::instance();+ if (!xl && column >= 0 && frame >= 0 &&+ preferences->isAutoCreateEnabled() &&+ (!xshColumn ||+ (xshColumn->getLevelColumn() && !xshColumn->isLocked() &&+ xshColumn->isCamstandVisible()))) {+ if (xsheet->isColumnEmpty(column)) {+ if (preferences->getDefLevelType() == OVL_XSHLEVEL)+ rasterPalette = FullColorPalette::instance()->getPalette(+ m_currentScene->getScene());+ } else {+ // Match the level chosen by touchImage without changing the current+ // level or enabling level commands on an empty cell.+ int r0, r1;+ xsheet->getCellRange(column, r0, r1);+ int previous = std::min(frame - 1, r1);+ int next = std::max(frame + 1, r0);+ while (previous >= r0 && xsheet->getCell(previous, column).isEmpty())+ --previous;+ while (next <= r1 && xsheet->getCell(next, column).isEmpty()) ++next;+ TXshSimpleLevel *rasterLevel =+ previous >= r0+ ? xsheet->getCell(previous, column).getSimpleLevel()+ : next <= r1 ? xsheet->getCell(next, column).getSimpleLevel()+ : nullptr;+ if (rasterLevel && rasterLevel->getType() == OVL_XSHLEVEL &&+ !rasterLevel->isSubsequence() && !rasterLevel->isReadOnly())+ rasterPalette = rasterLevel->getPalette();+ }+ }+ m_paletteController->getCurrentLevelPalette()->setPalette(rasterPalette);+ if (rasterPalette && editingCleanup)+ m_paletteController->editCleanupPalette();+ }}}diff --git a/toonz/sources/toonzlib/fullcolorpalette.cpp b/toonz/sources/toonzlib/fullcolorpalette.cppindex 875cc9853..0e4c74381 100644--- a/toonz/sources/toonzlib/fullcolorpalette.cpp+++ b/toonz/sources/toonzlib/fullcolorpalette.cpp@@ -4,10 +4,52 @@#include "toonz/tscenehandle.h"#include "toonz/toonzscene.h"#include "toonz/toonzfolders.h"+#include "toonz/tproject.h"#include "tsystem.h"#include "tstream.h"#include "tpalette.h"+#include <QDebug>+#include <QFile>+#include <QSaveFile>+#include <QTemporaryDir>++namespace {++void writePaletteFile(const TFilePath &path, TPalette *palette) {+ if (!TSystem::touchParentDir(path))+ throw TSystemException(path, "Could not create the palette folder.");++ QTemporaryDir temporary(path.getQString() + ".XXXXXX");+ if (!temporary.isValid())+ throw TSystemException(path, temporary.errorString().toStdString());+ // QTemporaryFile keeps its native handle open even after close(), which+ // prevents the Windows native stream from reopening the snapshot for writing.+ const QString snapshot = temporary.filePath("palette.tpl");+ {+ TOStream os{TFilePath(snapshot)};+ if (!os)+ throw TSystemException(path, "Could not write the palette snapshot.");+ os << palette;+ if (!os.checkStatus())+ throw TSystemException(path, "Could not finish the palette snapshot.");+ }++ QFile input(snapshot);+ if (!input.open(QIODevice::ReadOnly))+ throw TSystemException(path, input.errorString().toStdString());+ const QByteArray data = input.readAll();+ if (input.error() != QFileDevice::NoError)+ throw TSystemException(path, input.errorString().toStdString());++ QSaveFile output(path.getQString());+ if (!output.open(QIODevice::WriteOnly) || output.write(data) != data.size() ||+ !output.commit())+ throw TSystemException(path, output.errorString().toStdString());+}++} // namespace+//==================================================//// FullColorPalette@@ -38,28 +80,47 @@ void FullColorPalette::clear() {//----------------------------------------------------+bool FullColorPalette::getDirtyFlag() const {+ return m_palette && m_palette->getDirtyFlag();+}++//----------------------------------------------------+TPalette *FullColorPalette::getPalette(ToonzScene *scene) {if (m_palette) return m_palette;m_palette = new TPalette();m_palette->addRef();- TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath);- if (!TSystem::doesExistFileOrLevel(fullPath)) {- // Per I francesi che hanno il nome vecchio della paletta- // Verra' caricata la vecchia ma salvata col nome nuovo!- TFilePath app("+palettes\\fullcolorPalette.tpl");- fullPath = scene->decodeFilePath(app);+ TFilePath fullPath = getDefaultPalettePath();+ if (scene && scene->getProject() &&+ scene->getProject()->getFolderIndex("palettes") >= 0) {+ fullPath = scene->decodeFilePath(m_fullcolorPalettePath);+ if (!TSystem::doesExistFileOrLevel(fullPath)) {+ // Read the legacy project palette, but save under the current name.+ fullPath =+ scene->decodeFilePath(TFilePath("+palettes\\fullcolorPalette.tpl"));+ }}if (!TSystem::doesExistFileOrLevel(fullPath)) {- fullPath = ToonzFolder::getStudioPaletteFolder() +- "Global Palettes\\Default Palettes\\Raster_Drawing_Palette.tpl";+ fullPath = getDefaultPalettePath();}if (TSystem::doesExistFileOrLevel(fullPath)) {- TPalette *app = new TPalette();- TIStream is(fullPath);- is >> app;- m_palette->assign(app);- delete app;- }+ try {+ TIStream is(fullPath);+ std::string tagName;+ if (!is || !is.matchTag(tagName) || tagName != "palette")+ throw TException("Invalid raster palette.");+ TPaletteP loaded(new TPalette());+ loaded->loadData(is);+ if (!is.matchEndTag() || loaded->getStyleCount() < 2 ||+ !loaded->getStylePage(0) || !loaded->getStylePage(1))+ throw TException("The raster palette is missing its base styles.");+ loaded->addRef();+ m_palette->release();+ m_palette = loaded.getPointer();+ } catch (...) {+ qWarning() << "Could not load raster palette:" << fullPath.getQString();+ }+ }m_palette->setPaletteName(L"Raster Drawing Palette");return m_palette;@@ -68,14 +129,25 @@ TPalette *FullColorPalette::getPalette(ToonzScene *scene) {//----------------------------------------------------void FullColorPalette::savePalette(ToonzScene *scene) {- if (!m_palette || !m_palette->getDirtyFlag()) return;-- TFilePath fullPath = scene->decodeFilePath(m_fullcolorPalettePath);- if (TSystem::touchParentDir(fullPath)) {- if (TSystem::doesExistFileOrLevel(fullPath))- TSystem::removeFileOrLevel(fullPath);- TOStream os(fullPath);- os << m_palette;- m_palette->setDirtyFlag(false);- }+ if (!getDirtyFlag()) return;+ if (!scene || !scene->getProject() ||+ scene->getProject()->getFolderIndex("palettes") < 0)+ throw TSystemException("The project has no palettes folder.");++ writePaletteFile(scene->decodeFilePath(m_fullcolorPalettePath), m_palette);+ m_palette->setDirtyFlag(false);+}++//----------------------------------------------------++TFilePath FullColorPalette::getDefaultPalettePath() const {+ return ToonzFolder::getStudioPaletteFolder() ++ "Global Palettes\\Default Palettes\\Raster_Drawing_Palette.tpl";+}++//----------------------------------------------------++void FullColorPalette::saveAsDefault(TPalette *palette) {+ if (!palette) return;+ writePaletteFile(getDefaultPalettePath(), palette);}diff --git a/toonz/sources/toonzqt/paletteviewer.cpp b/toonz/sources/toonzqt/paletteviewer.cppindex 2e55adcbe..c6084afec 100644--- a/toonz/sources/toonzqt/paletteviewer.cpp+++ b/toonz/sources/toonzqt/paletteviewer.cpp@@ -598,6 +598,20 @@ void PaletteViewer::createPaletteToolBar() {viewModeButton->setMenu(viewMode);+ if (m_viewType == LEVEL_PALETTE && m_hasSavePaletteToolbar) {+ viewMode->addSeparator();+ QAction *command =+ CommandManager::instance()->getAction("MI_SaveAsDefaultRasterPalette");+ QAction *saveDefault = viewMode->addAction(command->text());+ connect(saveDefault, &QAction::triggered, command, &QAction::trigger);+ connect(viewMode, &QMenu::aboutToShow, this, [this, saveDefault]() {+ TPalette *palette = getPalette();+ saveDefault->setEnabled(+ m_isSaveActionEnabled && palette && !palette->isCleanupPalette() &&+ FullColorPalette::instance()->isFullColorPalette(palette));+ });+ }+// Attention: having reversed the direction I must add objects in reverse// order@@ -847,6 +861,9 @@ void PaletteViewer::contextMenuEvent(QContextMenuEvent *event) {menu->addAction(CommandManager::instance()->getAction("MI_OverwritePalette"));menu->addAction(CommandManager::instance()->getAction("MI_SavePaletteAs"));+ if (FullColorPalette::instance()->isFullColorPalette(getPalette()))+ menu->addAction(CommandManager::instance()->getAction(+ "MI_SaveAsDefaultRasterPalette"));}if (m_viewType == LEVEL_PALETTE && !getPalette()->isLocked() &&diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cppindex a44e5fed8..def3f3f5a 100644--- a/toonz/sources/toonzqt/paletteviewergui.cpp+++ b/toonz/sources/toonzqt/paletteviewergui.cpp@@ -21,6 +21,7 @@#include "toonz/tframehandle.h"#include "toonz/imagestyles.h"#include "toonz/preferences.h"+#include "toonz/fullcolorpalette.h"// TnzCore includes#include "tcolorstyles.h"@@ -1837,6 +1838,9 @@ void PageViewer::updateCommandLocks() {cmd->getAction("MI_GetColorFromStudioPalette")->setEnabled(!isLocked);cmd->getAction("MI_ToggleLinkToStudioPalette")->setEnabled(!isLocked);cmd->getAction("MI_RemoveReferenceToStudioPalette")->setEnabled(!isLocked);- cmd->getAction("MI_EraseUnusedStyles")->setEnabled(!isLocked);+ cmd->getAction("MI_EraseUnusedStyles")+ ->setEnabled(!isLocked &&+ !FullColorPalette::instance()->isFullColorPalette(+ m_page->getPalette()));update();}diff --git a/toonz/sources/toonzqt/styleselection.cpp b/toonz/sources/toonzqt/styleselection.cppindex 997ccab5e..8eff4782f 100644--- a/toonz/sources/toonzqt/styleselection.cpp+++ b/toonz/sources/toonzqt/styleselection.cpp@@ -18,6 +18,7 @@#include "toonz/cleanupcolorstyles.h"#include "toonz/txshlevelhandle.h"#include "toonz/levelproperties.h"+#include "toonz/fullcolorpalette.h"// TnzCore includes#include "tcolorstyles.h"@@ -694,9 +695,11 @@ void TStyleSelection::deleteStyles() {//-------------------------------------------------------------------void TStyleSelection::eraseUnusedStyle() {+ TPalette *palette = m_paletteHandle ? m_paletteHandle->getPalette() : nullptr;+ if (!palette || FullColorPalette::instance()->isFullColorPalette(palette))+ return;std::set<TXshSimpleLevel *> levels;int row, column, i, j;- TPalette *palette = m_paletteHandle->getPalette();findPaletteLevels(levels, row, column, palette, m_xsheetHandle->getXsheet());// Check which styles are used and which are not@@ -1878,4 +1881,4 @@ bool TStyleSelection::hasLinkedStyle() {}}return false;-}\ No newline at end of file+}