forked from qt-creator/qt-creator
Switch less often to edit mode
This change * Removes IMode::type, ModeManager::activateModeType, and IEditor::preferredModeType, and adds IEditor::isDesignModePreferred instead * Adapts the mode switching code in EditorManager to handle multiple windows, for example switching to edit mode should only happen if the editor/view is in the main window. Otherwise the editor window should be raised and focused * Renames EditorManager::NoActivate --> DoNotChangeCurrentEditor * Reverts the EditorManager::ModeSwitch logic to switch mode or make the current editor visible by default, introducing DoNotMakeVisible flag instead * Fixes a few instances where EditorManager::ModeSwitch should have been used One non-trivial problem left: If you open a .ui file and switch to an external editor window, edit mode is activated, because the current editor no longer is a .ui file, which means that the design mode gets deactivated. Change-Id: I76c5c2391eb4090143b778fb103acff3a5a1ff41 Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -650,7 +650,7 @@ bool BaseFileWizard::postGenerateOpenEditors(const GeneratedFiles &l, QString *e
|
||||
{
|
||||
foreach (const Core::GeneratedFile &file, l) {
|
||||
if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) {
|
||||
if (!Core::EditorManager::openEditor(file.path(), file.editorId(), Core::EditorManager::ModeSwitch )) {
|
||||
if (!Core::EditorManager::openEditor(file.path(), file.editorId())) {
|
||||
if (errorMessage)
|
||||
*errorMessage = tr("Failed to open an editor for '%1'.").arg(QDir::toNativeSeparators(file.path()));
|
||||
return false;
|
||||
|
||||
@@ -120,7 +120,6 @@ DesignMode::DesignMode()
|
||||
setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Design.png")));
|
||||
setPriority(Constants::P_MODE_DESIGN);
|
||||
setId(Constants::MODE_DESIGN);
|
||||
setType(Constants::MODE_DESIGN_TYPE);
|
||||
|
||||
ExtensionSystem::PluginManager::addObject(d->m_coreListener);
|
||||
|
||||
|
||||
@@ -1382,7 +1382,7 @@ void DocumentManager::executeOpenWithMenuAction(QAction *action)
|
||||
return;
|
||||
}
|
||||
|
||||
EditorManager::openEditor(entry.fileName, entry.editorFactory->id(), EditorManager::ModeSwitch);
|
||||
EditorManager::openEditor(entry.fileName, entry.editorFactory->id());
|
||||
return;
|
||||
}
|
||||
if (entry.externalEditor)
|
||||
|
||||
@@ -55,7 +55,6 @@ EditMode::EditMode() :
|
||||
setIcon(QIcon(QLatin1String(":/fancyactionbar/images/mode_Edit.png")));
|
||||
setPriority(Constants::P_MODE_EDIT);
|
||||
setId(Constants::MODE_EDIT);
|
||||
setType(Constants::MODE_EDIT_TYPE);
|
||||
|
||||
m_rightSplitWidgetLayout->setSpacing(0);
|
||||
m_rightSplitWidgetLayout->setMargin(0);
|
||||
|
||||
@@ -698,15 +698,15 @@ void EditorManager::splitNewWindow(Internal::EditorView *view)
|
||||
context->setContext(Context(Constants::C_EDITORMANAGER));
|
||||
context->setWidget(splitter);
|
||||
ICore::addContextObject(context);
|
||||
m_instance->d->m_root.append(splitter);
|
||||
m_instance->d->m_rootContext.append(context);
|
||||
connect(splitter, SIGNAL(destroyed(QObject*)), m_instance, SLOT(rootDestroyed(QObject*)));
|
||||
splitter->show();
|
||||
ICore::raiseWindow(splitter);
|
||||
if (newEditor)
|
||||
m_instance->activateEditor(splitter->view(), newEditor, IgnoreNavigationHistory);
|
||||
else
|
||||
splitter->view()->setFocus();
|
||||
m_instance->d->m_root.append(splitter);
|
||||
m_instance->d->m_rootContext.append(context);
|
||||
connect(splitter, SIGNAL(destroyed(QObject*)), m_instance, SLOT(rootDestroyed(QObject*)));
|
||||
m_instance->updateActions();
|
||||
}
|
||||
|
||||
@@ -1049,15 +1049,15 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
|
||||
if (!newCurrent)
|
||||
newCurrent = pickUnusedEditor();
|
||||
if (newCurrent) {
|
||||
activateEditor(view, newCurrent, NoActivate);
|
||||
activateEditor(view, newCurrent, DoNotChangeCurrentEditor);
|
||||
} else {
|
||||
QModelIndex idx = d->m_editorModel->firstRestoredEditor();
|
||||
if (idx.isValid()) {
|
||||
activateEditorForIndex(view, idx, NoActivate);
|
||||
activateEditorForIndex(view, idx, DoNotChangeCurrentEditor);
|
||||
} else {
|
||||
const QList<IEditor *> editors = d->m_editorModel->editors();
|
||||
if (!editors.isEmpty())
|
||||
activateEditor(view, editors.last(), NoActivate);
|
||||
activateEditor(view, editors.last(), DoNotChangeCurrentEditor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1112,11 +1112,11 @@ void EditorManager::closeDuplicate(Core::IEditor *editor)
|
||||
if (!newCurrent)
|
||||
newCurrent = pickUnusedEditor();
|
||||
if (newCurrent) {
|
||||
activateEditor(view, newCurrent, NoActivate);
|
||||
activateEditor(view, newCurrent, DoNotChangeCurrentEditor);
|
||||
} else {
|
||||
QModelIndex idx = d->m_editorModel->firstRestoredEditor();
|
||||
if (idx.isValid())
|
||||
activateEditorForIndex(view, idx, NoActivate);
|
||||
activateEditorForIndex(view, idx, DoNotChangeCurrentEditor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1221,13 +1221,22 @@ Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, C
|
||||
|
||||
editor = placeEditor(view, editor);
|
||||
|
||||
if (!(flags & NoActivate)) {
|
||||
if (!(flags & DoNotChangeCurrentEditor)) {
|
||||
setCurrentEditor(editor, (flags & IgnoreNavigationHistory));
|
||||
if (flags & ModeSwitch)
|
||||
switchToPreferedMode();
|
||||
if (isVisible()) {
|
||||
editor->widget()->setFocus();
|
||||
ICore::raiseWindow(editor->widget());
|
||||
if (!(flags & DoNotMakeVisible)) {
|
||||
// switch to design mode?
|
||||
if (editor->isDesignModePreferred()) {
|
||||
ModeManager::activateMode(Core::Constants::MODE_DESIGN);
|
||||
ModeManager::setFocusToCurrentMode();
|
||||
} else {
|
||||
int rootIndex;
|
||||
findRoot(view, &rootIndex);
|
||||
if (rootIndex == 0) // main window --> we might need to switch mode
|
||||
if (!editor->widget()->isVisible())
|
||||
ModeManager::activateMode(Core::Constants::MODE_EDIT);
|
||||
editor->widget()->setFocus();
|
||||
ICore::raiseWindow(editor->widget());
|
||||
}
|
||||
}
|
||||
}
|
||||
return editor;
|
||||
@@ -1572,22 +1581,6 @@ QStringList EditorManager::getOpenFileNames() const
|
||||
}
|
||||
|
||||
|
||||
/// Empty mode == figure out the correct mode from the editor
|
||||
/// forcePrefered = true, switch to the mode even if the editor is visible in another mode
|
||||
/// forcePrefered = false, only switch if it is not visible
|
||||
void EditorManager::switchToPreferedMode()
|
||||
{
|
||||
Id preferedMode;
|
||||
// Figure out preferred mode for editor
|
||||
if (d->m_currentEditor)
|
||||
preferedMode = d->m_currentEditor->preferredModeType();
|
||||
|
||||
if (!preferedMode.isValid())
|
||||
preferedMode = Id(Constants::MODE_EDIT_TYPE);
|
||||
|
||||
ModeManager::activateModeType(preferedMode);
|
||||
}
|
||||
|
||||
IEditor *EditorManager::openEditorWithContents(const Id &editorId,
|
||||
QString *titlePattern,
|
||||
const QString &contents)
|
||||
@@ -2191,7 +2184,7 @@ bool EditorManager::restoreState(const QByteArray &state)
|
||||
continue;
|
||||
QFileInfo rfi(autoSaveName(fileName));
|
||||
if (rfi.exists() && fi.lastModified() < rfi.lastModified())
|
||||
openEditor(fileName, id);
|
||||
openEditor(fileName, id, DoNotMakeVisible);
|
||||
else
|
||||
d->m_editorModel->addRestoredEditor(fileName, displayName, id);
|
||||
}
|
||||
|
||||
@@ -107,9 +107,9 @@ public:
|
||||
static EditorToolBar *createToolBar(QWidget *parent = 0);
|
||||
|
||||
enum OpenEditorFlag {
|
||||
NoActivate = 1,
|
||||
DoNotChangeCurrentEditor = 1,
|
||||
IgnoreNavigationHistory = 2,
|
||||
ModeSwitch = 4,
|
||||
DoNotMakeVisible = 4,
|
||||
CanContainLineNumber = 8,
|
||||
OpenInOtherSplit = 16
|
||||
};
|
||||
@@ -278,7 +278,6 @@ private:
|
||||
static void splitNewWindow(Internal::EditorView *view);
|
||||
IEditor *pickUnusedEditor() const;
|
||||
void addDocumentToRecentFiles(IDocument *document);
|
||||
void switchToPreferedMode();
|
||||
void updateAutoSave();
|
||||
void setCloseSplitEnabled(Internal::SplitterOrView *splitterOrView, bool enable);
|
||||
void updateMakeWritableWarning();
|
||||
|
||||
@@ -299,7 +299,7 @@ IEditor *EditorView::currentEditor() const
|
||||
void EditorView::listSelectionActivated(int index)
|
||||
{
|
||||
QAbstractItemModel *model = EditorManager::instance()->openedEditorsModel();
|
||||
EditorManager::instance()->activateEditorForIndex(this, model->index(index, 0), Core::EditorManager::ModeSwitch);
|
||||
EditorManager::instance()->activateEditorForIndex(this, model->index(index, 0));
|
||||
}
|
||||
|
||||
void EditorView::splitHorizontally()
|
||||
@@ -465,11 +465,11 @@ void EditorView::goBackInNavigationHistory()
|
||||
IEditor *editor = 0;
|
||||
if (location.document) {
|
||||
editor = em->activateEditorForDocument(this, location.document,
|
||||
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
|
||||
EditorManager::IgnoreNavigationHistory);
|
||||
}
|
||||
if (!editor) {
|
||||
editor = em->openEditor(this, location.fileName, location.id,
|
||||
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
|
||||
EditorManager::IgnoreNavigationHistory);
|
||||
if (!editor) {
|
||||
m_navigationHistory.removeAt(m_currentNavigationHistoryPosition);
|
||||
continue;
|
||||
@@ -492,7 +492,7 @@ void EditorView::goForwardInNavigationHistory()
|
||||
IEditor *editor = 0;
|
||||
if (location.document) {
|
||||
editor = em->activateEditorForDocument(this, location.document,
|
||||
EditorManager::IgnoreNavigationHistory | EditorManager::ModeSwitch);
|
||||
EditorManager::IgnoreNavigationHistory);
|
||||
}
|
||||
if (!editor) {
|
||||
editor = em->openEditor(this, location.fileName, location.id, EditorManager::IgnoreNavigationHistory);
|
||||
@@ -784,13 +784,13 @@ void SplitterOrView::restoreState(const QByteArray &state)
|
||||
if (!QFile::exists(fileName))
|
||||
return;
|
||||
IEditor *e = em->openEditor(view(), fileName, Id::fromString(id), Core::EditorManager::IgnoreNavigationHistory
|
||||
| Core::EditorManager::NoActivate);
|
||||
| Core::EditorManager::DoNotChangeCurrentEditor);
|
||||
|
||||
if (!e) {
|
||||
QModelIndex idx = em->openedEditorsModel()->firstRestoredEditor();
|
||||
if (idx.isValid())
|
||||
em->activateEditorForIndex(view(), idx, Core::EditorManager::IgnoreNavigationHistory
|
||||
| Core::EditorManager::NoActivate);
|
||||
| Core::EditorManager::DoNotChangeCurrentEditor);
|
||||
}
|
||||
|
||||
if (e) {
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
|
||||
virtual QWidget *toolBar() = 0;
|
||||
|
||||
virtual Id preferredModeType() const { return Id(); }
|
||||
virtual bool isDesignModePreferred() const { return false; }
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
@@ -189,7 +189,7 @@ void OpenEditorsWidget::handleClicked(const QModelIndex &index)
|
||||
void OpenEditorsWidget::activateEditor(const QModelIndex &index)
|
||||
{
|
||||
selectionModel()->select(index, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||
EditorManager::instance()->activateEditorForIndex(index, EditorManager::ModeSwitch);
|
||||
EditorManager::instance()->activateEditorForIndex(index);
|
||||
}
|
||||
|
||||
void OpenEditorsWidget::closeEditor(const QModelIndex &index)
|
||||
|
||||
@@ -225,11 +225,10 @@ void OpenEditorsWindow::selectEditor(QTreeWidgetItem *item)
|
||||
return;
|
||||
if (IDocument *document = item->data(0, Qt::UserRole).value<IDocument*>()) {
|
||||
EditorView *view = item->data(0, Qt::UserRole+1).value<EditorView*>();
|
||||
EditorManager::instance()->activateEditorForDocument(view, document, EditorManager::ModeSwitch);
|
||||
EditorManager::instance()->activateEditorForDocument(view, document);
|
||||
} else {
|
||||
if (!EditorManager::openEditor(
|
||||
item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>(),
|
||||
Core::EditorManager::ModeSwitch)) {
|
||||
item->toolTip(0), item->data(0, Qt::UserRole+2).value<Core::Id>())) {
|
||||
EditorManager::instance()->openedEditorsModel()->removeEditor(item->toolTip(0));
|
||||
delete item;
|
||||
}
|
||||
|
||||
@@ -311,7 +311,7 @@ void EditorToolBar::changeActiveEditor(int row)
|
||||
{
|
||||
EditorManager *em = ICore::editorManager();
|
||||
QAbstractItemModel *model = d->m_editorList->model();
|
||||
em->activateEditorForIndex(model->index(row, 0), EditorManager::ModeSwitch);
|
||||
em->activateEditorForIndex(model->index(row, 0));
|
||||
}
|
||||
|
||||
void EditorToolBar::listContextMenu(QPoint pos)
|
||||
|
||||
@@ -49,7 +49,6 @@ public:
|
||||
QIcon icon() const { return m_icon; }
|
||||
int priority() const { return m_priority; }
|
||||
Id id() const { return m_id; }
|
||||
Id type() const { return m_type; }
|
||||
bool isEnabled() const;
|
||||
|
||||
void setEnabled(bool enabled);
|
||||
@@ -57,7 +56,6 @@ public:
|
||||
void setIcon(const QIcon &icon) { m_icon = icon; }
|
||||
void setPriority(int priority) { m_priority = priority; }
|
||||
void setId(Id id) { m_id = id; }
|
||||
void setType(Id type) { m_type = type; }
|
||||
|
||||
signals:
|
||||
void enabledStateChanged(bool enabled);
|
||||
@@ -67,7 +65,6 @@ private:
|
||||
QIcon m_icon;
|
||||
int m_priority;
|
||||
Id m_id;
|
||||
Id m_type;
|
||||
bool m_isEnabled;
|
||||
};
|
||||
|
||||
|
||||
@@ -861,8 +861,6 @@ IDocument *MainWindow::openFiles(const QStringList &fileNames, ICore::OpenFilesF
|
||||
}
|
||||
} else {
|
||||
QFlags<EditorManager::OpenEditorFlag> emFlags;
|
||||
if (flags & ICore::SwitchMode)
|
||||
emFlags = EditorManager::ModeSwitch;
|
||||
if (flags & ICore::CanContainLineNumbers)
|
||||
emFlags |= EditorManager::CanContainLineNumber;
|
||||
IEditor *editor = EditorManager::openEditor(absoluteFilePath, Id(), emFlags);
|
||||
@@ -1005,7 +1003,7 @@ void MainWindow::openFileWith()
|
||||
if (isExternal)
|
||||
EditorManager::openExternalEditor(fileName, editorId);
|
||||
else
|
||||
EditorManager::openEditor(fileName, editorId, Core::EditorManager::ModeSwitch);
|
||||
EditorManager::openEditor(fileName, editorId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1289,7 +1287,7 @@ void MainWindow::openRecentFile()
|
||||
{
|
||||
if (const QAction *action = qobject_cast<const QAction*>(sender())) {
|
||||
const DocumentManager::RecentFile file = action->data().value<DocumentManager::RecentFile>();
|
||||
EditorManager::openEditor(file.first, file.second, EditorManager::ModeSwitch);
|
||||
EditorManager::openEditor(file.first, file.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -150,21 +150,6 @@ IMode *ModeManager::mode(Id id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModeManager::activateModeType(Id type)
|
||||
{
|
||||
if (currentMode() && currentMode()->type() == type)
|
||||
return;
|
||||
int index = -1;
|
||||
for (int i = 0; i < d->m_modes.count(); ++i) {
|
||||
if (d->m_modes.at(i)->type() == type) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (index != -1)
|
||||
d->m_modeStack->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
void ModeManager::slotActivateMode(int id)
|
||||
{
|
||||
m_instance->activateMode(Id::fromUniqueIdentifier(id));
|
||||
@@ -333,10 +318,10 @@ void ModeManager::setFocusToCurrentMode()
|
||||
QWidget *widget = mode->widget();
|
||||
if (widget) {
|
||||
QWidget *focusWidget = widget->focusWidget();
|
||||
if (focusWidget)
|
||||
focusWidget->setFocus();
|
||||
else
|
||||
widget->setFocus();
|
||||
if (!focusWidget)
|
||||
focusWidget = widget;
|
||||
focusWidget->setFocus();
|
||||
ICore::raiseWindow(focusWidget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ public:
|
||||
static void addProjectSelector(QAction *action);
|
||||
static void addWidget(QWidget *widget);
|
||||
|
||||
static void activateModeType(Id type);
|
||||
static void activateMode(Id id);
|
||||
static void setFocusToCurrentMode();
|
||||
static bool isModeSelectorVisible();
|
||||
|
||||
Reference in New Issue
Block a user