Merge topic 'QtDialogSearchText2'
f92d7e7
cmake-gui: use shortcut F only for "Find in Output"6e57724
cmake-gui: Add function for going to next error message in Output window7be2d8a
cmake-gui: Change shortcut of the search field from Ctrl-F to Alt-E4ce65e8
cmake-gui: Add search functions to the context menu of the Output widgetdf3663b
cmake-gui: Add search functions for Output window (#9733)
This commit is contained in:
commit
3e6f5ff33c
|
@ -28,6 +28,7 @@
|
|||
#include <QShortcut>
|
||||
#include <QKeySequence>
|
||||
#include <QMacInstallDialog.h>
|
||||
#include <QInputDialog>
|
||||
|
||||
#include "QCMake.h"
|
||||
#include "QCMakeCacheView.h"
|
||||
|
@ -122,6 +123,22 @@ CMakeSetupDialog::CMakeSetupDialog()
|
|||
QObject::connect(this->InstallForCommandLineAction, SIGNAL(triggered(bool)),
|
||||
this, SLOT(doInstallForCommandLine()));
|
||||
#endif
|
||||
ToolsMenu->addSeparator();
|
||||
ToolsMenu->addAction(tr("&Find in Output..."),
|
||||
this, SLOT(doOutputFindDialog()),
|
||||
QKeySequence::Find);
|
||||
ToolsMenu->addAction(tr("Find Next"),
|
||||
this, SLOT(doOutputFindNext()),
|
||||
QKeySequence::FindNext);
|
||||
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 =
|
||||
OptionsMenu->addAction(tr("&Suppress dev Warnings (-Wno-dev)"));
|
||||
|
@ -154,10 +171,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
|
||||
|
@ -172,6 +185,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()),
|
||||
|
@ -637,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)
|
||||
|
@ -1149,4 +1172,134 @@ 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()), QKeySequence::Find);
|
||||
menu->addAction(tr("Find Next"),
|
||||
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;
|
||||
}
|
||||
|
||||
void CMakeSetupDialog::doOutputFindDialog()
|
||||
{
|
||||
QStringList strings(this->FindHistory);
|
||||
|
||||
QString selection = this->Output->textCursor().selectedText();
|
||||
if (!selection.isEmpty() &&
|
||||
!selection.contains(QChar::ParagraphSeparator) &&
|
||||
!selection.contains(QChar::LineSeparator))
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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<QTextEdit::ExtraSelection>()
|
||||
<< 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,6 +77,11 @@ protected slots:
|
|||
bool doConfigureInternal();
|
||||
bool doGenerateInternal();
|
||||
void exitLoop(int);
|
||||
void doOutputContextMenu(const QPoint &);
|
||||
void doOutputFindDialog();
|
||||
void doOutputFindNext(bool directionForward = true);
|
||||
void doOutputFindPrev();
|
||||
void doOutputErrorNext();
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -106,6 +111,7 @@ protected:
|
|||
QTextCharFormat MessageFormat;
|
||||
|
||||
QStringList AddVariableCompletions;
|
||||
QStringList FindHistory;
|
||||
|
||||
QEventLoop LocalLoop;
|
||||
|
||||
|
|
|
@ -107,7 +107,10 @@
|
|||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Search:</string>
|
||||
<string>S&earch:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>Search</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
Loading…
Reference in New Issue