1
0
Fork 0

Merge pull request #2817 from rajkumarananthu/feature_search_in_log

Adding search action in LogView
This commit is contained in:
Duncan Ogilvie 2022-02-24 14:44:50 +01:00 committed by GitHub
commit 048825e30a
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 0 deletions

View File

@ -40,6 +40,8 @@ LogView::LogView(QWidget* parent) : QTextBrowser(parent), logRedirection(NULL)
connect(Bridge::getBridge(), SIGNAL(setLogEnabled(bool)), this, SLOT(setLoggingEnabled(bool)));
connect(Bridge::getBridge(), SIGNAL(flushLog()), this, SLOT(flushLogSlot()));
connect(this, SIGNAL(anchorClicked(QUrl)), this, SLOT(onAnchorClicked(QUrl)));
dialogFindInLog = new LineEditDialog(this);
dialogFindInLog->setWindowTitle(tr("Find For"));
duint setting;
if(BridgeSettingGetUint("Misc", "Utf16LogRedirect", &setting))
@ -105,6 +107,9 @@ void LogView::setupContextMenu()
menuCopyToNotes->addAction(actionCopyToDebuggeeNotes);
actionAutoScroll->setCheckable(true);
actionAutoScroll->setChecked(autoScroll);
actionFindInLog = setupAction(tr("Find"), this, SLOT(findInLogSlot()));
actionFindNext = setupAction(tr("Find Next Occurance"), this, SLOT(findNextInLogSlot()));;
actionFindPrevious = setupAction(tr("Find Previous Occurance"), this, SLOT(findPreviousInLogSlot()));
refreshShortcutsSlot();
connect(Config(), SIGNAL(shortcutsUpdated()), this, SLOT(refreshShortcutsSlot()));
@ -116,6 +121,9 @@ void LogView::refreshShortcutsSlot()
actionCopy->setShortcut(ConfigShortcut("ActionCopy"));
actionToggleLogging->setShortcut(ConfigShortcut("ActionToggleLogging"));
actionRedirectLog->setShortcut(ConfigShortcut("ActionRedirectLog"));
actionFindInLog->setShortcut(ConfigShortcut("ActionFind"));
actionFindNext->setShortcut(ConfigShortcut("ActionGotoNext"));
actionFindPrevious->setShortcut(ConfigShortcut("ActionGotoPrevious"));
}
void LogView::contextMenuEvent(QContextMenuEvent* event)
@ -136,6 +144,9 @@ void LogView::contextMenuEvent(QContextMenuEvent* event)
wMenu.addAction(actionToggleLogging);
actionAutoScroll->setChecked(autoScroll);
wMenu.addAction(actionAutoScroll);
wMenu.addAction(actionFindInLog);
wMenu.addAction(actionFindNext);
wMenu.addAction(actionFindPrevious);
if(logRedirection == NULL)
actionRedirectLog->setText(tr("&Redirect Log..."));
else
@ -415,6 +426,48 @@ void LogView::copyToDebuggeeNotes()
emit Bridge::getBridge()->setDebuggeeNotes(Notes);
}
void LogView::findNextInLogSlot()
{
find(QRegExp(lastFindText));
}
void LogView::findPreviousInLogSlot()
{
find(QRegExp(lastFindText), QTextDocument::FindBackward);
}
void LogView::findInLogSlot()
{
dialogFindInLog->show();
if(dialogFindInLog->exec() == QDialog::Accepted)
{
QList<QTextEdit::ExtraSelection> extraSelections;
QColor highlight = ConfigColor("SearchListViewHighlightColor");
QColor background = ConfigColor("SearchListViewHighlightBackgroundColor");
// capturing the current location, so that we can reset it once capturing all the
// extra selections
QTextCursor resetCursorLoc = textCursor();
moveCursor(QTextCursor::Start);
// finding all occurances matching the regex given from start
while(find(QRegExp(dialogFindInLog->editText)))
{
QTextEdit::ExtraSelection extra;
extra.format.setForeground(highlight);
extra.format.setBackground(background);
extra.cursor = textCursor();
extraSelections.append(extra);
}
// highlighting all those selections
setExtraSelections(extraSelections);
setTextCursor(resetCursorLoc); // resetting the cursor location
find(QRegExp(dialogFindInLog->editText));
lastFindText = dialogFindInLog->editText;
}
}
void LogView::pasteSlot()
{
QString clipboardText = QApplication::clipboard()->text();

View File

@ -2,6 +2,7 @@
#include <QTextBrowser>
#include <cstdio>
#include "LineEditDialog.h"
class LogView : public QTextBrowser
{
@ -21,6 +22,9 @@ public slots:
void redirectLogSlot();
void setLoggingEnabled(bool enabled);
void autoScrollSlot();
void findInLogSlot();
void findNextInLogSlot();
void findPreviousInLogSlot();
void copyToGlobalNotes();
void copyToDebuggeeNotes();
void pasteSlot();
@ -51,9 +55,14 @@ private:
QMenu* menuCopyToNotes;
QAction* actionCopyToGlobalNotes;
QAction* actionCopyToDebuggeeNotes;
QAction* actionFindInLog;
QAction* actionFindNext;
QAction* actionFindPrevious;
LineEditDialog* dialogFindInLog;
FILE* logRedirection;
QString logBuffer;
QTimer* flushTimer;
bool flushLog;
QString lastFindText;
};