64 #if defined (HAVE_CONFIG_H)
68 #if defined (HAVE_QSCINTILLA)
70 #include <QApplication>
74 #include <QDialogButtonBox>
75 #include <QGridLayout>
79 #include <QMessageBox>
80 #include <QPushButton>
81 #include <QVBoxLayout>
93 :
QDialog (p), m_octave_qobj (oct_qobj), m_editor (ed),
94 m_in_sel (false), m_sel_beg (-1), m_sel_end (-1)
96 setWindowTitle (tr (
"Editor: Find and Replace"));
98 m_search_label =
new QLabel (tr (
"Find &what:"));
99 m_search_line_edit =
new QComboBox (
this);
100 m_search_line_edit->setToolTip (tr (
"Enter text to search for"));
101 m_search_line_edit->setEditable (
true);
102 m_search_line_edit->setMaxCount (m_mru_length);
103 m_search_line_edit->completer ()->setCaseSensitivity (Qt::CaseSensitive);
104 m_search_label->setBuddy (m_search_line_edit);
106 m_replace_label =
new QLabel (tr (
"Re&place with:"));
107 m_replace_line_edit =
new QComboBox (
this);
108 m_replace_line_edit->setToolTip (tr (
"Enter new text replacing search hits"));
109 m_replace_line_edit->setEditable (
true);
110 m_replace_line_edit->setMaxCount (m_mru_length);
111 m_replace_line_edit->completer ()->setCaseSensitivity (Qt::CaseSensitive);
112 m_replace_label->setBuddy (m_replace_line_edit);
114 int width = QFontMetrics (m_search_line_edit->font ()).averageCharWidth();
115 m_search_line_edit->setFixedWidth (20*width);
116 m_replace_line_edit->setFixedWidth (20*width);
118 m_case_check_box =
new QCheckBox (tr (
"Match &case"));
119 m_from_start_check_box =
new QCheckBox (tr (
"Search from &start"));
120 m_wrap_check_box =
new QCheckBox (tr (
"&Wrap while searching"));
121 m_wrap_check_box->setChecked (
true);
122 m_find_next_button =
new QPushButton (tr (
"&Find Next"));
123 m_find_prev_button =
new QPushButton (tr (
"Find &Previous"));
124 m_replace_button =
new QPushButton (tr (
"&Replace"));
125 m_replace_all_button =
new QPushButton (tr (
"Replace &All"));
128 m_more_button->setCheckable (
true);
129 m_more_button->setAutoDefault (
false);
131 m_button_box =
new QDialogButtonBox (Qt::Vertical);
132 m_button_box->addButton (m_find_next_button, QDialogButtonBox::ActionRole);
133 m_button_box->addButton (m_find_prev_button, QDialogButtonBox::ActionRole);
134 m_button_box->addButton (m_replace_button, QDialogButtonBox::ActionRole);
135 m_button_box->addButton (m_replace_all_button, QDialogButtonBox::ActionRole);
136 m_button_box->addButton (m_more_button, QDialogButtonBox::ActionRole);
137 m_button_box->addButton (QDialogButtonBox::Close);
139 m_extension =
new QWidget (
this);
140 m_whole_words_check_box =
new QCheckBox (tr (
"&Whole words"));
141 m_regex_check_box =
new QCheckBox (tr (
"Regular E&xpressions"));
142 m_backward_check_box =
new QCheckBox (tr (
"Search &backward"));
143 m_search_selection_check_box =
new QCheckBox (tr (
"Search se&lection"));
144 m_search_selection_check_box->setCheckable (
true);
146 connect (m_find_next_button, &QPushButton::clicked,
148 connect (m_find_prev_button, &QPushButton::clicked,
150 connect (m_more_button, &QPushButton::toggled,
151 m_extension, &QWidget::setVisible);
152 connect (m_replace_button, &QPushButton::clicked,
154 connect (m_replace_all_button, &QPushButton::clicked,
156 connect (m_backward_check_box, &QCheckBox::stateChanged,
158 connect (m_button_box, &QDialogButtonBox::rejected,
159 this, &find_dialog::close);
161 connect (m_search_selection_check_box, &QCheckBox::stateChanged,
164 QVBoxLayout *extension_layout =
new QVBoxLayout ();
165 extension_layout->setMargin (0);
166 extension_layout->addWidget (m_whole_words_check_box);
167 extension_layout->addWidget (m_backward_check_box);
168 extension_layout->addWidget (m_search_selection_check_box);
169 m_extension->setLayout (extension_layout);
171 QGridLayout *top_left_layout =
new QGridLayout;
172 top_left_layout->addWidget (m_search_label, 1, 1);
173 top_left_layout->addWidget (m_search_line_edit, 1, 2);
174 top_left_layout->addWidget (m_replace_label, 2, 1);
175 top_left_layout->addWidget (m_replace_line_edit, 2, 2);
177 QVBoxLayout *left_layout =
new QVBoxLayout;
178 left_layout->addLayout (top_left_layout);
179 left_layout->insertStretch (1, 5);
180 left_layout->addWidget (m_case_check_box);
181 left_layout->addWidget (m_from_start_check_box);
182 left_layout->addWidget (m_wrap_check_box);
183 left_layout->addWidget (m_regex_check_box);
185 QGridLayout *main_layout =
new QGridLayout;
186 main_layout->setSizeConstraint (QLayout::SetFixedSize);
187 main_layout->addLayout (left_layout, 0, 0);
188 main_layout->addWidget (m_button_box, 0, 1);
189 main_layout->addWidget (m_extension, 1, 0);
190 setLayout (main_layout);
192 m_extension->hide ();
193 m_find_next_button->setDefault (
true);
194 m_find_result_available =
false;
196 m_rep_active =
false;
202 setWindowModality (Qt::NonModal);
204 setAttribute(Qt::WA_ShowWithoutActivating);
205 setAttribute(Qt::WA_DeleteOnClose);
214 connect (
m_edit_area, SIGNAL (copyAvailable (
bool)),
216 Qt::UniqueConnection);
225 QPoint dlg_pos = pos ();
227 #if defined (Q_OS_WIN32)
228 int y = dlg_pos.y ();
230 int y = dlg_pos.y () - geometry ().height () + frameGeometry ().height ();
296 int xp = ed_bottom_right.x () - sizeHint ().width ();
297 int yp = ed_bottom_right.y () - sizeHint ().height ();
298 QRect default_geometry (xp, yp, sizeHint ().width (), sizeHint ().height ());
303 QSize (sizeHint ().width (), sizeHint ().height ()));
349 while ((index = mru->findText (QString ())) >= 0)
350 mru->removeItem (index);
353 QString text = mru->currentText ();
359 while ((index = mru->findText (text)) >= 0)
360 mru->removeItem (index);
367 mru->insertItem (0, text);
368 mru->setCurrentIndex (0);
391 int lbeg, lend, cbeg, cend;
392 m_edit_area->getSelection (&lbeg, &cbeg, &lend, &cend);
424 int line = -1, col = -1;
427 bool do_forward = forward;
497 else if (! do_forward)
504 int currpos =
m_edit_area->positionFromLineIndex (line, col);
508 m_edit_area->lineIndexFromPosition (currpos, &line, &col);
523 #if defined (HAVE_QSCI_VERSION_2_6_0)
537 int pos =
m_edit_area->positionFromLineIndex (line, col);
624 QMessageBox msg_box (QMessageBox::Information, tr (
"Replace Result"),
625 tr (
"%1 items replaced").arg (
m_rep_all-1),
626 QMessageBox::Ok,
this);
639 QMessageBox msg_box (QMessageBox::Information, tr (
"Find Result"),
640 tr (
"No more matches found"), QMessageBox::Ok,
this);
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
void init_search_text(void)
Init the search text with the selected text in the editor tab.
bool m_find_result_available
QCheckBox * m_wrap_check_box
QComboBox * m_replace_line_edit
void restore_settings(QPoint def_pos)
Restore position and the search options from the given settings where def_pos is the default position...
QCheckBox * m_whole_words_check_box
QCheckBox * m_from_start_check_box
QCheckBox * m_case_check_box
base_qobject & m_octave_qobj
void handle_selection_changed(bool has_selected)
QPushButton * m_find_next_button
void set_visible(bool visible)
Set dialog visible or not and storing the new visibility state.
QCheckBox * m_search_selection_check_box
QComboBox * m_search_line_edit
void closeEvent(QCloseEvent *e)
Reimplemented close event.
void reject()
Reimplemented slot: close instead of hiding.
void update_edit_area(octave_qscintilla *)
Slot for updating the edit area when the active tab has changed.
void save_settings()
Save position and the search options in the given settings.
void handle_search_text_changed(void)
octave_qscintilla * m_edit_area
void mru_update(QComboBox *mru)
Update mru lists with new entry.
QCheckBox * m_regex_check_box
void handle_replace_text_changed(void)
void handle_backward_search_changed(int)
void find(bool forward=true)
void no_matches_message(void)
QCheckBox * m_backward_check_box
void handle_sel_search_changed(int)
QVariant value(const gui_pref &pref) const
void show_selection_markers(int l1, int c1, int l2, int c2)
virtual void setCursorPosition(int line, int col)
void clear_selection_markers(void)
gui_settings * get_settings(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
const gui_pref ed_fdlg_opts("editor/fdgl_opts", QVariant(FIND_DLG_WRAP))
const gui_pref ed_fdlg_pos("editor/fdgl_pos", QVariant(QPoint(0, 0)))
const gui_pref ed_fdlg_search("editor/fdgl_search", QVariant())
const gui_pref ed_fdlg_replace("editor/fdgl_replace", QVariant())
OCTGUI_API void adjust_to_screen(QRect &actual_geometry, const QRect &default_geometry)