Refactored Rename Tab dialog and its context menu (#2713)

* Added placeholder to tab rename dialog's input

* Always set placeholder to default tab name.

* Renamed context menu entries, updated popup

* Removed TextInputDialog class, slight popup fix

* Forgot to rename variable (no fun allowed 😥)

* forsenT

* Made use of QDialogButtonBox

* Added changelog entry
This commit is contained in:
Paweł
2021-05-02 12:59:14 +02:00
committed by GitHub
parent b614ce1cd8
commit f7506d495f
7 changed files with 43 additions and 108 deletions
+42 -10
View File
@@ -10,7 +10,6 @@
#include "util/Helpers.hpp"
#include "widgets/Notebook.hpp"
#include "widgets/dialogs/SettingsDialog.hpp"
#include "widgets/dialogs/TextInputDialog.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include <QApplication>
@@ -54,16 +53,16 @@ NotebookTab::NotebookTab(Notebook *notebook)
this->setMouseTracking(true);
this->menu_.addAction("Rename", [this]() {
this->menu_.addAction("Rename Tab", [this]() {
this->showRenameDialog();
});
this->menu_.addAction("Close", [=]() {
this->menu_.addAction("Close Tab", [=]() {
this->notebook_->removePage(this->page);
});
highlightNewMessagesAction_ =
new QAction("Enable highlights on new messages", &this->menu_);
new QAction("Mark Tab as Unread on New Messages", &this->menu_);
highlightNewMessagesAction_->setCheckable(true);
highlightNewMessagesAction_->setChecked(highlightEnabled_);
QObject::connect(highlightNewMessagesAction_, &QAction::triggered,
@@ -75,15 +74,48 @@ NotebookTab::NotebookTab(Notebook *notebook)
void NotebookTab::showRenameDialog()
{
TextInputDialog d(this);
auto dialog = new QDialog(this);
d.setWindowTitle("Choose tab title (Empty for default)");
d.setText(this->getCustomTitle());
d.highlightText();
auto vbox = new QVBoxLayout;
if (d.exec() == QDialog::Accepted)
auto lineEdit = new QLineEdit;
lineEdit->setText(this->getCustomTitle());
lineEdit->setPlaceholderText(this->getDefaultTitle());
lineEdit->selectAll();
vbox->addWidget(new QLabel("Name:"));
vbox->addWidget(lineEdit);
vbox->addStretch(1);
auto buttonBox =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
vbox->addWidget(buttonBox);
dialog->setLayout(vbox);
QObject::connect(buttonBox, &QDialogButtonBox::accepted, [dialog] {
dialog->accept();
dialog->close();
});
QObject::connect(buttonBox, &QDialogButtonBox::rejected, [dialog] {
dialog->reject();
dialog->close();
});
dialog->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
dialog->setMinimumSize(dialog->minimumSizeHint().width() + 50,
dialog->minimumSizeHint().height() + 10);
dialog->setWindowFlags(
(dialog->windowFlags() & ~(Qt::WindowContextHelpButtonHint)) |
Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
dialog->setWindowTitle("Rename Tab");
if (dialog->exec() == QDialog::Accepted)
{
QString newTitle = d.getText();
QString newTitle = lineEdit->text();
this->setCustomTitle(newTitle);
}
}