GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
set-path-dialog.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2019-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <QCheckBox>
31#include <QComboBox>
32#include <QDialogButtonBox>
33#include <QDirIterator>
34#include <QFileDialog>
35#include <QFileDialog>
36#include <QFileInfo>
37#include <QGridLayout>
38#include <QGroupBox>
39#include <QHBoxLayout>
40#include <QHeaderView>
41#include <QIcon>
42#include <QLabel>
43#include <QLineEdit>
44#include <QListView>
45#include <QMenu>
46#include <QPushButton>
47#include <QStatusBar>
48#include <QTextStream>
49#include <QTimer>
50#include <QVBoxLayout>
51
52#include "gui-preferences-pd.h"
53#include "octave-qobject.h"
54#include "octave-qtutils.h"
55#include "set-path-dialog.h"
56#include "set-path-model.h"
57
58#include "ovl.h"
59
60namespace octave
61{
63 : QDialog (parent), m_octave_qobj (oct_qobj)
64 {
65 setWindowTitle (tr ("Set Path"));
66
67 set_path_model *model = new set_path_model (this);
68
69 m_info_label = new QLabel (tr ("All changes take effect immediately."));
70
71 m_add_folder_button = new QPushButton (tr ("Add Folder..."));
72
73 QMenu *add_dir_menu = new QMenu ();
74 m_add_folder_button->setMenu (add_dir_menu);
75 add_dir_menu->addAction (tr ("Single Folder"),
77 add_dir_menu->addAction (tr ("Folder With Subfolders"),
79
80 m_move_to_top_button = new QPushButton (tr ("Move to Top"));
81 m_move_to_bottom_button = new QPushButton (tr ("Move to Bottom"));
82 m_move_up_button = new QPushButton (tr ("Move Up"));
83 m_move_down_button = new QPushButton (tr ("Move Down"));
84 m_remove_button = new QPushButton (tr ("Remove"));
85
86 m_reload_button = new QPushButton (tr ("Reload"));
87 m_save_button = new QPushButton (tr ("Save"));
88
89 m_revert_button = new QPushButton (tr ("Revert"));
90
91 QMenu *revert_menu = new QMenu ();
92 m_revert_button->setMenu (revert_menu);
93 revert_menu->addAction (tr ("Revert Last Change"),
95 revert_menu->addAction (tr ("Revert All Changes"),
97
98 m_save_button->setFocus ();
99
100 connect (m_remove_button, &QPushButton::clicked,
102
103 connect (m_move_to_top_button, &QPushButton::clicked,
105
106 connect (m_move_to_bottom_button, &QPushButton::clicked,
108
109 connect (m_move_up_button, &QPushButton::clicked,
111
112 connect (m_move_down_button, &QPushButton::clicked,
114
115 connect (m_reload_button, &QPushButton::clicked,
117
118 connect (m_save_button, &QPushButton::clicked,
119 model, &set_path_model::save);
120
121 // Any interpreter_event signal from a set_path_model object is
122 // handled the same as for the parent set_path_dialog object.
123
126
129
130 m_path_list = new QListView (this);
131 m_path_list->setWordWrap (false);
132 m_path_list->setModel (model);
133 m_path_list->setSelectionBehavior (QAbstractItemView::SelectRows);
134 m_path_list->setSelectionMode (QAbstractItemView::ExtendedSelection);
135 m_path_list->setAlternatingRowColors (true);
136 m_path_list->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
137
138 // layout everything
139 QDialogButtonBox *button_box = new QDialogButtonBox (Qt::Horizontal);
140 button_box->addButton (m_save_button, QDialogButtonBox::ActionRole);
141 button_box->addButton (m_reload_button, QDialogButtonBox::ActionRole);
142
143 // add dialog close button
144 m_close_button = button_box->addButton (QDialogButtonBox::Close);
145 connect (button_box, &QDialogButtonBox::rejected,
146 this, &set_path_dialog::close);
147
148 button_box->addButton (m_revert_button, QDialogButtonBox::ActionRole);
149
150 // path edit options
151 QDialogButtonBox *path_edit_layout = new QDialogButtonBox (Qt::Vertical);
152 path_edit_layout->addButton (m_add_folder_button, QDialogButtonBox::ActionRole);
153 path_edit_layout->addButton (m_move_to_top_button, QDialogButtonBox::ActionRole);
154 path_edit_layout->addButton (m_move_up_button, QDialogButtonBox::ActionRole);
155 path_edit_layout->addButton (m_move_down_button, QDialogButtonBox::ActionRole);
156 path_edit_layout->addButton (m_move_to_bottom_button, QDialogButtonBox::ActionRole);
157 path_edit_layout->addButton (m_remove_button, QDialogButtonBox::ActionRole);
158
159 // main layout
160 QHBoxLayout *main_hboxlayout = new QHBoxLayout;
161 main_hboxlayout->addWidget(path_edit_layout);
162 main_hboxlayout->addWidget(m_path_list);
163
164 QGridLayout *main_layout = new QGridLayout;
165 main_layout->addWidget (m_info_label, 0, 0);
166 main_layout->addLayout (main_hboxlayout, 1, 0);
167 main_layout->addWidget (button_box, 2, 0);
168
169 setLayout (main_layout);
170
173 restoreGeometry (
174 settings->value(pd_geometry.key).toByteArray());
175 }
176
178 {
179 set_path_model *m = static_cast<set_path_model *> (m_path_list->model ());
180 m->path_to_model ();
181 }
182
184 {
185 QString dir
186 = QFileDialog::getExistingDirectory (this, tr ("Open Directory"),
187 "",
188 (QFileDialog::ShowDirsOnly
189 | QFileDialog::DontResolveSymlinks));
190
191 if (! dir.isEmpty ())
192 {
193 if (subdirs)
194 {
195 // Use existing method mofifying load path and updating dialog
196 // instead of adding string and updating load path
197 emit modify_path_signal (QStringList (dir), false, true);
198 }
199 else
200 {
202 = static_cast<set_path_model *> (m_path_list->model ());
203 m->add_dir (dir);
204 }
205 }
206 }
207
209 {
210 add_dir_common (false);
211 }
212
214 {
215 add_dir_common (true);
216 }
217
219 {
220 set_path_model *m = static_cast<set_path_model *> (m_path_list->model ());
221 QItemSelectionModel *selmodel = m_path_list->selectionModel ();
222 QModelIndexList indexlist = selmodel->selectedIndexes();
223 m->rm_dir (indexlist);
224
225 selmodel->clearSelection ();
226 }
227
229 {
230 set_path_model *m = static_cast<set_path_model *> (m_path_list->model ());
231 QItemSelectionModel *selmodel = m_path_list->selectionModel ();
232 QModelIndexList indexlist = selmodel->selectedIndexes();
233 m->move_dir_up (indexlist);
234
235 // Update selection and view
236 selmodel->clearSelection ();
237 int min_row = m->rowCount () - 1;
238 for (int i = 0; i < indexlist.length (); i++)
239 {
240 int new_row = std::max (indexlist.at (i).row () - 1, 0);
241 min_row = std::min (min_row, new_row);
242 selmodel->select (m->index (new_row), QItemSelectionModel::Select);
243 }
244
245 m_path_list->scrollTo (m->index (min_row));
246 }
247
249 {
250 set_path_model *m = static_cast<set_path_model *> (m_path_list->model ());
251 QItemSelectionModel *selmodel = m_path_list->selectionModel ();
252 QModelIndexList indexlist = selmodel->selectedIndexes();
253 m->move_dir_down (indexlist);
254
255 // Update selection and view
256 selmodel->clearSelection ();
257 int max_row = 0;
258 for (int i = 0; i < indexlist.length (); i++)
259 {
260 int new_row = std::min (indexlist.at (i).row () + 1, m->rowCount () - 1);
261 max_row = std::max (max_row, new_row);
262 selmodel->select (m->index (new_row), QItemSelectionModel::Select);
263 }
264
265 m_path_list->scrollTo (m->index (max_row));
266 }
267
269 {
270 set_path_model *m = static_cast<set_path_model *> (m_path_list->model ());
271 QItemSelectionModel *selmodel = m_path_list->selectionModel ();
272 QModelIndexList indexlist = selmodel->selectedIndexes();
273 m->move_dir_top (indexlist);
274
275 // Update selection and view
276 selmodel->clearSelection ();
277 for (int i = 0; i < indexlist.length (); i++)
278 selmodel->select (m->index (i), QItemSelectionModel::Select);
279
280 m_path_list->scrollTo (m->index (0));
281 }
282
284 {
285 set_path_model *m = static_cast<set_path_model *> (m_path_list->model ());
286 QItemSelectionModel *selmodel = m_path_list->selectionModel ();
287 QModelIndexList indexlist = selmodel->selectedIndexes();
288 m->move_dir_bottom (indexlist);
289
290 // Update selection and view
291 selmodel->clearSelection ();
292 int row_count = m->rowCount ();
293 for (int i = 0; i < indexlist.length (); i++)
294 selmodel->select (m->index (row_count - 1 - i),
295 QItemSelectionModel::Select);
296
297 m_path_list->scrollTo (m->index (row_count - 1));
298 }
299
301 {
304 settings->setValue (pd_geometry.key, saveGeometry ());
305 }
306
307 void set_path_dialog::closeEvent (QCloseEvent *e)
308 {
309 save_settings ();
310
311 QWidget::closeEvent (e);
312 }
313
314}
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:230
charNDArray min(char d, const charNDArray &m)
Definition: chNDArray.cc:207
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
gui_settings * get_settings(void) const
void interpreter_event(const fcn_callback &fcn)
QPushButton * m_remove_button
set_path_dialog(QWidget *parent, base_qobject &oct_qobj)
QPushButton * m_move_to_top_button
void add_dir_common(bool subdirs)
base_qobject & m_octave_qobj
QPushButton * m_move_up_button
void modify_path_signal(const QStringList &dir_list, bool rm, bool subdirs)
Emitted, when the path has to be modified.
QPushButton * m_revert_button
QPushButton * m_add_folder_button
QPushButton * m_close_button
QPushButton * m_move_to_bottom_button
QPushButton * m_reload_button
QPushButton * m_move_down_button
void closeEvent(QCloseEvent *e)
void move_dir_down(const QModelIndexList &indices)
void interpreter_event(const fcn_callback &fcn)
void add_dir(const QString &p)
void move_dir_top(const QModelIndexList &indices)
void move_dir_up(const QModelIndexList &indices)
int rowCount(const QModelIndex &p=QModelIndex()) const
void rm_dir(const QModelIndexList &indices)
void move_dir_bottom(const QModelIndexList &indices)
const gui_pref pd_geometry("path_dlg_geometry", QVariant(QByteArray()))
const QString key