Changeset View
Changeset View
Standalone View
Standalone View
kate/katequickopen.cpp
Show First 20 Lines • Show All 157 Lines • ▼ Show 20 Line(s) | 146 | { | |||
---|---|---|---|---|---|
158 | QSet<QString> alreadySeenFiles; | 158 | QSet<QString> alreadySeenFiles; | ||
159 | QSet<KTextEditor::Document *> alreadySeenDocs; | 159 | QSet<KTextEditor::Document *> alreadySeenDocs; | ||
160 | 160 | | |||
161 | /** | 161 | /** | ||
162 | * get views in lru order | 162 | * get views in lru order | ||
163 | */ | 163 | */ | ||
164 | const QList<KTextEditor::View *> sortedViews(m_mainWindow->viewManager()->sortedViews()); | 164 | const QList<KTextEditor::View *> sortedViews(m_mainWindow->viewManager()->sortedViews()); | ||
165 | 165 | | |||
166 | auto prettyDocumentUrl = [](const QUrl & url) { | ||||
kfunk: Note: Is this any different to `url.toDisplayString(QUrl::PreferLocalFile)` now? | |||||
gregormi: Good idea, I used QUrl::PreferLocalFile in the revised code. | |||||
167 | if (!url.isEmpty() && url.isLocalFile()) { | ||||
168 | return url.toLocalFile(); | ||||
169 | } else { | ||||
170 | return url.toString(); | ||||
Prefer toDisplayString() for user-visible places which will strip out the password broulik: Prefer `toDisplayString()` for user-visible places which will strip out the password | |||||
171 | } | ||||
172 | }; | ||||
173 | | ||||
174 | auto addToAlreadySeen = [&alreadySeenFiles](KTextEditor::Document *doc) { | ||||
175 | if (!doc->url().isEmpty() && doc->url().isLocalFile()) { | ||||
176 | alreadySeenFiles.insert(doc->url().toLocalFile()); | ||||
177 | } | ||||
178 | }; | ||||
179 | | ||||
166 | /** | 180 | /** | ||
167 | * now insert them in order | 181 | * now insert them in order | ||
168 | */ | 182 | */ | ||
169 | QModelIndex idxToSelect; | 183 | QModelIndex idxToSelect; | ||
170 | int linecount = 0; | 184 | int linecount = 0; | ||
171 | foreach (KTextEditor::View *view, sortedViews) { | 185 | foreach (KTextEditor::View *view, sortedViews) { | ||
172 | KTextEditor::Document *doc = view->document(); | 186 | KTextEditor::Document *doc = view->document(); | ||
173 | 187 | | |||
174 | if (alreadySeenDocs.contains(doc)) { | 188 | if (alreadySeenDocs.contains(doc)) { | ||
175 | continue; | 189 | continue; | ||
176 | } | 190 | } | ||
177 | 191 | | |||
178 | alreadySeenDocs.insert(doc); | 192 | alreadySeenDocs.insert(doc); | ||
179 | 193 | | |||
180 | //QStandardItem *item=new QStandardItem(i18n("%1: %2",doc->documentName(),doc->url().toString())); | 194 | //QStandardItem *item=new QStandardItem(i18n("%1: %2",doc->documentName(),doc->url().toString())); | ||
181 | QStandardItem *itemName = new QStandardItem(doc->documentName()); | 195 | QStandardItem *itemName = new QStandardItem(doc->documentName()); | ||
182 | 196 | | |||
183 | itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole); | 197 | itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole); | ||
184 | itemName->setData(QString::fromLatin1("%1: %2").arg(doc->documentName()).arg(doc->url().toString()), SortFilterRole); | 198 | itemName->setData(QString::fromLatin1("%1: %2").arg(doc->documentName()).arg(doc->url().toString()), SortFilterRole); | ||
185 | itemName->setEditable(false); | 199 | itemName->setEditable(false); | ||
186 | QFont font = itemName->font(); | 200 | QFont font = itemName->font(); | ||
187 | font.setBold(true); | 201 | font.setBold(true); | ||
188 | itemName->setFont(font); | 202 | itemName->setFont(font); | ||
189 | 203 | | |||
190 | QStandardItem *itemUrl = new QStandardItem(doc->url().toString()); | 204 | QStandardItem *itemUrl = new QStandardItem(prettyDocumentUrl(doc->url())); | ||
191 | itemUrl->setEditable(false); | 205 | itemUrl->setEditable(false); | ||
192 | m_base_model->setItem(linecount, 0, itemName); | 206 | m_base_model->setItem(linecount, 0, itemName); | ||
193 | m_base_model->setItem(linecount, 1, itemUrl); | 207 | m_base_model->setItem(linecount, 1, itemUrl); | ||
194 | linecount++; | 208 | linecount++; | ||
195 | 209 | | |||
196 | if (!doc->url().isEmpty() && doc->url().isLocalFile()) { | 210 | addToAlreadySeen(doc); | ||
197 | alreadySeenFiles.insert(doc->url().toLocalFile()); | | |||
198 | } | | |||
199 | 211 | | |||
200 | // select second document, that is the last used (beside the active one) | 212 | // select second document, that is the last used (beside the active one) | ||
201 | if (linecount == 2) { | 213 | if (linecount == 2) { | ||
202 | idxToSelect = itemName->index(); | 214 | idxToSelect = itemName->index(); | ||
203 | } | 215 | } | ||
204 | } | 216 | } | ||
205 | 217 | | |||
206 | /** | 218 | /** | ||
207 | * get all open documents | 219 | * get all open documents | ||
208 | */ | 220 | */ | ||
209 | QList<KTextEditor::Document *> docs = KateApp::self()->documentManager()->documentList(); | 221 | QList<KTextEditor::Document *> docs = KateApp::self()->documentManager()->documentList(); | ||
210 | foreach(KTextEditor::Document * doc, docs) { | 222 | foreach(KTextEditor::Document * doc, docs) { | ||
211 | /** | 223 | /** | ||
212 | * skip docs already open | 224 | * skip docs already open | ||
213 | */ | 225 | */ | ||
214 | if (alreadySeenDocs.contains(doc)) { | 226 | if (alreadySeenDocs.contains(doc)) { | ||
215 | continue; | 227 | continue; | ||
216 | } | 228 | } | ||
217 | 229 | | |||
218 | //QStandardItem *item=new QStandardItem(i18n("%1: %2",doc->documentName(),doc->url().toString())); | | |||
219 | QStandardItem *itemName = new QStandardItem(doc->documentName()); | 230 | QStandardItem *itemName = new QStandardItem(doc->documentName()); | ||
220 | 231 | | |||
221 | itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole); | 232 | itemName->setData(qVariantFromValue(QPointer<KTextEditor::Document> (doc)), DocumentRole); | ||
222 | itemName->setData(QString::fromLatin1("%1: %2").arg(doc->documentName()).arg(doc->url().toString()), SortFilterRole); | 233 | itemName->setData(QString::fromLatin1("%1: %2").arg(doc->documentName()).arg(doc->url().toString()), SortFilterRole); | ||
223 | itemName->setEditable(false); | 234 | itemName->setEditable(false); | ||
224 | QFont font = itemName->font(); | 235 | QFont font = itemName->font(); | ||
225 | font.setBold(true); | 236 | font.setBold(true); | ||
226 | itemName->setFont(font); | 237 | itemName->setFont(font); | ||
227 | 238 | | |||
228 | QStandardItem *itemUrl = new QStandardItem(doc->url().toString()); | 239 | QStandardItem *itemUrl = new QStandardItem(prettyDocumentUrl(doc->url())); | ||
229 | itemUrl->setEditable(false); | 240 | itemUrl->setEditable(false); | ||
230 | m_base_model->setItem(linecount, 0, itemName); | 241 | m_base_model->setItem(linecount, 0, itemName); | ||
231 | m_base_model->setItem(linecount, 1, itemUrl); | 242 | m_base_model->setItem(linecount, 1, itemUrl); | ||
232 | linecount++; | 243 | linecount++; | ||
233 | 244 | | |||
234 | if (!doc->url().isEmpty() && doc->url().isLocalFile()) { | 245 | addToAlreadySeen(doc); | ||
235 | alreadySeenFiles.insert(doc->url().toLocalFile()); | | |||
236 | } | | |||
237 | } | 246 | } | ||
238 | 247 | | |||
239 | /** | 248 | /** | ||
240 | * insert all project files, if any project around | 249 | * insert all project files, if any project around | ||
241 | */ | 250 | */ | ||
242 | if (QObject *projectView = m_mainWindow->pluginView(QStringLiteral("kateprojectplugin"))) { | 251 | if (QObject *projectView = m_mainWindow->pluginView(QStringLiteral("kateprojectplugin"))) { | ||
243 | QStringList projectFiles = projectView->property("projectFiles").toStringList(); | 252 | QStringList projectFiles = projectView->property("projectFiles").toStringList(); | ||
244 | foreach(const QString & file, projectFiles) { | 253 | foreach(const QString & file, projectFiles) { | ||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |
Note: Is this any different to url.toDisplayString(QUrl::PreferLocalFile) now?