Merge pull request #3149 from shun-iwasawa/truncate_file_list_in_popup

Truncate File List in the Popup
This commit is contained in:
Rodney 2020-03-12 13:05:35 -07:00 committed by GitHub
commit edd9b3068c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 39 deletions

View file

@ -17,6 +17,7 @@
#endif #endif
#include <QString> #include <QString>
#include <QSet>
//============================================================================= //=============================================================================
// forward declarations // forward declarations
@ -112,8 +113,8 @@ If scene is untitled update save path.
*/ */
void updatePath(TFilePath &fp); void updatePath(TFilePath &fp);
virtual bool isDirty() = 0; virtual bool isDirty() = 0;
virtual QString getResourceName() = 0; virtual QStringList getResourceName() = 0;
}; };
//============================================================================= //=============================================================================
@ -157,7 +158,7 @@ Set simple level path to old path.
} }
bool isDirty() override; bool isDirty() override;
QString getResourceName() override; QStringList getResourceName() override;
}; };
//============================================================================= //=============================================================================
@ -203,7 +204,7 @@ Set simple level path to old path.
} }
bool isDirty() override; 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; } 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); void accept(ResourceProcessor *processor, bool autoCommit = true);
// return the name list of dirty resources // return the name list of dirty resources
void getDirtyResources(std::vector<QString> &dirtyResources); void getDirtyResources(QStringList &dirtyResources);
private: private:
// not implemented // not implemented

View file

@ -1202,21 +1202,29 @@ bool IoCmd::saveSceneIfNeeded(QString msg) {
ToonzScene *scene = app->getCurrentScene()->getScene(); ToonzScene *scene = app->getCurrentScene()->getScene();
if (scene) { if (scene) {
std::vector<QString> dirtyResources; QStringList dirtyResources;
{ {
SceneResources resources(scene, 0); SceneResources resources(scene, 0);
resources.getDirtyResources(dirtyResources); resources.getDirtyResources(dirtyResources);
} }
if (!dirtyResources.empty()) { 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; QString question;
question = msg + ":" + question = msg + ":" +
QObject::tr(" The following file(s) have been modified.\n\n"); QObject::tr(" The following file(s) have been modified.\n\n");
for (int i = 0; i < dirtyResources.size(); i++) {
question += " " + dirtyResources[i] + "\n"; question += " " + dirtyResources.join("\n ");
}
question += QObject::tr("\nWhat would you like to do? "); question += "\n" + QObject::tr("\nWhat would you like to do? ");
int ret = int ret =
DVGui::MsgBox(question, QObject::tr("Save Changes"), DVGui::MsgBox(question, QObject::tr("Save Changes"),

View file

@ -121,7 +121,7 @@ TFilePath ResourceImportStrategy::process(ToonzScene *scene,
if (srcPath.getWideString().find(L'+') == 0) if (srcPath.getWideString().find(L'+') == 0)
dstPath = srcPath; dstPath = srcPath;
else else
dstPath = scene->getImportedLevelPath(srcPath); dstPath = scene->getImportedLevelPath(srcPath);
TFilePath actualDstPath = scene->decodeFilePath(dstPath); TFilePath actualDstPath = scene->decodeFilePath(dstPath);
assert(actualDstPath != TFilePath()); assert(actualDstPath != TFilePath());
@ -334,7 +334,8 @@ bool SceneLevel::isDirty() {
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
QString SceneLevel::getResourceName() { QStringList SceneLevel::getResourceName() {
QStringList ret;
QString string; QString string;
bool levelIsDirty = false; bool levelIsDirty = false;
if (m_sl->getProperties()->getDirtyFlag()) { if (m_sl->getProperties()->getDirtyFlag()) {
@ -342,16 +343,23 @@ QString SceneLevel::getResourceName() {
levelIsDirty = true; levelIsDirty = true;
} }
if (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag()) { if (m_sl->getPalette() && m_sl->getPalette()->getDirtyFlag()) {
if (levelIsDirty) string += " and "; QString paletteName =
if (m_sl->getPath().getType() == "pli") QString::fromStdWString(m_sl->getPalette()->getPaletteName());
string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) + if (m_sl->getType() & FULLCOLOR_TYPE) {
".pli (palette)"; if (levelIsDirty) ret << string;
else ret << paletteName + ".tpl";
string += QString::fromStdWString(m_sl->getPalette()->getPaletteName()) + } else {
".tpl"; 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() { QStringList ScenePalette::getResourceName() {
return QString::fromStdString(m_pl->getPath().getLevelName()); return QStringList(QString::fromStdString(m_pl->getPath().getLevelName()));
} }
//============================================================================= //=============================================================================
@ -496,19 +504,24 @@ void SceneResources::save(const TFilePath newScenePath) {
TFilePath oldScenePath = m_scene->getScenePath(); TFilePath oldScenePath = m_scene->getScenePath();
m_scene->setScenePath(newScenePath); m_scene->setScenePath(newScenePath);
bool failedSave = false; bool failedSave = false;
QString failedList;
for (int i = 0; i < (int)m_resources.size(); i++) { for (int i = 0; i < (int)m_resources.size(); i++) {
m_resources[i]->save(); 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") + DVGui::warning(QObject::tr("Failed to save the following resources:\n") +
failedList); " " + failedList.join("\n "));
}
m_scene->setScenePath(oldScenePath); m_scene->setScenePath(oldScenePath);
} }
@ -536,11 +549,12 @@ void SceneResources::accept(ResourceProcessor *processor, bool autoCommit) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// return the name list of dirty resources // return the name list of dirty resources
void SceneResources::getDirtyResources(std::vector<QString> &dirtyResources) { void SceneResources::getDirtyResources(QStringList &dirtyResources) {
for (int i = 0; i < (int)m_resources.size(); i++) for (SceneResource *resource : m_resources)
if (m_resources[i]->isDirty()) { if (resource->isDirty()) {
dirtyResources.push_back(m_resources[i]->getResourceName()); dirtyResources << resource->getResourceName();
} }
dirtyResources.removeDuplicates();
} }
//============================================================================= //=============================================================================
@ -562,7 +576,7 @@ ResourceImporter::ResourceImporter(ToonzScene *scene, TProject *dstProject,
scene->getScenePath() - scene->getProject()->getScenesPath(); scene->getScenePath() - scene->getProject()->getScenesPath();
if (relativeScenePath.isAbsolute()) if (relativeScenePath.isAbsolute())
relativeScenePath = scene->getScenePath().withoutParentDir(); relativeScenePath = scene->getScenePath().withoutParentDir();
TFilePath newFp = dstProject->getScenesPath() + relativeScenePath; TFilePath newFp = dstProject->getScenesPath() + relativeScenePath;
makeUnique(newFp); makeUnique(newFp);
m_dstScene->setScenePath(newFp); m_dstScene->setScenePath(newFp);
} }
@ -680,7 +694,7 @@ void ResourceCollector::process(TXshSimpleLevel *sl) {
std::string suffix = ResourceImporter::extractPsdSuffix(path); std::string suffix = ResourceImporter::extractPsdSuffix(path);
std::map<TFilePath, TFilePath>::iterator it = m_collectedFiles.find(path); std::map<TFilePath, TFilePath>::iterator it = m_collectedFiles.find(path);
if (it != m_collectedFiles.end()) { if (it != m_collectedFiles.end()) {
TFilePath destPath = it->second; TFilePath destPath = it->second;
if (suffix != "") destPath = ResourceImporter::buildPsd(destPath, suffix); if (suffix != "") destPath = ResourceImporter::buildPsd(destPath, suffix);
sl->setPath(destPath); sl->setPath(destPath);
} else { } else {
@ -696,7 +710,7 @@ void ResourceCollector::process(TXshSimpleLevel *sl) {
} }
} }
++m_count; ++m_count;
TFilePath destPath = collectedPath; TFilePath destPath = collectedPath;
if (suffix != "") destPath = ResourceImporter::buildPsd(destPath, suffix); if (suffix != "") destPath = ResourceImporter::buildPsd(destPath, suffix);
sl->setPath(destPath); sl->setPath(destPath);
m_collectedFiles[path] = collectedPath; m_collectedFiles[path] = collectedPath;