r19180 by craig - #4012: Add standard OSX shortcuts to file dialogs.. cmd d for desktop, cmd up for parent dir, cmd down for selected dir, cmd shift h for home dir. control key on other OSes

scribus-commit scribus-commit at lists.scribus.net
Wed Jun 4 22:10:46 UTC 2014


Author: craig
Date: Wed Jun  4 22:10:46 2014
New Revision: 19180

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19180
Log:
#4012: Add standard OSX shortcuts to file dialogs.. cmd d for desktop, cmd up for parent dir, cmd down for selected dir, cmd shift h for home dir. control key on other OSes

Modified:
    trunk/Scribus/scribus/ui/filedialogeventcatcher.cpp
    trunk/Scribus/scribus/ui/filedialogeventcatcher.h
    trunk/Scribus/scribus/ui/newfile.cpp
    trunk/Scribus/scribus/ui/newfile.h
    trunk/Scribus/scribus/ui/scfilewidget.cpp
    trunk/Scribus/scribus/ui/scfilewidget.h

Modified: trunk/Scribus/scribus/ui/filedialogeventcatcher.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19180&path=/trunk/Scribus/scribus/ui/filedialogeventcatcher.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/filedialogeventcatcher.cpp (original)
+++ trunk/Scribus/scribus/ui/filedialogeventcatcher.cpp Wed Jun  4 22:10:46 2014
@@ -22,10 +22,39 @@
 	if (e->type() == QEvent::KeyPress)
 	{
 		QKeyEvent *keyEvent = static_cast<QKeyEvent *>(e);
-		if (keyEvent->key() == Qt::Key_Escape)
+		switch (keyEvent->key())
 		{
-			emit escapePressed();
-			return true;
+			case Qt::Key_Escape:
+				emit escapePressed();
+				return true;
+			case Qt::Key_D:
+				if (keyEvent->modifiers() & Qt::ControlModifier)
+				{
+					emit desktopPressed();
+					return true;
+				}
+				break;
+			case Qt::Key_H:
+				if (keyEvent->modifiers() & (Qt::ControlModifier|Qt::ShiftModifier))
+				{
+					emit homePressed();
+					return true;
+				}
+				break;
+			case Qt::Key_Up:
+				if (keyEvent->modifiers() & Qt::ControlModifier)
+				{
+					emit parentPressed();
+					return true;
+				}
+				break;
+			case Qt::Key_Down:
+				if (keyEvent->modifiers() & Qt::ControlModifier)
+				{
+					emit enterSelectedPressed();
+					return true;
+				}
+				break;
 		}
 	}
 	else

Modified: trunk/Scribus/scribus/ui/filedialogeventcatcher.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19180&path=/trunk/Scribus/scribus/ui/filedialogeventcatcher.h
==============================================================================
--- trunk/Scribus/scribus/ui/filedialogeventcatcher.h (original)
+++ trunk/Scribus/scribus/ui/filedialogeventcatcher.h Wed Jun  4 22:10:46 2014
@@ -24,6 +24,10 @@
 signals:
 	void escapePressed();
 	void dropLocation(QString dl);
+	void desktopPressed();
+	void homePressed();
+	void parentPressed();
+	void enterSelectedPressed();
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/newfile.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19180&path=/trunk/Scribus/scribus/ui/newfile.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/newfile.cpp (original)
+++ trunk/Scribus/scribus/ui/newfile.cpp Wed Jun  4 22:10:46 2014
@@ -23,6 +23,8 @@
 #include <QPushButton>
 #include <QSpacerItem>
 #include <QSpinBox>
+#include <QStandardPaths>
+#include <QStringList>
 #include <QTabWidget>
 #include <QToolTip>
 
@@ -385,6 +387,10 @@
 		lvi.next()->installEventFilter(keyCatcher);
 	connect(keyCatcher, SIGNAL(escapePressed()), this, SLOT(reject()));
 	connect(keyCatcher, SIGNAL(dropLocation(QString)), this, SLOT(locationDropped(QString)));
+	connect(keyCatcher, SIGNAL(desktopPressed()), this, SLOT(gotoDesktopDirectory()));
+	connect(keyCatcher, SIGNAL(homePressed()), this, SLOT(gotoHomeDirectory()));
+	connect(keyCatcher, SIGNAL(parentPressed()), this, SLOT(gotoParentDirectory()));
+	connect(keyCatcher, SIGNAL(enterSelectedPressed()), this, SLOT(gotoSelectedDirectory()));
 	connect(fileDialog, SIGNAL(filesSelected(const QStringList &)), this, SLOT(openFile()));
 	connect(fileDialog, SIGNAL(rejected()), this, SLOT(reject()));
 }
@@ -704,3 +710,39 @@
 	}
 }
 
+void NewDoc::gotoParentDirectory()
+{
+	QDir d(fileDialog->directory());
+	d.cdUp();
+	fileDialog->setDirectory(d);
+}
+
+
+void NewDoc::gotoSelectedDirectory()
+{
+	QStringList s(fileDialog->selectedFiles());
+	if (s.count()>0)
+	{
+		QFileInfo fi(s.first());
+		qDebug()<<s.first()<<fi.absoluteFilePath();
+		if (fi.isDir())
+			fileDialog->setDirectory(fi.absoluteFilePath());
+	}
+}
+
+void NewDoc::gotoDesktopDirectory()
+{
+	QString dp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+	QFileInfo fi(dp);
+	if (fi.exists())
+		fileDialog->setDirectory(dp);
+}
+
+
+void NewDoc::gotoHomeDirectory()
+{
+	QString dp=QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+	QFileInfo fi(dp);
+	if (fi.exists())
+		fileDialog->setDirectory(dp);
+}

Modified: trunk/Scribus/scribus/ui/newfile.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19180&path=/trunk/Scribus/scribus/ui/newfile.h
==============================================================================
--- trunk/Scribus/scribus/ui/newfile.h (original)
+++ trunk/Scribus/scribus/ui/newfile.h Wed Jun  4 22:10:46 2014
@@ -146,6 +146,10 @@
 	void openFile();
 	void adjustTitles(int tab);
 	void locationDropped(QString fileUrl);
+	void gotoParentDirectory();
+	void gotoSelectedDirectory();
+	void gotoDesktopDirectory();
+	void gotoHomeDirectory();
 
 protected:
 	QVBoxLayout* TabbedNewDocLayout;

Modified: trunk/Scribus/scribus/ui/scfilewidget.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19180&path=/trunk/Scribus/scribus/ui/scfilewidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/scfilewidget.cpp (original)
+++ trunk/Scribus/scribus/ui/scfilewidget.cpp Wed Jun  4 22:10:46 2014
@@ -5,9 +5,11 @@
 for which a new license (GPL+exception) is in place.
 */
 
-#include <QDesktopServices>
+#include <QDebug>
+#include <QStandardPaths>
 #include <QListView>
 #include <QPushButton>
+#include <QStringList>
 #include <QUrl>
 
 #include "filedialogeventcatcher.h"
@@ -30,7 +32,9 @@
 	QUrl volumes(QUrl::fromLocalFile("/Volumes"));
 	if (!urls.contains(volumes))
 		urls << volumes;
-	//desktop too?	QUrl computer(QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation)));
+	QUrl dt(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation)));
+	if (!urls.contains(dt))
+		urls << dt;
 	setSidebarUrls(urls);
 #endif
 
@@ -41,6 +45,10 @@
 		lvi.next()->installEventFilter(keyCatcher);
 	connect(keyCatcher, SIGNAL(escapePressed()), this, SLOT(reject()));
 	connect(keyCatcher, SIGNAL(dropLocation(QString)), this, SLOT(locationDropped(QString)));
+	connect(keyCatcher, SIGNAL(desktopPressed()), this, SLOT(gotoDesktopDirectory()));
+	connect(keyCatcher, SIGNAL(homePressed()), this, SLOT(gotoHomeDirectory()));
+	connect(keyCatcher, SIGNAL(parentPressed()), this, SLOT(gotoParentDirectory()));
+	connect(keyCatcher, SIGNAL(enterSelectedPressed()), this, SLOT(gotoSelectedDirectory()));
 
 	QList<QPushButton *> b = findChildren<QPushButton *>();
 	QListIterator<QPushButton *> i(b);
@@ -78,3 +86,39 @@
 		selectFile(fi.fileName());
 	}
 }
+
+void ScFileWidget::gotoParentDirectory()
+{
+	QDir d(directory());
+	d.cdUp();
+	setDirectory(d);
+}
+
+void ScFileWidget::gotoSelectedDirectory()
+{
+	QStringList s(selectedFiles());
+	if (s.count()>0)
+	{
+		QFileInfo fi(s.first());
+		qDebug()<<s.first()<<fi.absoluteFilePath();
+		if (fi.isDir())
+			setDirectory(fi.absoluteFilePath());
+	}
+}
+
+void ScFileWidget::gotoDesktopDirectory()
+{
+	QString dp=QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+	QFileInfo fi(dp);
+	if (fi.exists())
+		setDirectory(dp);
+}
+
+void ScFileWidget::gotoHomeDirectory()
+{
+	QString dp=QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
+	QFileInfo fi(dp);
+	if (fi.exists())
+		setDirectory(dp);
+}
+

Modified: trunk/Scribus/scribus/ui/scfilewidget.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19180&path=/trunk/Scribus/scribus/ui/scfilewidget.h
==============================================================================
--- trunk/Scribus/scribus/ui/scfilewidget.h (original)
+++ trunk/Scribus/scribus/ui/scfilewidget.h Wed Jun  4 22:10:46 2014
@@ -34,6 +34,10 @@
 public slots:
 	void accept();
 	void locationDropped(QString fileUrl);
+	void gotoParentDirectory();
+	void gotoSelectedDirectory();
+	void gotoDesktopDirectory();
+	void gotoHomeDirectory();
 };
 
 #endif




More information about the scribus-commit mailing list