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"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -170,7 +170,7 @@
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">openscad</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">openscad</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></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.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">openscad.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">openscad.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>

View File

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

View File

@ -23,6 +23,9 @@ public:
virtual void setTextCursor (const QTextCursor &) { } virtual void setTextCursor (const QTextCursor &) { }
virtual QTextDocument *document(){QTextDocument *t = new QTextDocument; return t;} virtual QTextDocument *document(){QTextDocument *t = new QTextDocument; return t;}
virtual bool find(const QString &, QTextDocument::FindFlags options = 0){ return options;} 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: public slots:
virtual void zoomIn(){ } virtual void zoomIn(){ }

View File

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

View File

@ -249,3 +249,18 @@ void ScintillaEditor::onTextChanged()
qsci->setMarginWidth(0, fontmetrics.width(QString::number(qsci->lines())) + 6); 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 Monokai();
void Solarized_light(); void Solarized_light();
void noColor(); void noColor();
bool findFirst(const QString&, bool, bool, bool, bool, bool, int, int, bool, bool);
bool findNext();
void replaceSelectedText(QString&);
public slots: public slots:
void zoomIn(); void zoomIn();
void zoomOut(); void zoomOut();