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

Method contextMenuExtension

plugins/grepview/grepviewplugin.cpp:124–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

122}
123
124KDevelop::ContextMenuExtension GrepViewPlugin::contextMenuExtension(KDevelop::Context* context, QWidget* parent)
125{
126 KDevelop::ContextMenuExtension extension = KDevelop::IPlugin::contextMenuExtension(context, parent);
127 if( context->type() == KDevelop::Context::ProjectItemContext ) {
128 auto* ctx = static_cast<KDevelop::ProjectItemContext*>(context);
129 QList<KDevelop::ProjectBaseItem*> items = ctx->items();
130 // verify if there is only one folder selected
131 if ((items.count() == 1) && (items.first()->folder())) {
132 auto* action = new QAction(i18nc("@action:inmenu", "Find/Replace in This Folder..."), parent);
133 action->setIcon(QIcon::fromTheme(QStringLiteral("edit-find")));
134 m_contextMenuDirectory = items.at(0)->folder()->path().toLocalFile();
135 connect( action, &QAction::triggered, this, &GrepViewPlugin::showDialogFromProject);
136 extension.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, action );
137 }
138 }
139
140 if ( context->type() == KDevelop::Context::EditorContext ) {
141 auto* econtext = static_cast<KDevelop::EditorContext*>(context);
142 if ( econtext->view()->selection() ) {
143 auto* action = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18nc("@action:inmenu", "&Find/Replace in Files..."), parent);
144 connect(action, &QAction::triggered, this, &GrepViewPlugin::showDialogFromMenu);
145 extension.addAction(KDevelop::ContextMenuExtension::ExtensionGroup, action);
146 }
147 }
148
149 if(context->type() == KDevelop::Context::FileContext) {
150 auto* fcontext = static_cast<KDevelop::FileContext*>(context);
151 // TODO: just stat() or QFileInfo().isDir() for local files? should be faster than mime type checking
152 QMimeType mimetype = QMimeDatabase().mimeTypeForUrl(fcontext->urls().at(0));
153 static const QMimeType directoryMime = QMimeDatabase().mimeTypeForName(QStringLiteral("inode/directory"));
154 if (mimetype == directoryMime) {
155 auto* action = new QAction(i18nc("@action:inmenu", "Find/Replace in This Folder..."), parent);
156 action->setIcon(QIcon::fromTheme(QStringLiteral("edit-find")));
157 m_contextMenuDirectory = fcontext->urls().at(0).toLocalFile();
158 connect( action, &QAction::triggered, this, &GrepViewPlugin::showDialogFromProject);
159 extension.addAction( KDevelop::ContextMenuExtension::ExtensionGroup, action );
160 }
161 }
162 return extension;
163}
164
165void GrepViewPlugin::showDialog(bool setLastUsed, const QString& pattern, bool show)
166{

Callers

nothing calls this directly

Calls 13

folderMethod · 0.80
setIconMethod · 0.80
toLocalFileMethod · 0.80
typeMethod · 0.45
itemsMethod · 0.45
countMethod · 0.45
firstMethod · 0.45
pathMethod · 0.45
atMethod · 0.45
addActionMethod · 0.45
selectionMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected