some more work concerning find/replace
This commit is contained in:
@ -29,15 +29,41 @@
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qpushbutton.h>
|
||||
#include <qcombobox.h>
|
||||
#include <qcheckbox.h>
|
||||
|
||||
#include "PReplaceDialog.h"
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
PReplaceDialog::PReplaceDialog(PFindReplaceData *data, QWidget *parent, const char *name, bool modal, WFlags f) :
|
||||
PReplaceDialog::PReplaceDialog(PFindReplaceData *data, const bool selection, QWidget *parent, const char *name, bool modal, WFlags f) :
|
||||
PReplaceDialogBase(parent, name, modal, f), fData(data)
|
||||
{
|
||||
// if only empty text, disable find button
|
||||
if (fData->findText == "") {
|
||||
fReplace_button->setEnabled(false);
|
||||
}
|
||||
|
||||
// if there is no selection, disable that option
|
||||
if (!selection) {
|
||||
fSelectedText_checkBox->setChecked(false);
|
||||
fSelectedText_checkBox->setEnabled(false);
|
||||
}
|
||||
|
||||
fFind_comboBox->setCurrentText(fData->findText);
|
||||
fReplacementText_comboBox->setCurrentText(fData->replaceText);
|
||||
fCaseSensitive_checkBox->setChecked(fData->caseSensitive);
|
||||
fWholeWordsOnly_checkBox->setChecked(fData->wholeWordsOnly);
|
||||
fFromCursor_checkBox->setChecked(fData->fromCursor);
|
||||
fFindBackwards_checkBox->setChecked(fData->findBackwards);
|
||||
fPromptOnReplace_checkBox->setChecked(fData->promptOnReplace);
|
||||
|
||||
if (selection) {
|
||||
fSelectedText_checkBox->setChecked(fData->selectedText);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -46,9 +72,31 @@ PReplaceDialog::PReplaceDialog(PFindReplaceData *data, QWidget *parent, const ch
|
||||
*/
|
||||
PFindReplaceData* PReplaceDialog::getData()
|
||||
{
|
||||
fData->findText = fFind_comboBox->currentText();
|
||||
fData->replaceText = fReplacementText_comboBox->currentText();
|
||||
fData->caseSensitive = fCaseSensitive_checkBox->isChecked();
|
||||
fData->wholeWordsOnly = fWholeWordsOnly_checkBox->isChecked();
|
||||
fData->fromCursor = fFromCursor_checkBox->isChecked();
|
||||
fData->findBackwards = fFindBackwards_checkBox->isChecked();
|
||||
if (fSelectedText_checkBox->isEnabled())
|
||||
fData->selectedText = fSelectedText_checkBox->isChecked();
|
||||
fData->promptOnReplace = fPromptOnReplace_checkBox->isChecked();
|
||||
|
||||
return fData;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
void PReplaceDialog::onFindTextAvailable()
|
||||
{
|
||||
if (fFind_comboBox->currentText() != "")
|
||||
fReplace_button->setEnabled(true);
|
||||
else
|
||||
fReplace_button->setEnabled(false);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// END
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
@ -40,12 +40,15 @@ class PReplaceDialog : public PReplaceDialogBase
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PReplaceDialog(PFindReplaceData *data, QWidget *parent = 0, const char *name = 0,
|
||||
PReplaceDialog(PFindReplaceData *data, const bool selection, QWidget *parent = 0, const char *name = 0,
|
||||
bool modal = TRUE, WFlags f = 0);
|
||||
virtual ~PReplaceDialog() {}
|
||||
|
||||
virtual PFindReplaceData *getData();
|
||||
|
||||
protected slots:
|
||||
virtual void onFindTextAvailable();
|
||||
|
||||
private:
|
||||
PFindReplaceData *fData;
|
||||
};
|
||||
|
@ -61,6 +61,7 @@ using namespace std;
|
||||
#include "PAdmin.h"
|
||||
#include "PFindDialog.h"
|
||||
#include "PReplaceDialog.h"
|
||||
#include "forms/PReplaceConfirmationDialog.h"
|
||||
#include "PFitOutputHandler.h"
|
||||
#include "PPrefsDialog.h"
|
||||
#include "PGetDefaultDialog.h"
|
||||
@ -834,7 +835,7 @@ void PTextEdit::editFindAndReplace()
|
||||
return;
|
||||
}
|
||||
|
||||
PReplaceDialog *dlg = new PReplaceDialog(fFindReplaceData);
|
||||
PReplaceDialog *dlg = new PReplaceDialog(fFindReplaceData, currentEditor()->hasSelectedText());
|
||||
|
||||
dlg->exec();
|
||||
|
||||
@ -846,7 +847,21 @@ void PTextEdit::editFindAndReplace()
|
||||
fFindReplaceData = dlg->getData();
|
||||
|
||||
delete dlg;
|
||||
QMessageBox::information(this, "**INFO**", "Not Yet Implemented", QMessageBox::Ok);
|
||||
|
||||
editFindNext();
|
||||
|
||||
PReplaceConfirmationDialog *confirmDlg = new PReplaceConfirmationDialog(this);
|
||||
|
||||
// connect all the necessary signals/slots
|
||||
QObject::connect(confirmDlg->fReplace_pushButton, SIGNAL(clicked()), this, SLOT(replace()));
|
||||
QObject::connect(confirmDlg->fReplaceAndClose_pushButton, SIGNAL(clicked()), this, SLOT(replaceAndClose()));
|
||||
QObject::connect(confirmDlg->fReplaceAll_pushButton, SIGNAL(clicked()), this, SLOT(replaceAll()));
|
||||
QObject::connect(confirmDlg->fFindNext_pushButton, SIGNAL(clicked()), this, SLOT(editFindNext()));
|
||||
QObject::connect(this, SIGNAL(close()), confirmDlg, SLOT(accept()));
|
||||
|
||||
confirmDlg->exec();
|
||||
|
||||
delete confirmDlg;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -1598,6 +1613,57 @@ void PTextEdit::textChanged()
|
||||
fTabWidget->setTabLabel(fTabWidget->currentPage(), tabLabel+"*");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
void PTextEdit::replace()
|
||||
{
|
||||
currentEditor()->insert(fFindReplaceData->replaceText);
|
||||
|
||||
editFindNext();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
void PTextEdit::replaceAndClose()
|
||||
{
|
||||
currentEditor()->insert(fFindReplaceData->replaceText);
|
||||
|
||||
emit close();
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* <p>
|
||||
*/
|
||||
void PTextEdit::replaceAll()
|
||||
{
|
||||
int currentPara, currentIndex;
|
||||
currentEditor()->getCursorPosition(¤tPara, ¤tIndex);
|
||||
|
||||
currentEditor()->setCursorPosition(0,0);
|
||||
|
||||
int para = 0, index = 0;
|
||||
while (currentEditor()->find(fFindReplaceData->findText,
|
||||
fFindReplaceData->caseSensitive,
|
||||
fFindReplaceData->wholeWordsOnly,
|
||||
true,
|
||||
¶, &index)) {
|
||||
// set cursor to the correct position
|
||||
currentEditor()->setCursorPosition(para, index);
|
||||
|
||||
// replace the text
|
||||
currentEditor()->insert(fFindReplaceData->replaceText);
|
||||
}
|
||||
|
||||
emit close();
|
||||
|
||||
currentEditor()->setCursorPosition(currentPara, currentIndex);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// END
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
@ -53,6 +53,9 @@ public:
|
||||
PTextEdit( QWidget *parent = 0, const char *name = 0 );
|
||||
virtual ~PTextEdit();
|
||||
|
||||
signals:
|
||||
void close();
|
||||
|
||||
private:
|
||||
void setupFileActions();
|
||||
void setupEditActions();
|
||||
@ -106,6 +109,10 @@ private slots:
|
||||
void fontChanged( const QFont &f );
|
||||
void textChanged();
|
||||
|
||||
void replace();
|
||||
void replaceAndClose();
|
||||
void replaceAll();
|
||||
|
||||
private:
|
||||
PAdmin *fAdmin;
|
||||
|
||||
|
182
src/musrgui/forms/PReplaceConfirmationDialog.ui
Normal file
182
src/musrgui/forms/PReplaceConfirmationDialog.ui
Normal file
@ -0,0 +1,182 @@
|
||||
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
|
||||
<class>PReplaceConfirmationDialog</class>
|
||||
<widget class="QDialog">
|
||||
<property name="name">
|
||||
<cstring>PReplaceConfirmationDialog</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>524</width>
|
||||
<height>86</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="caption">
|
||||
<string>Replace Confirmation - musrgui</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<pixmap>image0</pixmap>
|
||||
</property>
|
||||
<property name="sizeGripEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="Line">
|
||||
<property name="name">
|
||||
<cstring>line1</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>30</y>
|
||||
<width>501</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>Sunken</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel">
|
||||
<property name="name">
|
||||
<cstring>fTextLabel</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>435</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Found an occurrence of your search term. What do you want to do?</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fReplaceAndClose_pushButton</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>100</x>
|
||||
<y>50</y>
|
||||
<width>130</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Re&place && Close</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>Alt+P</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fClose_pushButton</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>450</x>
|
||||
<y>50</y>
|
||||
<width>60</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Close</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>Alt+C</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fReplaceAll_pushButton</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>240</x>
|
||||
<y>50</y>
|
||||
<width>100</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Replace &All</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>Alt+A</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fReplace_pushButton</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>50</y>
|
||||
<width>80</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Replace</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>Alt+R</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fFindNext_pushButton</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>350</x>
|
||||
<y>50</y>
|
||||
<width>90</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Find Next</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>Alt+F</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<images>
|
||||
<image name="image0">
|
||||
<data format="PNG" length="268">89504e470d0a1a0a0000000d4948445200000016000000160806000000c4b46c3b000000d349444154388db594510e84200c44a7864bd9fb673c16fe50b7a95501dd97104983435b06842422ab6ab5f946ca6941074b0ca813cd36eaa5f89f050049811352d53aac8a96b165640256fe468ac546b33eb5c298ededa3f05b1655adbef4b8c062a3e92fbc117d83643ebe6275d53dd1dd637345af3b3e3bbcb8e19470763b23ddc2de3924c58b676d2a67897b717f4b25dcd848f5a3b9e4f8c651dd200992c86205680f4f82c555b51e6b92fe5a2502c0cc3bd40a13b98a133faf17cb286639833fc4db56bce17fafdb9762deeb438fd0083bbf3298df1bba5b870000000049454e44ae426082</data>
|
||||
</image>
|
||||
</images>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>fClose_pushButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PReplaceConfirmationDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
<tabstops>
|
||||
<tabstop>fReplace_pushButton</tabstop>
|
||||
<tabstop>fReplaceAndClose_pushButton</tabstop>
|
||||
<tabstop>fReplaceAll_pushButton</tabstop>
|
||||
<tabstop>fFindNext_pushButton</tabstop>
|
||||
<tabstop>fClose_pushButton</tabstop>
|
||||
</tabstops>
|
||||
<layoutdefaults spacing="6" margin="11"/>
|
||||
</UI>
|
@ -244,31 +244,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fFind_button</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>200</x>
|
||||
<y>310</y>
|
||||
<width>60</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Find</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>Alt+F</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fClose_button</cstring>
|
||||
@ -291,6 +266,31 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>fReplace_button</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>190</x>
|
||||
<y>310</y>
|
||||
<width>70</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Replace</string>
|
||||
</property>
|
||||
<property name="accel">
|
||||
<string>Alt+R</string>
|
||||
</property>
|
||||
<property name="autoDefault">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="default">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<connections>
|
||||
<connection>
|
||||
@ -300,11 +300,17 @@
|
||||
<slot>reject()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>fFind_button</sender>
|
||||
<sender>fReplace_button</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>PReplaceDialogBase</receiver>
|
||||
<slot>accept()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>fFind_comboBox</sender>
|
||||
<signal>textChanged(const QString&)</signal>
|
||||
<receiver>PReplaceDialogBase</receiver>
|
||||
<slot>onFindTextAvailable()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
<tabstops>
|
||||
<tabstop>fFind_comboBox</tabstop>
|
||||
@ -315,8 +321,11 @@
|
||||
<tabstop>fFindBackwards_checkBox</tabstop>
|
||||
<tabstop>fSelectedText_checkBox</tabstop>
|
||||
<tabstop>fPromptOnReplace_checkBox</tabstop>
|
||||
<tabstop>fFind_button</tabstop>
|
||||
<tabstop>fReplace_button</tabstop>
|
||||
<tabstop>fClose_button</tabstop>
|
||||
</tabstops>
|
||||
<slots>
|
||||
<slot access="protected">onFindTextAvailable()</slot>
|
||||
</slots>
|
||||
<layoutdefaults spacing="6" margin="11"/>
|
||||
</UI>
|
||||
|
@ -52,7 +52,8 @@ SOURCES = PTextEdit.cpp \
|
||||
main.cpp
|
||||
|
||||
FORMS = forms/PFindDialogBase.ui \
|
||||
forms/PReplaceDialogBase.ui \
|
||||
forms/PReplaceDialogBase.ui \
|
||||
forms/PReplaceConfirmationDialog.ui \
|
||||
forms/PGetDefaultDialogBase.ui \
|
||||
forms/PMusrGuiAbout.ui \
|
||||
forms/PPrefsDialogBase.ui \
|
||||
|
Reference in New Issue
Block a user