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

fix: [session] Issues of session name #1050

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions src/plugins/core/session/sessiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
: DDialog(parent)
{
initUI();
connect(this, &SessionNameInputDialog::buttonClicked, this, &SessionNameInputDialog::handleButtonClicked);
}

void SessionNameInputDialog::initUI()
{
setSpacing(10);
setIcon(QIcon::fromTheme("ide"));
lineEdit = new DLineEdit(this);
QRegExpValidator *validator = new QRegExpValidator(QRegExp("[^/\?:\\\\*]*"), lineEdit);
lineEdit->lineEdit()->setValidator(validator);
lineEdit->setPlaceholderText(tr("Please input session name"));
connect(lineEdit, &DLineEdit::textChanged, this, [this](const QString &text) {
getButton(1)->setEnabled(!text.isEmpty());
Expand All @@ -194,6 +197,25 @@ void SessionNameInputDialog::initUI()
getButton(1)->setEnabled(false);
getButton(2)->setEnabled(false);
setFocusProxy(lineEdit);
setOnButtonClickedClose(false);
}

void SessionNameInputDialog::handleButtonClicked(int index)
{
if (index == 0)
return reject();

const auto name = sessionName();
if (SessionManager::instance()->sessionList().contains(name)) {
QString msg = tr("The session already exists, please re-enter.");
lineEdit->showAlertMessage(msg);
return;
}

if (index == 2)
isSwitchTo = true;

accept();
}

void SessionNameInputDialog::setSessionName(const QString &name)
Expand All @@ -211,3 +233,8 @@ void SessionNameInputDialog::setActionText(const QString &actText, const QString
getButton(1)->setText(actText);
getButton(2)->setText(openActText);
}

bool SessionNameInputDialog::isSwitchToRequested() const
{
return isSwitchTo;
}
3 changes: 3 additions & 0 deletions src/plugins/core/session/sessiondialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,14 @@ class SessionNameInputDialog : public DTK_WIDGET_NAMESPACE::DDialog
void setSessionName(const QString &name);
QString sessionName() const;
void setActionText(const QString &actText, const QString &openActText);
bool isSwitchToRequested() const;

private:
void initUI();
void handleButtonClicked(int index);

DTK_WIDGET_NAMESPACE::DLineEdit *lineEdit { nullptr };
bool isSwitchTo { false };
};

#endif // SESSIONDIALOG_H
24 changes: 12 additions & 12 deletions src/plugins/core/session/sessionlistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,17 @@ QStringList SessionListView::selectedSessions() const
void SessionListView::runInputDialog(SessionNameInputDialog *dialog,
std::function<void(const QString &)> handler)
{
int ret = dialog->exec();
if (ret < 1)
return;

const auto name = dialog->sessionName();
if (name.isEmpty() || SessionManager::instance()->sessionList().contains(name))
return;
if (dialog->exec() == QDialog::Accepted) {
const auto name = dialog->sessionName();
if (name.isEmpty())
return;

handler(name);
model.reset();
if (ret == 2)
SessionManager::instance()->loadSession(name);
Q_EMIT sessionCreated(name);
handler(name);
model.reset();
if (dialog->isSwitchToRequested()) {
SessionManager::instance()->loadSession(name);
Q_EMIT sessionSwitched();
}
Q_EMIT sessionCreated(name);
}
}
37 changes: 23 additions & 14 deletions src/plugins/recent/mainframe/sessionitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ArrowHeaderLine::ArrowHeaderLine(QWidget *parent)
titleLabel = new DLabel(this);
titleLabel->installEventFilter(this);
titleLabel->setCursor(Qt::PointingHandCursor);
titleLabel->setTextFormat(Qt::PlainText);
DFontSizeManager::instance()->bind(titleLabel, DFontSizeManager::T5, QFont::Medium);

connect(arrowButton, &DToolButton::clicked, this, &ArrowHeaderLine::expandChanged);
Expand Down Expand Up @@ -75,7 +76,7 @@ void ArrowHeaderLine::setTitleTip(const QString &tooltip)
void ArrowHeaderLine::resizeEvent(QResizeEvent *e)
{
updateTitle();

return QWidget::resizeEvent(e);
}

Expand Down Expand Up @@ -126,7 +127,7 @@ void ArrowHeaderLine::reverseArrowDirection()
void ArrowHeaderLine::updateTitle()
{
QFontMetrics fm = titleLabel->fontMetrics();
auto displayText = fm.elidedText(titleText, Qt::ElideRight, titleLabel->width());
auto displayText = fm.elidedText(titleText, Qt::ElideMiddle, titleLabel->width());
titleLabel->setText(displayText);
}

Expand Down Expand Up @@ -321,7 +322,10 @@ void SessionItemWidgetPrivate::runInputDialog(const QString &title, const QStrin
dlg.setTitle(title);
dlg.setIcon(QIcon::fromTheme("ide"));
DLineEdit *lineEdit = new DLineEdit(&dlg);
QRegExpValidator *validator = new QRegExpValidator(QRegExp("[^/\?:\\\\*]*"), lineEdit);
lineEdit->lineEdit()->setValidator(validator);
lineEdit->setPlaceholderText(SessionItemWidget::tr("Please input session name"));
lineEdit->setText(editText);
connect(lineEdit, &DLineEdit::textChanged, &dlg, [&dlg](const QString &text) {
dlg.getButton(1)->setEnabled(!text.isEmpty());
dlg.getButton(2)->setEnabled(!text.isEmpty());
Expand All @@ -332,21 +336,26 @@ void SessionItemWidgetPrivate::runInputDialog(const QString &title, const QStrin
dlg.addButton(SessionItemWidget::tr("Cancel", "button"));
dlg.addButton(actList[0]);
dlg.addButton(actList[1], true, DDialog::ButtonRecommend);
dlg.getButton(1)->setEnabled(false);
dlg.getButton(2)->setEnabled(false);
lineEdit->setText(editText);
dlg.setOnButtonClickedClose(false);
connect(&dlg, &DDialog::buttonClicked, this, [&](int index) {
if (index == 0)
return dlg.reject();

const auto name = lineEdit->text();
if (sessionSrv->sessionList().contains(name)) {
QString msg = tr("The session already exists, please re-enter.");
lineEdit->showAlertMessage(msg);
return;
}

int ret = dlg.exec();
if (ret < 1)
return;
handler(name);
if (index == 2)
sessionSrv->loadSession(name);

const auto name = lineEdit->text();
if (name.isEmpty() || sessionSrv->sessionList().contains(name))
return;
dlg.accept();
});

handler(name);
if (ret == 2)
sessionSrv->loadSession(name);
dlg.exec();
}

SessionItemWidget::SessionItemWidget(QWidget *parent)
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/recent/mainframe/sessionitemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ArrowHeaderLine : public QWidget
private:
void reverseArrowDirection();
void updateTitle();

bool isExpanded { false };
QString titleText;
DTK_WIDGET_NAMESPACE::DToolButton *arrowButton { nullptr };
Expand Down
Loading