aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/resourceeditor/resourceeditorplugin.cpp
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@digia.com>2014-03-31 14:26:03 +0200
committerDaniel Teske <daniel.teske@digia.com>2014-03-31 15:47:43 +0200
commit589945b7d3d41c97d075e756b259d709449ccc8c (patch)
tree320d08bffbeb62ba03f95019aa6c2cef47f9ea6a /src/plugins/resourceeditor/resourceeditorplugin.cpp
parenta5c77222d8f4b38cee10f18ff4ea38d3359e9028 (diff)
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>
Diffstat (limited to 'src/plugins/resourceeditor/resourceeditorplugin.cpp')
-rw-r--r--src/plugins/resourceeditor/resourceeditorplugin.cpp44
1 files changed, 44 insertions, 0 deletions
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,