From 4bf161d2ff761a83360c1e68bbb84771fb50686b Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Mar 12 2020 02:51:33 +0000 Subject: truncate file list in popup --- diff --git a/toonz/sources/include/toonz/sceneresources.h b/toonz/sources/include/toonz/sceneresources.h index 91f98db..6f2370e 100644 --- a/toonz/sources/include/toonz/sceneresources.h +++ b/toonz/sources/include/toonz/sceneresources.h @@ -17,6 +17,7 @@ #endif #include +#include //============================================================================= // forward declarations @@ -112,8 +113,8 @@ If scene is untitled update save path. */ void updatePath(TFilePath &fp); - virtual bool isDirty() = 0; - virtual QString getResourceName() = 0; + virtual bool isDirty() = 0; + virtual QStringList getResourceName() = 0; }; //============================================================================= @@ -157,7 +158,7 @@ Set simple level path to old path. } bool isDirty() override; - QString getResourceName() override; + QStringList getResourceName() override; }; //============================================================================= @@ -203,7 +204,7 @@ Set simple level path to old path. } bool isDirty() override; - QString getResourceName() override; + QStringList getResourceName() override; }; //============================================================================= @@ -247,7 +248,7 @@ Set sound track path to old path. } bool isDirty() override { return false; } - QString getResourceName() override { return QString(); } + QStringList getResourceName() override { return QStringList(); } }; //============================================================================= @@ -316,7 +317,7 @@ If doesn't make \b commit() destroyer calls \b rollbackPaths(). void accept(ResourceProcessor *processor, bool autoCommit = true); // return the name list of dirty resources - void getDirtyResources(std::vector &dirtyResources); + void getDirtyResources(QStringList &dirtyResources); private: // not implemented diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cpp index 9ec4f66..558c55e 100644 --- a/toonz/sources/toonz/iocommand.cpp +++ b/toonz/sources/toonz/iocommand.cpp @@ -1202,21 +1202,29 @@ bool IoCmd::saveSceneIfNeeded(QString msg) { ToonzScene *scene = app->getCurrentScene()->getScene(); if (scene) { - std::vector dirtyResources; + QStringList dirtyResources; { SceneResources resources(scene, 0); resources.getDirtyResources(dirtyResources); } if (!dirtyResources.empty()) { + // show up to 5 items + int extraCount = dirtyResources.count() - 5; + if (extraCount > 0) { + dirtyResources = dirtyResources.mid(0, 5); + dirtyResources.append( + QObject::tr("and %1 more item(s).").arg(extraCount)); + } + QString question; question = msg + ":" + QObject::tr(" The following file(s) have been modified.\n\n"); - for (int i = 0; i < dirtyResources.size(); i++) { - question += " " + dirtyResources[i] + "\n"; - } - question += QObject::tr("\nWhat would you like to do? "); + + question += " " + dirtyResources.join("\n "); + + question += "\n" + QObject::tr("\nWhat would you like to do? "); int ret = DVGui::MsgBox(question, QObject::tr("Save Changes"), diff --git a/toonz/sources/toonzlib/sceneresources.cpp b/toonz/sources/toonzlib/sceneresources.cpp index 9c7166a..1569d4e 100644 --- a/toonz/sources/toonzlib/sceneresources.cpp +++ b/toonz/sources/toonzlib/sceneresources.cpp @@ -121,7 +121,7 @@ TFilePath ResourceImportStrategy::process(ToonzScene *scene, if (srcPath.getWideString().find(L'+') == 0) dstPath = srcPath; else - dstPath = scene->getImportedLevelPath(srcPath); + dstPath = scene->getImportedLevelPath(srcPath); TFilePath actualDstPath = scene->decodeFilePath(dstPath); assert(actualDstPath != TFilePath()); @@ -334,7 +334,8 @@ bool SceneLevel::isDirty() { } //----------------------------------------------------------------------------- -QString SceneLevel::getResourceName() { +QStringList SceneLevel::getResourceName() { + QStringList ret; QString string; bool levelIsDirty = false; if (m_sl->getProperties()->getDirtyFlag()) { @@ -342,16 +343,23 @@ QString SceneLevel::getResourceName() { levelIsDirty = true; } if (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag()) { - if (levelIsDirty) string += " and "; - if (m_sl->getPath().getType() == "pli") - string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) + - ".pli (palette)"; - else - string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) + - ".tpl"; - } + QString paletteName = + QString::fromStdWString(m_sl->getPalette()->getPaletteName()); + if (m_sl->getType() & FULLCOLOR_TYPE) { + if (levelIsDirty) ret << string; + ret << paletteName + ".tpl"; + } else { + if (levelIsDirty) string += " and "; + if (m_sl->getPath().getType() == "pli") + string += paletteName + ".pli (palette)"; + else + string += paletteName + ".tpl"; + ret << string; + } + } else if (levelIsDirty) + ret << string; - return string; + return ret; } //============================================================================= @@ -403,8 +411,8 @@ bool ScenePalette::isDirty() { return m_pl->getPalette()->getDirtyFlag(); } //----------------------------------------------------------------------------- -QString ScenePalette::getResourceName() { - return QString::fromStdString(m_pl->getPath().getLevelName()); +QStringList ScenePalette::getResourceName() { + return QStringList(QString::fromStdString(m_pl->getPath().getLevelName())); } //============================================================================= @@ -496,19 +504,24 @@ void SceneResources::save(const TFilePath newScenePath) { TFilePath oldScenePath = m_scene->getScenePath(); m_scene->setScenePath(newScenePath); bool failedSave = false; - QString failedList; for (int i = 0; i < (int)m_resources.size(); i++) { m_resources[i]->save(); - if (m_resources[i]->isDirty()) // didn't save for some reason - { - failedList += "\n" + m_resources[i]->getResourceName(); - failedSave = true; - } } - if (failedSave) + QStringList failedList; + getDirtyResources(failedList); + + if (!failedList.isEmpty()) { // didn't save for some reason + // show up to 5 items + int extraCount = failedList.count() - 5; + if (extraCount > 0) { + failedList = failedList.mid(0, 5); + failedList.append(QObject::tr("and %1 more item(s).").arg(extraCount)); + } + DVGui::warning(QObject::tr("Failed to save the following resources:\n") + - failedList); + " " + failedList.join("\n ")); + } m_scene->setScenePath(oldScenePath); } @@ -536,11 +549,12 @@ void SceneResources::accept(ResourceProcessor *processor, bool autoCommit) { //----------------------------------------------------------------------------- // return the name list of dirty resources -void SceneResources::getDirtyResources(std::vector &dirtyResources) { - for (int i = 0; i < (int)m_resources.size(); i++) - if (m_resources[i]->isDirty()) { - dirtyResources.push_back(m_resources[i]->getResourceName()); +void SceneResources::getDirtyResources(QStringList &dirtyResources) { + for (SceneResource *resource : m_resources) + if (resource->isDirty()) { + dirtyResources << resource->getResourceName(); } + dirtyResources.removeDuplicates(); } //============================================================================= @@ -562,7 +576,7 @@ ResourceImporter::ResourceImporter(ToonzScene *scene, TProject *dstProject, scene->getScenePath() - scene->getProject()->getScenesPath(); if (relativeScenePath.isAbsolute()) relativeScenePath = scene->getScenePath().withoutParentDir(); - TFilePath newFp = dstProject->getScenesPath() + relativeScenePath; + TFilePath newFp = dstProject->getScenesPath() + relativeScenePath; makeUnique(newFp); m_dstScene->setScenePath(newFp); } @@ -680,7 +694,7 @@ void ResourceCollector::process(TXshSimpleLevel *sl) { std::string suffix = ResourceImporter::extractPsdSuffix(path); std::map::iterator it = m_collectedFiles.find(path); if (it != m_collectedFiles.end()) { - TFilePath destPath = it->second; + TFilePath destPath = it->second; if (suffix != "") destPath = ResourceImporter::buildPsd(destPath, suffix); sl->setPath(destPath); } else { @@ -696,7 +710,7 @@ void ResourceCollector::process(TXshSimpleLevel *sl) { } } ++m_count; - TFilePath destPath = collectedPath; + TFilePath destPath = collectedPath; if (suffix != "") destPath = ResourceImporter::buildPsd(destPath, suffix); sl->setPath(destPath); m_collectedFiles[path] = collectedPath;