ui: Filepicker fixes
* don't reset filepath used to open file picker dialog for SaveFileDialog * don't reset filepath used to open filepicker for OpenProject dialog * fixed non-native file picker starts in wrong directory if provided with filename to open (instead of directory) * fixed non-native dialog displays machines root directory if empty path is provided
This commit is contained in:
@@ -107,7 +107,7 @@ void QtListItemWidget::handleButtonPress()
|
|||||||
path = relativeRoot.getConcatenated(path);
|
path = relativeRoot.getConcatenated(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList list = QtFileDialog::getFileNamesAndDirectories(this, QString::fromStdString(path.str()));
|
QStringList list = QtFileDialog::getFileNamesAndDirectories(this, path);
|
||||||
if (!list.isEmpty())
|
if (!list.isEmpty())
|
||||||
{
|
{
|
||||||
setText(list.at(0));
|
setText(list.at(0));
|
||||||
|
|||||||
@@ -108,11 +108,11 @@ void QtLocationPicker::handleButtonPress()
|
|||||||
QString fileName;
|
QString fileName;
|
||||||
if (m_pickDirectory)
|
if (m_pickDirectory)
|
||||||
{
|
{
|
||||||
fileName = QtFileDialog::getExistingDirectory(this, tr("Select Directory"), QString::fromStdString(path.str()));
|
fileName = QtFileDialog::getExistingDirectory(this, tr("Select Directory"), path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fileName = QtFileDialog::getOpenFileName(this, tr("Open File"), QString::fromStdString(path.str()), m_fileFilter);
|
fileName = QtFileDialog::getOpenFileName(this, tr("Open File"), path, m_fileFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ void QtGraphicsView::stopTimer()
|
|||||||
void QtGraphicsView::exportGraph()
|
void QtGraphicsView::exportGraph()
|
||||||
{
|
{
|
||||||
QString fileName = QtFileDialog::showSaveFileDialog(
|
QString fileName = QtFileDialog::showSaveFileDialog(
|
||||||
nullptr, "Save image", QDir::homePath(), "PNG (*.png);;JPEG (*.JPEG);;BMP Files (*.bmp)");
|
nullptr, "Save image", FilePath(), "PNG (*.png);;JPEG (*.JPEG);;BMP Files (*.bmp)");
|
||||||
|
|
||||||
if (!fileName.isNull())
|
if (!fileName.isNull())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,13 +5,19 @@
|
|||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
#include "qt/utility/QtFilesAndDirectoriesDialog.h"
|
#include "qt/utility/QtFilesAndDirectoriesDialog.h"
|
||||||
|
#include "utility/file/FilePath.h"
|
||||||
#include "utility/utilityApp.h"
|
#include "utility/utilityApp.h"
|
||||||
|
|
||||||
QStringList QtFileDialog::getFileNamesAndDirectories(QWidget* parent, const QString& dir)
|
QStringList QtFileDialog::getFileNamesAndDirectories(QWidget* parent, const FilePath& path)
|
||||||
{
|
{
|
||||||
|
const QString dir = getDir(QString::fromStdString((path.isDirectory() ? path : path.getParentDirectory()).str()));
|
||||||
|
|
||||||
QFileDialog* dialog = (utility::getOsType() == OS_MAC ? new QFileDialog(parent) : new QtFilesAndDirectoriesDialog(parent));
|
QFileDialog* dialog = (utility::getOsType() == OS_MAC ? new QFileDialog(parent) : new QtFilesAndDirectoriesDialog(parent));
|
||||||
|
|
||||||
dialog->setDirectory(getDir(dir));
|
if (!dir.isEmpty())
|
||||||
|
{
|
||||||
|
dialog->setDirectory(dir);
|
||||||
|
}
|
||||||
|
|
||||||
QListView *l = dialog->findChild<QListView*>("listView");
|
QListView *l = dialog->findChild<QListView*>("listView");
|
||||||
if (l)
|
if (l)
|
||||||
@@ -35,25 +41,25 @@ QStringList QtFileDialog::getFileNamesAndDirectories(QWidget* parent, const QStr
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QtFileDialog::getExistingDirectory(QWidget* parent, const QString& caption, const QString& dir)
|
QString QtFileDialog::getExistingDirectory(QWidget* parent, const QString& caption, const FilePath& dir)
|
||||||
{
|
{
|
||||||
return QFileDialog::getExistingDirectory(parent, caption, getDir(dir));
|
return QFileDialog::getExistingDirectory(parent, caption, getDir(QString::fromStdString(dir.str())));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QtFileDialog::getOpenFileName(QWidget* parent, const QString& caption, const QString& dir, const QString& filter)
|
QString QtFileDialog::getOpenFileName(QWidget* parent, const QString& caption, const FilePath& dir, const QString& filter)
|
||||||
{
|
{
|
||||||
return QFileDialog::getOpenFileName(parent, caption, getDir(dir), filter);
|
return QFileDialog::getOpenFileName(parent, caption, getDir(QString::fromStdString(dir.str())), filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QtFileDialog::showSaveFileDialog(
|
QString QtFileDialog::showSaveFileDialog(
|
||||||
QWidget *parent, const QString& title, const QString& directory, const QString& filter)
|
QWidget *parent, const QString& title, const FilePath& directory, const QString& filter)
|
||||||
{
|
{
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
#if defined(Q_OS_WIN) || defined(Q_OS_MAC)
|
||||||
|
|
||||||
return QFileDialog::getSaveFileName(parent, title, directory, filter);
|
return QFileDialog::getSaveFileName(parent, title, getDir(QString::fromStdString(directory.str())), filter);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
QFileDialog dialog(parent, title, directory, filter);
|
QFileDialog dialog(parent, title, getDir(QString::fromStdString(directory.str())), filter);
|
||||||
|
|
||||||
if (parent)
|
if (parent)
|
||||||
{
|
{
|
||||||
@@ -96,7 +102,7 @@ QString QtFileDialog::getDir(QString dir)
|
|||||||
{
|
{
|
||||||
static bool used = false;
|
static bool used = false;
|
||||||
|
|
||||||
if (!used && !dir.size())
|
if (!used && dir.isEmpty())
|
||||||
{
|
{
|
||||||
dir = QDir::homePath();
|
dir = QDir::homePath();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef QT_FILE_DIALOG_H
|
#ifndef QT_FILE_DIALOG_H
|
||||||
#define QT_FILE_DIALOG_H
|
#define QT_FILE_DIALOG_H
|
||||||
|
|
||||||
|
class FilePath;
|
||||||
class QString;
|
class QString;
|
||||||
class QStringList;
|
class QStringList;
|
||||||
class QWidget;
|
class QWidget;
|
||||||
@@ -8,13 +9,13 @@ class QWidget;
|
|||||||
class QtFileDialog
|
class QtFileDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static QStringList getFileNamesAndDirectories(QWidget* parent, const QString& dir);
|
static QStringList getFileNamesAndDirectories(QWidget* parent, const FilePath& path);
|
||||||
|
|
||||||
static QString getExistingDirectory(QWidget* parent, const QString& caption, const QString& dir);
|
static QString getExistingDirectory(QWidget* parent, const QString& caption, const FilePath& dir);
|
||||||
static QString getOpenFileName(QWidget* parent, const QString& caption, const QString& dir, const QString& filter);
|
static QString getOpenFileName(QWidget* parent, const QString& caption, const FilePath& dir, const QString& filter);
|
||||||
|
|
||||||
static QString showSaveFileDialog(
|
static QString showSaveFileDialog(
|
||||||
QWidget *parent, const QString& title, const QString& directory, const QString& filter);
|
QWidget *parent, const QString& title, const FilePath& directory, const QString& filter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QString getDir(QString dir);
|
static QString getDir(QString dir);
|
||||||
|
|||||||
@@ -585,7 +585,7 @@ void QtMainWindow::newProjectFromCDB(const std::string& filePath, const std::vec
|
|||||||
void QtMainWindow::openProject()
|
void QtMainWindow::openProject()
|
||||||
{
|
{
|
||||||
QString fileName = QtFileDialog::getOpenFileName(
|
QString fileName = QtFileDialog::getOpenFileName(
|
||||||
this, tr("Open File"), QDir::homePath(), "Sourcetrail Project Files (*.srctrlprj *.coatiproject)");
|
this, tr("Open File"), FilePath(), "Sourcetrail Project Files (*.srctrlprj *.coatiproject)");
|
||||||
|
|
||||||
if (!fileName.isEmpty())
|
if (!fileName.isEmpty())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user