Changeset View
Changeset View
Standalone View
Standalone View
kate/session/katesessionmanagedialog.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 38 | { | |||
---|---|---|---|---|---|
42 | 42 | | |||
43 | m_sessionList->installEventFilter(this); | 43 | m_sessionList->installEventFilter(this); | ||
44 | connect(m_sessionList, &QTreeWidget::currentItemChanged, this, &KateSessionManageDialog::selectionChanged); | 44 | connect(m_sessionList, &QTreeWidget::currentItemChanged, this, &KateSessionManageDialog::selectionChanged); | ||
45 | connect(m_sessionList, &QTreeWidget::itemDoubleClicked, this, &KateSessionManageDialog::openSession); | 45 | connect(m_sessionList, &QTreeWidget::itemDoubleClicked, this, &KateSessionManageDialog::openSession); | ||
46 | m_sessionList->header()->moveSection(0, 1); // Re-order columns to "Files, Sessions" | 46 | m_sessionList->header()->moveSection(0, 1); // Re-order columns to "Files, Sessions" | ||
47 | 47 | | |||
48 | m_filterBox->installEventFilter(this); | 48 | m_filterBox->installEventFilter(this); | ||
49 | connect(m_filterBox, &QLineEdit::textChanged, this, &KateSessionManageDialog::filterChanged); | 49 | connect(m_filterBox, &QLineEdit::textChanged, this, &KateSessionManageDialog::filterChanged); | ||
50 | connect(m_sortButton, &QPushButton::clicked, this, &KateSessionManageDialog::changeSortOrder); | | |||
51 | 50 | | |||
52 | connect(m_newButton, &QPushButton::clicked, this, &KateSessionManageDialog::openNewSession); | 51 | connect(m_newButton, &QPushButton::clicked, this, &KateSessionManageDialog::openNewSession); | ||
53 | 52 | | |||
54 | KGuiItem::assign(m_openButton, KStandardGuiItem::open()); | 53 | KGuiItem::assign(m_openButton, KStandardGuiItem::open()); | ||
55 | m_openButton->setDefault(true); | 54 | m_openButton->setDefault(true); | ||
56 | connect(m_openButton, &QPushButton::clicked, this, &KateSessionManageDialog::openSession); | 55 | connect(m_openButton, &QPushButton::clicked, this, &KateSessionManageDialog::openSession); | ||
57 | 56 | | |||
58 | connect(m_templateButton, &QPushButton::clicked, this, &KateSessionManageDialog::openSessionAsTemplate); | 57 | connect(m_templateButton, &QPushButton::clicked, this, &KateSessionManageDialog::openSessionAsTemplate); | ||
59 | 58 | | |||
60 | connect(m_copyButton, &QPushButton::clicked, this, &KateSessionManageDialog::copySession); | 59 | connect(m_copyButton, &QPushButton::clicked, this, &KateSessionManageDialog::copySession); | ||
61 | 60 | | |||
62 | connect(m_renameButton, &QPushButton::clicked, this, &KateSessionManageDialog::editBegin); | 61 | connect(m_renameButton, &QPushButton::clicked, this, &KateSessionManageDialog::editBegin); | ||
63 | 62 | | |||
64 | connect(m_deleteButton, &QPushButton::clicked, this, &KateSessionManageDialog::updateDeleteList); | 63 | connect(m_deleteButton, &QPushButton::clicked, this, &KateSessionManageDialog::updateDeleteList); | ||
65 | 64 | | |||
66 | KGuiItem::assign(m_closeButton, KStandardGuiItem::close()); | 65 | KGuiItem::assign(m_closeButton, KStandardGuiItem::close()); | ||
67 | connect(m_closeButton, &QPushButton::clicked, this, &KateSessionManageDialog::closeDialog); | 66 | connect(m_closeButton, &QPushButton::clicked, this, &KateSessionManageDialog::closeDialog); | ||
68 | 67 | | |||
69 | connect(KateApp::self()->sessionManager(), &KateSessionManager::sessionListChanged, this, &KateSessionManageDialog::updateSessionList); | 68 | connect(KateApp::self()->sessionManager(), &KateSessionManager::sessionListChanged, this, &KateSessionManageDialog::updateSessionList); | ||
70 | | ||||
71 | changeSortOrder(); // Set order to SortAlphabetical, set button text and fill session list | | |||
72 | } | 69 | } | ||
73 | 70 | | |||
74 | KateSessionManageDialog::KateSessionManageDialog(QWidget *parent, const QString &lastSession) | 71 | KateSessionManageDialog::KateSessionManageDialog(QWidget *parent, const QString &lastSession) | ||
75 | : KateSessionManageDialog(parent) | 72 | : KateSessionManageDialog(parent) | ||
76 | { | 73 | { | ||
77 | setWindowTitle(i18n("Session Chooser")); | 74 | setWindowTitle(i18n("Session Chooser")); | ||
78 | m_dontAskCheckBox->show(); | 75 | m_dontAskCheckBox->show(); | ||
79 | m_chooserMode = true; | 76 | m_chooserMode = true; | ||
80 | connect(m_dontAskCheckBox, &QCheckBox::toggled, this, &KateSessionManageDialog::dontAskToggled); | 77 | connect(m_dontAskCheckBox, &QCheckBox::toggled, this, &KateSessionManageDialog::dontAskToggled); | ||
81 | 78 | | |||
82 | m_prefferedSession = lastSession; | 79 | m_preferredSession = lastSession; | ||
83 | changeSortOrder(); // Set order to SortChronological | 80 | updateSessionList(); | ||
84 | } | 81 | } | ||
85 | 82 | | |||
86 | KateSessionManageDialog::~KateSessionManageDialog() | 83 | KateSessionManageDialog::~KateSessionManageDialog() | ||
87 | { | 84 | { | ||
88 | } | 85 | } | ||
89 | 86 | | |||
90 | void KateSessionManageDialog::dontAskToggled() | 87 | void KateSessionManageDialog::dontAskToggled() | ||
91 | { | 88 | { | ||
92 | m_templateButton->setEnabled(!m_dontAskCheckBox->isChecked()); | 89 | m_templateButton->setEnabled(!m_dontAskCheckBox->isChecked()); | ||
93 | } | 90 | } | ||
94 | 91 | | |||
95 | void KateSessionManageDialog::changeSortOrder() | | |||
96 | { | | |||
97 | switch (m_sortOrder) { | | |||
98 | case SortAlphabetical: | | |||
99 | m_sortOrder = SortChronological; | | |||
100 | m_sortButton->setText(i18n("Sort Alphabetical")); | | |||
101 | // m_sortButton->setIcon(QIcon::fromTheme(QStringLiteral("FIXME"))); | | |||
102 | break; | | |||
103 | case SortChronological: | | |||
104 | m_sortOrder = SortAlphabetical; | | |||
105 | m_sortButton->setText(i18n("Sort Last Used")); | | |||
106 | // m_sortButton->setIcon(QIcon::fromTheme(QStringLiteral("FIXME"))); | | |||
107 | break; | | |||
108 | } | | |||
109 | | ||||
110 | updateSessionList(); | | |||
111 | } | | |||
112 | | ||||
113 | void KateSessionManageDialog::filterChanged() | 92 | void KateSessionManageDialog::filterChanged() | ||
114 | { | 93 | { | ||
115 | static QPointer<QTimer> delay; | 94 | static QPointer<QTimer> delay; | ||
116 | 95 | | |||
117 | if (!delay) { | 96 | if (!delay) { | ||
118 | delay = new QTimer(this); // Should be auto cleard by Qt when we die | 97 | delay = new QTimer(this); // Should be auto cleard by Qt when we die | ||
119 | delay->setSingleShot(true); | 98 | delay->setSingleShot(true); | ||
120 | delay->setInterval(400); | 99 | delay->setInterval(400); | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 176 | { | |||
198 | m_openButton->setEnabled(false); | 177 | m_openButton->setEnabled(false); | ||
199 | m_newButton->setEnabled(false); | 178 | m_newButton->setEnabled(false); | ||
200 | m_templateButton->setEnabled(false); | 179 | m_templateButton->setEnabled(false); | ||
201 | m_dontAskCheckBox->setEnabled(false); | 180 | m_dontAskCheckBox->setEnabled(false); | ||
202 | m_copyButton->setEnabled(false); | 181 | m_copyButton->setEnabled(false); | ||
203 | m_renameButton->setEnabled(false); | 182 | m_renameButton->setEnabled(false); | ||
204 | m_deleteButton->setEnabled(false); | 183 | m_deleteButton->setEnabled(false); | ||
205 | m_closeButton->setEnabled(false); | 184 | m_closeButton->setEnabled(false); | ||
206 | m_sortButton->setEnabled(false); | | |||
207 | m_filterBox->setEnabled(false); | 185 | m_filterBox->setEnabled(false); | ||
208 | } | 186 | } | ||
209 | 187 | | |||
210 | void KateSessionManageDialog::editBegin() | 188 | void KateSessionManageDialog::editBegin() | ||
211 | { | 189 | { | ||
212 | if (m_editByUser) { | 190 | if (m_editByUser) { | ||
213 | return; | 191 | return; | ||
214 | } | 192 | } | ||
Show All 21 Lines | |||||
236 | { | 214 | { | ||
237 | m_editByUser = nullptr; | 215 | m_editByUser = nullptr; | ||
238 | disconnect(m_sessionList, &QTreeWidget::itemChanged, this, &KateSessionManageDialog::editApply); | 216 | disconnect(m_sessionList, &QTreeWidget::itemChanged, this, &KateSessionManageDialog::editApply); | ||
239 | updateSessionList(); | 217 | updateSessionList(); | ||
240 | 218 | | |||
241 | m_newButton->setEnabled(true); | 219 | m_newButton->setEnabled(true); | ||
242 | m_dontAskCheckBox->setEnabled(true); | 220 | m_dontAskCheckBox->setEnabled(true); | ||
243 | m_closeButton->setEnabled(true); | 221 | m_closeButton->setEnabled(true); | ||
244 | m_sortButton->setEnabled(true); | | |||
245 | m_filterBox->setEnabled(true); | 222 | m_filterBox->setEnabled(true); | ||
246 | 223 | | |||
247 | m_sessionList->setFocus(); | 224 | m_sessionList->setFocus(); | ||
248 | } | 225 | } | ||
249 | 226 | | |||
250 | void KateSessionManageDialog::editApply() | 227 | void KateSessionManageDialog::editApply() | ||
251 | { | 228 | { | ||
252 | if (!m_editByUser) { | 229 | if (!m_editByUser) { | ||
253 | return; | 230 | return; | ||
254 | } | 231 | } | ||
255 | 232 | | |||
256 | KateApp::self()->sessionManager()->renameSession(m_editByUser->session, m_editByUser->text(0)); | 233 | KateApp::self()->sessionManager()->renameSession(m_editByUser->session, m_editByUser->text(0)); | ||
257 | editDone(); | 234 | editDone(); | ||
258 | } | 235 | } | ||
259 | 236 | | |||
260 | void KateSessionManageDialog::copySession() | 237 | void KateSessionManageDialog::copySession() | ||
261 | { | 238 | { | ||
262 | KateSessionChooserItem *item = currentSessionItem(); | 239 | KateSessionChooserItem *item = currentSessionItem(); | ||
263 | 240 | | |||
264 | if (!item) { | 241 | if (!item) { | ||
265 | return; | 242 | return; | ||
266 | } | 243 | } | ||
267 | 244 | | |||
268 | m_prefferedSession = KateApp::self()->sessionManager()->copySession(item->session); | 245 | m_preferredSession = KateApp::self()->sessionManager()->copySession(item->session); | ||
269 | m_sessionList->setFocus(); // Only needed when user abort | 246 | m_sessionList->setFocus(); // Only needed when user abort | ||
270 | } | 247 | } | ||
271 | 248 | | |||
272 | void KateSessionManageDialog::openSession() | 249 | void KateSessionManageDialog::openSession() | ||
273 | { | 250 | { | ||
274 | KateSessionChooserItem *item = currentSessionItem(); | 251 | KateSessionChooserItem *item = currentSessionItem(); | ||
275 | 252 | | |||
276 | if (!item) { | 253 | if (!item) { | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 326 | { | |||
353 | } | 330 | } | ||
354 | 331 | | |||
355 | KateSession::Ptr currSelSession = currentSelectedSession(); | 332 | KateSession::Ptr currSelSession = currentSelectedSession(); | ||
356 | KateSession::Ptr activeSession = KateApp::self()->sessionManager()->activeSession(); | 333 | KateSession::Ptr activeSession = KateApp::self()->sessionManager()->activeSession(); | ||
357 | 334 | | |||
358 | m_sessionList->clear(); | 335 | m_sessionList->clear(); | ||
359 | 336 | | |||
360 | KateSessionList slist = KateApp::self()->sessionManager()->sessionList(); | 337 | KateSessionList slist = KateApp::self()->sessionManager()->sessionList(); | ||
361 | switch (m_sortOrder) { | 338 | // SortAlphabetical: | ||
362 | case SortAlphabetical: | 339 | // std::sort(slist.begin(), slist.end(), KateSession::compareByName); | ||
363 | std::sort(slist.begin(), slist.end(), KateSession::compareByName); | 340 | // SortChronological: | ||
364 | break; | 341 | // std::sort(slist.begin(), slist.end(), KateSession::compareByTimeDesc); | ||
365 | case SortChronological: | | |||
366 | std::sort(slist.begin(), slist.end(), KateSession::compareByTimeDesc); | | |||
367 | break; | | |||
368 | } | | |||
369 | 342 | | |||
370 | KateSessionChooserItem *prefferedItem = nullptr; | 343 | KateSessionChooserItem *preferredItem = nullptr; | ||
371 | KateSessionChooserItem *currSessionItem = nullptr; | 344 | KateSessionChooserItem *currSessionItem = nullptr; | ||
372 | KateSessionChooserItem *activeSessionItem = nullptr; | 345 | KateSessionChooserItem *activeSessionItem = nullptr; | ||
373 | 346 | | |||
374 | for (const KateSession::Ptr &session : qAsConst(slist)) { | 347 | for (const KateSession::Ptr &session : qAsConst(slist)) { | ||
375 | if (!m_filterBox->text().isEmpty()) { | 348 | if (!m_filterBox->text().isEmpty()) { | ||
376 | if (!session->name().contains(m_filterBox->text(), Qt::CaseInsensitive)) { | 349 | if (!session->name().contains(m_filterBox->text(), Qt::CaseInsensitive)) { | ||
377 | continue; | 350 | continue; | ||
378 | } | 351 | } | ||
379 | } | 352 | } | ||
380 | 353 | | |||
381 | KateSessionChooserItem *item = new KateSessionChooserItem(m_sessionList, session); | 354 | KateSessionChooserItem *item = new KateSessionChooserItem(m_sessionList, session); | ||
382 | if (session == currSelSession) { | 355 | if (session == currSelSession) { | ||
383 | currSessionItem = item; | 356 | currSessionItem = item; | ||
384 | } else if (session == activeSession) { | 357 | } else if (session == activeSession) { | ||
385 | activeSessionItem = item; | 358 | activeSessionItem = item; | ||
386 | } else if (session->name() == m_prefferedSession) { | 359 | } else if (session->name() == m_preferredSession) { | ||
387 | prefferedItem = item; | 360 | preferredItem = item; | ||
388 | m_prefferedSession.clear(); | 361 | m_preferredSession.clear(); | ||
389 | } | 362 | } | ||
390 | 363 | | |||
391 | if (m_deleteList.contains(session)) { | 364 | if (m_deleteList.contains(session)) { | ||
392 | markItemAsToBeDeleted(item); | 365 | markItemAsToBeDeleted(item); | ||
393 | } | 366 | } | ||
394 | } | 367 | } | ||
395 | 368 | | |||
396 | m_sessionList->resizeColumnToContents(1); // Minimize "Files" column | 369 | m_sessionList->header()->setStretchLastSection(false); | ||
397 | 370 | m_sessionList->header()->setSectionResizeMode(0, QHeaderView::Stretch); // stretch "Session Name" column | |||
398 | if (!prefferedItem) { | 371 | m_sessionList->resizeColumnToContents(1); // Fit "Files" column | ||
399 | prefferedItem = currSessionItem ? currSessionItem : activeSessionItem; | 372 | m_sessionList->resizeColumnToContents(2); // Fit "Last update" column | ||
373 | m_sessionList->sortByColumn(2); // sort by "Last update" column.. don't worry, it only sorts when the model data changes. | ||||
374 | | ||||
375 | if (!preferredItem) { | ||||
376 | preferredItem = currSessionItem ? currSessionItem : activeSessionItem; | ||||
400 | } | 377 | } | ||
401 | 378 | | |||
402 | if (prefferedItem) { | 379 | if (preferredItem) { | ||
403 | m_sessionList->setCurrentItem(prefferedItem); | 380 | m_sessionList->setCurrentItem(preferredItem); | ||
404 | m_sessionList->scrollToItem(prefferedItem); | 381 | m_sessionList->scrollToItem(preferredItem); | ||
405 | } else if (m_sessionList->topLevelItemCount() > 0) { | 382 | } else if (m_sessionList->topLevelItemCount() > 0) { | ||
406 | m_sessionList->setCurrentItem(m_sessionList->topLevelItem(0)); | 383 | m_sessionList->setCurrentItem(m_sessionList->topLevelItem(0)); | ||
407 | } | 384 | } | ||
408 | 385 | | |||
409 | if (m_filterBox->hasFocus()) { | 386 | if (m_filterBox->hasFocus()) { | ||
410 | return; | 387 | return; | ||
411 | } | 388 | } | ||
412 | 389 | | |||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |