#include <QCloseEvent>
#include <QLineEdit>
+#include <QMenu>
#include <iostream>
replace_work_area_->init();
// We don't want two cursors blinking.
replace_work_area_->stopBlinkingCursor();
+
+ QMenu * menu = new QMenu();
+ QAction * regAny = menu->addAction("&Anything");
+ regAny->setData(".*");
+ QAction * regAnyNonEmpty = menu->addAction("Any non-&empty");
+ regAnyNonEmpty->setData(".+");
+ QAction * regAnyWord = menu->addAction("Any &word");
+ regAnyWord->setData("[a-z]+");
+ QAction * regAnyNumber = menu->addAction("Any &number");
+ regAnyNumber->setData("[0-9]+");
+ QAction * regCustom = menu->addAction("&User-defined");
+ regCustom->setData("");
+ regexpInsertPB->setMenu(menu);
+
+ connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(insertRegexp(QAction *)));
}
}
-void FindAndReplaceWidget::on_regexpInsertCombo_currentIndexChanged(int index)
+void FindAndReplaceWidget::insertRegexp(QAction * action)
{
- static char const * regexps[] = {
- ".*", ".+", "[a-z]+", "[0-9]+", ""
- };
- LYXERR(Debug::FIND, "Index: " << index);
- if (index >= 1 && index < 1 + int(sizeof(regexps)/sizeof(regexps[0]))) {
- find_work_area_->setFocus();
- Cursor & cur = find_work_area_->bufferView().cursor();
- if (! cur.inRegexped())
- dispatch(FuncRequest(LFUN_REGEXP_MODE));
- dispatch(FuncRequest(LFUN_SELF_INSERT, regexps[index - 1]));
- regexpInsertCombo->setCurrentIndex(0);
- }
+ string const regexp = fromqstr(action->data().toString());
+ LYXERR(Debug::FIND, "Regexp: " << regexp);
+ find_work_area_->setFocus();
+ Cursor & cur = find_work_area_->bufferView().cursor();
+ if (!cur.inRegexped())
+ dispatch(FuncRequest(LFUN_REGEXP_MODE));
+ dispatch(FuncRequest(LFUN_SELF_INSERT, regexp));
}
FindAndReplace::FindAndReplace(GuiView & parent,
Qt::DockWidgetArea area, Qt::WindowFlags flags)
- : DockView(parent, "Find LyX", qt_("Find LyX Dialog"), area, flags)
+ : DockView(parent, "Find LyX", qt_("Advanced Find and Replace"), area, flags)
{
widget_ = new FindAndReplaceWidget(parent);
setWidget(widget_);
void on_replacePrevPB_clicked();
void on_replaceallPB_clicked();
void on_closePB_clicked();
- void on_regexpInsertCombo_currentIndexChanged(int index);
+ void insertRegexp(QAction *);
};
</widget>
</widget>
</item>
- <item row="2" column="0">
+ <item row="2" column="1">
<widget class="QPushButton" name="replaceNextPB">
<property name="enabled">
<bool>true</bool>
<string>Find next occurrence and replace it [Enter]</string>
</property>
<property name="text">
- <string>Next</string>
+ <string>Ne&xt</string>
</property>
</widget>
</item>
- <item row="2" column="1">
+ <item row="2" column="0">
<widget class="QPushButton" name="replacePrevPB">
<property name="enabled">
<bool>true</bool>
<string>Find previous occurrence and replace it [Shift+Enter]</string>
</property>
<property name="text">
- <string>Prev</string>
+ <string>Pre&vious</string>
</property>
</widget>
</item>
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="toolTip">
+ <string>Replace all occurences at once</string>
+ </property>
<property name="text">
<string>Replace &All</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
- <widget class="QComboBox" name="regexpInsertCombo">
- <property name="enabled">
- <bool>true</bool>
- </property>
+ <widget class="QPushButton" name="regexpInsertPB">
<property name="sizePolicy">
<sizepolicy>
- <hsizetype>7</hsizetype>
- <vsizetype>1</vsizetype>
+ <hsizetype>3</hsizetype>
+ <vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<property name="toolTip">
<string>Choose one of the pre-arranged regular expressions.</string>
</property>
- <item>
- <property name="text">
- <string>Match...</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Anything</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Any non-empty</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Any word</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>Any number</string>
- </property>
- </item>
- <item>
- <property name="text">
- <string>User-defined</string>
- </property>
- </item>
+ <property name="text">
+ <string>Insert Re&gular Expression...</string>
+ </property>
</widget>
</item>
- <item row="4" column="0">
+ <item row="4" column="1">
<widget class="QPushButton" name="findNextPB">
<property name="enabled">
<bool>true</bool>
<string>Find next occurrence [Enter]</string>
</property>
<property name="text">
- <string>Next</string>
+ <string>&Next</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
- <item row="4" column="1">
+ <item row="4" column="0">
<widget class="QPushButton" name="findPrevPB">
<property name="enabled">
<bool>true</bool>
<string>Find previous occurrence [Shift+Enter]</string>
</property>
<property name="text">
- <string>Prev</string>
+ <string>&Previous</string>
</property>
<property name="default">
<bool>true</bool>