Changeset View
Changeset View
Standalone View
Standalone View
kate/session/katesessionmanagedialog.cpp
Show All 15 Lines | |||||
16 | * along with this library; see the file COPYING.LIB. If not, write to | 16 | * along with this library; see the file COPYING.LIB. If not, write to | ||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "katesessionmanagedialog.h" | 21 | #include "katesessionmanagedialog.h" | ||
22 | 22 | | |||
23 | #include "kateapp.h" | 23 | #include "kateapp.h" | ||
24 | #include "katesessionmanager.h" | | |||
25 | #include "katesessionchooseritem.h" | 24 | #include "katesessionchooseritem.h" | ||
25 | #include "katesessionmanager.h" | ||||
26 | 26 | | |||
27 | #include <KColorScheme> | ||||
28 | #include <KConfigGroup> | ||||
27 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
28 | #include <KMessageBox> | 30 | #include <KMessageBox> | ||
31 | #include <KSharedConfig> | ||||
29 | #include <KStandardGuiItem> | 32 | #include <KStandardGuiItem> | ||
30 | 33 | | |||
31 | #include <QApplication> | | |||
32 | #include <QDialogButtonBox> | | |||
33 | #include <QFile> | | |||
34 | #include <QInputDialog> | 34 | #include <QInputDialog> | ||
35 | #include <QPushButton> | | |||
36 | #include <QTreeWidget> | | |||
37 | #include <QVBoxLayout> | | |||
38 | 35 | | |||
39 | KateSessionManageDialog::KateSessionManageDialog(QWidget *parent) | 36 | KateSessionManageDialog::KateSessionManageDialog(QWidget *parent) | ||
40 | : QDialog(parent) | 37 | : QDialog(parent) | ||
41 | { | 38 | { | ||
39 | setupUi(this); | ||||
42 | setWindowTitle(i18n("Manage Sessions")); | 40 | setWindowTitle(i18n("Manage Sessions")); | ||
41 | m_dontAskCheckBox->hide(); | ||||
43 | 42 | | |||
44 | QVBoxLayout *mainLayout = new QVBoxLayout(this); | 43 | m_sessionList->installEventFilter(this); | ||
45 | setLayout(mainLayout); | 44 | connect(m_sessionList, &QTreeWidget::currentItemChanged, this, &KateSessionManageDialog::selectionChanged); | ||
45 | connect(m_sessionList, &QTreeWidget::itemDoubleClicked, this, &KateSessionManageDialog::openSession); | ||||
46 | m_sessionList->header()->moveSection(0, 1); // Re-order columns to "Files, Sessions" | ||||
46 | 47 | | |||
47 | QHBoxLayout *hb = new QHBoxLayout(); | 48 | m_filterBox->installEventFilter(this); | ||
48 | mainLayout->addLayout(hb); | 49 | connect(m_filterBox, &QLineEdit::textChanged, this, &KateSessionManageDialog::filterChanged); | ||
50 | connect(m_sortButton, &QPushButton::clicked, this, &KateSessionManageDialog::changeSortOrder); | ||||
49 | 51 | | |||
50 | m_sessions = new QTreeWidget(this); | 52 | connect(m_newButton, &QPushButton::clicked, this, &KateSessionManageDialog::openNewSession); | ||
51 | m_sessions->setMinimumSize(400, 200); | | |||
52 | hb->addWidget(m_sessions); | | |||
53 | m_sessions->setColumnCount(2); | | |||
54 | QStringList header; | | |||
55 | header << i18n("Session Name"); | | |||
56 | header << i18nc("The number of open documents", "Open Documents"); | | |||
57 | m_sessions->setHeaderLabels(header); | | |||
58 | m_sessions->setRootIsDecorated(false); | | |||
59 | m_sessions->setItemsExpandable(false); | | |||
60 | m_sessions->setAllColumnsShowFocus(true); | | |||
61 | m_sessions->setSelectionBehavior(QAbstractItemView::SelectRows); | | |||
62 | m_sessions->setSelectionMode(QAbstractItemView::SingleSelection); | | |||
63 | 53 | | |||
64 | connect(m_sessions, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(selectionChanged(QTreeWidgetItem*,QTreeWidgetItem*))); | 54 | KGuiItem::assign(m_openButton, KStandardGuiItem::open()); | ||
55 | m_openButton->setDefault(true); | ||||
56 | connect(m_openButton, &QPushButton::clicked, this, &KateSessionManageDialog::openSession); | ||||
65 | 57 | | |||
66 | updateSessionList(); | 58 | connect(m_templateButton, &QPushButton::clicked, this, &KateSessionManageDialog::openSessionAsTemplate); | ||
67 | m_sessions->resizeColumnToContents(0); | 59 | | ||
60 | connect(m_copyButton, &QPushButton::clicked, this, &KateSessionManageDialog::copySession); | ||||
61 | | ||||
62 | connect(m_renameButton, &QPushButton::clicked, this, &KateSessionManageDialog::editBegin); | ||||
63 | | ||||
anthonyfieroni: Especially this comments should go away. | |||||
64 | connect(m_deleteButton, &QPushButton::clicked, this, &KateSessionManageDialog::updateDeleteList); | ||||
65 | | ||||
66 | KGuiItem::assign(m_closeButton, KStandardGuiItem::close()); | ||||
67 | connect(m_closeButton, &QPushButton::clicked, this, &KateSessionManageDialog::closeDialog); | ||||
68 | | ||||
69 | connect(KateApp::self()->sessionManager(), &KateSessionManager::sessionListChanged, this, &KateSessionManageDialog::updateSessionList); | ||||
70 | | ||||
71 | changeSortOrder(); // Set order to SortAlphabetical, set button text and fill session list | ||||
72 | } | ||||
68 | 73 | | |||
69 | // right column buttons | | |||
70 | QDialogButtonBox *rightButtons = new QDialogButtonBox(this); | | |||
71 | rightButtons->setOrientation(Qt::Vertical); | | |||
72 | hb->addWidget(rightButtons); | | |||
73 | | ||||
74 | m_rename = new QPushButton(i18n("&Rename...")); | | |||
75 | connect(m_rename, SIGNAL(clicked()), this, SLOT(rename())); | | |||
76 | rightButtons->addButton(m_rename, QDialogButtonBox::ApplyRole); | | |||
77 | | ||||
78 | m_del = new QPushButton(); | | |||
79 | KGuiItem::assign(m_del, KStandardGuiItem::del()); | | |||
80 | connect(m_del, SIGNAL(clicked()), this, SLOT(del())); | | |||
81 | rightButtons->addButton(m_del, QDialogButtonBox::ApplyRole); | | |||
82 | | ||||
83 | // dialog buttons | | |||
84 | QDialogButtonBox *bottomButtons = new QDialogButtonBox(this); | | |||
85 | mainLayout->addWidget(bottomButtons); | | |||
86 | | ||||
87 | QPushButton *closeButton = new QPushButton; | | |||
88 | KGuiItem::assign(closeButton, KStandardGuiItem::close()); | | |||
89 | closeButton->setDefault(true); | | |||
90 | bottomButtons->addButton(closeButton, QDialogButtonBox::RejectRole); | | |||
91 | connect(closeButton, SIGNAL(clicked()), this, SLOT(slotClose())); | | |||
92 | | ||||
93 | m_openButton = new QPushButton(QIcon::fromTheme(QStringLiteral("document-open")), i18n("&Open")); | | |||
94 | bottomButtons->addButton(m_openButton, QDialogButtonBox::AcceptRole); | | |||
95 | connect(m_openButton, SIGNAL(clicked()), this, SLOT(open())); | | |||
96 | 74 | | |||
97 | // trigger action update | 75 | KateSessionManageDialog::KateSessionManageDialog(QWidget *parent, const QString &lastSession) | ||
98 | selectionChanged(nullptr, nullptr); | 76 | : KateSessionManageDialog(parent) | ||
77 | { | ||||
78 | setWindowTitle(i18n("Session Chooser")); | ||||
79 | m_dontAskCheckBox->show(); | ||||
80 | m_chooserMode = true; | ||||
81 | connect(m_dontAskCheckBox, &QCheckBox::toggled, this, &KateSessionManageDialog::dontAskToggled); | ||||
82 | | ||||
83 | m_prefferedSession = lastSession; | ||||
84 | changeSortOrder(); // Set order to SortChronological | ||||
99 | } | 85 | } | ||
100 | 86 | | |||
87 | | ||||
101 | KateSessionManageDialog::~KateSessionManageDialog() | 88 | KateSessionManageDialog::~KateSessionManageDialog() | ||
102 | {} | 89 | {} | ||
103 | 90 | | |||
104 | void KateSessionManageDialog::slotClose() | 91 | | ||
92 | void KateSessionManageDialog::dontAskToggled() | ||||
105 | { | 93 | { | ||
106 | done(0); | 94 | m_templateButton->setEnabled(!m_dontAskCheckBox->isChecked()); | ||
107 | } | 95 | } | ||
108 | 96 | | |||
109 | void KateSessionManageDialog::selectionChanged(QTreeWidgetItem *current, QTreeWidgetItem *) | 97 | | ||
98 | void KateSessionManageDialog::changeSortOrder() | ||||
110 | { | 99 | { | ||
111 | const bool validItem = (current != nullptr); | 100 | switch (m_sortOrder) { | ||
101 | case SortAlphabetical: | ||||
102 | m_sortOrder = SortChronological; | ||||
103 | m_sortButton->setText(i18n("Sort Alpabetical")); | ||||
104 | //m_sortButton->setIcon(QIcon::fromTheme(QStringLiteral("FIXME"))); | ||||
105 | break; | ||||
106 | case SortChronological: | ||||
107 | m_sortOrder = SortAlphabetical; | ||||
108 | m_sortButton->setText(i18n("Sort Last Used")); | ||||
109 | //m_sortButton->setIcon(QIcon::fromTheme(QStringLiteral("FIXME"))); | ||||
anthonyfieroni: Debug messages also go out. It's kind of info before you ship it. | |||||
110 | break; | ||||
111 | } | ||||
112 | 112 | | |||
113 | m_rename->setEnabled(validItem); | 113 | updateSessionList(); | ||
114 | m_del->setEnabled(validItem && (static_cast<KateSessionChooserItem *>(current))->session != KateApp::self()->sessionManager()->activeSession()); | | |||
115 | m_openButton->setEnabled(true); | | |||
116 | } | 114 | } | ||
117 | 115 | | |||
118 | void KateSessionManageDialog::rename() | 116 | | ||
117 | void KateSessionManageDialog::filterChanged() | ||||
119 | { | 118 | { | ||
120 | KateSessionChooserItem *item = static_cast<KateSessionChooserItem *>(m_sessions->currentItem()); | 119 | static QPointer<QTimer> delay; | ||
121 | 120 | | |||
122 | if (!item) { | 121 | if (!delay) { | ||
122 | delay = new QTimer(this); // Should be auto cleard by Qt when we die | ||||
123 | delay->setSingleShot(true); | ||||
124 | delay->setInterval(400); | ||||
125 | connect(delay, &QTimer::timeout, this, &KateSessionManageDialog::updateSessionList); | ||||
126 | } | ||||
127 | | ||||
128 | delay->start(); | ||||
129 | } | ||||
130 | | ||||
131 | | ||||
132 | void KateSessionManageDialog::done(int result) | ||||
133 | { | ||||
134 | for (auto session : qAsConst(m_deleteList)) { | ||||
135 | KateApp::self()->sessionManager()->deleteSession(session); | ||||
136 | } | ||||
137 | m_deleteList.clear(); // May not needed, but anyway | ||||
138 | | ||||
139 | if (ResultQuit == result) { | ||||
140 | QDialog::done(0); | ||||
123 | return; | 141 | return; | ||
124 | } | 142 | } | ||
125 | 143 | | |||
126 | bool ok = false; | 144 | if (m_chooserMode && m_dontAskCheckBox->isChecked()) { | ||
127 | QString name = QInputDialog::getText(QApplication::activeWindow(), // nasty trick:) | 145 | // write back our nice boolean :) | ||
128 | i18n("Specify New Name for Session"), i18n("Session name:"), | 146 | KConfigGroup generalConfig(KSharedConfig::openConfig(), QStringLiteral("General")); | ||
129 | QLineEdit::Normal, item->session->name(), &ok); | 147 | switch (result) { | ||
148 | case ResultOpen: | ||||
149 | generalConfig.writeEntry("Startup Session", "last"); | ||||
150 | break; | ||||
151 | case ResultNew: | ||||
152 | generalConfig.writeEntry("Startup Session", "new"); | ||||
153 | break; | ||||
154 | default: | ||||
155 | break; | ||||
156 | } | ||||
157 | generalConfig.sync(); | ||||
158 | } | ||||
159 | | ||||
160 | QDialog::done(1); | ||||
161 | } | ||||
162 | | ||||
130 | 163 | | |||
131 | if (!ok) { | 164 | void KateSessionManageDialog::selectionChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) | ||
165 | { | ||||
166 | Q_UNUSED(previous); | ||||
167 | | ||||
168 | if (m_editByUser) { | ||||
169 | editDone(); // Field was left unchanged, no need to apply | ||||
132 | return; | 170 | return; | ||
133 | } | 171 | } | ||
134 | 172 | | |||
135 | if (name.isEmpty()) { | 173 | if (!current) { | ||
136 | KMessageBox::sorry(this, i18n("To save a session, you must specify a name."), i18n("Missing Session Name")); | 174 | m_openButton->setEnabled(false); | ||
175 | m_templateButton->setEnabled(false); | ||||
176 | m_copyButton->setEnabled(false); | ||||
177 | m_renameButton->setEnabled(false); | ||||
178 | m_deleteButton->setEnabled(false); | ||||
137 | return; | 179 | return; | ||
138 | } | 180 | } | ||
139 | 181 | | |||
140 | if (KateApp::self()->sessionManager()->renameSession(item->session, name)) { | 182 | const KateSession::Ptr activeSession = KateApp::self()->sessionManager()->activeSession(); | ||
141 | updateSessionList(); | 183 | const bool notActiveSession = !KateApp::self()->sessionManager()->sessionIsActive(currentSelectedSession()->name()); | ||
184 | | ||||
185 | m_deleteButton->setEnabled(notActiveSession); | ||||
186 | | ||||
187 | if (m_deleteList.contains(currentSelectedSession())) { | ||||
188 | m_deleteButton->setText(i18n("Restore")); | ||||
189 | m_openButton->setEnabled(false); | ||||
190 | m_templateButton->setEnabled(false); | ||||
191 | m_copyButton->setEnabled(true); // Looks a little strange but is OK | ||||
192 | m_renameButton->setEnabled(false); | ||||
193 | } else { | ||||
194 | KGuiItem::assign(m_deleteButton, KStandardGuiItem::del()); | ||||
195 | m_openButton->setEnabled(currentSelectedSession() != activeSession); | ||||
196 | m_templateButton->setEnabled(true); | ||||
197 | m_copyButton->setEnabled(true); | ||||
198 | m_renameButton->setEnabled(true); | ||||
199 | } | ||||
142 | } | 200 | } | ||
201 | | ||||
202 | | ||||
203 | void KateSessionManageDialog::disableButtons() | ||||
204 | { | ||||
205 | m_openButton->setEnabled(false); | ||||
206 | m_newButton->setEnabled(false); | ||||
207 | m_templateButton->setEnabled(false); | ||||
208 | m_dontAskCheckBox->setEnabled(false); | ||||
209 | m_copyButton->setEnabled(false); | ||||
210 | m_renameButton->setEnabled(false); | ||||
211 | m_deleteButton->setEnabled(false); | ||||
212 | m_closeButton->setEnabled(false); | ||||
213 | m_sortButton->setEnabled(false); | ||||
214 | m_filterBox->setEnabled(false); | ||||
143 | } | 215 | } | ||
144 | 216 | | |||
145 | void KateSessionManageDialog::del() | 217 | | ||
218 | void KateSessionManageDialog::editBegin() | ||||
146 | { | 219 | { | ||
147 | KateSessionChooserItem *item = static_cast<KateSessionChooserItem *>(m_sessions->currentItem()); | 220 | if (m_editByUser) { | ||
221 | return; | ||||
222 | } | ||||
223 | | ||||
224 | KateSessionChooserItem *item = currentSessionItem(); | ||||
148 | 225 | | |||
149 | if (!item) { | 226 | if (!item) { | ||
150 | return; | 227 | return; | ||
151 | } | 228 | } | ||
152 | 229 | | |||
153 | KateApp::self()->sessionManager()->deleteSession(item->session); | 230 | disableButtons(); | ||
231 | | ||||
232 | item->setFlags(item->flags() | Qt::ItemIsEditable); | ||||
233 | m_sessionList->clearSelection(); | ||||
234 | m_sessionList->editItem(item, 0); | ||||
235 | | ||||
236 | // Always apply changes user did, like Dolphin | ||||
237 | connect(m_sessionList, &QTreeWidget::itemChanged, this, &KateSessionManageDialog::editApply); | ||||
238 | connect(m_sessionList->itemWidget(item, 0), &QObject::destroyed, this, &KateSessionManageDialog::editApply); | ||||
239 | | ||||
240 | m_editByUser = item; // Do it last to block eventFilter() actions until we are ready | ||||
241 | } | ||||
242 | | ||||
243 | | ||||
244 | void KateSessionManageDialog::editDone() | ||||
245 | { | ||||
246 | m_editByUser = nullptr; | ||||
247 | disconnect(m_sessionList, &QTreeWidget::itemChanged, this, &KateSessionManageDialog::editApply); | ||||
154 | updateSessionList(); | 248 | updateSessionList(); | ||
249 | | ||||
250 | m_newButton->setEnabled(true); | ||||
251 | m_dontAskCheckBox->setEnabled(true); | ||||
252 | m_closeButton->setEnabled(true); | ||||
253 | m_sortButton->setEnabled(true); | ||||
254 | m_filterBox->setEnabled(true); | ||||
255 | | ||||
256 | m_sessionList->setFocus(); | ||||
257 | } | ||||
258 | | ||||
259 | | ||||
260 | void KateSessionManageDialog::editApply() | ||||
261 | { | ||||
262 | if (!m_editByUser) { | ||||
263 | return; | ||||
264 | } | ||||
265 | | ||||
266 | KateApp::self()->sessionManager()->renameSession(m_editByUser->session, m_editByUser->text(0)); | ||||
267 | editDone(); | ||||
268 | } | ||||
269 | | ||||
270 | | ||||
271 | void KateSessionManageDialog::copySession() | ||||
272 | { | ||||
273 | KateSessionChooserItem *item = currentSessionItem(); | ||||
274 | | ||||
275 | if (!item) { | ||||
276 | return; | ||||
277 | } | ||||
278 | | ||||
279 | m_prefferedSession = KateApp::self()->sessionManager()->copySession(item->session); | ||||
280 | m_sessionList->setFocus(); // Only needed when user abort | ||||
155 | } | 281 | } | ||
156 | 282 | | |||
157 | void KateSessionManageDialog::open() | 283 | | ||
284 | void KateSessionManageDialog::openSession() | ||||
158 | { | 285 | { | ||
159 | KateSessionChooserItem *item = static_cast<KateSessionChooserItem *>(m_sessions->currentItem()); | 286 | KateSessionChooserItem *item = currentSessionItem(); | ||
160 | 287 | | |||
161 | if (!item) { | 288 | if (!item) { | ||
162 | return; | 289 | return; | ||
163 | } | 290 | } | ||
164 | 291 | | |||
165 | hide(); | 292 | hide(); | ||
166 | KateApp::self()->sessionManager()->activateSession(item->session); | 293 | KateApp::self()->sessionManager()->activateSession(item->session); | ||
167 | done(0); | 294 | done(ResultOpen); | ||
295 | } | ||||
296 | | ||||
297 | | ||||
298 | void KateSessionManageDialog::openSessionAsTemplate() | ||||
299 | { | ||||
300 | KateSessionChooserItem *item = currentSessionItem(); | ||||
301 | | ||||
302 | if (!item) { | ||||
303 | return; | ||||
168 | } | 304 | } | ||
169 | 305 | | |||
306 | hide(); | ||||
307 | | ||||
308 | KateSessionManager *sm = KateApp::self()->sessionManager(); | ||||
309 | KateSession::Ptr ns = KateSession::createAnonymousFrom(item->session, sm->anonymousSessionFile()); | ||||
310 | sm->activateSession(ns); | ||||
311 | | ||||
312 | done(ResultOpen); | ||||
313 | } | ||||
314 | | ||||
315 | | ||||
316 | void KateSessionManageDialog::openNewSession() | ||||
317 | { | ||||
318 | hide(); | ||||
319 | KateApp::self()->sessionManager()->sessionNew(); | ||||
320 | done(ResultNew); | ||||
321 | } | ||||
322 | | ||||
323 | | ||||
324 | void KateSessionManageDialog::updateDeleteList() | ||||
325 | { | ||||
326 | KateSessionChooserItem *item = currentSessionItem(); | ||||
327 | | ||||
328 | if (!item) { | ||||
329 | return; | ||||
330 | } | ||||
331 | | ||||
332 | const KateSession::Ptr session = item->session; | ||||
333 | if (m_deleteList.contains(session)) { | ||||
334 | m_deleteList.remove(session); | ||||
335 | item->setForeground(0, QBrush(KColorScheme(QPalette::Active).foreground(KColorScheme::NormalText).color())); | ||||
336 | item->setIcon(0, QIcon()); | ||||
337 | item->setToolTip(0, QString()); | ||||
338 | } else { | ||||
339 | m_deleteList.insert(session); | ||||
340 | markItemAsToBeDeleted(item); | ||||
341 | } | ||||
342 | | ||||
343 | // To ease multiple deletions, move the selection | ||||
344 | QTreeWidgetItem *newItem = m_sessionList->itemBelow(item) ? m_sessionList->itemBelow(item) : m_sessionList->topLevelItem(0); | ||||
345 | m_sessionList->setCurrentItem(newItem); | ||||
346 | m_sessionList->setFocus(); | ||||
347 | } | ||||
348 | | ||||
349 | | ||||
350 | void KateSessionManageDialog::markItemAsToBeDeleted(QTreeWidgetItem *item) | ||||
351 | { | ||||
352 | item->setForeground(0, QBrush(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText).color())); | ||||
353 | item->setIcon(0, QIcon::fromTheme(QStringLiteral("emblem-warning"))); | ||||
354 | item->setToolTip(0, i18n("Session will be deleted on dialog close")); | ||||
355 | } | ||||
356 | | ||||
357 | | ||||
358 | void KateSessionManageDialog::closeDialog() | ||||
359 | { | ||||
360 | done(ResultQuit); | ||||
361 | } | ||||
362 | | ||||
363 | | ||||
170 | void KateSessionManageDialog::updateSessionList() | 364 | void KateSessionManageDialog::updateSessionList() | ||
171 | { | 365 | { | ||
172 | m_sessions->clear(); | 366 | if (m_editByUser) { | ||
367 | // Don't crash accidentally an ongoing edit | ||||
368 | return; | ||||
369 | } | ||||
370 | | ||||
371 | KateSession::Ptr currSelSession = currentSelectedSession(); | ||||
372 | KateSession::Ptr activeSession = KateApp::self()->sessionManager()->activeSession(); | ||||
373 | | ||||
374 | m_sessionList->clear(); | ||||
173 | 375 | | |||
174 | KateSessionList slist = KateApp::self()->sessionManager()->sessionList(); | 376 | KateSessionList slist = KateApp::self()->sessionManager()->sessionList(); | ||
175 | qSort(slist.begin(), slist.end(), KateSession::compareByName); | 377 | switch (m_sortOrder) { | ||
378 | case SortAlphabetical: std::sort (slist.begin(), slist.end(), KateSession::compareByName); break; | ||||
379 | case SortChronological: std::sort (slist.begin(), slist.end(), KateSession::compareByTimeDesc); break; | ||||
380 | } | ||||
381 | | ||||
382 | KateSessionChooserItem *prefferedItem = nullptr; | ||||
383 | KateSessionChooserItem *currSessionItem = nullptr; | ||||
384 | KateSessionChooserItem *activeSessionItem= nullptr; | ||||
385 | | ||||
386 | for (const KateSession::Ptr &session : qAsConst(slist)) { | ||||
387 | if (!m_filterBox->text().isEmpty()) { | ||||
388 | if (!session->name().contains(m_filterBox->text(), Qt::CaseInsensitive)) { | ||||
389 | continue; | ||||
390 | } | ||||
391 | } | ||||
176 | 392 | | |||
177 | foreach(const KateSession::Ptr & session, slist) { | 393 | KateSessionChooserItem *item = new KateSessionChooserItem(m_sessionList, session); | ||
178 | new KateSessionChooserItem(m_sessions, session); | 394 | if (session == currSelSession) { | ||
395 | currSessionItem = item; | ||||
396 | } else if (session == activeSession) { | ||||
397 | activeSessionItem = item; | ||||
398 | } else if (session->name() == m_prefferedSession) { | ||||
399 | prefferedItem = item; | ||||
400 | m_prefferedSession.clear(); | ||||
179 | } | 401 | } | ||
402 | | ||||
403 | if (m_deleteList.contains(session)) { | ||||
404 | markItemAsToBeDeleted(item); | ||||
180 | } | 405 | } | ||
406 | } | ||||
407 | | ||||
408 | m_sessionList->resizeColumnToContents(1); // Minimize "Files" column | ||||
181 | 409 | | |||
410 | if (!prefferedItem) { | ||||
411 | prefferedItem = currSessionItem ? currSessionItem : activeSessionItem; | ||||
412 | } | ||||
413 | | ||||
414 | if (prefferedItem) { | ||||
415 | m_sessionList->setCurrentItem(prefferedItem); | ||||
416 | m_sessionList->scrollToItem(prefferedItem); | ||||
417 | } else if (m_sessionList->topLevelItemCount() > 0) { | ||||
418 | m_sessionList->setCurrentItem(m_sessionList->topLevelItem(0)); | ||||
419 | } | ||||
420 | | ||||
421 | if (m_filterBox->hasFocus()){ | ||||
422 | return; | ||||
423 | } | ||||
424 | | ||||
425 | if (m_sessionList->topLevelItemCount() == 0) { | ||||
426 | m_newButton->setFocus(); | ||||
427 | } else { | ||||
428 | m_sessionList->setFocus(); | ||||
429 | } | ||||
430 | } | ||||
431 | | ||||
432 | | ||||
433 | KateSessionChooserItem *KateSessionManageDialog::currentSessionItem() const | ||||
434 | { | ||||
435 | return static_cast<KateSessionChooserItem *>(m_sessionList->currentItem()); | ||||
436 | } | ||||
437 | | ||||
438 | | ||||
439 | KateSession::Ptr KateSessionManageDialog::currentSelectedSession() const | ||||
440 | { | ||||
441 | KateSessionChooserItem *item = currentSessionItem(); | ||||
442 | | ||||
443 | if (!item) { | ||||
444 | return KateSession::Ptr(); | ||||
445 | } | ||||
446 | | ||||
447 | return item->session; | ||||
448 | } | ||||
449 | | ||||
450 | | ||||
451 | bool KateSessionManageDialog::eventFilter(QObject *object, QEvent *event) | ||||
452 | { | ||||
453 | QKeyEvent *ke = static_cast<QKeyEvent*>(event); | ||||
454 | | ||||
455 | if (object == m_sessionList) { | ||||
456 | if (!m_editByUser) { // No need for further action | ||||
457 | return false; | ||||
458 | } | ||||
459 | | ||||
460 | if (event->type() == QEvent::KeyPress) { | ||||
461 | switch (ke->key()) { | ||||
462 | // Avoid to apply changes with untypical keys/don't left edit field this way | ||||
463 | case Qt::Key_Up : | ||||
464 | case Qt::Key_Down : | ||||
465 | case Qt::Key_PageUp : | ||||
466 | case Qt::Key_PageDown : | ||||
467 | return true; | ||||
468 | default: | ||||
469 | break; | ||||
470 | } | ||||
471 | | ||||
472 | } else if (event->type() == QEvent::KeyRelease) { | ||||
473 | switch (ke->key()) { | ||||
474 | case Qt::Key_Escape : | ||||
475 | editDone(); // Abort edit | ||||
476 | break; | ||||
477 | case Qt::Key_Return : | ||||
478 | editApply(); | ||||
479 | break; | ||||
480 | default: | ||||
481 | break; | ||||
482 | } | ||||
483 | } | ||||
484 | | ||||
485 | } else if (object == m_filterBox) { | ||||
486 | // Catch Return key to avoid to finish the dialog | ||||
487 | if (event->type() == QEvent::KeyPress && (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter)) { | ||||
488 | updateSessionList(); | ||||
anthonyfieroni: Also don't commit commented code. | |||||
489 | m_sessionList->setFocus(); | ||||
490 | return true; | ||||
491 | } | ||||
492 | } | ||||
493 | | ||||
494 | return false; | ||||
495 | } | ||||
496 | | ||||
497 | | ||||
498 | void KateSessionManageDialog::closeEvent(QCloseEvent *event) | ||||
499 | { | ||||
500 | Q_UNUSED(event); | ||||
501 | | ||||
502 | if (m_editByUser) { | ||||
503 | // We must catch closeEvent here due to connected signal of QLineEdit::destroyed->editApply()->crash! | ||||
504 | editDone(); // editApply() don't work, m_editByUser->text(0) will not updated from QLineEdit | ||||
505 | } | ||||
506 | } |
Especially this comments should go away.