OpenToonz - An open-source full-featured 2D animation creation software
C
Organize Custom Panel templates in folders (#6983)
Ahl7673f4ae5d3b1f
diff --git a/stuff/library/custom panel templates/25 buttons grid .ui b/stuff/library/custom panel templates/Templates/Grids/25 buttons grid .uisimilarity index 100%rename from stuff/library/custom panel templates/25 buttons grid .uirename to stuff/library/custom panel templates/Templates/Grids/25 buttons grid .uidiff --git a/stuff/library/custom panel templates/25 buttons grid seamless.ui b/stuff/library/custom panel templates/Templates/Grids/25 buttons grid seamless.uisimilarity index 100%rename from stuff/library/custom panel templates/25 buttons grid seamless.uirename to stuff/library/custom panel templates/Templates/Grids/25 buttons grid seamless.uidiff --git a/stuff/library/custom panel templates/25 buttons grid spaced.ui b/stuff/library/custom panel templates/Templates/Grids/25 buttons grid spaced.uisimilarity index 100%rename from stuff/library/custom panel templates/25 buttons grid spaced.uirename to stuff/library/custom panel templates/Templates/Grids/25 buttons grid spaced.uidiff --git a/stuff/library/custom panel templates/9 buttons grid.ui b/stuff/library/custom panel templates/Templates/Grids/9 buttons grid.uisimilarity index 100%rename from stuff/library/custom panel templates/9 buttons grid.uirename to stuff/library/custom panel templates/Templates/Grids/9 buttons grid.uidiff --git a/stuff/library/custom panel templates/drawing toolbox.ui b/stuff/library/custom panel templates/Templates/Grids/drawing toolbox.uisimilarity index 100%rename from stuff/library/custom panel templates/drawing toolbox.uirename to stuff/library/custom panel templates/Templates/Grids/drawing toolbox.uidiff --git a/stuff/library/custom panel templates/eight buttons.ui b/stuff/library/custom panel templates/Templates/Grids/eight buttons.uisimilarity index 100%rename from stuff/library/custom panel templates/eight buttons.uirename to stuff/library/custom panel templates/Templates/Grids/eight buttons.uidiff --git a/stuff/library/custom panel templates/one button.ui b/stuff/library/custom panel templates/Templates/Grids/one button.uisimilarity index 100%rename from stuff/library/custom panel templates/one button.uirename to stuff/library/custom panel templates/Templates/Grids/one button.uidiff --git a/stuff/library/custom panel templates/two button.ui b/stuff/library/custom panel templates/Templates/Grids/two button.uisimilarity index 100%rename from stuff/library/custom panel templates/two button.uirename to stuff/library/custom panel templates/Templates/Grids/two button.uidiff --git a/stuff/library/custom panel templates/classic horizontal bar seamless.ui b/stuff/library/custom panel templates/Templates/Horizontal Bars/Classic/classic horizontal bar seamless.uisimilarity index 100%rename from stuff/library/custom panel templates/classic horizontal bar seamless.uirename to stuff/library/custom panel templates/Templates/Horizontal Bars/Classic/classic horizontal bar seamless.uidiff --git a/stuff/library/custom panel templates/mini modern horizontal bar seamless large.ui b/stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/mini modern horizontal bar seamless large.uisimilarity index 100%rename from stuff/library/custom panel templates/mini modern horizontal bar seamless large.uirename to stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/mini modern horizontal bar seamless large.uidiff --git a/stuff/library/custom panel templates/mini modern horizontal bar seamless.ui b/stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/mini modern horizontal bar seamless.uisimilarity index 100%rename from stuff/library/custom panel templates/mini modern horizontal bar seamless.uirename to stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/mini modern horizontal bar seamless.uidiff --git a/stuff/library/custom panel templates/modern horizontal bar seamless v2.ui b/stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/modern horizontal bar seamless v2.uisimilarity index 100%rename from stuff/library/custom panel templates/modern horizontal bar seamless v2.uirename to stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/modern horizontal bar seamless v2.uidiff --git a/stuff/library/custom panel templates/modern horizontal bar seamless.ui b/stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/modern horizontal bar seamless.uisimilarity index 100%rename from stuff/library/custom panel templates/modern horizontal bar seamless.uirename to stuff/library/custom panel templates/Templates/Horizontal Bars/Modern/modern horizontal bar seamless.uidiff --git a/stuff/library/custom panel templates/circular radial buttons.ui b/stuff/library/custom panel templates/Templates/Radials/circular radial buttons.uisimilarity index 100%rename from stuff/library/custom panel templates/circular radial buttons.uirename to stuff/library/custom panel templates/Templates/Radials/circular radial buttons.uidiff --git a/stuff/library/custom panel templates/classic circular radial buttons.ui b/stuff/library/custom panel templates/Templates/Radials/classic circular radial buttons.uisimilarity index 100%rename from stuff/library/custom panel templates/classic circular radial buttons.uirename to stuff/library/custom panel templates/Templates/Radials/classic circular radial buttons.uidiff --git a/stuff/library/custom panel templates/extended radial buttons.ui b/stuff/library/custom panel templates/Templates/Radials/extended radial buttons.uisimilarity index 100%rename from stuff/library/custom panel templates/extended radial buttons.uirename to stuff/library/custom panel templates/Templates/Radials/extended radial buttons.uidiff --git a/stuff/library/custom panel templates/rectangular radial buttons.ui b/stuff/library/custom panel templates/Templates/Radials/rectangular radial buttons.uisimilarity index 100%rename from stuff/library/custom panel templates/rectangular radial buttons.uirename to stuff/library/custom panel templates/Templates/Radials/rectangular radial buttons.uidiff --git a/stuff/library/custom panel templates/classic vertical bar seamless icon large.ui b/stuff/library/custom panel templates/Templates/Vertical Bars/Classic/classic vertical bar seamless icon large.uisimilarity index 100%rename from stuff/library/custom panel templates/classic vertical bar seamless icon large.uirename to stuff/library/custom panel templates/Templates/Vertical Bars/Classic/classic vertical bar seamless icon large.uidiff --git a/stuff/library/custom panel templates/classic vertical bar seamless.ui b/stuff/library/custom panel templates/Templates/Vertical Bars/Classic/classic vertical bar seamless.uisimilarity index 100%rename from stuff/library/custom panel templates/classic vertical bar seamless.uirename to stuff/library/custom panel templates/Templates/Vertical Bars/Classic/classic vertical bar seamless.uidiff --git a/stuff/library/custom panel templates/classic vertical bar spaced.ui b/stuff/library/custom panel templates/Templates/Vertical Bars/Classic/classic vertical bar spaced.uisimilarity index 100%rename from stuff/library/custom panel templates/classic vertical bar spaced.uirename to stuff/library/custom panel templates/Templates/Vertical Bars/Classic/classic vertical bar spaced.uidiff --git a/stuff/library/custom panel templates/mini modern vertical bar seamless.ui b/stuff/library/custom panel templates/Templates/Vertical Bars/Modern/mini modern vertical bar seamless.uisimilarity index 100%rename from stuff/library/custom panel templates/mini modern vertical bar seamless.uirename to stuff/library/custom panel templates/Templates/Vertical Bars/Modern/mini modern vertical bar seamless.uidiff --git a/stuff/library/custom panel templates/modern vertical bar divided.ui b/stuff/library/custom panel templates/Templates/Vertical Bars/Modern/modern vertical bar divided.uisimilarity index 100%rename from stuff/library/custom panel templates/modern vertical bar divided.uirename to stuff/library/custom panel templates/Templates/Vertical Bars/Modern/modern vertical bar divided.uidiff --git a/stuff/library/custom panel templates/modern vertical bar framed.ui b/stuff/library/custom panel templates/Templates/Vertical Bars/Modern/modern vertical bar framed.uisimilarity index 100%rename from stuff/library/custom panel templates/modern vertical bar framed.uirename to stuff/library/custom panel templates/Templates/Vertical Bars/Modern/modern vertical bar framed.uidiff --git a/stuff/library/custom panel templates/modern vertical bar seamless.ui b/stuff/library/custom panel templates/Templates/Vertical Bars/Modern/modern vertical bar seamless.uisimilarity index 100%rename from stuff/library/custom panel templates/modern vertical bar seamless.uirename to stuff/library/custom panel templates/Templates/Vertical Bars/Modern/modern vertical bar seamless.uidiff --git a/toonz/sources/toonz/custompaneleditorpopup.cpp b/toonz/sources/toonz/custompaneleditorpopup.cppindex f9bf180f5..60136ddfa 100644--- a/toonz/sources/toonz/custompaneleditorpopup.cpp+++ b/toonz/sources/toonz/custompaneleditorpopup.cpp@@ -19,6 +19,7 @@// ToonzCore#include "tsystem.h"+#include "tfilepath.h"// Qt includes#include <QMainWindow>@@ -30,7 +31,6 @@#include <QApplication>#include <QLabel>#include <QScrollArea>-#include <QComboBox>#include <QCheckBox>#include <QPushButton>#include <QUiLoader>@@ -41,6 +41,14 @@#include <QToolButton>#include <QRegularExpression>#include <QInputDialog>+#include <QFrame>+#include <QVBoxLayout>+#include <QHBoxLayout>+#include <QEvent>+#include <QFileInfo>+#include <QDir>+#include <QFile>+#include <algorithm>namespace {const TFilePath CustomPanelTemplateFolderName("custom panel templates");@@ -55,6 +63,105 @@ TFilePath customPaneFolderPath() {return ToonzFolder::getMyModuleDir() + CustomPanelFolderName;}+// Mirror up to 3 nested subfolders under the template / custom panel roots.+const int kMaxTemplateFolderDepth = 3;++// Accent already defined by each theme (no theme-file edits): same fill as+// Tool Properties toggles / checked tool buttons / tree selection.+QColor themeHighlightAccent() {+ const QString styleSheet = qApp->styleSheet();+ auto colorFromRule = [&styleSheet](const QString& selector) -> QColor {+ const QRegularExpression re(+ QStringLiteral(R"(%1\s*\{[^}]*?background-color:\s*([^;]+);)")+ .arg(selector),+ QRegularExpression::DotMatchesEverythingOption |+ QRegularExpression::CaseInsensitiveOption);+ const QRegularExpressionMatch m = re.match(styleSheet);+ if (!m.hasMatch()) return QColor();+ return QColor(m.captured(1).trimmed());+ };++ // Prefer QToolButton:checked — exact square used by Tool Properties headers+ QColor accent = colorFromRule(QStringLiteral(R"(QToolButton:checked)"));+ if (accent.isValid()) return accent;++ accent = colorFromRule(QStringLiteral(R"(QTreeView::item:selected)"));+ if (accent.isValid()) return accent;++ return qApp->palette().color(QPalette::Highlight);+}++// Tool Properties style: accent square + white triangle (not a tinted triangle).+QByteArray openBranchBadgeSvg(const QColor& accent) {+ return QStringLiteral(+ "<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' "+ "viewBox='0 0 16 16'>"+ "<rect width='16' height='16' fill='%1'/>"+ "<path fill='#ffffff' d='M 4,5 L 12,5 L 8,11 Z'/>"+ "</svg>")+ .arg(accent.name(QColor::HexRgb))+ .toUtf8();+}++bool writeTempSvg(const QString& fileName, const QByteArray& svg) {+ const QString path = QDir::temp().filePath(fileName);+ QFile file(path);+ if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) return false;+ file.write(svg);+ return true;+}++QString cssUrlForTempFile(const QString& fileName) {+ QString path = QDir::temp().filePath(fileName);+ path.replace(QLatin1Char('\\'), QLatin1Char('/'));+ return path;+}++// Classic yellow folder icon (colored asset).+QIcon templateFolderIcon() { return createQIcon(QStringLiteral("folder")); }++void applyFolderIconRecursive(QTreeWidgetItem* item, const QIcon& folderIcon) {+ if (!item) return;+ if (item->data(0, Qt::UserRole).toString().isEmpty())+ item->setIcon(0, folderIcon);+ for (int i = 0; i < item->childCount(); ++i)+ applyFolderIconRecursive(item->child(i), folderIcon);+}++// Expanded folders: accent square around a white triangle (like Tool Properties).+// Collapsed folders keep the theme's default white branch indicators.+void applyTemplateTreeBranchAccent(QTreeWidget* tree) {+ if (!tree) return;++ const QColor accent = themeHighlightAccent();+ if (!accent.isValid()) return;++ const QString hex = accent.name(QColor::HexRgb).mid(1);+ const QString openName =+ QStringLiteral("opentoonz_cp_treebranch_badge_%1.svg").arg(hex);+ if (!writeTempSvg(openName, openBranchBadgeSvg(accent))) return;++ const QString openUrl = cssUrlForTempFile(openName);+ tree->setStyleSheet(QStringLiteral(+ "QTreeView::branch:has-children:open,"+ "QTreeView::branch:has-children:has-siblings:open {"+ " background: url(\"%1\") no-repeat center center;"+ " border-image: none;"+ " image: none;"+ "}")+ .arg(openUrl));+}++// Same as ToolPropertiesPanel collapsibles: checked → QSS @hl-color square,+// arrow painted white via QToolButton:checked { color: white; }.+void applyTemplateToggleAccent(QToolButton* toggle, bool browserOpen) {+ if (!toggle) return;+ toggle->setCheckable(true);+ toggle->setIcon(QIcon());+ toggle->setChecked(browserOpen);+ toggle->setArrowType(browserOpen ? Qt::DownArrow : Qt::RightArrow);+}+QPoint relativePos(QWidget* child, QWidget* refParent) {if (child->parentWidget() == refParent) {return child->pos();@@ -63,6 +170,50 @@ QPoint relativePos(QWidget* child, QWidget* refParent) {}}+QString relativePanelId(const TFilePath& file, const TFilePath& rootFolder) {+ TFilePath relative = file - rootFolder;+ QString id = relative.withType("").getQString();+ id.replace('\\', '/');+ return id;+}++void collectUiPanelIds(const TFilePath& folder, const TFilePath& rootFolder,+ int depth, QStringList& outIds) {+ if (!TSystem::doesExistFileOrLevel(folder)) return;++ TFilePathSet entries =+ TSystem::readDirectory(folder, false, false, false);++ QList<TFilePath> dirs;+ QList<TFilePath> files;+ for (const auto& entry : entries) {+ if (TFileStatus(entry).isDirectory())+ dirs.append(entry);+ else if (entry.getType() == "ui")+ files.append(entry);+ }++ std::sort(dirs.begin(), dirs.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(a.getQString(), b.getQString(),+ Qt::CaseInsensitive) < 0;+ });+ std::sort(files.begin(), files.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(QString::fromStdString(a.getName()),+ QString::fromStdString(b.getName()),+ Qt::CaseInsensitive) < 0;+ });++ if (depth < kMaxTemplateFolderDepth) {+ for (const auto& dir : dirs)+ collectUiPanelIds(dir, rootFolder, depth + 1, outIds);+ }++ for (const auto& file : files)+ outIds.append(relativePanelId(file, rootFolder));+}+} // anonymous namespace//=============================================================================@@ -77,6 +228,8 @@ CustomPanelUIField::CustomPanelUIField(int objId, const QString& objectName,setFont(fnt);setStyleSheet("background-color: rgb(255, 255, 128); color: black;");setAcceptDrops(true);+ // Original sizing = QLabel sizeHint; Fixed policy only prevents layout stretch+ setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);// objName may be a commandIdif (setCommand(objectName)) {@@ -311,8 +464,224 @@ void UiPreviewArea::resizeEvent(QResizeEvent* event) {// CustomPanelEditorPopup//-----------------------------------------------------------------------------+void CustomPanelEditorPopup::populateTemplateFolder(QTreeWidgetItem* parent,+ const TFilePath& folder,+ int depth,+ bool isEditSection,+ const QIcon& folderIcon) {+ if (!TSystem::doesExistFileOrLevel(folder)) return;++ TFilePathSet entries =+ TSystem::readDirectory(folder, false, false, false);++ QList<TFilePath> dirs;+ QList<TFilePath> files;+ for (const auto& entry : entries) {+ if (TFileStatus(entry).isDirectory())+ dirs.append(entry);+ else if (entry.getType() == "ui")+ files.append(entry);+ }++ std::sort(dirs.begin(), dirs.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(QString::fromStdString(a.getName()),+ QString::fromStdString(b.getName()),+ Qt::CaseInsensitive) < 0;+ });+ std::sort(files.begin(), files.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(QString::fromStdString(a.getName()),+ QString::fromStdString(b.getName()),+ Qt::CaseInsensitive) < 0;+ });++ if (depth < kMaxTemplateFolderDepth) {+ for (const auto& dir : dirs) {+ QTreeWidgetItem* folderItem = new QTreeWidgetItem(+ QStringList(QString::fromStdString(dir.getName())));+ folderItem->setIcon(0, folderIcon);+ folderItem->setFlags(Qt::ItemIsEnabled);+ folderItem->setData(0, Qt::UserRole, QString());+ populateTemplateFolder(folderItem, dir, depth + 1, isEditSection,+ folderIcon);+ if (folderItem->childCount() == 0) {+ delete folderItem;+ continue;+ }+ if (parent)+ parent->addChild(folderItem);+ else+ m_templateTree->addTopLevelItem(folderItem);+ }+ }++ for (const auto& file : files) {+ QString name = QString::fromStdString(file.getName());+ if (isEditSection) name = tr("%1 (Edit)").arg(name);+ QTreeWidgetItem* fileItem = new QTreeWidgetItem(QStringList(name));+ fileItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);+ fileItem->setData(0, Qt::UserRole, file.getQString());+ if (parent)+ parent->addChild(fileItem);+ else+ m_templateTree->addTopLevelItem(fileItem);+ }+}++//-----------------------------------------------------------------------------++QTreeWidgetItem* CustomPanelEditorPopup::findFirstTemplateItem(+ QTreeWidgetItem* parent) const {+ if (!parent) {+ for (int i = 0; i < m_templateTree->topLevelItemCount(); ++i) {+ QTreeWidgetItem* found =+ findFirstTemplateItem(m_templateTree->topLevelItem(i));+ if (found) return found;+ }+ return nullptr;+ }++ if (!parent->data(0, Qt::UserRole).toString().isEmpty()) return parent;++ for (int i = 0; i < parent->childCount(); ++i) {+ QTreeWidgetItem* found = findFirstTemplateItem(parent->child(i));+ if (found) return found;+ }+ return nullptr;+}++//-----------------------------------------------------------------------------++QString CustomPanelEditorPopup::currentTemplatePath() const {+ return m_currentTemplatePath;+}++//-----------------------------------------------------------------------------++QString CustomPanelEditorPopup::templateDisplayNameForItem(+ QTreeWidgetItem* item) const {+ if (!item) return QString();+ QStringList parts;+ for (QTreeWidgetItem* p = item; p; p = p->parent())+ parts.prepend(p->text(0));+ return parts.join(QStringLiteral(" / "));+}++//-----------------------------------------------------------------------------++void CustomPanelEditorPopup::updateTemplateValueLabel() {+ if (!m_templateValueLabel) return;+ QTreeWidgetItem* item = findTemplateItemByPath(m_currentTemplatePath);+ if (item)+ m_templateValueLabel->setText(templateDisplayNameForItem(item));+ else if (!m_currentTemplatePath.isEmpty())+ m_templateValueLabel->setText(+ QFileInfo(m_currentTemplatePath).completeBaseName());+ else+ m_templateValueLabel->setText(tr("(none)"));+}++//-----------------------------------------------------------------------------++void CustomPanelEditorPopup::setTemplateBrowserVisible(bool visible) {+ if (!m_templateBrowser) return;++ m_templateBrowser->setVisible(visible);+ applyTemplateToggleAccent(m_templateToggle, visible);++ // Do not clear search / rewrite expand state — user controls the tree+ if (visible && m_templateSearchEdit) m_templateSearchEdit->setFocus();+}++//-----------------------------------------------------------------------------++QString CustomPanelEditorPopup::templateTreeItemKey(QTreeWidgetItem* item) {+ if (!item) return QString();+ QStringList parts;+ for (QTreeWidgetItem* p = item; p; p = p->parent())+ parts.prepend(p->text(0));+ return parts.join(QLatin1Char('/'));+}++void CustomPanelEditorPopup::saveTemplateTreeExpandState() {+ m_templateExpandStateBeforeSearch.clear();+ if (!m_templateTree) return;+ const QList<QTreeWidgetItem*> allItems = m_templateTree->findItems(+ QString(), Qt::MatchContains | Qt::MatchRecursive);+ for (QTreeWidgetItem* item : allItems) {+ if (item->data(0, Qt::UserRole).toString().isEmpty() && item->isExpanded())+ m_templateExpandStateBeforeSearch.insert(templateTreeItemKey(item));+ }+}++void CustomPanelEditorPopup::restoreTemplateTreeExpandState() {+ if (!m_templateTree) return;+ const QList<QTreeWidgetItem*> allItems = m_templateTree->findItems(+ QString(), Qt::MatchContains | Qt::MatchRecursive);+ for (QTreeWidgetItem* item : allItems) {+ if (item->data(0, Qt::UserRole).toString().isEmpty())+ item->setExpanded(+ m_templateExpandStateBeforeSearch.contains(templateTreeItemKey(item)));+ }+}++void CustomPanelEditorPopup::expandTemplateTreeAncestors(QTreeWidgetItem* item) {+ for (QTreeWidgetItem* p = item ? item->parent() : nullptr; p; p = p->parent())+ p->setExpanded(true);+}++//-----------------------------------------------------------------------------++void CustomPanelEditorPopup::filterTemplateTree(const QString& searchWord) {+ if (!m_templateTree) return;++ QList<QTreeWidgetItem*> allItems = m_templateTree->findItems(+ QString(), Qt::MatchContains | Qt::MatchRecursive);++ if (searchWord.isEmpty()) {+ for (QTreeWidgetItem* item : allItems) item->setHidden(false);+ if (m_templateSearchActive) {+ restoreTemplateTreeExpandState();+ m_templateSearchActive = false;+ }+ return;+ }++ if (!m_templateSearchActive) {+ saveTemplateTreeExpandState();+ m_templateSearchActive = true;+ }++ // Hide all, then reveal matches and their ancestors+ for (QTreeWidgetItem* item : allItems) item->setHidden(true);++ QList<QTreeWidgetItem*> found = m_templateTree->findItems(+ searchWord, Qt::MatchContains | Qt::MatchRecursive);+ for (QTreeWidgetItem* item : found) {+ for (QTreeWidgetItem* p = item; p; p = p->parent()) {+ p->setHidden(false);+ p->setExpanded(true);+ }+ }+}++//-----------------------------------------------------------------------------++QTreeWidgetItem* CustomPanelEditorPopup::findTemplateItemByPath(+ const QString& path) const {+ if (path.isEmpty() || !m_templateTree) return nullptr;+ QList<QTreeWidgetItem*> items = m_templateTree->findItems(+ QString(), Qt::MatchContains | Qt::MatchRecursive);+ for (QTreeWidgetItem* item : items) {+ if (item->data(0, Qt::UserRole).toString() == path) return item;+ }+ return nullptr;+}++//-----------------------------------------------------------------------------+bool CustomPanelEditorPopup::loadTemplateList() {- // Check the library / custom panel templates directoryTFilePath customPanelTemplateFolder = customPaneTemplateFolderPath();if (!TSystem::doesExistFileOrLevel(customPanelTemplateFolder)) {DVGui::warning(tr("Template folder %1 not found.")@@ -320,49 +689,58 @@ bool CustomPanelEditorPopup::loadTemplateList() {return false;}- TFilePathSet fileList =- TSystem::readDirectory(customPanelTemplateFolder, false, true, false);- if (fileList.empty()) {- DVGui::warning(tr("Template files not found."));- return false;- }+ const QString previousPath = m_currentTemplatePath;- m_templateCombo->clear();- for (const auto& file : fileList) {- // Accept only .ui files- if (file.getType() != "ui") {- continue;- }- m_templateCombo->addItem(QString::fromStdString(file.getName()),- file.getQString());- }+ m_templateTree->blockSignals(true);+ m_templateTree->clear();- int templateCount = m_templateCombo->count();+ const QIcon folderIcon = templateFolderIcon();+ // Library templates — folders on disk become collapsible tree nodes+ populateTemplateFolder(nullptr, customPanelTemplateFolder, 0, false,+ folderIcon);++ const int templateCount = m_templateTree->topLevelItemCount();if (templateCount == 0) {+ m_templateTree->blockSignals(false);DVGui::warning(tr("Template files not found."));return false;}- // Then, insert user custom panel+ // Registered user panels (editable), including subfoldersTFilePath customPanelsFolder = customPaneFolderPath();if (TSystem::doesExistFileOrLevel(customPanelsFolder)) {- TFilePathSet fileList2 =- TSystem::readDirectory(customPanelsFolder, false, true, false);- for (const auto& file : fileList2) {- // Accept only .ui files- if (file.getType() != "ui") {- continue;- }- m_templateCombo->addItem(- tr("%1 (Edit)").arg(QString::fromStdString(file.getName())),- file.getQString());- }+ QTreeWidgetItem* editRoot =+ new QTreeWidgetItem(QStringList(tr("Registered Panels")));+ editRoot->setIcon(0, folderIcon);+ editRoot->setFlags(Qt::ItemIsEnabled);+ editRoot->setData(0, Qt::UserRole, QString());+ populateTemplateFolder(editRoot, customPanelsFolder, 0, true, folderIcon);+ if (editRoot->childCount() == 0)+ delete editRoot;+ else+ m_templateTree->addTopLevelItem(editRoot);+ }++ m_templateSearchActive = false;+ m_templateExpandStateBeforeSearch.clear();++ QTreeWidgetItem* toSelect = nullptr;+ if (!previousPath.isEmpty()) toSelect = findTemplateItemByPath(previousPath);+ if (!toSelect) toSelect = findFirstTemplateItem(nullptr);++ if (toSelect) {+ m_currentTemplatePath = toSelect->data(0, Qt::UserRole).toString();+ m_templateTree->setCurrentItem(toSelect);+ // Only open the path to the current template — leave other folders closed+ expandTemplateTreeAncestors(toSelect);+ } else {+ m_currentTemplatePath.clear();}+ m_templateTree->blockSignals(false);- if (m_templateCombo->count() > templateCount) {- m_templateCombo->insertSeparator(templateCount);- }+ updateTemplateValueLabel();+ if (!m_currentTemplatePath.isEmpty()) onTemplateSwitched();return true;}@@ -371,22 +749,24 @@ bool CustomPanelEditorPopup::loadTemplateList() {void CustomPanelEditorPopup::createFields() {// Clear existing fields- for (QWidget* child : m_UiFieldsContainer->findChildren<QWidget*>()) {- delete child;+ if (QLayout* oldLay = m_UiFieldsContainer->layout()) {+ QLayoutItem* item;+ while ((item = oldLay->takeAt(0)) != nullptr) {+ if (item->widget()) delete item->widget();+ delete item;+ }+ delete oldLay;}- QGridLayout* gridLay =- qobject_cast<QGridLayout*>(m_UiFieldsContainer->layout());- if (!gridLay) {- gridLay = new QGridLayout();- gridLay->setContentsMargins(15, 15, 15, 15);- gridLay->setHorizontalSpacing(10);- gridLay->setVerticalSpacing(15);- gridLay->setColumnStretch(0, 0);- gridLay->setColumnStretch(1, 1);- gridLay->setColumnStretch(2, 1);- m_UiFieldsContainer->setLayout(gridLay);- }+ auto* gridLay = new QGridLayout();+ gridLay->setContentsMargins(15, 15, 15, 15);+ gridLay->setHorizontalSpacing(10);+ gridLay->setVerticalSpacing(15);+ gridLay->setColumnStretch(0, 0);+ gridLay->setColumnStretch(1, 1);+ gridLay->setColumnStretch(2, 1);+ m_UiFieldsContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);+ m_UiFieldsContainer->setLayout(gridLay);// For each entryint uiCounts[2] = {0, 0};@@ -417,6 +797,23 @@ void CustomPanelEditorPopup::createFields() {&CustomPanelEditorPopup::onCommandChanged);id++;}++ m_UiFieldsContainer->adjustSize();++ // Scroll only when there are too many rows (e.g. 25-button templates).+ // Short templates keep natural height — no scrollbar.+ if (m_fieldsScrollArea) {+ static const int kScrollAfterRows = 12;+ if (row > kScrollAfterRows) {+ m_fieldsScrollArea->setMinimumHeight(80);+ m_fieldsScrollArea->setMaximumHeight(220);+ m_fieldsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);+ } else {+ m_fieldsScrollArea->setMinimumHeight(0);+ m_fieldsScrollArea->setMaximumHeight(QWIDGETSIZE_MAX);+ m_fieldsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);+ }+ }}//-----------------------------------------------------------------------------@@ -516,8 +913,10 @@ void CustomPanelEditorPopup::updateControls(QWidget* customWidget) {//-----------------------------------------------------------------------------void CustomPanelEditorPopup::onTemplateSwitched() {+ QString fp = currentTemplatePath();+ if (fp.isEmpty()) return;+QUiLoader loader;- QString fp = m_templateCombo->currentData().toString();QFile file(fp);if (!file.open(QFile::ReadOnly)) {@@ -561,11 +960,47 @@ void CustomPanelEditorPopup::onTemplateSwitched() {delete customWidget;- if (customPaneFolderPath().isAncestorOf(TFilePath(fp))) {- m_panelNameEdit->setText(m_templateCombo->currentText().chopped(7));+ TFilePath templateFp(fp);+ if (customPaneFolderPath().isAncestorOf(templateFp)) {+ m_panelNameEdit->setText(relativePanelId(templateFp, customPaneFolderPath()));}- updateGeometry();+ updateTemplateValueLabel();+}++//-----------------------------------------------------------------------------++void CustomPanelEditorPopup::onTemplateHeaderClicked() {+ setTemplateBrowserVisible(!m_templateBrowser || m_templateBrowser->isHidden());+}++//-----------------------------------------------------------------------------++void CustomPanelEditorPopup::onTemplateSearchTextChanged(const QString& text) {+ filterTemplateTree(text.trimmed());+}++//-----------------------------------------------------------------------------++void CustomPanelEditorPopup::onTemplateItemClicked(QTreeWidgetItem* item,+ int column) {+ Q_UNUSED(column);+ if (!item) return;++ const QString path = item->data(0, Qt::UserRole).toString();+ if (path.isEmpty()) {+ // Folder row: expand/collapse is handled by the branch triangle only+ return;+ }++ const bool pathChanged = (path != m_currentTemplatePath);+ m_currentTemplatePath = path;+ m_templateTree->setCurrentItem(item);+ updateTemplateValueLabel();+ // Keep the browser open so the user can try several templates without+ // reopening the tree or losing their expand/collapse layout.++ if (pathChanged) onTemplateSwitched();}//-----------------------------------------------------------------------------@@ -603,7 +1038,7 @@ void CustomPanelEditorPopup::onCommandChanged(const QString& oldCmdId,}}- QString fp = m_templateCombo->currentData().toString();+ QString fp = currentTemplatePath();QFile tmplFile(fp);if (!tmplFile.open(QFile::ReadOnly)) {return;@@ -719,15 +1154,33 @@ void CustomPanelEditorPopup::replaceObjectNames(QDomElement& element) {}void CustomPanelEditorPopup::onRegister() {- QString panelName = m_panelNameEdit->text();+ QString panelName = m_panelNameEdit->text().trimmed();+ panelName.replace('\\', '/');+ while (panelName.startsWith('/')) panelName.remove(0, 1);if (panelName.isEmpty()) {DVGui::warning(tr("Please input the panel name."));return;}+ if (panelName.contains("..")) {+ DVGui::warning(tr("Invalid panel name."));+ return;+ }++ // Allow optional subfolders in the panel name (e.g. Characters/Eyes)+ TFilePath customPanelPath = customPaneFolderPath();+ const QStringList parts = panelName.split('/', Qt::SkipEmptyParts);+ if (parts.isEmpty()) {+ DVGui::warning(tr("Please input the panel name."));+ return;+ }+ for (int i = 0; i < parts.size(); ++i) {+ if (i == parts.size() - 1)+ customPanelPath = customPanelPath + TFilePath(parts[i] + ".ui");+ else+ customPanelPath = customPanelPath + TFilePath(parts[i]);+ }// Overwrite confirmation- TFilePath customPanelPath =- customPaneFolderPath() + TFilePath(panelName + ".ui");if (TSystem::doesExistFileOrLevel(customPanelPath)) {QString question =tr("The custom panel %1 already exists. Do you want to overwrite?")@@ -745,8 +1198,8 @@ void CustomPanelEditorPopup::onRegister() {}// Base template file- QDomDocument doc(panelName);- QFile tmplFile(m_templateCombo->currentData().toString());+ QDomDocument doc(parts.last());+ QFile tmplFile(currentTemplatePath());if (!tmplFile.open(QIODevice::ReadOnly)) {DVGui::warning(tr("Failed to open the template."));return;@@ -900,76 +1353,79 @@ public:};void CustomPanelEditorPopup::onRemove() {- // List all existing custom panels+ // List all existing custom panels (including subfolders)TFilePath customPanelsFolder = customPaneFolderPath();if (!TSystem::doesExistFileOrLevel(customPanelsFolder)) {DVGui::warning(tr("No custom panels found."));return;}-- TFilePathSet fileList =- TSystem::readDirectory(customPanelsFolder, false, true, false);-+QStringList panelNames;- for (auto file : fileList) {- if (file.getType() != "ui") continue;- panelNames.append(QString::fromStdString(file.getName()));- }-+ collectUiPanelIds(customPanelsFolder, customPanelsFolder, 0, panelNames);+if (panelNames.isEmpty()) {DVGui::warning(tr("No custom panels found."));return;}-+// Determine current panel (use panel name edit field if it matches an existing panel)- QString currentPanel = m_panelNameEdit->text();+ QString currentPanel = m_panelNameEdit->text().trimmed();+ currentPanel.replace('\\', '/');if (!panelNames.contains(currentPanel)) {currentPanel = panelNames.first(); // Fallback to first panel}-+// Show custom dialogRemoveCustomPanelDialog dialog(panelNames, currentPanel, this);if (dialog.exec() != QDialog::Accepted) {return; // User cancelled}-+QStringList selectedPanels = dialog.getSelectedPanels();if (selectedPanels.isEmpty()) {return;}-+// Confirmation dialogQString question;if (selectedPanels.size() == 1) {question = tr("Are you sure you want to permanently remove the custom panel '%1'?\n\n""This will delete the panel file and unregister its command.")- .arg(selectedPanels.first());+ .arg(selectedPanels.first());} else {question = tr("Are you sure you want to permanently remove %1 custom panels?\n\n""This will delete the panel files and unregister their commands.")- .arg(selectedPanels.size());+ .arg(selectedPanels.size());}-+int ret = DVGui::MsgBox(question, tr("Remove"), tr("Cancel"), 0);if (ret == 0 || ret == 2) {return; // User cancelled}-+// Delete the .ui files and mark commands as invisibleint successCount = 0;QStringList deletedPanels;-+for (const QString& panelName : selectedPanels) {- TFilePath panelPath = customPanelsFolder + TFilePath(panelName.toStdString() + ".ui");+ TFilePath panelPath = customPanelsFolder;+ const QStringList parts = panelName.split('/', Qt::SkipEmptyParts);+ for (int i = 0; i < parts.size(); ++i) {+ if (i == parts.size() - 1)+ panelPath = panelPath + TFilePath(parts[i] + ".ui");+ else+ panelPath = panelPath + TFilePath(parts[i]);+ }if (TSystem::doesExistFileOrLevel(panelPath)) {try {TSystem::deleteFile(panelPath);deletedPanels.append(panelName);successCount++;-+// IMMEDIATELY mark the command action as invisible// to hide it from Configure Shortcuts during current session- QString commandId = "MI_CustomPanel_" + panelName;+ QString commandId = "MI_CustomPanel_" ++ QString(panelName).replace('/', "__");QAction* action = CommandManager::instance()->getAction(commandId.toStdString().c_str(), false);if (action) {@@ -980,19 +1436,20 @@ void CustomPanelEditorPopup::onRemove() {}}}-+if (successCount > 0) {// Reload custom panel entries// This rebuilds m_registeredPanelIds to exclude deleted panels// and updates the Custom Panels menuCustomPanelManager::instance()->loadCustomPanelEntries();-- // Refresh the template combo in this editor to reflect changes++ // Refresh the template tree in this editor to reflect changesloadTemplateList();-- QString message = (successCount == 1)- ? tr("Custom panel has been successfully removed.")- : tr("%1 custom panels have been successfully removed.").arg(successCount);++ QString message = (successCount == 1)+ ? tr("Custom panel has been successfully removed.")+ : tr("%1 custom panels have been successfully removed.")+ .arg(successCount);DVGui::info(message);}}@@ -1030,9 +1487,84 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()m_previewArea = new UiPreviewArea(this);m_UiFieldsContainer = new QWidget(this);- m_templateCombo = new QComboBox(this);m_panelNameEdit = new QLineEdit("My Custom Panel", this);+ // Hybrid template selector: one-line header + inline collapsible browser+ m_templateHeader = new QWidget(this);+ m_templateHeader->setCursor(Qt::PointingHandCursor);+ m_templateToggle = new QToolButton(m_templateHeader);+ // Match Tool Properties collapsible headers (checked → accent square)+ m_templateToggle->setFixedSize(16, 16);+ m_templateToggle->setStyleSheet("QToolButton { border: none; }");+ applyTemplateToggleAccent(m_templateToggle, false);++ QLabel* templateLabel = new QLabel(tr("Template:"), m_templateHeader);+ m_templateValueLabel = new QLabel(tr("(none)"), m_templateHeader);+ m_templateValueLabel->setObjectName("valueLabel");+ {+ QFont italicFont = m_templateValueLabel->font();+ italicFont.setItalic(true);+ m_templateValueLabel->setFont(italicFont);+ QPalette pal = m_templateValueLabel->palette();+ pal.setColor(QPalette::WindowText,+ palette().color(QPalette::Disabled, QPalette::WindowText));+ m_templateValueLabel->setPalette(pal);+ }++ QHBoxLayout* headerLay = new QHBoxLayout(m_templateHeader);+ headerLay->setContentsMargins(0, 0, 0, 0);+ headerLay->setSpacing(5);+ headerLay->addWidget(m_templateToggle, 0);+ headerLay->addWidget(templateLabel, 0);+ headerLay->addWidget(m_templateValueLabel, 1);++ // Inline browser (not Qt::Popup) so open/close via triangle is reliable+ m_templateBrowser = new QFrame(this);+ m_templateBrowser->setObjectName("TemplateSelectorBrowser");+ m_templateBrowser->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);+ m_templateBrowser->setVisible(false);+ m_templateBrowser->setMaximumHeight(240);++ m_templateSearchEdit = new QLineEdit(m_templateBrowser);+ m_templateSearchEdit->setPlaceholderText(tr("Search templates..."));+ m_templateSearchEdit->setClearButtonEnabled(true);++ m_templateTree = new QTreeWidget(m_templateBrowser);+ // Original OT tree style (readable zebra) — same as Command List+ m_templateTree->setObjectName("SolidLineFrame");+ m_templateTree->setAlternatingRowColors(true);+ m_templateTree->setHeaderHidden(true);+ m_templateTree->setRootIsDecorated(true);+ m_templateTree->setAnimated(false);+ m_templateTree->setUniformRowHeights(true);+ m_templateTree->setSelectionMode(QAbstractItemView::SingleSelection);+ m_templateTree->setIconSize(QSize(21, 18));+ m_templateTree->header()->close();+ applyTemplateTreeBranchAccent(m_templateTree);++ QVBoxLayout* browserLay = new QVBoxLayout(m_templateBrowser);+ browserLay->setContentsMargins(4, 4, 4, 4);+ browserLay->setSpacing(4);+ {+ QHBoxLayout* searchLay = new QHBoxLayout();+ searchLay->setContentsMargins(0, 0, 0, 0);+ searchLay->setSpacing(4);+ searchLay->addWidget(new QLabel(tr("Search:"), m_templateBrowser), 0);+ searchLay->addWidget(m_templateSearchEdit, 1);+ browserLay->addLayout(searchLay, 0);+ browserLay->addWidget(m_templateTree, 1);+ }++ // Command fields wrapper — scrollbar enabled in createFields() only if needed+ m_fieldsScrollArea = new QScrollArea(this);+ m_fieldsScrollArea->setWidgetResizable(true);+ m_fieldsScrollArea->setFrameShape(QFrame::NoFrame);+ m_fieldsScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);+ m_fieldsScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);+ // Do not vertically expand and stretch the yellow fields+ m_fieldsScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);+ m_fieldsScrollArea->setWidget(m_UiFieldsContainer);+QPushButton* registerButton = new QPushButton(tr("Register"), this);QPushButton* removeButton = new QPushButton(tr("Remove"), this);QPushButton* cancelButton = new QPushButton(tr("Cancel"), this);@@ -1045,15 +1577,9 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()leftLay->setContentsMargins(0, 0, 0, 0);leftLay->setSpacing(10);{- QHBoxLayout* templateLay = new QHBoxLayout();- templateLay->setContentsMargins(0, 0, 0, 0);- templateLay->setSpacing(5);- {- templateLay->addWidget(new QLabel(tr("Template:"), this), 0);- templateLay->addWidget(m_templateCombo, 1, Qt::AlignLeft);- }- leftLay->addLayout(templateLay, 0);- leftLay->addWidget(m_UiFieldsContainer, 0);+ leftLay->addWidget(m_templateHeader, 0);+ leftLay->addWidget(m_templateBrowser, 0);+ leftLay->addWidget(m_fieldsScrollArea, 0);leftLay->addWidget(m_previewArea, 1);}addLayout(leftLay);@@ -1093,8 +1619,10 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()connect(cancelButton, &QPushButton::clicked, this,&CustomPanelEditorPopup::close);- connect(m_templateCombo, QOverload<int>::of(&QComboBox::currentIndexChanged),- this, &CustomPanelEditorPopup::onTemplateSwitched);+ connect(m_templateTree, &QTreeWidget::itemClicked, this,+ &CustomPanelEditorPopup::onTemplateItemClicked);+ connect(m_templateSearchEdit, &QLineEdit::textChanged, this,+ &CustomPanelEditorPopup::onTemplateSearchTextChanged);connect(registerButton, &QPushButton::clicked, this,&CustomPanelEditorPopup::onRegister);connect(removeButton, &QPushButton::clicked, this,@@ -1102,6 +1630,9 @@ CustomPanelEditorPopup::CustomPanelEditorPopup()connect(searchEdit, &QLineEdit::textChanged, this,&CustomPanelEditorPopup::onSearchTextChanged);+ m_templateHeader->installEventFilter(this);+ m_templateToggle->installEventFilter(this);+// Load templateif (!loadTemplateList()) {// Handle template loading failure if needed@@ -1114,16 +1645,43 @@ void CustomPanelEditorPopup::showEvent(QShowEvent* event) {// Refresh brush preset and size commands to ensure they're up-to-dateToolPresetCommandManager::instance()->refreshPresetCommands();ToolPresetCommandManager::instance()->refreshSizeCommands();-+// Refresh the command list tree to show new commandsm_commandListTree->refreshTree();m_commandListTree->searchItems(); // Clear any search filter-++ // Theme may have been ready after construction — refresh accents+ if (m_templateTree) {+ applyTemplateTreeBranchAccent(m_templateTree);+ applyTemplateToggleAccent(m_templateToggle,+ m_templateBrowser && m_templateBrowser->isVisible());+ const QIcon folderIcon = templateFolderIcon();+ for (int i = 0; i < m_templateTree->topLevelItemCount(); ++i)+ applyFolderIconRecursive(m_templateTree->topLevelItem(i), folderIcon);+ }+Dialog::showEvent(event);}//-----------------------------------------------------------------------------+bool CustomPanelEditorPopup::eventFilter(QObject* watched, QEvent* event) {+ if (event->type() == QEvent::MouseButtonPress) {+ auto* mouseEvent = static_cast<QMouseEvent*>(event);+ if (mouseEvent->button() != Qt::LeftButton)+ return QObject::eventFilter(watched, event);++ // Whole header row toggles the browser (triangle included)+ if (watched == m_templateHeader || watched == m_templateToggle) {+ onTemplateHeaderClicked();+ return true;+ }+ }+ return QObject::eventFilter(watched, event);+}++//-----------------------------------------------------------------------------+void CustomPanelEditorPopup::onSearchTextChanged(const QString& text) {static bool busy = false;if (busy) {diff --git a/toonz/sources/toonz/custompaneleditorpopup.h b/toonz/sources/toonz/custompaneleditorpopup.hindex d7832d4eb..86c3f2842 100644--- a/toonz/sources/toonz/custompaneleditorpopup.h+++ b/toonz/sources/toonz/custompaneleditorpopup.h@@ -11,16 +11,20 @@#include <QTreeWidgetItem>#include <QMap>#include <QPair>+#include <QSet>#include <QLabel>#include <QScrollArea>#include <QDomElement>-#include <QComboBox>#include <QLineEdit>// Forward declarationsclass CustomPanelUIField;class CommandListTree;+class TFilePath;+class QToolButton;+class QFrame;+class QWidget;enum UiType { Button = 0, Scroller_Back, Scroller_Fore, TypeCount };@@ -130,10 +134,20 @@ class CustomPanelEditorPopup final : public DVGui::Dialog {private:CommandListTree* m_commandListTree;QWidget* m_UiFieldsContainer;+ QScrollArea* m_fieldsScrollArea;UiPreviewArea* m_previewArea;- QComboBox* m_templateCombo;+ QWidget* m_templateHeader;+ QToolButton* m_templateToggle;+ QLabel* m_templateValueLabel;+ QFrame* m_templateBrowser;+ QTreeWidget* m_templateTree;+ QLineEdit* m_templateSearchEdit;QLineEdit* m_panelNameEdit;QList<UiEntry> m_uiEntries;+ QString m_currentTemplatePath;+ // Expand/collapse snapshot while a search filter is active+ QSet<QString> m_templateExpandStateBeforeSearch;+ bool m_templateSearchActive = false;// Helper methodsQList<int> entryIdByObjName(const QString& objName);@@ -143,22 +157,40 @@ private:void buildEntries(QWidget* customWidget); // Create entries from UI filevoid updateControls(QWidget* customWidget); // Update widget using current entries+ QString currentTemplatePath() const;+ QString templateDisplayNameForItem(QTreeWidgetItem* item) const;+ void updateTemplateValueLabel();+ void setTemplateBrowserVisible(bool visible);+ void filterTemplateTree(const QString& searchWord);+ void populateTemplateFolder(QTreeWidgetItem* parent, const TFilePath& folder,+ int depth, bool isEditSection,+ const QIcon& folderIcon);+ QTreeWidgetItem* findFirstTemplateItem(QTreeWidgetItem* parent) const;+ QTreeWidgetItem* findTemplateItemByPath(const QString& path) const;+ static QString templateTreeItemKey(QTreeWidgetItem* item);+ void saveTemplateTreeExpandState();+ void restoreTemplateTreeExpandState();+ void expandTemplateTreeAncestors(QTreeWidgetItem* item);static CustomPanelEditorPopup* s_instance;public:CustomPanelEditorPopup();~CustomPanelEditorPopup();-+// Refresh the command list tree if the popup is currently open.// Call this after preset commands are added/removed so the tree stays in sync.static void refreshCommandTreeIfOpen();-+protected:void showEvent(QShowEvent* event) override;-+ bool eventFilter(QObject* watched, QEvent* event) override;+protected slots:void onTemplateSwitched();+ void onTemplateHeaderClicked();+ void onTemplateItemClicked(QTreeWidgetItem* item, int column);+ void onTemplateSearchTextChanged(const QString& text);void onHighlight(int id);void onCommandChanged(const QString& oldCmdId, const QString& newCmdId);void onPreviewClicked(int id);diff --git a/toonz/sources/toonz/custompanelmanager.cpp b/toonz/sources/toonz/custompanelmanager.cppindex eb8a413d2..cea686268 100644--- a/toonz/sources/toonz/custompanelmanager.cpp+++ b/toonz/sources/toonz/custompanelmanager.cpp@@ -12,6 +12,7 @@#include "toonz/toonzfolders.h"// ToonzCore#include "tsystem.h"+#include "tfilepath.h"#include <QUiLoader>#include <QAbstractButton>@@ -19,6 +20,9 @@#include <QToolButton>#include <QPainter>#include <QMouseEvent>+#include <QMenu>+#include <QFileInfo>+#include <algorithm>namespace {@@ -26,6 +30,130 @@ const TFilePath CustomPanelFolderName("custompanels");const TFilePath customPaneFolderPath() {return ToonzFolder::getMyModuleDir() + CustomPanelFolderName;}++// Keep in sync with Custom Panel Editor template tree depth.+const int kMaxCustomPanelFolderDepth = 3;++QString normalizePanelId(QString id) {+ id.replace('\\', '/');+ while (id.startsWith('/')) id.remove(0, 1);+ return id;+}++QString commandIdFromPanelId(const QString& panelId) {+ return "MI_CustomPanel_" + QString(panelId).replace('/', "__");+}++QString panelTypeFromPanelId(const QString& panelId) {+ return "Custom_" + QString(panelId).replace('/', "__");+}++QString relativePanelId(const TFilePath& file, const TFilePath& rootFolder) {+ TFilePath relative = file - rootFolder;+ return normalizePanelId(relative.withType("").getQString());+}++TFilePath panelFilePath(const QString& panelId) {+ TFilePath path = customPaneFolderPath();+ const QStringList parts = normalizePanelId(panelId).split('/', Qt::SkipEmptyParts);+ for (int i = 0; i < parts.size(); ++i) {+ if (i == parts.size() - 1)+ path = path + TFilePath(parts[i] + ".ui");+ else+ path = path + TFilePath(parts[i]);+ }+ return path;+}++void collectUiPanelIds(const TFilePath& folder, const TFilePath& rootFolder,+ int depth, QStringList& outIds) {+ if (!TSystem::doesExistFileOrLevel(folder)) return;++ TFilePathSet entries = TSystem::readDirectory(folder, false, false, false);++ QList<TFilePath> dirs;+ QList<TFilePath> files;+ for (const auto& entry : entries) {+ if (TFileStatus(entry).isDirectory())+ dirs.append(entry);+ else if (entry.getType() == "ui")+ files.append(entry);+ }++ std::sort(dirs.begin(), dirs.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(QString::fromStdString(a.getName()),+ QString::fromStdString(b.getName()),+ Qt::CaseInsensitive) < 0;+ });+ std::sort(files.begin(), files.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(QString::fromStdString(a.getName()),+ QString::fromStdString(b.getName()),+ Qt::CaseInsensitive) < 0;+ });++ if (depth < kMaxCustomPanelFolderDepth) {+ for (const auto& dir : dirs)+ collectUiPanelIds(dir, rootFolder, depth + 1, outIds);+ }++ for (const auto& file : files)+ outIds.append(relativePanelId(file, rootFolder));+}++void populateCustomPanelMenu(QMenu* menu, const TFilePath& folder, int depth,+ QStringList& menuPanelIds) {+ if (!menu || !TSystem::doesExistFileOrLevel(folder)) return;++ TFilePathSet entries = TSystem::readDirectory(folder, false, false, false);++ QList<TFilePath> dirs;+ QList<TFilePath> files;+ for (const auto& entry : entries) {+ if (TFileStatus(entry).isDirectory())+ dirs.append(entry);+ else if (entry.getType() == "ui")+ files.append(entry);+ }++ std::sort(dirs.begin(), dirs.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(QString::fromStdString(a.getName()),+ QString::fromStdString(b.getName()),+ Qt::CaseInsensitive) < 0;+ });+ std::sort(files.begin(), files.end(),+ [](const TFilePath& a, const TFilePath& b) {+ return QString::compare(QString::fromStdString(a.getName()),+ QString::fromStdString(b.getName()),+ Qt::CaseInsensitive) < 0;+ });++ if (depth < kMaxCustomPanelFolderDepth) {+ for (const auto& dir : dirs) {+ QMenu* subMenu =+ new QMenu(QString::fromStdString(dir.getName()), menu);+ populateCustomPanelMenu(subMenu, dir, depth + 1, menuPanelIds);+ if (subMenu->isEmpty()) {+ delete subMenu;+ continue;+ }+ menu->addMenu(subMenu);+ }+ }++ for (const auto& file : files) {+ // Proxy menu actions (not the CommandManager actions): a QAction can only+ // belong to one menu, and command actions must stay available for shortcuts.+ QString panelId = relativePanelId(file, customPaneFolderPath());+ QAction* leaf =+ menu->addAction(QString::fromStdString(file.getName()));+ leaf->setData(menuPanelIds.size());+ menuPanelIds.append(panelId);+ }+}+} // namespace//-----------------------------------------------------------------------------@@ -83,6 +211,13 @@ CustomPanelManager* CustomPanelManager::instance() {return &_instance;}+//-----------------------------------------------------------------------------++QString CustomPanelManager::menuPanelIdAt(int index) const {+ if (index < 0 || index >= m_menuPanelIds.size()) return QString();+ return m_menuPanelIds.at(index);+}+//-----------------------------------------------------------------------------// browse the custom panel settings and regisiter to the menuvoid CustomPanelManager::loadCustomPanelEntries() {@@ -92,38 +227,28 @@ void CustomPanelManager::loadCustomPanelEntries() {if (!menu) return;if (!menu->isEmpty()) menu->clear();+ m_menuPanelIds.clear();++ registerCustomPanelCommands();TFilePath customPanelsFolder = customPaneFolderPath();if (TSystem::doesExistFileOrLevel(customPanelsFolder)) {- TFilePathSet fileList =- TSystem::readDirectory(customPanelsFolder, false, true, false);- if (!fileList.empty()) {- QList<QString> fileNames;- for (auto file : fileList) {- // accept only .ui files- if (file.getType() != "ui") continue;- fileNames.append(QString::fromStdString(file.getName()));- }- if (!fileNames.isEmpty()) {- menu->setActions(fileNames);- menu->addSeparator();- }- }+ populateCustomPanelMenu(menu, customPanelsFolder, 0, m_menuPanelIds);+ if (!menu->isEmpty()) menu->addSeparator();}- // register an empty action with the label "Custom Panel Editor".- // actual command will be called in OpenCustomPanelCommandHandler- // in order to prevent double calling of the command++ // Text-only action: OpenCustomPanelCommandHandler opens the editor when+ // index is unset. Do not add the real MI_CustomPanelEditor action here —+ // QAction can only live in one menu at a time.menu->addAction(CommandManager::instance()->getAction(MI_CustomPanelEditor)->text());-- registerCustomPanelCommands();-+// Register tool presets as commands for Custom PanelsToolPresetCommandManager::instance()->registerToolPresetCommands();-+// Register universal size commandsToolPresetCommandManager::instance()->registerSizeCommands();-+// Initialize signal connections for automatic checked state updatesToolPresetCommandManager::instance()->initialize();}@@ -132,13 +257,15 @@ void CustomPanelManager::loadCustomPanelEntries() {TPanel* CustomPanelManager::createCustomPanel(const QString panelName,QWidget* parent) {+ // Panel types encode folder separators as "__" (see panelTypeFromPanelId).+ QString panelId = normalizePanelId(panelName);+ panelId.replace("__", "/");TPanel* panel = new TPanel(parent);- QString panelType = "Custom_" + panelName;+ QString panelType = panelTypeFromPanelId(panelId);panel->setPanelType(panelType.toStdString());panel->setObjectName(panelType);- TFilePath customPanelsFp =- customPaneFolderPath() + TFilePath(panelName + ".ui");+ TFilePath customPanelsFp = panelFilePath(panelId);QUiLoader loader;QFile file(customPanelsFp.getQString());@@ -148,7 +275,7 @@ TPanel* CustomPanelManager::createCustomPanel(const QString panelName,initializeControl(customWidget);- panel->setWindowTitle(panelName);+ panel->setWindowTitle(QFileInfo(customPanelsFp.getQString()).completeBaseName());panel->setWidget(customWidget);// Enable room binding feature (handled by TPanel base class)@@ -264,44 +391,35 @@ void CustomPanelManager::registerCustomPanelCommands() {TFilePath customPanelsFolder = customPaneFolderPath();if (!TSystem::doesExistFileOrLevel(customPanelsFolder)) return;- TFilePathSet fileList =- TSystem::readDirectory(customPanelsFolder, false, true, false);-- QList<QString> currentPanels;- for (auto file : fileList) {- if (file.getType() != "ui") continue;- currentPanels.append(QString::fromStdString(file.getName()));- }-+ QStringList currentPanels;+ collectUiPanelIds(customPanelsFolder, customPanelsFolder, 0, currentPanels);+m_registeredPanelIds.clear();MainWindow* mainWindow = dynamic_cast<MainWindow*>(TApp::instance()->getMainWindow());if (!mainWindow) return;- for (const QString& panelName : currentPanels) {- QString commandId = "MI_CustomPanel_" + panelName;-+ for (const QString& panelId : currentPanels) {+ QString commandId = commandIdFromPanelId(panelId);+QAction* existingAction = CommandManager::instance()->getAction(commandId.toStdString().c_str(), false);if (existingAction) {+ existingAction->setVisible(true);m_registeredPanelIds.append(commandId);continue;}- // Improved display name for better searchability- // Replace underscores and hyphens with spaces for readability- QString cleanName = panelName;- cleanName.replace('_', ' ');- cleanName.replace('-', ' ');-- // Create display name with [Panel] prefix- QString displayName = "[Panel] " + cleanName;-+ // Display / search name: basename only (folder context is in the menu path)+ QString baseName = panelId.section('/', -1);+ baseName.replace('_', ' ');+ baseName.replace('-', ' ');+ QString displayName = "[Panel] " + baseName;+QAction* action = new DVAction(displayName, mainWindow);mainWindow->addAction(action);-+// Define command with improved naming for search- // Add searchable keywords in the command definitionCommandManager::instance()->define(commandId.toStdString().c_str(),CustomPanelCommandType, // Custom Panels subcategory under Windows@@ -310,44 +428,44 @@ void CustomPanelManager::registerCustomPanelCommands() {"");class CustomPanelHandler : public CommandHandlerInterface {- QString m_panelName;+ QString m_panelId;public:- CustomPanelHandler(const QString& name) : m_panelName(name) {}+ CustomPanelHandler(const QString& id) : m_panelId(id) {}void execute() override {TMainWindow* currentRoom = TApp::instance()->getCurrentRoom();if (!currentRoom) return;-- std::string panelType = ("Custom_" + m_panelName).toStdString();++ std::string panelType = panelTypeFromPanelId(m_panelId).toStdString();QList<TPanel*> panels = currentRoom->findChildren<TPanel*>();-+for (TPanel* panel : panels) {if (panel->getPanelType() == panelType && !panel->isHidden()) {panel->close();return;}}-+OpenFloatingPanel::getOrOpenFloatingPanel(panelType);}};-+CommandManager::instance()->setHandler(commandId.toStdString().c_str(),- new CustomPanelHandler(panelName));+ new CustomPanelHandler(panelId));m_registeredPanelIds.append(commandId);}-+// Notify ShortcutPopup to refresh if it's currently open// This allows new custom panel commands to appear immediately without restartingShortcutPopup::refreshIfOpen();-+TFilePath shortcutsFile = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");if (!TFileStatus(shortcutsFile).doesExist()) return;-+QSettings settings(toQString(shortcutsFile), QSettings::IniFormat);settings.beginGroup("shortcuts");-+for (const QString& commandId : m_registeredPanelIds) {QString savedShortcut = settings.value(commandId, "").toString();if (!savedShortcut.isEmpty()) {@@ -358,7 +476,7 @@ void CustomPanelManager::registerCustomPanelCommands() {}}}-+settings.endGroup();}@@ -370,18 +488,23 @@ public:void execute() override {QAction* act = CommandManager::instance()->getAction(MI_OpenCustomPanels);DVMenuAction* menu = dynamic_cast<DVMenuAction*>(act->menu());- int index = menu->getTriggeredActionIndex();+ if (!menu) return;++ int index = menu->getTriggeredActionIndex();- // the last action is for opening custom panel editor, in which the index is- // not set.+ // Editor entry (and any action without panel index data)if (index == -1) {CommandManager::instance()->getAction(MI_CustomPanelEditor)->trigger();return;}- QString panelId = menu->actions()[index]->text();+ QString panelId = CustomPanelManager::instance()->menuPanelIdAt(index);+ if (panelId.isEmpty()) {+ CommandManager::instance()->getAction(MI_CustomPanelEditor)->trigger();+ return;+ }- OpenFloatingPanel::getOrOpenFloatingPanel("Custom_" +- panelId.toStdString());+ OpenFloatingPanel::getOrOpenFloatingPanel(+ panelTypeFromPanelId(panelId).toStdString());}} openCustomPanelCommandHandler;diff --git a/toonz/sources/toonz/custompanelmanager.h b/toonz/sources/toonz/custompanelmanager.hindex 976526036..18bde66a5 100644--- a/toonz/sources/toonz/custompanelmanager.h+++ b/toonz/sources/toonz/custompanelmanager.h@@ -6,6 +6,7 @@#include "toonzqt/menubarcommand.h"#include <QString>+#include <QStringList>#include <QWidget>#include <QList>@@ -47,8 +48,10 @@ protected:class CustomPanelManager { // singletonCustomPanelManager(){};-+QList<QString> m_registeredPanelIds;+ // Parallel to Custom Panels menu leaf actions (data = index).+ QStringList m_menuPanelIds;public:static CustomPanelManager* instance();@@ -58,6 +61,8 @@ public:TPanel* createCustomPanel(const QString panelName, QWidget* parent);void initializeControl(QWidget* customWidget);++ QString menuPanelIdAt(int index) const;};#endif