diff --git a/toonz/sources/include/toonz/palettecmd.h b/toonz/sources/include/toonz/palettecmd.h index bca5440..cc37f9d 100644 --- a/toonz/sources/include/toonz/palettecmd.h +++ b/toonz/sources/include/toonz/palettecmd.h @@ -88,6 +88,9 @@ DVAPI void renamePalettePage(TPaletteHandle *paletteHandle, int pageIndex, DVAPI void renamePaletteStyle(TPaletteHandle *paletteHandle, const std::wstring &newName); +/* called in ColorModelViewer::pick() - move selected style to the first page */ +DVAPI void organizePaletteStyle(TPaletteHandle *paletteHandle, int styleId); + } // namespace #endif diff --git a/toonz/sources/toonz/colormodelviewer.cpp b/toonz/sources/toonz/colormodelviewer.cpp index 69e207f..474a3e0 100644 --- a/toonz/sources/toonz/colormodelviewer.cpp +++ b/toonz/sources/toonz/colormodelviewer.cpp @@ -308,10 +308,16 @@ void ColorModelViewer::pick(const QPoint &p) { } /* - if the Style Picker too is current and "organize palette" is activated, + if the Style Picker tool is current and "organize palette" is activated, then move the picked style to the first page of the palette. */ - //TODO: write organize palette operation here (maybe implement in PaletteCmd) + TTool *tool = TApp::instance()->getCurrentTool()->getTool(); + if (tool->getName() == "T_StylePicker"){ + StylePickerTool* spTool = dynamic_cast(tool); + if (spTool && spTool->isOrganizePaletteActive()){ + PaletteCmd::organizePaletteStyle(ph, styleIndex); + } + } ph->setStyleIndex(styleIndex); } diff --git a/toonz/sources/toonzlib/palettecmd.cpp b/toonz/sources/toonzlib/palettecmd.cpp index 30a0390..5c375bd 100644 --- a/toonz/sources/toonzlib/palettecmd.cpp +++ b/toonz/sources/toonzlib/palettecmd.cpp @@ -1168,3 +1168,26 @@ void PaletteCmd::renamePaletteStyle(TPaletteHandle *paletteHandle, paletteHandle->notifyColorStyleChanged(false); TUndoManager::manager()->add(undo); } + +//============================================================================= +// organizePaletteStyle +// called in ColorModelViewer::pick() - move selected style to the first page +//----------------------------------------------------------------------------- +void PaletteCmd::organizePaletteStyle(TPaletteHandle *paletteHandle, int styleId){ + if (!paletteHandle) return; + TPalette *palette = paletteHandle->getPalette(); + if (!palette) return; + // if the style is already in the first page, then do nothing + TPalette::Page* page = palette->getStylePage(styleId); + if (!page || page->getIndex() == 0) return; + + int indexInPage = page->search(styleId); + + /* + just call arrangeStyles as tentative implementation. + TODO: store the picked position into the style name somehow + */ + arrangeStyles(paletteHandle, 0, palette->getPage(0)->getStyleCount(), + page->getIndex(), { indexInPage }); + +}