Skip to content

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

C

Level Create Popup now sets default name and updates paths correctly (#437)

turtletooth0bae6721d553
diff --git a/toonz/sources/include/toonz/txshleveltypes.h b/toonz/sources/include/toonz/txshleveltypes.h
index f2287bc96..3bddd6023 100644
--- a/toonz/sources/include/toonz/txshleveltypes.h
+++ b/toonz/sources/include/toonz/txshleveltypes.h
@@ -17,11 +17,11 @@ enum TXshLevelType {
FULLCOLOR_TYPE = TZI_TYPE | OVL_TYPE,
RASTER_TYPE = FULLCOLOR_TYPE | TZP_TYPE,
- TZI_XSHLEVEL = TZI_TYPE | LEVELCOLUMN_XSHLEVEL,
- PLI_XSHLEVEL = PLI_TYPE | LEVELCOLUMN_XSHLEVEL,
- TZP_XSHLEVEL = TZP_TYPE | LEVELCOLUMN_XSHLEVEL,
- OVL_XSHLEVEL = OVL_TYPE | LEVELCOLUMN_XSHLEVEL,
- CHILD_XSHLEVEL = CHILD_TYPE | LEVELCOLUMN_XSHLEVEL,
+ TZI_XSHLEVEL = TZI_TYPE | LEVELCOLUMN_XSHLEVEL, //Scan level
+ PLI_XSHLEVEL = PLI_TYPE | LEVELCOLUMN_XSHLEVEL, //ToonzVector
+ TZP_XSHLEVEL = TZP_TYPE | LEVELCOLUMN_XSHLEVEL, //ToonzRaster
+ OVL_XSHLEVEL = OVL_TYPE | LEVELCOLUMN_XSHLEVEL, //Raster
+ CHILD_XSHLEVEL = CHILD_TYPE | LEVELCOLUMN_XSHLEVEL,
ZERARYFX_XSHLEVEL = 1 << 7,
PLT_XSHLEVEL = 2 << 7,
diff --git a/toonz/sources/toonz/filebrowserpopup.cpp b/toonz/sources/toonz/filebrowserpopup.cpp
index e45c5c989..23a8a9eeb 100644
--- a/toonz/sources/toonz/filebrowserpopup.cpp
+++ b/toonz/sources/toonz/filebrowserpopup.cpp
@@ -373,6 +373,7 @@ void FileBrowserPopup::showEvent(QShowEvent *) {
m_currentProjectPath = projectPath;
initFolder();
m_nameField->update();
+ m_nameField->setFocus();
}
resize(m_dialogSize);
}
diff --git a/toonz/sources/toonz/levelcreatepopup.cpp b/toonz/sources/toonz/levelcreatepopup.cpp
index 834eb4a19..f28dda4d0 100644
--- a/toonz/sources/toonz/levelcreatepopup.cpp
+++ b/toonz/sources/toonz/levelcreatepopup.cpp
@@ -33,6 +33,7 @@
#include "toonz/preferences.h"
#include "toonz/palettecontroller.h"
#include "toonz/tproject.h"
+#include "toonz/namebuilder.h"
// TnzCore includes
#include "tsystem.h"
@@ -285,30 +286,52 @@ LevelCreatePopup::LevelCreatePopup()
//-----------------------------------------------------------------------------
-void LevelCreatePopup::updatePath() {
- ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
-
- /*--- 初期Pathを入れる。Xsheet Roomのときのみ、分岐 ---*/
- QString roomName = TApp::instance()->getCurrentRoomName();
- TFilePath defaultPath;
- if (roomName == "Xsheet") {
- /*--- 名称未設定シーンのとき、+satsuei直下に ---*/
- if (scene->isUntitled()) defaultPath = TFilePath("+" + TProject::Scenes);
- /*---
- * 保存済みシーンのとき、そのシーンファイルの入っているフォルダの1階層上のフォルダにする
- * ---*/
- else
- defaultPath = scene->codeFilePath(
- scene->getScenePath().getParentDir().getParentDir());
- } else
- defaultPath = scene->getDefaultLevelPath(getLevelType()).getParentDir();
-
- m_pathFld->setPath(toQString(defaultPath));
+void LevelCreatePopup::updatePath()
+{
+ ToonzScene *scene = TApp::instance()->getCurrentScene()->getScene();
+ TFilePath defaultPath;
+ defaultPath = scene->getDefaultLevelPath(getLevelType()).getParentDir();
+ m_pathFld->setPath(toQString(defaultPath));
}
//-----------------------------------------------------------------------------
-void LevelCreatePopup::showEvent(QShowEvent *) { update(); }
+void LevelCreatePopup::nextName() {
+ const std::auto_ptr<NameBuilder> nameBuilder(NameBuilder::getBuilder(L""));
+
+ TLevelSet* levelSet = TApp::instance()->getCurrentScene()->getScene()->getLevelSet();
+ ToonzScene* scene = TApp::instance()->getCurrentScene()->getScene();
+ std::wstring levelName = L"";
+
+ // Select a different unique level name in case it already exists (either in scene or on disk)
+ TFilePath fp;
+ TFilePath actualFp;
+ for (;;) {
+ levelName = nameBuilder->getNext();
+
+ if (levelSet->getLevel(levelName) != 0)
+ continue;
+
+ fp = scene->getDefaultLevelPath(getLevelType(), levelName);
+ actualFp = scene->decodeFilePath(fp);
+
+ if (TSystem::doesExistFileOrLevel(actualFp)) {
+ continue;
+ }
+
+ break;
+ }
+
+ m_nameFld->setText(QString::fromStdWString(levelName));
+}
+
+
+
+void LevelCreatePopup::showEvent(QShowEvent *) {
+ nextName();
+ update();
+ m_nameFld->setFocus();
+}
//-----------------------------------------------------------------------------
@@ -338,26 +361,36 @@ int LevelCreatePopup::getLevelType() const {
//-----------------------------------------------------------------------------
-void LevelCreatePopup::onLevelTypeChanged(const QString &text) {
- if (text == "Raster Level" || text == "Toonz Raster Level")
- setSizeWidgetEnable(true);
- else
- setSizeWidgetEnable(false);
- updatePath();
+void LevelCreatePopup::onLevelTypeChanged(const QString &text)
+{
+ if (text == "Raster Level" || text == "Toonz Raster Level")
+ setSizeWidgetEnable(true);
+ else
+ setSizeWidgetEnable(false);
+ updatePath();
+ nextName();
+ m_nameFld->setFocus();
}
//-----------------------------------------------------------------------------
-void LevelCreatePopup::onOkBtn() {
- apply();
- close();
- /*if(apply())
-this->accept();*/
+void LevelCreatePopup::onOkBtn()
+{
+ if(apply())
+ close();
+ else
+ m_nameFld->setFocus();
}
//-----------------------------------------------------------------------------
-void LevelCreatePopup::onApplyButton() { apply(); }
+void LevelCreatePopup::onApplyButton()
+{
+ if (apply()) {
+ nextName();
+ }
+ m_nameFld->setFocus();
+}
//-----------------------------------------------------------------------------
diff --git a/toonz/sources/toonz/levelcreatepopup.h b/toonz/sources/toonz/levelcreatepopup.h
index ae4825353..b3f9a6bec 100644
--- a/toonz/sources/toonz/levelcreatepopup.h
+++ b/toonz/sources/toonz/levelcreatepopup.h
@@ -44,10 +44,10 @@ public:
bool apply();
protected:
- // set m_pathFld to the default path
- void updatePath();
-
- void showEvent(QShowEvent *);
+ // set m_pathFld to the default path
+ void updatePath();
+ void nextName();
+ void showEvent(QShowEvent *);
public slots:
void onLevelTypeChanged(const QString &text);