14.29: the blank start tab stays put; Untitled numbers stay low

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 15:52:24 -04:00
1 parent 1e647a9b74
commit 10f51cdf72
9 files changed
+123 -26

No files matched your search

+22 -3
View File
@@ -3,6 +3,7 @@
#include "Logging.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QSet>
#include <QTimer>
#include <algorithm>
@@ -72,12 +73,30 @@ void ProjectWorkspace::finish(const std::function<void(bool)> &done, bool value)
QMetaObject::invokeMethod(this, [done, value] { done(value); }, Qt::QueuedConnection);
}
// "Untitled", else the lowest "Untitled N" no tab shows.
QString ProjectWorkspace::freeUntitledName() const
{
QSet<QString> taken;
for (const std::shared_ptr<ProjectTab> &each : m_tabs)
taken.insert(each->title());
if (!taken.contains(QStringLiteral("Untitled")))
return QStringLiteral("Untitled");
int number = 2;
while (taken.contains(QStringLiteral("Untitled %1").arg(number)))
number += 1;
return QStringLiteral("Untitled %1").arg(number);
}
bool ProjectWorkspace::canClose(const ProjectTab &tab) const
{
return !(m_tabs.size() == 1 && !tab.session.document() && !tab.session.projectPath());
}
ProjectTab &ProjectWorkspace::addTab(bool reuseEmpty)
{
if (reuseEmpty && m_tabs.size() == 1 && !current().session.document())
return current();
const auto added = std::make_shared<ProjectTab>(QStringLiteral("Untitled %1").arg(m_nextNumber));
m_nextNumber += 1;
const auto added = std::make_shared<ProjectTab>(freeUntitledName());
added->controller.workspace = this;
added->controller.window = window;
m_tabs.push_back(added);
@@ -182,7 +201,7 @@ void ProjectWorkspace::loadProject(const QString &path, std::function<void(bool)
void ProjectWorkspace::close(QUuid id, std::function<void()> done)
{
const std::shared_ptr<ProjectTab> closing = tab(id);
if (!canSwitch() || !closing) {
if (!canSwitch() || !closing || !canClose(*closing)) {
finish(done);
return;
}
+3 -1
View File
@@ -34,6 +34,8 @@ public:
ProjectTab &current() const;
std::shared_ptr<ProjectTab> tab(QUuid id) const;
bool canSwitch() const;
// The only tab, still blank, has nothing to close.
bool canClose(const ProjectTab &tab) const;
ProjectTab &addTab(bool reuseEmpty = true);
void select(QUuid id);
// A dragged tab lands at `index`, clamped; chrome, never undone.
@@ -74,6 +76,7 @@ signals:
void changed();
private:
QString freeUntitledName() const;
bool finishTextEditing();
struct Baked {
EditorSession::BakedImages images;
@@ -102,5 +105,4 @@ private:
std::vector<std::shared_ptr<ProjectTab>> m_tabs;
QUuid m_selectedID;
bool m_isManaging = false;
int m_nextNumber = 2;
};
+5 -2
View File
@@ -86,8 +86,11 @@ void ProjectTabButton::synchronize()
const QFontMetrics metrics(tabFont(active));
m_select->setText(dot + metrics.elidedText(tab->title(), Qt::ElideRight, label - (modified ? 10 : 0)));
m_select->setFont(tabFont(active));
// Swift's trailing 8 inside; a character dot outgrows Swift's 10.
m_select->setFixedWidth(label + 8 + (modified ? metrics.horizontalAdvance(dot) - 10 : 0));
// Trailing 8, or 11 closed up; a dot outgrows 10.
const bool closable = m_workspace.canClose(*tab);
m_select->setFixedWidth(label + (closable ? 8 : 11) + (modified ? metrics.horizontalAdvance(dot) - 10 : 0));
layout()->setContentsMargins(11, 0, closable ? 5 : 0, 0);
m_close->setVisible(closable);
m_select->setToolTip(tab->title());
m_select->setEnabled(m_workspace.canSwitch() || active);
m_close->setToolTip(QStringLiteral("Close %1").arg(tab->title()));