From 1e7bc6b0b3e7d3dcc6a438e3ebe44d2afbae9363 Mon Sep 17 00:00:00 2001 From: Christophe CURAY Date: Sun, 10 May 2020 19:41:17 +0200 Subject: [PATCH 1/2] Modify custom tab name behaviour: provide the current name+restore title when no text --- src/tabwidget.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index cfaec3df..052d0a55 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -34,6 +34,7 @@ #define TAB_INDEX_PROPERTY "tab_index" #define TAB_CUSTOM_NAME_PROPERTY "custom_name" +#define TAB_TERM_TITLE_NAME "term_title_name" TabWidget::TabWidget(QWidget* parent) : QTabWidget(parent), tabNumerator(0), mTabBar(new TabBar(this)), mSwitcher(new TabSwitcher(this)) { @@ -175,7 +176,11 @@ void TabWidget::onTermTitleChanged(QString title, QString icon) { TermWidgetHolder * console = qobject_cast(sender()); const bool custom_name = console->property(TAB_CUSTOM_NAME_PROPERTY).toBool(); - if (!custom_name) + if (custom_name) + { /* Store the new title to use it when customization is removed */ + console->setProperty(TAB_TERM_TITLE_NAME, title); + } + else { const int index = console->property(TAB_INDEX_PROPERTY).toInt(); @@ -197,12 +202,27 @@ void TabWidget::renameSession(int index) bool ok = false; QString text = QInputDialog::getText(this, tr("Tab name"), tr("New tab name:"), QLineEdit::Normal, - QString(), &ok); - if(ok && !text.isEmpty()) + QString(tabText(index)), &ok); + if(ok) { setTabIcon(index, QIcon{}); - setTabText(index, text); - widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, true); + if (text.isEmpty()) + { + /* Set the custom text */ + setTabText(index, widget(index)->property(TAB_TERM_TITLE_NAME).toString()); + widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, false); + /* Release the stored title memory */ + widget(index)->setProperty(TAB_TERM_TITLE_NAME, QVariant::Invalid); + } + else + { + /* Store the current title before we set the first custom value */ + if (!widget(index)->property(TAB_CUSTOM_NAME_PROPERTY).toBool()) + widget(index)->setProperty(TAB_TERM_TITLE_NAME, QString(tabText(index))); + /* Set the custom text */ + setTabText(index, text); + widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, true); + } if (currentIndex() == index) emit currentTitleChanged(index); } From 14fe83c404c893df72d826e8a1c0b03f0685c610 Mon Sep 17 00:00:00 2001 From: Christophe CURAY Date: Thu, 6 Aug 2020 15:00:57 +0200 Subject: [PATCH 2/2] Modify custom tab name behaviour: rename tab internal property to match existing ones --- src/tabwidget.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index 052d0a55..7e72b39e 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -34,7 +34,7 @@ #define TAB_INDEX_PROPERTY "tab_index" #define TAB_CUSTOM_NAME_PROPERTY "custom_name" -#define TAB_TERM_TITLE_NAME "term_title_name" +#define TAB_TERM_TITLE_NAME_PROPERTY "term_title_name" TabWidget::TabWidget(QWidget* parent) : QTabWidget(parent), tabNumerator(0), mTabBar(new TabBar(this)), mSwitcher(new TabSwitcher(this)) { @@ -178,7 +178,7 @@ void TabWidget::onTermTitleChanged(QString title, QString icon) const bool custom_name = console->property(TAB_CUSTOM_NAME_PROPERTY).toBool(); if (custom_name) { /* Store the new title to use it when customization is removed */ - console->setProperty(TAB_TERM_TITLE_NAME, title); + console->setProperty(TAB_TERM_TITLE_NAME_PROPERTY, title); } else { @@ -209,16 +209,16 @@ void TabWidget::renameSession(int index) if (text.isEmpty()) { /* Set the custom text */ - setTabText(index, widget(index)->property(TAB_TERM_TITLE_NAME).toString()); + setTabText(index, widget(index)->property(TAB_TERM_TITLE_NAME_PROPERTY).toString()); widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, false); /* Release the stored title memory */ - widget(index)->setProperty(TAB_TERM_TITLE_NAME, QVariant::Invalid); + widget(index)->setProperty(TAB_TERM_TITLE_NAME_PROPERTY, QVariant::Invalid); } else { /* Store the current title before we set the first custom value */ if (!widget(index)->property(TAB_CUSTOM_NAME_PROPERTY).toBool()) - widget(index)->setProperty(TAB_TERM_TITLE_NAME, QString(tabText(index))); + widget(index)->setProperty(TAB_TERM_TITLE_NAME_PROPERTY, QString(tabText(index))); /* Set the custom text */ setTabText(index, text); widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, true);