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: Eike Ziller <eike.ziller@nokia.com>
(cherry picked from commit da3e3200af)
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
This commit is contained in:
Konstantin Tokarev
2012-08-06 13:54:01 +04:00
committed by Eike Ziller
parent 41e140da04
commit 804be4d314
7 changed files with 34 additions and 4 deletions

View File

@@ -354,6 +354,11 @@ void QrcEditor::editCurrentItem()
m_treeview->edit(m_treeview->selectionModel()->currentIndex()); m_treeview->edit(m_treeview->selectionModel()->currentIndex());
} }
QString QrcEditor::currentResourcePath() const
{
return m_treeview->currentResourcePath();
}
// Slot for change of line edit content 'alias' // Slot for change of line edit content 'alias'
void QrcEditor::onAliasChanged(const QString &alias) void QrcEditor::onAliasChanged(const QString &alias)
{ {

View File

@@ -68,6 +68,8 @@ public:
void refresh(); void refresh();
void editCurrentItem(); void editCurrentItem();
QString currentResourcePath() const;
signals: signals:
void dirtyChanged(bool dirty); void dirtyChanged(bool dirty);
void itemActivated(const QString &fileName); void itemActivated(const QString &fileName);

View File

@@ -244,10 +244,10 @@ public:
QString absolutePath(const QString &path) const QString absolutePath(const QString &path) const
{ return m_resource_file.absolutePath(path); } { return m_resource_file.absolutePath(path); }
private:
QString relativePath(const QString &path) const QString relativePath(const QString &path) const
{ return m_resource_file.relativePath(path); } { return m_resource_file.relativePath(path); }
private:
QString lastResourceOpenDirectory() const; QString lastResourceOpenDirectory() const;
bool renameFile(const QString &fileName, const QString &newFileName); bool renameFile(const QString &fileName, const QString &newFileName);

View File

@@ -438,6 +438,19 @@ QString ResourceView::currentLanguage() const
return m_qrcModel->lang(preindex); 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 QString ResourceView::getCurrentValue(NodeProperty property) const
{ {
switch (property) { switch (property) {

View File

@@ -100,6 +100,7 @@ public:
QString currentAlias() const; QString currentAlias() const;
QString currentPrefix() const; QString currentPrefix() const;
QString currentLanguage() const; QString currentLanguage() const;
QString currentResourcePath() const;
void setResourceDragEnabled(bool e); void setResourceDragEnabled(bool e);
bool resourceDragEnabled() const; bool resourceDragEnabled() const;

View File

@@ -52,7 +52,7 @@
#include <QMenu> #include <QMenu>
#include <QToolBar> #include <QToolBar>
#include <QInputDialog> #include <QInputDialog>
#include <QMessageBox> #include <QClipboard>
namespace ResourceEditor { namespace ResourceEditor {
namespace Internal { namespace Internal {
@@ -102,7 +102,9 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
m_resourceEditor->setResourceDragEnabled(true); m_resourceEditor->setResourceDragEnabled(true);
m_contextMenu->addAction(tr("Open File"), this, SLOT(openCurrentFile())); m_contextMenu->addAction(tr("Open File"), this, SLOT(openCurrentFile()));
m_openWithMenu = m_contextMenu->addMenu(tr("Open With")); 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 // Below we need QueuedConnection because otherwise, if this qrc file
// is inside of the qrc file, crashes happen when using "Open With" on it. // is inside of the qrc file, crashes happen when using "Open With" on it.
// (That is because this editor instance is deleted in executeOpenWithMenuAction // (That is because this editor instance is deleted in executeOpenWithMenuAction
@@ -323,6 +325,11 @@ void ResourceEditorW::renameCurrentFile()
m_resourceEditor->editCurrentItem(); m_resourceEditor->editCurrentItem();
} }
void ResourceEditorW::copyCurrentResourcePath()
{
QApplication::clipboard()->setText(m_resourceEditor->currentResourcePath());
}
void ResourceEditorW::onUndo() void ResourceEditorW::onUndo()
{ {
m_resourceEditor->onUndo(); m_resourceEditor->onUndo();

View File

@@ -105,6 +105,7 @@ private slots:
void openCurrentFile(); void openCurrentFile();
void openFile(const QString &fileName); void openFile(const QString &fileName);
void renameCurrentFile(); void renameCurrentFile();
void copyCurrentResourcePath();
private: private:
const QString m_extension; const QString m_extension;
@@ -121,6 +122,7 @@ private:
QString m_currentFileName; QString m_currentFileName;
QToolBar *m_toolBar; QToolBar *m_toolBar;
QAction *m_renameAction; QAction *m_renameAction;
QAction *m_copyFileNameAction;
public slots: public slots:
void onRefresh(); void onRefresh();