23 #if defined (HAVE_CONFIG_H) 27 #include <QPushButton> 28 #include <QDialogButtonBox> 29 #include <QGridLayout> 34 #include <QHeaderView> 36 #include <QFileDialog> 41 #include <QDirIterator> 42 #include <QTextStream> 54 setWindowTitle (tr (
"Find Files"));
65 QLabel *file_name_label =
new QLabel (tr (
"Named:"));
73 QLabel *start_dir_label =
new QLabel (tr (
"Start in:"));
77 QDir::currentPath ()).toString ());
89 m_recurse_dirs_check->setToolTip (tr (
"Search recursively through directories for matching files"));
122 m_file_list->setSelectionBehavior (QAbstractItemView::SelectRows);
123 m_file_list->setSelectionMode (QAbstractItemView::SingleSelection);
127 m_file_list->horizontalHeader ()->restoreState (settings->value (
"findfiles/column_state").toByteArray ());
128 m_file_list->horizontalHeader ()->setSortIndicatorShown (
true);
129 #if defined (HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE) 130 m_file_list->horizontalHeader ()->setSectionsClickable (
true);
132 m_file_list->horizontalHeader ()->setClickable (
true);
134 m_file_list->horizontalHeader ()->setStretchLastSection (
true);
135 m_file_list->sortByColumn (settings->value (
"findfiles/sort_files_by_column",0).toInt (),
136 static_cast<Qt::SortOrder
> 137 (settings->value (
"findfiles/sort_files_by_order",
138 Qt::AscendingOrder).toUInt ()));
140 connect (
m_file_list, SIGNAL (doubleClicked (
const QModelIndex&)),
147 m_find_button->setToolTip (tr (
"Start search for matching files"));
158 QDialogButtonBox *button_box =
new QDialogButtonBox (Qt::Vertical);
159 button_box->addButton (
m_find_button, QDialogButtonBox::ActionRole);
160 button_box->addButton (
m_stop_button, QDialogButtonBox::ActionRole);
164 connect (button_box, SIGNAL (rejected (
void)),
this, SLOT (close (
void)));
167 QGroupBox *name_group =
new QGroupBox (tr (
"Filename/location"));
168 QGridLayout *name_layout =
new QGridLayout;
169 name_group->setLayout (name_layout);
171 name_layout->addWidget (file_name_label,1,1, 1,1);
174 name_layout->addWidget (start_dir_label,2,1);
177 name_layout->setColumnStretch (2,1);
184 QGroupBox *content_group =
new QGroupBox (tr (
"File contents"));
185 QGridLayout *content_layout =
new QGridLayout;
186 content_group->setLayout (content_layout);
189 content_layout->setColumnStretch (2,1);
192 QGridLayout *main_layout =
new QGridLayout;
193 main_layout->setSizeConstraint (QLayout::SetFixedSize);
194 main_layout->addWidget (name_group, 0, 0);
195 main_layout->addWidget (content_group, 1, 0);
196 main_layout->addWidget (button_box, 0, 1,3,1);
198 main_layout->setRowStretch (2,1);
201 setLayout (main_layout);
203 connect (
this, SIGNAL (finished (
int)),
this, SLOT (
handle_done (
int)));
218 int sort_column =
m_file_list->horizontalHeader ()->sortIndicatorSection ();
219 Qt::SortOrder sort_order
220 =
m_file_list->horizontalHeader ()->sortIndicatorOrder ();
221 settings->setValue (
"findfiles/sort_files_by_column", sort_column);
222 settings->setValue (
"findfiles/sort_files_by_order", sort_order);
223 settings->setValue (
"findfiles/column_state",
235 settings->setValue (
"findfiles/check_text",
237 settings->setValue (
"findfiles/content_case",
256 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
258 flags |= QDirIterator::Subdirectories;
260 QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files;
262 filters |= QDir::CaseSensitive;
264 QStringList nameFilters;
309 QString res_str = QString (tr (
"%1 match (es)")).arg (m->
rowCount ());
317 QFileDialog::getExistingDirectory (
this, tr (
"Set search directory"),
320 if (! dir.isEmpty ())
330 if (idx.column () == 1)
384 QFile
file (info.absoluteFilePath ());
385 if (
file.open (QIODevice::ReadOnly))
393 Qt::CaseInsensitive : Qt::CaseSensitive;
398 match =
line.contains (match_str,
cs);
400 while (!
line.isNull () && match ==
false);
void set_search_dir(const QString &dir)
QLineEdit * m_file_name_edit
For example cd octave end example noindent changes the current working directory to file
bool is_match(const QFileInfo &info)
void file_selected(const QString &fileName)
find_files_dialog(QWidget *parent=nullptr)
QLineEdit * m_contains_text_edit
QCheckBox * m_contains_text_check
QPushButton * m_browse_button
void addFile(const QFileInfo &info)
void dir_selected(const QString &fileName)
QPushButton * m_stop_button
void item_double_clicked(const QModelIndex &)
QFileInfo fileInfo(const QModelIndex &p) const
void browse_folders(void)
virtual ~find_files_dialog(void)
QCheckBox * m_name_case_check
QPushButton * m_close_button
QStatusBar * m_status_bar
QPushButton * m_find_button
QDirIterator * m_dir_iterator
static QIcon icon(const QString &icon_name, bool fallback=true)
void look_for_files(void)
static QSettings * get_settings(void)
QLineEdit * m_start_dir_edit
QCheckBox * m_content_case_check
QCheckBox * m_recurse_dirs_check
int rowCount(const QModelIndex &p=QModelIndex()) const
QCheckBox * m_include_dirs_check