[qet] [2023] Elements panel: added contextual actions so users can easily find elements, title block templates and projects on their filesystem.

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 2023
Author:   xavier
Date:     2013-02-03 20:25:02 +0100 (Sun, 03 Feb 2013)
Log Message:
-----------
Elements panel: added contextual actions so users can easily find elements, title block templates and projects on their filesystem.

Modified Paths:
--------------
    trunk/sources/elementspanelwidget.cpp
    trunk/sources/elementspanelwidget.h

Modified: trunk/sources/elementspanelwidget.cpp
===================================================================
--- trunk/sources/elementspanelwidget.cpp	2013-02-03 19:22:58 UTC (rev 2022)
+++ trunk/sources/elementspanelwidget.cpp	2013-02-03 19:25:02 UTC (rev 2023)
@@ -53,6 +53,8 @@
 	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 @@
 	
 	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()));
@@ -190,6 +194,33 @@
 }
 
 /**
+	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
 */
 void ElementsPanelWidget::reloadAndFilter() {
@@ -468,6 +499,13 @@
 	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);

Modified: trunk/sources/elementspanelwidget.h
===================================================================
--- trunk/sources/elementspanelwidget.h	2013-02-03 19:22:58 UTC (rev 2022)
+++ trunk/sources/elementspanelwidget.h	2013-02-03 19:25:02 UTC (rev 2023)
@@ -39,6 +39,7 @@
 	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 @@
 	
 	public slots:
 	void clearFilterTextField();
+	void openDirectoryForSelectedItem();
+	void copyPathForSelectedItem();
 	void reloadAndFilter();
 	void activateProject();
 	void closeProject();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/