diff options
author | Ken Moore <moorekou@gmail.com> | 2016-04-19 13:53:17 -0400 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2016-04-19 13:53:17 -0400 |
commit | 2ac52279a091b1e4a81df199d302e12c8e2cad3e (patch) | |
tree | 5c6bf9cd643cb9379c14dd69f12389fbe27c2685 /desktop-utilities | |
parent | Some more work on lumina-textedit. (diff) | |
download | lumina-2ac52279a091b1e4a81df199d302e12c8e2cad3e.tar.gz lumina-2ac52279a091b1e4a81df199d302e12c8e2cad3e.tar.bz2 lumina-2ac52279a091b1e4a81df199d302e12c8e2cad3e.zip |
Get find/replace support fully implemented.
Diffstat (limited to 'desktop-utilities')
-rw-r--r-- | desktop-utilities/lumina-textedit/MainUI.cpp | 110 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/MainUI.h | 12 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/MainUI.ui | 169 | ||||
-rw-r--r-- | desktop-utilities/lumina-textedit/syntaxSupport.cpp | 4 |
4 files changed, 292 insertions, 3 deletions
diff --git a/desktop-utilities/lumina-textedit/MainUI.cpp b/desktop-utilities/lumina-textedit/MainUI.cpp index d477071d..86f204bc 100644 --- a/desktop-utilities/lumina-textedit/MainUI.cpp +++ b/desktop-utilities/lumina-textedit/MainUI.cpp @@ -14,6 +14,7 @@ #include <QFileDialog> #include <QDir> +#include <QKeySequence> MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); @@ -21,6 +22,9 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ Custom_Syntax::SetupDefaultColors(settings); //pre-load any color settings as needed this->setWindowTitle(tr("Text Editor")); ui->tabWidget->clear(); + closeFindS = new QShortcut(QKeySequence(Qt::Key_Escape), this); + connect(closeFindS, SIGNAL(activated()), this, SLOT(closeFindReplace()) ); + ui->groupReplace->setVisible(false); //Update the menu of available syntax highlighting modes QStringList smodes = Custom_Syntax::availableRules(); for(int i=0; i<smodes.length(); i++){ @@ -41,6 +45,14 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->actionLine_Numbers, SIGNAL(toggled(bool)), this, SLOT(showLineNumbers(bool)) ); connect(ui->actionWrap_Lines, SIGNAL(toggled(bool)), this, SLOT(wrapLines(bool)) ); connect(ui->actionCustomize_Colors, SIGNAL(triggered()), this, SLOT(ModifyColors()) ); + connect(ui->actionFind, SIGNAL(triggered()), this, SLOT(openFind()) ); + connect(ui->actionReplace, SIGNAL(triggered()), this, SLOT(openReplace()) ); + connect(ui->tool_find_next, SIGNAL(clicked()), this, SLOT(findNext()) ); + connect(ui->tool_find_prev, SIGNAL(clicked()), this, SLOT(findPrev()) ); + connect(ui->tool_replace, SIGNAL(clicked()), this, SLOT(replaceOne()) ); + connect(ui->tool_replace_all, SIGNAL(clicked()), this, SLOT(replaceAll()) ); + connect(ui->line_find, SIGNAL(returnPressed()), this, SLOT(findNext()) ); + connect(ui->line_replace, SIGNAL(returnPressed()), this, SLOT(replaceOne()) ); updateIcons(); //Now load the initial size of the window QSize lastSize = settings->value("lastSize",QSize()).toSize(); @@ -56,6 +68,7 @@ MainUI::~MainUI(){ void MainUI::LoadArguments(QStringList args){ //CLI arguments for(int i=0; i<args.length(); i++){ OpenFile( LUtils::PathToAbsolute(args[i]) ); + ui->line_find->setFocus(); } } @@ -70,9 +83,17 @@ void MainUI::updateIcons(){ ui->actionClose_File->setIcon(LXDG::findIcon("document-close") ); ui->actionSave_File->setIcon(LXDG::findIcon("document-save") ); ui->actionSave_File_As->setIcon(LXDG::findIcon("document-save-as") ); + ui->actionFind->setIcon(LXDG::findIcon("edit-find") ); + ui->actionReplace->setIcon(LXDG::findIcon("edit-find-replace") ); ui->menuSyntax_Highlighting->setIcon( LXDG::findIcon("format-text-color") ); ui->actionCustomize_Colors->setIcon( LXDG::findIcon("format-fill-color") ); - + //icons for the special find/replace groupbox + ui->tool_find_next->setIcon(LXDG::findIcon("go-down-search")); + ui->tool_find_prev->setIcon(LXDG::findIcon("go-up-search")); + ui->tool_find_casesensitive->setIcon(LXDG::findIcon("format-text-italic")); + ui->tool_replace->setIcon(LXDG::findIcon("arrow-down")); + ui->tool_replace_all->setIcon(LXDG::findIcon("arrow-down-double")); + //ui->tool_find_next->setIcon(LXDG::findIcon("")); } // ================= @@ -118,6 +139,7 @@ void MainUI::OpenFile(QString file){ ui->tabWidget->addTab(edit, files[i].section("/",-1)); edit->showLineNumbers(ui->actionLine_Numbers->isChecked()); edit->setLineWrapMode( ui->actionWrap_Lines->isChecked() ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap); + edit->setFocusPolicy(Qt::ClickFocus); //no "tabbing" into this widget ui->tabWidget->setCurrentWidget(edit); edit->LoadFile(files[i]); edit->setFocus(); @@ -206,3 +228,89 @@ void MainUI::tabClosed(int tab){ ui->tabWidget->removeTab(tab); edit->deleteLater(); } + +//Find/Replace functions +void MainUI::closeFindReplace(){ + ui->groupReplace->setVisible(false); + PlainTextEditor *cur = currentEditor(); + if(cur!=0){ cur->setFocus(); } +} + +void MainUI::openFind(){ + PlainTextEditor *cur = currentEditor(); + if(cur==0){ return; } + ui->groupReplace->setVisible(true); + ui->line_find->setText( cur->textCursor().selectedText() ); + ui->line_replace->setText(""); + ui->line_find->setFocus(); +} + +void MainUI::openReplace(){ + PlainTextEditor *cur = currentEditor(); + if(cur==0){ return; } + ui->groupReplace->setVisible(true); + ui->line_find->setText( cur->textCursor().selectedText() ); + ui->line_replace->setText(""); + ui->line_replace->setFocus(); +} + +void MainUI::findNext(){ + PlainTextEditor *cur = currentEditor(); + if(cur==0){ return; } + bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); + if(!found){ + //Try starting back at the top of the file + cur->moveCursor(QTextCursor::Start); + cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); + } +} + +void MainUI::findPrev(){ + PlainTextEditor *cur = currentEditor(); + if(cur==0){ return; } + bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively | QTextDocument::FindBackward : QTextDocument::FindBackward ); + if(!found){ + //Try starting back at the bottom of the file + cur->moveCursor(QTextCursor::End); + cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively | QTextDocument::FindBackward : QTextDocument::FindBackward ); + } +} + +void MainUI::replaceOne(){ + PlainTextEditor *cur = currentEditor(); + if(cur==0){ return; } + //See if the current selection matches the find field first + bool done = false; + if(cur->textCursor().selectedText()==ui->line_find->text()){ + cur->insertPlainText(ui->line_replace->text()); + done = true; + }else{ + //Find/replace the next occurance of the string + bool found = cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ); + if(found){ cur->insertPlainText(ui->line_replace->text()); done = true;} + } + if(done){ + //Re-highlight the newly-inserted text + cur->find( ui->line_replace->text(), QTextDocument::FindCaseSensitively | QTextDocument::FindBackward); + } +} + +void MainUI::replaceAll(){ +PlainTextEditor *cur = currentEditor(); + if(cur==0){ return; } + //See if the current selection matches the find field first + bool done = false; + if(cur->textCursor().selectedText()==ui->line_find->text()){ + cur->insertPlainText(ui->line_replace->text()); + done = true; + } + while( cur->find( ui->line_find->text(), ui->tool_find_casesensitive->isChecked() ? QTextDocument::FindCaseSensitively : QTextDocument::FindFlags() ) ){ + //Find/replace every occurance of the string + cur->insertPlainText(ui->line_replace->text()); + done = true; + } + if(done){ + //Re-highlight the newly-inserted text + cur->find( ui->line_replace->text(), QTextDocument::FindCaseSensitively | QTextDocument::FindBackward); + } +} diff --git a/desktop-utilities/lumina-textedit/MainUI.h b/desktop-utilities/lumina-textedit/MainUI.h index 64b4de3d..e040591a 100644 --- a/desktop-utilities/lumina-textedit/MainUI.h +++ b/desktop-utilities/lumina-textedit/MainUI.h @@ -10,6 +10,7 @@ #include <QMainWindow> #include <QStringList> #include <QSettings> +#include <QShortcut> #include "PlainTextEditor.h" @@ -31,6 +32,7 @@ public slots: private: Ui::MainUI *ui; QSettings *settings; + QShortcut *closeFindS; //Simplification functions PlainTextEditor* currentEditor(); @@ -55,6 +57,16 @@ private slots: void tabChanged(); void tabClosed(int); + //Find/Replace functions + void closeFindReplace(); + void openFind(); + void openReplace(); + + void findNext(); + void findPrev(); + void replaceOne(); + void replaceAll(); + protected: void resizeEvent(QResizeEvent *ev){ settings->setValue("lastSize", ev->size()); diff --git a/desktop-utilities/lumina-textedit/MainUI.ui b/desktop-utilities/lumina-textedit/MainUI.ui index 264646d7..0bd17b99 100644 --- a/desktop-utilities/lumina-textedit/MainUI.ui +++ b/desktop-utilities/lumina-textedit/MainUI.ui @@ -15,6 +15,9 @@ </property> <widget class="QWidget" name="centralwidget"> <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>2</number> + </property> <property name="leftMargin"> <number>0</number> </property> @@ -29,6 +32,9 @@ </property> <item> <widget class="QTabWidget" name="tabWidget"> + <property name="focusPolicy"> + <enum>Qt::ClickFocus</enum> + </property> <property name="tabsClosable"> <bool>true</bool> </property> @@ -45,6 +51,136 @@ </widget> </widget> </item> + <item> + <widget class="QGroupBox" name="groupReplace"> + <property name="title"> + <string>Find/Replace</string> + </property> + <property name="flat"> + <bool>false</bool> + </property> + <layout class="QGridLayout" name="gridLayout"> + <property name="leftMargin"> + <number>1</number> + </property> + <property name="topMargin"> + <number>3</number> + </property> + <property name="rightMargin"> + <number>1</number> + </property> + <property name="bottomMargin"> + <number>1</number> + </property> + <property name="spacing"> + <number>2</number> + </property> + <item row="1" column="1"> + <widget class="QLineEdit" name="line_replace"/> + </item> + <item row="0" column="2"> + <widget class="QToolButton" name="tool_find_prev"> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="statusTip"> + <string>Find the previous match</string> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Find:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="3"> + <widget class="QToolButton" name="tool_find_next"> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="statusTip"> + <string>Find the next match</string> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Replace:</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="line_find"/> + </item> + <item row="0" column="4"> + <widget class="QToolButton" name="tool_find_casesensitive"> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="toolTip"> + <string/> + </property> + <property name="statusTip"> + <string>Match case</string> + </property> + <property name="text"> + <string notr="true"/> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + <property name="checked"> + <bool>false</bool> + </property> + <property name="autoRaise"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QToolButton" name="tool_replace"> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="statusTip"> + <string>Replace next match</string> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item row="1" column="3"> + <widget class="QToolButton" name="tool_replace_all"> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="statusTip"> + <string>Replace all matches (to end of document)</string> + </property> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> </layout> </widget> <widget class="QMenuBar" name="menubar"> @@ -86,11 +222,22 @@ <addaction name="separator"/> <addaction name="actionCustomize_Colors"/> </widget> + <widget class="QMenu" name="menuEdit"> + <property name="title"> + <string>Edit</string> + </property> + <addaction name="actionFind"/> + <addaction name="actionReplace"/> + </widget> <addaction name="menuFile"/> + <addaction name="menuEdit"/> <addaction name="menuView"/> </widget> <widget class="QStatusBar" name="statusbar"/> <widget class="QToolBar" name="toolBar"> + <property name="contextMenuPolicy"> + <enum>Qt::CustomContextMenu</enum> + </property> <property name="windowTitle"> <string>toolBar</string> </property> @@ -202,6 +349,28 @@ <string>Wrap Lines</string> </property> </action> + <action name="actionFind"> + <property name="text"> + <string>Find</string> + </property> + <property name="shortcut"> + <string>Ctrl+F</string> + </property> + <property name="shortcutContext"> + <enum>Qt::ApplicationShortcut</enum> + </property> + </action> + <action name="actionReplace"> + <property name="text"> + <string>Replace</string> + </property> + <property name="shortcut"> + <string>Ctrl+R</string> + </property> + <property name="shortcutContext"> + <enum>Qt::ApplicationShortcut</enum> + </property> + </action> </widget> <resources/> <connections/> diff --git a/desktop-utilities/lumina-textedit/syntaxSupport.cpp b/desktop-utilities/lumina-textedit/syntaxSupport.cpp index 2d00201f..1e3f796b 100644 --- a/desktop-utilities/lumina-textedit/syntaxSupport.cpp +++ b/desktop-utilities/lumina-textedit/syntaxSupport.cpp @@ -152,12 +152,12 @@ void Custom_Syntax::loadRules(QString type){ // Strong Emphasis rule.format.setFontItalic(false); rule.format.setFontWeight(QFont::Bold); - rule.pattern = QRegExp("\\b[*]{2}.*[*]{2}\\b"); + rule.pattern = QRegExp("\\b[*]{2}[^*\n]+[*]{2}\\b"); rules << rule; // Emphasis rule.format.setFontItalic(true); rule.format.setFontWeight(QFont::Normal); - rule.pattern = QRegExp("\\b[*].+[*]\\b"); + rule.pattern = QRegExp("\\b[*][^*\n]+[*]\\b"); rules << rule; // Code Sample rule.format.setFontItalic(false); |