Commit 5a684874 authored by Kåre Särs's avatar Kåre Särs

Search plugin: Usability and UI tweaks

Esc handling for hiding the view
Ctrl-c handling for copy url of found file
Add close button to get the search combo visually aligned with the options
parent 35a21894
......@@ -36,6 +36,8 @@
#include <kaboutdata.h>
#include <kurlcompletion.h>
#include <QLineEdit>
#include <QKeyEvent>
#include <QClipboard>
K_PLUGIN_FACTORY(KatePluginSearchFactory, registerPlugin<KatePluginSearch>();)
K_EXPORT_PLUGIN(KatePluginSearchFactory(KAboutData("katesearch","katesearch",ki18n("Search in files"), "0.1", ki18n("Find in open files plugin"))))
......@@ -98,6 +100,12 @@ m_kateApp(application)
m_ui.searchPlaceCombo->setItemIcon(0, KIcon("text-plain"));
m_ui.searchPlaceCombo->setItemIcon(1, KIcon("folder"));
m_ui.currentFolderButton->setIcon(KIcon("view-refresh"));
m_ui.hideButton->setIcon(KIcon("dialog-close"));
int padWidth = m_ui.folderLabel->width();
padWidth = qMax(padWidth, m_ui.filterLabel->width());
m_ui.gridLayout->setColumnMinimumWidth(0, padWidth);
m_ui.gridLayout->setAlignment(m_ui.hideButton, Qt::AlignHCenter);
// get url-requester's combo box and sanely initialize
KComboBox* cmbUrl = m_ui.folderRequester->comboBox();
......@@ -116,6 +124,7 @@ m_kateApp(application)
m_useRegExp->setCheckable(true);
m_ui.optionsButton->addAction(m_useRegExp);
connect(m_ui.hideButton, SIGNAL(clicked()), this, SLOT(toggleSearchView()));
connect(m_ui.searchButton, SIGNAL(clicked()), this, SLOT(startSearch()));
connect(m_ui.searchCombo, SIGNAL(returnPressed()), this, SLOT(startSearch()));
connect(m_ui.folderRequester, SIGNAL(returnPressed()), this, SLOT(startSearch()));
......@@ -131,7 +140,7 @@ m_kateApp(application)
m_ui.displayOptions->setChecked(true);
connect(m_ui.searchResults, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
connect(m_ui.searchResults, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
SLOT(itemSelected(QTreeWidgetItem *)));
connect(&m_searchOpenFiles, SIGNAL(matchFound(QString, int, int, QString)),
......@@ -147,6 +156,9 @@ m_kateApp(application)
searchPlaceChanged();
m_ui.searchResults->installEventFilter(this);
m_toolView->installEventFilter(this);
mainWindow()->guiFactory()->addClient(this);
}
......@@ -257,11 +269,13 @@ void KatePluginSearchView::searchPatternChanged()
m_ui.searchButton->setDisabled(m_ui.searchCombo->currentText().isEmpty());
}
void KatePluginSearchView::matchFound(const QString &fileName, int line, int column, const QString &lineContent)
void KatePluginSearchView::matchFound(const QString &url, int line, int column, const QString &lineContent)
{
QStringList row;
row << fileName << QString::number(line +1) << lineContent;
row << QFileInfo(url).fileName() << QString::number(line +1) << lineContent;
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui.searchResults, row);
item->setData(0, Qt::UserRole, url);
item->setData(0, Qt::ToolTipRole, url);
item->setData(1, Qt::UserRole, column);
}
......@@ -275,12 +289,16 @@ void KatePluginSearchView::searchDone()
m_ui.searchResults->resizeColumnToContents(0);
m_ui.searchResults->resizeColumnToContents(1);
m_ui.searchResults->resizeColumnToContents(2);
if (m_ui.searchResults->topLevelItemCount() > 0) {
m_ui.searchResults->setCurrentItem(m_ui.searchResults-> topLevelItem(0));
m_ui.searchResults->setFocus(Qt::OtherFocusReason);
}
}
void KatePluginSearchView::itemSelected(QTreeWidgetItem *item)
{
// get stuff
const QString url = item->data(0, Qt::DisplayRole).toString();
const QString url = item->data(0, Qt::UserRole).toString();
if (url.isEmpty()) return;
int line = item->data(1, Qt::DisplayRole).toInt() - 1;
int column = item->data(1, Qt::UserRole).toInt();
......@@ -295,7 +313,7 @@ void KatePluginSearchView::itemSelected(QTreeWidgetItem *item)
// do it ;)
mainWindow()->activeView()->setCursorPosition(KTextEditor::Cursor(line, column));
mainWindow()->activeView()->setFocus();
//mainWindow()->activeView()->setFocus();
}
void KatePluginSearchView::readSessionConfig(KConfigBase* config, const QString& groupPrefix)
......@@ -343,7 +361,34 @@ void KatePluginSearchView::writeSessionConfig(KConfigBase* config, const QString
cg.writeEntry("CurrentFilter", m_ui.filterCombo->currentIndex());
}
bool KatePluginSearchView::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
if (obj == m_ui.searchResults) {
if (ke->matches(QKeySequence::Copy)) {
// user pressed ctrl+c -> copy full URL to the clipboard
QVariant variant = m_ui.searchResults->currentItem()->data(0, Qt::UserRole);
QApplication::clipboard()->setText(variant.toString());
event->accept();
return true;
}
if (ke->key() == Qt::Key_Enter || ke->key() == Qt::Key_Return) {
if (m_ui.searchResults->currentItem()) {
itemSelected(m_ui.searchResults->currentItem());
event->accept();
return true;
}
}
}
if ((obj == m_toolView) && (ke->key() == Qt::Key_Escape)) {
mainWindow()->hideToolView(m_toolView);
event->accept();
return true;
}
}
return QObject::eventFilter(obj, event);
}
KateSearchCommand::KateSearchCommand(QObject *parent)
: QObject(parent), KTextEditor::Command()
......@@ -387,4 +432,5 @@ bool KateSearchCommand::help (KTextEditor::View */*view*/, const QString &cmd, Q
return true;
}
// kate: space-indent on; indent-width 4; replace-tabs on;
......@@ -27,6 +27,8 @@
#include <kxmlguiclient.h>
#include <kaction.h>
#include <QTreeWidget>
#include "ui_search.h"
#include "search_open_files.h"
......@@ -79,6 +81,9 @@ private Q_SLOTS:
void itemSelected(QTreeWidgetItem *item);
protected:
bool eventFilter(QObject *obj, QEvent *ev);
private:
Ui::SearchDialog m_ui;
QWidget *m_toolView;
......@@ -110,7 +115,6 @@ public:
bool help (KTextEditor::View *view, const QString &cmd, QString &msg);
};
#endif
// kate: space-indent on; indent-width 4; replace-tabs on;
......
......@@ -6,15 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>373</width>
<width>416</width>
<height>110</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0,0,0,0">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,1" columnstretch="0,1,0,0,0,0">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<item row="0" column="1">
<widget class="KHistoryComboBox" name="searchCombo">
<property name="editable">
<bool>true</bool>
......@@ -24,7 +24,7 @@
</property>
</widget>
</item>
<item row="0" column="3">
<item row="0" column="4">
<widget class="QToolButton" name="optionsButton">
<property name="text">
<string>Options</string>
......@@ -37,7 +37,7 @@
</property>
</widget>
</item>
<item row="0" column="4">
<item row="0" column="5">
<widget class="QToolButton" name="displayOptions">
<property name="text">
<string>...</string>
......@@ -50,7 +50,7 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="5">
<item row="1" column="0" colspan="6">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>1</number>
......@@ -62,9 +62,6 @@
</property>
<item>
<widget class="QTreeWidget" name="searchResults">
<property name="autoScroll">
<bool>false</bool>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
......@@ -232,7 +229,7 @@
</widget>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="2">
<widget class="KPushButton" name="searchButton">
<property name="enabled">
<bool>false</bool>
......@@ -242,7 +239,7 @@
</property>
</widget>
</item>
<item row="0" column="2">
<item row="0" column="3">
<widget class="QStackedWidget" name="locationAndStop">
<property name="currentIndex">
<number>0</number>
......@@ -296,6 +293,16 @@
</widget>
</widget>
</item>
<item row="0" column="0">
<widget class="QToolButton" name="hideButton">
<property name="text">
<string>...</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
......
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