Skip to content

Commit

Permalink
- support live grep
Browse files Browse the repository at this point in the history
- default limit search result to 30000 row
- autocomplete suggestion sorted by levenshtein distance
- update screen cast
  • Loading branch information
ychclone committed Oct 5, 2021
1 parent 0184a18 commit 4e9bede
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 246 deletions.
11 changes: 11 additions & 0 deletions Display/CConfigDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <QFileDialog>

#include <QFontDialog>
#include <QDebug>

#include "CConfigDlg.h"
#include "Model/CConfigManager.h"
Expand Down Expand Up @@ -86,6 +87,12 @@ void CConfigDlg::loadSetting()
defaultMaskForNewProject_lineEdit->setText("*.cpp *.c *.h *.hpp *.go *.java *.js *.py *.scala *.ts *.v *.vh *.sv *.svh *.yaml *.xml");
}

unsigned int limitSearchRow = confManager->getAppSettingValue("limitSearchRow").toUInt();
if (limitSearchRow == 0) { // default setting
limitSearchRow_lineEdit->setText("30000");
} else {
limitSearchRow_lineEdit->setText(QString::number(limitSearchRow));
}
}

void CConfigDlg::saveSetting()
Expand All @@ -106,6 +113,8 @@ void CConfigDlg::saveSetting()

confManager->setAppSettingValue("UseExternalEditor", useExternalEditor_checkBox->isChecked());
confManager->setAppSettingValue("defaultMaskForNewProject", defaultMaskForNewProject_lineEdit->text());

confManager->setAppSettingValue("limitSearchRow", limitSearchRow_lineEdit->text());
}

void CConfigDlg::createActions()
Expand All @@ -126,6 +135,8 @@ void CConfigDlg::createActions()

QObject::connect(useExternalEditor_checkBox, &QCheckBox::stateChanged, this, &CConfigDlg::configContentChanged);
QObject::connect(defaultMaskForNewProject_lineEdit, SIGNAL(textChanged(QString)), this, SLOT(configContentChanged()));

QObject::connect(limitSearchRow_lineEdit, SIGNAL(textChanged(QString)), this, SLOT(configContentChanged()));
}

void CConfigDlg::changePage(QListWidgetItem *current, QListWidgetItem *previous)
Expand Down
81 changes: 63 additions & 18 deletions Display/CMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ bTagBuildInProgress_(false)
bool bFileFilterCaseSensitive;
bool bSymbolSearchCaseSensitive;
bool bSymbolSearchRegularExpression;
bool bLiveSearch;

bProjectAndGroupFilterCaseSensitive = confManager_->getAppSettingValue("ProjectAndGroupFilterCaseSensitive", false).toBool();
if (bProjectAndGroupFilterCaseSensitive) {
Expand Down Expand Up @@ -297,6 +298,14 @@ bTagBuildInProgress_(false)
actionSymbolRegularExpression->setChecked(false);
}

// live search
bLiveSearch = confManager_->getAppSettingValue("LiveSearch", true).toBool();
if (bLiveSearch) {
actionLiveSearch->setChecked(true);
} else {
actionLiveSearch->setChecked(false);
}

createActions();
}

Expand Down Expand Up @@ -436,13 +445,14 @@ void CMainWindow::loadFileList()

foreach (const CFileItem& fileItem, fileItemList_) {
fileListModel_->addItem(fileItem);
if (eventLoopCounter >= 1000) { // prevent ui freeze
if (eventLoopCounter >= 2000) { // prevent ui freeze
updateFileListWidget();
QCoreApplication::processEvents();
eventLoopCounter = 0;
}
eventLoopCounter++;
}

updateFileListWidget();
}

Expand Down Expand Up @@ -588,6 +598,7 @@ void CMainWindow::createActions()
#else
symbol_textBrowser->setReadOnly(true);
symbol_textBrowser->setLineWrapMode(QPlainTextEdit::NoWrap);
//symbol_textBrowser->setUndoRedoEnabled(false);

QTextCharFormat charFormat;
charFormat.setFontFamily("Consolas");
Expand Down Expand Up @@ -671,6 +682,8 @@ void CMainWindow::on_loadProjectButton_clicked()
projectLoadThread_.setTaggerPtr(&tagger_);
projectLoadThread_.setFileItemListPtr(&fileItemList_);

search_lineEdit->setEnabled(false);

projectLoadThread_.start();

setWindowTitle(projectItemName + " - Blink");
Expand Down Expand Up @@ -1164,6 +1177,17 @@ void CMainWindow::on_actionAlways_on_top_toggled()
on_actionTransparent_toggled(); // still transparency
}

void CMainWindow::on_actionLiveSearch_toggled()
{
qDebug() << "on_actionLiveSearch_toggled IN";

if (actionLiveSearch->isChecked()) {
confManager_->setAppSettingValue("LiveSearch", true);
} else {
confManager_->setAppSettingValue("LiveSearch", false);
}
}

void CMainWindow::setTransparency(bool enable)
{
if (enable) {
Expand Down Expand Up @@ -1356,9 +1380,13 @@ void CMainWindow::updateProjectLoadProgress(int percentage)
search_lineEdit->clear(); // clear symbol search line edit
symbol_textBrowser->clear(); // clear symbol text widget as well

search_lineEdit->setEnabled(true);

statusBar()->showMessage("Project " + currentProjectItem_.name_ + " loaded.");
} else if (percentage == 0) {
statusBar()->showMessage("Failed to load Project " + currentProjectItem_.name_ + ".");

search_lineEdit->setEnabled(true);
}
}

Expand Down Expand Up @@ -1521,7 +1549,12 @@ void CMainWindow::searchLineEditChanged()
}

QStringList tagList;
tagger_.getMatchedTags(search_lineEdit->text(), tagList, caseSensitivity);
QMap<int, QString> tagMap;
tagger_.getMatchedTags(search_lineEdit->text(), tagMap, caseSensitivity);

for (auto tag: tagMap) {
tagList.push_back(tag);
}

stringListModel_.setStringList(tagList);

Expand All @@ -1531,6 +1564,11 @@ void CMainWindow::searchLineEditChanged()
completer_.setFilterMode(Qt::MatchContains);

search_lineEdit->setCompleter(&completer_);

bool bLiveSearch = confManager_->getAppSettingValue("LiveSearch", true).toBool();
if (bLiveSearch) {
queryTagRowLimit(search_lineEdit->text(), 1000);
}
}

void CMainWindow::on_symbolSearchFrameShortcutPressed()
Expand Down Expand Up @@ -1907,6 +1945,19 @@ void CMainWindow::on_filePropertiesPressed()

void CMainWindow::queryTag(const QString& tag)
{
unsigned int limitSearchRow = confManager_->getAppSettingValue("limitSearchRow").toUInt();
if (limitSearchRow == 0) {
limitSearchRow = 30000;
}

queryTagRowLimit(tag, limitSearchRow);
}

void CMainWindow::queryTagRowLimit(const QString& tag, unsigned int limitSearchRow)
{
QElapsedTimer timerQuery;
timerQuery.start();

QString tagDbFileName, inputFileName;

QString resultHtml;
Expand All @@ -1931,7 +1982,6 @@ void CMainWindow::queryTag(const QString& tag)
webView->show();
*/

QString funcSignatureToPrint;
QString lineSrcBeforeToPrint;
QString lineSrcAfterToPrint;

Expand All @@ -1950,8 +2000,7 @@ void CMainWindow::queryTag(const QString& tag)
QElapsedTimer timer;
timer.start();

//tagger_.queryTag(inputFileName, tagDbFileName, tag, tagToQueryFiltered, resultList, caseSensitivity, bSymbolRegularExpression);
tagger_.queryTagLoadedSymbol(fileItemList_, tag, tagToQueryFiltered, resultList, caseSensitivity, bSymbolRegularExpression);
tagger_.queryTagLoadedSymbol(fileItemList_, tag, tagToQueryFiltered, resultList, caseSensitivity, bSymbolRegularExpression, limitSearchRow);

qDebug() << "queryTag took" << timer.elapsed() << "ms";

Expand All @@ -1977,14 +2026,9 @@ void CMainWindow::queryTag(const QString& tag)
resultItemSrcLine = resultItemSrcLine.toHtmlEscaped();
resultItemSrcLine.replace(tagToQuery, "<keyword>" + tagToQuery + "</keyword>", Qt::CaseSensitive);

funcSignatureToPrint = "";
lineSrcBeforeToPrint = "";
lineSrcAfterToPrint = "";

if (resultItem.functionSignature_ != "") {
funcSignatureToPrint = "<functionsig>&nbsp;&nbsp;&nbsp;" + resultItem.functionSignature_ + "</functionsig>";
}

minIndent = resultItem.lineSrcIndentLevel_;

if (resultItem.beforeIndentLevelList_.size() > 0) {
Expand Down Expand Up @@ -2044,18 +2088,13 @@ void CMainWindow::queryTag(const QString& tag)
}
}

resultHtml += QString("<div class=\"itemblock\"><div class=\"header\">") +
"<a href=\"" + resultItem.filePath_ + "#" + QString::number(resultItem.fileLineNum_) + "\">" +
resultItemFileInfo.fileName() + "</a>" +
funcSignatureToPrint +
"</div><code>" +
resultHtml += QString("<div><a href=\"") + resultItem.filePath_ + "#" + QString::number(resultItem.fileLineNum_) + "\">" +
resultItemFileInfo.fileName() + "</a></div>" +
lineSrcBeforeToPrint +

"<linenum>" + QString::number(resultItem.fileLineNum_) + "</linenum> " +
resultItemSrcLine +

lineSrcAfterToPrint +
"</code></div><div><spacesize>&nbsp;</spacesize></div>";
lineSrcAfterToPrint + "<div><spacesize>&nbsp;</spacesize></div>";

//qDebug() << "resultHtml = " << resultHtml << endl;

Expand Down Expand Up @@ -2087,10 +2126,15 @@ void CMainWindow::queryTag(const QString& tag)
symbol_textBrowser->setHtml(resultHtml);
symbol_textBrowser->show();
#else
QElapsedTimer timerSetHtml;
timerSetHtml.start();

textDocument_.setHtml(resultHtml);

qDebug() << "setHtml took" << timerSetHtml.elapsed() << "ms";

symbol_textBrowser->setDocument(&textDocument_);

symbol_textBrowser->show();
/*
symbol_textBrowser->clear();
Expand All @@ -2109,6 +2153,7 @@ void CMainWindow::queryTag(const QString& tag)

}

qDebug() << "queryTag full took" << timerQuery.elapsed() << "ms";
}

void CMainWindow::on_searchButton_clicked()
Expand Down
3 changes: 3 additions & 0 deletions Display/CMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ private slots:
void on_nextSymbolButton_clicked();
void on_previousSymbolButton_clicked();

void on_actionLiveSearch_toggled();

void frameSymbolLineEditChanged();

void on_cancelTagUpdate();
Expand All @@ -142,6 +144,7 @@ private slots:
void keyPressEvent(QKeyEvent *event);

void queryTag(const QString& tag);
void queryTagRowLimit(const QString& tag, unsigned int limitSearchRow);

private:
void updateProjectListWidget();
Expand Down
Loading

0 comments on commit 4e9bede

Please sign in to comment.