forked from qt-creator/qt-creator
Add Close/Close Others/Close All items to editor list's context menu
Move the context menu actions from the "Open Documents" pane to the editor manager and use these for both the open documents pane and the editor combo box in the editor tool bar. Change-Id: If2a8cb4cf0498c78bd06053919b3cb74692b7cd8 Reviewed-on: http://codereview.qt.nokia.com/2973 Reviewed-by: Eike Ziller <eike.ziller@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
This commit is contained in:
@@ -214,6 +214,11 @@ struct EditorManagerPrivate {
|
||||
QAction *m_removeAllSplitsAction;
|
||||
QAction *m_gotoOtherSplitAction;
|
||||
|
||||
QAction *m_closeCurrentEditorContextAction;
|
||||
QAction *m_closeAllEditorsContextAction;
|
||||
QAction *m_closeOtherEditorsContextAction;
|
||||
QModelIndex m_contextMenuEditorIndex;
|
||||
|
||||
Internal::OpenEditorsWindow *m_windowPopup;
|
||||
Internal::EditorClosingCoreListener *m_coreListener;
|
||||
|
||||
@@ -246,6 +251,9 @@ EditorManagerPrivate::EditorManagerPrivate(ICore *core, QWidget *parent) :
|
||||
m_gotoPreviousDocHistoryAction(new QAction(EditorManager::tr("Previous Open Document in History"), parent)),
|
||||
m_goBackAction(new QAction(QIcon(QLatin1String(Constants::ICON_PREV)), EditorManager::tr("Go Back"), parent)),
|
||||
m_goForwardAction(new QAction(QIcon(QLatin1String(Constants::ICON_NEXT)), EditorManager::tr("Go Forward"), parent)),
|
||||
m_closeCurrentEditorContextAction(new QAction(EditorManager::tr("Close"), parent)),
|
||||
m_closeAllEditorsContextAction(new QAction(EditorManager::tr("Close All"), parent)),
|
||||
m_closeOtherEditorsContextAction(new QAction(EditorManager::tr("Close Others"), parent)),
|
||||
m_windowPopup(0),
|
||||
m_coreListener(0),
|
||||
m_reloadSetting(IFile::AlwaysAsk),
|
||||
@@ -348,6 +356,11 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
|
||||
cmd->setAttribute(Core::Command::CA_UpdateText);
|
||||
connect(m_d->m_closeOtherEditorsAction, SIGNAL(triggered()), this, SLOT(closeOtherEditors()));
|
||||
|
||||
// Close XXX Context Actions
|
||||
connect(m_d->m_closeAllEditorsContextAction, SIGNAL(triggered()), this, SLOT(closeAllEditors()));
|
||||
connect(m_d->m_closeCurrentEditorContextAction, SIGNAL(triggered()), this, SLOT(closeEditorFromContextMenu()));
|
||||
connect(m_d->m_closeOtherEditorsContextAction, SIGNAL(triggered()), this, SLOT(closeOtherEditorsFromContextMenu()));
|
||||
|
||||
// Goto Previous In History Action
|
||||
cmd = am->registerAction(m_d->m_gotoPreviousDocHistoryAction, Constants::GOTOPREVINHISTORY, editDesignContext);
|
||||
#ifdef Q_WS_MAC
|
||||
@@ -751,6 +764,34 @@ void EditorManager::closeEditor()
|
||||
closeEditor(m_d->m_currentEditor);
|
||||
}
|
||||
|
||||
void EditorManager::addCloseEditorActions(QMenu *contextMenu, const QModelIndex &editorIndex)
|
||||
{
|
||||
QTC_ASSERT(contextMenu, return);
|
||||
m_d->m_contextMenuEditorIndex = editorIndex;
|
||||
m_d->m_closeCurrentEditorContextAction->setText(editorIndex.isValid()
|
||||
? tr("Close \"%1\"").arg(editorIndex.data().toString())
|
||||
: tr("Close Editor"));
|
||||
m_d->m_closeOtherEditorsContextAction->setText(editorIndex.isValid()
|
||||
? tr("Close All Except \"%1\"").arg(editorIndex.data().toString())
|
||||
: tr("Close Other Editors"));
|
||||
m_d->m_closeCurrentEditorContextAction->setEnabled(editorIndex.isValid());
|
||||
m_d->m_closeOtherEditorsContextAction->setEnabled(editorIndex.isValid());
|
||||
m_d->m_closeAllEditorsContextAction->setEnabled(!openedEditors().isEmpty());
|
||||
contextMenu->addAction(m_d->m_closeCurrentEditorContextAction);
|
||||
contextMenu->addAction(m_d->m_closeAllEditorsContextAction);
|
||||
contextMenu->addAction(m_d->m_closeOtherEditorsContextAction);
|
||||
}
|
||||
|
||||
void EditorManager::closeEditorFromContextMenu()
|
||||
{
|
||||
closeEditor(m_d->m_contextMenuEditorIndex);
|
||||
}
|
||||
|
||||
void EditorManager::closeOtherEditorsFromContextMenu()
|
||||
{
|
||||
closeOtherEditors(m_d->m_contextMenuEditorIndex.data(Qt::UserRole).value<IEditor *>());
|
||||
}
|
||||
|
||||
void EditorManager::closeEditor(Core::IEditor *editor)
|
||||
{
|
||||
if (!editor)
|
||||
|
||||
@@ -37,8 +37,9 @@
|
||||
|
||||
#include <coreplugin/ifile.h> // enumerations
|
||||
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtCore/QList>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QMenu>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QModelIndex;
|
||||
@@ -190,6 +191,8 @@ public:
|
||||
void setWindowTitleAddition(const QString &addition);
|
||||
QString windowTitleAddition() const;
|
||||
|
||||
void addCloseEditorActions(QMenu *contextMenu, const QModelIndex &editorIndex);
|
||||
|
||||
signals:
|
||||
void currentEditorChanged(Core::IEditor *editor);
|
||||
void currentEditorStateChanged(Core::IEditor *editor);
|
||||
@@ -219,6 +222,9 @@ private slots:
|
||||
void updateVariable(const QString &variable);
|
||||
void autoSave();
|
||||
|
||||
void closeEditorFromContextMenu();
|
||||
void closeOtherEditorsFromContextMenu();
|
||||
|
||||
public slots:
|
||||
void goBackInNavigationHistory();
|
||||
void goForwardInNavigationHistory();
|
||||
|
||||
@@ -204,33 +204,9 @@ void OpenEditorsWidget::closeEditor(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*>());
|
||||
EditorManager::instance()->addCloseEditorActions(&contextMenu, m_ui.editorList->indexAt(pos));
|
||||
contextMenu.exec(m_ui.editorList->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
@@ -289,8 +289,10 @@ void EditorToolBar::listContextMenu(QPoint pos)
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
QMenu menu;
|
||||
menu.addAction(tr("Copy Full Path to Clipboard"));
|
||||
if (menu.exec(d->m_editorList->mapToGlobal(pos))) {
|
||||
QAction *copyPath = menu.addAction(tr("Copy Full Path to Clipboard"));
|
||||
EditorManager::instance()->addCloseEditorActions(&menu, index);
|
||||
QAction *result = menu.exec(d->m_editorList->mapToGlobal(pos));
|
||||
if (result == copyPath) {
|
||||
QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user