Commit 9310b652 authored by Daniel Teske's avatar Daniel Teske

Resource file in project tree

Task-number: QTCREATORBUG-1346
Change-Id: I0cbb5633ef06a4762c48af46d9da551c67259d70
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 1e998432
......@@ -1734,6 +1734,11 @@ QList<RunControl *> ProjectExplorerPlugin::runControls() const
return d->m_outputPane->runControls();
}
void ProjectExplorerPlugin::initiateInlineRenaming()
{
renameFile();
}
void ProjectExplorerPlugin::buildQueueFinished(bool success)
{
if (debug)
......@@ -2758,6 +2763,12 @@ QString pathOrDirectoryFor(Node *node, bool dir)
}
} else {
QFileInfo fi(path);
// remove any /suffixes, which e.g. ResourceNode uses
// Note this should be removed again by making node->path() a true path again
// That requires changes in both the VirtualFolderNode and ResourceNode
while (!fi.exists() && !fi.isRoot())
fi.setFile(fi.absolutePath());
if (dir)
location = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
else
......@@ -2833,8 +2844,7 @@ void ProjectExplorerPlugin::addExistingDirectory()
{
QTC_ASSERT(d->m_currentNode, return);
const QString path = QFileInfo(d->m_currentNode->path()).absolutePath();
SelectableFilesDialogAddDirectory dialog(path, QStringList(), Core::ICore::mainWindow());
SelectableFilesDialogAddDirectory dialog(directoryFor(d->m_currentNode), QStringList(), Core::ICore::mainWindow());
if (dialog.exec() == QDialog::Accepted)
addExistingFiles(dialog.selectedFiles());
......@@ -2981,16 +2991,13 @@ void ProjectExplorerPlugin::renameFile()
void ProjectExplorerPlugin::renameFile(Node *node, const QString &to)
{
FileNode *fileNode = qobject_cast<FileNode *>(node);
if (!fileNode)
return;
QString orgFilePath = QFileInfo(node->path()).absoluteFilePath();
QString dir = QFileInfo(orgFilePath).absolutePath();
QString newFilePath = dir + QLatin1Char('/') + to;
if (Core::FileUtils::renameFile(orgFilePath, newFilePath)) {
// Tell the project plugin about rename
FolderNode *folderNode = fileNode->parentFolderNode();
FolderNode *folderNode = node->parentFolderNode();
if (!folderNode->renameFile(orgFilePath, newFilePath)) {
QMessageBox::warning(ICore::mainWindow(), tr("Project Editing Failed"),
tr("The file %1 was renamed to %2, but the project file %3 could not be automatically changed.")
......
......@@ -122,8 +122,13 @@ public:
QList<RunControl *> runControls() const;
void initiateInlineRenaming();
static QString displayNameForStepId(Core::Id stepId);
static QString directoryFor(Node *node);
static QString pathFor(Node *node);
signals:
void runControlStarted(ProjectExplorer::RunControl *rc);
void runControlFinished(ProjectExplorer::RunControl *rc);
......@@ -270,8 +275,6 @@ private slots:
#endif
private:
QString directoryFor(Node *node);
QString pathFor(Node *node);
void deploy(QList<Project *>);
int queue(QList<Project *>, QList<Core::Id> stepIds);
void updateContextMenuActions();
......
......@@ -51,6 +51,8 @@
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/uicodemodelsupport.h>
#include <resourceeditor/resourcenode.h>
#include <cpptools/cppmodelmanagerinterface.h>
#include <cpptools/cpptoolsconstants.h>
......@@ -394,12 +396,15 @@ struct InternalNode
// Makes the projectNode's subtree below the given folder match this internal node's subtree
void updateSubFolders(ProjectExplorer::FolderNode *folder)
{
updateFiles(folder, type);
if (type == ProjectExplorer::ResourceType)
updateResourceFiles(folder);
else
updateFiles(folder, type);
// updateFolders
QMultiMap<QString, FolderNode *> existingFolderNodes;
foreach (FolderNode *node, folder->subFolderNodes())
if (node->nodeType() != ProjectNodeType)
if (node->nodeType() != ProjectNodeType && !qobject_cast<ResourceEditor::ResourceTopLevelNode *>(node))
existingFolderNodes.insert(node->path(), node);
QList<FolderNode *> foldersToRemove;
......@@ -507,6 +512,37 @@ struct InternalNode
folder->removeFileNodes(filesToRemove);
folder->addFileNodes(nodesToAdd);
}
// Makes the folder's files match this internal node's file list
void updateResourceFiles(FolderNode *folder)
{
QList<ProjectExplorer::FolderNode *> existingResourceNodes; // for resource special handling
foreach (FolderNode *folderNode, folder->subFolderNodes()) {
if (ResourceEditor::ResourceTopLevelNode *rn = qobject_cast<ResourceEditor::ResourceTopLevelNode *>(folderNode))
existingResourceNodes << rn;
}
QList<ProjectExplorer::FolderNode *> resourcesToRemove;
QStringList resourcesToAdd;
SortByPath sortByPath;
qSort(files.begin(), files.end(), sortByPath);
qSort(existingResourceNodes.begin(), existingResourceNodes.end(), sortByPath);
ProjectExplorer::compareSortedLists(existingResourceNodes, files, resourcesToRemove, resourcesToAdd, sortByPath);
QList<FolderNode *> nodesToAdd;
nodesToAdd.reserve(resourcesToAdd.size());
foreach (const QString &file, resourcesToAdd)
nodesToAdd.append(new ResourceEditor::ResourceTopLevelNode(file, folder));
folder->removeFolderNodes(resourcesToRemove);
folder->addFolderNodes(nodesToAdd);
foreach (FolderNode *fn, nodesToAdd)
qobject_cast<ResourceEditor::ResourceTopLevelNode *>(fn)->update();
}
};
}
......@@ -866,7 +902,8 @@ QList<ProjectExplorer::ProjectAction> QmakePriFileNode::supportedActions(Node *n
}
ProjectExplorer::FileNode *fileNode = qobject_cast<FileNode *>(node);
if (fileNode && fileNode->fileType() != ProjectExplorer::ProjectFileType)
if ((fileNode && fileNode->fileType() != ProjectExplorer::ProjectFileType)
|| qobject_cast<ResourceEditor::ResourceTopLevelNode *>(node))
actions << ProjectExplorer::Rename;
......
......@@ -10,6 +10,7 @@ QTC_PLUGIN_DEPENDS += \
qtsupport \
texteditor \
cpptools \
qmljstools
qmljstools \
resourceeditor
QTC_PLUGIN_RECOMMENDS += \
designer
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef RESOUCE_GLOBAL_H
#define RESOUCE_GLOBAL_H
#include <qglobal.h>
#if defined(RESOURCE_LIBRARY)
# define RESOURCE_EXPORT Q_DECL_EXPORT
#else
# define RESOURCE_EXPORT Q_DECL_IMPORT
#endif
#endif // RESOUCE_GLOBAL_H
......@@ -5,11 +5,16 @@ HEADERS += resourceeditorfactory.h \
resourceeditorplugin.h \
resourcewizard.h \
resourceeditorw.h \
resourceeditorconstants.h
resourceeditorconstants.h \
resource_global.h \
resourcenode.h
SOURCES +=resourceeditorfactory.cpp \
resourceeditorplugin.cpp \
resourcewizard.cpp \
resourceeditorw.cpp
resourceeditorw.cpp \
resourcenode.cpp
RESOURCES += resourceeditor.qrc
DEFINES += RESOURCE_LIBRARY
......@@ -20,6 +20,7 @@ QtcPlugin {
"resourceeditorplugin.cpp", "resourceeditorplugin.h",
"resourceeditorw.cpp", "resourceeditorw.h",
"resourcewizard.cpp", "resourcewizard.h",
"resource_global.h", "resourcenode.cpp", "resourcenode.h"
]
}
......
......@@ -5,3 +5,4 @@ QTC_LIB_DEPENDS += \
utils
QTC_PLUGIN_DEPENDS += \
coreplugin \
projectexplorer
......@@ -41,6 +41,17 @@ const char REFRESH[] = "ResourceEditor.Refresh";
const char C_RESOURCE_MIMETYPE[] = "application/vnd.qt.xml.resource";
const char C_ADD_PREFIX[] = "ResourceEditor.AddPrefix";
const char C_REMOVE_PREFIX[] = "ResourceEditor.RemovePrefix";
const char C_RENAME_PREFIX[] = "ResourceEditor.RenamePrefix";
const char C_REMOVE_FILE[] = "ResourceEditor.RemoveFile";
const char C_RENAME_FILE[] = "ResourceEditor.RenameFile";
const char C_OPEN_EDITOR[] = "ResourceEditor.OpenEditor";
const char C_OPEN_TEXT_EDITOR[] = "ResourceEditor.OpenTextEditor";
} // namespace Constants
} // namespace ResourceEditor
......
......@@ -36,6 +36,11 @@ QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE
namespace ProjectExplorer {
class Node;
class Project;
}
namespace ResourceEditor {
namespace Internal {
......@@ -60,6 +65,17 @@ private slots:
void onRedo();
void onRefresh();
void addPrefixContextMenu();
void renamePrefixContextMenu();
void removePrefixContextMenu();
void renameFileContextMenu();
void removeFileContextMenu();
void openEditorContextMenu();
void openTextEditorContextMenu();
void updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*);
public:
void onUndoStackChanged(ResourceEditorW const *editor, bool canUndo, bool canRedo);
......@@ -70,6 +86,17 @@ private:
QAction *m_redoAction;
QAction *m_undoAction;
QAction *m_refreshAction;
// project tree's folder context menu
QAction *m_addPrefix;
QAction *m_removePrefix;
QAction *m_renamePrefix;
QAction *m_renameResourceFile;
QAction *m_removeResourceFile;
QAction *m_openInEditor;
QAction *m_openInTextEditor;
};
} // namespace Internal
......
This diff is collapsed.
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef RESOURCENODE_H
#define RESOURCENODE_H
#include "resource_global.h"
#include <projectexplorer/projectnodes.h>
#include <coreplugin/idocument.h>
namespace ProjectExplorer {
class RunConfiguration;
}
namespace ResourceEditor {
namespace Internal { class ResourceFileWatcher; }
class RESOURCE_EXPORT ResourceTopLevelNode : public ProjectExplorer::FolderNode
{
Q_OBJECT
public:
ResourceTopLevelNode(const QString &filePath, FolderNode *parent);
~ResourceTopLevelNode();
void update();
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const;
bool addFiles(const QStringList &filePaths, QStringList *notAdded);
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved);
bool addFiles(const QString &prefix, const QString &lang, const QStringList &filePaths, QStringList *notAdded);
bool removeFiles(const QString &prefix, const QString &lang,const QStringList &filePaths, QStringList *notRemoved);
bool addPrefix(const QString &prefix, const QString &lang);
bool removePrefix(const QString &prefix, const QString &lang);
AddNewInformation addNewInformation(const QStringList &files) const;
private:
Internal::ResourceFileWatcher *m_document;
};
namespace Internal {
class ResourceFolderNode : public ProjectExplorer::FolderNode
{
friend class ResourceEditor::ResourceTopLevelNode; // for updateFiles
Q_OBJECT
public:
ResourceFolderNode(const QString &prefix, const QString &lang, ResourceTopLevelNode *parent);
~ResourceFolderNode();
QList<ProjectExplorer::ProjectAction> supportedActions(Node *node) const;
QString displayName() const;
bool addFiles(const QStringList &filePaths, QStringList *notAdded);
bool removeFiles(const QStringList &filePaths, QStringList *notRemoved);
bool renameFile(const QString &filePath, const QString &newFilePath);
bool renamePrefix(const QString &prefix, const QString &lang);
AddNewInformation addNewInformation(const QStringList &files) const;
QString prefix() const;
QString lang() const;
ResourceTopLevelNode *resourceNode() const;
private:
void updateFiles(QList<ProjectExplorer::FileNode *> newList);
ResourceTopLevelNode *m_topLevelNode;
QString m_prefix;
QString m_lang;
};
class ResourceFileNode : public ProjectExplorer::FileNode
{
Q_OBJECT
public:
ResourceFileNode(const QString &filePath, ResourceTopLevelNode *topLevel);
QString displayName() const;
private:
QString m_displayName;
ResourceTopLevelNode *m_topLevel;
};
class ResourceFileWatcher : public Core::IDocument
{
Q_OBJECT
public:
ResourceFileWatcher(ResourceTopLevelNode *node);
virtual bool save(QString *errorString, const QString &fileName, bool autoSave);
virtual QString defaultPath() const;
virtual QString suggestedFileName() const;
virtual QString mimeType() const;
virtual bool isModified() const;
virtual bool isSaveAsAllowed() const;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const;
bool reload(QString *errorString, ReloadFlag flag, ChangeType type);
private:
ResourceTopLevelNode *m_node;
};
} // namespace Internal
} // namespace ResourceEditor
#endif // RESOUCENODE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment