Commit a767358c authored by jhammen's avatar jhammen
Browse files

basic text replace

parent dfc45760
...@@ -126,6 +126,14 @@ void EditorWidget::findNext(const QString &term) { ...@@ -126,6 +126,14 @@ void EditorWidget::findNext(const QString &term) {
setFocus(); setFocus();
} }
void EditorWidget::replaceNext(const QString &term, const QString &replace) {
QString s = textCursor().selectedText();
if (term.compare(s) == 0) { // make sure term is same as selected text
textCursor().insertText(replace);
find(term); // select next
}
}
void EditorWidget::focusLine(int line, int column) { void EditorWidget::focusLine(int line, int column) {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
cursor.movePosition(QTextCursor::Start); cursor.movePosition(QTextCursor::Start);
......
...@@ -58,6 +58,7 @@ class EditorWidget : public QPlainTextEdit { ...@@ -58,6 +58,7 @@ class EditorWidget : public QPlainTextEdit {
bool save(); bool save();
QList<EditorLink> findAll(const QString &term, bool active); QList<EditorLink> findAll(const QString &term, bool active);
void findNext(const QString &term); void findNext(const QString &term);
void replaceNext(const QString &term, const QString &replace);
void focusLine(int line, int column = 0); void focusLine(int line, int column = 0);
void focusLocation(EditorLocation &loc); void focusLocation(EditorLocation &loc);
void commentSelection(); void commentSelection();
......
...@@ -61,6 +61,8 @@ MainWindow::MainWindow(QWidget *parent) ...@@ -61,6 +61,8 @@ MainWindow::MainWindow(QWidget *parent)
connect(searchWidget, SIGNAL(searchCurrent(QString)), this, SLOT(searchCurrent(QString))); connect(searchWidget, SIGNAL(searchCurrent(QString)), this, SLOT(searchCurrent(QString)));
connect(searchWidget, SIGNAL(searchNext(QString)), this, SLOT(searchNext(QString))); connect(searchWidget, SIGNAL(searchNext(QString)), this, SLOT(searchNext(QString)));
connect(searchWidget, SIGNAL(searchProject(QString)), this, SLOT(searchProject(QString))); connect(searchWidget, SIGNAL(searchProject(QString)), this, SLOT(searchProject(QString)));
connect(searchWidget, SIGNAL(replaceNext(QString, QString)), this,
SLOT(replaceNext(QString, QString)));
connect(searchWidget, SIGNAL(clearSearch()), this, SLOT(clearSearch())); connect(searchWidget, SIGNAL(clearSearch()), this, SLOT(clearSearch()));
connect(searchWidget, SIGNAL(navigateResult(EditorLocation &)), this, connect(searchWidget, SIGNAL(navigateResult(EditorLocation &)), this,
SLOT(handleLink(EditorLocation &))); SLOT(handleLink(EditorLocation &)));
...@@ -236,6 +238,12 @@ void MainWindow::searchNext(const QString &term) { ...@@ -236,6 +238,12 @@ void MainWindow::searchNext(const QString &term) {
} }
} }
void MainWindow::replaceNext(const QString &term, const QString &replace) {
if (currentEditor()) {
currentEditor()->replaceNext(term, replace);
}
}
void MainWindow::searchFolder(const QString &term, NamedFile &folder) { void MainWindow::searchFolder(const QString &term, NamedFile &folder) {
QDir dir(folder.path); QDir dir(folder.path);
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
......
...@@ -53,6 +53,7 @@ class MainWindow : public QMainWindow { ...@@ -53,6 +53,7 @@ class MainWindow : public QMainWindow {
void searchCurrent(const QString &); void searchCurrent(const QString &);
void searchNext(const QString &); void searchNext(const QString &);
void searchProject(const QString &); void searchProject(const QString &);
void replaceNext(const QString &term, const QString &replace);
void clearSearch(); void clearSearch();
void showTime(Position pos); void showTime(Position pos);
void tabChanged(int index); void tabChanged(int index);
......
...@@ -79,6 +79,12 @@ void SearchWidget::on_searchLineEdit_returnPressed() { doSearch(); } ...@@ -79,6 +79,12 @@ void SearchWidget::on_searchLineEdit_returnPressed() { doSearch(); }
void SearchWidget::on_searchLineEdit_textEdited(const QString &) { newSearch = true; } void SearchWidget::on_searchLineEdit_textEdited(const QString &) { newSearch = true; }
void SearchWidget::on_replaceButton_clicked() {
QString term = this->ui->searchLineEdit->text();
QString replace = this->ui->replaceLineEdit->text();
emit replaceNext(term, replace);
}
void SearchWidget::on_refreshButton_clicked() { void SearchWidget::on_refreshButton_clicked() {
newSearch = true; newSearch = true;
doSearch(); doSearch();
......
...@@ -39,6 +39,7 @@ class SearchWidget : public QWidget { ...@@ -39,6 +39,7 @@ class SearchWidget : public QWidget {
void searchCurrent(QString); void searchCurrent(QString);
void searchNext(QString); void searchNext(QString);
void searchProject(QString); void searchProject(QString);
void replaceNext(QString, QString);
void navigateResult(EditorLocation &); void navigateResult(EditorLocation &);
void clearSearch(); void clearSearch();
...@@ -47,6 +48,7 @@ class SearchWidget : public QWidget { ...@@ -47,6 +48,7 @@ class SearchWidget : public QWidget {
void on_searchButton_clicked(); void on_searchButton_clicked();
void on_searchLineEdit_returnPressed(); void on_searchLineEdit_returnPressed();
void on_searchLineEdit_textEdited(const QString &arg1); void on_searchLineEdit_textEdited(const QString &arg1);
void on_replaceButton_clicked();
void on_refreshButton_clicked(); void on_refreshButton_clicked();
void on_fileScopeButton_clicked(); void on_fileScopeButton_clicked();
void on_projectScopeButton_clicked(); void on_projectScopeButton_clicked();
......
...@@ -27,6 +27,20 @@ ...@@ -27,6 +27,20 @@
</widget> </widget>
</item> </item>
</layout> </layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="replaceLineEdit"/>
</item>
<item>
<widget class="QPushButton" name="replaceButton">
<property name="text">
<string>Replace</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
...@@ -60,7 +74,7 @@ ...@@ -60,7 +74,7 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<widget class="QLabel" name="countLabel"> <widget class="QLabel" name="countLabel">
<property name="text"> <property name="text">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment