From df3663bfabc9de99a7338ea0a19a1101a8dbc703 Mon Sep 17 00:00:00 2001 From: Marc Bartholomaeus Date: Thu, 18 Apr 2013 01:01:10 +0200 Subject: [PATCH 1/5] cmake-gui: Add search functions for Output window (#9733) Signed-off-by: Alex Neundorf --- Source/QtDialog/CMakeSetupDialog.cxx | 72 ++++++++++++++++++++++++++++ Source/QtDialog/CMakeSetupDialog.h | 4 ++ 2 files changed, 76 insertions(+) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index c0dde1c2c..3cf799f79 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include "QCMake.h" #include "QCMakeCacheView.h" @@ -122,6 +123,16 @@ CMakeSetupDialog::CMakeSetupDialog() QObject::connect(this->InstallForCommandLineAction, SIGNAL(triggered(bool)), this, SLOT(doInstallForCommandLine())); #endif + ToolsMenu->addSeparator(); + ToolsMenu->addAction(tr("&Find in Output..."), + this, SLOT(doOutputFindDialog())); + ToolsMenu->addAction(tr("&Find Next"), + this, SLOT(doOutputFindNext()), + QKeySequence::FindNext); + ToolsMenu->addAction(tr("&Find Previous"), + this, SLOT(doOutputFindPrev()), + QKeySequence::FindPrevious); + QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options")); this->SuppressDevWarningsAction = OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)")); @@ -1149,4 +1160,65 @@ void CMakeSetupDialog::setSearchFilter(const QString& str) this->CacheValues->setSearchFilter(str); } +void CMakeSetupDialog::doOutputFindDialog() +{ + QStringList strings(this->FindHistory); + QString selection = this->Output->textCursor().selectedText(); + if (!selection.isEmpty() && !selection.contains(QChar::ParagraphSeparator)) + { + strings.push_front(selection); + } + + bool ok; + QString search = QInputDialog::getItem(this, tr("Find in Output"), + tr("Find:"), strings, 0, true, &ok); + if (ok && !search.isEmpty()) + { + if (!this->FindHistory.contains(search)) + { + this->FindHistory.push_front(search); + } + doOutputFindNext(); + } +} + +void CMakeSetupDialog::doOutputFindPrev() +{ + doOutputFindNext(false); +} + +void CMakeSetupDialog::doOutputFindNext(bool directionForward) +{ + if (this->FindHistory.isEmpty()) + { + doOutputFindDialog(); //will re-call this function again + return; + } + + QString search = this->FindHistory.front(); + + QTextCursor cursor = this->Output->textCursor(); + QTextDocument* document = this->Output->document(); + QTextDocument::FindFlags flags; + if (!directionForward) + { + flags |= QTextDocument::FindBackward; + } + + cursor = document->find(search, cursor, flags); + + if (cursor.isNull()) + { + // first search found nothing, wrap around and search again + cursor = this->Output->textCursor(); + cursor.movePosition(directionForward ? QTextCursor::Start + : QTextCursor::End); + cursor = document->find(search, cursor, flags); + } + + if (cursor.hasSelection()) + { + this->Output->setTextCursor(cursor); + } +} diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index 259967580..88fefccf3 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -77,6 +77,9 @@ protected slots: bool doConfigureInternal(); bool doGenerateInternal(); void exitLoop(int); + void doOutputFindDialog(); + void doOutputFindNext(bool directionForward = true); + void doOutputFindPrev(); protected: @@ -106,6 +109,7 @@ protected: QTextCharFormat MessageFormat; QStringList AddVariableCompletions; + QStringList FindHistory; QEventLoop LocalLoop; From 4ce65e82f5865469f392b0d021da588366bc14c3 Mon Sep 17 00:00:00 2001 From: Marc Bartholomaeus Date: Thu, 18 Apr 2013 00:53:12 +0200 Subject: [PATCH 2/5] cmake-gui: Add search functions to the context menu of the Output widget Signed-off-by: Alex Neundorf --- Source/QtDialog/CMakeSetupDialog.cxx | 20 ++++++++++++++++++++ Source/QtDialog/CMakeSetupDialog.h | 1 + 2 files changed, 21 insertions(+) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 3cf799f79..0be45c6c7 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -183,6 +183,10 @@ CMakeSetupDialog::CMakeSetupDialog() this->Output->setFont(outputFont); this->ErrorFormat.setForeground(QBrush(Qt::red)); + this->Output->setContextMenuPolicy(Qt::CustomContextMenu); + connect(this->Output, SIGNAL(customContextMenuRequested(const QPoint&)), + this, SLOT(doOutputContextMenu(const QPoint &))); + // start the cmake worker thread this->CMakeThread = new QCMakeThread(this); QObject::connect(this->CMakeThread, SIGNAL(cmakeInitialized()), @@ -1160,6 +1164,22 @@ void CMakeSetupDialog::setSearchFilter(const QString& str) this->CacheValues->setSearchFilter(str); } +void CMakeSetupDialog::doOutputContextMenu(const QPoint &pt) +{ + QMenu *menu = this->Output->createStandardContextMenu(); + + menu->addSeparator(); + menu->addAction(tr("Find..."), + this, SLOT(doOutputFindDialog())); + menu->addAction(tr("Find Next"), + this, SLOT(doOutputFindNext()), QKeySequence::FindNext); + menu->addAction(tr("Find Previous"), + this, SLOT(doOutputFindPrev()), QKeySequence::FindPrevious); + + menu->exec(this->Output->mapToGlobal(pt)); + delete menu; +} + void CMakeSetupDialog::doOutputFindDialog() { QStringList strings(this->FindHistory); diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index 88fefccf3..100834d32 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -77,6 +77,7 @@ protected slots: bool doConfigureInternal(); bool doGenerateInternal(); void exitLoop(int); + void doOutputContextMenu(const QPoint &); void doOutputFindDialog(); void doOutputFindNext(bool directionForward = true); void doOutputFindPrev(); From 7be2d8acc64e371748b8758f16b7aa6bdaf3fd0f Mon Sep 17 00:00:00 2001 From: Marc Bartholomaeus Date: Thu, 18 Apr 2013 01:03:02 +0200 Subject: [PATCH 3/5] cmake-gui: Change shortcut of the search field from Ctrl-F to Alt-E Ctrl-F is now used by "Find in Output". Signed-off-by: Alex Neundorf --- Source/QtDialog/CMakeSetupDialog.cxx | 9 +++------ Source/QtDialog/CMakeSetupDialog.ui | 5 ++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 0be45c6c7..fb74aafe5 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -125,7 +125,8 @@ CMakeSetupDialog::CMakeSetupDialog() #endif ToolsMenu->addSeparator(); ToolsMenu->addAction(tr("&Find in Output..."), - this, SLOT(doOutputFindDialog())); + this, SLOT(doOutputFindDialog()), + QKeySequence::Find); ToolsMenu->addAction(tr("&Find Next"), this, SLOT(doOutputFindNext()), QKeySequence::FindNext); @@ -165,10 +166,6 @@ CMakeSetupDialog::CMakeSetupDialog() QObject::connect(a, SIGNAL(triggered(bool)), this, SLOT(doHelp())); - QShortcut* filterShortcut = new QShortcut(QKeySequence::Find, this); - QObject::connect(filterShortcut, SIGNAL(activated()), - this, SLOT(startSearch())); - this->setAcceptDrops(true); // get the saved binary directories @@ -1170,7 +1167,7 @@ void CMakeSetupDialog::doOutputContextMenu(const QPoint &pt) menu->addSeparator(); menu->addAction(tr("Find..."), - this, SLOT(doOutputFindDialog())); + this, SLOT(doOutputFindDialog()), QKeySequence::Find); menu->addAction(tr("Find Next"), this, SLOT(doOutputFindNext()), QKeySequence::FindNext); menu->addAction(tr("Find Previous"), diff --git a/Source/QtDialog/CMakeSetupDialog.ui b/Source/QtDialog/CMakeSetupDialog.ui index dc8ee3fbd..98da249d5 100644 --- a/Source/QtDialog/CMakeSetupDialog.ui +++ b/Source/QtDialog/CMakeSetupDialog.ui @@ -107,7 +107,10 @@ - Search: + S&earch: + + + Search From 6e57724fc3f95f954666fbe9c33ea14e22c858a3 Mon Sep 17 00:00:00 2001 From: Marc Bartholomaeus Date: Thu, 18 Apr 2013 01:06:00 +0200 Subject: [PATCH 4/5] cmake-gui: Add function for going to next error message in Output window Using new shortcuts: F8 (Visual Studio) and Ctrl-. (Eclipse) Signed-off-by: Alex Neundorf --- Source/QtDialog/CMakeSetupDialog.cxx | 68 +++++++++++++++++++++++++++- Source/QtDialog/CMakeSetupDialog.h | 1 + 2 files changed, 67 insertions(+), 2 deletions(-) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index fb74aafe5..91279fd35 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -133,6 +133,11 @@ CMakeSetupDialog::CMakeSetupDialog() ToolsMenu->addAction(tr("&Find Previous"), this, SLOT(doOutputFindPrev()), QKeySequence::FindPrevious); + ToolsMenu->addAction(tr("Goto Next Error"), + this, SLOT(doOutputErrorNext()), + QKeySequence(Qt::Key_F8)); // in Visual Studio + new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Period), + this, SLOT(doOutputErrorNext())); // in Eclipse QMenu* OptionsMenu = this->menuBar()->addMenu(tr("&Options")); this->SuppressDevWarningsAction = @@ -649,7 +654,13 @@ void CMakeSetupDialog::showProgress(const QString& /*msg*/, float percent) void CMakeSetupDialog::error(const QString& msg) { this->Output->setCurrentCharFormat(this->ErrorFormat); - this->Output->append(msg); + //QTextEdit will terminate the msg with a ParagraphSeparator, but it also replaces + //all newlines with ParagraphSeparators. By replacing the newlines by ourself, one + //error msg will be one paragraph. + QString paragraph(msg); + paragraph.replace(QLatin1Char('\n'), QChar::LineSeparator); + this->Output->append(paragraph); + } void CMakeSetupDialog::message(const QString& msg) @@ -1172,6 +1183,9 @@ void CMakeSetupDialog::doOutputContextMenu(const QPoint &pt) this, SLOT(doOutputFindNext()), QKeySequence::FindNext); menu->addAction(tr("Find Previous"), this, SLOT(doOutputFindPrev()), QKeySequence::FindPrevious); + menu->addSeparator(); + menu->addAction(tr("Goto Next Error"), + this, SLOT(doOutputErrorNext()), QKeySequence(Qt::Key_F8)); menu->exec(this->Output->mapToGlobal(pt)); delete menu; @@ -1182,7 +1196,9 @@ void CMakeSetupDialog::doOutputFindDialog() QStringList strings(this->FindHistory); QString selection = this->Output->textCursor().selectedText(); - if (!selection.isEmpty() && !selection.contains(QChar::ParagraphSeparator)) + if (!selection.isEmpty() && + !selection.contains(QChar::ParagraphSeparator) && + !selection.contains(QChar::LineSeparator)) { strings.push_front(selection); } @@ -1239,3 +1255,51 @@ void CMakeSetupDialog::doOutputFindNext(bool directionForward) this->Output->setTextCursor(cursor); } } + +void CMakeSetupDialog::doOutputErrorNext() +{ + QTextCursor cursor = this->Output->textCursor(); + bool atEnd = false; + + // move cursor out of current error-block + if (cursor.blockCharFormat() == this->ErrorFormat) + { + atEnd = !cursor.movePosition(QTextCursor::NextBlock); + } + + // move cursor to next error-block + while (cursor.blockCharFormat() != this->ErrorFormat && !atEnd) + { + atEnd = !cursor.movePosition(QTextCursor::NextBlock); + } + + if (atEnd) + { + // first search found nothing, wrap around and search again + atEnd = !cursor.movePosition(QTextCursor::Start); + + // move cursor to next error-block + while (cursor.blockCharFormat() != this->ErrorFormat && !atEnd) + { + atEnd = !cursor.movePosition(QTextCursor::NextBlock); + } + } + + if (!atEnd) + { + cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + + QTextCharFormat selectionFormat; + selectionFormat.setBackground(Qt::yellow); + QTextEdit::ExtraSelection extraSelection = {cursor, selectionFormat}; + this->Output->setExtraSelections(QList() + << extraSelection); + + // make the whole error-block visible + this->Output->setTextCursor(cursor); + + // remove the selection to see the extraSelection + cursor.setPosition(cursor.anchor()); + this->Output->setTextCursor(cursor); + } +} diff --git a/Source/QtDialog/CMakeSetupDialog.h b/Source/QtDialog/CMakeSetupDialog.h index 100834d32..963c7d12e 100644 --- a/Source/QtDialog/CMakeSetupDialog.h +++ b/Source/QtDialog/CMakeSetupDialog.h @@ -81,6 +81,7 @@ protected slots: void doOutputFindDialog(); void doOutputFindNext(bool directionForward = true); void doOutputFindPrev(); + void doOutputErrorNext(); protected: From f92d7e7f9541f74357d55ccc6781a8fe6c3bb8e9 Mon Sep 17 00:00:00 2001 From: Alex Neundorf Date: Thu, 18 Apr 2013 19:59:11 +0200 Subject: [PATCH 5/5] cmake-gui: use shortcut F only for "Find in Output" Before it was used also for "Find Next" and "Find Previous" Alex --- Source/QtDialog/CMakeSetupDialog.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/QtDialog/CMakeSetupDialog.cxx b/Source/QtDialog/CMakeSetupDialog.cxx index 91279fd35..4d62f7263 100644 --- a/Source/QtDialog/CMakeSetupDialog.cxx +++ b/Source/QtDialog/CMakeSetupDialog.cxx @@ -127,10 +127,10 @@ CMakeSetupDialog::CMakeSetupDialog() ToolsMenu->addAction(tr("&Find in Output..."), this, SLOT(doOutputFindDialog()), QKeySequence::Find); - ToolsMenu->addAction(tr("&Find Next"), + ToolsMenu->addAction(tr("Find Next"), this, SLOT(doOutputFindNext()), QKeySequence::FindNext); - ToolsMenu->addAction(tr("&Find Previous"), + ToolsMenu->addAction(tr("Find Previous"), this, SLOT(doOutputFindPrev()), QKeySequence::FindPrevious); ToolsMenu->addAction(tr("Goto Next Error"),