forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -51,6 +51,9 @@ const char C_RENAME_FILE[] = "ResourceEditor.RenameFile";
|
|||||||
const char C_OPEN_EDITOR[] = "ResourceEditor.OpenEditor";
|
const char C_OPEN_EDITOR[] = "ResourceEditor.OpenEditor";
|
||||||
const char C_OPEN_TEXT_EDITOR[] = "ResourceEditor.OpenTextEditor";
|
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 Constants
|
||||||
} // namespace ResourceEditor
|
} // namespace ResourceEditor
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
|
#include <utils/parameteraction.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
@@ -58,9 +59,14 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
|
#include <QClipboard>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
using namespace ResourceEditor::Internal;
|
using namespace ResourceEditor::Internal;
|
||||||
|
|
||||||
|
static const char resourcePrefix[] = ":";
|
||||||
|
static const char urlPrefix[] = "qrc://";
|
||||||
|
|
||||||
class PrefixLangDialog : public QDialog
|
class PrefixLangDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -145,6 +151,8 @@ bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *err
|
|||||||
Core::Context projectTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE);
|
Core::Context projectTreeContext(ProjectExplorer::Constants::C_PROJECT_TREE);
|
||||||
Core::ActionContainer *folderContextMenu =
|
Core::ActionContainer *folderContextMenu =
|
||||||
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FOLDERCONTEXT);
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FOLDERCONTEXT);
|
||||||
|
Core::ActionContainer *fileContextMenu =
|
||||||
|
Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_FILECONTEXT);
|
||||||
Core::Command *command = 0;
|
Core::Command *command = 0;
|
||||||
|
|
||||||
m_addPrefix = new QAction(tr("Add Prefix..."), this);
|
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);
|
folderContextMenu->addAction(command, ProjectExplorer::Constants::G_FOLDER_FILES);
|
||||||
connect(m_openInTextEditor, SIGNAL(triggered()), this, SLOT(openTextEditorContextMenu()));
|
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_addPrefix->setEnabled(false);
|
||||||
m_removePrefix->setEnabled(false);
|
m_removePrefix->setEnabled(false);
|
||||||
m_renamePrefix->setEnabled(false);
|
m_renamePrefix->setEnabled(false);
|
||||||
@@ -268,6 +288,18 @@ void ResourceEditorPlugin::openTextEditorContextMenu()
|
|||||||
Core::EditorManager::openEditor(path, Core::Constants::K_DEFAULT_TEXT_EDITOR_ID);
|
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()
|
void ResourceEditorPlugin::renamePrefixContextMenu()
|
||||||
{
|
{
|
||||||
ResourceFolderNode *rfn = static_cast<ResourceFolderNode *>(ProjectExplorer::ProjectExplorerPlugin::instance()->currentNode());
|
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->setEnabled(isResourceFolder);
|
||||||
m_renamePrefix->setVisible(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,
|
void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor,
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ class Node;
|
|||||||
class Project;
|
class Project;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Utils { class ParameterAction; }
|
||||||
|
|
||||||
namespace ResourceEditor {
|
namespace ResourceEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -74,6 +76,9 @@ private slots:
|
|||||||
void openEditorContextMenu();
|
void openEditorContextMenu();
|
||||||
void openTextEditorContextMenu();
|
void openTextEditorContextMenu();
|
||||||
|
|
||||||
|
void copyPathContextMenu();
|
||||||
|
void copyUrlContextMenu();
|
||||||
|
|
||||||
void updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*);
|
void updateContextActions(ProjectExplorer::Node*,ProjectExplorer::Project*);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -97,6 +102,10 @@ private:
|
|||||||
|
|
||||||
QAction *m_openInEditor;
|
QAction *m_openInEditor;
|
||||||
QAction *m_openInTextEditor;
|
QAction *m_openInTextEditor;
|
||||||
|
|
||||||
|
// file context menu
|
||||||
|
Utils::ParameterAction *m_copyPath;
|
||||||
|
Utils::ParameterAction *m_copyUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
|
|||||||
@@ -150,14 +150,19 @@ void ResourceTopLevelNode::update()
|
|||||||
int filecount = file.fileCount(i);
|
int filecount = file.fileCount(i);
|
||||||
for (int j = 0; j < filecount; ++j) {
|
for (int j = 0; j < filecount; ++j) {
|
||||||
const QString &fileName = file.file(i, 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)) {
|
if (fileNames.contains(fileName)) {
|
||||||
// The file name is duplicated, skip it
|
// The file name is duplicated, skip it
|
||||||
// Note: this is wrong, but the qrceditor doesn't allow it either
|
// Note: this is wrong, but the qrceditor doesn't allow it either
|
||||||
// only aliases need to be unique
|
// only aliases need to be unique
|
||||||
} else {
|
} else {
|
||||||
|
const QString qrcPath = QDir::cleanPath(prefix + QLatin1Char('/') + alias);
|
||||||
fileNames.insert(fileName);
|
fileNames.insert(fileName);
|
||||||
filesToAdd[qMakePair(prefix, lang)]
|
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;
|
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),
|
: ProjectExplorer::FileNode(filePath, ProjectExplorer::UnknownFileType, false),
|
||||||
m_topLevel(topLevel)
|
m_topLevel(topLevel),
|
||||||
|
m_qrcPath(qrcPath)
|
||||||
|
|
||||||
{
|
{
|
||||||
QString baseDir = QFileInfo(topLevel->path()).absolutePath();
|
QString baseDir = QFileInfo(topLevel->path()).absolutePath();
|
||||||
@@ -491,3 +497,8 @@ QString ResourceFileNode::displayName() const
|
|||||||
{
|
{
|
||||||
return m_displayName;
|
return m_displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ResourceFileNode::qrcPath() const
|
||||||
|
{
|
||||||
|
return m_qrcPath;
|
||||||
|
}
|
||||||
|
|||||||
@@ -101,13 +101,15 @@ class ResourceFileNode : public ProjectExplorer::FileNode
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ResourceFileNode(const QString &filePath, ResourceTopLevelNode *topLevel);
|
ResourceFileNode(const QString &filePath, const QString &qrcPath, ResourceTopLevelNode *topLevel);
|
||||||
|
|
||||||
QString displayName() const;
|
QString displayName() const;
|
||||||
|
QString qrcPath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_displayName;
|
|
||||||
ResourceTopLevelNode *m_topLevel;
|
ResourceTopLevelNode *m_topLevel;
|
||||||
|
QString m_displayName;
|
||||||
|
QString m_qrcPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ResourceFileWatcher : public Core::IDocument
|
class ResourceFileWatcher : public Core::IDocument
|
||||||
|
|||||||
Reference in New Issue
Block a user