Skip to content

Commit

Permalink
fix: [session] Issues of session name
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakueeen authored and deepin-ci-robot committed Jan 14, 2025
1 parent 2b9621c commit 30c13a0
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
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

0 comments on commit 30c13a0

Please sign in to comment.