diff --git a/toonz/sources/include/toonzqt/styleselection.h b/toonz/sources/include/toonzqt/styleselection.h index d18bccf..6e5099e 100644 --- a/toonz/sources/include/toonzqt/styleselection.h +++ b/toonz/sources/include/toonzqt/styleselection.h @@ -98,6 +98,8 @@ public: void removeLink(); // get back the style from the studio palette (if linked) void getBackOriginalStyle(); + // return true if there is at least one linked style in the selection + bool hasLinkedStyle(); }; #endif // STYLESELECTION_INCLUDED diff --git a/toonz/sources/toonzlib/studiopalettecmd.cpp b/toonz/sources/toonzlib/studiopalettecmd.cpp index 8cf07e9..c8023ec 100644 --- a/toonz/sources/toonzlib/studiopalettecmd.cpp +++ b/toonz/sources/toonzlib/studiopalettecmd.cpp @@ -501,7 +501,11 @@ void StudioPaletteCmd::loadIntoCurrentPalette(TPaletteHandle *paletteHandle, // keep the color model path unchanged TFilePath oldRefImagePath = current->getRefImgPath(); + std::wstring oldGlobalName = current->getGlobalName(); current->assign(palette, true); + // keep global name unchanged + current->setGlobalName(oldGlobalName); + current->setDirtyFlag(true); current->setRefImgPath(oldRefImagePath); diff --git a/toonz/sources/toonzqt/paletteviewergui.cpp b/toonz/sources/toonzqt/paletteviewergui.cpp index b30936b..bf826a7 100644 --- a/toonz/sources/toonzqt/paletteviewergui.cpp +++ b/toonz/sources/toonzqt/paletteviewergui.cpp @@ -1023,7 +1023,8 @@ void PageViewer::contextMenuEvent(QContextMenuEvent *event) { // remove links from studio palette if (m_viewType == LEVEL_PALETTE && m_styleSelection && - !m_styleSelection->isEmpty() && !isLocked) { + !m_styleSelection->isEmpty() && !isLocked && + m_styleSelection->hasLinkedStyle()) { menu.addSeparator(); QAction *toggleStyleLink = cmd->getAction("MI_ToggleLinkToStudioPalette"); menu.addAction(toggleStyleLink); diff --git a/toonz/sources/toonzqt/styleselection.cpp b/toonz/sources/toonzqt/styleselection.cpp index 1b49737..99f9bb9 100644 --- a/toonz/sources/toonzqt/styleselection.cpp +++ b/toonz/sources/toonzqt/styleselection.cpp @@ -1794,3 +1794,26 @@ void TStyleSelection::getBackOriginalStyle() { } else delete undo; } + +//----------------------------------------------------------------------------- +/*! return true if there is at least one linked style in the selection +*/ + +bool TStyleSelection::hasLinkedStyle() { + TPalette *palette = getPalette(); + if (!palette || m_pageIndex < 0 || isEmpty()) return false; + if (m_styleIndicesInPage.size() <= 0) return false; + + TPalette::Page *page = palette->getPage(m_pageIndex); + assert(page); + + // for each selected style + for (std::set::iterator it = m_styleIndicesInPage.begin(); + it != m_styleIndicesInPage.end(); ++it) { + TColorStyle *cs = page->getStyle(*it); + std::wstring gname = cs->getGlobalName(); + // if the style has link, return true + if (gname != L"" && (gname[0] == L'-' || gname[0] == L'+')) return true; + } + return false; +}