| 39 | #include <utility> |
| 40 | |
| 41 | static QString patternFromSelection(const KDevelop::IDocument* doc) |
| 42 | { |
| 43 | if (!doc) |
| 44 | return QString(); |
| 45 | |
| 46 | QString pattern; |
| 47 | KTextEditor::Range range = doc->textSelection(); |
| 48 | if( range.isValid() ) |
| 49 | { |
| 50 | pattern = doc->textDocument()->text( range ); |
| 51 | } |
| 52 | if( pattern.isEmpty() ) |
| 53 | { |
| 54 | pattern = doc->textWord(); |
| 55 | } |
| 56 | |
| 57 | // Before anything, this removes line feeds from the |
| 58 | // beginning and the end. |
| 59 | int len = pattern.length(); |
| 60 | if (len > 0 && pattern[0] == QLatin1Char('\n')) { |
| 61 | pattern.remove(0, 1); |
| 62 | len--; |
| 63 | } |
| 64 | if (len > 0 && pattern[len-1] == QLatin1Char('\n')) |
| 65 | pattern.truncate(len-1); |
| 66 | return pattern; |
| 67 | } |
| 68 | |
| 69 | GrepViewPlugin::GrepViewPlugin(QObject* parent, const KPluginMetaData& metaData, const QVariantList&) |
| 70 | : KDevelop::IPlugin(QStringLiteral("kdevgrepview"), parent, metaData) |
no test coverage detected