| 88 | } |
| 89 | |
| 90 | ContextMenuExtension 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 | |
| 123 | void SwitchToBuddyPlugin::createActionsForMainWindow(Sublime::MainWindow* /*window*/, QString& xmlFile, KActionCollection& actions) |
| 124 | { |
nothing calls this directly
no test coverage detected