diff --git a/src/plugins/coreplugin/filemanager.cpp b/src/plugins/coreplugin/filemanager.cpp index 52be854cd894e1a52ac57639ae2155f7dffc9b11..2e4391260a9c44ddbce7ebb1bacce6292318ea99 100644 --- a/src/plugins/coreplugin/filemanager.cpp +++ b/src/plugins/coreplugin/filemanager.cpp @@ -1333,6 +1333,7 @@ void FileManager::populateOpenWithMenu(QMenu *menu, const QString &fileName) void FileManager::executeOpenWithMenuAction(QAction *action) { + QTC_ASSERT(action, return); EditorManager *em = EditorManager::instance(); const QVariant data = action->data(); Internal::OpenWithEntry entry = qVariantValue<Internal::OpenWithEntry>(data); diff --git a/src/plugins/coreplugin/filemanager.h b/src/plugins/coreplugin/filemanager.h index 65218d4bf408d13decf4ad3fd6ddf3f94e35e066..9b91198440f40e8098fd5aac74dfc13ed2cd46e8 100644 --- a/src/plugins/coreplugin/filemanager.h +++ b/src/plugins/coreplugin/filemanager.h @@ -138,13 +138,14 @@ public: void setProjectsDirectory(const QString &); static void populateOpenWithMenu(QMenu *menu, const QString &fileName); - static void executeOpenWithMenuAction(QAction *action); public slots: /* Used to notify e.g. the code model to update the given files. Does *not* lead to any editors to reload or any other editor manager actions. */ void notifyFilesChangedInternally(const QStringList &files); + void executeOpenWithMenuAction(QAction *action); + signals: void currentFileChanged(const QString &filePath); /* Used to notify e.g. the code model to update the given files. Does *not* diff --git a/src/plugins/projectexplorer/foldernavigationwidget.cpp b/src/plugins/projectexplorer/foldernavigationwidget.cpp index d0c359a1d4acca350275cc27eaeb04feac641967..4a54fa21c423b59729caf99cc7d1572d88bfddd0 100644 --- a/src/plugins/projectexplorer/foldernavigationwidget.cpp +++ b/src/plugins/projectexplorer/foldernavigationwidget.cpp @@ -361,7 +361,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev) findOnFileSystem(info.absolutePath()); return; } - Core::FileManager::executeOpenWithMenuAction(action); + Core::FileManager::instance()->executeOpenWithMenuAction(action); } QString FolderNavigationWidget::msgFindOnFileSystem() diff --git a/src/plugins/projectexplorer/projectexplorer.cpp b/src/plugins/projectexplorer/projectexplorer.cpp index 13f091d400a5350b3553941f0b95dc8fe813cde0..57304c0306e670021d7e386bb1fa3bb8855fb896 100644 --- a/src/plugins/projectexplorer/projectexplorer.cpp +++ b/src/plugins/projectexplorer/projectexplorer.cpp @@ -515,7 +515,7 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er d->m_openWithMenu->setTitle(tr("Open With")); connect(d->m_openWithMenu, SIGNAL(triggered(QAction *)), - this, SLOT(openWithMenuTriggered(QAction *))); + Core::FileManager::instance(), SLOT(executeOpenWithMenuAction(QAction*))); // // Separators @@ -2785,14 +2785,6 @@ void ProjectExplorerPlugin::populateOpenWithMenu() Core::FileManager::populateOpenWithMenu(d->m_openWithMenu, currentNode()->path()); } -void ProjectExplorerPlugin::openWithMenuTriggered(QAction *action) -{ - if (!action) - qWarning() << "ProjectExplorerPlugin::openWithMenuTriggered no action, can't happen."; - else - Core::FileManager::executeOpenWithMenuAction(action); -} - void ProjectExplorerPlugin::updateSessionMenu() { d->m_sessionMenu->clear(); diff --git a/src/plugins/projectexplorer/projectexplorer.h b/src/plugins/projectexplorer/projectexplorer.h index d59c0356fccf311e894cb6be57518a7739f2fd89..5faad029b816a9d8aa7b6fc3af3e6ad85a483dd9 100644 --- a/src/plugins/projectexplorer/projectexplorer.h +++ b/src/plugins/projectexplorer/projectexplorer.h @@ -176,7 +176,6 @@ private slots: void newProject(); void showSessionManager(); void populateOpenWithMenu(); - void openWithMenuTriggered(QAction *action); void updateSessionMenu(); void setSession(QAction *action); diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp index 6ad8ec4b035ea0dd1f98dc8447297b8c7c5acc6a..a7fa3eadee232c85659c9a113a1a16e0fb50390a 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 ac13330ce2b1d7e7bf6b5fac9c82318283764f33..5b24ac532065ab6932ba317e64bbc62e50c7b25e 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(); diff --git a/src/shared/qrceditor/qrceditor.cpp b/src/shared/qrceditor/qrceditor.cpp index b83368c16ab7fbbefb6aa78ec754f7e0f28b68ba..e06a939ca410101b7fa50ccd7fa45358b6d9b0d4 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(showContextMenu(QPoint,QString)), + this, SIGNAL(showContextMenu(QPoint,QString))); m_treeview->setFocus(); connect(m_ui.aliasText, SIGNAL(textEdited(QString)), diff --git a/src/shared/qrceditor/qrceditor.h b/src/shared/qrceditor/qrceditor.h index d0aae75cfd1739add327f7421e9af50ad74a4af3..117d82decf4401caf4ba07d3f81c19be06c41392 100644 --- a/src/shared/qrceditor/qrceditor.h +++ b/src/shared/qrceditor/qrceditor.h @@ -68,6 +68,7 @@ public: signals: void dirtyChanged(bool dirty); + void showContextMenu(const QPoint &globalPos, const QString &fileName); private slots: void updateCurrent(); diff --git a/src/shared/qrceditor/resourceview.cpp b/src/shared/qrceditor/resourceview.cpp index d34196fffe5f64b0456493849304987c4c17f1df..54d3d3854ed0940d17d4f08ba201b89ca6176c45 100644 --- a/src/shared/qrceditor/resourceview.cpp +++ b/src/shared/qrceditor/resourceview.cpp @@ -182,11 +182,14 @@ ResourceView::ResourceView(QUndoStack *history, QWidget *parent) : { advanceMergeId(); setModel(m_qrcModel); + setContextMenuPolicy(Qt::CustomContextMenu); header()->hide(); connect(m_qrcModel, SIGNAL(dirtyChanged(bool)), this, SIGNAL(dirtyChanged(bool))); + connect(this, SIGNAL(customContextMenuRequested(QPoint)), + this, SLOT(showContextMenu(QPoint))); } ResourceView::~ResourceView() @@ -429,6 +432,15 @@ void ResourceView::changeValue(const QModelIndex &nodeIndex, NodeProperty proper } } +void ResourceView::showContextMenu(const QPoint &pos) +{ + const QModelIndex index = indexAt(pos); + const QString fileName = m_qrcModel->file(index); + if (fileName.isEmpty()) + return; + emit showContextMenu(mapToGlobal(pos), fileName); +} + void ResourceView::advanceMergeId() { m_mergeId++; diff --git a/src/shared/qrceditor/resourceview.h b/src/shared/qrceditor/resourceview.h index 1b62ff968ebc27209dc78e6094981dab0f0e9581..a608608a53723a0e313c6b985983aa5f0d4ffd28 100644 --- a/src/shared/qrceditor/resourceview.h +++ b/src/shared/qrceditor/resourceview.h @@ -130,11 +130,15 @@ protected: signals: void removeItem(); void dirtyChanged(bool b); + void showContextMenu(const QPoint &globalPos, const QString &fileName); public: QString getCurrentValue(NodeProperty property) const; void changeValue(const QModelIndex &nodeIndex, NodeProperty property, const QString &value); +private slots: + void showContextMenu(const QPoint &pos); + private: void addUndoCommand(const QModelIndex &nodeIndex, NodeProperty property, const QString &before, const QString &after);