Commit 0d58e509 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Kåre Särs
Browse files

New preg command based TODO search

parent 7181f796
......@@ -10,6 +10,7 @@
#include "gitwidget.h"
#include "kateprojectinfoviewindex.h"
#include <KTextEditor/Command>
#include <ktexteditor/application.h>
#include <ktexteditor/codecompletioninterface.h>
#include <ktexteditor/document.h>
......@@ -160,10 +161,17 @@ KateProjectPluginView::KateProjectPluginView(KateProjectPlugin *plugin, KTextEdi
*/
auto a = actionCollection()->addAction(QStringLiteral("projects_open_project"), this, SLOT(openDirectoryOrProject()));
a->setText(i18n("Open Folder..."));
a = actionCollection()->addAction(QStringLiteral("projects_todos"), this, SLOT(showProjectTodos()));
a->setText(i18n("Project TODOs"));
a->setIcon(QIcon::fromTheme(QStringLiteral("korg-todo")));
a = actionCollection()->addAction(KStandardAction::Back, QStringLiteral("projects_prev_project"), this, SLOT(slotProjectPrev()));
actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Left));
a = actionCollection()->addAction(KStandardAction::Forward, QStringLiteral("projects_next_project"), this, SLOT(slotProjectNext()));
actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Right));
a = actionCollection()->addAction(QStringLiteral("projects_goto_index"), this, SLOT(slotProjectIndex()));
a->setText(i18n("Lookup"));
actionCollection()->setDefaultShortcut(a, QKeySequence(Qt::ALT | Qt::Key_1));
......@@ -654,4 +662,14 @@ void KateProjectPluginView::openDirectoryOrProject()
}
}
void KateProjectPluginView::showProjectTodos()
{
KTextEditor::Command *pgrep = KTextEditor::Editor::instance()->queryCommand(QStringLiteral("pgrep"));
if (!pgrep) {
return;
}
QString msg;
pgrep->exec(nullptr, QStringLiteral("preg (TODO|FIXME)\\b"), msg);
}
#include "kateprojectpluginview.moc"
......@@ -259,6 +259,11 @@ private Q_SLOTS:
*/
void openDirectoryOrProject();
/**
* Show projects To-Dos and Fix-mes
*/
void showProjectTodos();
private:
/**
* find current selected or under cursor word
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="kateprojectplugin" library="kateprojectplugin" version="10" translationDomain="kateproject">
<gui name="kateprojectplugin" library="kateprojectplugin" version="11" translationDomain="kateproject">
<MenuBar>
<Menu name="file">
<Action name="projects_open_project" group="open_merge"/>
</Menu>
<Menu name="projects">
<text>&amp;Projects</text>
<Action name="projects_todos"/>
<Action name="projects_prev_project"/>
<Action name="projects_next_project"/>
<Action name="projects_goto_index" />
......
......@@ -11,7 +11,7 @@
KateSearchCommand::KateSearchCommand(QObject *parent)
: KTextEditor::Command(QStringList() << QStringLiteral("grep") << QStringLiteral("newGrep") << QStringLiteral("search") << QStringLiteral("newSearch")
<< QStringLiteral("pgrep") << QStringLiteral("newPGrep"),
<< QStringLiteral("pgrep") << QStringLiteral("newPGrep") << QStringLiteral("preg"),
parent)
{
}
......@@ -57,6 +57,12 @@ bool KateSearchCommand::exec(KTextEditor::View * /*view*/, const QString &cmd, Q
}
}
else if (command == QLatin1String("preg")) {
Q_EMIT setSearchPlace(MatchModel::Project);
Q_EMIT setPregSearch();
Q_EMIT newTab();
}
Q_EMIT setSearchString(searchText);
Q_EMIT startSearch();
......@@ -83,6 +89,10 @@ bool KateSearchCommand::help(KTextEditor::View * /*view*/, const QString &cmd, Q
msg = i18n("Usage: newPGrep [pattern to search for in current project]");
}
else if (cmd.startsWith(QLatin1String("preg"))) {
msg = i18n("Usage: preg [pattern to search for in current project]");
}
return true;
}
......
......@@ -28,6 +28,7 @@ Q_SIGNALS:
void setSearchPlace(int place);
void setCurrentFolder();
void setSearchString(const QString &pattern);
void setPregSearch();
void startSearch();
void newTab();
......
......@@ -221,6 +221,7 @@ QObject *KatePluginSearch::createView(KTextEditor::MainWindow *mainWindow)
connect(m_searchCommand, &KateSearchCommand::setCurrentFolder, view, &KatePluginSearchView::setCurrentFolder);
connect(m_searchCommand, &KateSearchCommand::setSearchString, view, &KatePluginSearchView::setSearchString);
connect(m_searchCommand, &KateSearchCommand::startSearch, view, &KatePluginSearchView::startSearch);
connect(m_searchCommand, &KateSearchCommand::setPregSearch, view, &KatePluginSearchView::setPregSearch);
connect(m_searchCommand, SIGNAL(newTab()), view, SLOT(addTab()));
connect(view, &KatePluginSearchView::searchBusy, m_searchCommand, &KateSearchCommand::setBusy);
......@@ -978,7 +979,7 @@ void KatePluginSearchView::startSearch()
QRegularExpression::PatternOptions patternOptions =
(m_ui.matchCase->isChecked() ? QRegularExpression::UseUnicodePropertiesOption
: QRegularExpression::UseUnicodePropertiesOption | QRegularExpression::CaseInsensitiveOption);
QString pattern = (m_ui.useRegExp->isChecked() ? currentSearchText : QRegularExpression::escape(currentSearchText));
QString pattern = (m_ui.useRegExp->isChecked() || m_isPreg ? currentSearchText : QRegularExpression::escape(currentSearchText));
QRegularExpression reg(pattern, patternOptions);
if (!reg.isValid()) {
......@@ -992,8 +993,8 @@ void KatePluginSearchView::startSearch()
updateViewColors();
m_curResults->regExp = reg;
m_curResults->useRegExp = m_ui.useRegExp->isChecked();
m_curResults->matchCase = m_ui.matchCase->isChecked();
m_curResults->useRegExp = m_isPreg ? true : m_ui.useRegExp->isChecked();
m_curResults->matchCase = m_isPreg ? false : m_ui.matchCase->isChecked();
m_curResults->searchPlaceIndex = m_ui.searchPlaceCombo->currentIndex();
m_ui.newTabButton->setDisabled(true);
......@@ -1261,6 +1262,8 @@ void KatePluginSearchView::searchDone()
m_searchJustOpened = false;
updateMatchMarks();
// unset preg command mode
m_isPreg = false;
// qDebug() << "done:" << s_timer.elapsed();
}
......@@ -1581,6 +1584,12 @@ void KatePluginSearchView::expandResults()
return;
}
// preg command? => expand all
if (m_isPreg) {
m_curResults->treeView->expandAll();
return;
}
// we expand recursively if we either are told so or we have just one toplevel match item
QModelIndex rootItem = m_curResults->matchModel.index(0, 0);
if ((m_ui.expandResults->isChecked() && m_curResults->matchModel.rowCount(rootItem) < 200) || m_curResults->matchModel.rowCount(rootItem) == 1) {
......@@ -1797,6 +1806,11 @@ void KatePluginSearchView::goToPreviousMatch()
}
}
void KatePluginSearchView::setPregSearch()
{
m_isPreg = true;
}
void KatePluginSearchView::readSessionConfig(const KConfigGroup &cg)
{
m_ui.searchCombo->clear();
......
......@@ -107,6 +107,7 @@ public Q_SLOTS:
void setSearchPlace(int place);
void goToNextMatch();
void goToPreviousMatch();
void setPregSearch();
private:
enum CopyResultType { AllExpanded, All };
......@@ -204,6 +205,7 @@ private:
int m_projectSearchPlaceIndex = 0;
bool m_isSearchAsYouType = false;
bool m_isVerticalLayout = false;
bool m_isPreg = false; /* ci-regex search via preg command with auto expand */
QString m_resultBaseDir;
QVector<KTextEditor::MovingRange *> m_matchRanges;
QTimer m_changeTimer;
......
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