forked from qt-creator/qt-creator
Add lacking qrc files into the project
Task-number: QTCREATORBUG-9610 Change-Id: I3f98ce154e05f419ea8a3c45a18eb9df51b5cfa2 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
@@ -111,7 +111,7 @@ bool FormWindowEditor::open(QString *errorString, const QString &fileName, const
|
|||||||
d->m_widget->formWindowFile()->setShouldAutoSave(false);
|
d->m_widget->formWindowFile()->setShouldAutoSave(false);
|
||||||
|
|
||||||
if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>())
|
if (Internal::ResourceHandler *rh = form->findChild<Designer::Internal::ResourceHandler*>())
|
||||||
rh->updateResources();
|
rh->updateResources(true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,8 @@ ResourceHandler::ResourceHandler(qdesigner_internal::FormWindowBase *fw) :
|
|||||||
QObject(fw),
|
QObject(fw),
|
||||||
m_form(fw),
|
m_form(fw),
|
||||||
m_sessionNode(0),
|
m_sessionNode(0),
|
||||||
m_sessionWatcher(0)
|
m_sessionWatcher(0),
|
||||||
|
m_handlingResources(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,8 +125,11 @@ ResourceHandler::~ResourceHandler()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceHandler::updateResources()
|
void ResourceHandler::updateResources(bool updateProjectResources)
|
||||||
{
|
{
|
||||||
|
if (m_handlingResources)
|
||||||
|
return;
|
||||||
|
|
||||||
ensureInitialized();
|
ensureInitialized();
|
||||||
|
|
||||||
const QString fileName = m_form->fileName();
|
const QString fileName = m_form->fileName();
|
||||||
@@ -136,6 +140,9 @@ void ResourceHandler::updateResources()
|
|||||||
|
|
||||||
// Filename could change in the meantime.
|
// Filename could change in the meantime.
|
||||||
Project *project = SessionManager::projectForFile(fileName);
|
Project *project = SessionManager::projectForFile(fileName);
|
||||||
|
const bool dirty = m_form->property("_q_resourcepathchanged").toBool();
|
||||||
|
if (dirty)
|
||||||
|
m_form->setDirty(true);
|
||||||
|
|
||||||
// Does the file belong to a project?
|
// Does the file belong to a project?
|
||||||
if (project) {
|
if (project) {
|
||||||
@@ -143,7 +150,29 @@ void ResourceHandler::updateResources()
|
|||||||
ProjectNode *root = project->rootProjectNode();
|
ProjectNode *root = project->rootProjectNode();
|
||||||
QrcFilesVisitor qrcVisitor;
|
QrcFilesVisitor qrcVisitor;
|
||||||
root->accept(&qrcVisitor);
|
root->accept(&qrcVisitor);
|
||||||
const QStringList projectQrcFiles = qrcVisitor.qrcFiles();
|
QStringList projectQrcFiles = qrcVisitor.qrcFiles();
|
||||||
|
// Check if the user has chosen to update the lacking resource inside designer
|
||||||
|
if (dirty && updateProjectResources) {
|
||||||
|
QStringList qrcPathsToBeAdded;
|
||||||
|
foreach (const QString &originalQrcPath, m_originalUiQrcPaths) {
|
||||||
|
if (!projectQrcFiles.contains(originalQrcPath) && !qrcPathsToBeAdded.contains(originalQrcPath))
|
||||||
|
qrcPathsToBeAdded.append(originalQrcPath);
|
||||||
|
}
|
||||||
|
if (!qrcPathsToBeAdded.isEmpty()) {
|
||||||
|
m_handlingResources = true;
|
||||||
|
root->addFiles(qrcPathsToBeAdded);
|
||||||
|
m_handlingResources = false;
|
||||||
|
projectQrcFiles += qrcPathsToBeAdded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList originalSorted = m_originalUiQrcPaths;
|
||||||
|
originalSorted.sort();
|
||||||
|
QStringList projectSorted = projectQrcFiles;
|
||||||
|
projectSorted.sort();
|
||||||
|
if (originalSorted != projectSorted)
|
||||||
|
m_form->setDirty(true);
|
||||||
|
|
||||||
#if QT_VERSION >= 0x050000
|
#if QT_VERSION >= 0x050000
|
||||||
m_form->activateResourceFilePaths(projectQrcFiles);
|
m_form->activateResourceFilePaths(projectQrcFiles);
|
||||||
m_form->setResourceFileSaveMode(QDesignerFormWindowInterface::SaveOnlyUsedResourceFiles);
|
m_form->setResourceFileSaveMode(QDesignerFormWindowInterface::SaveOnlyUsedResourceFiles);
|
||||||
|
@@ -73,7 +73,7 @@ public:
|
|||||||
virtual ~ResourceHandler();
|
virtual ~ResourceHandler();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateResources();
|
void updateResources(bool updateProjectResources = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ensureInitialized();
|
void ensureInitialized();
|
||||||
@@ -85,6 +85,7 @@ private:
|
|||||||
QStringList m_originalUiQrcPaths;
|
QStringList m_originalUiQrcPaths;
|
||||||
ProjectExplorer::SessionNode *m_sessionNode;
|
ProjectExplorer::SessionNode *m_sessionNode;
|
||||||
ProjectExplorer::NodesWatcher *m_sessionWatcher;
|
ProjectExplorer::NodesWatcher *m_sessionWatcher;
|
||||||
|
bool m_handlingResources;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
Reference in New Issue
Block a user