Skip to content

Commit

Permalink
feat: show info rggrip not found
Browse files Browse the repository at this point in the history
  • Loading branch information
Montel committed Oct 29, 2024
1 parent 4735c79 commit 1db9852
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
42 changes: 41 additions & 1 deletion src/gui/findinfilespanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Contact KDAB at <[email protected]> for commercial licensing options.
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLineEdit>
#include <QPainter>
#include <QToolButton>
#include <QTreeWidget>
#include <QTreeWidgetItem>
Expand All @@ -24,10 +25,23 @@ namespace Gui {

enum { LineRole = Qt::UserRole + 1, ColumnRole };

class FindInFilesTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
explicit FindInFilesTreeWidget(QWidget *parent = nullptr);

protected:
void paintEvent(QPaintEvent *) override;

private:
const bool m_findInFilesAvailable;
};

FindInFilesPanel::FindInFilesPanel(QWidget *parent)
: QWidget(parent)
, m_toolBar(new QWidget(this))
, m_resultsDisplay(new QTreeWidget(this))
, m_resultsDisplay(new FindInFilesTreeWidget(this))
{
setWindowTitle(tr("Find in Files"));
setObjectName("FindInFilesPanel");
Expand All @@ -45,6 +59,8 @@ FindInFilesPanel::FindInFilesPanel(QWidget *parent)
connect(m_resultsDisplay, &QTreeWidget::itemActivated, this, [this](QTreeWidgetItem *item, int) {
openFileAtItem(item);
});
const bool available = Core::Project::instance()->isFindInFilesAvailable();
m_searchInput->setEnabled(available);
}

QWidget *FindInFilesPanel::toolBar() const
Expand Down Expand Up @@ -146,4 +162,28 @@ void FindInFilesPanel::openFileAtItem(QTreeWidgetItem *item)
}
}

FindInFilesTreeWidget::FindInFilesTreeWidget(QWidget *parent)
: QTreeWidget(parent)
, m_findInFilesAvailable(Core::Project::instance()->isFindInFilesAvailable())
{
}

void FindInFilesTreeWidget::paintEvent(QPaintEvent *event)
{
if (!m_findInFilesAvailable) {
QPainter p(viewport());

QFont font = p.font();
font.setItalic(true);
p.setFont(font);

p.drawText(QRect(0, 0, width(), height()), Qt::AlignCenter,
tr("Ripgrep (rg) executable not found.\nPlease ensure that ripgrep is installed and its location is "
"included in the PATH environment variable."));
} else {
QTreeWidget::paintEvent(event);
}
}

} // namespace Gui
#include "findinfilespanel.moc"
5 changes: 2 additions & 3 deletions src/gui/findinfilespanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ Contact KDAB at <[email protected]> for commercial licensing options.

class QLineEdit;
class QToolButton;
class QTreeWidget;
class QTreeWidgetItem;

#include <QWidget>
#include <QTreeWidget>

namespace Gui {

Expand All @@ -35,7 +34,7 @@ class FindInFilesPanel : public QWidget
void setupToolBar();

QWidget *const m_toolBar;
QTreeWidget *m_resultsDisplay;
QTreeWidget *m_resultsDisplay = nullptr;
QLineEdit *m_searchInput;
};

Expand Down

0 comments on commit 1db9852

Please sign in to comment.