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>
59 if (e->button () != Qt::RightButton)
60 QTreeView::mousePressEvent (e);
67 setObjectName (
"FilesDockWidget");
68 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
70 setToolTip (tr (
"Browse your files"));
90 setWidget (container);
92 connect (
this, SIGNAL (
open_file (
const QString&)),
96 main_win (), SLOT (set_current_working_directory (
const QString&)));
109 QComboBox::AdjustToMinimumContentsLengthWithIcon);
110 QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Preferred);
115 directory_up_action->setToolTip (tr (
"One directory up"));
121 tr (
"Go to current Octave directory"));
128 tr (
"Set Octave directory to current browser directory"));
131 QToolButton * popdown_button =
new QToolButton ();
132 popdown_button->setToolTip (tr (
"Actions on current directory"));
133 QMenu * popdown_menu =
new QMenu ();
135 tr (
"Show Home Directory"),
139 popdown_button->setMenu (popdown_menu);
140 popdown_button->setPopupMode (QToolButton::InstantPopup);
141 popdown_button->setDefaultAction (
new QAction (
145 popdown_menu->addSeparator ();
147 tr (
"Set Browser Directory..."),
149 popdown_menu->addSeparator ();
151 tr (
"Find Files..."),
153 popdown_menu->addSeparator ();
158 tr (
"New Directory..."),
165 connect (directory_up_action, SIGNAL (triggered ()),
this,
178 if (settings->value (
"filesdockwidget/restore_last_dir",
false).toBool ())
181 QStringList last_dirs
182 = settings->value (
"filesdockwidget/mru_dir_list").toStringList ();
183 if (last_dirs.length () > 0)
184 startup_dir = QDir (last_dirs.at (0));
186 else if (! settings->value (
"filesdockwidget/startup_dir").toString ().isEmpty ())
190 = QDir (settings->value (
"filesdockwidget/startup_dir").toString ());
193 if (! startup_dir.exists ())
196 startup_dir = QDir ();
201 startup_dir.absolutePath ());
205 _file_tree_view->setSelectionMode (QAbstractItemView::ExtendedSelection);
212 tr (
"Activate to open in editor, right click for alternatives"));
217 settings->value (
"filesdockwidget/sort_files_by_column",0).toInt (),
218 static_cast<Qt::SortOrder
>
219 (settings->value (
"filesdockwidget/sort_files_by_order",
220 Qt::AscendingOrder).toUInt ())
223 settings->value (
"filesdockwidget/column_state").toByteArray ());
225 QStringList mru_dirs =
226 settings->value (
"filesdockwidget/mru_dir_list").toStringList ();
238 SIGNAL (customContextMenuRequested (
const QPoint &)),
241 _file_tree_view->header()->setContextMenuPolicy (Qt::CustomContextMenu);
243 SIGNAL (customContextMenuRequested (
const QPoint &)),
247 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
248 vbox_layout->setSpacing (0);
251 vbox_layout->setMargin (1);
253 container->setLayout (vbox_layout);
265 main_win (), SLOT (run_file_in_terminal (
const QFileInfo&)));
285 Qt::SortOrder sort_order =
_file_tree_view->header ()->sortIndicatorOrder ();
286 settings->setValue (
"filesdockwidget/sort_files_by_column", sort_column);
287 settings->setValue (
"filesdockwidget/sort_files_by_order", sort_order);
288 settings->setValue (
"filesdockwidget/column_state",
296 settings->setValue (
"filesdockwidget/mru_dir_list", dirs);
362 QFileInfo fileInfo (dir);
363 if (fileInfo.exists ())
365 if (fileInfo.isDir ())
368 index (fileInfo.absoluteFilePath ()));
386 QString abs_fname = fileInfo.absoluteFilePath ();
388 QString suffix = fileInfo.suffix ().toLower ();
390 QString ext = settings->value (
"filesdockwidget/txt_file_extensions",
391 "m;c;cc;cpp;h;txt").toString ();
392 QStringList extensions = ext.split(
";", QString::SkipEmptyParts);
394 if (QFile::exists (abs_fname))
398 else if (extensions.contains (suffix))
399 emit
open_file (fileInfo.absoluteFilePath ());
414 QString
file = fileInfo.absoluteFilePath ();
416 QDesktopServices::openUrl (QUrl::fromLocalFile (file));
424 bool shown = settings->value (key,
false).toBool ();
425 settings->setValue (key, ! shown);
460 action->setCheckable (
true);
479 if (index.isValid ())
484 QModelIndexList sel = m->selectedRows ();
487 if (! sel.contains (index))
490 m->setCurrentIndex(index,
491 QItemSelectionModel::Clear
492 | QItemSelectionModel::Select
493 | QItemSelectionModel::Rows);
502 menu.addAction (tr (
"Open in System File Explorer"),
507 menu.addAction (tr (
"Open in Text Editor"),
510 menu.addAction (tr (
"Copy Selection to Clipboard"),
513 if (info.isFile () && info.suffix () ==
"m")
522 menu.addSeparator ();
524 tr (
"Set Current Directory"),
526 menu.addSeparator ();
528 tr (
"Find Files..."),
this,
532 menu.addSeparator ();
539 menu.addSeparator ();
544 tr (
"New Directory..."),
559 QModelIndexList rows = m->selectedRows ();
561 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
574 QModelIndexList rows = m->selectedRows ();
576 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
580 emit
open_file (file.absoluteFilePath ());
588 QModelIndexList rows = m->selectedRows ();
590 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
598 QModelIndexList rows = m->selectedRows ();
600 QStringList selection;
602 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
606 selection << info.fileName ();
609 QClipboard *clipboard = QApplication::clipboard ();
611 clipboard->setText (selection.join (
"\n"));
618 QModelIndexList rows = m->selectedRows ();
620 if (rows.size () > 0)
622 QModelIndex index = rows[0];
634 QModelIndexList rows = m->selectedRows ();
636 if (rows.size () > 0)
638 QModelIndex index = rows[0];
649 QModelIndexList rows = m->selectedRows ();
650 if (rows.size () > 0)
652 QModelIndex index = rows[0];
655 QDir path = info.absoluteDir ();
656 QString old_name = info.fileName ();
660 = QInputDialog::getText (
this, tr (
"Rename file/directory"),
661 tr (
"Rename file/directory:\n")
662 + old_name + tr (
"\n to: "),
663 QLineEdit::Normal, old_name, &ok);
664 if (ok && new_name.length () > 0)
666 new_name = path.absolutePath () +
"/" + new_name;
667 old_name = path.absolutePath () +
"/" + old_name;
668 path.rename (old_name, new_name);
679 QModelIndexList rows = m->selectedRows ();
681 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
683 QModelIndex index = *it;
687 if (QMessageBox::question (
this, tr (
"Delete file/directory"),
688 tr (
"Are you sure you want to delete\n")
696 QDir path (info.absoluteFilePath ());
698 QDir::NoDotAndDotDot);
700 if (fileLst.count () != 0)
702 tr (
"Can not delete a directory that is not empty"));
721 QModelIndexList rows = m->selectedRows ();
723 if (rows.size () > 0)
725 QModelIndex index = rows[0];
728 QString parent_dir = info.filePath ();
738 QModelIndexList rows = m->selectedRows ();
740 if (rows.size () > 0)
742 QModelIndex index = rows[0];
745 QString parent_dir = info.filePath ();
755 QModelIndexList rows = m->selectedRows ();
757 if (rows.size () > 0)
759 QModelIndex index = rows[0];
774 QModelIndexList rows = m->selectedRows ();
776 if (rows.size () > 0)
778 QModelIndex index = rows[0];
794 int icon_size_settings = settings->value (
"toolbar_icon_size",0).toInt ();
795 QStyle *st = style ();
796 int icon_size = st->pixelMetric (QStyle::PM_ToolBarIconSize);
798 if (icon_size_settings == 1)
799 icon_size = st->pixelMetric (QStyle::PM_LargeIconSize);
800 else if (icon_size_settings == -1)
801 icon_size = st->pixelMetric (QStyle::PM_SmallIconSize);
806 for (
int i = 0;
i < 3;
i++)
823 = settings->value (
"filesdockwidget/sync_octave_directory",
false).toBool ();
839 dir = QDir::homePath ();
847 QString dir = QFileDialog::getExistingDirectory
848 (
this, tr (
"Set directory of file browser"),
850 QFileDialog::ShowDirsOnly
851 | QFileDialog::DontUseNativeDialog);
878 QString
name = QInputDialog::getText (
this, tr (
"Create File"),
879 tr (
"Create file in\n",
"String ends with \\n!") + parent_dir,
880 QLineEdit::Normal, tr (
"New File.txt"), &ok);
881 if (ok && name.length () > 0)
883 name = parent_dir +
"/" +
name;
886 file.open (QIODevice::WriteOnly);
896 QString
name = QInputDialog::getText (
this, tr (
"Create Directory"),
897 tr (
"Create folder in\n",
"String ends with \\n!") + parent_dir,
898 QLineEdit::Normal, tr (
"New Directory"), &ok);
899 if (ok && name.length () > 0)
901 QDir dir (parent_dir);
924 QClipboard *clipboard = QApplication::clipboard ();
927 if (edit && edit->hasSelectedText ())
929 clipboard->setText (edit->selectedText ());
939 QClipboard *clipboard = QApplication::clipboard ();
940 QString
str = clipboard->text ();
942 if (edit && str.length () > 0)
For example cd octave end example noindent changes the current working directory to file
void mousePressEvent(QMouseEvent *e)
bool is_octave_data_file(const std::string &fname)
FileTreeViewer(QWidget *p)
QString fromStdString(const std::string &s)
static std::string get_home_directory(void)
nd deftypefn *octave_map m
static QSettings * get_settings(void)
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 ACM Transactions on Mathematical Article No
void warning(const char *fmt,...)
=val(i)}if ode{val(i)}occurs in table i
static QIcon icon(const QString &icon_name, bool fallback=true)