Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance the custom tab name behavior #678

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#define TAB_INDEX_PROPERTY "tab_index"
#define TAB_CUSTOM_NAME_PROPERTY "custom_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))
{
Expand Down Expand Up @@ -175,7 +176,11 @@ void TabWidget::onTermTitleChanged(QString title, QString icon)
{
TermWidgetHolder * console = qobject_cast<TermWidgetHolder*>(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_PROPERTY, title);
}
else
{
const int index = console->property(TAB_INDEX_PROPERTY).toInt();

Expand All @@ -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_PROPERTY).toString());
widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, false);
/* Release the stored title memory */
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_PROPERTY, QString(tabText(index)));
/* Set the custom text */
setTabText(index, text);
widget(index)->setProperty(TAB_CUSTOM_NAME_PROPERTY, true);
}
if (currentIndex() == index)
emit currentTitleChanged(index);
}
Expand Down