forked from qt-creator/qt-creator
ProjectExplorer: Move filtering infrastructure up
... from AppOutputPane to IOutputPane. We want to have filtering in other output panes too. Change-Id: I805ec68baedf491b71d392c3370dee78ed4ab76c Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -26,12 +26,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "core_global.h"
|
||||
#include "id.h"
|
||||
|
||||
#include <utils/fancylineedit.h>
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QAction;
|
||||
class QToolButton;
|
||||
class QWidget;
|
||||
QT_END_NAMESPACE
|
||||
@@ -93,11 +97,28 @@ signals:
|
||||
void fontChanged(const QFont &font);
|
||||
|
||||
protected:
|
||||
void setupFilterUi(const QString &historyKey);
|
||||
QString filterText() const;
|
||||
void setFilteringEnabled(bool enable);
|
||||
|
||||
void setZoomButtonsEnabled(bool enabled);
|
||||
|
||||
private:
|
||||
virtual void updateFilter();
|
||||
|
||||
void filterOutputButtonClicked();
|
||||
void setCaseSensitive(bool caseSensitive);
|
||||
void setRegularExpressions(bool regularExpressions);
|
||||
Id filterRegexpActionId() const;
|
||||
Id filterCaseSensitivityActionId() const;
|
||||
|
||||
QToolButton * const m_zoomInButton = nullptr;
|
||||
QToolButton * const m_zoomOutButton = nullptr;
|
||||
QAction *m_filterActionRegexp = nullptr;
|
||||
QAction *m_filterActionCaseSensitive = nullptr;
|
||||
Utils::FancyLineEdit *m_filterOutputLineEdit = nullptr;
|
||||
bool m_filterRegexp = false;
|
||||
bool m_filterCaseSensitive = false;
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
#include <coreplugin/editormanager/ieditor.h>
|
||||
#include <coreplugin/find/optionspopup.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
@@ -117,7 +118,10 @@ IOutputPane::~IOutputPane()
|
||||
|
||||
QList<QWidget *> IOutputPane::toolBarWidgets() const
|
||||
{
|
||||
return {m_zoomInButton, m_zoomOutButton};
|
||||
QList<QWidget *> widgets;
|
||||
if (m_filterOutputLineEdit)
|
||||
widgets << m_filterOutputLineEdit;
|
||||
return widgets << m_zoomInButton << m_zoomOutButton;
|
||||
}
|
||||
|
||||
void IOutputPane::setFont(const QFont &font)
|
||||
@@ -130,12 +134,84 @@ void IOutputPane::setWheelZoomEnabled(bool enabled)
|
||||
emit wheelZoomEnabledChanged(enabled);
|
||||
}
|
||||
|
||||
void IOutputPane::setupFilterUi(const QString &historyKey)
|
||||
{
|
||||
m_filterOutputLineEdit = new FancyLineEdit;
|
||||
m_filterActionRegexp = new QAction(this);
|
||||
m_filterActionRegexp->setCheckable(true);
|
||||
m_filterActionRegexp->setText(tr("Use Regular Expressions"));
|
||||
connect(m_filterActionRegexp, &QAction::toggled, this, &IOutputPane::setRegularExpressions);
|
||||
Core::ActionManager::registerAction(m_filterActionRegexp, filterRegexpActionId());
|
||||
|
||||
m_filterActionCaseSensitive = new QAction(this);
|
||||
m_filterActionCaseSensitive->setCheckable(true);
|
||||
m_filterActionCaseSensitive->setText(tr("Case Sensitive"));
|
||||
connect(m_filterActionCaseSensitive, &QAction::toggled, this, &IOutputPane::setCaseSensitive);
|
||||
Core::ActionManager::registerAction(m_filterActionCaseSensitive,
|
||||
filterCaseSensitivityActionId());
|
||||
|
||||
m_filterOutputLineEdit->setPlaceholderText(tr("Filter output..."));
|
||||
m_filterOutputLineEdit->setButtonVisible(FancyLineEdit::Left, true);
|
||||
m_filterOutputLineEdit->setButtonIcon(FancyLineEdit::Left, Icons::MAGNIFIER.icon());
|
||||
m_filterOutputLineEdit->setFiltering(true);
|
||||
m_filterOutputLineEdit->setEnabled(false);
|
||||
m_filterOutputLineEdit->setHistoryCompleter(historyKey);
|
||||
connect(m_filterOutputLineEdit, &FancyLineEdit::textChanged,
|
||||
this, &IOutputPane::updateFilter);
|
||||
connect(m_filterOutputLineEdit, &FancyLineEdit::returnPressed,
|
||||
this, &IOutputPane::updateFilter);
|
||||
connect(m_filterOutputLineEdit, &FancyLineEdit::leftButtonClicked,
|
||||
this, &IOutputPane::filterOutputButtonClicked);
|
||||
}
|
||||
|
||||
QString IOutputPane::filterText() const
|
||||
{
|
||||
return m_filterOutputLineEdit->text();
|
||||
}
|
||||
|
||||
void IOutputPane::setFilteringEnabled(bool enable)
|
||||
{
|
||||
m_filterOutputLineEdit->setEnabled(enable);
|
||||
}
|
||||
|
||||
void IOutputPane::setZoomButtonsEnabled(bool enabled)
|
||||
{
|
||||
m_zoomInButton->setEnabled(enabled);
|
||||
m_zoomOutButton->setEnabled(enabled);
|
||||
}
|
||||
|
||||
void IOutputPane::updateFilter()
|
||||
{
|
||||
QTC_ASSERT(false, qDebug() << "updateFilter() needs to get re-implemented");
|
||||
}
|
||||
|
||||
void IOutputPane::filterOutputButtonClicked()
|
||||
{
|
||||
auto popup = new Core::OptionsPopup(m_filterOutputLineEdit,
|
||||
{filterRegexpActionId(), filterCaseSensitivityActionId()});
|
||||
popup->show();
|
||||
}
|
||||
|
||||
void IOutputPane::setRegularExpressions(bool regularExpressions)
|
||||
{
|
||||
m_filterRegexp = regularExpressions;
|
||||
}
|
||||
|
||||
Id IOutputPane::filterRegexpActionId() const
|
||||
{
|
||||
return Id("OutputFilter.RegularExpressions").withSuffix(metaObject()->className());
|
||||
}
|
||||
|
||||
Id IOutputPane::filterCaseSensitivityActionId() const
|
||||
{
|
||||
return Id("OutputFilter.CaseSensitive").withSuffix(metaObject()->className());
|
||||
}
|
||||
|
||||
void IOutputPane::setCaseSensitive(bool caseSensitive)
|
||||
{
|
||||
m_filterCaseSensitive = caseSensitive;
|
||||
}
|
||||
|
||||
namespace Internal {
|
||||
|
||||
const char outputPaneSettingsKeyC[] = "OutputPaneVisibility";
|
||||
|
||||
@@ -68,6 +68,7 @@ public:
|
||||
bool linksActive = true;
|
||||
bool m_zoomEnabled = false;
|
||||
float m_originalFontSize = 0.;
|
||||
bool m_originalReadOnly = false;
|
||||
int maxCharCount = Core::Constants::DEFAULT_MAX_CHAR_COUNT;
|
||||
Qt::MouseButton mouseButtonPressed = Qt::NoButton;
|
||||
QTextCursor cursor;
|
||||
@@ -291,6 +292,7 @@ void OutputWindow::setFilterText(const QString &filterText)
|
||||
{
|
||||
if (d->filterText != filterText) {
|
||||
d->lastFilteredBlock = {};
|
||||
const bool filterTextWasEmpty = d->filterText.isEmpty();
|
||||
d->filterText = filterText;
|
||||
|
||||
// Update textedit's background color
|
||||
@@ -305,7 +307,14 @@ void OutputWindow::setFilterText(const QString &filterText)
|
||||
setPalette(pal);
|
||||
}
|
||||
|
||||
setReadOnly(!filterText.isEmpty());
|
||||
if (filterText.isEmpty()) {
|
||||
setReadOnly(d->m_originalReadOnly);
|
||||
} else {
|
||||
if (filterTextWasEmpty)
|
||||
d->m_originalReadOnly = isReadOnly();
|
||||
setReadOnly(true);
|
||||
}
|
||||
|
||||
filterNewContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <coreplugin/actionmanager/command.h>
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/find/basetextfind.h>
|
||||
#include <coreplugin/find/optionspopup.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/outputwindow.h>
|
||||
#include <texteditor/behaviorsettings.h>
|
||||
@@ -100,12 +99,6 @@ const char CLEAN_OLD_OUTPUT_KEY[] = "ProjectExplorer/Settings/CleanOldAppOutput"
|
||||
const char MERGE_CHANNELS_KEY[] = "ProjectExplorer/Settings/MergeStdErrAndStdOut";
|
||||
const char WRAP_OUTPUT_KEY[] = "ProjectExplorer/Settings/WrapAppOutput";
|
||||
const char MAX_LINES_KEY[] = "ProjectExplorer/Settings/MaxAppOutputLines";
|
||||
|
||||
|
||||
// Output filtering
|
||||
const char FILTER_REGULAR_EXPRESSIONS[] = "OutputFilter.RegularExpressions";
|
||||
const char FILTER_CASE_SENSITIVE[] = "OutputFilter.CaseSensitive";
|
||||
|
||||
}
|
||||
|
||||
namespace ProjectExplorer {
|
||||
@@ -185,7 +178,6 @@ AppOutputPane::AppOutputPane() :
|
||||
m_stopButton(new QToolButton),
|
||||
m_attachButton(new QToolButton),
|
||||
m_settingsButton(new QToolButton),
|
||||
m_filterOutputLineEdit(new Utils::FancyLineEdit),
|
||||
m_formatterWidget(new QWidget)
|
||||
{
|
||||
setObjectName("AppOutputPane"); // Used in valgrind engine
|
||||
@@ -228,33 +220,6 @@ AppOutputPane::AppOutputPane() :
|
||||
Core::ICore::showOptionsDialog(OPTIONS_PAGE_ID);
|
||||
});
|
||||
|
||||
m_filterActionRegexp = new QAction(this);
|
||||
m_filterActionRegexp->setCheckable(true);
|
||||
m_filterActionRegexp->setText(tr("Use Regular Expressions"));
|
||||
connect(m_filterActionRegexp, &QAction::toggled, this, &AppOutputPane::setRegularExpressions);
|
||||
|
||||
Core::ActionManager::registerAction(m_filterActionRegexp, FILTER_REGULAR_EXPRESSIONS);
|
||||
|
||||
m_filterActionCaseSensitive = new QAction(this);
|
||||
m_filterActionCaseSensitive->setCheckable(true);
|
||||
m_filterActionCaseSensitive->setText(tr("Case Sensitive"));
|
||||
connect(m_filterActionCaseSensitive, &QAction::toggled, this, &AppOutputPane::setCaseSensitive);
|
||||
Core::ActionManager::registerAction(m_filterActionCaseSensitive, FILTER_CASE_SENSITIVE);
|
||||
|
||||
m_filterOutputLineEdit->setPlaceholderText(tr("Filter output..."));
|
||||
m_filterOutputLineEdit->setButtonVisible(Utils::FancyLineEdit::Left, true);
|
||||
m_filterOutputLineEdit->setButtonIcon(Utils::FancyLineEdit::Left, Utils::Icons::MAGNIFIER.icon());
|
||||
m_filterOutputLineEdit->setFiltering(true);
|
||||
m_filterOutputLineEdit->setEnabled(false);
|
||||
m_filterOutputLineEdit->setHistoryCompleter("AppOutputPane.Filter");
|
||||
connect(m_filterOutputLineEdit, &Utils::FancyLineEdit::textChanged, this, &AppOutputPane::updateFilter);
|
||||
connect(m_filterOutputLineEdit, &Utils::FancyLineEdit::returnPressed, this, &AppOutputPane::updateFilter);
|
||||
|
||||
connect(m_filterOutputLineEdit, &Utils::FancyLineEdit::leftButtonClicked, this, [&](){
|
||||
if (currentIndex() >= 0)
|
||||
AppOutputPane::filterOutputButtonClicked();
|
||||
});
|
||||
|
||||
auto formatterWidgetsLayout = new QHBoxLayout;
|
||||
formatterWidgetsLayout->setContentsMargins(QMargins());
|
||||
m_formatterWidget->setLayout(formatterWidgetsLayout);
|
||||
@@ -279,6 +244,8 @@ AppOutputPane::AppOutputPane() :
|
||||
connect(SessionManager::instance(), &SessionManager::aboutToUnloadSession,
|
||||
this, &AppOutputPane::aboutToUnloadSession);
|
||||
|
||||
setupFilterUi("AppOutputPane.Filter");
|
||||
setFilteringEnabled(false);
|
||||
setZoomButtonsEnabled(false);
|
||||
}
|
||||
|
||||
@@ -359,7 +326,7 @@ QWidget *AppOutputPane::outputWidget(QWidget *)
|
||||
QList<QWidget*> AppOutputPane::toolBarWidgets() const
|
||||
{
|
||||
return QList<QWidget *>{m_reRunButton, m_stopButton, m_attachButton, m_settingsButton,
|
||||
m_filterOutputLineEdit, m_formatterWidget} + IOutputPane::toolBarWidgets();
|
||||
m_formatterWidget} + IOutputPane::toolBarWidgets();
|
||||
}
|
||||
|
||||
QString AppOutputPane::displayName() const
|
||||
@@ -404,27 +371,9 @@ void AppOutputPane::setFocus()
|
||||
|
||||
void AppOutputPane::updateFilter()
|
||||
{
|
||||
const QString filter = m_filterOutputLineEdit->text();
|
||||
const int index = currentIndex();
|
||||
if (index != -1)
|
||||
m_runControlTabs.at(index).window->setFilterText(filter);
|
||||
}
|
||||
|
||||
void AppOutputPane::filterOutputButtonClicked()
|
||||
{
|
||||
auto popup = new Core::OptionsPopup(m_filterOutputLineEdit,
|
||||
{FILTER_REGULAR_EXPRESSIONS, FILTER_CASE_SENSITIVE});
|
||||
popup->show();
|
||||
}
|
||||
|
||||
void AppOutputPane::setRegularExpressions(bool regularExpressions)
|
||||
{
|
||||
m_filterRegexp = regularExpressions;
|
||||
}
|
||||
|
||||
void AppOutputPane::setCaseSensitive(bool caseSensitive)
|
||||
{
|
||||
m_filterCaseSensitive = caseSensitive;
|
||||
m_runControlTabs.at(index).window->setFilterText(filterText());
|
||||
}
|
||||
|
||||
void AppOutputPane::createNewOutputWindow(RunControl *rc)
|
||||
@@ -517,7 +466,7 @@ void AppOutputPane::createNewOutputWindow(RunControl *rc)
|
||||
m_tabWidget->addTab(ow, rc->displayName());
|
||||
qCDebug(appOutputLog) << "AppOutputPane::createNewOutputWindow: Adding tab for" << rc;
|
||||
updateCloseActions();
|
||||
m_filterOutputLineEdit->setEnabled(m_tabWidget->count() > 0);
|
||||
setFilteringEnabled(m_tabWidget->count() > 0);
|
||||
}
|
||||
|
||||
void AppOutputPane::handleOldOutput(Core::OutputWindow *window) const
|
||||
@@ -679,7 +628,7 @@ void AppOutputPane::closeTab(int tabIndex, CloseTabMode closeTabMode)
|
||||
runControl->initiateFinish(); // Will self-destruct.
|
||||
m_runControlTabs.removeAt(index);
|
||||
updateCloseActions();
|
||||
m_filterOutputLineEdit->setEnabled(m_tabWidget->count() > 0);
|
||||
setFilteringEnabled(m_tabWidget->count() > 0);
|
||||
|
||||
if (m_runControlTabs.isEmpty())
|
||||
hide();
|
||||
@@ -754,7 +703,7 @@ void AppOutputPane::tabChanged(int i)
|
||||
const int index = indexOf(m_tabWidget->widget(i));
|
||||
if (i != -1 && index != -1) {
|
||||
const RunControlTab &controlTab = m_runControlTabs[index];
|
||||
controlTab.window->setFilterText(m_filterOutputLineEdit->text());
|
||||
controlTab.window->setFilterText(filterText());
|
||||
enableButtons(controlTab.runControl);
|
||||
} else {
|
||||
enableDefaultButtons();
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <coreplugin/ioutputpane.h>
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
|
||||
#include <utils/fancylineedit.h>
|
||||
#include <utils/outputformat.h>
|
||||
|
||||
#include <QPointer>
|
||||
@@ -143,11 +142,7 @@ private:
|
||||
int tabWidgetIndexOf(int runControlIndex) const;
|
||||
void handleOldOutput(Core::OutputWindow *window) const;
|
||||
void updateCloseActions();
|
||||
void updateFilter();
|
||||
void filterOutputButtonClicked();
|
||||
|
||||
void setCaseSensitive(bool caseSensitive);
|
||||
void setRegularExpressions(bool regularExpressions);
|
||||
void updateFilter() override;
|
||||
|
||||
void loadSettings();
|
||||
void storeSettings() const;
|
||||
@@ -164,13 +159,8 @@ private:
|
||||
QToolButton *m_stopButton;
|
||||
QToolButton *m_attachButton;
|
||||
QToolButton * const m_settingsButton;
|
||||
QAction *m_filterActionRegexp = nullptr;
|
||||
QAction *m_filterActionCaseSensitive = nullptr;
|
||||
Utils::FancyLineEdit *m_filterOutputLineEdit = nullptr;
|
||||
QWidget *m_formatterWidget;
|
||||
AppOutputSettings m_settings;
|
||||
bool m_filterRegexp = false;
|
||||
bool m_filterCaseSensitive = false;
|
||||
};
|
||||
|
||||
class AppOutputSettingsPage : public Core::IOptionsPage
|
||||
|
||||
Reference in New Issue
Block a user