24 #if defined (HAVE_CONFIG_H) 31 #include <QApplication> 37 #include <QHeaderView> 39 #include <QSizePolicy> 41 #include <QInputDialog> 42 #include <QMessageBox> 43 #include <QToolButton> 45 #include <QDesktopServices> 46 #include <QFileDialog> 63 if (
e->button () != Qt::RightButton)
64 QTreeView::mousePressEvent (
e);
71 setObjectName (
"FilesDockWidget");
72 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
74 setToolTip (tr (
"Browse your files"));
94 setWidget (container);
96 connect (
this, SIGNAL (
open_file (
const QString&)),
101 SLOT (set_current_working_directory (
const QString&)));
114 QComboBox::AdjustToMinimumContentsLengthWithIcon);
115 QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred);
120 directory_up_action->setToolTip (tr (
"One directory up"));
126 tr (
"Go to current Octave directory"));
133 tr (
"Set Octave directory to current browser directory"));
137 popdown_button->setToolTip (tr (
"Actions on current directory"));
140 tr (
"Show Home Directory"),
144 popdown_button->setMenu (popdown_menu);
145 popdown_button->setPopupMode (QToolButton::InstantPopup);
146 popdown_button->setDefaultAction (
new QAction (
150 popdown_menu->addSeparator ();
152 tr (
"Set Browser Directory..."),
154 popdown_menu->addSeparator ();
156 tr (
"Find Files..."),
158 popdown_menu->addSeparator ();
163 tr (
"New Directory..."),
170 connect (directory_up_action, SIGNAL (triggered ()),
this,
183 if (settings->value (
"filesdockwidget/restore_last_dir",
false).toBool ())
186 QStringList last_dirs
187 = settings->value (
"filesdockwidget/mru_dir_list").toStringList ();
188 if (last_dirs.length () > 0)
189 startup_dir = QDir (last_dirs.at (0));
191 else if (! settings->value (
"filesdockwidget/startup_dir").toString ().isEmpty ())
195 = QDir (settings->value (
"filesdockwidget/startup_dir").toString ());
198 if (! startup_dir.exists ())
201 startup_dir = QDir ();
206 startup_dir.absolutePath ());
217 tr (
"Activate to open in editor, right click for alternatives"));
222 settings->value (
"filesdockwidget/sort_files_by_column",0).toInt (),
223 static_cast<Qt::SortOrder
> 224 (settings->value (
"filesdockwidget/sort_files_by_order",
225 Qt::AscendingOrder).toUInt ())
228 settings->value (
"filesdockwidget/column_state").toByteArray ());
230 QStringList mru_dirs =
231 settings->value (
"filesdockwidget/mru_dir_list").toStringList ();
243 SIGNAL (customContextMenuRequested (
const QPoint &)),
248 SIGNAL (customContextMenuRequested (
const QPoint &)),
252 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
253 vbox_layout->setSpacing (0);
256 vbox_layout->setMargin (1);
258 container->setLayout (vbox_layout);
270 main_win (), SLOT (run_file_in_terminal (
const QFileInfo&)));
289 Qt::SortOrder sort_order =
m_file_tree_view->header ()->sortIndicatorOrder ();
290 settings->setValue (
"filesdockwidget/sort_files_by_column", sort_column);
291 settings->setValue (
"filesdockwidget/sort_files_by_order", sort_order);
292 settings->setValue (
"filesdockwidget/column_state",
300 settings->setValue (
"filesdockwidget/mru_dir_list", dirs);
358 QFileInfo fileInfo (dir);
359 if (fileInfo.exists ())
361 if (fileInfo.isDir ())
364 index (fileInfo.absoluteFilePath ()));
382 QString abs_fname = fileInfo.absoluteFilePath ();
384 QString suffix = fileInfo.suffix ().toLower ();
386 QString ext = settings->value (
"filesdockwidget/txt_file_extensions",
387 "m;c;cc;cpp;h;txt").toString ();
388 QStringList extensions = ext.split (
";", QString::SkipEmptyParts);
390 if (QFile::exists (abs_fname))
394 else if (extensions.contains (suffix))
395 emit
open_file (fileInfo.absoluteFilePath ());
409 QString
file = fileInfo.absoluteFilePath ();
411 QDesktopServices::openUrl (QUrl::fromLocalFile (
file));
419 bool shown = settings->value (key,
false).toBool ();
420 settings->setValue (key, ! shown);
454 action->setCheckable (
true);
472 if (index.isValid ())
477 QModelIndexList sel = m->selectedRows ();
480 if (! sel.contains (index))
483 m->setCurrentIndex (index,
484 QItemSelectionModel::Clear
485 | QItemSelectionModel::Select
486 | QItemSelectionModel::Rows);
495 menu.addAction (tr (
"Open in System File Explorer"),
500 menu.addAction (tr (
"Open in Text Editor"),
503 menu.addAction (tr (
"Copy Selection to Clipboard"),
506 if (info.isFile () && info.suffix () ==
"m")
515 menu.addSeparator ();
517 tr (
"Set Current Directory"),
519 menu.addSeparator ();
521 tr (
"Find Files..."),
this,
525 menu.addSeparator ();
532 menu.addSeparator ();
537 tr (
"New Directory..."),
551 QModelIndexList rows = m->selectedRows ();
553 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
565 QModelIndexList rows = m->selectedRows ();
567 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
578 QModelIndexList rows = m->selectedRows ();
580 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
587 QModelIndexList rows = m->selectedRows ();
589 QStringList selection;
591 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
595 selection << info.fileName ();
598 QClipboard *clipboard = QApplication::clipboard ();
600 clipboard->setText (selection.join (
"\n"));
606 QModelIndexList rows = m->selectedRows ();
608 if (rows.size () > 0)
610 QModelIndex index = rows[0];
621 QModelIndexList rows = m->selectedRows ();
623 if (rows.size () > 0)
625 QModelIndex index = rows[0];
635 QModelIndexList rows = m->selectedRows ();
636 if (rows.size () > 0)
638 QModelIndex index = rows[0];
641 QDir path = info.absoluteDir ();
642 QString old_name = info.fileName ();
646 = QInputDialog::getText (
this, tr (
"Rename file/directory"),
647 tr (
"Rename file/directory:\n")
648 + old_name + tr (
"\n to: "),
649 QLineEdit::Normal, old_name, &ok);
650 if (ok && new_name.length () > 0)
652 new_name = path.absolutePath () +
'/' + new_name;
653 old_name = path.absolutePath () +
'/' + old_name;
657 bool st = path.rename (old_name, new_name);
670 QModelIndexList rows = m->selectedRows ();
672 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
674 QModelIndex index = *it;
678 if (QMessageBox::question (
this, tr (
"Delete file/directory"),
679 tr (
"Are you sure you want to delete\n")
687 QDir path (info.absoluteFilePath ());
689 QDir::NoDotAndDotDot);
691 if (fileLst.count () != 0)
693 tr (
"Can not delete a directory that is not empty"));
717 QModelIndexList rows = m->selectedRows ();
719 if (rows.size () > 0)
721 QModelIndex index = rows[0];
724 QString parent_dir = info.filePath ();
733 QModelIndexList rows = m->selectedRows ();
735 if (rows.size () > 0)
737 QModelIndex index = rows[0];
740 QString parent_dir = info.filePath ();
749 QModelIndexList rows = m->selectedRows ();
751 if (rows.size () > 0)
753 QModelIndex index = rows[0];
767 QModelIndexList rows = m->selectedRows ();
769 if (rows.size () > 0)
771 QModelIndex index = rows[0];
786 int icon_size_settings = settings->value (
"toolbar_icon_size",0).toInt ();
787 QStyle *st = style ();
788 int icon_size = st->pixelMetric (QStyle::PM_ToolBarIconSize);
790 if (icon_size_settings == 1)
791 icon_size = st->pixelMetric (QStyle::PM_LargeIconSize);
792 else if (icon_size_settings == -1)
793 icon_size = st->pixelMetric (QStyle::PM_SmallIconSize);
798 for (
int i = 0;
i < 3;
i++)
815 = settings->value (
"filesdockwidget/sync_octave_directory",
true).toBool ();
830 dir = QDir::homePath ();
837 QString dir = QFileDialog::getExistingDirectory (
this,
838 tr (
"Set directory of file browser"),
840 QFileDialog::ShowDirsOnly
841 | QFileDialog::DontUseNativeDialog);
864 QString
name = QInputDialog::getText (
this, tr (
"Create File"),
865 tr (
"Create file in\n",
"String ends with \\n!") + parent_dir,
867 tr (
"New File.txt"), &ok);
868 if (ok &&
name.length () > 0)
873 file.open (QIODevice::WriteOnly);
882 QString
name = QInputDialog::getText (
this, tr (
"Create Directory"),
883 tr (
"Create folder in\n",
"String ends with \\n!") + parent_dir,
885 tr (
"New Directory"), &ok);
886 if (ok &&
name.length () > 0)
888 QDir dir (parent_dir);
910 QClipboard *clipboard = QApplication::clipboard ();
913 if (edit && edit->hasSelectedText ())
915 clipboard->setText (edit->selectedText ());
924 QClipboard *clipboard = QApplication::clipboard ();
925 QString
str = clipboard->text ();
927 if (edit &&
str.length () > 0)
For example cd octave end example noindent changes the current working directory to file
FileTreeViewer(QWidget *p)
bool is_octave_data_file(const std::string &fname)
QString fromStdString(const std::string &s)
nd deftypefn *std::string name
static std::string get_home_directory(void)
void warning(const char *fmt,...)
static QIcon icon(const QString &icon_name, bool fallback=true)
void mousePressEvent(QMouseEvent *e)
static QSettings * get_settings(void)
~FileTreeViewer(void)=default
nd example The result of the integration is returned in the value of it is recommended to verify this value for difficult integrands and then a warning is issued and as may be less efficient for a smooth or otherwise well behaved integrand than other methods such as Article No