Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

fix replace level popup (#1868)

shun-iwasawaa7d74c6237ea
diff --git a/toonz/sources/toonz/filebrowserpopup.cpp b/toonz/sources/toonz/filebrowserpopup.cpp
index 4a1acef9a..737a02f32 100644
--- a/toonz/sources/toonz/filebrowserpopup.cpp
+++ b/toonz/sources/toonz/filebrowserpopup.cpp
@@ -1526,6 +1526,55 @@ public:
}
} saveLevelAsCommandHandler;
+//=============================================================================
+// Used both for ReplaceLevelPopup and ReplaceParentDirectoryPopup
+// which are needed to maintain the current selection on open.
+
+template <class T>
+class OpenReplaceFilePopupHandler final : public MenuItemHandler {
+ T *m_popup;
+
+public:
+ OpenReplaceFilePopupHandler(CommandId cmdId)
+ : MenuItemHandler(cmdId), m_popup(0) {}
+
+ // The current selection is cleared on the construction of FileBrowser
+ // ( by calling makeCurrent() in DvDirTreeView::currentChanged() ).
+ // Thus checking the selection must be done BEFORE making the browser
+ // or it fails to get the selection on the first call of this command.
+ bool initialize(TCellSelection::Range &range, std::set<int> &columnRange,
+ bool &replaceCells) {
+ TSelection *sel = TApp::instance()->getCurrentSelection()->getSelection();
+ if (!sel) return false;
+ TCellSelection *cellSel = dynamic_cast<TCellSelection *>(sel);
+ TColumnSelection *columnSel = dynamic_cast<TColumnSelection *>(sel);
+ if ((!cellSel && !columnSel) || sel->isEmpty()) {
+ DVGui::error(tr("Nothing to replace: no cells or columns selected."));
+ return false;
+ }
+ if (cellSel) {
+ range = cellSel->getSelectedCells();
+ replaceCells = true;
+ } else if (columnSel) {
+ columnRange = columnSel->getIndices();
+ replaceCells = false;
+ }
+ return true;
+ }
+
+ void execute() override {
+ TCellSelection::Range range;
+ std::set<int> columnRange;
+ bool replaceCells;
+ if (!initialize(range, columnRange, replaceCells)) return;
+ if (!m_popup) m_popup = new T();
+ m_popup->setRange(range, columnRange, replaceCells);
+ m_popup->show();
+ m_popup->raise();
+ m_popup->activateWindow();
+ }
+};
+
//=============================================================================
// ReplaceLevelPopup
@@ -1537,24 +1586,12 @@ ReplaceLevelPopup::ReplaceLevelPopup()
SLOT(onSelectionChanged(TSelection *)));
}
-void ReplaceLevelPopup::show() {
- TSelection *sel = TApp::instance()->getCurrentSelection()->getSelection();
- if (!sel) return;
- TCellSelection *cellSel = dynamic_cast<TCellSelection *>(sel);
- TColumnSelection *columnSel = dynamic_cast<TColumnSelection *>(sel);
- if ((!cellSel && !columnSel) || sel->isEmpty()) {
- DVGui::error(tr("Nothing to replace: no cells selected."));
- return;
- }
-
- if (cellSel) {
- m_range = cellSel->getSelectedCells();
- m_replaceCells = true;
- } else if (columnSel) {
- m_columnRange = columnSel->getIndices();
- m_replaceCells = false;
- }
- QDialog::show();
+void ReplaceLevelPopup::setRange(TCellSelection::Range &range,
+ std::set<int> &columnRange,
+ bool &replaceCells) {
+ m_range = range;
+ m_columnRange = columnRange;
+ m_replaceCells = replaceCells;
}
bool ReplaceLevelPopup::execute() {
@@ -1860,50 +1897,6 @@ void LoadColorModelPopup::showEvent(QShowEvent *e) {
/*! replace the parent folder path of the levels in the selected cells
*/
-class OpenReplaceParentDirectoryPopupHandler final : public MenuItemHandler {
- ReplaceParentDirectoryPopup *m_popup;
-
-public:
- OpenReplaceParentDirectoryPopupHandler()
- : MenuItemHandler(MI_ReplaceParentDirectory), m_popup(0) {}
-
- // The current selection is cleared on the construction of FileBrowser
- // ( by calling makeCurrent() in DvDirTreeView::currentChanged() ).
- // Thus checking the selection must be done BEFORE making the browser
- // or it fails to get the selection on the first call of this command.
- bool initialize(TCellSelection::Range &range, std::set<int> &columnRange,
- bool &replaceCells) {
- TSelection *sel = TApp::instance()->getCurrentSelection()->getSelection();
- if (!sel) return false;
- TCellSelection *cellSel = dynamic_cast<TCellSelection *>(sel);
- TColumnSelection *columnSel = dynamic_cast<TColumnSelection *>(sel);
- if ((!cellSel && !columnSel) || sel->isEmpty()) {
- DVGui::error(tr("Nothing to replace: no cells or columns selected."));
- return false;
- }
- if (cellSel) {
- range = cellSel->getSelectedCells();
- replaceCells = true;
- } else if (columnSel) {
- columnRange = columnSel->getIndices();
- replaceCells = false;
- }
- return true;
- }
-
- void execute() override {
- TCellSelection::Range range;
- std::set<int> columnRange;
- bool replaceCells;
- if (!initialize(range, columnRange, replaceCells)) return;
- if (!m_popup) m_popup = new ReplaceParentDirectoryPopup();
- m_popup->setRange(range, columnRange, replaceCells);
- m_popup->show();
- m_popup->raise();
- m_popup->activateWindow();
- }
-} openReplaceParentDirectoryPopupHandler;
-
ReplaceParentDirectoryPopup::ReplaceParentDirectoryPopup()
: FileBrowserPopup(tr("Replace Parent Directory")) {
setOkText(tr("Replace"));
@@ -2162,8 +2155,6 @@ OpenPopupCommandHandler<SaveSubSceneAsPopup> saveSubSceneAsPopupCommand(
OpenPopupCommandHandler<LoadLevelPopup> loadLevelPopupCommand(MI_LoadLevel);
OpenPopupCommandHandler<ConvertPopupWithInput> convertWithInputPopupCommand(
MI_ConvertFileWithInput);
-OpenPopupCommandHandler<ReplaceLevelPopup> replaceLevelPopupCommand(
- MI_ReplaceLevel);
OpenPopupCommandHandler<SavePaletteAsPopup> savePalettePopupCommand(
MI_SavePaletteAs);
OpenPopupCommandHandler<LoadColorModelPopup> loadColorModelPopupCommand(
@@ -2171,5 +2162,10 @@ OpenPopupCommandHandler<LoadColorModelPopup> loadColorModelPopupCommand(
OpenPopupCommandHandler<ImportMagpieFilePopup> importMagpieFilePopupCommand(
MI_ImportMagpieFile);
-// Note: MI_ReplaceParentDirectory uses the original hadler in order to obtain
-// the selection information before making the browser.
\ No newline at end of file
+// Note: MI_ReplaceLevel and MI_ReplaceParentDirectory uses the original
+// handler in order to obtain the selection information before making the
+// browser.
+OpenReplaceFilePopupHandler<ReplaceLevelPopup> replaceLevelPopupCommand(
+ MI_ReplaceLevel);
+OpenReplaceFilePopupHandler<ReplaceParentDirectoryPopup>
+ replaceParentFolderPopupCommand(MI_ReplaceParentDirectory);
\ No newline at end of file
diff --git a/toonz/sources/toonz/filebrowserpopup.h b/toonz/sources/toonz/filebrowserpopup.h
index 47e6b74f8..03af3ae9f 100644
--- a/toonz/sources/toonz/filebrowserpopup.h
+++ b/toonz/sources/toonz/filebrowserpopup.h
@@ -332,9 +332,10 @@ public:
ReplaceLevelPopup();
bool execute() override;
- void show();
void initFolder() override;
+ void setRange(TCellSelection::Range &range, std::set<int> &columnRange,
+ bool &replaceCells);
protected slots:
void onSelectionChanged(TSelection *selection);