work done: find in files
This commit is contained in:
parent
ecc4934fd3
commit
82f548a3b8
|
@ -111,9 +111,12 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
mSearchResultTreeModel = std::make_shared<SearchResultTreeModel>(&mSearchResultModel);
|
||||
mSearchResultListModel = std::make_shared<SearchResultListModel>(&mSearchResultModel);
|
||||
mSearchViewDelegate = std::make_shared<SearchResultTreeViewDelegate>(mSearchResultTreeModel);
|
||||
ui->cbSearchHistory->view()->setModel(mSearchResultListModel.get());
|
||||
ui->cbSearchHistory->setModel(mSearchResultListModel.get());
|
||||
ui->searchView->setModel(mSearchResultTreeModel.get());
|
||||
ui->searchView->setItemDelegate(mSearchViewDelegate.get());
|
||||
connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset,
|
||||
ui->searchView,&QTreeView::expandAll);
|
||||
ui->replacePanel->setVisible(false);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -180,6 +183,11 @@ void MainWindow::updateEditorActions()
|
|||
ui->actionStep_Out->setEnabled(false);
|
||||
ui->actionContinue->setEnabled(false);
|
||||
ui->actionRun_To_Cursor->setEnabled(false);
|
||||
|
||||
ui->actionFind->setEnabled(false);
|
||||
ui->actionReplace->setEnabled(false);
|
||||
ui->actionFind_Next->setEnabled(false);
|
||||
ui->actionFind_Previous->setEnabled(false);
|
||||
} else {
|
||||
ui->actionAuto_Detect->setEnabled(true);
|
||||
ui->actionEncode_in_ANSI->setEnabled(true);
|
||||
|
@ -203,6 +211,11 @@ void MainWindow::updateEditorActions()
|
|||
ui->actionUnIndent->setEnabled(!e->readOnly() && e->lines()->count()>0);
|
||||
ui->actionUnfoldAll->setEnabled(e->lines()->count()>0);
|
||||
|
||||
ui->actionFind->setEnabled(true);
|
||||
ui->actionReplace->setEnabled(true);
|
||||
ui->actionFind_Next->setEnabled(true);
|
||||
ui->actionFind_Previous->setEnabled(true);
|
||||
|
||||
updateCompileActions();
|
||||
}
|
||||
|
||||
|
@ -826,6 +839,12 @@ void MainWindow::debug()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::showSearchPanel()
|
||||
{
|
||||
openCloseMessageSheet(true);
|
||||
ui->tabMessages->setCurrentWidget(ui->tabSearch);
|
||||
}
|
||||
|
||||
void MainWindow::openCloseMessageSheet(bool open)
|
||||
{
|
||||
// if Assigned(fReportToolWindow) then
|
||||
|
@ -1533,12 +1552,28 @@ void MainWindow::on_actionFind_triggered()
|
|||
|
||||
void MainWindow::on_actionFind_in_files_triggered()
|
||||
{
|
||||
|
||||
if (mSearchDialog==nullptr) {
|
||||
mSearchDialog = new SearchDialog(this);
|
||||
}
|
||||
Editor *e = mEditorList->getEditor();
|
||||
if (e) {
|
||||
QString s = e->WordAtCursor();
|
||||
mSearchDialog->findInFiles(s);
|
||||
} else {
|
||||
mSearchDialog->findInFiles("");
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionReplace_triggered()
|
||||
{
|
||||
|
||||
Editor *e = mEditorList->getEditor();
|
||||
if (!e)
|
||||
return;
|
||||
if (mSearchDialog==nullptr) {
|
||||
mSearchDialog = new SearchDialog(this);
|
||||
}
|
||||
QString s = e->WordAtCursor();
|
||||
mSearchDialog->replace(s,s);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionFind_Next_triggered()
|
||||
|
@ -1564,3 +1599,22 @@ void MainWindow::on_actionFind_Previous_triggered()
|
|||
|
||||
mSearchDialog->findPrevious();
|
||||
}
|
||||
|
||||
void MainWindow::on_cbSearchHistory_currentIndexChanged(int index)
|
||||
{
|
||||
ui->btnSearchAgin->setEnabled(!ui->cbSearchHistory->currentText().isEmpty());
|
||||
mSearchResultModel.setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void MainWindow::on_btnSearchAgin_clicked()
|
||||
{
|
||||
if (mSearchDialog==nullptr) {
|
||||
mSearchDialog = new SearchDialog(this);
|
||||
}
|
||||
PSearchResults results=mSearchResultModel.currentResults();
|
||||
if (results){
|
||||
mSearchDialog->findInFiles(results->keyword,
|
||||
results->scope,
|
||||
results->options);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ public:
|
|||
void runExecutable(const QString& exeName, const QString& filename=QString());
|
||||
void runExecutable();
|
||||
void debug();
|
||||
void showSearchPanel();
|
||||
|
||||
void applySettings();
|
||||
|
||||
|
@ -184,6 +185,10 @@ private slots:
|
|||
|
||||
void on_actionFind_Previous_triggered();
|
||||
|
||||
void on_cbSearchHistory_currentIndexChanged(int index);
|
||||
|
||||
void on_btnSearchAgin_clicked();
|
||||
|
||||
public slots:
|
||||
void onCompileLog(const QString& msg);
|
||||
void onCompileIssue(PCompileIssue issue);
|
||||
|
|
|
@ -590,7 +590,10 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<widget class="QPushButton" name="btnSearchAgin">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
|
@ -657,7 +660,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<widget class="QPushButton" name="btnReplace">
|
||||
<property name="text">
|
||||
<string>Replace</string>
|
||||
</property>
|
||||
|
|
|
@ -65,6 +65,29 @@ void SearchDialog::findInFiles(const QString &text)
|
|||
show();
|
||||
}
|
||||
|
||||
void SearchDialog::findInFiles(const QString &keyword, SearchFileScope scope, SynSearchOptions options)
|
||||
{
|
||||
mTabBar->setCurrentIndex(1);
|
||||
ui->cbFind->setCurrentText(keyword);
|
||||
switch(scope) {
|
||||
case SearchFileScope::currentFile:
|
||||
ui->rbCurrentFile->setChecked(true);
|
||||
break;
|
||||
case SearchFileScope::openedFiles:
|
||||
ui->rbOpenFiles->setChecked(true);
|
||||
break;
|
||||
case SearchFileScope::wholeProject:
|
||||
ui->rbProject->setChecked(true);
|
||||
break;
|
||||
}
|
||||
// Apply options
|
||||
ui->chkRegExp->setChecked(mSearchOptions.testFlag(ssoRegExp));
|
||||
ui->chkCaseSensetive->setChecked(mSearchOptions.testFlag(ssoMatchCase));
|
||||
ui->chkWholeWord->setChecked(mSearchOptions.testFlag(ssoWholeWord));
|
||||
|
||||
show();
|
||||
}
|
||||
|
||||
void SearchDialog::replace(const QString &sFind, const QString &sReplace)
|
||||
{
|
||||
mTabBar->setCurrentIndex(2);
|
||||
|
@ -280,6 +303,8 @@ void SearchDialog::on_btnExecute_clicked()
|
|||
// inc(filehitted);
|
||||
// end;
|
||||
}
|
||||
if (findCount>0)
|
||||
pMainWindow->showSearchPanel();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -330,6 +355,7 @@ std::shared_ptr<SearchResultTreeItem> SearchDialog::batchFindInEditor(Editor *e,
|
|||
item->len = wordLen;
|
||||
item->parent = parentItem.get();
|
||||
item->text = e->lines()->getString(Line-1);
|
||||
item->text.replace('\t',' ');
|
||||
parentItem->results.append(item);
|
||||
return SynSearchAction::Skip;
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QDialog>
|
||||
#include "../qsynedit/SynEdit.h"
|
||||
#include "../utils.h"
|
||||
|
||||
namespace Ui {
|
||||
class SearchDialog;
|
||||
|
@ -29,6 +30,7 @@ public:
|
|||
void findNext();
|
||||
void findPrevious();
|
||||
void findInFiles(const QString& text);
|
||||
void findInFiles(const QString& keyword, SearchFileScope scope, SynSearchOptions options);
|
||||
void replace(const QString& sFind, const QString& sReplace);
|
||||
PSynSearchBase searchEngine() const;
|
||||
|
||||
|
|
|
@ -195,8 +195,6 @@ SearchResultListModel::SearchResultListModel(SearchResultModel *model, QObject *
|
|||
QAbstractListModel(parent),
|
||||
mSearchResultModel(model)
|
||||
{
|
||||
connect(mSearchResultModel, &SearchResultModel::currentChanged,
|
||||
this, &SearchResultListModel::onResultModelChanged);
|
||||
connect(mSearchResultModel, &SearchResultModel::modelChanged,
|
||||
this, &SearchResultListModel::onResultModelChanged);
|
||||
}
|
||||
|
@ -216,11 +214,11 @@ QVariant SearchResultListModel::data(const QModelIndex &index, int role) const
|
|||
return QVariant();
|
||||
switch (results->scope) {
|
||||
case SearchFileScope::currentFile:
|
||||
return tr("Current File") + QString(" \"%1\"").arg(results->keyword);
|
||||
return tr("Current File:") + QString(" \"%1\"").arg(results->keyword);
|
||||
case SearchFileScope::wholeProject:
|
||||
return tr("Files In Project") + QString(" \"%1\"").arg(results->keyword);
|
||||
return tr("Files In Project:") + QString(" \"%1\"").arg(results->keyword);
|
||||
case SearchFileScope::openedFiles:
|
||||
return tr("Open Files") + QString(" \"%1\"").arg(results->keyword);
|
||||
return tr("Open Files:") + QString(" \"%1\"").arg(results->keyword);
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
|
@ -266,10 +264,9 @@ void SearchResultTreeViewDelegate::paint(QPainter *painter, const QStyleOptionVi
|
|||
if (item->parent==nullptr) { //is filename
|
||||
fullText = item->filename;
|
||||
} else {
|
||||
fullText = QString("%1 %2: %3").arg(tr("Line")).arg(item->line)
|
||||
fullText = QString("%1 %2: %3").arg(tr("Line")).arg(item->line)
|
||||
.arg(item->text);
|
||||
}
|
||||
|
||||
// Figure out where to render the text in order to follow the requested alignment
|
||||
option.text = fullText;
|
||||
QRect textRect = style->subElementRect(QStyle::SE_ItemViewItemText, &option);
|
||||
|
@ -277,7 +274,27 @@ void SearchResultTreeViewDelegate::paint(QPainter *painter, const QStyleOptionVi
|
|||
QFontMetrics metrics = option.fontMetrics;
|
||||
int x=textRect.left();
|
||||
int y=textRect.top() + metrics.ascent();
|
||||
//painter->setClipRect(textRect);
|
||||
painter->drawText(x,y,fullText);
|
||||
if (item->parent==nullptr) { //is filename
|
||||
painter->drawText(x,y,fullText);
|
||||
} else {
|
||||
QString s = item->text.mid(0,item->start-1);
|
||||
QString text = QString("%1 %2: %3").arg(tr("Line")).arg(item->line)
|
||||
.arg(s);
|
||||
painter->drawText(x,y,text);
|
||||
x+=metrics.horizontalAdvance(text);
|
||||
QFont font = option.font;
|
||||
font.setBold(true);
|
||||
font.setItalic(true);
|
||||
QFont oldFont = painter->font();
|
||||
painter->setFont(font);
|
||||
text=item->text.mid(item->start-1,item->len);
|
||||
painter->drawText(x,y,text);
|
||||
metrics = QFontMetrics(font);
|
||||
x+=metrics.horizontalAdvance(text);
|
||||
painter->setFont(oldFont);
|
||||
text = item->text.mid(item->start-1+item->len);
|
||||
painter->drawText(x,y,text);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue