diff options
author | Daniel Teske <daniel.teske@digia.com> | 2014-03-31 14:26:03 +0200 |
---|---|---|
committer | Daniel Teske <daniel.teske@digia.com> | 2014-03-31 15:47:43 +0200 |
commit | 589945b7d3d41c97d075e756b259d709449ccc8c (patch) | |
tree | 320d08bffbeb62ba03f95019aa6c2cef47f9ea6a | |
parent | a5c77222d8f4b38cee10f18ff4ea38d3359e9028 (diff) | |
download | qt-creator-589945b7d3d41c97d075e756b259d709449ccc8c.tar.gz |
ResourceNodes: Add copy to clipboard actions.
One for :/prefix/file paths and one as a url qrc:///prefix/file
Task-number: QTCREATORBUG-11776
Change-Id: I98cc2fccf98a6bf07487352e9b10ae29e8347a45
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorconstants.h | 3 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorplugin.cpp | 44 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorplugin.h | 9 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcenode.cpp | 17 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcenode.h | 6 |
5 files changed, 74 insertions, 5 deletions
diff --git a/src/plugins/resourceeditor/resourceeditorconstants.h b/src/plugins/resourceeditor/resourceeditorconstants.h index 284c7f049c..3965edcd67 100644 --- a/src/plugins/resourceeditor/resourceeditorconstants.h +++ b/src/plugins/resourceeditor/resourceeditorconstants.h @@ -51,6 +51,9 @@ const char C_RENAME_FILE[] = "ResourceEditor.RenameFile"; const char C_OPEN_EDITOR[] = "ResourceEditor.OpenEditor"; const char C_OPEN_TEXT_EDITOR[] = "ResourceEditor.OpenTextEditor"; +const char C_COPY_PATH[] = "ResourceEditor.CopyPath"; +const char C_COPY_URL[] = "ResourceEditor.CopyUrl"; + } // namespace Constants } // namespace ResourceEditor diff --git a/src/plugins/resourceeditor/resourceeditorplugin.cpp b/src/plugins/resourceeditor/resourceeditorplugin.cpp index 8ae6b7cefd..72cb090abb 100644 --- a/src/plugins/resourceeditor/resourceeditorplugin.cpp +++ b/src/plugins/resourceeditor/resourceeditorplugin.cpp @@ -48,6 +48,7 @@ #include <projectexplorer/projectnodes.h> #include <extensionsystem/pluginmanager.h> +#include <utils/parameteraction.h> #include <utils/qtcassert.h> #include <QtPlugin> @@ -58,9 +59,14 @@ #include <QMessageBox> #include <QFormLayout> #include <QDialogButtonBox> +#include <QClipboard> +#include <QApplication> using namespace ResourceEditor::Internal; +static const char resourcePrefix[] = ":"; +static const char urlPrefix[] = "qrc://"; + class PrefixLangDialog : public QDialog { Q_OBJECT @@ -145,6 +151,8 @@ bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *err Core::Context projectTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE); Core::ActionContainer *folderContextMenu = Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FOLDERCONTEXT); + Core::ActionContainer *fileContextMenu = + Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT); Core::Command *command = 0; m_addPrefix = new QAction(tr("Add Prefix..."), this); @@ -182,6 +190,18 @@ bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *err folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES); connect(m_openInTextEditor, SIGNAL(triggered()), this, SLOT(openTextEditorContextMenu())); + m_copyPath = new Utils::ParameterAction(QString(), tr("Copy path \"%1\""), Utils::ParameterAction::AlwaysEnabled, this); + command = Core::ActionManager::registerAction(m_copyPath, Constants::C_COPY_PATH, projectTreeContext); + command->setAttribute(Core::Command::CA_UpdateText); + fileContextMenu->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER); + connect(m_copyPath, SIGNAL(triggered()), this, SLOT(copyPathContextMenu())); + + m_copyUrl = new Utils::ParameterAction(QString(), tr("Copy url \"%1\""), Utils::ParameterAction::AlwaysEnabled, this); + command = Core::ActionManager::registerAction(m_copyUrl, Constants::C_COPY_URL, projectTreeContext); + command->setAttribute(Core::Command::CA_UpdateText); + fileContextMenu->addAction(command, ProjectExplorer::Constants::G_FILE_OTHER); + connect(m_copyUrl, SIGNAL(triggered()), this, SLOT(copyUrlContextMenu())); + m_addPrefix->setEnabled(false); m_removePrefix->setEnabled(false); m_renamePrefix->setEnabled(false); @@ -268,6 +288,18 @@ void ResourceEditorPlugin::openTextEditorContextMenu() Core::EditorManager::openEditor(path, Core::Constants::K_DEFAULT_TEXT_EDITOR_ID); } +void ResourceEditorPlugin::copyPathContextMenu() +{ + ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode()); + QApplication::clipboard()->setText(QLatin1String(resourcePrefix) + node->qrcPath()); +} + +void ResourceEditorPlugin::copyUrlContextMenu() +{ + ResourceFileNode *node = static_cast<ResourceFileNode *>(ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode()); + QApplication::clipboard()->setText(QLatin1String(urlPrefix) + node->qrcPath()); +} + void ResourceEditorPlugin::renamePrefixContextMenu() { ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode()); @@ -314,6 +346,18 @@ void ResourceEditorPlugin::updateContextActions(ProjectExplorer::Node *node, Pro m_renamePrefix->setEnabled(isResourceFolder); m_renamePrefix->setVisible(isResourceFolder); + + bool isResourceFile = qobject_cast<ResourceFileNode *>(node); + m_copyPath->setEnabled(isResourceFile); + m_copyPath->setVisible(isResourceFile); + m_copyUrl->setEnabled(isResourceFile); + m_copyUrl->setVisible(isResourceFile); + if (isResourceFile) { + ResourceFileNode *fileNode = static_cast<ResourceFileNode *>(node); + QString qrcPath = fileNode->qrcPath(); + m_copyPath->setParameter(QLatin1String(resourcePrefix) + qrcPath); + m_copyUrl->setParameter(QLatin1String(urlPrefix) + qrcPath); + } } void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor, diff --git a/src/plugins/resourceeditor/resourceeditorplugin.h b/src/plugins/resourceeditor/resourceeditorplugin.h index e773b6d40f..98677ef631 100644 --- a/src/plugins/resourceeditor/resourceeditorplugin.h +++ b/src/plugins/resourceeditor/resourceeditorplugin.h @@ -41,6 +41,8 @@ class Node; class Project; } +namespace Utils { class ParameterAction; } + namespace ResourceEditor { namespace Internal { @@ -74,6 +76,9 @@ private slots: void openEditorContextMenu(); void openTextEditorContextMenu(); + void copyPathContextMenu(); + void copyUrlContextMenu(); + void updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*); public: @@ -97,6 +102,10 @@ private: QAction *m_openInEditor; QAction *m_openInTextEditor; + + // file context menu + Utils::ParameterAction *m_copyPath; + Utils::ParameterAction *m_copyUrl; }; } // namespace Internal diff --git a/src/plugins/resourceeditor/resourcenode.cpp b/src/plugins/resourceeditor/resourcenode.cpp index 7a95719efe..fc3d4f4e9b 100644 --- a/src/plugins/resourceeditor/resourcenode.cpp +++ b/src/plugins/resourceeditor/resourcenode.cpp @@ -150,14 +150,19 @@ void ResourceTopLevelNode::update() int filecount = file.fileCount(i); for (int j = 0; j < filecount; ++j) { const QString &fileName = file.file(i, j); + QString alias = file.alias(i, j); + if (alias.isEmpty()) { + alias = QFileInfo(path()).absoluteDir().relativeFilePath(fileName); + } 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 { + const QString qrcPath = QDir::cleanPath(prefix + QLatin1Char('/') + alias); fileNames.insert(fileName); filesToAdd[qMakePair(prefix, lang)] - << new ResourceFileNode(fileName, this); + << new ResourceFileNode(fileName, qrcPath, this); } } @@ -478,9 +483,10 @@ bool ResourceFileWatcher::reload(QString *errorString, ReloadFlag flag, ChangeTy return true; } -ResourceFileNode::ResourceFileNode(const QString &filePath, ResourceTopLevelNode *topLevel) +ResourceFileNode::ResourceFileNode(const QString &filePath, const QString &qrcPath, ResourceTopLevelNode *topLevel) : ProjectExplorer::FileNode(filePath, ProjectExplorer::UnknownFileType, false), - m_topLevel(topLevel) + m_topLevel(topLevel), + m_qrcPath(qrcPath) { QString baseDir = QFileInfo(topLevel->path()).absolutePath(); @@ -491,3 +497,8 @@ QString ResourceFileNode::displayName() const { return m_displayName; } + +QString ResourceFileNode::qrcPath() const +{ + return m_qrcPath; +} diff --git a/src/plugins/resourceeditor/resourcenode.h b/src/plugins/resourceeditor/resourcenode.h index 01dfaf1c2e..e984151f1a 100644 --- a/src/plugins/resourceeditor/resourcenode.h +++ b/src/plugins/resourceeditor/resourcenode.h @@ -101,13 +101,15 @@ class ResourceFileNode : public ProjectExplorer::FileNode { Q_OBJECT public: - ResourceFileNode(const QString &filePath, ResourceTopLevelNode *topLevel); + ResourceFileNode(const QString &filePath, const QString &qrcPath, ResourceTopLevelNode *topLevel); QString displayName() const; + QString qrcPath() const; private: - QString m_displayName; ResourceTopLevelNode *m_topLevel; + QString m_displayName; + QString m_qrcPath; }; class ResourceFileWatcher : public Core::IDocument |