mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-18 10:26:15 +01:00
Allow saving the results of a regular expression search into a file
This commit is contained in:
parent
746abef2cf
commit
cae5f38af5
3 changed files with 64 additions and 3 deletions
|
@ -75,6 +75,8 @@ DicToolsWidget::DicToolsWidget(QWidget *parent)
|
|||
this, SLOT(refreshRegexp()));
|
||||
QObject::connect(buttonSearchRegexp, SIGNAL(clicked()),
|
||||
this, SLOT(refreshRegexp()));
|
||||
QObject::connect(buttonSaveRegexp, SIGNAL(clicked()),
|
||||
this, SLOT(saveRegexpResults()));
|
||||
QObject::connect(buttonSaveWords, SIGNAL(clicked()),
|
||||
this, SLOT(exportWordsList()));
|
||||
|
||||
|
@ -244,7 +246,9 @@ void DicToolsWidget::refreshPlus1()
|
|||
|
||||
void DicToolsWidget::enableSearchRegexp()
|
||||
{
|
||||
buttonSearchRegexp->setEnabled(lineEditRegexp->text() != "");
|
||||
bool hasText = lineEditRegexp->text() != "";
|
||||
buttonSearchRegexp->setEnabled(hasText);
|
||||
buttonSaveRegexp->setEnabled(m_dic != NULL && hasText);
|
||||
}
|
||||
|
||||
|
||||
|
@ -306,6 +310,47 @@ void DicToolsWidget::refreshRegexp()
|
|||
}
|
||||
|
||||
|
||||
void DicToolsWidget::saveRegexpResults()
|
||||
{
|
||||
if (m_dic == NULL)
|
||||
return;
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(this, _q("Save words list"));
|
||||
if (fileName != "")
|
||||
{
|
||||
const wstring &input = m_dic->convertFromInput(wfq(lineEditRegexp->text().toUpper()));
|
||||
unsigned lmin = spinBoxMinLength->value();
|
||||
unsigned lmax = spinBoxMaxLength->value();
|
||||
vector<wstring> wordList;
|
||||
try
|
||||
{
|
||||
m_dic->searchRegExp(input, wordList, lmin, lmax, 0);
|
||||
}
|
||||
catch (InvalidRegexpException &e)
|
||||
{
|
||||
QMessageBox::warning(this, _q("Eliot - Error"),
|
||||
_q("Invalid regular expression: %1").arg(qfl(e.what())));
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
ofstream file(lfq(fileName).c_str());
|
||||
foreach (const wstring &word, wordList)
|
||||
{
|
||||
file << lfw(word) << endl;
|
||||
}
|
||||
QMessageBox::information(this, _q("Save words list"),
|
||||
_q("File '%1' successfully saved").arg(fileName));
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
QMessageBox::warning(this, _q("Eliot - Error"),
|
||||
_q("Cannot save the words list: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DicToolsWidget::refreshDicInfo()
|
||||
{
|
||||
if (m_dic == NULL)
|
||||
|
@ -366,14 +411,14 @@ void DicToolsWidget::exportWordsList()
|
|||
{
|
||||
if (m_dic == NULL)
|
||||
return;
|
||||
QString fileName = QFileDialog::getSaveFileName(this, _q("Export words list"));
|
||||
QString fileName = QFileDialog::getSaveFileName(this, _q("Save words list"));
|
||||
if (fileName != "")
|
||||
{
|
||||
try
|
||||
{
|
||||
ofstream file(lfq(fileName).c_str());
|
||||
ListDic::printWords(file, *m_dic);
|
||||
QMessageBox::information(this, _q("Export words list"),
|
||||
QMessageBox::information(this, _q("Save words list"),
|
||||
_q("File '%1' successfully saved").arg(fileName));
|
||||
}
|
||||
catch (std::exception &e)
|
||||
|
|
|
@ -77,6 +77,8 @@ private slots:
|
|||
void enableSearchPlus1();
|
||||
void enableSearchRegexp();
|
||||
|
||||
void saveRegexpResults();
|
||||
|
||||
/// Force synchronizing the model with the "check" results
|
||||
void refreshCheck();
|
||||
/// Force synchronizing the model with the "plus 1" results
|
||||
|
|
|
@ -103,6 +103,16 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonSaveRegexp">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>_("Save list...")</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -122,6 +132,9 @@
|
|||
<property name="maximum">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>2</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -287,6 +300,7 @@
|
|||
<tabstop>treeViewPlus1</tabstop>
|
||||
<tabstop>lineEditRegexp</tabstop>
|
||||
<tabstop>buttonSearchRegexp</tabstop>
|
||||
<tabstop>buttonSaveRegexp</tabstop>
|
||||
<tabstop>spinBoxMinLength</tabstop>
|
||||
<tabstop>spinBoxMaxLength</tabstop>
|
||||
<tabstop>treeViewRegexp</tabstop>
|
||||
|
|
Loading…
Reference in a new issue