diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 8ba3a2590ea..1d17d42e31c 100644 --- a/src/plugins/resourceeditor/resourceeditorw.cpp +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -92,6 +92,7 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context, agg->add(new Find::TreeViewFind(m_resourceEditor->treeView())); m_resourceEditor->setResourceDragEnabled(true); + m_contextMenu->addAction(tr("Open File"), this, SLOT(openCurrentFile())); 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. @@ -106,6 +107,8 @@ ResourceEditorW::ResourceEditorW(const Core::Context &context, this, SLOT(onUndoStackChanged(bool,bool))); connect(m_resourceEditor, SIGNAL(showContextMenu(QPoint,QString)), this, SLOT(showContextMenu(QPoint,QString))); + connect(m_resourceEditor, SIGNAL(itemActivated(QString)), + this, SLOT(openFile(QString))); connect(m_resourceEditor->commandHistory(), SIGNAL(indexChanged(int)), this, SLOT(setShouldAutoSave())); connect(m_resourceDocument, SIGNAL(changed()), this, SIGNAL(changed())); @@ -280,8 +283,20 @@ void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo) void ResourceEditorW::showContextMenu(const QPoint &globalPoint, const QString &fileName) { Core::DocumentManager::populateOpenWithMenu(m_openWithMenu, fileName); - if (!m_openWithMenu->actions().isEmpty()) + if (!m_openWithMenu->actions().isEmpty()) { + m_currentFileName = fileName; m_contextMenu->popup(globalPoint); + } +} + +void ResourceEditorW::openCurrentFile() +{ + openFile(m_currentFileName); +} + +void ResourceEditorW::openFile(const QString &fileName) +{ + Core::EditorManager::openEditor(fileName); } void ResourceEditorW::onUndo() diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h index d74a97711d3..fc16ceb8116 100644 --- a/src/plugins/resourceeditor/resourceeditorw.h +++ b/src/plugins/resourceeditor/resourceeditorw.h @@ -108,6 +108,8 @@ private slots: void onUndoStackChanged(bool canUndo, bool canRedo); void setShouldAutoSave(bool sad = true) { m_shouldAutoSave = sad; } void showContextMenu(const QPoint &globalPoint, const QString &fileName); + void openCurrentFile(); + void openFile(const QString &fileName); private: const QString m_extension; @@ -121,6 +123,7 @@ private: bool m_diskIo; QMenu *m_contextMenu; QMenu *m_openWithMenu; + QString m_currentFileName; public: void onUndo(); diff --git a/src/shared/qrceditor/qrceditor.cpp b/src/shared/qrceditor/qrceditor.cpp index 0896574e284..8a60fae2851 100644 --- a/src/shared/qrceditor/qrceditor.cpp +++ b/src/shared/qrceditor/qrceditor.cpp @@ -66,6 +66,8 @@ QrcEditor::QrcEditor(QWidget *parent) connect(m_treeview->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(updateCurrent())); connect(m_treeview, SIGNAL(dirtyChanged(bool)), this, SIGNAL(dirtyChanged(bool))); + connect(m_treeview, SIGNAL(itemActivated(QString)), + this, SIGNAL(itemActivated(QString))); connect(m_treeview, SIGNAL(showContextMenu(QPoint,QString)), this, SIGNAL(showContextMenu(QPoint,QString))); m_treeview->setFocus(); diff --git a/src/shared/qrceditor/qrceditor.h b/src/shared/qrceditor/qrceditor.h index 45d02966a61..b026c12b950 100644 --- a/src/shared/qrceditor/qrceditor.h +++ b/src/shared/qrceditor/qrceditor.h @@ -69,6 +69,7 @@ public: signals: void dirtyChanged(bool dirty); + void itemActivated(const QString &fileName); void showContextMenu(const QPoint &globalPos, const QString &fileName); private slots: diff --git a/src/shared/qrceditor/resourceview.cpp b/src/shared/qrceditor/resourceview.cpp index 7590af1abee..19465ceba94 100644 --- a/src/shared/qrceditor/resourceview.cpp +++ b/src/shared/qrceditor/resourceview.cpp @@ -190,6 +190,8 @@ ResourceView::ResourceView(QUndoStack *history, QWidget *parent) : this, SIGNAL(dirtyChanged(bool))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showContextMenu(QPoint))); + connect(this, SIGNAL(activated(QModelIndex)), + this, SLOT(itemActivated(QModelIndex))); } ResourceView::~ResourceView() @@ -432,6 +434,14 @@ void ResourceView::changeValue(const QModelIndex &nodeIndex, NodeProperty proper } } +void ResourceView::itemActivated(const QModelIndex &index) +{ + const QString fileName = m_qrcModel->file(index); + if (fileName.isEmpty()) + return; + emit itemActivated(fileName); +} + void ResourceView::showContextMenu(const QPoint &pos) { const QModelIndex index = indexAt(pos); diff --git a/src/shared/qrceditor/resourceview.h b/src/shared/qrceditor/resourceview.h index 5cda89c904b..3ca9999d0e6 100644 --- a/src/shared/qrceditor/resourceview.h +++ b/src/shared/qrceditor/resourceview.h @@ -130,6 +130,7 @@ protected: signals: void removeItem(); void dirtyChanged(bool b); + void itemActivated(const QString &fileName); void showContextMenu(const QPoint &globalPos, const QString &fileName); public: @@ -137,6 +138,7 @@ public: void changeValue(const QModelIndex &nodeIndex, NodeProperty property, const QString &value); private slots: + void itemActivated(const QModelIndex &index); void showContextMenu(const QPoint &pos); private: