26#if defined (HAVE_CONFIG_H)
30#include <QApplication>
34#include <QDesktopServices>
38#include <QInputDialog>
68 if (e->button () != Qt::RightButton)
69 QTreeView::mousePressEvent (e);
76 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
78 setToolTip (tr (
"Browse your files"));
105 setWidget (container);
117 m_current_directory->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon);
118 QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred);
123 QAction *directory_up_action
125 directory_up_action->setToolTip (tr (
"One directory up"));
128 =
new QAction (rmgr.
icon (
"go-first"), tr (
"Show Octave directory"),
134 =
new QAction (rmgr.
icon (
"go-last"), tr (
"Set Octave directory"),
140 popdown_button->setToolTip (tr (
"Actions on current directory"));
142 popdown_menu->addAction (rmgr.
icon (
"user-home"),
143 tr (
"Show Home Directory"),
this,
147 popdown_button->setMenu (popdown_menu);
148 popdown_button->setPopupMode (QToolButton::InstantPopup);
149 popdown_button->setDefaultAction (
new QAction (rmgr.
icon (
"applications-system"),
152 popdown_menu->addSeparator ();
153 popdown_menu->addAction (rmgr.
icon (
"folder"),
154 tr (
"Set Browser Directory..."),
156 popdown_menu->addSeparator ();
157 popdown_menu->addAction (rmgr.
icon (
"edit-find"),
158 tr (
"Find Files..."),
160 popdown_menu->addSeparator ();
161 popdown_menu->addAction (rmgr.
icon (
"document-new"),
164 popdown_menu->addAction (rmgr.
icon (
"folder-new"),
165 tr (
"New Directory..."),
172 connect (directory_up_action, &QAction::triggered,
188 QStringList last_dirs
190 if (last_dirs.length () > 0)
191 startup_dir = QDir (last_dirs.at (0));
199 if (! startup_dir.exists ())
202 startup_dir = QDir ();
208 QDir::System | QDir::NoDotAndDotDot | QDir::AllEntries);
209 QModelIndex rootPathIndex
220 m_file_tree_view->setToolTip (tr (
"Double-click to open file/folder, right click for alternatives"));
239 QStringList mru_dirs =
256 &QHeaderView::customContextMenuRequested,
260 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
261 vbox_layout->setSpacing (0);
264 vbox_layout->setMargin (1);
266 container->setLayout (vbox_layout);
313 Qt::SortOrder sort_order =
m_file_tree_view->header ()->sortIndicatorOrder ();
383 QFileInfo fileInfo (dir);
384 if (fileInfo.exists ())
386 if (fileInfo.isDir ())
389 index (fileInfo.absoluteFilePath ()));
407 QString abs_fname = fileInfo.absoluteFilePath ();
409 QString suffix = fileInfo.suffix ().toLower ();
413#if defined (HAVE_QT_SPLITBEHAVIOR_ENUM)
414 QStringList extensions = ext.split (
";", Qt::SkipEmptyParts);
416 QStringList extensions = ext.split (
";", QString::SkipEmptyParts);
418 if (QFile::exists (abs_fname))
420 if (extensions.contains (suffix))
421 emit
open_file (fileInfo.absoluteFilePath ());
434 QString file = fileInfo.absoluteFilePath ();
436 QDesktopServices::openUrl (QUrl::fromLocalFile (file));
445 bool shown =
settings->value (key,
false).toBool ();
481 action->setCheckable (
true);
514 if (index.isValid ())
519 QModelIndexList sel = m->selectedRows ();
522 if (! sel.contains (index))
525 m->setCurrentIndex (index,
526 QItemSelectionModel::Clear
527 | QItemSelectionModel::Select
528 | QItemSelectionModel::Rows);
534 menu.addAction (rmgr.
icon (
"document-open"), tr (
"Open"),
539 menu.addAction (tr (
"Open in System File Explorer"),
544 menu.addAction (tr (
"Open in Text Editor"),
547 menu.addAction (tr (
"Copy Selection to Clipboard"),
550 if (info.isFile () && info.suffix () ==
"m")
551 menu.addAction (rmgr.
icon (
"media-playback-start"), tr (
"Run"),
555 menu.addAction (tr (
"Load Data"),
560 menu.addSeparator ();
561 menu.addAction (rmgr.
icon (
"go-first"), tr (
"Set Current Directory"),
564 QMenu *add_path_menu = menu.addMenu (tr (
"Add to Path"));
566 add_path_menu->addAction (tr (
"Selected Directories"),
568 add_path_menu->addAction (tr (
"Selected Directories and Subdirectories"),
571 QMenu *rm_path_menu = menu.addMenu (tr (
"Remove from Path"));
573 rm_path_menu->addAction (tr (
"Selected Directories"),
575 rm_path_menu->addAction (tr (
"Selected Directories and Subdirectories"),
578 menu.addSeparator ();
580 menu.addAction (rmgr.
icon (
"edit-find"), tr (
"Find Files..."),
584 menu.addSeparator ();
585 menu.addAction (tr (
"Rename..."),
587 menu.addAction (rmgr.
icon (
"edit-delete"), tr (
"Delete..."),
592 menu.addSeparator ();
593 menu.addAction (rmgr.
icon (
"document-new"), tr (
"New File..."),
595 menu.addAction (rmgr.
icon (
"folder-new"), tr (
"New Directory..."),
609 QModelIndexList rows = m->selectedRows ();
611 for (
auto it = rows.begin (); it != rows.end (); it++)
623 QModelIndexList rows = m->selectedRows ();
625 for (
auto it = rows.begin (); it != rows.end (); it++)
629 emit
open_file (file.absoluteFilePath ());
636 QModelIndexList rows = m->selectedRows ();
638 for (
auto it = rows.begin (); it != rows.end (); it++)
645 QModelIndexList rows = m->selectedRows ();
647 QStringList selection;
649 for (
auto it = rows.begin (); it != rows.end (); it++)
653 selection << info.fileName ();
656 QClipboard *clipboard = QApplication::clipboard ();
658 clipboard->setText (selection.join (
"\n"));
664 QModelIndexList rows = m->selectedRows ();
666 if (rows.size () > 0)
668 QModelIndex index = rows[0];
679 QModelIndexList rows = m->selectedRows ();
681 if (rows.size () > 0)
683 QModelIndex index = rows[0];
693 QModelIndexList rows = m->selectedRows ();
694 if (rows.size () > 0)
696 QModelIndex index = rows[0];
699 QDir
path = info.absoluteDir ();
700 QString old_name = info.fileName ();
704 = QInputDialog::getText (
this, tr (
"Rename file/directory"),
705 tr (
"Rename file/directory:\n")
706 + old_name + tr (
"\n to: "),
707 QLineEdit::Normal, old_name, &ok);
708 if (ok && new_name.length () > 0)
710 new_name =
path.absolutePath () +
'/' + new_name;
711 old_name =
path.absolutePath () +
'/' + old_name;
716 bool st =
f.rename (new_name);
719 tr (
"Could not rename file \"%1\" to \"%2\".").
720 arg (old_name).arg (new_name));
733 QModelIndexList rows = m->selectedRows ();
735 int file_cnt = rows.size ();
736 bool multiple_files = (file_cnt > 1);
738 for (
auto it = rows.begin (); it != rows.end (); it++)
740 QModelIndex index = *it;
744 QMessageBox::StandardButton dlg_answer;
746 if (it == rows.begin ())
748 dlg_answer = QMessageBox::question (
this,
749 tr (
"Delete file/directory"),
750 tr (
"Are you sure you want to delete all %1 selected files?\n").arg (file_cnt),
751 QMessageBox::Yes | QMessageBox::No);
752 if (dlg_answer != QMessageBox::Yes)
756 dlg_answer = QMessageBox::Yes;
759 dlg_answer = QMessageBox::question (
this,
760 tr (
"Delete file/directory"),
761 tr (
"Are you sure you want to delete\n")
763 QMessageBox::Yes | QMessageBox::No);
771 QDir
path (info.absoluteFilePath ());
773 QDir::Hidden | QDir::AllEntries |
774 QDir::NoDotAndDotDot | QDir::System);
776 if (fileLst.count () != 0)
778 tr (
"Can not delete a directory that is not empty"));
791 tr (
"Could not delete file \"%1\".").
792 arg (info.filePath ()));
809 QModelIndexList rows = m->selectedRows ();
813 for (
auto it = rows.begin (); it != rows.end (); it++)
815 QModelIndex index = *it;
819 if (info.exists () &&
820 ((dir & info.isDir ()) || (! dir && info.isFile ())))
830 QModelIndexList rows = m->selectedRows ();
832 if (rows.size () > 0)
834 QModelIndex index = rows[0];
837 QString parent_dir = info.filePath ();
846 QModelIndexList rows = m->selectedRows ();
848 if (rows.size () > 0)
850 QModelIndex index = rows[0];
853 QString parent_dir = info.filePath ();
863 if (infos.length () > 0 && infos.first ().isDir ())
871 QStringList dir_list;
873 for (
int i = 0; i < infos.length (); i++)
874 dir_list.append (infos.at (i).absoluteFilePath ());
876 if (infos.length () > 0)
898 QModelIndexList rows = m->selectedRows ();
900 if (rows.size () > 0)
902 QModelIndex index = rows[0];
918 size_idx = (size_idx > 0) - (size_idx < 0) + 1;
920 QStyle *st = style ();
925 for (
int i = 0; i < 3; i++)
961 dir = QDir::homePath ();
969 int opts = QFileDialog::ShowDirsOnly;
973 opts |= QFileDialog::DontUseNativeDialog;
975 QString dir = QFileDialog::getExistingDirectory (
this,
976 tr (
"Set directory of file browser"),
978 QFileDialog::Option (opts));
1001 QString
name = QInputDialog::getText (
this, tr (
"Create File"),
1002 tr (
"Create file in\n",
"String ends with \\n!") + parent_dir,
1004 tr (
"New File.txt"), &ok);
1005 if (ok &&
name.length () > 0)
1010 file.open (QIODevice::WriteOnly);
1019 QString
name = QInputDialog::getText (
this, tr (
"Create Directory"),
1020 tr (
"Create folder in\n",
"String ends with \\n!") + parent_dir,
1022 tr (
"New Directory"), &ok);
1023 if (ok &&
name.length () > 0)
1025 QDir dir (parent_dir);
1047 QClipboard *clipboard = QApplication::clipboard ();
1050 if (edit && edit->hasSelectedText ())
1052 clipboard->setText (edit->selectedText ());
1061 QClipboard *clipboard = QApplication::clipboard ();
1062 QString str = clipboard->text ();
1064 if (edit && str.length () > 0)
void mousePressEvent(QMouseEvent *e)
~FileTreeViewer(void)=default
FileTreeViewer(QWidget *p)
Base class for Octave interfaces that use Qt.
resource_manager & get_resource_manager(void)
gui_settings * get_settings(void) const
QIcon icon(const QString &icon_name, bool fallback=true)
static std::string get_home_directory(void)
void warning(const char *fmt,...)
const gui_pref fb_mru_list("filesdockwidget/mru_dir_list", QVariant(QStringList()))
const gui_pref fb_column_state("filesdockwidget/column_state", QVariant())
const gui_pref fb_show_date("filesdockwidget/showLastModified", QVariant(false))
const gui_pref fb_sync_octdir("filesdockwidget/sync_octave_directory", QVariant(true))
const gui_pref fb_sort_order("filesdockwidget/sort_files_by_order", QVariant(Qt::AscendingOrder))
const gui_pref fb_sort_column("filesdockwidget/sort_files_by_column", QVariant(0))
const gui_pref fb_show_type("filesdockwidget/showFileType", QVariant(false))
const gui_pref fb_show_hidden("filesdockwidget/showHiddenFiles", QVariant(false))
const gui_pref fb_startup_dir("filesdockwidget/startup_dir", QVariant(QString()))
const gui_pref fb_show_size("filesdockwidget/showFileSize", QVariant(false))
const gui_pref fb_txt_file_ext("filesdockwidget/txt_file_extensions", QVariant("m;c;cc;cpp;h;txt"))
const gui_pref fb_restore_last_dir("filesdockwidget/restore_last_dir", QVariant(false))
const gui_pref fb_show_altcol("filesdockwidget/useAlternatingRowColors", QVariant(true))
const QStyle::PixelMetric global_icon_sizes[3]
const gui_pref global_use_native_dialogs("use_native_file_dialogs", QVariant(true))
const gui_pref global_icon_size("toolbar_icon_size", QVariant(0))
QString fromStdString(const std::string &s)
static double f(double k, double l_nu, double c_pm)