mirror of https://github.com/vitalif/openscad
Editor: Implemented simple Find functionality
parent
143a7102c6
commit
9750866aa8
|
@ -115,6 +115,15 @@ private slots:
|
||||||
void hideEditor();
|
void hideEditor();
|
||||||
void preferences();
|
void preferences();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void find();
|
||||||
|
void findNext();
|
||||||
|
void findPrev();
|
||||||
|
void useSelectionForFind();
|
||||||
|
protected:
|
||||||
|
void findOperation(QTextDocument::FindFlags options = 0);
|
||||||
|
virtual bool eventFilter(QObject* obj, QEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void actionRenderPreview();
|
void actionRenderPreview();
|
||||||
void csgRender();
|
void csgRender();
|
||||||
|
|
|
@ -15,7 +15,16 @@
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<property name="margin">
|
<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>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
|
@ -23,13 +32,86 @@
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="Editor" name="editor" native="true">
|
<widget class="QWidget" name="editorlayoutwidget">
|
||||||
<property name="font">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<font>
|
<item>
|
||||||
<family>Monaco</family>
|
<widget class="QFrame" name="find_panel">
|
||||||
<pointsize>8</pointsize>
|
<property name="enabled">
|
||||||
</font>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Raised</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Find</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="findInputField"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="prevButton">
|
||||||
|
<property name="text">
|
||||||
|
<string><</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="nextButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="hideFindButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Done</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="Editor" name="editor" native="true">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Monaco</family>
|
||||||
|
<pointsize>8</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="layoutWidget">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
@ -61,7 +143,16 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<property name="margin">
|
<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>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
|
@ -165,6 +256,11 @@
|
||||||
<addaction name="editActionPasteVPT"/>
|
<addaction name="editActionPasteVPT"/>
|
||||||
<addaction name="editActionPasteVPR"/>
|
<addaction name="editActionPasteVPR"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
|
<addaction name="editActionFind"/>
|
||||||
|
<addaction name="editActionFindNext"/>
|
||||||
|
<addaction name="editActionFindPrevious"/>
|
||||||
|
<addaction name="editActionUseSelectionForFind"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
<addaction name="editActionZoomIn"/>
|
<addaction name="editActionZoomIn"/>
|
||||||
<addaction name="editActionZoomOut"/>
|
<addaction name="editActionZoomOut"/>
|
||||||
<addaction name="editActionPreferences"/>
|
<addaction name="editActionPreferences"/>
|
||||||
|
@ -653,6 +749,38 @@
|
||||||
<string>Preferences</string>
|
<string>Preferences</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="editActionFind">
|
||||||
|
<property name="text">
|
||||||
|
<string>Find...</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+F</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="editActionFindNext">
|
||||||
|
<property name="text">
|
||||||
|
<string>Find Next</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+G</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="editActionFindPrevious">
|
||||||
|
<property name="text">
|
||||||
|
<string>Find Previous</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+Shift+G</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="editActionUseSelectionForFind">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use Selection for Find</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+E</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="designActionFlushCaches">
|
<action name="designActionFlushCaches">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Flush Caches</string>
|
<string>Flush Caches</string>
|
||||||
|
|
|
@ -210,6 +210,7 @@ MainWindow::MainWindow(const QString &filename)
|
||||||
connect(this->e_fps, SIGNAL(textChanged(QString)), this, SLOT(updatedFps()));
|
connect(this->e_fps, SIGNAL(textChanged(QString)), this, SLOT(updatedFps()));
|
||||||
|
|
||||||
animate_panel->hide();
|
animate_panel->hide();
|
||||||
|
find_panel->hide();
|
||||||
|
|
||||||
// Application menu
|
// Application menu
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -282,6 +283,11 @@ MainWindow::MainWindow(const QString &filename)
|
||||||
connect(this->editActionZoomOut, SIGNAL(triggered()), editor, SLOT(zoomOut()));
|
connect(this->editActionZoomOut, SIGNAL(triggered()), editor, SLOT(zoomOut()));
|
||||||
connect(this->editActionHide, SIGNAL(triggered()), this, SLOT(hideEditor()));
|
connect(this->editActionHide, SIGNAL(triggered()), this, SLOT(hideEditor()));
|
||||||
connect(this->editActionPreferences, SIGNAL(triggered()), this, SLOT(preferences()));
|
connect(this->editActionPreferences, SIGNAL(triggered()), this, SLOT(preferences()));
|
||||||
|
// Edit->Find
|
||||||
|
connect(this->editActionFind, SIGNAL(triggered()), this, SLOT(find()));
|
||||||
|
connect(this->editActionFindNext, SIGNAL(triggered()), this, SLOT(findNext()));
|
||||||
|
connect(this->editActionFindPrevious, SIGNAL(triggered()), this, SLOT(findPrev()));
|
||||||
|
connect(this->editActionUseSelectionForFind, SIGNAL(triggered()), this, SLOT(useSelectionForFind()));
|
||||||
|
|
||||||
// Design menu
|
// Design menu
|
||||||
connect(this->designActionAutoReload, SIGNAL(toggled(bool)), this, SLOT(autoReloadSet(bool)));
|
connect(this->designActionAutoReload, SIGNAL(toggled(bool)), this, SLOT(autoReloadSet(bool)));
|
||||||
|
@ -371,6 +377,13 @@ MainWindow::MainWindow(const QString &filename)
|
||||||
this, SLOT(setSyntaxHighlight(const QString&)));
|
this, SLOT(setSyntaxHighlight(const QString&)));
|
||||||
Preferences::inst()->apply();
|
Preferences::inst()->apply();
|
||||||
|
|
||||||
|
connect(this->findInputField, SIGNAL(returnPressed()), this, SLOT(findNext()));
|
||||||
|
find_panel->installEventFilter(this);
|
||||||
|
|
||||||
|
connect(this->prevButton, SIGNAL(clicked()), this, SLOT(findPrev()));
|
||||||
|
connect(this->nextButton, SIGNAL(clicked()), this, SLOT(findNext()));
|
||||||
|
connect(this->hideFindButton, SIGNAL(clicked()), find_panel, SLOT(hide()));
|
||||||
|
|
||||||
// make sure it looks nice..
|
// make sure it looks nice..
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
resize(settings.value("window/size", QSize(800, 600)).toSize());
|
resize(settings.value("window/size", QSize(800, 600)).toSize());
|
||||||
|
@ -1088,6 +1101,60 @@ void MainWindow::pasteViewportRotation()
|
||||||
cursor.insertText(txt);
|
cursor.insertText(txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::find()
|
||||||
|
{
|
||||||
|
find_panel->show();
|
||||||
|
findInputField->setFocus();
|
||||||
|
findInputField->selectAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::findOperation(QTextDocument::FindFlags options) {
|
||||||
|
bool success = editor->find(findInputField->text(), options);
|
||||||
|
if (!success) { // Implement wrap-around search behavior
|
||||||
|
QTextCursor old_cursor = editor->textCursor();
|
||||||
|
QTextCursor tmp_cursor = old_cursor;
|
||||||
|
tmp_cursor.movePosition((options & QTextDocument::FindBackward) ? QTextCursor::End : QTextCursor::Start);
|
||||||
|
editor->setTextCursor(tmp_cursor);
|
||||||
|
bool success = editor->find(findInputField->text(), options);
|
||||||
|
if (!success) {
|
||||||
|
editor->setTextCursor(old_cursor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::findNext()
|
||||||
|
{
|
||||||
|
findOperation();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::findPrev()
|
||||||
|
{
|
||||||
|
findOperation(QTextDocument::FindBackward);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::useSelectionForFind()
|
||||||
|
{
|
||||||
|
findInputField->setText(editor->textCursor().selectedText());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::eventFilter(QObject* obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if (obj == find_panel)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::KeyPress)
|
||||||
|
{
|
||||||
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
|
||||||
|
if (keyEvent->key() == Qt::Key_Escape)
|
||||||
|
{
|
||||||
|
find_panel->hide();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return QMainWindow::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateTemporalVariables()
|
void MainWindow::updateTemporalVariables()
|
||||||
{
|
{
|
||||||
this->top_ctx.set_variable("$t", Value(this->e_tval->text().toDouble()));
|
this->top_ctx.set_variable("$t", Value(this->e_tval->text().toDouble()));
|
||||||
|
|
Loading…
Reference in New Issue