Skip to content

Commit 30c13a0

Browse files
Kakueeendeepin-ci-robot
authored andcommitted
1 parent 2b9621c commit 30c13a0

File tree

5 files changed

+66
-27
lines changed

5 files changed

+66
-27
lines changed

src/plugins/core/session/sessiondialog.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,16 @@ SessionNameInputDialog::SessionNameInputDialog(QWidget *parent)
174174
: DDialog(parent)
175175
{
176176
initUI();
177+
connect(this, &SessionNameInputDialog::buttonClicked, this, &SessionNameInputDialog::handleButtonClicked);
177178
}
178179

179180
void SessionNameInputDialog::initUI()
180181
{
181182
setSpacing(10);
182183
setIcon(QIcon::fromTheme("ide"));
183184
lineEdit = new DLineEdit(this);
185+
QRegExpValidator *validator = new QRegExpValidator(QRegExp("[^/\?:\\\\*]*"), lineEdit);
186+
lineEdit->lineEdit()->setValidator(validator);
184187
lineEdit->setPlaceholderText(tr("Please input session name"));
185188
connect(lineEdit, &DLineEdit::textChanged, this, [this](const QString &text) {
186189
getButton(1)->setEnabled(!text.isEmpty());
@@ -194,6 +197,25 @@ void SessionNameInputDialog::initUI()
194197
getButton(1)->setEnabled(false);
195198
getButton(2)->setEnabled(false);
196199
setFocusProxy(lineEdit);
200+
setOnButtonClickedClose(false);
201+
}
202+
203+
void SessionNameInputDialog::handleButtonClicked(int index)
204+
{
205+
if (index == 0)
206+
return reject();
207+
208+
const auto name = sessionName();
209+
if (SessionManager::instance()->sessionList().contains(name)) {
210+
QString msg = tr("The session already exists, please re-enter.");
211+
lineEdit->showAlertMessage(msg);
212+
return;
213+
}
214+
215+
if (index == 2)
216+
isSwitchTo = true;
217+
218+
accept();
197219
}
198220

199221
void SessionNameInputDialog::setSessionName(const QString &name)
@@ -211,3 +233,8 @@ void SessionNameInputDialog::setActionText(const QString &actText, const QString
211233
getButton(1)->setText(actText);
212234
getButton(2)->setText(openActText);
213235
}
236+
237+
bool SessionNameInputDialog::isSwitchToRequested() const
238+
{
239+
return isSwitchTo;
240+
}

src/plugins/core/session/sessiondialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ class SessionNameInputDialog : public DTK_WIDGET_NAMESPACE::DDialog
5151
void setSessionName(const QString &name);
5252
QString sessionName() const;
5353
void setActionText(const QString &actText, const QString &openActText);
54+
bool isSwitchToRequested() const;
5455

5556
private:
5657
void initUI();
58+
void handleButtonClicked(int index);
5759

5860
DTK_WIDGET_NAMESPACE::DLineEdit *lineEdit { nullptr };
61+
bool isSwitchTo { false };
5962
};
6063

6164
#endif // SESSIONDIALOG_H

src/plugins/core/session/sessionlistview.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ QStringList SessionListView::selectedSessions() const
195195
void SessionListView::runInputDialog(SessionNameInputDialog *dialog,
196196
std::function<void(const QString &)> handler)
197197
{
198-
int ret = dialog->exec();
199-
if (ret < 1)
200-
return;
201-
202-
const auto name = dialog->sessionName();
203-
if (name.isEmpty() || SessionManager::instance()->sessionList().contains(name))
204-
return;
198+
if (dialog->exec() == QDialog::Accepted) {
199+
const auto name = dialog->sessionName();
200+
if (name.isEmpty())
201+
return;
205202

206-
handler(name);
207-
model.reset();
208-
if (ret == 2)
209-
SessionManager::instance()->loadSession(name);
210-
Q_EMIT sessionCreated(name);
203+
handler(name);
204+
model.reset();
205+
if (dialog->isSwitchToRequested()) {
206+
SessionManager::instance()->loadSession(name);
207+
Q_EMIT sessionSwitched();
208+
}
209+
Q_EMIT sessionCreated(name);
210+
}
211211
}

src/plugins/recent/mainframe/sessionitemwidget.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ArrowHeaderLine::ArrowHeaderLine(QWidget *parent)
3535
titleLabel = new DLabel(this);
3636
titleLabel->installEventFilter(this);
3737
titleLabel->setCursor(Qt::PointingHandCursor);
38+
titleLabel->setTextFormat(Qt::PlainText);
3839
DFontSizeManager::instance()->bind(titleLabel, DFontSizeManager::T5, QFont::Medium);
3940

4041
connect(arrowButton, &DToolButton::clicked, this, &ArrowHeaderLine::expandChanged);
@@ -75,7 +76,7 @@ void ArrowHeaderLine::setTitleTip(const QString &tooltip)
7576
void ArrowHeaderLine::resizeEvent(QResizeEvent *e)
7677
{
7778
updateTitle();
78-
79+
7980
return QWidget::resizeEvent(e);
8081
}
8182

@@ -126,7 +127,7 @@ void ArrowHeaderLine::reverseArrowDirection()
126127
void ArrowHeaderLine::updateTitle()
127128
{
128129
QFontMetrics fm = titleLabel->fontMetrics();
129-
auto displayText = fm.elidedText(titleText, Qt::ElideRight, titleLabel->width());
130+
auto displayText = fm.elidedText(titleText, Qt::ElideMiddle, titleLabel->width());
130131
titleLabel->setText(displayText);
131132
}
132133

@@ -321,7 +322,10 @@ void SessionItemWidgetPrivate::runInputDialog(const QString &title, const QStrin
321322
dlg.setTitle(title);
322323
dlg.setIcon(QIcon::fromTheme("ide"));
323324
DLineEdit *lineEdit = new DLineEdit(&dlg);
325+
QRegExpValidator *validator = new QRegExpValidator(QRegExp("[^/\?:\\\\*]*"), lineEdit);
326+
lineEdit->lineEdit()->setValidator(validator);
324327
lineEdit->setPlaceholderText(SessionItemWidget::tr("Please input session name"));
328+
lineEdit->setText(editText);
325329
connect(lineEdit, &DLineEdit::textChanged, &dlg, [&dlg](const QString &text) {
326330
dlg.getButton(1)->setEnabled(!text.isEmpty());
327331
dlg.getButton(2)->setEnabled(!text.isEmpty());
@@ -332,21 +336,26 @@ void SessionItemWidgetPrivate::runInputDialog(const QString &title, const QStrin
332336
dlg.addButton(SessionItemWidget::tr("Cancel", "button"));
333337
dlg.addButton(actList[0]);
334338
dlg.addButton(actList[1], true, DDialog::ButtonRecommend);
335-
dlg.getButton(1)->setEnabled(false);
336-
dlg.getButton(2)->setEnabled(false);
337-
lineEdit->setText(editText);
339+
dlg.setOnButtonClickedClose(false);
340+
connect(&dlg, &DDialog::buttonClicked, this, [&](int index) {
341+
if (index == 0)
342+
return dlg.reject();
343+
344+
const auto name = lineEdit->text();
345+
if (sessionSrv->sessionList().contains(name)) {
346+
QString msg = tr("The session already exists, please re-enter.");
347+
lineEdit->showAlertMessage(msg);
348+
return;
349+
}
338350

339-
int ret = dlg.exec();
340-
if (ret < 1)
341-
return;
351+
handler(name);
352+
if (index == 2)
353+
sessionSrv->loadSession(name);
342354

343-
const auto name = lineEdit->text();
344-
if (name.isEmpty() || sessionSrv->sessionList().contains(name))
345-
return;
355+
dlg.accept();
356+
});
346357

347-
handler(name);
348-
if (ret == 2)
349-
sessionSrv->loadSession(name);
358+
dlg.exec();
350359
}
351360

352361
SessionItemWidget::SessionItemWidget(QWidget *parent)

src/plugins/recent/mainframe/sessionitemwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ArrowHeaderLine : public QWidget
4545
private:
4646
void reverseArrowDirection();
4747
void updateTitle();
48-
48+
4949
bool isExpanded { false };
5050
QString titleText;
5151
DTK_WIDGET_NAMESPACE::DToolButton *arrowButton { nullptr };

0 commit comments

Comments
 (0)