Commit da3e3200 authored by Konstantin Tokarev's avatar Konstantin Tokarev Committed by Eike Ziller
Browse files

ResourceEditor: copy current resource path to clipboard



This menu action provides easy way to insert references to resources
into source code.

Change-Id: I3a77910e82c6ef896cac8a2562d59bb9db78efa2
Reviewed-by: default avatarEike Ziller <eike.ziller@nokia.com>
parent c81a4000
......@@ -354,6 +354,11 @@ void QrcEditor::editCurrentItem()
m_treeview->edit(m_treeview->selectionModel()->currentIndex());
}
QString QrcEditor::currentResourcePath() const
{
return m_treeview->currentResourcePath();
}
// Slot for change of line edit content 'alias'
void QrcEditor::onAliasChanged(const QString &alias)
{
......
......@@ -68,6 +68,8 @@ public:
void refresh();
void editCurrentItem();
QString currentResourcePath() const;
signals:
void dirtyChanged(bool dirty);
void itemActivated(const QString &fileName);
......
......@@ -244,10 +244,10 @@ public:
QString absolutePath(const QString &path) const
{ return m_resource_file.absolutePath(path); }
private:
QString relativePath(const QString &path) const
{ return m_resource_file.relativePath(path); }
private:
QString lastResourceOpenDirectory() const;
bool renameFile(const QString &fileName, const QString &newFileName);
......
......@@ -438,6 +438,19 @@ QString ResourceView::currentLanguage() const
return m_qrcModel->lang(preindex);
}
QString ResourceView::currentResourcePath() const
{
const QModelIndex current = currentIndex();
if (!current.isValid())
return QString();
const QString alias = m_qrcModel->alias(current);
if (!alias.isEmpty())
return QLatin1Char(':') + currentPrefix() + QLatin1Char('/') + alias;
return QLatin1Char(':') + currentPrefix() + QLatin1Char('/') + m_qrcModel->relativePath(m_qrcModel->file(current));
}
QString ResourceView::getCurrentValue(NodeProperty property) const
{
switch (property) {
......
......@@ -100,6 +100,7 @@ public:
QString currentAlias() const;
QString currentPrefix() const;
QString currentLanguage() const;
QString currentResourcePath() const;
void setResourceDragEnabled(bool e);
bool resourceDragEnabled() const;
......
......@@ -52,7 +52,7 @@
#include <QMenu>
#include <QToolBar>
#include <QInputDialog>
#include <QMessageBox>
#include <QClipboard>
namespace ResourceEditor {
namespace Internal {
......@@ -102,7 +102,9 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
m_resourceEditor->setResourceDragEnabled(true);
m_contextMenu->addAction(tr("Open File"), this, SLOT(openCurrentFile()));
m_openWithMenu = m_contextMenu->addMenu(tr("Open With"));
m_renameAction = m_contextMenu->addAction(tr("Rename File..."), this, SLOT(renameCurrentFile()), Qt::Key_F2);
m_renameAction = m_contextMenu->addAction(tr("Rename File..."), this, SLOT(renameCurrentFile()));
m_copyFileNameAction = m_contextMenu->addAction(tr("Copy Resource Path to Clipboard"), this, SLOT(copyCurrentResourcePath()));
// Below we need QueuedConnection because otherwise, if this qrc file
// is inside of the qrc file, crashes happen when using "Open With" on it.
// (That is because this editor instance is deleted in executeOpenWithMenuAction
......@@ -323,6 +325,11 @@ void ResourceEditorW::renameCurrentFile()
m_resourceEditor->editCurrentItem();
}
void ResourceEditorW::copyCurrentResourcePath()
{
QApplication::clipboard()->setText(m_resourceEditor->currentResourcePath());
}
void ResourceEditorW::onUndo()
{
m_resourceEditor->onUndo();
......
......@@ -105,6 +105,7 @@ private slots:
void openCurrentFile();
void openFile(const QString &fileName);
void renameCurrentFile();
void copyCurrentResourcePath();
private:
const QString m_extension;
......@@ -121,6 +122,7 @@ private:
QString m_currentFileName;
QToolBar *m_toolBar;
QAction *m_renameAction;
QAction *m_copyFileNameAction;
public slots:
void onRefresh();
......
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