forked from qt-creator/qt-creator
QmlDesigner: Allow using assets from entire project in subfolders
If editing a subcomponent qml, assets tab now lists assets from the entire project, and url/font choosers list appropriate resources from entire project with correct relative paths. Fixes: QDS-3638 Change-Id: I4a066c30d1bd696e8edbd17754bb9df2b7880873 Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -60,7 +60,7 @@ StudioControls.ComboBox {
|
|||||||
var familyNames = ["Arial", "Times New Roman", "Courier", "Verdana", "Tahoma"] // default fonts
|
var familyNames = ["Arial", "Times New Roman", "Courier", "Verdana", "Tahoma"] // default fonts
|
||||||
|
|
||||||
for (var i = 0; i < fileModel.fullPathModel.length; ++i) { // add custom fonts
|
for (var i = 0; i < fileModel.fullPathModel.length; ++i) { // add custom fonts
|
||||||
var fontLoader = createFontLoader(fileModel.dirPath + "/" + fileModel.fullPathModel[i]);
|
var fontLoader = createFontLoader(fileModel.docPath + "/" + fileModel.fullPathModel[i]);
|
||||||
familyNames.push(fontLoader.name);
|
familyNames.push(fontLoader.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -143,7 +143,7 @@ void ItemLibraryView::modelAttached(Model *model)
|
|||||||
model->attachView(m_importManagerView);
|
model->attachView(m_importManagerView);
|
||||||
m_hasErrors = !rewriterView()->errors().isEmpty();
|
m_hasErrors = !rewriterView()->errors().isEmpty();
|
||||||
m_widget->setFlowMode(QmlItemNode(rootModelNode()).isFlowView());
|
m_widget->setFlowMode(QmlItemNode(rootModelNode()).isFlowView());
|
||||||
setResourcePath(QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->fileName().toFileInfo().absolutePath());
|
setResourcePath(DocumentManager::currentResourcePath().toFileInfo().absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemLibraryView::modelAboutToBeDetached(Model *model)
|
void ItemLibraryView::modelAboutToBeDetached(Model *model)
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <model.h>
|
#include <model.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <documentmanager.h>
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
@@ -53,8 +54,12 @@ void FileResourcesModel::setModelNodeBackend(const QVariant &modelNodeBackend)
|
|||||||
const auto backendObjectCasted =
|
const auto backendObjectCasted =
|
||||||
qobject_cast<const QmlDesigner::QmlModelNodeProxy *>(modelNodeBackendObject);
|
qobject_cast<const QmlDesigner::QmlModelNodeProxy *>(modelNodeBackendObject);
|
||||||
|
|
||||||
if (backendObjectCasted)
|
if (backendObjectCasted) {
|
||||||
m_path = backendObjectCasted->qmlObjectNode().modelNode().model()->fileUrl();
|
QmlDesigner::Model *model = backendObjectCasted->qmlObjectNode().modelNode().model();
|
||||||
|
m_docPath = QDir{QFileInfo{model->fileUrl().toLocalFile()}.absolutePath()};
|
||||||
|
m_path = QUrl::fromLocalFile(QmlDesigner::DocumentManager::currentResourcePath()
|
||||||
|
.toFileInfo().absoluteFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
setupModel();
|
setupModel();
|
||||||
emit modelNodeBackendChanged();
|
emit modelNodeBackendChanged();
|
||||||
@@ -91,9 +96,9 @@ QUrl FileResourcesModel::path() const
|
|||||||
return m_path;
|
return m_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl FileResourcesModel::dirPath() const
|
QUrl FileResourcesModel::docPath() const
|
||||||
{
|
{
|
||||||
return QUrl::fromLocalFile(m_dirPath.path());
|
return QUrl::fromLocalFile(m_docPath.path());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileResourcesModel::setFilter(const QString &filter)
|
void FileResourcesModel::setFilter(const QString &filter)
|
||||||
@@ -121,28 +126,24 @@ QStringList FileResourcesModel::fileNameModel() const
|
|||||||
|
|
||||||
void FileResourcesModel::openFileDialog()
|
void FileResourcesModel::openFileDialog()
|
||||||
{
|
{
|
||||||
QString modelPath = m_path.toLocalFile();
|
QString resourcePath = m_path.toLocalFile();
|
||||||
|
bool resourcePathChanged = m_lastResourcePath != resourcePath;
|
||||||
|
m_lastResourcePath = resourcePath;
|
||||||
|
|
||||||
m_lastModelPath = modelPath;
|
// First we try the last path this browser widget was opened with within current project
|
||||||
|
QString path = resourcePathChanged ? QString() : m_currentPath;
|
||||||
|
|
||||||
bool documentChanged = m_lastModelPath == modelPath;
|
// If that one is not valid we try the path for the current file
|
||||||
|
|
||||||
//First we try the last path this browser widget was opened with if the document was not changed
|
|
||||||
QString path = documentChanged ? QString() : m_currentPath;
|
|
||||||
|
|
||||||
|
|
||||||
//If that one is not valid we try the path for the current file
|
|
||||||
if (path.isEmpty() && !m_fileName.isEmpty())
|
if (path.isEmpty() && !m_fileName.isEmpty())
|
||||||
path = QFileInfo(modelPath + '/' + m_fileName.toString()).absolutePath();
|
path = QFileInfo(m_fileName.toString()).absolutePath();
|
||||||
|
|
||||||
|
// Next we try to fall back to the path any file browser was opened with
|
||||||
//Next we try to fall back to the path any file browser was opened with
|
|
||||||
if (!QFileInfo::exists(path))
|
if (!QFileInfo::exists(path))
|
||||||
path = s_lastBrowserPath;
|
path = s_lastBrowserPath;
|
||||||
|
|
||||||
//The last fallback is to try the path of the document
|
// The last fallback is to try the resource path
|
||||||
if (!QFileInfo::exists(path))
|
if (!QFileInfo::exists(path))
|
||||||
path = modelPath;
|
path = resourcePath;
|
||||||
|
|
||||||
QString newFile = QFileDialog::getOpenFileName(Core::ICore::dialogParent(),
|
QString newFile = QFileDialog::getOpenFileName(Core::ICore::dialogParent(),
|
||||||
tr("Open File"),
|
tr("Open File"),
|
||||||
@@ -151,7 +152,6 @@ void FileResourcesModel::openFileDialog()
|
|||||||
|
|
||||||
if (!newFile.isEmpty()) {
|
if (!newFile.isEmpty()) {
|
||||||
setFileNameStr(newFile);
|
setFileNameStr(newFile);
|
||||||
|
|
||||||
m_currentPath = QFileInfo(newFile).absolutePath();
|
m_currentPath = QFileInfo(newFile).absolutePath();
|
||||||
s_lastBrowserPath = m_currentPath;
|
s_lastBrowserPath = m_currentPath;
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ bool filterMetaIcons(const QString &fileName)
|
|||||||
|
|
||||||
void FileResourcesModel::setupModel()
|
void FileResourcesModel::setupModel()
|
||||||
{
|
{
|
||||||
m_dirPath = QFileInfo(m_path.toLocalFile()).dir();
|
m_dirPath = QDir(m_path.toLocalFile());
|
||||||
|
|
||||||
refreshModel();
|
refreshModel();
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ void FileResourcesModel::refreshModel()
|
|||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
QString absolutePath = it.next();
|
QString absolutePath = it.next();
|
||||||
if (filterMetaIcons(absolutePath)) {
|
if (filterMetaIcons(absolutePath)) {
|
||||||
QString filePath = m_dirPath.relativeFilePath(absolutePath);
|
QString filePath = m_docPath.relativeFilePath(absolutePath);
|
||||||
m_fullPathModel.append(filePath);
|
m_fullPathModel.append(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ class FileResourcesModel : public QObject
|
|||||||
Q_PROPERTY(QString filter READ filter WRITE setFilter)
|
Q_PROPERTY(QString filter READ filter WRITE setFilter)
|
||||||
Q_PROPERTY(QVariant modelNodeBackendProperty READ modelNodeBackend WRITE setModelNodeBackend NOTIFY modelNodeBackendChanged)
|
Q_PROPERTY(QVariant modelNodeBackendProperty READ modelNodeBackend WRITE setModelNodeBackend NOTIFY modelNodeBackendChanged)
|
||||||
Q_PROPERTY(QUrl path READ path WRITE setPath)
|
Q_PROPERTY(QUrl path READ path WRITE setPath)
|
||||||
Q_PROPERTY(QUrl dirPath READ dirPath)
|
Q_PROPERTY(QUrl docPath READ docPath)
|
||||||
Q_PROPERTY(QStringList fullPathModel READ fullPathModel NOTIFY fullPathModelChanged)
|
Q_PROPERTY(QStringList fullPathModel READ fullPathModel NOTIFY fullPathModelChanged)
|
||||||
Q_PROPERTY(QStringList fileNameModel READ fileNameModel NOTIFY fileNameModelChanged)
|
Q_PROPERTY(QStringList fileNameModel READ fileNameModel NOTIFY fileNameModelChanged)
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ public:
|
|||||||
void setFileNameStr(const QString &fileName);
|
void setFileNameStr(const QString &fileName);
|
||||||
void setPath(const QUrl &url);
|
void setPath(const QUrl &url);
|
||||||
QUrl path() const;
|
QUrl path() const;
|
||||||
QUrl dirPath() const;
|
QUrl docPath() const;
|
||||||
void setFilter(const QString &filter);
|
void setFilter(const QString &filter);
|
||||||
QString filter() const;
|
QString filter() const;
|
||||||
QStringList fullPathModel() const;
|
QStringList fullPathModel() const;
|
||||||
@@ -81,9 +81,10 @@ private:
|
|||||||
QUrl m_fileName;
|
QUrl m_fileName;
|
||||||
QUrl m_path;
|
QUrl m_path;
|
||||||
QDir m_dirPath;
|
QDir m_dirPath;
|
||||||
|
QDir m_docPath;
|
||||||
QString m_filter;
|
QString m_filter;
|
||||||
QString m_currentPath;
|
QString m_currentPath;
|
||||||
QString m_lastModelPath;
|
QString m_lastResourcePath;
|
||||||
QStringList m_fullPathModel;
|
QStringList m_fullPathModel;
|
||||||
QStringList m_fileNameModel;
|
QStringList m_fileNameModel;
|
||||||
Utils::FileSystemWatcher *m_fileSystemWatcher;
|
Utils::FileSystemWatcher *m_fileSystemWatcher;
|
||||||
|
@@ -495,5 +495,12 @@ bool DocumentManager::belongsToQmakeProject()
|
|||||||
return proNode;
|
return proNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::FilePath DocumentManager::currentResourcePath()
|
||||||
|
{
|
||||||
|
Utils::FilePath resourcePath = currentProjectDirPath();
|
||||||
|
if (resourcePath.isEmpty())
|
||||||
|
return currentFilePath().absolutePath();
|
||||||
|
return resourcePath;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
@@ -65,6 +65,7 @@ public:
|
|||||||
static bool isoProFileSupportsAddingExistingFiles(const QString &resourceFileProPath);
|
static bool isoProFileSupportsAddingExistingFiles(const QString &resourceFileProPath);
|
||||||
static bool addResourceFileToIsoProject(const QString &resourceFileProPath, const QString &resourceFilePath);
|
static bool addResourceFileToIsoProject(const QString &resourceFileProPath, const QString &resourceFilePath);
|
||||||
static bool belongsToQmakeProject();
|
static bool belongsToQmakeProject();
|
||||||
|
static Utils::FilePath currentResourcePath();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<Core::IEditor *,QPointer<DesignDocument> > m_designDocumentHash;
|
QHash<Core::IEditor *,QPointer<DesignDocument> > m_designDocumentHash;
|
||||||
|
Reference in New Issue
Block a user