find and replace working in scintillaeditor

master
shaina7837 2014-08-07 07:34:37 +05:30
parent 7da7c07918
commit 46a948d302
6 changed files with 58 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.0.1, 2014-07-11T19:39:57. -->
<!-- Written by QtCreator 3.0.1, 2014-08-07T07:06:09. -->
<qtcreator>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -170,7 +170,7 @@
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">openscad</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/shaina/openscad/openscad.pro</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/shaina/letsbegin/openscad/openscad.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">openscad.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>

View File

@ -66,6 +66,9 @@ public:
static const int maxRecentFiles = 10;
QAction *actionRecentFile[maxRecentFiles];
QMap<QString, QString> knownFileExtensions;
QString editortype;
bool useScintilla;
MainWindow(const QString &filename);
~MainWindow();
@ -138,7 +141,10 @@ private slots:
private slots:
void selectFindType(int);
void find();
void scintillaFind(QString);
void scintillaFindNext();
void findAndReplace();
void scintillaReplace();
void findNext();
void findPrev();
void useSelectionForFind();

View File

@ -23,6 +23,9 @@ public:
virtual void setTextCursor (const QTextCursor &) { }
virtual QTextDocument *document(){QTextDocument *t = new QTextDocument; return t;}
virtual bool find(const QString &, QTextDocument::FindFlags options = 0){ return options;}
virtual bool findFirst(const QString&, bool, bool, bool, bool, bool, int, int, bool, bool){return 0;}
virtual bool findNext(){return 0;}
virtual void replaceSelectedText(QString&){ }
public slots:
virtual void zoomIn(){ }

View File

@ -23,7 +23,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <iostream>
#include "GeometryCache.h"
#include "ModuleCache.h"
#include "MainWindow.h"
@ -168,14 +168,15 @@ MainWindow::MainWindow(const QString &filename)
{
setupUi(this);
QString editortype = Preferences::inst()->getValue("editor/editortype").toString();
editortype = Preferences::inst()->getValue("editor/editortype").toString();
bool useScintilla = (editortype == "QScintilla Editor");
useScintilla = (editortype == "QScintilla Editor");
#ifdef USE_SCINTILLA_EDITOR
if (useScintilla) editor = new ScintillaEditor(editorDockContents);
if (useScintilla)
editor = new ScintillaEditor(editorDockContents);
else
#endif
editor = new LegacyEditor(editorDockContents);
editor = new LegacyEditor(editorDockContents);
editorDockContents->layout()->addWidget(editor);
@ -436,6 +437,10 @@ MainWindow::MainWindow(const QString &filename)
connect(this->replaceAllButton, SIGNAL(clicked()), this, SLOT(replaceAll()));
connect(this->replaceInputField, SIGNAL(returnPressed()), this->replaceButton, SLOT(animateClick()));
connect(this->findInputField, SIGNAL(textChanged(QString)), this, SLOT(scintillaFind(QString)));
connect(this->nextButton, SIGNAL(clicked()), this, SLOT(scintillaFindNext()));
connect(this->replaceButton, SIGNAL(clicked()), this, SLOT(scintillaReplace()));
// make sure it looks nice..
QSettings settings;
QByteArray windowState = settings.value("window/state", QByteArray()).toByteArray();
@ -1280,7 +1285,19 @@ void MainWindow::find()
replaceAllButton->hide();
find_panel->show();
findInputField->setFocus();
findInputField->selectAll();
findInputField->selectAll();
}
void MainWindow::scintillaFind(QString textToFind)
{
if(useScintilla)
editor->findFirst(textToFind, false, false, false, false, true, 1, 1, true, false);
}
void MainWindow::scintillaFindNext()
{
if(useScintilla)
editor->findNext();
}
void MainWindow::findAndReplace()
@ -1335,6 +1352,11 @@ void MainWindow::replaceAll() {
editor->setTextCursor(old_cursor);
}
void MainWindow::scintillaReplace(){
QString newText = this->replaceInputField->text();
editor->replaceSelectedText(newText);
}
void MainWindow::findNext()
{
findOperation();

View File

@ -249,3 +249,18 @@ void ScintillaEditor::onTextChanged()
qsci->setMarginWidth(0, fontmetrics.width(QString::number(qsci->lines())) + 6);
}
bool ScintillaEditor::findFirst(const QString &expr, bool re, bool cs, bool wo, bool wrap, bool forward, int line, int index, bool show, bool posix)
{
qsci->findFirst(expr, re, cs, wo, wrap, forward, line, index, show, posix);
}
bool ScintillaEditor::findNext()
{
qsci->findNext();
}
void ScintillaEditor::replaceSelectedText(QString& newText)
{
qsci->replaceSelectedText(newText);
}

View File

@ -23,7 +23,10 @@ public:
void Monokai();
void Solarized_light();
void noColor();
bool findFirst(const QString&, bool, bool, bool, bool, bool, int, int, bool, bool);
bool findNext();
void replaceSelectedText(QString&);
public slots:
void zoomIn();
void zoomOut();