Commit f41d3c2e authored by Alex Neundorf's avatar Alex Neundorf

search: show summary item at top of search results

This patch
- adds properties projectName and projectBaseDir to the project plugin
- when searching in files, folders or projects, adds a header item to the results treeview

Alex
parent ec190186
......@@ -188,6 +188,24 @@ QString KateProjectPluginView::projectFileName () const
return static_cast<KateProjectView *> (active)->project()->fileName ();
}
QString KateProjectPluginView::projectName () const
{
QWidget *active = m_stackedProjectViews->currentWidget ();
if (!active)
return QString ();
return static_cast<KateProjectView *> (active)->project()->name ();
}
QString KateProjectPluginView::projectBaseDir () const
{
QWidget *active = m_stackedProjectViews->currentWidget ();
if (!active)
return QString ();
return static_cast<KateProjectView *> (active)->project()->baseDir ();
}
QVariantMap KateProjectPluginView::projectMap () const
{
QWidget *active = m_stackedProjectViews->currentWidget ();
......
......@@ -36,6 +36,8 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
Q_OBJECT
Q_PROPERTY(QString projectFileName READ projectFileName NOTIFY projectFileNameChanged)
Q_PROPERTY(QString projectName READ projectName)
Q_PROPERTY(QString projectBaseDir READ projectBaseDir)
Q_PROPERTY(QVariantMap projectMap READ projectMap NOTIFY projectMapChanged)
Q_PROPERTY(QStringList projectFiles READ projectFiles)
......@@ -58,6 +60,16 @@ class KateProjectPluginView : public Kate::PluginView, public Kate::XMLGUIClient
*/
QString projectFileName () const;
/**
* Returns the name of the project
*/
QString projectName () const;
/**
* Returns the base directory of the project
*/
QString projectBaseDir () const;
/**
* files for the current active project?
* @return empty list if none, else project files as stringlist
......
......@@ -51,8 +51,15 @@ void SPHtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option
// draw area
QRect clip = options.widget->style()->subElementRect(QStyle::SE_ItemViewItemText, &options);
QFontMetrics metrics(options.font);
painter->translate(clip.topLeft() - QPoint(0, metrics.descent()));
if ((index.row() == 0) && (!index.parent().isValid())) {
painter->setBrush(QBrush(QWidget().palette().color(QPalette::Base)));
painter->setPen(QWidget().palette().color(QPalette::Base));
painter->drawRect(QRect(clip.topLeft() - QPoint(20, metrics.descent()), clip.bottomRight()));
painter->translate(clip.topLeft() - QPoint(20, metrics.descent()));
}
else {
painter->translate(clip.topLeft() - QPoint(0, metrics.descent()));
}
QAbstractTextDocumentLayout::PaintContext pcontext;
doc.documentLayout()->draw(painter, pcontext);
......
......@@ -421,10 +421,13 @@ void KatePluginSearchView::startSearch()
if (m_ui.searchPlaceCombo->currentIndex() == 0) {
m_resultBaseDir.clear();
m_searchOpenFiles.startSearch(m_kateApp->documentManager()->documents(), reg);
const QList<KTextEditor::Document*> & documents = m_kateApp->documentManager()->documents();
addHeaderItem(i18n("<b><i>Results from %1 open files</i></b>").arg(documents.size()));
m_searchOpenFiles.startSearch(documents, reg);
}
else if (m_ui.searchPlaceCombo->currentIndex() == 1) {
m_resultBaseDir = m_ui.folderRequester->text();
addHeaderItem(i18n("<b><i>Results in folder %1</i></b>").arg(m_resultBaseDir));
m_folderFilesList.generateList(m_ui.folderRequester->text(),
m_ui.recursiveCheckBox->isChecked(),
m_ui.hiddenCheckBox->isChecked(),
......@@ -441,10 +444,11 @@ void KatePluginSearchView::startSearch()
m_resultBaseDir.clear();
QStringList files;
if (m_projectPluginView) {
QString projectFile = m_projectPluginView->property ("projectFileName").toString();
if (projectFile.endsWith(".kateproject")) {
m_resultBaseDir = projectFile.left(projectFile.size() - QString(".kateproject").size());
}
QString projectName = m_projectPluginView->property ("projectName").toString();
m_resultBaseDir = m_projectPluginView->property ("projectBaseDir").toString();
if (!m_resultBaseDir.endsWith("/"))
m_resultBaseDir += "/";
addHeaderItem(i18n("<b><i>Results in project %1 (%2)</i></b>").arg(projectName).arg(m_resultBaseDir));
files = m_projectPluginView->property ("projectFiles").toStringList();
}
......@@ -555,6 +559,14 @@ void KatePluginSearchView::folderFileListChanged()
}
void KatePluginSearchView::addHeaderItem(const QString& text)
{
QTreeWidgetItem *item = new QTreeWidgetItem(m_curResults->tree, QStringList(text));
item->setFlags(Qt::NoItemFlags);
}
QTreeWidgetItem * KatePluginSearchView::rootFileItem(const QString &url)
{
if (!m_curResults) {
......
......@@ -133,6 +133,7 @@ private Q_SLOTS:
protected:
bool eventFilter(QObject *obj, QEvent *ev);
void addHeaderItem(const QString& text);
private:
QTreeWidgetItem *rootFileItem(const QString &url);
......
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