31 #include <QApplication>
37 #include <QHeaderView>
39 #include <QSizePolicy>
41 #include <QInputDialog>
42 #include <QMessageBox>
43 #include <QToolButton>
45 #include <QDesktopServices>
46 #include <QFileDialog>
58 if (e->button () != Qt::RightButton)
59 QTreeView::mousePressEvent (e);
66 setObjectName (
"FilesDockWidget");
67 setWindowIcon (QIcon (
":/actions/icons/logo.png"));
69 setToolTip (tr (
"Browse your files."));
73 setWidget (container);
75 connect (
this, SIGNAL (
open_file (
const QString&)),
79 main_win (), SLOT (set_current_working_directory (
const QString&)));
92 QComboBox::AdjustToMinimumContentsLengthWithIcon);
93 QSizePolicy sizePol (QSizePolicy::Expanding, QSizePolicy::Maximum);
96 QAction *directory_up_action =
new QAction (QIcon (
":/actions/icons/up.png"),
98 directory_up_action->setToolTip (tr (
"Move up one directory"));
101 =
new QAction (QIcon (
":/actions/icons/reload.png"),
104 tr (
"Goto current octave directory"));
108 =
new QAction (QIcon (
":/actions/icons/ok.png"),
111 tr (
"Set octave directroy to current browser directory"));
114 QToolButton * popdown_button =
new QToolButton ();
115 popdown_button->setToolTip (tr (
"Actions on current directory"));
116 QMenu * popdown_menu =
new QMenu ();
117 popdown_menu->addAction (QIcon (
":/actions/icons/home.png"),
118 tr (
"Show Home directory"),
122 popdown_button->setMenu (popdown_menu);
123 popdown_button->setPopupMode (QToolButton::InstantPopup);
124 popdown_button->setDefaultAction (
new QAction (
125 QIcon (
":/actions/icons/gear.png"),
"",
128 popdown_menu->addSeparator ();
129 popdown_menu->addAction (QIcon (
":/actions/icons/search.png"),
130 tr (
"Search directory"),
132 popdown_menu->addSeparator ();
133 popdown_menu->addAction ( tr (
"Find Files ..."),
135 popdown_menu->addSeparator ();
136 popdown_menu->addAction (QIcon (
":/actions/icons/filenew.png"),
139 popdown_menu->addAction (QIcon (
":/actions/icons/folder_new.png"),
140 tr (
"New Directory"),
147 connect (directory_up_action, SIGNAL (triggered ()),
this,
160 if (settings->value (
"filesdockwidget/showHiddenFiles",
false).toBool ())
170 curr_dir.absolutePath ());
174 _file_tree_view->setSelectionMode (QAbstractItemView::ExtendedSelection);
185 settings->value (
"filesdockwidget/sort_files_by_column",0).toInt (),
186 static_cast<Qt::SortOrder
>
187 (settings->value (
"filesdockwidget/sort_files_by_order",
188 Qt::AscendingOrder).toUInt ())
191 settings->value (
"filesdockwidget/column_state").toByteArray ());
193 QStringList mru_dirs =
194 settings->value (
"filesdockwidget/mru_dir_list").toStringList ();
200 connect (
_file_tree_view, SIGNAL (doubleClicked (
const QModelIndex &)),
206 SIGNAL (customContextMenuRequested (
const QPoint &)),
209 _file_tree_view->header()->setContextMenuPolicy (Qt::CustomContextMenu);
211 SIGNAL (customContextMenuRequested (
const QPoint &)),
215 QVBoxLayout *vbox_layout =
new QVBoxLayout ();
216 vbox_layout->setSpacing (0);
219 vbox_layout->setMargin (1);
221 container->setLayout (vbox_layout);
233 main_win (), SLOT (run_file_in_terminal (
const QFileInfo&)));
248 Qt::SortOrder sort_order =
_file_tree_view->header ()->sortIndicatorOrder ();
249 settings->setValue (
"filesdockwidget/sort_files_by_column", sort_column);
250 settings->setValue (
"filesdockwidget/sort_files_by_order", sort_order);
251 settings->setValue (
"filesdockwidget/column_state",
259 settings->setValue (
"filesdockwidget/mru_dir_list", dirs);
320 QFileInfo fileInfo (dir);
321 if (fileInfo.exists ())
323 if (fileInfo.isDir ())
326 index (fileInfo.absoluteFilePath ()));
345 QString abs_fname = fileInfo.absoluteFilePath ();
352 emit
open_file (fileInfo.absoluteFilePath ());
364 QString file = fileInfo.absoluteFilePath ();
366 QDesktopServices::openUrl (QUrl::fromLocalFile (file));
373 (
"filesdockwidget/showFileSize",
374 ! settings->value (
"filesdockwidget/showFileSize",
false).toBool ());
383 (
"filesdockwidget/showFileType",
384 ! settings->value (
"filesdockwidget/showFileType",
false).toBool ());
393 (
"filesdockwidget/showLastModified",
394 ! settings->value (
"filesdockwidget/showLastModified",
false).toBool ());
403 (
"filesdockwidget/showHiddenFiles",
404 ! settings->value (
"filesdockwidget/showHiddenFiles",
false).toBool ());
416 QAction fileSizeAction (tr (
"File size"), &menu);
417 fileSizeAction.setCheckable (
true);
418 fileSizeAction.setChecked (
419 settings->value (
"filesdockwidget/showFileSize",
false).toBool ());
420 connect (&fileSizeAction, SIGNAL(triggered ()),
422 menu.addAction (&fileSizeAction);
424 QAction fileTypeAction (tr (
"File type"), &menu);
425 fileTypeAction.setCheckable (
true);
426 fileTypeAction.setChecked (
427 settings->value (
"filesdockwidget/showFileType",
false).toBool ());
428 connect (&fileTypeAction, SIGNAL(triggered ()),
430 menu.addAction (&fileTypeAction);
432 QAction dateModifiedAction (tr (
"Date modified"), &menu);
433 dateModifiedAction.setCheckable (
true);
434 dateModifiedAction.setChecked(
435 settings->value (
"filesdockwidget/showLastModified",
false).toBool ());
436 connect (&dateModifiedAction, SIGNAL(triggered ()),
438 menu.addAction (&dateModifiedAction);
440 QAction showHiddenAction (tr (
"Show hidden"), &menu);
441 showHiddenAction.setCheckable (
true);
442 showHiddenAction.setChecked (
443 settings->value (
"filesdockwidget/showHiddenFiles",
false).toBool ());
444 connect (&showHiddenAction, SIGNAL (triggered ()),
446 menu.addAction (&showHiddenAction);
460 if (index.isValid ())
464 menu.addAction (QIcon (
":/actions/icons/fileopen.png"), tr (
"Open"),
467 menu.addAction (tr (
"Open in Default Application"),
470 menu.addAction (tr (
"Copy Selection to Clipboard"),
473 if (info.isFile () && info.suffix () ==
"m")
474 menu.addAction (QIcon (
":/actions/icons/artsbuilderexecute.png"),
482 menu.addSeparator ();
483 menu.addAction (QIcon (
":/actions/icons/ok.png"),
484 tr (
"Set Current Directory"),
486 menu.addSeparator ();
487 menu.addAction (tr (
"Find Files ..."),
this,
491 menu.addSeparator ();
493 menu.addAction (QIcon (
":/actions/icons/editdelete.png"), tr (
"Delete"),
498 menu.addSeparator ();
499 menu.addAction (QIcon (
":/actions/icons/filenew.png"),
502 menu.addAction (QIcon (
":/actions/icons/folder_new.png"),
503 tr (
"New Directory"),
517 QModelIndexList rows = m->selectedRows ();
519 for ( QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
529 QModelIndexList rows = m->selectedRows ();
531 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
539 QModelIndexList rows = m->selectedRows ();
541 QStringList selection;
543 for (QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
547 selection << info.fileName ();
550 QClipboard *clipboard = QApplication::clipboard ();
552 clipboard->setText (selection.join (
"\n"));
559 QModelIndexList rows = m->selectedRows ();
561 if (rows.size () > 0)
563 QModelIndex index = rows[0];
575 QModelIndexList rows = m->selectedRows ();
577 if (rows.size () > 0)
579 QModelIndex index = rows[0];
590 QModelIndexList rows = m->selectedRows ();
591 if (rows.size () > 0)
593 QModelIndex index = rows[0];
596 QDir path = info.absoluteDir ();
597 QString old_name = info.fileName ();
601 = QInputDialog::getText (
this, tr (
"Rename file/directory"),
602 tr (
"Rename file/directory:\n")
603 + old_name + tr (
"\n to: "),
604 QLineEdit::Normal, old_name, &ok);
605 if (ok && new_name.length () > 0)
607 new_name = path.absolutePath () +
"/" + new_name;
608 old_name = path.absolutePath () +
"/" + old_name;
609 path.rename (old_name, new_name);
620 QModelIndexList rows = m->selectedRows ();
622 for ( QModelIndexList::iterator it = rows.begin (); it != rows.end (); it++)
624 QModelIndex index = *it;
628 if (QMessageBox::question (
this, tr (
"Delete file/directory"),
629 tr (
"Are you sure you want to delete\n")
631 QMessageBox::Yes|QMessageBox::No)
637 QDir path (info.absoluteFilePath ());
639 QDir::NoDotAndDotDot);
641 if (fileLst.count () != 0)
643 tr (
"Can not delete a directory that is not empty"));
662 QModelIndexList rows = m->selectedRows ();
664 if (rows.size () > 0)
666 QModelIndex index = rows[0];
669 QString parent_dir = info.filePath ();
679 QModelIndexList rows = m->selectedRows ();
681 if (rows.size () > 0)
683 QModelIndex index = rows[0];
686 QString parent_dir = info.filePath ();
696 QModelIndexList rows = m->selectedRows ();
698 if (rows.size () > 0)
700 QModelIndex index = rows[0];
715 QModelIndexList rows = m->selectedRows ();
717 if (rows.size () > 0)
719 QModelIndex index = rows[0];
735 int icon_size = settings->value (
"toolbar_icon_size",16).toInt ();
737 icon_size = icon_size - 4;
743 ! settings->value (
"filesdockwidget/showFileSize",
false).toBool ());
745 ! settings->value (
"filesdockwidget/showFileType",
false).toBool ());
747 ! settings->value (
"filesdockwidget/showLastModified",
false).toBool ());
749 settings->value (
"filesdockwidget/useAlternatingRowColors",
true).toBool ());
750 if (settings->value (
"filesdockwidget/showHiddenFiles",
false).toBool ())
764 = settings->value (
"filesdockwidget/sync_octave_directory",
false).toBool ();
776 QString dir = qgetenv (
"HOME");
778 dir = QDir::homePath ();
786 QString dir = QFileDialog::getExistingDirectory
787 (
this, tr (
"Set directory of file browser"),
789 QFileDialog::DontUseNativeDialog);
816 QString name = QInputDialog::getText (
this, tr (
"Create File"),
817 tr (
"Create file in\n") + parent_dir,
818 QLineEdit::Normal,
"New File.txt", &ok);
819 if (ok && name.length () > 0)
821 name = parent_dir +
"/" + name;
824 file.open (QIODevice::WriteOnly);
834 QString name = QInputDialog::getText (
this, tr (
"Create Directory"),
835 tr (
"Create folder in\n") + parent_dir,
836 QLineEdit::Normal,
"New Directory",
838 if (ok && name.length () > 0)
840 QDir dir (parent_dir);
863 QClipboard *clipboard = QApplication::clipboard ();
866 if (edit && edit->hasSelectedText ())
868 clipboard->setText (edit->selectedText ());
878 QClipboard *clipboard = QApplication::clipboard ();
879 QString str = clipboard->text ();
881 if (edit && str.length () > 0)