From 7c2e68cb1e7a2f05fc74a3eae77912222b89dc5a Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Fri, 25 Oct 2024 09:37:28 +0200 Subject: [PATCH] feat: show info rggrip not found --- src/gui/findinfilespanel.cpp | 42 +++++++++++++++++++++++++++++++++++- src/gui/findinfilespanel.h | 5 ++--- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/gui/findinfilespanel.cpp b/src/gui/findinfilespanel.cpp index a6c69b90..646136f8 100644 --- a/src/gui/findinfilespanel.cpp +++ b/src/gui/findinfilespanel.cpp @@ -15,6 +15,7 @@ Contact KDAB at for commercial licensing options. #include #include #include +#include #include #include #include @@ -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"); @@ -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 @@ -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" diff --git a/src/gui/findinfilespanel.h b/src/gui/findinfilespanel.h index 5b6d5dfe..859e17f7 100644 --- a/src/gui/findinfilespanel.h +++ b/src/gui/findinfilespanel.h @@ -12,10 +12,9 @@ Contact KDAB at for commercial licensing options. class QLineEdit; class QToolButton; -class QTreeWidget; class QTreeWidgetItem; -#include +#include namespace Gui { @@ -35,7 +34,7 @@ class FindInFilesPanel : public QWidget void setupToolBar(); QWidget *const m_toolBar; - QTreeWidget *m_resultsDisplay; + QTreeWidget *m_resultsDisplay = nullptr; QLineEdit *m_searchInput; };