Commit 2f078c60 authored by Kåre Särs's avatar Kåre Särs

Add actions for going to the next or previous search match.

parent 9f8c7745
......@@ -113,6 +113,14 @@ m_curResults(0)
a->setText(i18n("Search in Files"));
connect(a, SIGNAL(triggered(bool)), this, SLOT(openSearchView()));
a = actionCollection()->addAction("go_to_next_match");
a->setText(i18n("Go to Next Match"));
connect(a, SIGNAL(triggered(bool)), this, SLOT(goToNextMatch()));
a = actionCollection()->addAction("go_to_prev_match");
a->setText(i18n("Go to Previous Match"));
connect(a, SIGNAL(triggered(bool)), this, SLOT(goToPreviousMatch()));
m_toolView = mainWin->createToolView ("kate_plugin_katesearch",
Kate::MainWindow::Bottom,
SmallIcon("edit-find"),
......@@ -475,6 +483,8 @@ void KatePluginSearchView::searchDone()
void KatePluginSearchView::itemSelected(QTreeWidgetItem *item)
{
if (!item) return;
// get stuff
const QString url = item->data(0, Qt::UserRole).toString();
if (url.isEmpty()) return;
......@@ -512,6 +522,83 @@ void KatePluginSearchView::itemSelected(QTreeWidgetItem *item)
//mainWindow()->activeView()->setFocus();
}
void KatePluginSearchView::goToNextMatch()
{
Results *res = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
if (!res) {
return;
}
QTreeWidgetItem *curr = res->tree->currentItem();
if (!curr) {
curr = res->tree->topLevelItem(0);
}
if (!curr) return;
if (curr->parent() == 0) {
res->tree->expandItem(curr);
}
curr = res->tree->itemBelow(curr);
if (!curr) {
curr = res->tree->topLevelItem(0);
}
if (curr->parent() == 0) {
res->tree->expandItem(curr);
curr = res->tree->itemBelow(curr);
}
if (!curr) return;
res->tree->setCurrentItem(curr);
itemSelected(curr);
}
void KatePluginSearchView::goToPreviousMatch()
{
Results *res = qobject_cast<Results *>(m_ui.resultTabWidget->currentWidget());
if (!res) {
return;
}
if (res->tree->topLevelItemCount() == 0) {
return;
}
QTreeWidgetItem *curr = res->tree->currentItem();
if (!curr) {
// select the last child of the last top-level item
curr = res->tree->topLevelItem(res->tree->topLevelItemCount()-1);
curr = curr->child(curr->childCount()-1);
if (!curr) return;
res->tree->setCurrentItem(curr);
itemSelected(curr);
return;
}
curr = res->tree->itemAbove(curr);
if (!curr) {
// current was the first top-level item
res->tree->setCurrentItem(curr);
goToPreviousMatch();
return;
}
if (curr->parent() == 0) {
// this is a top-level item -> go to the item above
curr = res->tree->itemAbove(curr);
if (!curr) {
res->tree->setCurrentItem(curr);
goToPreviousMatch();
return;
}
}
if (curr->parent() == 0) {
// still a top-level item -> expand and take the last
res->tree->expandItem(curr);
curr = curr->child(curr->childCount()-1);
if (!curr) return;
}
res->tree->setCurrentItem(curr);
itemSelected(curr);
}
void KatePluginSearchView::readSessionConfig(KConfigBase* config, const QString& groupPrefix)
{
KConfigGroup cg(config, groupPrefix + ":search-plugin");
......
......@@ -82,7 +82,9 @@ public Q_SLOTS:
void navigateFolderUp();
void setCurrentFolder();
void setSearchPlace(int place);
void goToNextMatch();
void goToPreviousMatch();
private Q_SLOTS:
void openSearchView();
void addTab();
......
<!DOCTYPE kpartgui>
<gui name="katesearch" library="libkatesearchplugin" version="1">
<gui name="katesearch" library="libkatesearchplugin" version="2">
<MenuBar>
<Menu name="edit">
<text>&amp;Edit</text>
<Action name="search_in_files" />
<Action name="go_to_next_match" />
<Action name="go_to_prev_match" />
</Menu>
</MenuBar>
</gui>
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