mirror of https://github.com/vitalif/openscad
added generic function in editor interface
parent
1ef69bb940
commit
fbc13a7456
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 3.0.1, 2014-08-07T07:06:09. -->
|
||||
<!-- Written by QtCreator 3.0.1, 2014-08-11T22:59:13. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
|
|
|
@ -141,10 +141,8 @@ private slots:
|
|||
private slots:
|
||||
void selectFindType(int);
|
||||
void find();
|
||||
void scintillaFind(QString);
|
||||
void scintillaFindNext();
|
||||
void FindString(QString);
|
||||
void findAndReplace();
|
||||
void scintillaReplace();
|
||||
void findNext();
|
||||
void findPrev();
|
||||
void useSelectionForFind();
|
||||
|
|
|
@ -23,8 +23,7 @@ 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 bool findNext(QTextDocument::FindFlags, QString&){return 0;}
|
||||
virtual void replaceSelectedText(QString&){ }
|
||||
|
||||
public slots:
|
||||
|
|
|
@ -223,3 +223,30 @@ LegacyEditor::~LegacyEditor()
|
|||
{
|
||||
delete highlighter;
|
||||
}
|
||||
|
||||
void LegacyEditor::replaceSelectedText(QString& newText)
|
||||
{
|
||||
QTextCursor cursor = this->textCursor();
|
||||
QString selectedText = cursor.selectedText();
|
||||
if (selectedText == newText) {
|
||||
cursor.insertText(newText);
|
||||
}
|
||||
}
|
||||
|
||||
bool LegacyEditor::findNext(QTextDocument::FindFlags options, QString& newText)
|
||||
{
|
||||
bool success = this->find(newText, options);
|
||||
if (!success) { // Implement wrap-around search behavior
|
||||
QTextCursor old_cursor = this->textCursor();
|
||||
QTextCursor tmp_cursor = old_cursor;
|
||||
tmp_cursor.movePosition((options & QTextDocument::FindBackward) ? QTextCursor::End : QTextCursor::Start);
|
||||
this->setTextCursor(tmp_cursor);
|
||||
bool success = this->find(newText, options);
|
||||
if (!success) {
|
||||
this->setTextCursor(old_cursor);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ public:
|
|||
void setTextCursor (const QTextCursor&);
|
||||
QTextDocument *document() { return textedit->document(); }
|
||||
bool find(const QString&, QTextDocument::FindFlags options = 0);
|
||||
void replaceSelectedText(QString& newText);
|
||||
bool findNext(QTextDocument::FindFlags, QString&);
|
||||
|
||||
public slots:
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
|
|
|
@ -173,7 +173,12 @@ MainWindow::MainWindow(const QString &filename)
|
|||
useScintilla = (editortype == "QScintilla Editor");
|
||||
#ifdef USE_SCINTILLA_EDITOR
|
||||
if (useScintilla)
|
||||
editor = new ScintillaEditor(editorDockContents);
|
||||
{ editor = new ScintillaEditor(editorDockContents);
|
||||
this->editActionIndent->setVisible(false);
|
||||
this->editActionUnindent->setVisible(false);
|
||||
this->editActionComment->setVisible(false);
|
||||
this->editActionUncomment->setVisible(false);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
editor = new LegacyEditor(editorDockContents);
|
||||
|
@ -436,10 +441,7 @@ MainWindow::MainWindow(const QString &filename)
|
|||
connect(this->replaceButton, SIGNAL(clicked()), this, SLOT(replace()));
|
||||
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()));
|
||||
connect(this->findInputField, SIGNAL(textChanged(QString)), this, SLOT(FindString(QString)));
|
||||
|
||||
// make sure it looks nice..
|
||||
QSettings settings;
|
||||
|
@ -1288,16 +1290,10 @@ void MainWindow::find()
|
|||
findInputField->selectAll();
|
||||
}
|
||||
|
||||
void MainWindow::scintillaFind(QString textToFind)
|
||||
void MainWindow::FindString(QString textToFind)
|
||||
{
|
||||
if(useScintilla)
|
||||
editor->findFirst(textToFind, false, false, false, false, true, 1, 1, true, false);
|
||||
}
|
||||
|
||||
void MainWindow::scintillaFindNext()
|
||||
{
|
||||
if(useScintilla)
|
||||
editor->findNext();
|
||||
QTextDocument::FindFlags options;
|
||||
editor->find(textToFind, options);
|
||||
}
|
||||
|
||||
void MainWindow::findAndReplace()
|
||||
|
@ -1333,12 +1329,8 @@ bool MainWindow::findOperation(QTextDocument::FindFlags options) {
|
|||
}
|
||||
|
||||
void MainWindow::replace() {
|
||||
QTextCursor cursor = editor->textCursor();
|
||||
QString selectedText = cursor.selectedText();
|
||||
if (selectedText == findInputField->text()) {
|
||||
cursor.insertText(replaceInputField->text());
|
||||
}
|
||||
findNext();
|
||||
QString newText = this->replaceInputField->text();
|
||||
editor->replaceSelectedText(newText);
|
||||
}
|
||||
|
||||
void MainWindow::replaceAll() {
|
||||
|
@ -1352,14 +1344,11 @@ void MainWindow::replaceAll() {
|
|||
editor->setTextCursor(old_cursor);
|
||||
}
|
||||
|
||||
void MainWindow::scintillaReplace(){
|
||||
QString newText = this->replaceInputField->text();
|
||||
editor->replaceSelectedText(newText);
|
||||
}
|
||||
|
||||
void MainWindow::findNext()
|
||||
{
|
||||
findOperation();
|
||||
QTextDocument::FindFlags options;
|
||||
QString newText = this->replaceInputField->text();
|
||||
editor->findNext(options, newText);
|
||||
}
|
||||
|
||||
void MainWindow::findPrev()
|
||||
|
|
|
@ -250,14 +250,15 @@ 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)
|
||||
bool ScintillaEditor::find(const QString &expr, QTextDocument::FindFlags options)
|
||||
{
|
||||
qsci->findFirst(expr, re, cs, wo, wrap, forward, line, index, show, posix);
|
||||
qsci->findFirst(expr, false, false, false, false, true, 1, 1, true, false);
|
||||
}
|
||||
|
||||
bool ScintillaEditor::findNext()
|
||||
bool ScintillaEditor::findNext(QTextDocument::FindFlags options, QString& newText)
|
||||
{
|
||||
qsci->findNext();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ScintillaEditor::replaceSelectedText(QString& newText)
|
||||
|
|
|
@ -23,29 +23,29 @@ public:
|
|||
void Monokai();
|
||||
void Solarized_light();
|
||||
void noColor();
|
||||
bool findFirst(const QString&, bool, bool, bool, bool, bool, int, int, bool, bool);
|
||||
bool findNext();
|
||||
bool find(const QString&, QTextDocument::FindFlags options);
|
||||
bool findNext(QTextDocument::FindFlags, QString&);
|
||||
void replaceSelectedText(QString&);
|
||||
|
||||
public slots:
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void indentSelection();
|
||||
void unindentSelection();
|
||||
void commentSelection();
|
||||
void uncommentSelection();
|
||||
void setPlainText(const QString&);
|
||||
bool isContentModified();
|
||||
void highlightError(int);
|
||||
void unhighlightLastError();
|
||||
void setHighlightScheme(const QString&);
|
||||
void insertPlainText(const QString&);
|
||||
void undo();
|
||||
void redo();
|
||||
void cut();
|
||||
void copy();
|
||||
void paste();
|
||||
void onTextChanged();
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void indentSelection();
|
||||
void unindentSelection();
|
||||
void commentSelection();
|
||||
void uncommentSelection();
|
||||
void setPlainText(const QString&);
|
||||
bool isContentModified();
|
||||
void highlightError(int);
|
||||
void unhighlightLastError();
|
||||
void setHighlightScheme(const QString&);
|
||||
void insertPlainText(const QString&);
|
||||
void undo();
|
||||
void redo();
|
||||
void cut();
|
||||
void copy();
|
||||
void paste();
|
||||
void onTextChanged();
|
||||
private:
|
||||
QVBoxLayout *scintillaLayout;
|
||||
const int indicatorNumber = 1;
|
||||
|
|
Loading…
Reference in New Issue