Changeset View
Changeset View
Standalone View
Standalone View
kate/katequickopenmodel.cpp
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 76 | { | |||
---|---|---|---|---|---|
79 | const QList<KTextEditor::Document *> openDocs = KateApp::self()->documentManager()->documentList(); | 79 | const QList<KTextEditor::Document *> openDocs = KateApp::self()->documentManager()->documentList(); | ||
80 | const QStringList projectDocs = projectView ? projectView->property("projectFiles").toStringList() : QStringList(); | 80 | const QStringList projectDocs = projectView ? projectView->property("projectFiles").toStringList() : QStringList(); | ||
81 | 81 | | |||
82 | QVector<ModelEntry> allDocuments; | 82 | QVector<ModelEntry> allDocuments; | ||
83 | allDocuments.resize(sortedViews.size() + openDocs.size() + projectDocs.size()); | 83 | allDocuments.resize(sortedViews.size() + openDocs.size() + projectDocs.size()); | ||
84 | 84 | | |||
85 | for (auto *view : qAsConst(sortedViews)) { | 85 | for (auto *view : qAsConst(sortedViews)) { | ||
86 | auto doc = view->document(); | 86 | auto doc = view->document(); | ||
87 | allDocuments.push_back({ doc->documentName(), doc->url().toString(QUrl::NormalizePathSegments), false }); | 87 | allDocuments.push_back({ doc->documentName(), doc->url().toDisplayString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile), false }); | ||
88 | } | 88 | } | ||
89 | 89 | | |||
90 | QStringList openedUrls; | 90 | QStringList openedUrls; | ||
91 | openedUrls.reserve(openDocs.size()); | 91 | openedUrls.reserve(openDocs.size()); | ||
92 | for (auto *doc : qAsConst(openDocs)) { | 92 | for (auto *doc : qAsConst(openDocs)) { | ||
93 | const auto normalizedUrl = doc->url().toString(QUrl::NormalizePathSegments); | 93 | const auto normalizedUrl = doc->url().toString(QUrl::NormalizePathSegments | QUrl::PreferLocalFile); | ||
94 | allDocuments.push_back({ doc->documentName(), normalizedUrl, false }); | 94 | allDocuments.push_back({ doc->documentName(), normalizedUrl, false }); | ||
95 | openedUrls.push_back(normalizedUrl); | 95 | openedUrls.push_back(normalizedUrl); | ||
96 | } | 96 | } | ||
97 | 97 | | |||
98 | for (const auto& file : qAsConst(projectDocs)) { | 98 | for (const auto& file : qAsConst(projectDocs)) { | ||
99 | QFileInfo fi(file); | 99 | QFileInfo fi(file); | ||
100 | allDocuments.push_back({ fi.fileName(), QUrl::fromLocalFile(file).toString(QUrl::NormalizePathSegments), false }); | 100 | // example of file: "/home/user/projects/myfile.txt" which is consistent with QUrl::toDisplayString(QUrl::PreferLocalFile) | ||
101 | allDocuments.push_back({ fi.fileName(), file, false }); | ||||
101 | } | 102 | } | ||
102 | 103 | | |||
103 | /** Sort the arrays via Url. */ | 104 | /** Sort the arrays by filePath. */ | ||
104 | std::sort(std::begin(allDocuments), std::end(allDocuments), | 105 | std::sort(std::begin(allDocuments), std::end(allDocuments), | ||
105 | [](const ModelEntry& a, const ModelEntry& b) { | 106 | [](const ModelEntry& a, const ModelEntry& b) { | ||
106 | return a.filePath < b.filePath; | 107 | return a.filePath < b.filePath; | ||
107 | }); | 108 | }); | ||
108 | 109 | | |||
109 | /** remove Duplicates. */ | 110 | /** remove Duplicates. */ | ||
110 | allDocuments.erase( | 111 | allDocuments.erase( | ||
111 | std::unique(allDocuments.begin(), allDocuments.end(), | 112 | std::unique(allDocuments.begin(), allDocuments.end(), | ||
112 | [](const ModelEntry& a, const ModelEntry& b) { | 113 | [](const ModelEntry& a, const ModelEntry& b) { | ||
113 | return a.filePath == b.filePath; | 114 | return a.filePath == b.filePath; | ||
114 | }), | 115 | }), | ||
115 | std::end(allDocuments)); | 116 | std::end(allDocuments)); | ||
116 | 117 | | |||
117 | for(auto& doc : allDocuments) { | 118 | for (auto& doc : allDocuments) { | ||
118 | if (Q_UNLIKELY(openedUrls.indexOf(doc.filePath) != -1)) { | 119 | if (Q_UNLIKELY(openedUrls.indexOf(doc.filePath) != -1)) { | ||
119 | doc.bold = true; | 120 | doc.bold = true; | ||
120 | } | 121 | } | ||
121 | } | 122 | } | ||
122 | 123 | | |||
123 | /** sort the arrays via boldness (open or not */ | 124 | /** sort the arrays via boldness (open or not */ | ||
124 | std::sort(std::begin(allDocuments), std::end(allDocuments), | 125 | std::sort(std::begin(allDocuments), std::end(allDocuments), | ||
125 | [](const ModelEntry& a, const ModelEntry& b) { | 126 | [](const ModelEntry& a, const ModelEntry& b) { | ||
126 | return a.bold > b.bold; | 127 | return a.bold > b.bold; | ||
127 | }); | 128 | }); | ||
128 | 129 | | |||
129 | beginResetModel(); | 130 | beginResetModel(); | ||
130 | m_modelEntries = allDocuments; | 131 | m_modelEntries = allDocuments; | ||
131 | endResetModel(); | 132 | endResetModel(); | ||
132 | } | 133 | } |