summaryrefslogtreecommitdiff
path: root/src/plugins/resourceeditor
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@nokia.com>2011-12-09 12:23:46 +0100
committerEike Ziller <eike.ziller@nokia.com>2011-12-13 10:09:58 +0100
commit1899a3838f012a43abaeba3959c1b591649fde1e (patch)
treecc4732c9eff37f554f89185d8e4e66e68a55e0c3 /src/plugins/resourceeditor
parentcfcb7e3101f69e18a7e2dfdba86349ec16db8610 (diff)
downloadqt-creator-1899a3838f012a43abaeba3959c1b591649fde1e.tar.gz
Provide "Open with" context menu in qrc editor.
Task-number: QTCREATORBUG-4224 Change-Id: If2b13fa8b58779058d483d532c2c9649f7fa8dfd Reviewed-by: Jarek Kobus <jaroslaw.kobus@nokia.com>
Diffstat (limited to 'src/plugins/resourceeditor')
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.cpp25
-rw-r--r--src/plugins/resourceeditor/resourceeditorw.h7
2 files changed, 30 insertions, 2 deletions
diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp
index 6ad8ec4b03..a7fa3eadee 100644
--- a/src/plugins/resourceeditor/resourceeditorw.cpp
+++ b/src/plugins/resourceeditor/resourceeditorw.cpp
@@ -38,6 +38,7 @@
#include <coreplugin/icore.h>
#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/filemanager.h>
#include <utils/reloadpromptutils.h>
#include <utils/fileutils.h>
@@ -45,8 +46,9 @@
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtCore/qdebug.h>
-#include <QtGui/QMainWindow>
#include <QtGui/QHBoxLayout>
+#include <QtGui/QMainWindow>
+#include <QtGui/QMenu>
namespace ResourceEditor {
namespace Internal {
@@ -77,16 +79,27 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context,
m_resourceFile(new ResourceEditorFile(this)),
m_plugin(plugin),
m_shouldAutoSave(false),
- m_diskIo(false)
+ m_diskIo(false),
+ m_contextMenu(new QMenu)
{
setContext(context);
setWidget(m_resourceEditor);
m_resourceEditor->setResourceDragEnabled(true);
+ m_openWithMenu = m_contextMenu->addMenu(tr("Open With"));
+ // 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
+ // in that case.)
+ connect(m_openWithMenu, SIGNAL(triggered(QAction*)),
+ Core::FileManager::instance(), SLOT(executeOpenWithMenuAction(QAction*)),
+ Qt::QueuedConnection);
connect(m_resourceEditor, SIGNAL(dirtyChanged(bool)), this, SLOT(dirtyChanged(bool)));
connect(m_resourceEditor, SIGNAL(undoStackChanged(bool, bool)),
this, SLOT(onUndoStackChanged(bool, bool)));
+ connect(m_resourceEditor, SIGNAL(showContextMenu(QPoint,QString)),
+ this, SLOT(showContextMenu(QPoint,QString)));
connect(m_resourceEditor->commandHistory(), SIGNAL(indexChanged(int)),
this, SLOT(setShouldAutoSave()));
connect(m_resourceFile, SIGNAL(changed()), this, SIGNAL(changed()));
@@ -98,6 +111,7 @@ ResourceEditorW::~ResourceEditorW()
{
if (m_resourceEditor)
m_resourceEditor->deleteLater();
+ delete m_contextMenu;
}
bool ResourceEditorW::createNew(const QString &contents)
@@ -264,6 +278,13 @@ void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo)
m_plugin->onUndoStackChanged(this, canUndo, canRedo);
}
+void ResourceEditorW::showContextMenu(const QPoint &globalPoint, const QString &fileName)
+{
+ Core::FileManager::populateOpenWithMenu(m_openWithMenu, fileName);
+ if (!m_openWithMenu->actions().isEmpty())
+ m_contextMenu->popup(globalPoint);
+}
+
void ResourceEditorW::onUndo()
{
if (!m_resourceEditor.isNull())
diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h
index ac13330ce2..5b24ac5320 100644
--- a/src/plugins/resourceeditor/resourceeditorw.h
+++ b/src/plugins/resourceeditor/resourceeditorw.h
@@ -38,6 +38,10 @@
#include <QtCore/QPointer>
+QT_BEGIN_NAMESPACE
+class QMenu;
+QT_END_NAMESPACE
+
namespace SharedTools {
class QrcEditor;
}
@@ -104,6 +108,7 @@ private slots:
void dirtyChanged(bool);
void onUndoStackChanged(bool canUndo, bool canRedo);
void setShouldAutoSave(bool sad = true) { m_shouldAutoSave = sad; }
+ void showContextMenu(const QPoint &globalPoint, const QString &fileName);
private:
const QString m_extension;
@@ -115,6 +120,8 @@ private:
ResourceEditorPlugin *m_plugin;
bool m_shouldAutoSave;
bool m_diskIo;
+ QMenu *m_contextMenu;
+ QMenu *m_openWithMenu;
public:
void onUndo();