Mercurial > octave
comparison libgui/src/find-files-dialog.cc @ 31648:29d734430e5f stable
maint: Re-indent code after switch to using namespace macros.
* BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h,
ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h,
CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h,
ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h,
Figure.cc, Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc,
GLCanvas.h, GenericEventNotify.h, KeyMap.cc, KeyMap.h,
ListBoxControl.cc, ListBoxControl.h, Logger.cc, Logger.h, Menu.cc,
Menu.h, MenuContainer.h, Object.cc, Object.h, ObjectProxy.cc,
ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc,
PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h,
PushTool.cc, PushTool.h, QtHandlesUtils.cc, QtHandlesUtils.h,
RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc,
SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h,
TextEdit.cc, TextEdit.h, ToggleButtonControl.cc,
ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc,
ToolBar.h, ToolBarButton.cc, ToolBarButton.h, annotation-dialog.cc,
annotation-dialog.h, gl-select.cc, gl-select.h, qopengl-functions.h,
qt-graphics-toolkit.cc, qt-graphics-toolkit.h, module.mk, QTerminal.h,
color-picker.cc, color-picker.h, command-widget.cc, command-widget.h,
community-news.cc, community-news.h, dialog.cc, dialog.h,
documentation-bookmarks.cc, documentation-bookmarks.h,
documentation-dock-widget.cc, documentation-dock-widget.h,
documentation.cc, documentation.h, dw-main-window.cc,
dw-main-window.h, external-editor-interface.cc,
external-editor-interface.h, files-dock-widget.cc,
files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h,
find-files-model.cc, find-files-model.h, graphics-init.cc,
graphics-init.h, gui-settings.cc, gui-settings.h, gui-utils.cc,
gui-utils.h, history-dock-widget.cc, history-dock-widget.h,
interpreter-qobject.cc, interpreter-qobject.h, led-indicator.cc,
led-indicator.h, file-editor-interface.h, file-editor-tab.cc,
file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc,
find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc,
octave-qscintilla.h, octave-txt-lexer.cc, octave-txt-lexer.h,
main-window.cc, main-window.h, news-reader.cc, news-reader.h,
octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc,
octave-qobject.h, qt-application.cc, qt-application.h,
qt-interpreter-events.cc, qt-interpreter-events.h, qt-utils.h,
release-notes.cc, release-notes.h, resource-manager.cc,
resource-manager.h, set-path-dialog.cc, set-path-dialog.h,
set-path-model.cc, set-path-model.h, settings-dialog.cc,
settings-dialog.h, shortcut-manager.cc, shortcut-manager.h,
tab-bar.cc, tab-bar.h, terminal-dock-widget.cc,
terminal-dock-widget.h, variable-editor-model.cc,
variable-editor-model.h, variable-editor.cc, variable-editor.h,
welcome-wizard.cc, welcome-wizard.h, workspace-model.cc,
workspace-model.h, workspace-view.cc, workspace-view.h:
Re-indent code after switch to using namespace macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 14:53:00 -0500 |
parents | c6d54dd31a7e |
children | deb553ac2c54 597f3ee61a48 |
comparison
equal
deleted
inserted
replaced
31646:c6d54dd31a7e | 31648:29d734430e5f |
---|---|
51 #include "gui-preferences-ff.h" | 51 #include "gui-preferences-ff.h" |
52 #include "octave-qobject.h" | 52 #include "octave-qobject.h" |
53 | 53 |
54 OCTAVE_BEGIN_NAMESPACE(octave) | 54 OCTAVE_BEGIN_NAMESPACE(octave) |
55 | 55 |
56 find_files_dialog::find_files_dialog (QWidget *p, base_qobject& oct_qobj) | 56 find_files_dialog::find_files_dialog (QWidget *p, base_qobject& oct_qobj) |
57 : QDialog (p), m_octave_qobj (oct_qobj) | 57 : QDialog (p), m_octave_qobj (oct_qobj) |
58 { | 58 { |
59 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | 59 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); |
60 | 60 |
61 setWindowTitle (tr ("Find Files")); | 61 setWindowTitle (tr ("Find Files")); |
62 setWindowIcon (rmgr.icon ("edit-find")); | 62 setWindowIcon (rmgr.icon ("edit-find")); |
63 | 63 |
64 m_dir_iterator = nullptr; | 64 m_dir_iterator = nullptr; |
65 | 65 |
66 m_timer = new QTimer (this); | 66 m_timer = new QTimer (this); |
67 connect (m_timer, &QTimer::timeout, | 67 connect (m_timer, &QTimer::timeout, |
68 this, &find_files_dialog::look_for_files); | 68 this, &find_files_dialog::look_for_files); |
69 | 69 |
70 gui_settings *settings = rmgr.get_settings (); | 70 gui_settings *settings = rmgr.get_settings (); |
71 | 71 |
72 QLabel *file_name_label = new QLabel (tr ("Named:")); | 72 QLabel *file_name_label = new QLabel (tr ("Named:")); |
73 m_file_name_edit = new QLineEdit; | 73 m_file_name_edit = new QLineEdit; |
74 m_file_name_edit->setToolTip (tr ("Enter the filename search expression")); | 74 m_file_name_edit->setToolTip (tr ("Enter the filename search expression")); |
75 | 75 |
76 m_file_name_edit->setText (settings->value (ff_file_name).toString ()); | 76 m_file_name_edit->setText (settings->value (ff_file_name).toString ()); |
77 file_name_label->setBuddy (m_file_name_edit); | 77 file_name_label->setBuddy (m_file_name_edit); |
78 | 78 |
79 QLabel *start_dir_label = new QLabel (tr ("Start in:")); | 79 QLabel *start_dir_label = new QLabel (tr ("Start in:")); |
80 | 80 |
81 m_start_dir_edit = new QLineEdit; | 81 m_start_dir_edit = new QLineEdit; |
82 m_start_dir_edit->setText (settings->value (ff_start_dir.key, | 82 m_start_dir_edit->setText (settings->value (ff_start_dir.key, |
83 QDir::currentPath ()).toString ()); | 83 QDir::currentPath ()).toString ()); |
84 m_start_dir_edit->setToolTip (tr ("Enter the start directory")); | 84 m_start_dir_edit->setToolTip (tr ("Enter the start directory")); |
85 start_dir_label->setBuddy (m_start_dir_edit); | 85 start_dir_label->setBuddy (m_start_dir_edit); |
86 | 86 |
87 m_browse_button = new QPushButton (tr ("Browse...")); | 87 m_browse_button = new QPushButton (tr ("Browse...")); |
88 m_browse_button->setToolTip (tr ("Browse for start directory")); | 88 m_browse_button->setToolTip (tr ("Browse for start directory")); |
89 connect (m_browse_button, &QPushButton::clicked, | 89 connect (m_browse_button, &QPushButton::clicked, |
90 this, &find_files_dialog::browse_folders); | 90 this, &find_files_dialog::browse_folders); |
91 | 91 |
92 m_recurse_dirs_check = new QCheckBox (tr ("Search subdirectories")); | 92 m_recurse_dirs_check = new QCheckBox (tr ("Search subdirectories")); |
93 m_recurse_dirs_check->setChecked (settings->value (ff_recurse_dirs).toBool ()); | 93 m_recurse_dirs_check->setChecked (settings->value (ff_recurse_dirs).toBool ()); |
94 m_recurse_dirs_check->setToolTip (tr ("Search recursively through directories for matching files")); | 94 m_recurse_dirs_check->setToolTip (tr ("Search recursively through directories for matching files")); |
95 | 95 |
96 m_include_dirs_check = new QCheckBox (tr ("Include directory names")); | 96 m_include_dirs_check = new QCheckBox (tr ("Include directory names")); |
97 m_include_dirs_check->setChecked (settings->value (ff_include_dirs).toBool ()); | 97 m_include_dirs_check->setChecked (settings->value (ff_include_dirs).toBool ()); |
98 m_include_dirs_check->setToolTip (tr ("Include matching directories in search results")); | 98 m_include_dirs_check->setToolTip (tr ("Include matching directories in search results")); |
99 | 99 |
100 m_name_case_check = new QCheckBox (tr ("Name case insensitive")); | 100 m_name_case_check = new QCheckBox (tr ("Name case insensitive")); |
101 m_name_case_check->setChecked (settings->value (ff_name_case).toBool ()); | 101 m_name_case_check->setChecked (settings->value (ff_name_case).toBool ()); |
102 m_name_case_check->setToolTip (tr ("Set matching name is case insensitive")); | 102 m_name_case_check->setToolTip (tr ("Set matching name is case insensitive")); |
103 | 103 |
104 m_contains_text_check = new QCheckBox (tr ("Contains text:")); | 104 m_contains_text_check = new QCheckBox (tr ("Contains text:")); |
105 m_contains_text_check->setToolTip (tr ("Enter the file content search expression")); | 105 m_contains_text_check->setToolTip (tr ("Enter the file content search expression")); |
106 m_contains_text_check->setChecked (settings->value (ff_check_text).toBool ()); | 106 m_contains_text_check->setChecked (settings->value (ff_check_text).toBool ()); |
107 | 107 |
108 m_contains_text_edit = new QLineEdit (); | 108 m_contains_text_edit = new QLineEdit (); |
109 m_contains_text_edit->setToolTip (tr ("Text to match")); | 109 m_contains_text_edit->setToolTip (tr ("Text to match")); |
110 m_contains_text_edit->setText (settings->value (ff_contains_text).toString ()); | 110 m_contains_text_edit->setText (settings->value (ff_contains_text).toString ()); |
111 | 111 |
112 m_content_case_check = new QCheckBox (tr ("Text case insensitive")); | 112 m_content_case_check = new QCheckBox (tr ("Text case insensitive")); |
113 m_content_case_check->setChecked (settings->value (ff_content_case).toBool ()); | 113 m_content_case_check->setChecked (settings->value (ff_content_case).toBool ()); |
114 m_content_case_check->setToolTip (tr ("Set text content is case insensitive")); | 114 m_content_case_check->setToolTip (tr ("Set text content is case insensitive")); |
115 | 115 |
116 find_files_model *model = new find_files_model (this); | 116 find_files_model *model = new find_files_model (this); |
117 | 117 |
118 m_file_list = new QTableView; | 118 m_file_list = new QTableView; |
119 m_file_list->setWordWrap (false); | 119 m_file_list->setWordWrap (false); |
120 m_file_list->setModel (model); | 120 m_file_list->setModel (model); |
121 m_file_list->setShowGrid (false); | 121 m_file_list->setShowGrid (false); |
122 m_file_list->setSelectionBehavior (QAbstractItemView::SelectRows); | 122 m_file_list->setSelectionBehavior (QAbstractItemView::SelectRows); |
123 m_file_list->setSelectionMode (QAbstractItemView::SingleSelection); | 123 m_file_list->setSelectionMode (QAbstractItemView::SingleSelection); |
124 m_file_list->setAlternatingRowColors (true); | 124 m_file_list->setAlternatingRowColors (true); |
125 m_file_list->setToolTip (tr ("Search results")); | 125 m_file_list->setToolTip (tr ("Search results")); |
126 m_file_list->setSortingEnabled (true); | 126 m_file_list->setSortingEnabled (true); |
127 m_file_list->horizontalHeader ()->restoreState (settings->value (ff_column_state.key).toByteArray ()); | 127 m_file_list->horizontalHeader ()->restoreState (settings->value (ff_column_state.key).toByteArray ()); |
128 m_file_list->horizontalHeader ()->setSortIndicatorShown (true); | 128 m_file_list->horizontalHeader ()->setSortIndicatorShown (true); |
129 m_file_list->horizontalHeader ()->setSectionsClickable (true); | 129 m_file_list->horizontalHeader ()->setSectionsClickable (true); |
130 m_file_list->horizontalHeader ()->setStretchLastSection (true); | 130 m_file_list->horizontalHeader ()->setStretchLastSection (true); |
131 m_file_list->sortByColumn (settings->value (ff_sort_files_by_column).toInt (), | 131 m_file_list->sortByColumn (settings->value (ff_sort_files_by_column).toInt (), |
132 static_cast<Qt::SortOrder> | 132 static_cast<Qt::SortOrder> |
133 (settings->value (ff_sort_files_by_order).toUInt ())); | 133 (settings->value (ff_sort_files_by_order).toUInt ())); |
134 // FIXME: use value<Qt::SortOrder> instead of static cast after | 134 // FIXME: use value<Qt::SortOrder> instead of static cast after |
135 // dropping support of Qt 5.4 | 135 // dropping support of Qt 5.4 |
136 | 136 |
137 connect (m_file_list, &QTableView::doubleClicked, | 137 connect (m_file_list, &QTableView::doubleClicked, |
138 this, &find_files_dialog::item_double_clicked); | 138 this, &find_files_dialog::item_double_clicked); |
139 | 139 |
140 m_status_bar = new QStatusBar; | 140 m_status_bar = new QStatusBar; |
141 m_status_bar->showMessage (tr ("Idle.")); | 141 m_status_bar->showMessage (tr ("Idle.")); |
142 | 142 |
143 m_find_button = new QPushButton (tr ("Find")); | 143 m_find_button = new QPushButton (tr ("Find")); |
144 m_find_button->setToolTip (tr ("Start search for matching files")); | 144 m_find_button->setToolTip (tr ("Start search for matching files")); |
145 connect (m_find_button, &QPushButton::clicked, | 145 connect (m_find_button, &QPushButton::clicked, |
146 this, &find_files_dialog::start_find); | 146 this, &find_files_dialog::start_find); |
147 | 147 |
148 m_stop_button = new QPushButton (tr ("Stop")); | 148 m_stop_button = new QPushButton (tr ("Stop")); |
149 m_stop_button->setToolTip (tr ("Stop searching")); | 149 m_stop_button->setToolTip (tr ("Stop searching")); |
150 m_stop_button->setEnabled (false); | 150 m_stop_button->setEnabled (false); |
151 connect (m_stop_button, &QPushButton::clicked, | 151 connect (m_stop_button, &QPushButton::clicked, |
152 this, &find_files_dialog::stop_find); | 152 this, &find_files_dialog::stop_find); |
153 | 153 |
154 // layout everything | 154 // layout everything |
155 QDialogButtonBox *button_box = new QDialogButtonBox (Qt::Vertical); | 155 QDialogButtonBox *button_box = new QDialogButtonBox (Qt::Vertical); |
156 button_box->addButton (m_find_button, QDialogButtonBox::ActionRole); | 156 button_box->addButton (m_find_button, QDialogButtonBox::ActionRole); |
157 button_box->addButton (m_stop_button, QDialogButtonBox::ActionRole); | 157 button_box->addButton (m_stop_button, QDialogButtonBox::ActionRole); |
158 | 158 |
159 // add dialog close button | 159 // add dialog close button |
160 m_close_button = button_box->addButton (QDialogButtonBox::Close); | 160 m_close_button = button_box->addButton (QDialogButtonBox::Close); |
161 connect (button_box, &QDialogButtonBox::rejected, | 161 connect (button_box, &QDialogButtonBox::rejected, |
162 this, &find_files_dialog::close); | 162 this, &find_files_dialog::close); |
163 | 163 |
164 // name options | 164 // name options |
165 QGroupBox *name_group = new QGroupBox (tr ("Filename/location")); | 165 QGroupBox *name_group = new QGroupBox (tr ("Filename/location")); |
166 QGridLayout *name_layout = new QGridLayout; | 166 QGridLayout *name_layout = new QGridLayout; |
167 name_group->setLayout (name_layout); | 167 name_group->setLayout (name_layout); |
168 | 168 |
169 name_layout->addWidget (file_name_label, 1, 1, 1, 1); | 169 name_layout->addWidget (file_name_label, 1, 1, 1, 1); |
170 name_layout->addWidget (m_file_name_edit, 1, 2, 1, -1); | 170 name_layout->addWidget (m_file_name_edit, 1, 2, 1, -1); |
171 | 171 |
172 name_layout->addWidget (start_dir_label, 2, 1); | 172 name_layout->addWidget (start_dir_label, 2, 1); |
173 name_layout->addWidget (m_start_dir_edit, 2, 2, 1, 3); | 173 name_layout->addWidget (m_start_dir_edit, 2, 2, 1, 3); |
174 name_layout->addWidget (m_browse_button, 2, 5); | 174 name_layout->addWidget (m_browse_button, 2, 5); |
175 name_layout->setColumnStretch (2, 1); | 175 name_layout->setColumnStretch (2, 1); |
176 | 176 |
177 name_layout->addWidget (m_recurse_dirs_check, 3, 1); | 177 name_layout->addWidget (m_recurse_dirs_check, 3, 1); |
178 name_layout->addWidget (m_include_dirs_check, 3, 2); | 178 name_layout->addWidget (m_include_dirs_check, 3, 2); |
179 name_layout->addWidget (m_name_case_check, 3, 3); | 179 name_layout->addWidget (m_name_case_check, 3, 3); |
180 | 180 |
181 // content options | 181 // content options |
182 QGroupBox *content_group = new QGroupBox (tr ("File contents")); | 182 QGroupBox *content_group = new QGroupBox (tr ("File contents")); |
183 QGridLayout *content_layout = new QGridLayout; | 183 QGridLayout *content_layout = new QGridLayout; |
184 content_group->setLayout (content_layout); | 184 content_group->setLayout (content_layout); |
185 content_layout->addWidget (m_contains_text_check, 4, 1); | 185 content_layout->addWidget (m_contains_text_check, 4, 1); |
186 content_layout->addWidget (m_contains_text_edit, 4, 2, 1, 3); | 186 content_layout->addWidget (m_contains_text_edit, 4, 2, 1, 3); |
187 content_layout->setColumnStretch (2, 1); | 187 content_layout->setColumnStretch (2, 1); |
188 content_layout->addWidget (m_content_case_check, 5, 1); | 188 content_layout->addWidget (m_content_case_check, 5, 1); |
189 | 189 |
190 QGridLayout *main_layout = new QGridLayout; | 190 QGridLayout *main_layout = new QGridLayout; |
191 main_layout->setSizeConstraint (QLayout::SetFixedSize); | 191 main_layout->setSizeConstraint (QLayout::SetFixedSize); |
192 main_layout->addWidget (name_group, 0, 0); | 192 main_layout->addWidget (name_group, 0, 0); |
193 main_layout->addWidget (content_group, 1, 0); | 193 main_layout->addWidget (content_group, 1, 0); |
194 main_layout->addWidget (button_box, 0, 1, 3, 1); | 194 main_layout->addWidget (button_box, 0, 1, 3, 1); |
195 main_layout->addWidget (m_file_list, 2, 0); | 195 main_layout->addWidget (m_file_list, 2, 0); |
196 main_layout->setRowStretch (2, 1); | 196 main_layout->setRowStretch (2, 1); |
197 main_layout->addWidget (m_status_bar, 3, 0, 1, -1); | 197 main_layout->addWidget (m_status_bar, 3, 0, 1, -1); |
198 | 198 |
199 setLayout (main_layout); | 199 setLayout (main_layout); |
200 | 200 |
201 connect (this, &find_files_dialog::finished, | 201 connect (this, &find_files_dialog::finished, |
202 this, &find_files_dialog::handle_done); | 202 this, &find_files_dialog::handle_done); |
203 } | 203 } |
204 | 204 |
205 find_files_dialog::~find_files_dialog (void) | 205 find_files_dialog::~find_files_dialog (void) |
206 { | 206 { |
207 delete m_dir_iterator; | |
208 } | |
209 | |
210 void find_files_dialog::save_settings (void) | |
211 { | |
212 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | |
213 gui_settings *settings = rmgr.get_settings (); | |
214 | |
215 if (! settings) | |
216 return; | |
217 | |
218 int sort_column = m_file_list->horizontalHeader ()->sortIndicatorSection (); | |
219 Qt::SortOrder sort_order | |
220 = m_file_list->horizontalHeader ()->sortIndicatorOrder (); | |
221 settings->setValue (ff_sort_files_by_column.key, sort_column); | |
222 settings->setValue (ff_sort_files_by_order.key, sort_order); | |
223 settings->setValue (ff_column_state.key, m_file_list->horizontalHeader ()->saveState ()); | |
224 | |
225 settings->setValue (ff_file_name.key, m_file_name_edit->text ()); | |
226 | |
227 settings->setValue (ff_start_dir.key, m_start_dir_edit->text ()); | |
228 | |
229 settings->setValue (ff_recurse_dirs.key, m_recurse_dirs_check->text ()); | |
230 settings->setValue (ff_include_dirs.key, m_include_dirs_check->text ()); | |
231 settings->setValue (ff_name_case.key, m_name_case_check->text ()); | |
232 | |
233 settings->setValue (ff_contains_text.key, m_contains_text_edit->text ()); | |
234 settings->setValue (ff_check_text.key, m_contains_text_check->isChecked ()); | |
235 settings->setValue (ff_content_case.key, m_content_case_check->isChecked ()); | |
236 | |
237 settings->sync (); | |
238 } | |
239 | |
240 void find_files_dialog::set_search_dir (const QString& dir) | |
241 { | |
242 stop_find (); | |
243 m_start_dir_edit->setText (dir); | |
244 } | |
245 | |
246 void find_files_dialog::start_find (void) | |
247 { | |
248 stop_find (); | |
249 | |
250 find_files_model *m = static_cast<find_files_model *> (m_file_list->model ()); | |
251 m->clear (); | |
252 | |
253 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags; | |
254 if (m_recurse_dirs_check->isChecked ()) | |
255 flags |= QDirIterator::Subdirectories; | |
256 | |
257 QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files; | |
258 if (! m_name_case_check->isChecked ()) | |
259 filters |= QDir::CaseSensitive; | |
260 | |
261 QStringList nameFilters; | |
262 nameFilters.append (m_file_name_edit->text ()); | |
263 | |
264 if (m_dir_iterator) | |
207 delete m_dir_iterator; | 265 delete m_dir_iterator; |
208 } | 266 |
209 | 267 m_dir_iterator = new QDirIterator (m_start_dir_edit->text (), nameFilters, |
210 void find_files_dialog::save_settings (void) | 268 filters, flags); |
211 { | 269 |
212 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | 270 // enable/disable widgets |
213 gui_settings *settings = rmgr.get_settings (); | 271 m_find_button->setEnabled (false); |
214 | 272 m_stop_button->setEnabled (true); |
215 if (! settings) | 273 m_close_button->setEnabled (false); |
216 return; | 274 m_browse_button->setEnabled (false); |
217 | 275 m_start_dir_edit->setEnabled (false); |
218 int sort_column = m_file_list->horizontalHeader ()->sortIndicatorSection (); | 276 m_file_name_edit->setEnabled (false); |
219 Qt::SortOrder sort_order | 277 m_recurse_dirs_check->setEnabled (false); |
220 = m_file_list->horizontalHeader ()->sortIndicatorOrder (); | 278 m_include_dirs_check->setEnabled (false); |
221 settings->setValue (ff_sort_files_by_column.key, sort_column); | 279 m_name_case_check->setEnabled (false); |
222 settings->setValue (ff_sort_files_by_order.key, sort_order); | 280 m_contains_text_check->setEnabled (false); |
223 settings->setValue (ff_column_state.key, m_file_list->horizontalHeader ()->saveState ()); | 281 m_content_case_check->setEnabled (false); |
224 | 282 m_contains_text_edit->setEnabled (false); |
225 settings->setValue (ff_file_name.key, m_file_name_edit->text ()); | 283 |
226 | 284 m_status_bar->showMessage (tr ("Searching...")); |
227 settings->setValue (ff_start_dir.key, m_start_dir_edit->text ()); | 285 m_timer->start (0); |
228 | 286 } |
229 settings->setValue (ff_recurse_dirs.key, m_recurse_dirs_check->text ()); | 287 |
230 settings->setValue (ff_include_dirs.key, m_include_dirs_check->text ()); | 288 void find_files_dialog::stop_find (void) |
231 settings->setValue (ff_name_case.key, m_name_case_check->text ()); | 289 { |
232 | 290 m_timer->stop (); |
233 settings->setValue (ff_contains_text.key, m_contains_text_edit->text ()); | 291 |
234 settings->setValue (ff_check_text.key, m_contains_text_check->isChecked ()); | 292 m_find_button->setEnabled (true); |
235 settings->setValue (ff_content_case.key, m_content_case_check->isChecked ()); | 293 m_stop_button->setEnabled (false); |
236 | 294 m_close_button->setEnabled (true); |
237 settings->sync (); | 295 m_browse_button->setEnabled (true); |
238 } | 296 m_start_dir_edit->setEnabled (true); |
239 | 297 m_file_name_edit->setEnabled (true); |
240 void find_files_dialog::set_search_dir (const QString& dir) | 298 m_recurse_dirs_check->setEnabled (true); |
241 { | 299 m_include_dirs_check->setEnabled (true); |
242 stop_find (); | 300 m_name_case_check->setEnabled (true); |
301 m_contains_text_check->setEnabled (true); | |
302 m_content_case_check->setEnabled (true); | |
303 m_contains_text_edit->setEnabled (true); | |
304 | |
305 find_files_model *m = static_cast<find_files_model *> (m_file_list->model ()); | |
306 QString res_str = QString (tr ("%1 match (es)")).arg (m->rowCount ()); | |
307 | |
308 m_status_bar->showMessage (res_str); | |
309 } | |
310 | |
311 void find_files_dialog::browse_folders (void) | |
312 { | |
313 int opts = 0; // No options by default. | |
314 // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. | |
315 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | |
316 gui_settings *settings = rmgr.get_settings (); | |
317 if (! settings->value (global_use_native_dialogs).toBool ()) | |
318 opts = QFileDialog::DontUseNativeDialog; | |
319 | |
320 QString dir = | |
321 QFileDialog::getExistingDirectory (this, tr ("Set search directory"), | |
322 m_start_dir_edit->text (), | |
323 QFileDialog::Option (opts)); | |
324 | |
325 if (! dir.isEmpty ()) | |
243 m_start_dir_edit->setText (dir); | 326 m_start_dir_edit->setText (dir); |
244 } | 327 } |
245 | 328 |
246 void find_files_dialog::start_find (void) | 329 void find_files_dialog::item_double_clicked (const QModelIndex& idx) |
247 { | 330 { |
248 stop_find (); | 331 find_files_model *m = static_cast<find_files_model *> (m_file_list->model ()); |
249 | 332 |
250 find_files_model *m = static_cast<find_files_model *> (m_file_list->model ()); | 333 QFileInfo info = m->fileInfo (idx); |
251 m->clear (); | 334 |
252 | 335 if (idx.column () == 1) |
253 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags; | 336 { |
254 if (m_recurse_dirs_check->isChecked ()) | 337 // clicked in directory part |
255 flags |= QDirIterator::Subdirectories; | 338 emit dir_selected (info.absolutePath ()); |
256 | 339 } |
257 QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files; | 340 else |
258 if (! m_name_case_check->isChecked ()) | 341 { |
259 filters |= QDir::CaseSensitive; | 342 // clicked in filename part |
260 | 343 if (info.isDir ()) |
261 QStringList nameFilters; | 344 emit dir_selected (info.absoluteFilePath ()); |
262 nameFilters.append (m_file_name_edit->text ()); | 345 else |
263 | 346 emit file_selected (info.absoluteFilePath ()); |
264 if (m_dir_iterator) | 347 } |
265 delete m_dir_iterator; | 348 } |
266 | 349 |
267 m_dir_iterator = new QDirIterator (m_start_dir_edit->text (), nameFilters, | 350 void find_files_dialog::look_for_files (void) |
268 filters, flags); | 351 { |
269 | 352 if (m_dir_iterator && m_dir_iterator->hasNext ()) |
270 // enable/disable widgets | 353 { |
271 m_find_button->setEnabled (false); | 354 QFileInfo info (m_dir_iterator->next ()); |
272 m_stop_button->setEnabled (true); | 355 |
273 m_close_button->setEnabled (false); | 356 find_files_model *m |
274 m_browse_button->setEnabled (false); | 357 = static_cast<find_files_model *> (m_file_list->model ()); |
275 m_start_dir_edit->setEnabled (false); | 358 |
276 m_file_name_edit->setEnabled (false); | 359 if (is_match (info)) |
277 m_recurse_dirs_check->setEnabled (false); | 360 m->addFile (info); |
278 m_include_dirs_check->setEnabled (false); | 361 } |
279 m_name_case_check->setEnabled (false); | 362 else |
280 m_contains_text_check->setEnabled (false); | 363 { |
281 m_content_case_check->setEnabled (false); | 364 stop_find (); |
282 m_contains_text_edit->setEnabled (false); | 365 } |
283 | 366 } |
284 m_status_bar->showMessage (tr ("Searching...")); | 367 |
285 m_timer->start (0); | 368 void find_files_dialog::handle_done (int) |
286 } | 369 { |
287 | 370 // make sure we stopped processing |
288 void find_files_dialog::stop_find (void) | 371 stop_find (); |
289 { | 372 } |
290 m_timer->stop (); | 373 |
291 | 374 bool find_files_dialog::is_match (const QFileInfo& info) |
292 m_find_button->setEnabled (true); | 375 { |
293 m_stop_button->setEnabled (false); | 376 bool match = true; |
294 m_close_button->setEnabled (true); | 377 if (info.isDir ()) |
295 m_browse_button->setEnabled (true); | 378 { |
296 m_start_dir_edit->setEnabled (true); | 379 if (! m_include_dirs_check->isChecked ()) match = false; |
297 m_file_name_edit->setEnabled (true); | 380 if (m_contains_text_check->isChecked ()) match = false; |
298 m_recurse_dirs_check->setEnabled (true); | 381 } |
299 m_include_dirs_check->setEnabled (true); | 382 else |
300 m_name_case_check->setEnabled (true); | 383 { |
301 m_contains_text_check->setEnabled (true); | 384 // a file |
302 m_content_case_check->setEnabled (true); | 385 if (m_contains_text_check->isChecked ()) |
303 m_contains_text_edit->setEnabled (true); | 386 { |
304 | 387 match = false; |
305 find_files_model *m = static_cast<find_files_model *> (m_file_list->model ()); | 388 |
306 QString res_str = QString (tr ("%1 match (es)")).arg (m->rowCount ()); | 389 QFile file (info.absoluteFilePath ()); |
307 | 390 if (file.open (QIODevice::ReadOnly)) |
308 m_status_bar->showMessage (res_str); | 391 { |
309 } | 392 QTextStream stream (&file); |
310 | 393 |
311 void find_files_dialog::browse_folders (void) | 394 QString line; |
312 { | 395 QString match_str = m_contains_text_edit->text (); |
313 int opts = 0; // No options by default. | 396 |
314 // FIXME: Remove, if for all common KDE versions (bug #54607) is resolved. | 397 Qt::CaseSensitivity cs = m_content_case_check->isChecked () |
315 resource_manager& rmgr = m_octave_qobj.get_resource_manager (); | 398 ? Qt::CaseInsensitive |
316 gui_settings *settings = rmgr.get_settings (); | 399 : Qt::CaseSensitive; |
317 if (! settings->value (global_use_native_dialogs).toBool ()) | 400 |
318 opts = QFileDialog::DontUseNativeDialog; | 401 do |
319 | 402 { |
320 QString dir = | 403 line = stream.readLine (); |
321 QFileDialog::getExistingDirectory (this, tr ("Set search directory"), | 404 match = line.contains (match_str, cs); |
322 m_start_dir_edit->text (), | 405 } |
323 QFileDialog::Option (opts)); | 406 while (! line.isNull () && match == false); |
324 | 407 } |
325 if (! dir.isEmpty ()) | 408 |
326 m_start_dir_edit->setText (dir); | 409 } |
327 } | 410 } |
328 | 411 |
329 void find_files_dialog::item_double_clicked (const QModelIndex& idx) | 412 return match; |
330 { | 413 } |
331 find_files_model *m = static_cast<find_files_model *> (m_file_list->model ()); | |
332 | |
333 QFileInfo info = m->fileInfo (idx); | |
334 | |
335 if (idx.column () == 1) | |
336 { | |
337 // clicked in directory part | |
338 emit dir_selected (info.absolutePath ()); | |
339 } | |
340 else | |
341 { | |
342 // clicked in filename part | |
343 if (info.isDir ()) | |
344 emit dir_selected (info.absoluteFilePath ()); | |
345 else | |
346 emit file_selected (info.absoluteFilePath ()); | |
347 } | |
348 } | |
349 | |
350 void find_files_dialog::look_for_files (void) | |
351 { | |
352 if (m_dir_iterator && m_dir_iterator->hasNext ()) | |
353 { | |
354 QFileInfo info (m_dir_iterator->next ()); | |
355 | |
356 find_files_model *m | |
357 = static_cast<find_files_model *> (m_file_list->model ()); | |
358 | |
359 if (is_match (info)) | |
360 m->addFile (info); | |
361 } | |
362 else | |
363 { | |
364 stop_find (); | |
365 } | |
366 } | |
367 | |
368 void find_files_dialog::handle_done (int) | |
369 { | |
370 // make sure we stopped processing | |
371 stop_find (); | |
372 } | |
373 | |
374 bool find_files_dialog::is_match (const QFileInfo& info) | |
375 { | |
376 bool match = true; | |
377 if (info.isDir ()) | |
378 { | |
379 if (! m_include_dirs_check->isChecked ()) match = false; | |
380 if (m_contains_text_check->isChecked ()) match = false; | |
381 } | |
382 else | |
383 { | |
384 // a file | |
385 if (m_contains_text_check->isChecked ()) | |
386 { | |
387 match = false; | |
388 | |
389 QFile file (info.absoluteFilePath ()); | |
390 if (file.open (QIODevice::ReadOnly)) | |
391 { | |
392 QTextStream stream (&file); | |
393 | |
394 QString line; | |
395 QString match_str = m_contains_text_edit->text (); | |
396 | |
397 Qt::CaseSensitivity cs = m_content_case_check->isChecked () | |
398 ? Qt::CaseInsensitive | |
399 : Qt::CaseSensitive; | |
400 | |
401 do | |
402 { | |
403 line = stream.readLine (); | |
404 match = line.contains (match_str, cs); | |
405 } | |
406 while (! line.isNull () && match == false); | |
407 } | |
408 | |
409 } | |
410 } | |
411 | |
412 return match; | |
413 } | |
414 | 414 |
415 OCTAVE_END_NAMESPACE(octave) | 415 OCTAVE_END_NAMESPACE(octave) |