Changeset View
Changeset View
Standalone View
Standalone View
kate/session/katesessionmanagedialog.h
Show All 20 Lines | |||||
21 | #ifndef __KATE_SESSION_MANAGE_DIALOG_H__ | 21 | #ifndef __KATE_SESSION_MANAGE_DIALOG_H__ | ||
22 | #define __KATE_SESSION_MANAGE_DIALOG_H__ | 22 | #define __KATE_SESSION_MANAGE_DIALOG_H__ | ||
23 | 23 | | |||
24 | #include <QDialog> | 24 | #include <QDialog> | ||
25 | 25 | | |||
26 | class QPushButton; | 26 | class QPushButton; | ||
27 | class QTreeWidget; | 27 | class QTreeWidget; | ||
28 | class QTreeWidgetItem; | 28 | class QTreeWidgetItem; | ||
29 | class KateSessionChooserItem; | ||||
30 | | ||||
31 | #include "katesession.h" | ||||
32 | #include "ui_katesessionmanagedialog.h" | ||||
29 | 33 | | |||
30 | class KateSessionManageDialog : public QDialog | 34 | class KateSessionManageDialog : public QDialog | ||
35 | , public Ui::KateSessionManageDialogUi | ||||
31 | { | 36 | { | ||
32 | Q_OBJECT | 37 | Q_OBJECT | ||
33 | 38 | | |||
34 | public: | 39 | public: | ||
40 | /** | ||||
41 | * The normal ctor for manage mode | ||||
42 | */ | ||||
35 | KateSessionManageDialog(QWidget *parent); | 43 | KateSessionManageDialog(QWidget *parent); | ||
44 | | ||||
45 | /** | ||||
46 | * The special ctor for chooser mode | ||||
47 | * Set a differend window title, enables some extra widget and try to select | ||||
48 | * the @p lastSession in the session list. | ||||
49 | */ | ||||
50 | KateSessionManageDialog(QWidget *parent, const QString &lastSession); | ||||
36 | ~KateSessionManageDialog() override; | 51 | ~KateSessionManageDialog() override; | ||
37 | 52 | | |||
38 | protected Q_SLOTS: | 53 | protected Q_SLOTS: | ||
39 | /** | 54 | /** | ||
40 | * close pressed | 55 | * Re-implemented to save in chooser mode users choice when needed and to | ||
56 | * exit the dialog with a return code of @c 0/1 fitting to the code of | ||||
57 | * @p result to indicate that the user chose a session to open not. | ||||
58 | * @see KateSessionManager::chooseSession() | ||||
59 | * @param result has to be one of enum @c ResultCode | ||||
41 | */ | 60 | */ | ||
42 | void slotClose(); | 61 | void done(int result) override; | ||
43 | 62 | | |||
44 | /** | 63 | /** | ||
45 | * selection has changed | 64 | * To update the button states | ||
46 | */ | 65 | */ | ||
47 | void selectionChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); | 66 | void selectionChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); | ||
48 | 67 | | |||
49 | /** | 68 | /** | ||
50 | * try to rename session | 69 | * Close the dialog and open the selected session | ||
51 | */ | 70 | */ | ||
52 | void rename(); | 71 | void openSession(); | ||
53 | 72 | | |||
54 | /** | 73 | /** | ||
55 | * try to delete session | 74 | * Use the selected session as template for a new session | ||
56 | */ | 75 | */ | ||
57 | void del(); | 76 | void openSessionAsTemplate(); | ||
58 | 77 | | |||
59 | /** | 78 | /** | ||
60 | * close dialog and open the selected session | 79 | * Open new anonymous session | ||
61 | */ | 80 | */ | ||
62 | void open() override; | 81 | void openNewSession(); | ||
82 | | ||||
83 | /** | ||||
84 | * Copy the selected session | ||||
85 | */ | ||||
86 | void copySession(); | ||||
87 | | ||||
88 | /** | ||||
89 | * Try to rename the session hold by @c m_editByUser | ||||
90 | * @see editDone(), editBegin(), m_editByUser | ||||
91 | */ | ||||
92 | void editApply(); | ||||
93 | | ||||
94 | /** | ||||
95 | * Open the inline editor on the selected session, set @c m_editByUser to | ||||
96 | * the selected session and connect @c QTreeWidget::itemChanged signal to | ||||
97 | * @c editApply(). | ||||
98 | * @see editDone(), editApply(), m_editByUser | ||||
99 | */ | ||||
100 | void editBegin(); | ||||
101 | | ||||
102 | /** | ||||
103 | * Finish the edit process, reset intern settings. | ||||
104 | * Calling this function without to call @c editApply() will abort edit. | ||||
105 | */ | ||||
106 | void editDone(); | ||||
63 | 107 | | |||
64 | private: | | |||
65 | /** | 108 | /** | ||
66 | * update our list | 109 | * To close the dialog | ||
110 | */ | ||||
111 | void closeDialog(); | ||||
112 | | ||||
113 | /** | ||||
114 | * Slot for the delete button | ||||
115 | * @see m_deleteList, deleteSessions() | ||||
116 | */ | ||||
117 | void updateDeleteList(); | ||||
118 | | ||||
119 | /** | ||||
120 | * Update the list of sessions in @c m_sessionList and trigger some needed | ||||
121 | * actions belong to the editing of session names. | ||||
67 | */ | 122 | */ | ||
68 | void updateSessionList(); | 123 | void updateSessionList(); | ||
69 | 124 | | |||
125 | /** | ||||
126 | * To enable/disable not useful buttons | ||||
127 | */ | ||||
128 | void dontAskToggled(); | ||||
129 | | ||||
130 | /** | ||||
131 | * To change the sort order of the session list | ||||
132 | */ | ||||
133 | void changeSortOrder(); | ||||
134 | | ||||
135 | /** | ||||
136 | * Slot for @c m_filterField | ||||
137 | */ | ||||
138 | void filterChanged(); | ||||
139 | | ||||
70 | private: | 140 | private: | ||
71 | QTreeWidget *m_sessions; | 141 | /** | ||
72 | QPushButton *m_rename; | 142 | * Result codes used to call @c done() | ||
73 | QPushButton *m_del; | 143 | */ | ||
74 | QPushButton *m_openButton; | 144 | enum ResultCode { | ||
145 | ResultQuit = QDialog::Rejected, | ||||
146 | ResultOpen, | ||||
147 | ResultNew, | ||||
75 | }; | 148 | }; | ||
76 | 149 | | |||
77 | #endif | 150 | /** | ||
151 | * Sort order of the session list | ||||
152 | */ | ||||
153 | enum SortOrder { | ||||
154 | SortAlphabetical, | ||||
155 | SortChronological, | ||||
156 | }; | ||||
157 | | ||||
158 | /** | ||||
159 | * Re-implemented to avoid crash when in edit state | ||||
160 | */ | ||||
161 | void closeEvent(QCloseEvent *event) override; | ||||
78 | 162 | | |||
163 | /** | ||||
164 | * Disables all buttons on the "normal" button stack page and the close button | ||||
165 | */ | ||||
166 | void disableButtons(); | ||||
167 | | ||||
168 | /** | ||||
169 | * To handle the rename process | ||||
170 | */ | ||||
171 | bool eventFilter(QObject *object, QEvent *event) override; | ||||
172 | | ||||
173 | /** | ||||
174 | * @return current selected item in @c m_sessionList or @c nullptr | ||||
175 | */ | ||||
176 | KateSessionChooserItem *currentSessionItem() const; | ||||
177 | | ||||
178 | /** | ||||
179 | * @return current selected session in @c m_sessionList or empty @c KateSession::Ptr() | ||||
180 | */ | ||||
181 | KateSession::Ptr currentSelectedSession() const; | ||||
182 | | ||||
183 | /** | ||||
184 | * Display @p item in a striking way to indicate that the session represent | ||||
185 | * by @p item will be deleted | ||||
186 | */ | ||||
187 | void markItemAsToBeDeleted(QTreeWidgetItem *item); | ||||
188 | | ||||
189 | /** | ||||
190 | * The item which is currently edited by the user or @c nullptr to indicate | ||||
191 | * that nothing is on edit. | ||||
192 | */ | ||||
193 | KateSessionChooserItem *m_editByUser = nullptr; | ||||
194 | | ||||
195 | /** | ||||
196 | * Used by @c updateSessionList() to choose a new current item | ||||
197 | */ | ||||
198 | QString m_prefferedSession; | ||||
199 | | ||||
200 | /** | ||||
201 | * How the list of sessions has to be ordered | ||||
202 | */ | ||||
203 | int m_sortOrder = SortChronological; | ||||
dhaumann: I would prefer using the enum SortOrder here as type instead of an int. In fact, I would even… | |||||
204 | | ||||
205 | /** | ||||
206 | * Used in dtor to do some savings or not | ||||
207 | */ | ||||
208 | bool m_chooserMode = false; | ||||
209 | | ||||
210 | /** | ||||
211 | * Will filled with sessions to be deleted by @c updateDeleteList() and process | ||||
212 | * by @c deleteSessions() | ||||
213 | */ | ||||
214 | QSet<KateSession::Ptr> m_deleteList; | ||||
215 | }; | ||||
216 | | ||||
217 | #endif |
I would prefer using the enum SortOrder here as type instead of an int. In fact, I would even be in favor of an enum class SortOrder { Alphabetical, Chronological };