| 122 | } |
| 123 | |
| 124 | KDevelop::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 | |
| 165 | void GrepViewPlugin::showDialog(bool setLastUsed, const QString& pattern, bool show) |
| 166 | { |
nothing calls this directly
no test coverage detected