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

Method contextMenuExtension

plugins/switchtobuddy/switchtobuddyplugin.cpp:90–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90ContextMenuExtension SwitchToBuddyPlugin::contextMenuExtension(Context* context, QWidget* parent)
91{
92 auto* ctx = dynamic_cast<EditorContext*>(context);
93 if (!ctx) {
94 return ContextMenuExtension();
95 }
96
97 QUrl currentUrl = ctx->url();
98 IBuddyDocumentFinder* buddyFinder = IBuddyDocumentFinder::finderForMimeType(QMimeDatabase().mimeTypeForUrl(currentUrl).name());
99 if (!buddyFinder)
100 return ContextMenuExtension();
101
102 // Get all potential buddies for the current document and add a switch-to action
103 // for each buddy who really exists in the file system. Note: if no buddies could be calculated
104 // no extension actions are generated.
105 const QVector<QUrl>& potentialBuddies = buddyFinder->potentialBuddies(currentUrl);
106
107 ContextMenuExtension extension;
108
109 for (const QUrl& url : potentialBuddies) {
110 if (!QFile::exists(url.toLocalFile())) {
111 continue;
112 }
113
114 auto* action = new QAction(i18nc("@action:inmenu", "Switch to '%1'", url.fileName()), parent);
115 const QString surl = url.toLocalFile();
116 connect(action, &QAction::triggered, this, [this, surl](){ switchToBuddy(surl); }, Qt::QueuedConnection);
117 extension.addAction(ContextMenuExtension::NavigationGroup, action);
118 }
119
120 return extension;
121}
122
123void SwitchToBuddyPlugin::createActionsForMainWindow(Sublime::MainWindow* /*window*/, QString& xmlFile, KActionCollection& actions)
124{

Callers

nothing calls this directly

Calls 7

toLocalFileMethod · 0.80
urlMethod · 0.45
nameMethod · 0.45
potentialBuddiesMethod · 0.45
fileNameMethod · 0.45
addActionMethod · 0.45

Tested by

no test coverage detected