GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
files-dock-widget.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2021 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 (octave_files_dock_widget_h)
27 #define octave_files_dock_widget_h 1
28 
29 #include <QAction>
30 #include <QComboBox>
31 #include <QDate>
32 #include <QFileSystemModel>
33 #include <QList>
34 #include <QListView>
35 #include <QListWidget>
36 #include <QMouseEvent>
37 #include <QObject>
38 #include <QSignalMapper>
39 #include <QToolBar>
40 #include <QToolButton>
41 #include <QTreeView>
42 #include <QVBoxLayout>
43 #include <QWidget>
44 
45 #include "octave-dock-widget.h"
46 
47 class octave_value_list;
48 
49 namespace octave
50 {
51  class base_qobject;
52 
53  //! Dock widget to display files in the current directory.
54 
56  {
57  Q_OBJECT
58 
59  public:
60 
61  files_dock_widget (QWidget *parent, base_qobject& oct_qobj);
62 
63  ~files_dock_widget (void) = default;
64 
65  signals:
66 
67  //! Emitted, whenever the user requested to open a file.
68 
69  void open_file (const QString& fileName);
70 
71  //! Emitted, whenever the currently displayed directory changed.
72 
73  void displayed_directory_changed (const QString& dir);
74 
75  //! Emitted, whenever the user requested to load a file in the text editor.
76 
77  void load_file_signal (const QString& fileName);
78 
79  //! Emitted, whenever the user requested to open an unknown type file.
80 
81  void open_any_signal (const QString& fileName);
82 
83  //! Emitted, whenever the user requested to run a file.
84 
85  void run_file_signal (const QFileInfo& info);
86 
87  //! Emitted, whenever wants to search for a file .
88 
89  void find_files_signal (const QString& startdir);
90 
91  //! Emitted, whenever the user removes or renames a file.
92 
93  void file_remove_signal (const QString& old_name, const QString& new_name);
94 
95  //! Emitted, when a file or directory is renamed.
96 
97  void file_renamed_signal (bool);
98 
99  //! Emitted, when the path has to be modified
100 
101  void modify_path_signal (const octave_value_list& dir_list,
102  bool rm, bool subdirs);
103 
104  public slots:
105 
106  //! Slot for handling a change in directory via double click.
107 
108  void item_double_clicked (const QModelIndex & index);
109 
110  //! Slot for handling the up-directory button in the toolbar.
111 
112  void change_directory_up (void);
113 
114  //! Slot for handling the sync octave directory button in the toolbar.
115 
116  void do_sync_octave_directory (void);
117 
118  //! Slot for handling the sync browser directory button in the toolbar.
119 
120  void do_sync_browser_directory (void);
121 
122  //! Sets the current directory being displayed.
123 
124  void set_current_directory (const QString& dir);
125 
126  //! Accepts user input a the line edit for the current directory.
127 
128  void accept_directory_line_edit (void);
129 
130  //! Set the internal variable that holds the actual octave variable.
131 
132  void update_octave_directory (const QString& dir);
133 
134  //! Tells the widget to react on changed settings.
135 
136  void notice_settings (const gui_settings *settings);
137 
138  void save_settings (void);
139 
140  private slots:
141 
142  void headercontextmenu_requested (const QPoint& pos);
143  void toggle_header (int col);
144 
145  //! Context menu wanted.
146 
147  void contextmenu_requested (const QPoint& pos);
148 
149  //! Context menu actions.
150  //!@{
151  void contextmenu_open (bool);
152  void contextmenu_open_in_editor (bool);
153  void contextmenu_open_in_app (bool);
154  void contextmenu_copy_selection (bool);
155  void contextmenu_run (bool);
156  void contextmenu_load (bool);
157  void contextmenu_rename (bool);
158  void contextmenu_delete (bool);
159  void contextmenu_newfile (bool);
160  void contextmenu_newdir (bool);
161  void contextmenu_setcurrentdir (bool);
162  void contextmenu_add_to_path (bool, bool rm=false, bool subdirs=false);
164  void contextmenu_rm_from_path (bool);
166  void contextmenu_findfiles (bool);
167  //!@}
168 
169  //! Popdown menu options.
170  //!@{
171  void popdownmenu_newfile (bool);
172  void popdownmenu_newdir (bool);
173  void popdownmenu_search_dir (bool);
174  void popdownmenu_findfiles (bool);
175  void popdownmenu_home (bool);
176  //!@}
177 
178  //! Inherited from octave_doc_widget.
179  //!@{
180  void copyClipboard ();
181  void pasteClipboard ();
182  void selectAll ();
183  //!@}
184 
185  private:
186 
187  //! Get currently selected QFileInfo object.
188 
190 
191  //! Process new file/directory actions
192 
193  void process_new_file (const QString& parent_name);
194  void process_new_dir (const QString& parent_name);
195 
196  //! Process setting current dir or find in files
197 
198  void process_set_current_dir (const QString& parent_name);
199  void process_find_files (const QString& dir_name);
200 
201  //! set a new directory or open a file
202 
203  void display_directory (const QString& dir, bool set_octave_dir = true);
204 
205  void open_item_in_app (const QModelIndex& index);
206 
207  //! Variables for the actions
208 
212 
213  //! The file system model.
214 
215  QFileSystemModel *m_file_system_model;
216 
217  //! The file system view.
218  //!@{
221  //!@}
222 
223  //! Flag if syncing with Octave.
224 
226 
227  //! The actual Octave directory.
228 
229  QString m_octave_dir;
230 
231  enum { MaxMRUDirs = 10 };
232 
233  QStringList m_columns_shown;
234  QStringList m_columns_shown_keys;
236  QSignalMapper *m_sig_mapper;
237  };
238 }
239 
240 #endif
Base class for Octave interfaces that use Qt.
Dock widget to display files in the current directory.
void contextmenu_copy_selection(bool)
Context menu actions.
void contextmenu_rm_from_path_subdirs(bool)
Context menu actions.
QString m_octave_dir
The actual Octave directory.
void contextmenu_add_to_path_subdirs(bool)
Context menu actions.
void contextmenu_add_to_path(bool, bool rm=false, bool subdirs=false)
Context menu actions.
void process_new_dir(const QString &parent_name)
void do_sync_browser_directory(void)
Slot for handling the sync browser directory button in the toolbar.
~files_dock_widget(void)=default
void open_item_in_app(const QModelIndex &index)
void process_new_file(const QString &parent_name)
Process new file/directory actions.
void headercontextmenu_requested(const QPoint &pos)
void contextmenu_run(bool)
Context menu actions.
void open_file(const QString &fileName)
Emitted, whenever the user requested to open a file.
void open_any_signal(const QString &fileName)
Emitted, whenever the user requested to open an unknown type file.
void update_octave_directory(const QString &dir)
Set the internal variable that holds the actual octave variable.
void contextmenu_rm_from_path(bool)
Context menu actions.
void process_set_current_dir(const QString &parent_name)
Process setting current dir or find in files.
QList< QFileInfo > get_selected_items_info(bool)
Get currently selected QFileInfo object.
QTreeView * m_file_tree_view
The file system view.
void notice_settings(const gui_settings *settings)
Tells the widget to react on changed settings.
void contextmenu_load(bool)
Context menu actions.
void copyClipboard()
Inherited from octave_doc_widget.
void selectAll()
Inherited from octave_doc_widget.
QToolBar * m_navigation_tool_bar
Variables for the actions.
void change_directory_up(void)
Slot for handling the up-directory button in the toolbar.
void run_file_signal(const QFileInfo &info)
Emitted, whenever the user requested to run a file.
void accept_directory_line_edit(void)
Accepts user input a the line edit for the current directory.
void popdownmenu_newdir(bool)
Popdown menu options.
void contextmenu_newdir(bool)
Context menu actions.
void display_directory(const QString &dir, bool set_octave_dir=true)
set a new directory or open a file
void popdownmenu_search_dir(bool)
Popdown menu options.
void popdownmenu_home(bool)
Popdown menu options.
void contextmenu_open(bool)
Context menu actions.
files_dock_widget(QWidget *parent, base_qobject &oct_qobj)
void contextmenu_open_in_editor(bool)
Context menu actions.
void item_double_clicked(const QModelIndex &index)
Slot for handling a change in directory via double click.
bool m_sync_octave_dir
Flag if syncing with Octave.
void pasteClipboard()
Inherited from octave_doc_widget.
void contextmenu_newfile(bool)
Context menu actions.
QFileSystemModel * m_file_system_model
The file system model.
void contextmenu_requested(const QPoint &pos)
Context menu wanted.
void do_sync_octave_directory(void)
Slot for handling the sync octave directory button in the toolbar.
void file_remove_signal(const QString &old_name, const QString &new_name)
Emitted, whenever the user removes or renames a file.
void popdownmenu_findfiles(bool)
Popdown menu options.
QComboBox * m_current_directory
The file system view.
void process_find_files(const QString &dir_name)
void contextmenu_rename(bool)
Context menu actions.
QList< QVariant > m_columns_shown_defs
void find_files_signal(const QString &startdir)
Emitted, whenever wants to search for a file .
void contextmenu_setcurrentdir(bool)
Context menu actions.
void contextmenu_delete(bool)
Context menu actions.
void load_file_signal(const QString &fileName)
Emitted, whenever the user requested to load a file in the text editor.
void popdownmenu_newfile(bool)
Popdown menu options.
void set_current_directory(const QString &dir)
Sets the current directory being displayed.
void file_renamed_signal(bool)
Emitted, when a file or directory is renamed.
void contextmenu_findfiles(bool)
Context menu actions.
void modify_path_signal(const octave_value_list &dir_list, bool rm, bool subdirs)
Emitted, when the path has to be modified.
void contextmenu_open_in_app(bool)
Context menu actions.
void displayed_directory_changed(const QString &dir)
Emitted, whenever the currently displayed directory changed.