Merge pull request #3149 from shun-iwasawa/truncate_file_list_in_popup
Truncate File List in the Popup
This commit is contained in:
commit
edd9b3068c
3 changed files with 62 additions and 39 deletions
|
@ -17,6 +17,7 @@
|
|||
#endif
|
||||
|
||||
#include <QString>
|
||||
#include <QSet>
|
||||
|
||||
//=============================================================================
|
||||
// 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<QString> &dirtyResources);
|
||||
void getDirtyResources(QStringList &dirtyResources);
|
||||
|
||||
private:
|
||||
// not implemented
|
||||
|
|
|
@ -1202,21 +1202,29 @@ bool IoCmd::saveSceneIfNeeded(QString msg) {
|
|||
|
||||
ToonzScene *scene = app->getCurrentScene()->getScene();
|
||||
if (scene) {
|
||||
std::vector<QString> 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"),
|
||||
|
|
|
@ -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<QString> &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<TFilePath, TFilePath>::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;
|
||||
|
|
Loading…
Reference in a new issue