work save: basic find done

This commit is contained in:
royqh1979@gmail.com 2021-08-03 23:55:57 +08:00
parent 176c92ace8
commit f93b23f451
11 changed files with 619 additions and 102 deletions

View File

@ -103,7 +103,6 @@ Editor::~Editor() {
mParentPageControl->removeTab(index);
}
this->setParent(0);
}
void Editor::loadFile() {

View File

@ -91,7 +91,8 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
pMainWindow->rebuildOpenedFileHisotryMenu();
}
editor->deleteLater();
//editor->deleteLater();
delete editor;
return true;
}

View File

@ -25,6 +25,8 @@
#include <QTextCodec>
#include <QDebug>
#include <widgets/searchdialog.h>
MainWindow* pMainWindow;
MainWindow::MainWindow(QWidget *parent)
@ -32,7 +34,8 @@ MainWindow::MainWindow(QWidget *parent)
ui(new Ui::MainWindow),
mMessageControlChanged(false),
mTabMessagesTogglingState(false),
mCheckSyntaxInBack(false)
mCheckSyntaxInBack(false),
mSearchDialog(nullptr)
{
ui->setupUi(this);
// status bar
@ -874,6 +877,16 @@ void MainWindow::prepareDebugger()
// mDebugger->deleteWatchVars(false);
}
SearchDialog *MainWindow::searchDialog() const
{
return mSearchDialog;
}
EditorList *MainWindow::editorList() const
{
return mEditorList;
}
Debugger *MainWindow::debugger() const
{
return mDebugger;
@ -1493,3 +1506,35 @@ void MainWindow::onDebugEvaluateInput()
mDebugger->sendCommand("print",s,false);
}
}
void MainWindow::on_actionFind_triggered()
{
Editor *e = mEditorList->getEditor();
if (!e)
return;
if (mSearchDialog==nullptr) {
mSearchDialog = new SearchDialog(this);
}
QString s = e->WordAtCursor();
mSearchDialog->find(s);
}
void MainWindow::on_actionFind_in_files_triggered()
{
}
void MainWindow::on_actionReplace_triggered()
{
}
void MainWindow::on_actionFind_Next_triggered()
{
}
void MainWindow::on_actionFind_Previous_triggered()
{
}

View File

@ -21,6 +21,7 @@ class Editor;
class Debugger;
class CPUDialog;
class QPlainTextEdit;
class SearchDialog;
class MainWindow : public QMainWindow
{
@ -76,6 +77,10 @@ public:
Debugger *debugger() const;
EditorList *editorList() const;
SearchDialog *searchDialog() const;
protected:
void openFiles(const QStringList& files);
void openFile(const QString& filename);
@ -166,6 +171,16 @@ private slots:
void on_actionExit_triggered();
void on_actionFind_triggered();
void on_actionFind_in_files_triggered();
void on_actionReplace_triggered();
void on_actionFind_Next_triggered();
void on_actionFind_Previous_triggered();
public slots:
void onCompileLog(const QString& msg);
void onCompileIssue(PCompileIssue issue);
@ -195,6 +210,7 @@ private:
CompilerManager *mCompilerManager;
Debugger *mDebugger;
CPUDialog *mCPUDialog;
SearchDialog *mSearchDialog;
QList<QAction *> mRecentFileActions;
bool mMessageControlChanged;

View File

@ -216,7 +216,7 @@
<enum>QTabWidget::South</enum>
</property>
<property name="currentIndex">
<number>3</number>
<number>4</number>
</property>
<widget class="QWidget" name="tabIssues">
<attribute name="icon">
@ -544,6 +544,145 @@
<attribute name="title">
<string>Search</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QWidget" name="searchHistoryPanel" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>History:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Search Again</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="replacePanel" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_2">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAtTop</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>Replace</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QTreeView" name="searchView"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabClose">
<attribute name="icon">
@ -566,7 +705,7 @@
<x>0</x>
<y>0</y>
<width>946</width>
<height>26</height>
<height>25</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -627,8 +766,20 @@
<addaction name="actionFoldAll"/>
<addaction name="actionUnfoldAll"/>
</widget>
<widget class="QMenu" name="menuSearch">
<property name="title">
<string>Search</string>
</property>
<addaction name="actionFind"/>
<addaction name="actionFind_in_files"/>
<addaction name="actionReplace"/>
<addaction name="separator"/>
<addaction name="actionFind_Next"/>
<addaction name="actionFind_Previous"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuSearch"/>
<addaction name="menuExecute"/>
<addaction name="menuTools"/>
</widget>
@ -1098,6 +1249,50 @@
<string>Exit</string>
</property>
</action>
<action name="actionFind">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/079-srchrep.png</normalon>
</iconset>
</property>
<property name="text">
<string>Find...</string>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
</action>
<action name="actionFind_in_files">
<property name="text">
<string>Find in Files...</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+F</string>
</property>
</action>
<action name="actionReplace">
<property name="icon">
<iconset>
<normalon>:/icons/images/newlook24/066-replace.png</normalon>
</iconset>
</property>
<property name="text">
<string>Replace...</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
<action name="actionFind_Next">
<property name="text">
<string>Find Next</string>
</property>
</action>
<action name="actionFind_Previous">
<property name="text">
<string>Find Previous</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -41,7 +41,7 @@ int SynSearch::findAll(const QString &newText)
break;
}
mResults.append(next);
start = next;
start = next + newText.length();
}
return mResults.size();
}

View File

@ -5,9 +5,15 @@
#include <memory>
enum SynSearchOption {
ssoMatchCase, ssoWholeWord, ssoBackwards,
ssoEntireScope, ssoSelectedOnly, ssoReplace, ssoReplaceAll, ssoPrompt,
ssoRegExp};
ssoMatchCase = 0x0001,
ssoWholeWord = 0x0002,
ssoBackwards = 0x0004,
ssoEntireScope = 0x0008,
ssoSelectedOnly = 0x0010,
ssoFindAll = 0x0020,
ssoPrompt = 0x0040,
ssoRegExp = 0x0080
};
Q_DECLARE_FLAGS(SynSearchOptions, SynSearchOption)
Q_DECLARE_OPERATORS_FOR_FLAGS(SynSearchOptions)

View File

@ -3208,16 +3208,6 @@ void SynEdit::doScrolled(int)
invalidate();
}
PSynSearchBase SynEdit::searchEngine() const
{
return mSearchEngine;
}
void SynEdit::setSearchEngine(const PSynSearchBase &searchEngine)
{
mSearchEngine = searchEngine;
}
int SynEdit::textHeight() const
{
return mTextHeight;
@ -4165,9 +4155,10 @@ void SynEdit::setSelText(const QString &Value)
mActiveSelectionMode);
}
int SynEdit::searchReplace(const QString &ASearch, const QString &AReplace, SynSearchOptions AOptions)
int SynEdit::search(const QString &ASearch, SynSearchOptions AOptions, PSynSearchBase searchEngine,
SynSearchMathedProc matchedCallback)
{
if (!mSearchEngine)
if (!searchEngine)
return 0;
// can't search for or replace an empty string
@ -4179,8 +4170,7 @@ int SynEdit::searchReplace(const QString &ASearch, const QString &AReplace, SynS
// option if nothing is selected
bool bBackward = AOptions.testFlag(ssoBackwards);
bool bPrompt = AOptions.testFlag(ssoPrompt);
bool bReplace = AOptions.testFlag(ssoReplace);
bool bReplaceAll = AOptions.testFlag(ssoReplaceAll);
bool bFindAll = AOptions.testFlag(ssoFindAll);
bool bFromCursor = !AOptions.testFlag(ssoEntireScope);
BufferCoord ptCurrent;
BufferCoord ptStart;
@ -4222,43 +4212,33 @@ int SynEdit::searchReplace(const QString &ASearch, const QString &AReplace, SynS
ptCurrent = ptStart;
}
// initialize the search engine
mSearchEngine->setOptions(AOptions);
mSearchEngine->setPattern(ASearch);
searchEngine->setOptions(AOptions);
searchEngine->setPattern(ASearch);
// search while the current search position is inside of the search range
int nReplaceLen = 0;
bool bEndUndoBlock =false;
doOnPaintTransient(SynTransientType::ttBefore);
if (bReplaceAll && !bPrompt) {
incPaintLock();
mUndoList->BeginBlock();
bEndUndoBlock = true;
}
{
auto action = finally([&,this]{
if (bReplaceAll && !bPrompt)
decPaintLock();
if (bEndUndoBlock)
mUndoList->EndBlock();
doOnPaintTransient(SynTransientType::ttAfter);
});
int n;
int i;
while ((ptCurrent.Line >= ptStart.Line) && (ptCurrent.Line <= ptEnd.Line)) {
int nInLine = mSearchEngine->findAll(mLines->getString(ptCurrent.Line - 1));
int nInLine = searchEngine->findAll(mLines->getString(ptCurrent.Line - 1));
int iResultOffset = 0;
if (bBackward)
n = mSearchEngine->resultCount()-1;
i = searchEngine->resultCount()-1;
else
n = 0;
i = 0;
// Operate on all results in this line.
while (nInLine > 0) {
// An occurrence may have been replaced with a text of different length
int nFound = mSearchEngine->result(n) + 1 + iResultOffset;
int nSearchLen = mSearchEngine->length(n);
int nReplaceLen = 0;
int nFound = searchEngine->result(i) + 1 + iResultOffset;
int nSearchLen = searchEngine->length(i);
if (bBackward)
n--;
i--;
else
n++;
i++;
nInLine--;
// Is the search result entirely in the search range?
bool isInValidSearchRange = true;
@ -4271,7 +4251,7 @@ int SynEdit::searchReplace(const QString &ASearch, const QString &AReplace, SynS
isInValidSearchRange = false;
} else if (mActiveSelectionMode == SynSelectionMode::smColumn) {
// solves bug in search/replace when smColumn mode active and no selection
isInValidSearchRange = (first >= ptStart.Char) && (last <= ptEnd.Char)
isInValidSearchRange = ((first >= ptStart.Char) && (last <= ptEnd.Char))
|| (ptEnd.Char - ptStart.Char < 1);
}
if (!isInValidSearchRange)
@ -4293,46 +4273,23 @@ int SynEdit::searchReplace(const QString &ASearch, const QString &AReplace, SynS
else
internalSetCaretXY(ptCurrent);
// If it's a search only we can leave the procedure now.
if (! (bReplace || bReplaceAll))
return result;
// Prompt and replace or replace all. If user chooses to replace
// all after prompting, turn off prompting.
SynReplaceAction nAction;
if (bPrompt && this->mOnReplaceText) {
nAction = mOnReplaceText(ASearch, AReplace, ptCurrent.Line, nFound, nSearchLen);
if (nAction == SynReplaceAction::raCancel)
return result;
} else
nAction = SynReplaceAction::raReplace;
if (nAction != SynReplaceAction::raSkip) {
// user has been prompted and has requested to silently replace all
// so turn off prompting
if (nAction == SynReplaceAction::raReplaceAll) {
if ((not bReplaceAll) || bPrompt) {
bReplaceAll = true;
incPaintLock();
}
bPrompt = false;
if (bEndUndoBlock == false)
mUndoList->BeginBlock();
bEndUndoBlock = true;
}
setSelText(mSearchEngine->replace(selText(), AReplace));
nReplaceLen = caretX() - nFound;
if (matchedCallback) {
matchedCallback(ASearch,ptCurrent.Line,
nFound,nSearchLen);
}
if (!bFindAll)
return result;
// fix the caret position and the remaining results
if (!bBackward) {
internalSetCaretX(nFound + nReplaceLen);
if ((nSearchLen != nReplaceLen) && (nAction != SynReplaceAction::raSkip)) {
iResultOffset += nReplaceLen - nSearchLen;
if ((mActiveSelectionMode != SynSelectionMode::smColumn) && (caretY() == ptEnd.Line)) {
ptEnd.Char+=nReplaceLen - nSearchLen;
setBlockEnd(ptEnd);
}
}
}
if (!bReplaceAll)
return result;
// if (!bBackward) {
// internalSetCaretX(nFound + nReplaceLen);
// if ((nSearchLen != nReplaceLen) && (nAction != SynReplaceAction::raSkip)) {
// iResultOffset += nReplaceLen - nSearchLen;
// if ((mActiveSelectionMode != SynSelectionMode::smColumn) && (caretY() == ptEnd.Line)) {
// ptEnd.Char+=nReplaceLen - nSearchLen;
// setBlockEnd(ptEnd);
// }
// }
// }
}
// search next / previous line
if (bBackward)
@ -4341,6 +4298,7 @@ int SynEdit::searchReplace(const QString &ASearch, const QString &AReplace, SynS
ptCurrent.Line++;
}
}
return result;
}
void SynEdit::DoLinesDeleted(int FirstLine, int Count)

View File

@ -125,7 +125,7 @@ using SynPaintProc = std::function<void(const QPaintDevice& paintDevice )>;
using SynPreparePaintHighlightTokenProc = std::function<void(int row,
int column, const QString& token, PSynHighlighterAttribute attr,
SynFontStyles& style, QColor& foreground, QColor& background)>;
using SynReplaceTextProc = std::function<SynReplaceAction(const QString& ASearch, const QString& AReplace,
using SynSearchMathedProc = std::function<void(const QString& ASearch,
int Line, int ch, int wordLen)>;
//using SynSpecialLineColorsProc = std::function<void(int Line,
// bool& Special, QColor& foreground, QColor& backgroundColor)>;
@ -215,7 +215,8 @@ public:
PSynEditFoldRange foldHidesLine(int line);
void setSelText(const QString& Value);
int searchReplace(const QString& ASearch, const QString& AReplace, SynSearchOptions AOptions);
int search(const QString& ASearch,SynSearchOptions AOptions,
PSynSearchBase searchEngine, SynSearchMathedProc matchedCallback = nullptr);
int maxScrollWidth() const;
int maxScrollHeight() const;
@ -325,9 +326,6 @@ public:
int textHeight() const;
PSynSearchBase searchEngine() const;
void setSearchEngine(const PSynSearchBase &searchEngine);
signals:
void Changed();
@ -593,8 +591,6 @@ private:
int mScrollDeltaX;
int mScrollDeltaY;
PSynSearchBase mSearchEngine;
PSynEdit fChainedEditor;
int mPaintTransientLock;
@ -611,7 +607,6 @@ private:
SynProcessCommandProc mOnProcessingCommand;
SynProcessCommandProc mOnProcessingUserCommand;
SynReplaceTextProc mOnReplaceText;
// SynSpecialLineColorsProc mOnSpecialLineColors;
// SynEditingAreasProc mOnEditingAreas;
// SynGutterGetTextProc mOnGutterGetText;

View File

@ -1,10 +1,18 @@
#include "searchdialog.h"
#include "ui_searchdialog.h"
#include <QTabBar>
#include "../editor.h"
#include "../mainwindow.h"
#include "../editorlist.h"
#include "../qsynedit/Search.h"
#include "../qsynedit/SearchRegex.h"
#include <QMessageBox>
SearchDialog::SearchDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SearchDialog)
ui(new Ui::SearchDialog),
mSearchEngine()
{
ui->setupUi(this);
mTabBar = new QTabBar();
@ -12,8 +20,12 @@ SearchDialog::SearchDialog(QWidget *parent) :
mTabBar->addTab(tr("Find in files"));
mTabBar->addTab(tr("Replace"));
mTabBar->addTab(tr("Replace in files"));
mTabBar->setExpanding(false);
ui->dialogLayout->insertWidget(0,mTabBar);
connect(mTabBar,&QTabBar::currentChanged,this, &SearchDialog::onTabChanged);
mSearchOptions&=0;
mBasicSearchEngine= PSynSearchBase(new SynSearch());
mRegexSearchEngine= PSynSearchBase(new SynSearchRegex());
}
SearchDialog::~SearchDialog()
@ -94,12 +106,290 @@ void SearchDialog::on_btnCancel_clicked()
this->close();
}
void SearchDialog::closeEvent(QCloseEvent *event)
{
this->deleteLater();
}
void SearchDialog::on_btnExecute_clicked()
{
int findcount = 0;
SearchAction actionType;
switch (mTabBar->currentIndex()) {
case 0:
actionType = SearchAction::Find;
break;
case 1:
actionType = SearchAction::FindFiles;
break;
case 2:
actionType = SearchAction::Replace;
break;
case 3:
actionType = SearchAction::ReplaceFiles;
break;
default:
return;
}
mSearchOptions&=0;
// Apply options
if (ui->chkRegExp->isChecked()) {
mSearchOptions.setFlag(ssoRegExp);
}
if (ui->chkCaseSensetive->isChecked()) {
mSearchOptions.setFlag(ssoMatchCase);
}
if (ui->chkWholeWord->isChecked()) {
mSearchOptions.setFlag(ssoWholeWord);
}
if (ui->chkPrompt->isChecked()) {
mSearchOptions.setFlag(ssoPrompt);
}
// Apply scope, when visible
if (ui->grpScope->isVisible()) {
if (ui->rbSelection->isChecked()) {
mSearchOptions.setFlag(ssoSelectedOnly);
}
}
// Apply direction, when visible
if (ui->grpDirection->isVisible()) {
if (ui->rbBackward->isChecked()) {
mSearchOptions.setFlag(ssoBackwards);
}
}
// Apply origin, when visible
if (ui->grpOrigin->isVisible()) {
if (ui->rbEntireScope->isChecked()) {
mSearchOptions.setFlag(ssoEntireScope);
}
}
// Use entire scope for file finding/replacing
if (actionType == SearchAction::FindFiles || actionType == SearchAction::ReplaceFiles) {
mSearchOptions.setFlag(ssoEntireScope);
}
this->close();
// Find the first one, then quit
if (actionType == SearchAction::Find) {
Editor *e = pMainWindow->editorList()->getEditor();
if (e!=nullptr) {
findcount+=execute(e,SearchAction::Find);
}
}
// // Replace first, find to next
//end else if actiontype = faReplace then begin
// e := MainForm.EditorList.GetEditor;
// if Assigned(e) then begin
// Inc(findcount, Execute(e.Text, faReplace));
// if findcount > 0 then begin
// Exclude(fSearchOptions, ssoReplace);
// Inc(findcount, Execute(e.Text, faFind));
// end;
// end;
// // Or find everything
//end else if actiontype = faFindFiles then begin
// fileSearched:=0;
// fileHitted:=0;
// MainForm.FindOutput.BeginFind(cboFindText.Text);
// try
// // loop through pagecontrol
// if rbOpenFiles.Checked then begin
// // loop through editors, add results to message control
// for I := 0 to MainForm.EditorList.PageCount - 1 do begin
// e := MainForm.EditorList[i];
// if Assigned(e) then begin
// inc(fileSearched);
// fCurFile := e.FileName;
// t:=Execute(e.Text, actiontype);
// Inc(findcount, t);
// if t>0 then
// inc(filehitted);
// end;
// end;
// // loop through project
// end else if rbProjectFiles.Checked then begin
// for I := 0 to MainForm.Project.Units.Count - 1 do begin
// e := MainForm.Project.Units[i].Editor;
// fCurFile := MainForm.Project.Units[i].FileName;
// // file is already open, use memory
// if Assigned(e) then begin begin
// inc(fileSearched);
// t:=Execute(e.Text, actiontype);
// Inc(findcount, t);
// if t>0 then
// inc(filehitted);
// end;
// // not open? load from disk
// end else if FileExists(fCurFile) then begin
// // Only finding...
// fTempSynEdit.Lines.LoadFromFile(fCurFile);
// inc(fileSearched);
// t:=Execute(fTempSynEdit, actiontype);
// Inc(findcount, t);
// if t>0 then
// inc(filehitted);
// end;
// end;
// // Don't loop, only pass single file
// end else if rbCurFile.Checked then begin
// e := MainForm.EditorList.GetEditor;
// if Assigned(e) then begin
// fCurFile := e.FileName;
// inc(fileSearched);
// t:=Execute(e.Text, actiontype);
// Inc(findcount, t);
// if t>0 then
// inc(filehitted);
// end;
// end;
// finally
// MainForm.FindOutput.EndFind(cboFindText.Text,findCount,
// filehitted,filesearched);
// end;
//end else if actiontype = faReplaceFiles then begin
// // loop through pagecontrol
// if rbOpenFiles.Checked then begin
// // loop through editors, add results to message control
// for I := 0 to MainForm.EditorList.PageCount - 1 do begin
// e := MainForm.EditorList[i];
// if Assigned(e) then begin
// fCurFile := e.FileName;
// if (ssoPrompt in fSearchOptions) then
// e.Activate;
// Inc(findcount, Execute(e.Text, actiontype));
// end;
// end;
// // loop through project
// end else if rbProjectFiles.Checked then begin
// for I := 0 to MainForm.Project.Units.Count - 1 do begin
// e := MainForm.Project.Units[i].Editor;
// fCurFile := MainForm.Project.Units[i].FileName;
// // file is already open, use memory
// if Assigned(e) then begin
// if (ssoPrompt in fSearchOptions) then
// e.Activate;
// Inc(findcount, Execute(e.Text, actiontype));
// // not open? load from disk
// end else if FileExists(fCurFile) then begin
// // we have to open an editor...
// if ssoPrompt in fSearchOptions then begin
// e := MainForm.EditorList.GetEditorFromFileName(fCurFile);
// if Assigned(e) then begin
// e.Activate;
// Inc(findcount, Execute(e.Text, actiontype));
// // Save and close
// e.Save;
// MainForm.Project.CloseUnit(MainForm.Project.Units.Indexof(e));
// end;
// end else begin
// // Stealth replace
// fTempSynEdit.Lines.LoadFromFile(fCurFile);
// Inc(findcount, Execute(fTempSynEdit, actiontype));
// fTempSynEdit.Lines.SaveToFile(fCurFile);
// end;
// end;
// end;
// // Don't loop, only pass single file
// end else if rbCurFile.Checked then begin
// e := MainForm.EditorList.GetEditor;
// if Assigned(e) then begin
// fCurFile := e.FileName;
// Inc(findcount, Execute(e.Text, actiontype));
// end;
// end;
//end;
//if actiontype = faFindFiles then begin
// MainForm.MessageControl.ActivePageIndex := 4; // Find Tab
// if findcount > 0 then
// MainForm.FindSheet.Caption := Lang[ID_SHEET_FIND];
// MainForm.OpenCloseMessageSheet(TRUE);
// self.Close;
//end else if findcount = 0 then begin
// MessageBox(
// Self.Handle,
// PAnsiChar(Format(Lang[ID_MSG_TEXTNOTFOUND], [cboFindText.Text])),
// PAnsiChar(Lang[ID_INFO]),
// MB_ICONINFORMATION or MB_TOPMOST);
// cboFindText.SetFocus;
//end;
//if actiontype = faFind then begin
// self.Close;
//end;
}
int SearchDialog::execute(Editor *editor, SearchDialog::SearchAction actionType)
{
if (editor==nullptr)
return 0;
// Modify the caret when using 'from cursor' and when the selection is ignored
if (!mSearchOptions.testFlag(ssoEntireScope) && !mSearchOptions.testFlag(ssoSelectedOnly)
&& editor->selAvail()) {
// start at end of selection
if (mSearchOptions.testFlag(ssoBackwards)) {
editor->setCaretXY(editor->blockBegin());
} else {
editor->setCaretXY(editor->blockEnd());
}
}
if (mSearchOptions.testFlag(ssoRegExp)) {
mSearchEngine = mRegexSearchEngine;
} else {
mSearchEngine = mBasicSearchEngine;
}
return editor->search(ui->cbFind->currentText(),
mSearchOptions,
mSearchEngine);
// // When using find in files, report each find using OnReplaceText
// if action = faFindFiles then
// editor.OnReplaceText := FindAllAction;
// // Swap search engire for ours
// if (ssoRegExp in fSearchOptions) then
// editor.SearchEngine := fRegExpSearchEngine
// else
// editor.SearchEngine := fSearchEngine;
// result := editor.SearchReplace(cboFindText.Text, cboReplaceText.Text, fSearchOptions);
// // Don't touch editors which we are only scanning
// if action in [faFindFiles] then begin
// // Put backup back into place
// editor.CaretXY := caretbackup;
// editor.BlockBegin := blockbeginbackup;
// editor.BlockEnd := blockendbackup;
// editor.TopLine := toplinebackup;
// end;
// editor.OnReplaceText := onreplacebackup;
// editor.SearchEngine := enginebackup;
}
PSynSearchBase SearchDialog::searchEngine() const
{
return mSearchEngine;
}

View File

@ -2,16 +2,25 @@
#define SEARCHDIALOG_H
#include <QDialog>
#include "../qsynedit/SearchBase.h"
namespace Ui {
class SearchDialog;
}
class QTabBar;
class Editor;
class SearchDialog : public QDialog
{
Q_OBJECT
enum class SearchAction {
Find,
FindFiles,
Replace,
ReplaceFiles
};
public:
explicit SearchDialog(QWidget *parent = nullptr);
~SearchDialog();
@ -19,21 +28,24 @@ public:
void findInFiles(const QString& text);
void replace(const QString& sFind, const QString& sReplace);
void replaceInFiles(const QString& sFind, const QString& sReplace);
PSynSearchBase searchEngine() const;
private slots:
void onTabChanged();
void onTabChanged();
void on_cbFind_currentTextChanged(const QString &arg1);
void on_btnCancel_clicked();
void on_btnExecute_clicked();
private:
int execute(Editor* editor, SearchAction actionType);
private:
Ui::SearchDialog *ui;
QTabBar *mTabBar;
// QWidget interface
protected:
void closeEvent(QCloseEvent *event) override;
SynSearchOptions mSearchOptions;
PSynSearchBase mSearchEngine;
PSynSearchBase mBasicSearchEngine;
PSynSearchBase mRegexSearchEngine;
};
#endif // SEARCHDIALOG_H