Commit 893bb799 authored by Kåre Särs's avatar Kåre Särs
Browse files

Move KateSearchCommand to a separate file

parent 2bac3af1
......@@ -27,6 +27,7 @@ target_sources(
FolderFilesList.cpp
replace_matches.cpp
htmldelegate.cpp
KateSearchCommand.cpp
plugin.qrc
)
......
/* Kate search plugin
*
* Copyright (C) 2020 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file called COPYING; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "KateSearchCommand.h"
#include "plugin_search.h"
KateSearchCommand::KateSearchCommand(QObject *parent)
: KTextEditor::Command(QStringList() << QStringLiteral("grep") << QStringLiteral("newGrep") << QStringLiteral("search") << QStringLiteral("newSearch") << QStringLiteral("pgrep") << QStringLiteral("newPGrep"), parent)
{
}
bool KateSearchCommand::exec(KTextEditor::View * /*view*/, const QString &cmd, QString & /*msg*/, const KTextEditor::Range &)
{
// create a list of args
QStringList args(cmd.split(QLatin1Char(' '), QString::KeepEmptyParts));
QString command = args.takeFirst();
QString searchText = args.join(QLatin1Char(' '));
if (command == QLatin1String("grep") || command == QLatin1String("newGrep")) {
emit setSearchPlace(KatePluginSearchView::Folder);
emit setCurrentFolder();
if (command == QLatin1String("newGrep"))
emit newTab();
}
else if (command == QLatin1String("search") || command == QLatin1String("newSearch")) {
emit setSearchPlace(KatePluginSearchView::OpenFiles);
if (command == QLatin1String("newSearch"))
emit newTab();
}
else if (command == QLatin1String("pgrep") || command == QLatin1String("newPGrep")) {
emit setSearchPlace(KatePluginSearchView::Project);
if (command == QLatin1String("newPGrep"))
emit newTab();
}
emit setSearchString(searchText);
emit startSearch();
return true;
}
bool KateSearchCommand::help(KTextEditor::View * /*view*/, const QString &cmd, QString &msg)
{
if (cmd.startsWith(QLatin1String("grep"))) {
msg = i18n("Usage: grep [pattern to search for in folder]");
} else if (cmd.startsWith(QLatin1String("newGrep"))) {
msg = i18n("Usage: newGrep [pattern to search for in folder]");
}
else if (cmd.startsWith(QLatin1String("search"))) {
msg = i18n("Usage: search [pattern to search for in open files]");
} else if (cmd.startsWith(QLatin1String("newSearch"))) {
msg = i18n("Usage: search [pattern to search for in open files]");
}
else if (cmd.startsWith(QLatin1String("pgrep"))) {
msg = i18n("Usage: pgrep [pattern to search for in current project]");
} else if (cmd.startsWith(QLatin1String("newPGrep"))) {
msg = i18n("Usage: newPGrep [pattern to search for in current project]");
}
return true;
}
// kate: space-indent on; indent-width 4; replace-tabs on;
/* Kate search plugin
*
* Copyright (C) 2020 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file called COPYING; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#ifndef KateSearchCommand_h
#define KateSearchCommand_h
#include <KTextEditor/Command>
#include <QString>
namespace KTextEditor {
class View;
class Range;
}
class KateSearchCommand : public KTextEditor::Command
{
Q_OBJECT
public:
KateSearchCommand(QObject *parent);
Q_SIGNALS:
void setSearchPlace(int place);
void setCurrentFolder();
void setSearchString(const QString &pattern);
void startSearch();
void newTab();
//
// KTextEditor::Command
//
public:
bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range::invalid()) override;
bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override;
};
#endif
// kate: space-indent on; indent-width 4; replace-tabs on;
/* Kate search plugin
*
* Copyright (C) 2011-2013 by Kåre Särs <kare.sars@iki.fi>
* Copyright (C) 2011-2020 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -19,7 +19,7 @@
*/
#include "plugin_search.h"
#include "KateSearchCommand.h"
#include "htmldelegate.h"
#include <ktexteditor/application.h>
......@@ -2292,65 +2292,6 @@ void KatePluginSearchView::slotProjectFileNameChanged()
}
}
KateSearchCommand::KateSearchCommand(QObject *parent)
: KTextEditor::Command(QStringList() << QStringLiteral("grep") << QStringLiteral("newGrep") << QStringLiteral("search") << QStringLiteral("newSearch") << QStringLiteral("pgrep") << QStringLiteral("newPGrep"), parent)
{
}
bool KateSearchCommand::exec(KTextEditor::View * /*view*/, const QString &cmd, QString & /*msg*/, const KTextEditor::Range &)
{
// create a list of args
QStringList args(cmd.split(QLatin1Char(' '), QString::KeepEmptyParts));
QString command = args.takeFirst();
QString searchText = args.join(QLatin1Char(' '));
if (command == QLatin1String("grep") || command == QLatin1String("newGrep")) {
emit setSearchPlace(KatePluginSearchView::Folder);
emit setCurrentFolder();
if (command == QLatin1String("newGrep"))
emit newTab();
}
else if (command == QLatin1String("search") || command == QLatin1String("newSearch")) {
emit setSearchPlace(KatePluginSearchView::OpenFiles);
if (command == QLatin1String("newSearch"))
emit newTab();
}
else if (command == QLatin1String("pgrep") || command == QLatin1String("newPGrep")) {
emit setSearchPlace(KatePluginSearchView::Project);
if (command == QLatin1String("newPGrep"))
emit newTab();
}
emit setSearchString(searchText);
emit startSearch();
return true;
}
bool KateSearchCommand::help(KTextEditor::View * /*view*/, const QString &cmd, QString &msg)
{
if (cmd.startsWith(QLatin1String("grep"))) {
msg = i18n("Usage: grep [pattern to search for in folder]");
} else if (cmd.startsWith(QLatin1String("newGrep"))) {
msg = i18n("Usage: newGrep [pattern to search for in folder]");
}
else if (cmd.startsWith(QLatin1String("search"))) {
msg = i18n("Usage: search [pattern to search for in open files]");
} else if (cmd.startsWith(QLatin1String("newSearch"))) {
msg = i18n("Usage: search [pattern to search for in open files]");
}
else if (cmd.startsWith(QLatin1String("pgrep"))) {
msg = i18n("Usage: pgrep [pattern to search for in current project]");
} else if (cmd.startsWith(QLatin1String("newPGrep"))) {
msg = i18n("Usage: newPGrep [pattern to search for in current project]");
}
return true;
}
#include "plugin_search.moc"
......
/* Kate search plugin
*
* Copyright (C) 2011-2013 by Kåre Särs <kare.sars@iki.fi>
* Copyright (C) 2011-2020 by Kåre Särs <kare.sars@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -214,27 +214,6 @@ private:
KTextEditor::MainWindow *m_mainWindow;
};
class KateSearchCommand : public KTextEditor::Command
{
Q_OBJECT
public:
KateSearchCommand(QObject *parent);
Q_SIGNALS:
void setSearchPlace(int place);
void setCurrentFolder();
void setSearchString(const QString &pattern);
void startSearch();
void newTab();
//
// KTextEditor::Command
//
public:
bool exec(KTextEditor::View *view, const QString &cmd, QString &msg, const KTextEditor::Range &range = KTextEditor::Range::invalid()) override;
bool help(KTextEditor::View *view, const QString &cmd, QString &msg) override;
};
#endif
// kate: space-indent on; indent-width 4; replace-tabs on;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment