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
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -143,7 +143,7 @@ void ItemLibraryView::modelAttached(Model *model)
|
||||
model->attachView(m_importManagerView);
|
||||
m_hasErrors = !rewriterView()->errors().isEmpty();
|
||||
m_widget->setFlowMode(QmlItemNode(rootModelNode()).isFlowView());
|
||||
setResourcePath(QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->fileName().toFileInfo().absolutePath());
|
||||
setResourcePath(DocumentManager::currentResourcePath().toFileInfo().absoluteFilePath());
|
||||
}
|
||||
|
||||
void ItemLibraryView::modelAboutToBeDetached(Model *model)
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include <model.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <documentmanager.h>
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QDirIterator>
|
||||
@@ -53,8 +54,12 @@ void FileResourcesModel::setModelNodeBackend(const QVariant &modelNodeBackend)
|
||||
const auto backendObjectCasted =
|
||||
qobject_cast<const QmlDesigner::QmlModelNodeProxy *>(modelNodeBackendObject);
|
||||
|
||||
if (backendObjectCasted)
|
||||
m_path = backendObjectCasted->qmlObjectNode().modelNode().model()->fileUrl();
|
||||
if (backendObjectCasted) {
|
||||
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();
|
||||
emit modelNodeBackendChanged();
|
||||
@@ -91,9 +96,9 @@ QUrl FileResourcesModel::path() const
|
||||
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)
|
||||
@@ -121,28 +126,24 @@ QStringList FileResourcesModel::fileNameModel() const
|
||||
|
||||
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;
|
||||
|
||||
//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 that one is not valid we try the path for the current file
|
||||
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))
|
||||
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))
|
||||
path = modelPath;
|
||||
path = resourcePath;
|
||||
|
||||
QString newFile = QFileDialog::getOpenFileName(Core::ICore::dialogParent(),
|
||||
tr("Open File"),
|
||||
@@ -151,7 +152,6 @@ void FileResourcesModel::openFileDialog()
|
||||
|
||||
if (!newFile.isEmpty()) {
|
||||
setFileNameStr(newFile);
|
||||
|
||||
m_currentPath = QFileInfo(newFile).absolutePath();
|
||||
s_lastBrowserPath = m_currentPath;
|
||||
}
|
||||
@@ -194,7 +194,7 @@ bool filterMetaIcons(const QString &fileName)
|
||||
|
||||
void FileResourcesModel::setupModel()
|
||||
{
|
||||
m_dirPath = QFileInfo(m_path.toLocalFile()).dir();
|
||||
m_dirPath = QDir(m_path.toLocalFile());
|
||||
|
||||
refreshModel();
|
||||
|
||||
@@ -214,7 +214,7 @@ void FileResourcesModel::refreshModel()
|
||||
while (it.hasNext()) {
|
||||
QString absolutePath = it.next();
|
||||
if (filterMetaIcons(absolutePath)) {
|
||||
QString filePath = m_dirPath.relativeFilePath(absolutePath);
|
||||
QString filePath = m_docPath.relativeFilePath(absolutePath);
|
||||
m_fullPathModel.append(filePath);
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ class FileResourcesModel : public QObject
|
||||
Q_PROPERTY(QString filter READ filter WRITE setFilter)
|
||||
Q_PROPERTY(QVariant modelNodeBackendProperty READ modelNodeBackend WRITE setModelNodeBackend NOTIFY modelNodeBackendChanged)
|
||||
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 fileNameModel READ fileNameModel NOTIFY fileNameModelChanged)
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
void setFileNameStr(const QString &fileName);
|
||||
void setPath(const QUrl &url);
|
||||
QUrl path() const;
|
||||
QUrl dirPath() const;
|
||||
QUrl docPath() const;
|
||||
void setFilter(const QString &filter);
|
||||
QString filter() const;
|
||||
QStringList fullPathModel() const;
|
||||
@@ -81,9 +81,10 @@ private:
|
||||
QUrl m_fileName;
|
||||
QUrl m_path;
|
||||
QDir m_dirPath;
|
||||
QDir m_docPath;
|
||||
QString m_filter;
|
||||
QString m_currentPath;
|
||||
QString m_lastModelPath;
|
||||
QString m_lastResourcePath;
|
||||
QStringList m_fullPathModel;
|
||||
QStringList m_fileNameModel;
|
||||
Utils::FileSystemWatcher *m_fileSystemWatcher;
|
||||
|
@@ -495,5 +495,12 @@ bool DocumentManager::belongsToQmakeProject()
|
||||
return proNode;
|
||||
}
|
||||
|
||||
Utils::FilePath DocumentManager::currentResourcePath()
|
||||
{
|
||||
Utils::FilePath resourcePath = currentProjectDirPath();
|
||||
if (resourcePath.isEmpty())
|
||||
return currentFilePath().absolutePath();
|
||||
return resourcePath;
|
||||
}
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
@@ -65,6 +65,7 @@ public:
|
||||
static bool isoProFileSupportsAddingExistingFiles(const QString &resourceFileProPath);
|
||||
static bool addResourceFileToIsoProject(const QString &resourceFileProPath, const QString &resourceFilePath);
|
||||
static bool belongsToQmakeProject();
|
||||
static Utils::FilePath currentResourcePath();
|
||||
|
||||
private:
|
||||
QHash<Core::IEditor *,QPointer<DesignDocument> > m_designDocumentHash;
|
||||
|
Reference in New Issue
Block a user