Changeset View
Changeset View
Standalone View
Standalone View
addons/tabswitcher/tabswitcherfilesmodel.cpp
Show All 15 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
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 "tabswitcherfilesmodel.h" | 21 | #include "tabswitcherfilesmodel.h" | ||
22 | 22 | | |||
23 | #include <QDebug> | 23 | #include <QDebug> | ||
24 | #include <QBrush> | ||||
24 | #include <QFileInfo> | 25 | #include <QFileInfo> | ||
26 | #include <QMimeDatabase> | ||||
27 | | ||||
28 | #include <KTextEditor/Document> | ||||
25 | 29 | | |||
26 | #include <algorithm> | 30 | #include <algorithm> | ||
27 | 31 | | |||
28 | namespace detail { | 32 | namespace detail | ||
33 | { | ||||
34 | static QIcon iconForDocument(KTextEditor::Document * doc) | ||||
35 | { | ||||
36 | return QIcon::fromTheme(QMimeDatabase().mimeTypeForUrl(doc->url()).iconName()); | ||||
37 | } | ||||
38 | | ||||
39 | FilenameListItem::FilenameListItem(KTextEditor::Document* doc) | ||||
40 | : document(doc) | ||||
41 | , icon(iconForDocument(doc)) | ||||
42 | , documentName(doc->documentName()) | ||||
43 | , fullPath(doc->url().toLocalFile()) | ||||
44 | { | ||||
45 | } | ||||
46 | | ||||
29 | /** | 47 | /** | ||
30 | * adapted from https://helloacm.com/c-coding-exercise-longest-common-prefix/ | 48 | * adapted from https://helloacm.com/c-coding-exercise-longest-common-prefix/ | ||
31 | * see also http://www.cplusplus.com/forum/beginner/83540/ | 49 | * see also http://www.cplusplus.com/forum/beginner/83540/ | ||
32 | * Note that if strs contains the empty string, the result will be "" | 50 | * Note that if strs contains the empty string, the result will be "" | ||
33 | */ | 51 | */ | ||
34 | QString longestCommonPrefix(std::vector<QString> const & strs) { | 52 | QString longestCommonPrefix(std::vector<QString> const & strs) { | ||
35 | int n = INT_MAX; | 53 | int n = INT_MAX; | ||
36 | if (strs.size() <= 0) { | 54 | if (strs.size() <= 0) { | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
94 | } | 112 | } | ||
95 | 113 | | |||
96 | detail::TabswitcherFilesModel::TabswitcherFilesModel(const FilenameList & data) | 114 | detail::TabswitcherFilesModel::TabswitcherFilesModel(const FilenameList & data) | ||
97 | { | 115 | { | ||
98 | data_ = data; | 116 | data_ = data; | ||
99 | post_process(data_); | 117 | post_process(data_); | ||
100 | } | 118 | } | ||
101 | 119 | | |||
102 | bool detail::TabswitcherFilesModel::insertRow(int row, FilenameListItem const * const item) | 120 | bool detail::TabswitcherFilesModel::insertRow(int row, const FilenameListItem & item) | ||
103 | { | 121 | { | ||
104 | beginInsertRows(QModelIndex(), row, row + 1); | 122 | beginInsertRows(QModelIndex(), row, row + 1); | ||
105 | data_.insert(data_.begin() + row, *item); | 123 | data_.insert(data_.begin() + row, item); | ||
106 | post_process(data_); | 124 | post_process(data_); | ||
107 | endInsertRows(); | 125 | endInsertRows(); | ||
108 | return true; | 126 | return true; | ||
109 | } | 127 | } | ||
110 | 128 | | |||
111 | bool detail::TabswitcherFilesModel::removeRow(int row) | 129 | bool detail::TabswitcherFilesModel::removeRow(int row) | ||
112 | { | 130 | { | ||
113 | if (data_.begin() + row == data_.end()) { | 131 | if (data_.begin() + row == data_.end()) { | ||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |