Changeset View
Changeset View
Standalone View
Standalone View
src/lib/repository.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 72 | for (const auto &def : qAsConst(d->m_sortedDefs)) | |||
---|---|---|---|---|---|
73 | DefinitionData::get(def)->repo = nullptr; | 73 | DefinitionData::get(def)->repo = nullptr; | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | Definition Repository::definitionForName(const QString& defName) const | 76 | Definition Repository::definitionForName(const QString& defName) const | ||
77 | { | 77 | { | ||
78 | return d->m_defs.value(defName); | 78 | return d->m_defs.value(defName); | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | static Definition bestCandidate(QVector<Definition>& candidates) | 81 | static Definition bestCandidate(QVector<Definition> &&candidates) | ||
82 | { | 82 | { | ||
83 | if (candidates.isEmpty()) | 83 | if (candidates.isEmpty()) | ||
84 | return Definition(); | 84 | return Definition(); | ||
85 | 85 | | |||
86 | std::partial_sort(candidates.begin(), candidates.begin() + 1, candidates.end(), [](const Definition &lhs, const Definition &rhs) { | 86 | std::partial_sort(candidates.begin(), candidates.begin() + 1, candidates.end(), [](const Definition &lhs, const Definition &rhs) { | ||
87 | return lhs.priority() > rhs.priority(); | 87 | return lhs.priority() > rhs.priority(); | ||
88 | }); | 88 | }); | ||
89 | 89 | | |||
90 | return candidates.at(0); | 90 | return candidates.at(0); | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | Definition Repository::definitionForFileName(const QString& fileName) const | 93 | Definition Repository::definitionForFileName(const QString& fileName) const | ||
94 | { | 94 | { | ||
95 | return bestCandidate(definitionsForFileName(fileName)); | ||||
96 | } | ||||
97 | | ||||
98 | QVector<Definition> Repository::definitionsForFileName(const QString &fileName) const | ||||
99 | { | ||||
95 | QFileInfo fi(fileName); | 100 | QFileInfo fi(fileName); | ||
96 | const auto name = fi.fileName(); | 101 | const auto name = fi.fileName(); | ||
97 | 102 | | |||
98 | QVector<Definition> candidates; | 103 | QVector<Definition> candidates; | ||
99 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | 104 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | ||
100 | auto def = it.value(); | 105 | auto def = it.value(); | ||
101 | for (const auto &pattern : def.extensions()) { | 106 | for (const auto &pattern : def.extensions()) { | ||
102 | if (WildcardMatcher::exactMatch(name, pattern)) { | 107 | if (WildcardMatcher::exactMatch(name, pattern)) { | ||
103 | candidates.push_back(def); | 108 | candidates.push_back(def); | ||
104 | break; | 109 | break; | ||
105 | } | 110 | } | ||
106 | } | 111 | } | ||
107 | } | 112 | } | ||
108 | 113 | | |||
109 | return bestCandidate(candidates); | 114 | return candidates; | ||
110 | } | 115 | } | ||
111 | 116 | | |||
112 | Definition Repository::definitionForMimeType(const QString& mimeType) const | 117 | Definition Repository::definitionForMimeType(const QString& mimeType) const | ||
113 | { | 118 | { | ||
119 | return bestCandidate(definitionsForMimeType(mimeType)); | ||||
120 | } | ||||
121 | | ||||
122 | QVector<Definition> Repository::definitionsForMimeType(const QString &mimeType) const | ||||
123 | { | ||||
114 | QVector<Definition> candidates; | 124 | QVector<Definition> candidates; | ||
115 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | 125 | for (auto it = d->m_defs.constBegin(); it != d->m_defs.constEnd(); ++it) { | ||
116 | auto def = it.value(); | 126 | auto def = it.value(); | ||
117 | for (const auto &matchType : def.mimeTypes()) { | 127 | for (const auto &matchType : def.mimeTypes()) { | ||
118 | if (mimeType == matchType) { | 128 | if (mimeType == matchType) { | ||
119 | candidates.push_back(def); | 129 | candidates.push_back(def); | ||
120 | break; | 130 | break; | ||
121 | } | 131 | } | ||
122 | } | 132 | } | ||
123 | } | 133 | } | ||
124 | 134 | return candidates; | |||
125 | return bestCandidate(candidates); | | |||
126 | } | 135 | } | ||
127 | 136 | | |||
128 | QVector<Definition> Repository::definitions() const | 137 | QVector<Definition> Repository::definitions() const | ||
129 | { | 138 | { | ||
130 | return d->m_sortedDefs; | 139 | return d->m_sortedDefs; | ||
131 | } | 140 | } | ||
132 | 141 | | |||
133 | QVector<Theme> Repository::themes() const | 142 | QVector<Theme> Repository::themes() const | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |