From 62d519fb72c8f9c637d745aed1fdb0c2689210e2 Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Nov 13 2019 22:41:12 +0000 Subject: enable to create folder in startup popup (#2875) --- diff --git a/toonz/sources/toonz/startuppopup.cpp b/toonz/sources/toonz/startuppopup.cpp index 761182f..a965ea7 100644 --- a/toonz/sources/toonz/startuppopup.cpp +++ b/toonz/sources/toonz/startuppopup.cpp @@ -274,15 +274,15 @@ StartupPopup::StartupPopup() bool ret = true; ret = ret && connect(sceneHandle, SIGNAL(sceneChanged()), this, SLOT(onSceneChanged())); - ret = ret && connect(sceneHandle, SIGNAL(sceneSwitched()), this, + ret = ret && connect(sceneHandle, SIGNAL(sceneSwitched()), this, SLOT(onSceneChanged())); - ret = ret && connect(newProjectButton, SIGNAL(clicked()), this, + ret = ret && connect(newProjectButton, SIGNAL(clicked()), this, SLOT(onNewProjectButtonPressed())); - ret = ret && connect(loadOtherSceneButton, SIGNAL(clicked()), this, + ret = ret && connect(loadOtherSceneButton, SIGNAL(clicked()), this, SLOT(onLoadSceneButtonPressed())); - ret = ret && connect(m_projectsCB, SIGNAL(currentIndexChanged(int)), + ret = ret && connect(m_projectsCB, SIGNAL(currentIndexChanged(int)), SLOT(onProjectChanged(int))); - ret = ret && + ret = ret && connect(createButton, SIGNAL(clicked()), this, SLOT(onCreateButton())); ret = ret && connect(m_showAtStartCB, SIGNAL(stateChanged(int)), this, SLOT(onShowAtStartChanged(int))); @@ -440,12 +440,6 @@ void StartupPopup::onCreateButton() { m_nameFld->setFocus(); return; } - if (!TSystem::doesExistFileOrLevel(TFilePath(m_pathFld->getPath()))) { - DVGui::warning(tr("The chosen file path is not valid.")); - m_pathFld->setFocus(); - return; - } - if (m_widthFld->getValue() <= 0) { DVGui::warning(tr("The width must be greater than zero.")); m_widthFld->setFocus(); @@ -461,9 +455,28 @@ void StartupPopup::onCreateButton() { m_fpsFld->setFocus(); return; } - if (TSystem::doesExistFileOrLevel( - TFilePath(m_pathFld->getPath()) + - TFilePath(m_nameFld->text().trimmed().toStdWString() + L".tnz"))) { + + TFilePath scenePath = + TFilePath(m_pathFld->getPath()) + + TFilePath(m_nameFld->text().trimmed().toStdWString() + L".tnz"); + + if (!TSystem::doesExistFileOrLevel(TFilePath(m_pathFld->getPath()))) { + QString question; + question = QObject::tr( + "The chosen folder path does not exist." + "\nDo you want to create it?"); + int ret = DVGui::MsgBox(question, QObject::tr("Create"), + QObject::tr("Cancel"), 0); + if (ret == 0 || ret == 2) { + m_pathFld->setFocus(); + return; + } + if (!TSystem::touchParentDir(scenePath)) { + DVGui::warning(tr("Failed to create the folder.")); + m_pathFld->setFocus(); + return; + } + } else if (TSystem::doesExistFileOrLevel(scenePath)) { QString question; question = QObject::tr( "The file name already exists." @@ -476,9 +489,7 @@ void StartupPopup::onCreateButton() { } } CommandManager::instance()->execute(MI_NewScene); - TApp::instance()->getCurrentScene()->getScene()->setScenePath( - TFilePath(m_pathFld->getPath()) + - TFilePath(m_nameFld->text().trimmed().toStdWString())); + TApp::instance()->getCurrentScene()->getScene()->setScenePath(scenePath); TDimensionD size = TDimensionD(m_widthFld->getValue(), m_heightFld->getValue()); TDimension res = TDimension(m_xRes, m_yRes); @@ -794,8 +805,8 @@ double StartupPopup::aspectRatioStringToValue(const QString &s) { } int i = s.indexOf("/"); if (i <= 0 || i + 1 >= s.length()) return s.toDouble(); - int num = s.left(i).toInt(); - int den = s.mid(i + 1).toInt(); + int num = s.left(i).toInt(); + int den = s.mid(i + 1).toInt(); if (den <= 0) den = 1; return (double)num / (double)den; } diff --git a/toonz/sources/toonzlib/tproject.cpp b/toonz/sources/toonzlib/tproject.cpp index 877ff10..4daa45d 100644 --- a/toonz/sources/toonzlib/tproject.cpp +++ b/toonz/sources/toonzlib/tproject.cpp @@ -119,7 +119,7 @@ std::wstring getProjectSuffix(const TFilePath &path) { /*! Looks in the directory for a project file. If nothing found, returns a * blank TFilePath -*/ + */ TFilePath getProjectFile(const TFilePath &fp) { const std::wstring &fpName = fp.getWideName(); const std::wstring &folderName = fp.getParentDir().getWideName(); @@ -724,18 +724,15 @@ public: and folders. It is possible to handle more than one project root. - The class maintains a container this purpose. All the projects roots must - be set by hand in the windows - registery. By default, only one project root is created when toonz is - installed.\n - The project root container can be updated using addProjectsRoot(const - TFilePath &root), addDefaultProjectsRoot() - methods. - - The class maintains also information about the current project. The class - provides all needed method to retrieve - the current project path, name and folder. - \see TProject + The class maintains a container this purpose. All the projects roots + must be set by hand in the windows registery. By default, only one project + root is created when toonz is installed.\n The project root container can be + updated using addProjectsRoot(const TFilePath &root), + addDefaultProjectsRoot() methods. + + The class maintains also information about the current project. The + class provides all needed method to retrieve the current project path, name + and folder. \see TProject */ @@ -896,7 +893,7 @@ TFilePath TProjectManager::getProjectPathByName(const TFilePath &projectName) { TFilePath TProjectManager::getProjectPathByProjectFolder( const TFilePath &projectFolder) { - assert(!projectFolder.isAbsolute()); + assert(projectFolder.isAbsolute()); TFilePath projectPath = searchProjectPath(projectFolder); return projectPathToProjectName(projectPath); } diff --git a/toonz/sources/toonzqt/filefield.cpp b/toonz/sources/toonzqt/filefield.cpp index ce9e42f..5b3875f 100644 --- a/toonz/sources/toonzqt/filefield.cpp +++ b/toonz/sources/toonzqt/filefield.cpp @@ -38,6 +38,8 @@ FileField::FileField(QWidget *parent, QString path, bool readOnly, // if the initial text is not path, set the string here and prevent browsing if (doNotBrowseInitialPath) m_descriptionText = path; + setFocusProxy(m_field); + QHBoxLayout *mainLayout = new QHBoxLayout(); mainLayout->setMargin(0); mainLayout->setSpacing(1);