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

Method contextMenuExtension

plugins/externalscript/externalscriptplugin.cpp:180–256  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180KDevelop::ContextMenuExtension ExternalScriptPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent)
181{
182 m_urls.clear();
183
184 int folderCount = 0;
185
186 if (context->type() == KDevelop::Context::FileContext) {
187 auto* filectx = static_cast<KDevelop::FileContext*>(context);
188 m_urls = filectx->urls();
189 } else if (context->type() == KDevelop::Context::ProjectItemContext) {
190 auto* projctx = static_cast<KDevelop::ProjectItemContext*>(context);
191 const auto items = projctx->items();
192 for (KDevelop::ProjectBaseItem* item : items) {
193 if (item->file()) {
194 m_urls << item->file()->path().toUrl();
195 } else if (item->folder()) {
196 m_urls << item->folder()->path().toUrl();
197 folderCount++;
198 }
199 }
200 } else if (context->type() == KDevelop::Context::EditorContext) {
201 auto* econtext = static_cast<KDevelop::EditorContext*>(context);
202 m_urls << econtext->url();
203 }
204
205 if (!m_urls.isEmpty()) {
206 KDevelop::ContextMenuExtension ext;
207 QMenu* menu = nullptr;
208
209 for (int row = 0; row < m_model->rowCount(); ++row) {
210 auto* item = dynamic_cast<ExternalScriptItem*>(m_model->item(row));
211 Q_ASSERT(item);
212
213 if (context->type() != KDevelop::Context::EditorContext) {
214 // filter scripts that depend on an opened document
215 // if the context menu was not requested inside the editor
216 if (item->performParameterReplacement() && item->command().contains(QLatin1String("%s"))) {
217 continue;
218 } else if (item->inputMode() == ExternalScriptItem::InputSelectionOrNone) {
219 continue;
220 }
221 }
222
223 if (folderCount == m_urls.count()) {
224 // when only folders filter items that don't have %d parameter (or another parameter)
225 if (item->performParameterReplacement() &&
226 (!item->command().contains(QLatin1String("%d")) ||
227 item->command().contains(QLatin1String("%s")) ||
228 item->command().contains(QLatin1String("%u")) ||
229 item->command().contains(QLatin1String("%f")) ||
230 item->command().contains(QLatin1String("%b")) ||
231 item->command().contains(QLatin1String("%n"))
232 )
233 ) {
234 continue;
235 }
236 }
237

Callers

nothing calls this directly

Calls 15

folderMethod · 0.80
inputModeMethod · 0.80
clearMethod · 0.45
typeMethod · 0.45
urlsMethod · 0.45
itemsMethod · 0.45
fileMethod · 0.45
toUrlMethod · 0.45
pathMethod · 0.45
urlMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected