26 #if defined (HAVE_CONFIG_H)
30 #include <QApplication>
34 #include <QDesktopServices>
35 #include <QFileDialog>
37 #include <QHeaderView>
38 #include <QInputDialog>
41 #include <QMessageBox>
43 #include <QSizePolicy>
44 #include <QToolButton>
69 if (e->button () != Qt::RightButton)
70 QTreeView::mousePressEvent (e);
77 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
79 setToolTip (tr (
"Browse your files"));
106 setWidget (container);
108 connect (
this, SIGNAL (
open_file (
const QString&)),
113 SLOT (set_current_working_directory (
const QString&)));
130 m_current_directory->setSizeAdjustPolicy (QComboBox::AdjustToMinimumContentsLengthWithIcon);
131 QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred);
136 QAction *directory_up_action
138 directory_up_action->setToolTip (tr (
"One directory up"));
141 =
new QAction (rmgr.
icon (
"go-first"), tr (
"Show Octave directory"),
147 =
new QAction (rmgr.
icon (
"go-last"), tr (
"Set Octave directory"),
153 popdown_button->setToolTip (tr (
"Actions on current directory"));
155 popdown_menu->addAction (rmgr.
icon (
"user-home"),
156 tr (
"Show Home Directory"),
this,
160 popdown_button->setMenu (popdown_menu);
161 popdown_button->setPopupMode (QToolButton::InstantPopup);
162 popdown_button->setDefaultAction (
new QAction (rmgr.
icon (
"applications-system"),
165 popdown_menu->addSeparator ();
166 popdown_menu->addAction (rmgr.
icon (
"folder"),
167 tr (
"Set Browser Directory..."),
169 popdown_menu->addSeparator ();
170 popdown_menu->addAction (rmgr.
icon (
"edit-find"),
171 tr (
"Find Files..."),
173 popdown_menu->addSeparator ();
174 popdown_menu->addAction (rmgr.
icon (
"document-new"),
177 popdown_menu->addAction (rmgr.
icon (
"folder-new"),
178 tr (
"New Directory..."),
185 connect (directory_up_action, SIGNAL (triggered ()),
this,
201 QStringList last_dirs
203 if (last_dirs.length () > 0)
204 startup_dir = QDir (last_dirs.at (0));
212 if (! startup_dir.exists ())
215 startup_dir = QDir ();
221 QDir::System | QDir::NoDotAndDotDot | QDir::AllEntries);
222 QModelIndex rootPathIndex
233 m_file_tree_view->setToolTip (tr (
"Double-click to open file/folder, right click for alternatives"));
248 #if defined (HAVE_QHEADERVIEW_SETSECTIONSCLICKABLE)
253 #if defined (HAVE_QHEADERVIEW_SETSECTIONSMOVABLE)
260 QStringList mru_dirs =
273 SIGNAL (customContextMenuRequested (
const QPoint &)),
278 SIGNAL (customContextMenuRequested (
const QPoint &)),
282 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
283 vbox_layout->setSpacing (0);
286 vbox_layout->setMargin (1);
288 container->setLayout (vbox_layout);
300 main_win (), SLOT (run_file_in_terminal (
const QFileInfo&)));
320 Qt::SortOrder sort_order =
m_file_tree_view->header ()->sortIndicatorOrder ();
390 QFileInfo fileInfo (dir);
391 if (fileInfo.exists ())
393 if (fileInfo.isDir ())
396 index (fileInfo.absoluteFilePath ()));
414 QString abs_fname = fileInfo.absoluteFilePath ();
416 QString suffix = fileInfo.suffix ().toLower ();
420 #if defined (HAVE_QT_SPLITBEHAVIOR_ENUM)
421 QStringList extensions = ext.split (
";", Qt::SkipEmptyParts);
423 QStringList extensions = ext.split (
";", QString::SkipEmptyParts);
425 if (QFile::exists (abs_fname))
427 if (extensions.contains (suffix))
428 emit
open_file (fileInfo.absoluteFilePath ());
441 QString file = fileInfo.absoluteFilePath ();
443 QDesktopServices::openUrl (QUrl::fromLocalFile (file));
452 bool shown =
settings->value (key,
false).toBool ();
488 action->setCheckable (
true);
507 if (index.isValid ())
512 QModelIndexList sel =
m->selectedRows ();
515 if (! sel.contains (index))
518 m->setCurrentIndex (index,
519 QItemSelectionModel::Clear
520 | QItemSelectionModel::Select
521 | QItemSelectionModel::Rows);
527 menu.addAction (rmgr.
icon (
"document-open"), tr (
"Open"),
532 menu.addAction (tr (
"Open in System File Explorer"),
537 menu.addAction (tr (
"Open in Text Editor"),
540 menu.addAction (tr (
"Copy Selection to Clipboard"),
543 if (info.isFile () && info.suffix () ==
"m")
544 menu.addAction (rmgr.
icon (
"media-playback-start"),
552 menu.addSeparator ();
553 menu.addAction (rmgr.
icon (
"go-first"),
554 tr (
"Set Current Directory"),
557 QMenu *add_path_menu = menu.addMenu (tr (
"Add to Path"));
559 add_path_menu->addAction (tr (
"Selected Directories"),
561 add_path_menu->addAction (tr (
"Selected Directories and Subdirectories"),
564 QMenu *rm_path_menu = menu.addMenu (tr (
"Remove from Path"));
566 rm_path_menu->addAction (tr (
"Selected Directories"),
this,
568 rm_path_menu->addAction (tr (
"Selected Directories and Subdirectories"),
571 menu.addSeparator ();
573 menu.addAction (rmgr.
icon (
"edit-find"),
574 tr (
"Find Files..."),
this,
578 menu.addSeparator ();
580 menu.addAction (rmgr.
icon (
"edit-delete"),
585 menu.addSeparator ();
586 menu.addAction (rmgr.
icon (
"document-new"),
589 menu.addAction (rmgr.
icon (
"folder-new"),
590 tr (
"New Directory..."),
604 QModelIndexList rows =
m->selectedRows ();
606 for (
auto it = rows.begin (); it != rows.end (); it++)
618 QModelIndexList rows =
m->selectedRows ();
620 for (
auto it = rows.begin (); it != rows.end (); it++)
624 emit
open_file (file.absoluteFilePath ());
631 QModelIndexList rows =
m->selectedRows ();
633 for (
auto it = rows.begin (); it != rows.end (); it++)
640 QModelIndexList rows =
m->selectedRows ();
642 QStringList selection;
644 for (
auto it = rows.begin (); it != rows.end (); it++)
648 selection << info.fileName ();
651 QClipboard *clipboard = QApplication::clipboard ();
653 clipboard->setText (selection.join (
"\n"));
659 QModelIndexList rows =
m->selectedRows ();
661 if (rows.size () > 0)
663 QModelIndex index = rows[0];
674 QModelIndexList rows =
m->selectedRows ();
676 if (rows.size () > 0)
678 QModelIndex index = rows[0];
688 QModelIndexList rows =
m->selectedRows ();
689 if (rows.size () > 0)
691 QModelIndex index = rows[0];
694 QDir
path = info.absoluteDir ();
695 QString old_name = info.fileName ();
699 = QInputDialog::getText (
this, tr (
"Rename file/directory"),
700 tr (
"Rename file/directory:\n")
701 + old_name + tr (
"\n to: "),
702 QLineEdit::Normal, old_name, &ok);
703 if (ok && new_name.length () > 0)
705 new_name =
path.absolutePath () +
'/' + new_name;
706 old_name =
path.absolutePath () +
'/' + old_name;
711 bool st =
f.rename (new_name);
724 QModelIndexList rows =
m->selectedRows ();
726 for (
auto it = rows.begin (); it != rows.end (); it++)
728 QModelIndex index = *it;
732 if (QMessageBox::question (
this, tr (
"Delete file/directory"),
733 tr (
"Are you sure you want to delete\n")
735 QMessageBox::Yes | QMessageBox::No)
741 QDir
path (info.absoluteFilePath ());
743 QDir::Hidden | QDir::AllEntries |
744 QDir::NoDotAndDotDot | QDir::System);
746 if (fileLst.count () != 0)
748 tr (
"Can not delete a directory that is not empty"));
774 QModelIndexList rows =
m->selectedRows ();
778 for (
auto it = rows.begin (); it != rows.end (); it++)
780 QModelIndex index = *it;
784 if (info.exists () &&
785 ((dir & info.isDir ()) || (! dir && info.isFile ())))
795 QModelIndexList rows =
m->selectedRows ();
797 if (rows.size () > 0)
799 QModelIndex index = rows[0];
802 QString parent_dir = info.filePath ();
811 QModelIndexList rows =
m->selectedRows ();
813 if (rows.size () > 0)
815 QModelIndex index = rows[0];
818 QString parent_dir = info.filePath ();
828 if (infos.length () > 0 && infos.first ().isDir ())
838 for (
int i = 0; i < infos.length (); i++)
839 dir_list.
append (infos.at (i).absoluteFilePath ().toStdString ());
841 if (infos.length () > 0)
863 QModelIndexList rows =
m->selectedRows ();
865 if (rows.size () > 0)
867 QModelIndex index = rows[0];
883 size_idx = (size_idx > 0) - (size_idx < 0) + 1;
885 QStyle *st = style ();
890 for (
int i = 0; i < 3; i++)
926 dir = QDir::homePath ();
934 int opts = QFileDialog::ShowDirsOnly;
938 opts |= QFileDialog::DontUseNativeDialog;
940 QString dir = QFileDialog::getExistingDirectory (
this,
941 tr (
"Set directory of file browser"),
943 QFileDialog::Option (opts));
966 QString
name = QInputDialog::getText (
this, tr (
"Create File"),
967 tr (
"Create file in\n",
"String ends with \\n!") + parent_dir,
969 tr (
"New File.txt"), &ok);
970 if (ok &&
name.length () > 0)
975 file.open (QIODevice::WriteOnly);
984 QString
name = QInputDialog::getText (
this, tr (
"Create Directory"),
985 tr (
"Create folder in\n",
"String ends with \\n!") + parent_dir,
987 tr (
"New Directory"), &ok);
988 if (ok &&
name.length () > 0)
990 QDir dir (parent_dir);
1012 QClipboard *clipboard = QApplication::clipboard ();
1015 if (edit && edit->hasSelectedText ())
1017 clipboard->setText (edit->selectedText ());
1026 QClipboard *clipboard = QApplication::clipboard ();
1027 QString str = clipboard->text ();
1029 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)
octave_value_list & append(const octave_value &val)
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)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.