r22702 by jghali - #15426: Pasting path into file dialog and hitting return stopped working

scribus-commit scribus-commit at lists.scribus.net
Wed Sep 19 21:27:15 UTC 2018


Author: jghali
Date: Wed Sep 19 21:27:15 2018
New Revision: 22702

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22702
Log:
#15426: Pasting path into file dialog and hitting return stopped working

Modified:
    trunk/Scribus/scribus/ui/customfdialog.cpp
    trunk/Scribus/scribus/ui/scfilewidget.cpp
    trunk/Scribus/scribus/ui/scfilewidget.h

Modified: trunk/Scribus/scribus/ui/customfdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22702&path=/trunk/Scribus/scribus/ui/customfdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/customfdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/customfdialog.cpp	Wed Sep 19 21:27:15 2018
@@ -362,6 +362,7 @@
 		Layout1C->addItem( spacer2 );
 		vboxLayout->addWidget(LayoutC);
 		fileDialog->setFileMode(QFileDialog::DirectoryOnly);
+		fileDialog->forceDoubleClickActivation(false);
 		filePreview->hide();
 		showPreview->setVisible(false);
 		showPreview->setChecked(false);
@@ -482,6 +483,7 @@
 		if (flags & fdCompressFile)
 			connect(saveZip, SIGNAL(clicked()), this, SLOT(handleCompress()));
 	}
+	fileDialog->forceDoubleClickActivation(m_previewIsShown);
 	fileDialog->setNameFilterDetailsVisible(false);
 	m_extZip = "gz";
 	connect(okButton, SIGNAL(clicked()), this, SLOT(okClicked()));
@@ -518,6 +520,7 @@
 void CustomFDialog::togglePreview()
 {
 	m_previewIsShown = !m_previewIsShown;
+	fileDialog->forceDoubleClickActivation(m_previewIsShown);
 	filePreview->setVisible(m_previewIsShown);
 	if (m_previewIsShown)
 	{

Modified: trunk/Scribus/scribus/ui/scfilewidget.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22702&path=/trunk/Scribus/scribus/ui/scfilewidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/scfilewidget.cpp	(original)
+++ trunk/Scribus/scribus/ui/scfilewidget.cpp	Wed Sep 19 21:27:15 2018
@@ -5,8 +5,11 @@
 for which a new license (GPL+exception) is in place.
 */
 
+#include <cstdlib>
+
 #include <QDebug>
 #include <QStandardPaths>
+#include <QLineEdit>
 #include <QListView>
 #include <QPushButton>
 #include <QStringList>
@@ -18,6 +21,8 @@
 
 ScFileWidget::ScFileWidget(QWidget * parent) : QFileDialog(parent, Qt::Widget)
 {
+	m_forceDoubleClickActivation = false;
+
 	setOption(QFileDialog::DontUseNativeDialog);
 	setSizeGripEnabled(false);
 	setModal(false);
@@ -58,6 +63,21 @@
 	setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
 }
 
+void ScFileWidget::forceDoubleClickActivation(bool force)
+{
+	// Hack to make the previews in our file dialogs useable again,
+	// needed e.g on OpenSuse KDE. Otherwise file would open on first
+	// click, leaving user no time to see preview.
+	if (m_forceDoubleClickActivation == force)
+		return;
+
+	if (force)
+		setStyleSheet(QStringLiteral("QAbstractItemView { activate-on-singleclick: 0; }"));
+	else
+		setStyleSheet(QString());
+	m_forceDoubleClickActivation = force;
+}
+
 QString ScFileWidget::selectedFile()
 {
 	QStringList l(selectedFiles());
@@ -66,28 +86,20 @@
 	return l.at(0);
 }
 
-/* Hack to make the previews in our file dialogs useable again,
-   needed e.g on OpenSuse KDE. Otherwise file would open on first
-   click, leaving user no time to see preview. Drawback: in other 
-   Linux desktop environment, this may force user to click OK for
-   opening/saving file. */
-void ScFileWidget::accept()
-{
-#ifndef Q_OS_LINUX
-	QFileDialog::accept();
-#endif
-}
-
 void ScFileWidget::locationDropped(const QString& fileUrl)
 {
 	QFileInfo fi(fileUrl);
 	if (fi.isDir())
+	{
 		setDirectory(fi.absoluteFilePath());
-	else
-	{
-		setDirectory(fi.absolutePath());
-		selectFile(fi.fileName());
+		return;
 	}
+
+	QString absFilePath = fi.absolutePath();
+	QString fileName = fi.fileName();
+		
+	setDirectory(absFilePath);
+	selectFile(fileName);
 }
 
 void ScFileWidget::gotoParentDirectory()

Modified: trunk/Scribus/scribus/ui/scfilewidget.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22702&path=/trunk/Scribus/scribus/ui/scfilewidget.h
==============================================================================
--- trunk/Scribus/scribus/ui/scfilewidget.h	(original)
+++ trunk/Scribus/scribus/ui/scfilewidget.h	Wed Sep 19 21:27:15 2018
@@ -30,14 +30,17 @@
 	ScFileWidget(QWidget * parent);
 
 	QString selectedFile();
+	void forceDoubleClickActivation(bool force);
 
 public slots:
-	void accept();
 	void locationDropped(const QString& fileUrl);
 	void gotoParentDirectory();
 	void gotoSelectedDirectory();
 	void gotoDesktopDirectory();
 	void gotoHomeDirectory();
+
+private:
+	bool m_forceDoubleClickActivation;
 };
 
 #endif




More information about the scribus-commit mailing list