annotate libgui/src/find-files-dialog.cc @ 21662:5b9868c2e212

maint: Octave coding convention cleanups. * Figure.cc, QtHandlesUtils.cc, files-dock-widget.cc, find-files-dialog.cc, debug.cc, ls-hdf5.h, oct-fstrm.h, oct-iostrm.h, oct-stdstrm.h, oct-stream.h, pr-output.cc, sysdep.cc, zfstream.h, pt-cbinop.cc, f77-fcn.h, DASPK.cc, DASSL.cc, cmd-hist.cc, glob-match.h: Cuddle angle bracket '<' next to C++ cast operator. Space between variable reference and variable name (int& a). Space between bitwise operators and their operands (A & B). Create typedef tree_expression_ptr_t to avoid "tree_expression *&a" which is unclear.
author Rik <rik@octave.org>
date Mon, 02 May 2016 11:13:50 -0700
parents 3d60ed163b70
children aba2e6293dd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
1 /*
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
2
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18345
diff changeset
3 Copyright (C) 2013-2015 John Donoghue
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
4
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
5 This file is part of Octave.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
6
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
10 option) any later version.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
11
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
15 for more details.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
16
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
20
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
21 */
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
22
17921
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
23 #ifdef HAVE_CONFIG_H
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
24 # include "config.h"
17921
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
25 #endif
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
26
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
27 #include <QPushButton>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
28 #include <QDialogButtonBox>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
29 #include <QGridLayout>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
30 #include <QLabel>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
31 #include <QLineEdit>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
32 #include <QComboBox>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
33 #include <QCheckBox>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
34 #include <QHeaderView>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
35 #include <QTableView>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
36 #include <QFileDialog>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
37 #include <QStatusBar>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
38 #include <QIcon>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
39 #include <QFileInfo>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
40 #include <QTimer>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
41 #include <QDirIterator>
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
42 #include <QTextStream>
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
43 #include <QGroupBox>
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
44
17921
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
45 #include "find-files-dialog.h"
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
46 #include "find-files-model.h"
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
47 #include "resource-manager.h"
2a4acd6548c6 include config.h in more files in libgui
John W. Eaton <jwe@octave.org>
parents: 17790
diff changeset
48
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
49 find_files_dialog::find_files_dialog (QWidget * p)
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
50 : QDialog (p)
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
51 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
52 setWindowTitle (tr ("Find Files"));
19899
a8a5415b05cb new gui icons
Torsten <ttl@justmail.de>
parents: 19697
diff changeset
53 setWindowIcon (resource_manager::icon ("edit-find"));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
54
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
55 _dir_iterator = 0;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
56
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
57 _timer = new QTimer (this);
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
58 connect (_timer, SIGNAL (timeout ()), this, SLOT (look_for_files ()));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
59
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
60 QSettings *settings = resource_manager::get_settings ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
61
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
62 QLabel * file_name_label = new QLabel (tr ("Named:"));
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
63 _file_name_edit = new QLineEdit;
18345
dfc6ef6ac455 some text improvements in the gui (#bug 41201)
Torsten <ttl@justmail.de>
parents: 18283
diff changeset
64 _file_name_edit->setToolTip (tr ("Enter the filename search expression"));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
65
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
66 _file_name_edit->setText (settings->value ("findfiles/file_name",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
67 "*").toString ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
68 file_name_label->setBuddy (_file_name_edit);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
69
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
70 QLabel * start_dir_label = new QLabel (tr ("Start in:"));
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
71
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
72 _start_dir_edit = new QLineEdit;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
73 _start_dir_edit->setText (settings->value ("findfiles/start_dir",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
74 QDir::currentPath ()).toString ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
75 _start_dir_edit->setToolTip (tr ("Enter the start directory"));
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
76 start_dir_label->setBuddy (_start_dir_edit);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
77
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
78 _browse_button = new QPushButton (tr ("Browse..."));
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
79 _browse_button->setToolTip (tr ("Browse for start directory"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
80 connect (_browse_button, SIGNAL (clicked ()), this, SLOT (browse_folders ()));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
81
18345
dfc6ef6ac455 some text improvements in the gui (#bug 41201)
Torsten <ttl@justmail.de>
parents: 18283
diff changeset
82 _recurse_dirs_check = new QCheckBox (tr ("Search subdirectories"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
83 _recurse_dirs_check->setChecked (settings->value ("findfiles/recurse_dirs",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
84 false).toBool ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
85 _recurse_dirs_check->setToolTip (
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
86 tr ("Search recursively through directories for matching files"));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
87
18345
dfc6ef6ac455 some text improvements in the gui (#bug 41201)
Torsten <ttl@justmail.de>
parents: 18283
diff changeset
88 _include_dirs_check = new QCheckBox (tr ("Include directory names"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
89 _include_dirs_check->setChecked (settings->value ("findfiles/include_dirs",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
90 false).toBool ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
91 _include_dirs_check->setToolTip (
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
92 tr ("Include matching directories in search results"));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
93
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
94 _name_case_check = new QCheckBox (tr ("Name case insensitive"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
95 _name_case_check->setChecked (settings->value ("findfiles/name_case",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
96 false).toBool ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
97 _name_case_check->setToolTip (tr ("Set matching name is case insensitive"));
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
98
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
99 _contains_text_check = new QCheckBox (tr ("Contains text:"));
18345
dfc6ef6ac455 some text improvements in the gui (#bug 41201)
Torsten <ttl@justmail.de>
parents: 18283
diff changeset
100 _contains_text_check->setToolTip (tr ("Enter the file content search expression"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
101 _contains_text_check->setChecked (settings->value ("findfiles/check_text",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
102 false).toBool ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
103
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
104 _contains_text_edit = new QLineEdit ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
105 _contains_text_edit->setToolTip (tr ("Text to match"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
106 _contains_text_edit->setText (settings->value ("findfiles/contains_text",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
107 "").toString ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
108
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
109 _content_case_check = new QCheckBox (tr ("Text case insensitive"));
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
110 _content_case_check->setChecked (settings->value ("findfiles/content_case",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
111 false).toBool ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
112 _content_case_check->setToolTip (tr ("Set text content is case insensitive"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
113
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16823
diff changeset
114 find_files_model * model = new find_files_model (this);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16823
diff changeset
115
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
116 _file_list = new QTableView;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
117 _file_list->setWordWrap (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
118 _file_list->setModel (model);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
119 _file_list->setShowGrid (false);
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
120 _file_list->setSelectionBehavior (QAbstractItemView::SelectRows);
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
121 _file_list->setSelectionMode (QAbstractItemView::SingleSelection);
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
122 _file_list->setAlternatingRowColors (true);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
123 _file_list->setToolTip (tr ("Search results"));
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16823
diff changeset
124 _file_list->setSortingEnabled (true);
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
125 _file_list->horizontalHeader ()->restoreState (
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
126 settings->value ("findfiles/column_state").toByteArray ());
16997
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16823
diff changeset
127 _file_list->horizontalHeader ()->setSortIndicatorShown (true);
90d50e56a06a Add sortable table headers to find_files_dialog results
John Donoghue <john.donoghue@ieee.org>
parents: 16823
diff changeset
128 _file_list->horizontalHeader ()->setClickable (true);
16823
ffc246701137 make the result list in find files dialog always fill its layout
Torsten <ttl@justmail.de>
parents: 16544
diff changeset
129 _file_list->horizontalHeader ()->setStretchLastSection (true);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
130 _file_list->sortByColumn (
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
131 settings->value ("findfiles/sort_files_by_column",0).toInt (),
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
132 static_cast<Qt::SortOrder>
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
133 (settings->value ("findfiles/sort_files_by_order",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
134 Qt::AscendingOrder).toUInt ()));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
135
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
136 connect (_file_list, SIGNAL (doubleClicked (const QModelIndex&)),
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
137 this, SLOT (item_double_clicked (const QModelIndex &)));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
138
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
139 _status_bar = new QStatusBar;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
140 _status_bar->showMessage (tr ("Idle."));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
141
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21301
diff changeset
142 _find_button = new QPushButton (tr ("Find"));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
143 _find_button->setToolTip (tr ("Start search for matching files"));
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
144 connect (_find_button, SIGNAL (clicked ()), this, SLOT (start_find ()));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
145
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21301
diff changeset
146 _stop_button = new QPushButton (tr ("Stop"));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
147 _stop_button->setToolTip (tr ("Stop searching"));
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
148 _stop_button->setEnabled (false);
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
149 connect (_stop_button, SIGNAL (clicked ()), this, SLOT (stop_find ()));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
150
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
151 // layout everything
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
152 QDialogButtonBox * button_box = new QDialogButtonBox (Qt::Vertical);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
153 button_box->addButton (_find_button, QDialogButtonBox::ActionRole);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
154 button_box->addButton (_stop_button, QDialogButtonBox::ActionRole);
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
155
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
156 // add dialog close button
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
157 _close_button = button_box->addButton (QDialogButtonBox::Close);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
158 connect (button_box, SIGNAL (rejected ()),
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
159 this, SLOT (close ()));
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
160
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
161 // name options
20713
2469d78a1d8b Consistently use 'filename' rather than 'file name' throughout code base.
Rik <rik@octave.org>
parents: 19899
diff changeset
162 QGroupBox * name_group = new QGroupBox (tr ("Filename/location"));
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
163 QGridLayout * name_layout = new QGridLayout;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
164 name_group->setLayout (name_layout);
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
165
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
166 name_layout->addWidget (file_name_label,1,1, 1,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
167 name_layout->addWidget (_file_name_edit,1,2, 1,-1);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
168
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
169 name_layout->addWidget (start_dir_label,2,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
170 name_layout->addWidget (_start_dir_edit,2,2,1,3);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
171 name_layout->addWidget (_browse_button,2,5);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
172 name_layout->setColumnStretch (2,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
173
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
174 name_layout->addWidget (_recurse_dirs_check,3,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
175 name_layout->addWidget (_include_dirs_check,3,2);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
176 name_layout->addWidget (_name_case_check,3,3);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
177
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
178 // content options
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
179 QGroupBox * content_group = new QGroupBox (tr ("File contents"));
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
180 QGridLayout * content_layout = new QGridLayout;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
181 content_group->setLayout (content_layout);
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
182 content_layout->addWidget (_contains_text_check,4,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
183 content_layout->addWidget (_contains_text_edit,4,2,1,3);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
184 content_layout->setColumnStretch (2,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
185 content_layout->addWidget (_content_case_check,5,1);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
186
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
187 QGridLayout *main_layout = new QGridLayout;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
188 main_layout->setSizeConstraint (QLayout::SetFixedSize);
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
189 main_layout->addWidget (name_group, 0, 0);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
190 main_layout->addWidget (content_group, 1, 0);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
191 main_layout->addWidget (button_box, 0, 1,3,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
192 main_layout->addWidget (_file_list,2,0);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
193 main_layout->setRowStretch (2,1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
194 main_layout->addWidget (_status_bar,3,0,1,-1);
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
195
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
196
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
197 setLayout (main_layout);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
198
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
199 connect (this, SIGNAL (finished (int)), this, SLOT (handle_done (int)));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
200 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
201
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
202 find_files_dialog::~find_files_dialog ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
203 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
204 QSettings *settings = resource_manager::get_settings ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
205
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
206 int sort_column = _file_list->horizontalHeader ()->sortIndicatorSection ();
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
207 Qt::SortOrder sort_order
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
208 = _file_list->horizontalHeader ()->sortIndicatorOrder ();
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
209 settings->setValue ("findfiles/sort_files_by_column", sort_column);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
210 settings->setValue ("findfiles/sort_files_by_order", sort_order);
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
211 settings->setValue ("findfiles/column_state",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
212 _file_list->horizontalHeader ()->saveState ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
213
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
214 settings->setValue ("findfiles/file_name", _file_name_edit->text ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
215
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
216 settings->setValue ("findfiles/start_dir", _start_dir_edit->text ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
217
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
218 settings->setValue ("findfiles/recurse_dirs", _recurse_dirs_check->text ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
219 settings->setValue ("findfiles/include_dirs", _include_dirs_check->text ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
220 settings->setValue ("findfiles/name_case", _name_case_check->text ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
221
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
222 settings->setValue ("findfiles/contains_text", _contains_text_edit->text ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
223 settings->setValue ("findfiles/check_text",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
224 _contains_text_check->isChecked ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
225 settings->setValue ("findfiles/content_case",
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
226 _content_case_check->isChecked ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
227
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
228 settings->sync ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
229
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
230 if (_dir_iterator)
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
231 delete _dir_iterator;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
232 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
233
16823
ffc246701137 make the result list in find files dialog always fill its layout
Torsten <ttl@justmail.de>
parents: 16544
diff changeset
234 void find_files_dialog::handle_done (int)
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
235 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
236 // make sure we stopped processing
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
237 stop_find ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
238 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
239
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
240 void find_files_dialog::set_search_dir (const QString &dir)
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
241 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
242 stop_find ();
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
243 _start_dir_edit->setText (dir);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
244 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
245
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
246 void
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
247 find_files_dialog::start_find ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
248 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
249 stop_find ();
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
250
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
251 find_files_model *m = static_cast<find_files_model *> (_file_list->model ());
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
252 m->clear ();
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
253
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
254 QDirIterator::IteratorFlags flags = QDirIterator::NoIteratorFlags;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
255 if (_recurse_dirs_check->isChecked ())
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
256 flags |= QDirIterator::Subdirectories;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
257
21662
5b9868c2e212 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21568
diff changeset
258 QDir::Filters filters = QDir::Dirs | QDir::NoDotAndDotDot | QDir::Files;
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20713
diff changeset
259 if (! _name_case_check->isChecked ())
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21301
diff changeset
260 filters |= QDir::CaseSensitive;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
261
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
262 QStringList nameFilters;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
263 nameFilters.append (_file_name_edit->text ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
264
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
265 if (_dir_iterator) delete _dir_iterator;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
266
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
267 _dir_iterator = new QDirIterator (_start_dir_edit->text (), nameFilters,
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
268 filters, flags);
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
269
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
270 // enable/disable widgets
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
271 _find_button->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
272 _stop_button->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
273 _close_button->setEnabled (false);
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
274 _browse_button->setEnabled (false);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
275 _start_dir_edit->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
276 _file_name_edit->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
277 _recurse_dirs_check->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
278 _include_dirs_check->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
279 _name_case_check->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
280 _contains_text_check->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
281 _content_case_check->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
282 _contains_text_edit->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
283
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
284 _status_bar->showMessage (tr ("Searching..."));
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
285 _timer->start (0);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
286 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
287
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
288 void
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
289 find_files_dialog::stop_find ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
290 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
291 _timer->stop ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
292
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
293 _find_button->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
294 _stop_button->setEnabled (false);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
295 _close_button->setEnabled (true);
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
296 _browse_button->setEnabled (true);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
297 _start_dir_edit->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
298 _file_name_edit->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
299 _recurse_dirs_check->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
300 _include_dirs_check->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
301 _name_case_check->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
302 _contains_text_check->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
303 _content_case_check->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
304 _contains_text_edit->setEnabled (true);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
305
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
306 find_files_model *m = static_cast<find_files_model *> (_file_list->model ());
18283
12291fb903de fix missing translations (bug #41200)
Torsten <ttl@justmail.de>
parents: 17921
diff changeset
307 QString res_str = QString (tr("%1 match(es)")).arg (m->rowCount ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
308
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
309 _status_bar->showMessage (res_str);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
310 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
311
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
312 void
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
313 find_files_dialog::browse_folders ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
314 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
315 QString dir =
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
316 QFileDialog::getExistingDirectory (this, tr ("Set search directory"),
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
317 _start_dir_edit->text ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
318
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
319 if (! dir.isEmpty ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
320 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
321 _start_dir_edit->setText (dir);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
322 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
323 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
324
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
325 void
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
326 find_files_dialog::item_double_clicked (const QModelIndex &idx)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
327 {
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
328 find_files_model *m = static_cast<find_files_model *> (_file_list->model ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
329
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
330 QFileInfo info = m->fileInfo (idx);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
331
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
332 if (idx.column () == 1)
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
333 {
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
334 // clicked in directory part
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
335 emit dir_selected (info.absolutePath ());
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
336 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
337 else
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
338 {
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
339 // clicked in filename part
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
340 if (info.isDir ())
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
341 emit dir_selected (info.absoluteFilePath ());
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
342 else
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
343 emit file_selected (info.absoluteFilePath ());
16544
ced9b101723c Updates to find-file-dialog usage
John Donoghue <john.donoghue@ieee.org>
parents: 16519
diff changeset
344 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
345 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
346
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
347 void
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
348 find_files_dialog::look_for_files ()
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
349 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
350 if (_dir_iterator && _dir_iterator->hasNext ())
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
351 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
352 QFileInfo info (_dir_iterator->next ());
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
353
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
354 find_files_model *m
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
355 = static_cast<find_files_model *> (_file_list->model ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
356
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
357 if (is_match (info))
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
358 m->addFile (info);
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
359 }
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
360 else
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
361 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
362 stop_find ();
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
363 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
364 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
365
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
366 bool find_files_dialog::is_match (const QFileInfo &info)
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
367 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
368 bool match = true;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
369 if (info.isDir ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
370 {
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20713
diff changeset
371 if (! _include_dirs_check->isChecked ()) match = false;
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
372 if (_contains_text_check->isChecked ()) match = false;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
373 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
374 else
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
375 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
376 // a file
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
377 if (_contains_text_check->isChecked ())
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
378 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
379 match = false;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
380
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
381 QFile file (info.absoluteFilePath ());
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
382 if (file.open (QIODevice::ReadOnly))
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
383 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
384 QTextStream stream (&file);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
385
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
386 QString line;
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
387 QString match_str = _contains_text_edit->text ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
388
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
389 Qt::CaseSensitivity cs = _content_case_check->isChecked () ?
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
390 Qt::CaseInsensitive : Qt::CaseSensitive;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
391
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
392 do
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
393 {
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
394 line = stream.readLine ();
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
395 match = line.contains (match_str, cs);
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
396 }
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20713
diff changeset
397 while (! line.isNull () && match == false);
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
398 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
399
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
400 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
401 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
402
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 16997
diff changeset
403 return match;
16519
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
404 }
3e8fd0c479b4 Add find files implemtation to main window menu
John Donoghue <john.donoghue@ieee.org>
parents:
diff changeset
405