diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index 32ee75e4feec6cd33e2428e72ffaf015d7666e23..c346fbbc463f4b2bcf53660d750d035a0a1b2db5 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -87,6 +87,8 @@ EditorView::EditorView(QWidget *parent) : { connect(m_toolBar, SIGNAL(goBackClicked()), this, SLOT(goBackInNavigationHistory())); connect(m_toolBar, SIGNAL(goForwardClicked()), this, SLOT(goForwardInNavigationHistory())); + connect(m_toolBar, SIGNAL(closeClicked()), this, SLOT(closeView())); + connect(m_toolBar, SIGNAL(listSelectionActivated(int)), this, SLOT(listSelectionActivated(int))); tl->addWidget(m_toolBar); } { @@ -157,6 +159,14 @@ EditorView::~EditorView() { } + +void EditorView::closeView() +{ + EditorManager *em = CoreImpl::instance()->editorManager(); + if (IEditor *editor = currentEditor()) { + em->closeDuplicate(editor); + } +} void EditorView::showEditorInfoBar(const QString &id, const QString &infoText, const QString &buttonText, @@ -249,6 +259,17 @@ IEditor *EditorView::currentEditor() const return 0; } +void EditorView::listSelectionActivated(int index) +{ + EditorManager *em = CoreImpl::instance()->editorManager(); + QAbstractItemModel *model = EditorManager::instance()->openedEditorsModel(); + if (IEditor *editor = model->data(model->index(index, 0), Qt::UserRole).value<IEditor*>()) { + em->activateEditor(this, editor); + } else { + em->activateEditor(model->index(index, 0), this); + } +} + void EditorView::setCurrentEditor(IEditor *editor) { // FIXME: this keeps the editor hidden if switching from A to B and back diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h index 671bfc79f203132652c9de1d7cc74c6789ee7a96..2ba22fcf6f17526a24701518824f39d11717308d 100644 --- a/src/plugins/coreplugin/editormanager/editorview.h +++ b/src/plugins/coreplugin/editormanager/editorview.h @@ -96,6 +96,10 @@ public: QObject *object, const char *member); void hideEditorStatusBar(const QString &id); +private slots: + void closeView(); + void listSelectionActivated(int index); + private: void updateNavigatorActions(); void updateToolBar(IEditor *editor); @@ -122,7 +126,6 @@ private: int m_currentNavigationHistoryPosition; void updateCurrentPositionInNavigationHistory(); - public: inline bool canGoForward() const { return m_currentNavigationHistoryPosition < m_navigationHistory.size()-1; } inline bool canGoBack() const { return m_currentNavigationHistoryPosition > 0; } diff --git a/src/plugins/coreplugin/editortoolbar.cpp b/src/plugins/coreplugin/editortoolbar.cpp index b9f50bf86c0c3645fd3a4f4920aa7620297a919b..6fa3737cca77b22c85ed3f82faf41bb53adcc9ca 100644 --- a/src/plugins/coreplugin/editortoolbar.cpp +++ b/src/plugins/coreplugin/editortoolbar.cpp @@ -85,7 +85,7 @@ EditorToolBar::EditorToolBar(QWidget *parent) : m_activeToolBar(0), m_toolBarPlaceholder(new QWidget), m_defaultToolBar(new QWidget(this)), - m_ignoreEditorToolbar(false) + m_isStandalone(false) { QHBoxLayout *toolBarLayout = new QHBoxLayout(this); toolBarLayout->setMargin(0); @@ -139,7 +139,10 @@ EditorToolBar::EditorToolBar(QWidget *parent) : setLayout(toplayout); - connect(m_editorList, SIGNAL(activated(int)), this, SLOT(listSelectionActivated(int))); + // this signal is disconnected for standalone toolbars and replaced with + // a private slot connection + connect(m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int))); + connect(m_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint))); connect(m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable())); connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection); @@ -175,9 +178,12 @@ void EditorToolBar::closeView() if (!currentEditor()) return; - EditorManager *em = ICore::instance()->editorManager(); - if (IEditor *editor = currentEditor()) { - em->closeDuplicate(editor); + if (m_isStandalone) { + EditorManager *em = ICore::instance()->editorManager(); + if (IEditor *editor = currentEditor()) { + //em->closeDuplicate(editor); + em->closeEditor(editor); + } } emit closeClicked(); } @@ -187,7 +193,7 @@ void EditorToolBar::addEditor(IEditor *editor) connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus())); QWidget *toolBar = editor->toolBar(); - if (toolBar && !m_ignoreEditorToolbar) + if (toolBar && !m_isStandalone) addCenterToolBar(toolBar); updateEditorStatus(editor); @@ -214,10 +220,13 @@ void EditorToolBar::updateToolBar(QWidget *toolBar) void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags) { - m_ignoreEditorToolbar = flags & FlagsIgnoreIEditorToolBar; - if (m_ignoreEditorToolbar) { + m_isStandalone = flags & FlagsStandalone; + if (m_isStandalone) { EditorManager *em = EditorManager::instance(); connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*))); + + disconnect(m_editorList, SIGNAL(activated(int)), this, SIGNAL(listSelectionActivated(int))); + connect(m_editorList, SIGNAL(activated(int)), this, SLOT(changeActiveEditor(int))); } } @@ -227,7 +236,7 @@ void EditorToolBar::setCurrentEditor(IEditor *editor) // If we never added the toolbar from the editor, we will never change // the editor, so there's no need to update the toolbar either. - if (!m_ignoreEditorToolbar) + if (!m_isStandalone) updateToolBar(editor->toolBar()); updateEditorStatus(editor); @@ -239,12 +248,13 @@ void EditorToolBar::updateEditorListSelection(IEditor *newSelection) m_editorList->setCurrentIndex(m_editorsListModel->indexOf(newSelection).row()); } -void EditorToolBar::listSelectionActivated(int row) +void EditorToolBar::changeActiveEditor(int row) { EditorManager *em = ICore::instance()->editorManager(); QAbstractItemModel *model = m_editorList->model(); const QModelIndex modelIndex = model->index(row, 0); IEditor *editor = model->data(modelIndex, Qt::UserRole).value<IEditor*>(); + if (editor) { if (editor != em->currentEditor()) em->activateEditor(editor, EditorManager::NoModeSwitch); diff --git a/src/plugins/coreplugin/editortoolbar.h b/src/plugins/coreplugin/editortoolbar.h index 9149e26b89f7c582eef2378132c97a308014533f..227a210fe2a2589189b5ec45afdd54d80866b8e2 100644 --- a/src/plugins/coreplugin/editortoolbar.h +++ b/src/plugins/coreplugin/editortoolbar.h @@ -62,7 +62,7 @@ class CORE_EXPORT EditorToolBar : public Utils::StyledBar public: explicit EditorToolBar(QWidget *parent = 0); - enum ToolbarCreationFlags { FlagsNone = 0, FlagsIgnoreIEditorToolBar = 1 }; + enum ToolbarCreationFlags { FlagsNone = 0, FlagsStandalone = 1 }; /** * Adds an editor whose state is listened to, so that the toolbar can be kept up to date @@ -94,10 +94,11 @@ signals: void closeClicked(); void goBackClicked(); void goForwardClicked(); + void listSelectionActivated(int row); private slots: void updateEditorListSelection(Core::IEditor *newSelection); - void listSelectionActivated(int row); + void changeActiveEditor(int row); void listContextMenu(QPoint); void makeEditorWritable(); @@ -123,9 +124,7 @@ private: QWidget *m_toolBarPlaceholder; QWidget *m_defaultToolBar; - bool m_ignoreEditorToolbar; - - friend class Internal::EditorView; + bool m_isStandalone; }; } diff --git a/src/plugins/designer/formeditorw.cpp b/src/plugins/designer/formeditorw.cpp index e4e896dc247734c5b10dbc581eab3fd04a5baee9..657e7b30596c0b6f637f9139f9607aea2533cb93 100644 --- a/src/plugins/designer/formeditorw.cpp +++ b/src/plugins/designer/formeditorw.cpp @@ -314,7 +314,7 @@ void FormEditorW::fullInit() m_editorToolBar = createEditorToolBar(); m_toolBar = Core::EditorManager::createToolBar(); - m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsIgnoreIEditorToolBar); + m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone); m_toolBar->setNavigationVisible(false); m_toolBar->addCenterToolBar(m_editorToolBar); diff --git a/src/plugins/qmldesigner/designmodewidget.cpp b/src/plugins/qmldesigner/designmodewidget.cpp index 13ced6956cd41313d421a2832399663f03b52819..499095bf102f659aee3249a9c335486493bfa636 100644 --- a/src/plugins/qmldesigner/designmodewidget.cpp +++ b/src/plugins/qmldesigner/designmodewidget.cpp @@ -297,7 +297,7 @@ void DocumentWidget::setup() m_designToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); - m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsIgnoreIEditorToolBar); + m_fakeToolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone); m_fakeToolBar->addEditor(textEditor()); m_fakeToolBar->addCenterToolBar(m_designToolBar); m_fakeToolBar->setNavigationVisible(false);