diff --git a/sources/elementspanelwidget.cpp b/sources/elementspanelwidget.cpp index 09b3cd124..87d54dfb4 100644 --- a/sources/elementspanelwidget.cpp +++ b/sources/elementspanelwidget.cpp @@ -53,6 +53,8 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { elements_panel = new ElementsPanel(this); // initialise les actions + open_directory = new QAction(QET::Icons::DocumentOpen, tr("Ouvrir le dossier correspondant"), this); + copy_path = new QAction(QET::Icons::CopyFile, tr("Copier le chemin"), this); reload = new QAction(QET::Icons::ViewRefresh, tr("Recharger les collections"), this); new_category = new QAction(QET::Icons::FolderNew, tr("Nouvelle cat\351gorie"), this); edit_category = new QAction(QET::Icons::FolderEdit, tr("\311diter la cat\351gorie"), this); @@ -95,6 +97,8 @@ ElementsPanelWidget::ElementsPanelWidget(QWidget *parent) : QWidget(parent) { context_menu = new QMenu(this); + connect(open_directory, SIGNAL(triggered()), this, SLOT(openDirectoryForSelectedItem())); + connect(copy_path, SIGNAL(triggered()), this, SLOT(copyPathForSelectedItem())); connect(reload, SIGNAL(triggered()), this, SLOT(reloadAndFilter())); connect(new_category, SIGNAL(triggered()), this, SLOT(newCategory())); connect(edit_category, SIGNAL(triggered()), this, SLOT(editCategory())); @@ -189,6 +193,33 @@ void ElementsPanelWidget::clearFilterTextField() { filterEdited(QString()); } +/** + Require the desktop environment to open the directory containing the file + represented by the selected item, if any. +*/ +void ElementsPanelWidget::openDirectoryForSelectedItem() { + if (QTreeWidgetItem *qtwi = elements_panel -> currentItem()) { + QString dir_path = elements_panel -> dirPathForItem(qtwi); + if (!dir_path.isEmpty()) { + QDesktopServices::openUrl(dir_path); + } + } +} + +/** + Copy the full path to the file represented by the selected item to the + clipboard. +*/ +void ElementsPanelWidget::copyPathForSelectedItem() { + if (QTreeWidgetItem *qtwi = elements_panel -> currentItem()) { + QString file_path = elements_panel -> filePathForItem(qtwi); + file_path = QDir::toNativeSeparators(file_path); + if (!file_path.isEmpty()) { + QApplication::clipboard() -> setText(file_path); + } + } +} + /** Recharge le panel d'elements */ @@ -468,6 +499,13 @@ void ElementsPanelWidget::handleContextMenu(const QPoint &pos) { updateButtons(); context_menu -> clear(); + QString dir_path = elements_panel -> dirPathForItem(item); + if (!dir_path.isEmpty()) { + context_menu -> addAction(open_directory); + context_menu -> addAction(copy_path); + context_menu -> addSeparator(); + } + switch(item -> type()) { case QET::ElementsCategory: context_menu -> addAction(new_category); diff --git a/sources/elementspanelwidget.h b/sources/elementspanelwidget.h index d37fb0772..a6eef6a0f 100644 --- a/sources/elementspanelwidget.h +++ b/sources/elementspanelwidget.h @@ -39,6 +39,7 @@ class ElementsPanelWidget : public QWidget { private: ElementsPanel *elements_panel; QToolBar *toolbar, *filter_toolbar; + QAction *open_directory, *copy_path; QAction *reload; QAction *new_category, *edit_category, *delete_category; QAction *delete_collection; @@ -69,6 +70,8 @@ class ElementsPanelWidget : public QWidget { public slots: void clearFilterTextField(); + void openDirectoryForSelectedItem(); + void copyPathForSelectedItem(); void reloadAndFilter(); void activateProject(); void closeProject();