Commit e33508b2 authored by con's avatar con

Add "Close all except 'foo.bar'" action.

parent 38d7c52d
......@@ -130,6 +130,7 @@ const char * const SAVEASDEFAULT = "QtCreator.SaveAsDefaultLayout";
const char * const RESTOREDEFAULT = "QtCreator.RestoreDefaultLayout";
const char * const CLOSE = "QtCreator.Close";
const char * const CLOSEALL = "QtCreator.CloseAll";
const char * const CLOSEOTHERS = "QtCreator.CloseOthers";
const char * const GOTONEXT = "QtCreator.GotoNext";
const char * const GOTOPREV = "QtCreator.GotoPrevious";
const char * const GOTONEXTINHISTORY = "QtCreator.GotoNextInHistory";
......
......@@ -149,6 +149,7 @@ struct EditorManagerPrivate {
QAction *m_saveAsAction;
QAction *m_closeCurrentEditorAction;
QAction *m_closeAllEditorsAction;
QAction *m_closeOtherEditorsAction;
QAction *m_gotoNextDocHistoryAction;
QAction *m_gotoPreviousDocHistoryAction;
QAction *m_goBackAction;
......@@ -187,6 +188,7 @@ EditorManagerPrivate::EditorManagerPrivate(ICore *core, QWidget *parent) :
m_saveAsAction(new QAction(parent)),
m_closeCurrentEditorAction(new QAction(EditorManager::tr("Close"), parent)),
m_closeAllEditorsAction(new QAction(EditorManager::tr("Close All"), parent)),
m_closeOtherEditorsAction(new QAction(EditorManager::tr("Close Others"), parent)),
m_gotoNextDocHistoryAction(new QAction(EditorManager::tr("Next Document in History"), parent)),
m_gotoPreviousDocHistoryAction(new QAction(EditorManager::tr("Previous Document in History"), parent)),
m_goBackAction(new QAction(EditorManager::tr("Go back"), parent)),
......@@ -292,6 +294,12 @@ EditorManager::EditorManager(ICore *core, QWidget *parent) :
mfile->addAction(cmd, Constants::G_FILE_CLOSE);
connect(m_d->m_closeAllEditorsAction, SIGNAL(triggered()), this, SLOT(closeAllEditors()));
//Close All Others Action
cmd = am->registerAction(m_d->m_closeOtherEditorsAction, Constants::CLOSEOTHERS, editManagerContext);
mfile->addAction(cmd, Constants::G_FILE_CLOSE);
cmd->setAttribute(Core::Command::CA_UpdateText);
connect(m_d->m_closeOtherEditorsAction, SIGNAL(triggered()), this, SLOT(closeOtherEditors()));
// Goto Previous In History Action
cmd = am->registerAction(m_d->m_gotoPreviousDocHistoryAction, Constants::GOTOPREVINHISTORY, editManagerContext);
#ifdef Q_WS_MAC
......@@ -648,6 +656,16 @@ bool EditorManager::closeAllEditors(bool askAboutModifiedEditors)
return closeEditors(openedEditors(), askAboutModifiedEditors);
}
void EditorManager::closeOtherEditors()
{
IEditor *current = currentEditor();
QTC_ASSERT(current, return);
m_d->m_editorModel->removeAllRestoredEditors();
QList<IEditor*> editors = openedEditors();
editors.removeAll(current);
closeEditors(editors, true);
}
bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askAboutModifiedEditors)
{
if (editorsToClose.isEmpty())
......@@ -1331,7 +1349,7 @@ void EditorManager::updateActions()
{
QString fName;
IEditor *curEditor = currentEditor();
int openedCount = openedEditors().count();
int openedCount = openedEditors().count() + m_d->m_editorModel->restoredEditorCount();
if (curEditor) {
if (!curEditor->file()->fileName().isEmpty()) {
QFileInfo fi(curEditor->file()->fileName());
......@@ -1367,6 +1385,8 @@ void EditorManager::updateActions()
m_d->m_closeCurrentEditorAction->setEnabled(curEditor != 0);
m_d->m_closeCurrentEditorAction->setText(tr("Close %1").arg(quotedName));
m_d->m_closeAllEditorsAction->setEnabled(openedCount > 0);
m_d->m_closeOtherEditorsAction->setEnabled(openedCount > 1);
m_d->m_closeOtherEditorsAction->setText((openedCount > 1 ? tr("Close All Except %1").arg(quotedName) : tr("Close Others")));
m_d->m_gotoNextDocHistoryAction->setEnabled(m_d->m_editorHistory.count() > 0);
m_d->m_gotoPreviousDocHistoryAction->setEnabled(m_d->m_editorHistory.count() > 0);
......
......@@ -198,6 +198,7 @@ private slots:
bool saveFile(Core::IEditor *editor = 0);
bool saveFileAs(Core::IEditor *editor = 0);
void closeEditor();
void closeOtherEditors();
void gotoNextDocHistory();
void gotoPreviousDocHistory();
......
......@@ -205,6 +205,17 @@ void EditorModel::removeAllRestoredEditors()
}
}
int EditorModel::restoredEditorCount() const
{
int count = 0;
for (int i = m_editors.count()-1; i >= 0; --i) {
if (!m_editors.at(i).editor) {
++count;
}
}
return count;
}
bool EditorModel::isDuplicate(IEditor *editor) const
{
return m_duplicateEditors.contains(editor);
......
......@@ -89,6 +89,7 @@ public:
void removeEditor(const QModelIndex &index);
void removeAllRestoredEditors();
int restoredEditorCount() const;
void emitDataChanged(IEditor *editor);
QList<IEditor *> editors() const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment