2014-02-18 21:38:03 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2014-02-18 21:38:03 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2014-02-18 21:38:03 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2014-02-18 21:38:03 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2014-02-18 21:38:03 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "resourcenode.h"
|
|
|
|
|
#include "resourceeditorconstants.h"
|
2014-02-19 20:07:12 +02:00
|
|
|
#include "qrceditor/resourcefile_p.h"
|
2014-02-18 21:38:03 +01:00
|
|
|
|
|
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/documentmanager.h>
|
|
|
|
|
#include <coreplugin/fileiconprovider.h>
|
|
|
|
|
|
|
|
|
|
#include <qmljstools/qmljstoolsconstants.h>
|
|
|
|
|
|
2015-02-04 09:32:46 +01:00
|
|
|
#include <utils/mimetypes/mimedatabase.h>
|
|
|
|
|
|
2015-01-09 15:50:06 +01:00
|
|
|
#include <QCoreApplication>
|
2014-02-18 21:38:03 +01:00
|
|
|
#include <QDir>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
|
|
using namespace ResourceEditor;
|
|
|
|
|
using namespace ResourceEditor::Internal;
|
|
|
|
|
|
2014-03-07 16:23:04 +01:00
|
|
|
static bool priority(const QStringList &files)
|
2014-02-18 21:38:03 +01:00
|
|
|
{
|
|
|
|
|
if (files.isEmpty())
|
2014-03-11 20:23:22 +01:00
|
|
|
return false;
|
2015-02-04 09:32:46 +01:00
|
|
|
Utils::MimeDatabase mdb;
|
|
|
|
|
QString type = mdb.mimeTypeForFile(files.at(0)).name();
|
2014-02-18 21:38:03 +01:00
|
|
|
if (type.startsWith(QLatin1String("image/"))
|
|
|
|
|
|| type == QLatin1String(QmlJSTools::Constants::QML_MIMETYPE)
|
|
|
|
|
|| type == QLatin1String(QmlJSTools::Constants::JS_MIMETYPE))
|
2014-03-07 16:23:04 +01:00
|
|
|
return true;
|
|
|
|
|
return false;
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
static bool addFilesToResource(const Utils::FileName &resourceFile,
|
|
|
|
|
const QStringList &filePaths,
|
|
|
|
|
QStringList *notAdded,
|
|
|
|
|
const QString &prefix,
|
|
|
|
|
const QString &lang)
|
2014-02-18 21:38:03 +01:00
|
|
|
{
|
|
|
|
|
if (notAdded)
|
|
|
|
|
*notAdded = filePaths;
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFile file(resourceFile.toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
if (!file.load())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int index = file.indexOfPrefix(prefix, lang);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
index = file.addPrefix(prefix, lang);
|
|
|
|
|
|
|
|
|
|
if (notAdded)
|
|
|
|
|
notAdded->clear();
|
|
|
|
|
foreach (const QString &path, filePaths) {
|
2014-05-17 22:30:21 +02:00
|
|
|
if (file.contains(index, path)) {
|
|
|
|
|
if (notAdded)
|
|
|
|
|
*notAdded << path;
|
|
|
|
|
} else {
|
2014-02-18 21:38:03 +01:00
|
|
|
file.addFile(index, path);
|
2014-05-17 22:30:21 +02:00
|
|
|
}
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::expectFileChange(resourceFile.toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
file.save();
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::unexpectFileChange(resourceFile.toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool sortByPrefixAndLang(ProjectExplorer::FolderNode *a, ProjectExplorer::FolderNode *b)
|
|
|
|
|
{
|
|
|
|
|
ResourceFolderNode *aa = static_cast<ResourceFolderNode *>(a);
|
|
|
|
|
ResourceFolderNode *bb = static_cast<ResourceFolderNode *>(b);
|
|
|
|
|
|
|
|
|
|
if (aa->prefix() < bb->prefix())
|
|
|
|
|
return true;
|
|
|
|
|
if (bb->prefix() < aa->prefix())
|
|
|
|
|
return false;
|
|
|
|
|
return aa->lang() < bb->lang();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool sortNodesByPath(ProjectExplorer::Node *a, ProjectExplorer::Node *b)
|
|
|
|
|
{
|
|
|
|
|
return a->path() < b->path();
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceTopLevelNode::ResourceTopLevelNode(const Utils::FileName &filePath, FolderNode *parent)
|
2014-02-18 21:38:03 +01:00
|
|
|
: ProjectExplorer::FolderNode(filePath)
|
|
|
|
|
{
|
2015-02-02 00:37:38 +02:00
|
|
|
setIcon(Core::FileIconProvider::icon(filePath.toString()));
|
2014-02-18 21:38:03 +01:00
|
|
|
m_document = new ResourceFileWatcher(this);
|
|
|
|
|
Core::DocumentManager::addDocument(m_document);
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
Utils::FileName base = parent->path();
|
|
|
|
|
if (filePath.isChildOf(base))
|
|
|
|
|
setDisplayName(filePath.relativeChildPath(base).toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
else
|
2015-02-02 00:37:38 +02:00
|
|
|
setDisplayName(filePath.toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResourceTopLevelNode::~ResourceTopLevelNode()
|
|
|
|
|
{
|
|
|
|
|
Core::DocumentManager::removeDocument(m_document);
|
2015-01-09 15:50:06 +01:00
|
|
|
delete m_document;
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ResourceTopLevelNode::update()
|
|
|
|
|
{
|
|
|
|
|
QList<ProjectExplorer::FolderNode *> newFolderList;
|
|
|
|
|
QMap<QPair<QString, QString>, QList<ProjectExplorer::FileNode *> > filesToAdd;
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFile file(path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
if (file.load()) {
|
|
|
|
|
QSet<QPair<QString, QString > > prefixes;
|
|
|
|
|
|
|
|
|
|
int prfxcount = file.prefixCount();
|
|
|
|
|
for (int i = 0; i < prfxcount; ++i) {
|
|
|
|
|
const QString &prefix = file.prefix(i);
|
|
|
|
|
const QString &lang = file.lang(i);
|
|
|
|
|
// ensure that we don't duplicate prefixes
|
|
|
|
|
if (!prefixes.contains(qMakePair(prefix, lang))) {
|
|
|
|
|
ProjectExplorer::FolderNode *fn = new ResourceFolderNode(file.prefix(i), file.lang(i), this);
|
|
|
|
|
newFolderList << fn;
|
|
|
|
|
|
|
|
|
|
prefixes.insert(qMakePair(prefix, lang));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSet<QString> fileNames;
|
|
|
|
|
int filecount = file.fileCount(i);
|
|
|
|
|
for (int j = 0; j < filecount; ++j) {
|
|
|
|
|
const QString &fileName = file.file(i, j);
|
2014-03-31 14:26:03 +02:00
|
|
|
QString alias = file.alias(i, j);
|
2015-02-02 00:37:38 +02:00
|
|
|
if (alias.isEmpty())
|
|
|
|
|
alias = path().toFileInfo().absoluteDir().relativeFilePath(fileName);
|
2014-02-18 21:38:03 +01:00
|
|
|
if (fileNames.contains(fileName)) {
|
|
|
|
|
// The file name is duplicated, skip it
|
|
|
|
|
// Note: this is wrong, but the qrceditor doesn't allow it either
|
|
|
|
|
// only aliases need to be unique
|
|
|
|
|
} else {
|
2014-06-02 14:25:47 +02:00
|
|
|
QString prefixWithSlash = prefix;
|
|
|
|
|
if (!prefixWithSlash.endsWith(QLatin1Char('/')))
|
|
|
|
|
prefixWithSlash.append(QLatin1Char('/'));
|
|
|
|
|
const QString qrcPath = QDir::cleanPath(prefixWithSlash + alias);
|
2014-02-18 21:38:03 +01:00
|
|
|
fileNames.insert(fileName);
|
|
|
|
|
filesToAdd[qMakePair(prefix, lang)]
|
2015-02-02 00:37:38 +02:00
|
|
|
<< new ResourceFileNode(Utils::FileName::fromString(fileName),
|
|
|
|
|
qrcPath, this);
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::FolderNode *> oldFolderList = subFolderNodes();
|
|
|
|
|
QList<ProjectExplorer::FolderNode *> foldersToAdd;
|
|
|
|
|
QList<ProjectExplorer::FolderNode *> foldersToRemove;
|
|
|
|
|
|
|
|
|
|
std::sort(oldFolderList.begin(), oldFolderList.end(), sortByPrefixAndLang);
|
|
|
|
|
std::sort(newFolderList.begin(), newFolderList.end(), sortByPrefixAndLang);
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::compareSortedLists(oldFolderList, newFolderList, foldersToRemove, foldersToAdd, sortByPrefixAndLang);
|
|
|
|
|
|
|
|
|
|
removeFolderNodes(foldersToRemove);
|
|
|
|
|
addFolderNodes(foldersToAdd);
|
|
|
|
|
|
|
|
|
|
// delete nodes that weren't added
|
|
|
|
|
qDeleteAll(ProjectExplorer::subtractSortedList(newFolderList, foldersToAdd, sortByPrefixAndLang));
|
|
|
|
|
|
|
|
|
|
foreach (FolderNode *fn, subFolderNodes()) {
|
|
|
|
|
ResourceFolderNode *rn = static_cast<ResourceFolderNode *>(fn);
|
|
|
|
|
rn->updateFiles(filesToAdd.value(qMakePair(rn->prefix(), rn->lang())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::ProjectAction> ResourceTopLevelNode::supportedActions(ProjectExplorer::Node *node) const
|
|
|
|
|
{
|
|
|
|
|
if (node != this)
|
|
|
|
|
return QList<ProjectExplorer::ProjectAction>();
|
|
|
|
|
return QList<ProjectExplorer::ProjectAction>()
|
|
|
|
|
<< ProjectExplorer::AddNewFile
|
|
|
|
|
<< ProjectExplorer::AddExistingFile
|
|
|
|
|
<< ProjectExplorer::AddExistingDirectory
|
|
|
|
|
<< ProjectExplorer::HidePathActions
|
|
|
|
|
<< ProjectExplorer::Rename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceTopLevelNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
|
|
|
|
{
|
|
|
|
|
return addFilesToResource(path(), filePaths, notAdded, QLatin1String("/"), QString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceTopLevelNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
|
|
|
|
|
{
|
|
|
|
|
return parentFolderNode()->removeFiles(filePaths, notRemoved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceTopLevelNode::addPrefix(const QString &prefix, const QString &lang)
|
|
|
|
|
{
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFile file(path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
if (!file.load())
|
|
|
|
|
return false;
|
|
|
|
|
int index = file.addPrefix(prefix, lang);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return false;
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::expectFileChange(path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
file.save();
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::unexpectFileChange(path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceTopLevelNode::removePrefix(const QString &prefix, const QString &lang)
|
|
|
|
|
{
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFile file(path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
if (!file.load())
|
|
|
|
|
return false;
|
|
|
|
|
for (int i = 0; i < file.prefixCount(); ++i) {
|
|
|
|
|
if (file.prefix(i) == prefix
|
|
|
|
|
&& file.lang(i) == lang) {
|
|
|
|
|
file.removePrefix(i);
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::expectFileChange(path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
file.save();
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::unexpectFileChange(path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 15:32:12 +02:00
|
|
|
bool ResourceTopLevelNode::removeNonExistingFiles()
|
|
|
|
|
{
|
|
|
|
|
ResourceFile file(path().toString());
|
|
|
|
|
if (!file.load())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
QFileInfo fi;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < file.prefixCount(); ++i) {
|
|
|
|
|
int fileCount = file.fileCount(i);
|
|
|
|
|
for (int j = fileCount -1; j >= 0; --j) {
|
|
|
|
|
fi.setFile(file.file(i, j));
|
|
|
|
|
if (!fi.exists())
|
|
|
|
|
file.removeFile(i, j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::DocumentManager::expectFileChange(path().toString());
|
|
|
|
|
file.save();
|
|
|
|
|
Core::DocumentManager::unexpectFileChange(path().toString());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 16:23:04 +01:00
|
|
|
ProjectExplorer::FolderNode::AddNewInformation ResourceTopLevelNode::addNewInformation(const QStringList &files, Node *context) const
|
2014-02-18 21:38:03 +01:00
|
|
|
{
|
2015-01-09 15:50:06 +01:00
|
|
|
QString name = QCoreApplication::translate("ResourceTopLevelNode", "%1 Prefix: %2")
|
2015-02-02 00:37:38 +02:00
|
|
|
.arg(path().fileName())
|
2014-08-29 14:00:18 +02:00
|
|
|
.arg(QLatin1Char('/'));
|
2014-03-07 16:23:04 +01:00
|
|
|
|
2014-08-05 16:08:45 +02:00
|
|
|
int p = -1;
|
|
|
|
|
if (priority(files)) { // images/* and qml/js mimetypes
|
|
|
|
|
p = 110;
|
|
|
|
|
if (context == this)
|
|
|
|
|
p = 120;
|
2014-03-07 16:23:04 +01:00
|
|
|
else if (projectNode() == context)
|
|
|
|
|
p = 150; // steal from our project node
|
2014-04-04 12:29:51 +02:00
|
|
|
// The ResourceFolderNode '/' defers to us, as otherwise
|
|
|
|
|
// two nodes would be responsible for '/'
|
|
|
|
|
// Thus also return a high priority for it
|
2015-01-09 15:50:06 +01:00
|
|
|
if (ResourceFolderNode *rfn = dynamic_cast<ResourceFolderNode *>(context))
|
2014-06-02 15:09:25 +02:00
|
|
|
if (rfn->prefix() == QLatin1String("/") && rfn->parentFolderNode() == this)
|
2014-08-05 16:08:45 +02:00
|
|
|
p = 120;
|
2014-03-07 16:23:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AddNewInformation(name, p);
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-17 11:52:45 +01:00
|
|
|
bool ResourceTopLevelNode::showInSimpleTree() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-18 21:38:03 +01:00
|
|
|
ResourceFolderNode::ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent)
|
2015-02-27 09:36:54 +02:00
|
|
|
: ProjectExplorer::FolderNode(Utils::FileName(parent->path()).appendPath(prefix)),
|
2014-02-18 21:38:03 +01:00
|
|
|
// TOOD Why add existing directory doesn't work
|
|
|
|
|
m_topLevelNode(parent),
|
|
|
|
|
m_prefix(prefix),
|
|
|
|
|
m_lang(lang)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResourceFolderNode::~ResourceFolderNode()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<ProjectExplorer::ProjectAction> ResourceFolderNode::supportedActions(ProjectExplorer::Node *node) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(node)
|
|
|
|
|
QList<ProjectExplorer::ProjectAction> actions;
|
|
|
|
|
actions << ProjectExplorer::AddNewFile
|
|
|
|
|
<< ProjectExplorer::AddExistingFile
|
|
|
|
|
<< ProjectExplorer::AddExistingDirectory
|
|
|
|
|
<< ProjectExplorer::RemoveFile
|
|
|
|
|
<< ProjectExplorer::Rename // Note: only works for the filename, works akwardly for relative file paths
|
|
|
|
|
<< ProjectExplorer::HidePathActions; // hides open terminal etc.
|
|
|
|
|
|
|
|
|
|
// if the prefix is '/' (without lang) hide this node in add new dialog,
|
|
|
|
|
// as the ResouceTopLevelNode is always shown for the '/' prefix
|
|
|
|
|
if (m_prefix == QLatin1String("/") && m_lang.isEmpty())
|
|
|
|
|
actions << ProjectExplorer::InheritedFromParent;
|
|
|
|
|
|
|
|
|
|
return actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFolderNode::addFiles(const QStringList &filePaths, QStringList *notAdded)
|
|
|
|
|
{
|
|
|
|
|
return addFilesToResource(m_topLevelNode->path(), filePaths, notAdded, m_prefix, m_lang);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFolderNode::removeFiles(const QStringList &filePaths, QStringList *notRemoved)
|
|
|
|
|
{
|
|
|
|
|
if (notRemoved)
|
|
|
|
|
*notRemoved = filePaths;
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFile file(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
if (!file.load())
|
|
|
|
|
return false;
|
|
|
|
|
int index = file.indexOfPrefix(m_prefix, m_lang);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return false;
|
|
|
|
|
for (int j = 0; j < file.fileCount(index); ++j) {
|
|
|
|
|
QString fileName = file.file(index, j);
|
|
|
|
|
if (!filePaths.contains(fileName))
|
|
|
|
|
continue;
|
|
|
|
|
if (notRemoved)
|
|
|
|
|
notRemoved->removeOne(fileName);
|
|
|
|
|
file.removeFile(index, j);
|
|
|
|
|
--j;
|
|
|
|
|
}
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::expectFileChange(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
file.save();
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::unexpectFileChange(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFolderNode::renameFile(const QString &filePath, const QString &newFilePath)
|
|
|
|
|
{
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFile file(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
if (!file.load())
|
|
|
|
|
return false;
|
|
|
|
|
int index = file.indexOfPrefix(m_prefix, m_lang);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < file.fileCount(index); ++j) {
|
|
|
|
|
if (file.file(index, j) == filePath) {
|
|
|
|
|
file.replaceFile(index, j, newFilePath);
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::expectFileChange(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
file.save();
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::unexpectFileChange(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFolderNode::renamePrefix(const QString &prefix, const QString &lang)
|
|
|
|
|
{
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFile file(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
if (!file.load())
|
|
|
|
|
return false;
|
2014-03-13 15:04:27 +01:00
|
|
|
int index = file.indexOfPrefix(m_prefix, m_lang);
|
2014-02-18 21:38:03 +01:00
|
|
|
if (index == -1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!file.replacePrefixAndLang(index, prefix, lang))
|
|
|
|
|
return false;
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::expectFileChange(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
file.save();
|
2015-02-02 00:37:38 +02:00
|
|
|
Core::DocumentManager::unexpectFileChange(m_topLevelNode->path().toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 16:23:04 +01:00
|
|
|
ProjectExplorer::FolderNode::AddNewInformation ResourceFolderNode::addNewInformation(const QStringList &files, Node *context) const
|
2014-02-18 21:38:03 +01:00
|
|
|
{
|
2015-01-09 15:50:06 +01:00
|
|
|
QString name = QCoreApplication::translate("ResourceTopLevelNode", "%1 Prefix: %2")
|
2015-02-02 00:37:38 +02:00
|
|
|
.arg(m_topLevelNode->path().fileName())
|
2014-02-18 21:38:03 +01:00
|
|
|
.arg(displayName());
|
2014-03-07 16:23:04 +01:00
|
|
|
|
2014-08-05 16:08:45 +02:00
|
|
|
int p = -1; // never the default
|
|
|
|
|
if (priority(files)) { // image/* and qml/js mimetypes
|
|
|
|
|
p = 105; // prefer against .pro and .pri files
|
|
|
|
|
if (context == this)
|
2014-03-07 16:23:04 +01:00
|
|
|
p = 120;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AddNewInformation(name, p);
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ResourceFolderNode::displayName() const
|
|
|
|
|
{
|
|
|
|
|
if (m_lang.isEmpty())
|
|
|
|
|
return m_prefix;
|
|
|
|
|
return m_prefix + QLatin1String(" (") + m_lang + QLatin1Char(')');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ResourceFolderNode::prefix() const
|
|
|
|
|
{
|
|
|
|
|
return m_prefix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ResourceFolderNode::lang() const
|
|
|
|
|
{
|
|
|
|
|
return m_lang;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResourceTopLevelNode *ResourceFolderNode::resourceNode() const
|
|
|
|
|
{
|
|
|
|
|
return m_topLevelNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ResourceFolderNode::updateFiles(QList<ProjectExplorer::FileNode *> newList)
|
|
|
|
|
{
|
|
|
|
|
QList<ProjectExplorer::FileNode *> oldList = fileNodes();
|
|
|
|
|
QList<ProjectExplorer::FileNode *> filesToAdd;
|
|
|
|
|
QList<ProjectExplorer::FileNode *> filesToRemove;
|
|
|
|
|
|
|
|
|
|
std::sort(oldList.begin(), oldList.end(), sortNodesByPath);
|
|
|
|
|
std::sort(newList.begin(), newList.end(), sortNodesByPath);
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::compareSortedLists(oldList, newList, filesToRemove, filesToAdd, sortNodesByPath);
|
|
|
|
|
|
|
|
|
|
removeFileNodes(filesToRemove);
|
|
|
|
|
addFileNodes(filesToAdd);
|
|
|
|
|
|
|
|
|
|
qDeleteAll(ProjectExplorer::subtractSortedList(newList, filesToAdd, sortNodesByPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResourceFileWatcher::ResourceFileWatcher(ResourceTopLevelNode *node)
|
2015-01-09 15:50:06 +01:00
|
|
|
: IDocument(0), m_node(node)
|
2014-02-18 21:38:03 +01:00
|
|
|
{
|
2014-03-05 15:58:12 +01:00
|
|
|
setId("ResourceNodeWatcher");
|
2014-06-26 02:15:34 +02:00
|
|
|
setMimeType(QLatin1String(ResourceEditor::Constants::C_RESOURCE_MIMETYPE));
|
2015-02-02 00:37:38 +02:00
|
|
|
setFilePath(node->path());
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFileWatcher::save(QString *errorString, const QString &fileName, bool autoSave)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(errorString);
|
|
|
|
|
Q_UNUSED(fileName);
|
|
|
|
|
Q_UNUSED(autoSave);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ResourceFileWatcher::defaultPath() const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ResourceFileWatcher::suggestedFileName() const
|
|
|
|
|
{
|
|
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFileWatcher::isModified() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFileWatcher::isSaveAsAllowed() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IDocument::ReloadBehavior ResourceFileWatcher::reloadBehavior(ChangeTrigger state, ChangeType type) const
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(state)
|
|
|
|
|
Q_UNUSED(type)
|
|
|
|
|
return BehaviorSilent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ResourceFileWatcher::reload(QString *errorString, ReloadFlag flag, ChangeType type)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(errorString)
|
|
|
|
|
Q_UNUSED(flag)
|
|
|
|
|
if (type == TypePermissions)
|
|
|
|
|
return true;
|
|
|
|
|
m_node->update();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-02 00:37:38 +02:00
|
|
|
ResourceFileNode::ResourceFileNode(const Utils::FileName &filePath, const QString &qrcPath, ResourceTopLevelNode *topLevel)
|
2014-02-18 21:38:03 +01:00
|
|
|
: ProjectExplorer::FileNode(filePath, ProjectExplorer::UnknownFileType, false),
|
2014-03-31 14:26:03 +02:00
|
|
|
m_qrcPath(qrcPath)
|
2014-02-18 21:38:03 +01:00
|
|
|
|
|
|
|
|
{
|
2015-02-02 00:37:38 +02:00
|
|
|
QDir baseDir = topLevel->path().toFileInfo().absoluteDir();
|
|
|
|
|
m_displayName = QDir(baseDir).relativeFilePath(filePath.toString());
|
2014-02-18 21:38:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ResourceFileNode::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return m_displayName;
|
|
|
|
|
}
|
2014-03-31 14:26:03 +02:00
|
|
|
|
|
|
|
|
QString ResourceFileNode::qrcPath() const
|
|
|
|
|
{
|
|
|
|
|
return m_qrcPath;
|
|
|
|
|
}
|
2014-06-12 15:12:27 +02:00
|
|
|
|
|
|
|
|
QList<ProjectExplorer::ProjectAction> ResourceFileNode::supportedActions(ProjectExplorer::Node *node) const
|
|
|
|
|
{
|
|
|
|
|
QList<ProjectExplorer::ProjectAction> actions = parentFolderNode()->supportedActions(node);
|
|
|
|
|
actions.removeOne(ProjectExplorer::HidePathActions);
|
|
|
|
|
return actions;
|
|
|
|
|
}
|