Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 09691d55 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

WINDOW: On new/open document, the first untouched document is replaced by the new document

parent 292089a8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!3Add documents
......@@ -272,7 +272,15 @@ MainWindow::loadSubDocumentAudio() noexcept
void
MainWindow::addTab(VivyDocumentView *tab)
{
const int index = documents->addTab(tab, QIcon(":/icons/vivy.png"), tab->getDocumentTabName());
int index = -1;
if (const int untouched_index = findFirstUntouchedDocument(); untouched_index >= 0) {
closeDocument(untouched_index);
index = documents->insertTab(untouched_index, tab, QIcon(":/icons/vivy.png"),
tab->getDocumentTabName());
} else {
index = documents->addTab(tab, QIcon(":/icons/vivy.png"), tab->getDocumentTabName());
}
documents->setTabToolTip(index, tab->getDocumentTabToolTip());
qDebug() << "View constructed successfully";
}
......@@ -289,3 +297,24 @@ MainWindow::getCurrentDocumentView() const
throw std::runtime_error("no current document");
}
}
VivyDocumentView *
MainWindow::getTab(const int index) const noexcept
{
if (index > documents->count())
return nullptr;
return reinterpret_cast<VivyDocumentView *>(documents->widget(index));
}
int
MainWindow::findFirstUntouchedDocument() const noexcept
{
const int count = documents->count();
for (int index = 0; index < count; ++index) {
if (getTab(index)->getDocument().lock()->checkDocumentOption(
VivyDocument::UntouchedByDefault))
return index;
}
return -1;
}
......@@ -26,7 +26,9 @@ public:
private:
void addTab(VivyDocumentView *);
VivyDocumentView *getTab(const int) const noexcept;
VivyDocumentView *getCurrentDocumentView() const;
int findFirstUntouchedDocument() const noexcept;
private slots:
void newDocument() noexcept;
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter