diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index e235e09acc933bd1801325fcc988e0760cb84379..1ac5e0ab8c168c241841cdd6256bf6473f9868dc 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -656,17 +656,23 @@ bool EditorManager::closeAllEditors(bool askAboutModifiedEditors) return false; } -void EditorManager::closeOtherEditors() +void EditorManager::closeOtherEditors(IEditor *editor) { - IEditor *current = currentEditor(); - QTC_ASSERT(current, return); m_d->m_editorModel->removeAllRestoredEditors(); QList<IEditor*> editors = openedEditors(); - editors.removeAll(current); + editors.removeAll(editor); closeEditors(editors, true); } +void EditorManager::closeOtherEditors() +{ + IEditor *current = currentEditor(); + QTC_ASSERT(current, return); + closeOtherEditors(current); +} + + // SLOT connected to action // since this is potentially called in the event handler of the editor // we simply postpone it with a single shot timer @@ -691,7 +697,6 @@ void EditorManager::closeEditor(const QModelIndex &index) m_d->m_editorModel->removeEditor(index); } - bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askAboutModifiedEditors) { if (editorsToClose.isEmpty()) diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index b985353116f735f60dcdc42483492271108ed53b..212925a6f7e17efb6183b69c9f2415f6e3793f74 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -131,7 +131,7 @@ public: Internal::EditorModel *openedEditorsModel() const; void activateEditor(const QModelIndex &index, Internal::EditorView *view = 0, OpenEditorFlags = 0); void closeEditor(const QModelIndex &index); - + void closeOtherEditors(IEditor *editor); QList<IEditor*> editorsForFiles(QList<IFile*> files) const; //QList<EditorGroup *> editorGroups() const; diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp index 1a7213b0aa44c776b20036221eef9b5913499599..0eb177167776287332e43e30a0b4f9c8b24cd99e 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp @@ -35,6 +35,7 @@ #include <coreplugin/coreconstants.h> #include <coreplugin/filemanager.h> #include <coreplugin/uniqueidmanager.h> +#include <coreplugin/actionmanager/actionmanager.h> #include <utils/qtcassert.h> #include <QtCore/QTimer> @@ -88,6 +89,10 @@ void OpenEditorsDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o } +//// +// OpenEditorsWidget +//// + OpenEditorsWidget::OpenEditorsWidget() { m_ui.setupUi(this); @@ -110,12 +115,17 @@ OpenEditorsWidget::OpenEditorsWidget() m_ui.editorList->header()->setResizeMode(0, QHeaderView::Stretch); m_ui.editorList->header()->setResizeMode(1, QHeaderView::Fixed); m_ui.editorList->header()->resizeSection(1, 16); + m_ui.editorList->setContextMenuPolicy(Qt::CustomContextMenu); + connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), this, SLOT(updateCurrentItem(Core::IEditor*))); connect(m_ui.editorList, SIGNAL(clicked(QModelIndex)), this, SLOT(handleClicked(QModelIndex))); connect(m_ui.editorList, SIGNAL(pressed(QModelIndex)), this, SLOT(handlePressed(QModelIndex))); + + connect(m_ui.editorList, SIGNAL(customContextMenuRequested(QPoint)), + this, SLOT(contextMenuRequested(QPoint))); } OpenEditorsWidget::~OpenEditorsWidget() @@ -158,6 +168,40 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index) } } +void OpenEditorsWidget::contextMenuRequested(QPoint pos) +{ + const QModelIndex index = m_ui.editorList->indexAt(pos); + QMenu contextMenu; + QAction *closeEditor = contextMenu.addAction( + index.isValid() ? tr("Close %1").arg(index.data().toString()) + : tr("Close Editor")); + QAction *closeOtherEditors = contextMenu.addAction( + index.isValid() ? tr("Close All Except %1").arg(index.data().toString()) + : tr("Close Other Editors")); + QAction *closeAllEditors = contextMenu.addAction(tr("Close All Editors")); + + if (!index.isValid()) { + closeEditor->setEnabled(false); + closeOtherEditors->setEnabled(false); + } + + if (EditorManager::instance()->openedEditors().isEmpty()) + closeAllEditors->setEnabled(false); + + QAction *action = contextMenu.exec(m_ui.editorList->mapToGlobal(pos)); + if (action == 0) + return; + if (action == closeEditor) + EditorManager::instance()->closeEditor(index); + else if (action == closeAllEditors) + EditorManager::instance()->closeAllEditors(); + else if (action == closeOtherEditors) + EditorManager::instance()->closeOtherEditors(index.data(Qt::UserRole).value<Core::IEditor*>()); +} + +/// +// OpenEditorsViewFactory +/// NavigationView OpenEditorsViewFactory::createWidget() { diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.h b/src/plugins/coreplugin/editormanager/openeditorsview.h index a67e0f963fbf6a7d027b78d585dcad606fd580e0..307b699e11a004a0f78b063f21f2c4a84f9dc290 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsview.h +++ b/src/plugins/coreplugin/editormanager/openeditorsview.h @@ -71,6 +71,7 @@ private slots: void handleClicked(const QModelIndex &); void handlePressed(const QModelIndex &); void updateCurrentItem(Core::IEditor*); + void contextMenuRequested(QPoint pos); private: Ui::OpenEditorsView m_ui;