Commit 1ce34736 authored by Lasse Holmstedt's avatar Lasse Holmstedt

Fixed toolbar for splitted editors

parent 43f9c27b
......@@ -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
......
......@@ -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; }
......
......@@ -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);
......
......@@ -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;
};
}
......
......@@ -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);
......
......@@ -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);
......
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