MCPcopy Create free account
hub / github.com/KDE/kdevelop / match

Method match

app/plasma/runner/kdevelopsessions.cpp:51–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void KDevelopSessions::match(KRunner::RunnerContext& context)
52{
53 QString term = context.query();
54 if (term.size() < 3) {
55 return;
56 }
57
58 bool listAll = false;
59 if (term.startsWith(QLatin1String("kdevelop"), Qt::CaseInsensitive)) {
60 const auto trimmedStrippedTerm = QStringView{term}.sliced(8).trimmed();
61 // "kdevelop" -> list all sessions
62 if (trimmedStrippedTerm.isEmpty()) {
63 listAll = true;
64 term.clear();
65 }
66 // "kdevelop X" -> list all sessions with "X"
67 else if (term.at(8) == QLatin1Char(' ') ) {
68 term = trimmedStrippedTerm.toString();
69 }
70 // "kdevelopX" -> list all sessions with "kdevelopX"
71 else {
72 term = term.trimmed();
73 }
74 }
75
76 if (term.isEmpty() && !listAll) {
77 return;
78 }
79
80 for (const auto& session : std::as_const(m_sessionDataList)) {
81 if (!context.isValid()) {
82 return;
83 }
84
85 if (listAll || (!term.isEmpty() && session.description.contains(term, Qt::CaseInsensitive))) {
86 KRunner::QueryMatch match(this);
87 if (listAll) {
88 // All sessions listed, but with a low priority
89 match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::Highest);
90 match.setRelevance(0.8);
91 } else {
92 if (session.description.compare(term, Qt::CaseInsensitive) == 0) {
93 // parameter to kdevelop matches session exactly, bump it up!
94 match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::Highest);
95 match.setRelevance(1.0);
96 } else {
97 // fuzzy match of the session in "kdevelop $session"
98 match.setCategoryRelevance(KRunner::QueryMatch::CategoryRelevance::Moderate);
99 match.setRelevance(0.8);
100 }
101 }
102 match.setIconName(QStringLiteral("kdevelop"));
103 match.setData(session.id);
104 match.setText(session.description);
105 match.setSubtext(i18n("Open KDevelop Session"));
106 context.addMatch(match);
107 }
108 }

Callers

nothing calls this directly

Calls 11

sizeMethod · 0.45
isEmptyMethod · 0.45
clearMethod · 0.45
atMethod · 0.45
toStringMethod · 0.45
isValidMethod · 0.45
containsMethod · 0.45
compareMethod · 0.45
setIconNameMethod · 0.45
setDataMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected