Skip to content

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

C

Show project name in title bars and startup menu (#2507)

manongjohn7ab0b7ba7f7b
diff --git a/toonz/sources/toonz/comboviewerpane.cpp b/toonz/sources/toonz/comboviewerpane.cpp
index f0c4a5d68..1c6a1ef45 100644
--- a/toonz/sources/toonz/comboviewerpane.cpp
+++ b/toonz/sources/toonz/comboviewerpane.cpp
@@ -29,6 +29,7 @@
#include "toonz/palettecontroller.h"
#include "toonz/toonzfolders.h"
#include "toonz/preferences.h"
+#include "toonz/tproject.h"
// TnzQt includes
#include "toonzqt/menubarcommand.h"
@@ -616,11 +617,13 @@ void ComboViewerPanel::changeWindowTitle() {
// if the frame type is "scene editing"
if (app->getCurrentFrame()->isEditingScene()) {
- QString sceneName = QString::fromStdWString(scene->getSceneName());
+ TProject *project = scene->getProject();
+ QString projectName = QString::fromStdString(project->getName().getName());
+ QString sceneName = QString::fromStdWString(scene->getSceneName());
if (sceneName.isEmpty()) sceneName = tr("Untitled");
- if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString(" *");
- name = tr("Scene: ") + sceneName;
+ if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString("*");
+ name = tr("Scene: ") + sceneName + tr(" :: Project: ") + projectName;
if (frame >= 0)
name =
name + tr(" :: Frame: ") + tr(std::to_string(frame + 1).c_str());
diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cpp
index 98cd2bece..f52422033 100644
--- a/toonz/sources/toonz/iocommand.cpp
+++ b/toonz/sources/toonz/iocommand.cpp
@@ -1440,8 +1440,13 @@ bool IoCmd::saveScene(const TFilePath &path, int flags) {
app->getCurrentScene()->setDirtyFlag(false);
History::instance()->addItem(scenePath);
- RecentFiles::instance()->addFilePath(toQString(scenePath),
- RecentFiles::Scene);
+ RecentFiles::instance()->addFilePath(
+ toQString(scenePath), RecentFiles::Scene,
+ QString::fromStdString(app->getCurrentScene()
+ ->getScene()
+ ->getProject()
+ ->getName()
+ .getName()));
QApplication::restoreOverrideCursor();
@@ -1884,8 +1889,9 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,
TApp::instance()->getCurrentScene()->setDirtyFlag(false);
History::instance()->addItem(scenePath);
if (updateRecentFile)
- RecentFiles::instance()->addFilePath(toQString(scenePath),
- RecentFiles::Scene);
+ RecentFiles::instance()->addFilePath(
+ toQString(scenePath), RecentFiles::Scene,
+ QString::fromStdString(scene->getProject()->getName().getName()));
QApplication::restoreOverrideCursor();
int forbiddenLevelCount = 0;
diff --git a/toonz/sources/toonz/mainwindow.cpp b/toonz/sources/toonz/mainwindow.cpp
index e3c8073fd..73a3525a7 100644
--- a/toonz/sources/toonz/mainwindow.cpp
+++ b/toonz/sources/toonz/mainwindow.cpp
@@ -32,6 +32,7 @@
#include "toonz/tscenehandle.h"
#include "toonz/toonzscene.h"
#include "toonz/txshleveltypes.h"
+#include "toonz/tproject.h"
// TnzBase includes
#include "tenv.h"
@@ -484,14 +485,19 @@ void MainWindow::changeWindowTitle() {
ToonzScene *scene = app->getCurrentScene()->getScene();
if (!scene) return;
- QString name = QString::fromStdWString(scene->getSceneName());
+ TProject *project = scene->getProject();
+ QString projectName = QString::fromStdString(project->getName().getName());
- /*--- レイアウトファイル名を頭に表示させる ---*/
- if (!m_layoutName.isEmpty()) name.prepend(m_layoutName + " : ");
+ QString sceneName = QString::fromStdWString(scene->getSceneName());
+
+ if (sceneName.isEmpty()) sceneName = tr("Untitled");
+ if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString("*");
- if (name.isEmpty()) name = tr("Untitled");
+ /*--- レイアウトファイル名を頭に表示させる ---*/
+ if (!m_layoutName.isEmpty()) sceneName.prepend(m_layoutName + " : ");
- name += " : " + QString::fromStdString(TEnv::getApplicationFullName());
+ QString name = sceneName + " [" + projectName + "] : " +
+ QString::fromStdString(TEnv::getApplicationFullName());
setWindowTitle(name);
}
@@ -2316,7 +2322,8 @@ void MainWindow::onQuit() { close(); }
// RecentFiles
//=============================================================================
-RecentFiles::RecentFiles() : m_recentScenes(), m_recentLevels() {}
+RecentFiles::RecentFiles()
+ : m_recentScenes(), m_recentSceneProjects(), m_recentLevels() {}
//-----------------------------------------------------------------------------
@@ -2331,17 +2338,25 @@ RecentFiles::~RecentFiles() {}
//-----------------------------------------------------------------------------
-void RecentFiles::addFilePath(QString path, FileType fileType) {
+void RecentFiles::addFilePath(QString path, FileType fileType,
+ QString projectName) {
QList<QString> files =
(fileType == Scene) ? m_recentScenes : (fileType == Level)
? m_recentLevels
: m_recentFlipbookImages;
int i;
for (i = 0; i < files.size(); i++)
- if (files.at(i) == path) files.removeAt(i);
+ if (files.at(i) == path) {
+ files.removeAt(i);
+ if (fileType == Scene) m_recentSceneProjects.removeAt(i);
+ }
files.insert(0, path);
+ if (fileType == Scene) m_recentSceneProjects.insert(0, projectName);
int maxSize = 10;
- if (files.size() > maxSize) files.removeAt(maxSize);
+ if (files.size() > maxSize) {
+ files.removeAt(maxSize);
+ if (fileType == Scene) m_recentSceneProjects.removeAt(maxSize);
+ }
if (fileType == Scene)
m_recentScenes = files;
@@ -2357,9 +2372,10 @@ void RecentFiles::addFilePath(QString path, FileType fileType) {
//-----------------------------------------------------------------------------
void RecentFiles::moveFilePath(int fromIndex, int toIndex, FileType fileType) {
- if (fileType == Scene)
+ if (fileType == Scene) {
m_recentScenes.move(fromIndex, toIndex);
- else if (fileType == Level)
+ m_recentSceneProjects.move(fromIndex, toIndex);
+ } else if (fileType == Level)
m_recentLevels.move(fromIndex, toIndex);
else
m_recentFlipbookImages.move(fromIndex, toIndex);
@@ -2369,9 +2385,10 @@ void RecentFiles::moveFilePath(int fromIndex, int toIndex, FileType fileType) {
//-----------------------------------------------------------------------------
void RecentFiles::removeFilePath(int index, FileType fileType) {
- if (fileType == Scene)
+ if (fileType == Scene) {
m_recentScenes.removeAt(index);
- else if (fileType == Level)
+ m_recentSceneProjects.removeAt(index);
+ } else if (fileType == Level)
m_recentLevels.removeAt(index);
saveRecentFiles();
}
@@ -2387,10 +2404,26 @@ QString RecentFiles::getFilePath(int index, FileType fileType) const {
//-----------------------------------------------------------------------------
+QString RecentFiles::getFileProject(int index) const {
+ if (index >= m_recentScenes.size() || index >= m_recentSceneProjects.size())
+ return "-";
+ return m_recentSceneProjects[index];
+}
+
+QString RecentFiles::getFileProject(QString fileName) const {
+ for (int index = 0; index < m_recentScenes.size(); index++)
+ if (m_recentScenes[index] == fileName) return m_recentSceneProjects[index];
+
+ return "-";
+}
+
+//-----------------------------------------------------------------------------
+
void RecentFiles::clearRecentFilesList(FileType fileType) {
- if (fileType == Scene)
+ if (fileType == Scene) {
m_recentScenes.clear();
- else if (fileType == Level)
+ m_recentSceneProjects.clear();
+ } else if (fileType == Level)
m_recentLevels.clear();
else
m_recentFlipbookImages.clear();
@@ -2414,6 +2447,22 @@ void RecentFiles::loadRecentFiles() {
QString scene = settings.value(QString("Scenes")).toString();
if (!scene.isEmpty()) m_recentScenes.append(scene);
}
+
+ // Load scene's projects info. This is for display purposes only. For
+ // backwards compatibility it is stored and maintained separately.
+ QList<QVariant> sceneProjects =
+ settings.value(QString("SceneProjects")).toList();
+ if (!sceneProjects.isEmpty()) {
+ for (i = 0; i < sceneProjects.size(); i++)
+ m_recentSceneProjects.append(sceneProjects.at(i).toString());
+ } else {
+ QString sceneProject = settings.value(QString("SceneProjects")).toString();
+ if (!sceneProject.isEmpty()) m_recentSceneProjects.append(sceneProject);
+ }
+ // Should be 1-to-1. If we're short, append projects list with "-".
+ while (m_recentSceneProjects.size() < m_recentScenes.size())
+ m_recentSceneProjects.append("-");
+
QList<QVariant> levels = settings.value(QString("Levels")).toList();
if (!levels.isEmpty()) {
for (i = 0; i < levels.size(); i++) {
@@ -2451,6 +2500,7 @@ void RecentFiles::saveRecentFiles() {
TFilePath fp = ToonzFolder::getMyModuleDir() + TFilePath("RecentFiles.ini");
QSettings settings(toQString(fp), QSettings::IniFormat);
settings.setValue(QString("Scenes"), QVariant(m_recentScenes));
+ settings.setValue(QString("SceneProjects"), QVariant(m_recentSceneProjects));
settings.setValue(QString("Levels"), QVariant(m_recentLevels));
settings.setValue(QString("FlipbookImages"),
QVariant(m_recentFlipbookImages));
diff --git a/toonz/sources/toonz/mainwindow.h b/toonz/sources/toonz/mainwindow.h
index bf1163790..9c7d94e13 100644
--- a/toonz/sources/toonz/mainwindow.h
+++ b/toonz/sources/toonz/mainwindow.h
@@ -208,6 +208,7 @@ signals:
class RecentFiles {
friend class StartupPopup;
QList<QString> m_recentScenes;
+ QList<QString> m_recentSceneProjects;
QList<QString> m_recentLevels;
QList<QString> m_recentFlipbookImages;
@@ -219,10 +220,12 @@ public:
static RecentFiles *instance();
~RecentFiles();
- void addFilePath(QString path, FileType fileType);
+ void addFilePath(QString path, FileType fileType, QString projectName = 0);
void moveFilePath(int fromIndex, int toIndex, FileType fileType);
void removeFilePath(int fromIndex, FileType fileType);
QString getFilePath(int index, FileType fileType) const;
+ QString getFileProject(QString fileName) const;
+ QString getFileProject(int index) const;
void clearRecentFilesList(FileType fileType);
void loadRecentFiles();
void saveRecentFiles();
diff --git a/toonz/sources/toonz/startuppopup.cpp b/toonz/sources/toonz/startuppopup.cpp
index b84d86005..967bd1225 100644
--- a/toonz/sources/toonz/startuppopup.cpp
+++ b/toonz/sources/toonz/startuppopup.cpp
@@ -97,7 +97,7 @@ StartupPopup::StartupPopup()
m_projectBox = new QGroupBox(tr("Choose Project"), this);
m_sceneBox = new QGroupBox(tr("Create a New Scene"), this);
- m_recentBox = new QGroupBox(tr("Open Scene"), this);
+ m_recentBox = new QGroupBox(tr("Open Scene [Project]"), this);
m_projectBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_nameFld = new LineEdit(this);
m_pathFld = new FileField(this);
@@ -409,10 +409,13 @@ void StartupPopup::refreshRecentScenes() {
int i = 0;
for (QString name : m_sceneNames) {
if (i > 9) break; // box can hold 10 scenes
- QString justName = QString::fromStdString(TFilePath(name).getName());
+ QString fileName =
+ name.remove(0, name.indexOf(" ") + 1); // remove "#. " prefix
+ QString projectName = RecentFiles::instance()->getFileProject(fileName);
+ QString justName = QString::fromStdString(TFilePath(fileName).getName()) +
+ (projectName != "-" ? " [" + projectName + "]" : "");
m_recentNamesLabels[i] = new StartupLabel(justName, this, i);
- m_recentNamesLabels[i]->setToolTip(
- name.remove(0, name.indexOf(" ") + 1)); // remove "#. " prefix
+ m_recentNamesLabels[i]->setToolTip(fileName);
m_recentSceneLay->addWidget(m_recentNamesLabels[i], 0, Qt::AlignTop);
i++;
}
@@ -857,7 +860,20 @@ void StartupPopup::onRecentSceneClicked(int index) {
refreshRecentScenes();
} else {
IoCmd::loadScene(TFilePath(path.toStdWString()), false);
- RecentFiles::instance()->moveFilePath(index, 0, RecentFiles::Scene);
+ if (RecentFiles::instance()->getFileProject(index) == "-") {
+ QString fileName =
+ RecentFiles::instance()->getFilePath(index, RecentFiles::Scene);
+ QString projectName = QString::fromStdString(TApp::instance()
+ ->getCurrentScene()
+ ->getScene()
+ ->getProject()
+ ->getName()
+ .getName());
+ RecentFiles::instance()->removeFilePath(index, RecentFiles::Scene);
+ RecentFiles::instance()->addFilePath(fileName, RecentFiles::Scene,
+ projectName);
+ } else
+ RecentFiles::instance()->moveFilePath(index, 0, RecentFiles::Scene);
RecentFiles::instance()->refreshRecentFilesMenu(RecentFiles::Scene);
hide();
}
diff --git a/toonz/sources/toonz/viewerpane.cpp b/toonz/sources/toonz/viewerpane.cpp
index a82f7e768..7373e7b33 100644
--- a/toonz/sources/toonz/viewerpane.cpp
+++ b/toonz/sources/toonz/viewerpane.cpp
@@ -27,6 +27,7 @@
#include "toonz/tonionskinmaskhandle.h"
#include "toutputproperties.h"
#include "toonz/preferences.h"
+#include "toonz/tproject.h"
// TnzQt includes
#include "toonzqt/menubarcommand.h"
@@ -521,10 +522,12 @@ void SceneViewerPanel::changeWindowTitle() {
int frame = app->getCurrentFrame()->getFrame();
QString name;
if (app->getCurrentFrame()->isEditingScene()) {
- QString sceneName = QString::fromStdWString(scene->getSceneName());
+ TProject *project = scene->getProject();
+ QString projectName = QString::fromStdString(project->getName().getName());
+ QString sceneName = QString::fromStdWString(scene->getSceneName());
if (sceneName.isEmpty()) sceneName = tr("Untitled");
if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString("*");
- name = tr("Scene: ") + sceneName;
+ name = tr("Scene: ") + sceneName + tr(" :: Project: ") + projectName;
if (frame >= 0)
name =
name + tr(" :: Frame: ") + tr(std::to_string(frame + 1).c_str());
diff --git a/toonz/sources/toonz/xsheetviewer.cpp b/toonz/sources/toonz/xsheetviewer.cpp
index 0d7d9dbc8..0c085df5d 100644
--- a/toonz/sources/toonz/xsheetviewer.cpp
+++ b/toonz/sources/toonz/xsheetviewer.cpp
@@ -32,6 +32,7 @@
#include "toonz/txshnoteset.h"
#include "toonz/childstack.h"
#include "toonz/txshlevelhandle.h"
+#include "toonz/tproject.h"
#include "tconvert.h"
#include "tenv.h"
@@ -1603,13 +1604,16 @@ void XsheetViewer::changeWindowTitle() {
TApp *app = TApp::instance();
ToonzScene *scene = app->getCurrentScene()->getScene();
if (!scene || !app->getCurrentFrame()->isEditingScene()) return;
- QString sceneName = QString::fromStdWString(scene->getSceneName());
+ TProject *project = scene->getProject();
+ QString projectName = QString::fromStdString(project->getName().getName());
+ QString sceneName = QString::fromStdWString(scene->getSceneName());
if (sceneName.isEmpty()) sceneName = tr("Untitled");
if (app->getCurrentScene()->getDirtyFlag()) sceneName += QString("*");
- QString name = tr("Scene: ") + sceneName;
+ QString name =
+ tr("Scene: ") + sceneName + tr(" :: Project: ") + projectName;
int frameCount = scene->getFrameCount();
name = name + " :: " + tr(std::to_string(frameCount).c_str()) +
- tr(" Frames");
+ (frameCount == 1 ? tr(" Frame") : tr(" Frames"));
// subXsheet or not
ChildStack *childStack = scene->getChildStack();