forked from qt-creator/qt-creator
Fixed toolbar for splitted editors
This commit is contained in:
@@ -87,6 +87,8 @@ EditorView::EditorView(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
connect(m_toolBar, SIGNAL(goBackClicked()), this, SLOT(goBackInNavigationHistory()));
|
connect(m_toolBar, SIGNAL(goBackClicked()), this, SLOT(goBackInNavigationHistory()));
|
||||||
connect(m_toolBar, SIGNAL(goForwardClicked()), this, SLOT(goForwardInNavigationHistory()));
|
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);
|
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,
|
void EditorView::showEditorInfoBar(const QString &id,
|
||||||
const QString &infoText,
|
const QString &infoText,
|
||||||
const QString &buttonText,
|
const QString &buttonText,
|
||||||
@@ -249,6 +259,17 @@ IEditor *EditorView::currentEditor() const
|
|||||||
return 0;
|
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)
|
void EditorView::setCurrentEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
// FIXME: this keeps the editor hidden if switching from A to B and back
|
// FIXME: this keeps the editor hidden if switching from A to B and back
|
||||||
|
|||||||
@@ -96,6 +96,10 @@ public:
|
|||||||
QObject *object, const char *member);
|
QObject *object, const char *member);
|
||||||
void hideEditorStatusBar(const QString &id);
|
void hideEditorStatusBar(const QString &id);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void closeView();
|
||||||
|
void listSelectionActivated(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateNavigatorActions();
|
void updateNavigatorActions();
|
||||||
void updateToolBar(IEditor *editor);
|
void updateToolBar(IEditor *editor);
|
||||||
@@ -122,7 +126,6 @@ private:
|
|||||||
int m_currentNavigationHistoryPosition;
|
int m_currentNavigationHistoryPosition;
|
||||||
void updateCurrentPositionInNavigationHistory();
|
void updateCurrentPositionInNavigationHistory();
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline bool canGoForward() const { return m_currentNavigationHistoryPosition < m_navigationHistory.size()-1; }
|
inline bool canGoForward() const { return m_currentNavigationHistoryPosition < m_navigationHistory.size()-1; }
|
||||||
inline bool canGoBack() const { return m_currentNavigationHistoryPosition > 0; }
|
inline bool canGoBack() const { return m_currentNavigationHistoryPosition > 0; }
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
|
|||||||
m_activeToolBar(0),
|
m_activeToolBar(0),
|
||||||
m_toolBarPlaceholder(new QWidget),
|
m_toolBarPlaceholder(new QWidget),
|
||||||
m_defaultToolBar(new QWidget(this)),
|
m_defaultToolBar(new QWidget(this)),
|
||||||
m_ignoreEditorToolbar(false)
|
m_isStandalone(false)
|
||||||
{
|
{
|
||||||
QHBoxLayout *toolBarLayout = new QHBoxLayout(this);
|
QHBoxLayout *toolBarLayout = new QHBoxLayout(this);
|
||||||
toolBarLayout->setMargin(0);
|
toolBarLayout->setMargin(0);
|
||||||
@@ -139,7 +139,10 @@ EditorToolBar::EditorToolBar(QWidget *parent) :
|
|||||||
|
|
||||||
setLayout(toplayout);
|
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_editorList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(listContextMenu(QPoint)));
|
||||||
connect(m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
|
connect(m_lockButton, SIGNAL(clicked()), this, SLOT(makeEditorWritable()));
|
||||||
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection);
|
connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection);
|
||||||
@@ -175,9 +178,12 @@ void EditorToolBar::closeView()
|
|||||||
if (!currentEditor())
|
if (!currentEditor())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
EditorManager *em = ICore::instance()->editorManager();
|
if (m_isStandalone) {
|
||||||
if (IEditor *editor = currentEditor()) {
|
EditorManager *em = ICore::instance()->editorManager();
|
||||||
em->closeDuplicate(editor);
|
if (IEditor *editor = currentEditor()) {
|
||||||
|
//em->closeDuplicate(editor);
|
||||||
|
em->closeEditor(editor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emit closeClicked();
|
emit closeClicked();
|
||||||
}
|
}
|
||||||
@@ -187,7 +193,7 @@ void EditorToolBar::addEditor(IEditor *editor)
|
|||||||
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
|
connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus()));
|
||||||
QWidget *toolBar = editor->toolBar();
|
QWidget *toolBar = editor->toolBar();
|
||||||
|
|
||||||
if (toolBar && !m_ignoreEditorToolbar)
|
if (toolBar && !m_isStandalone)
|
||||||
addCenterToolBar(toolBar);
|
addCenterToolBar(toolBar);
|
||||||
|
|
||||||
updateEditorStatus(editor);
|
updateEditorStatus(editor);
|
||||||
@@ -214,10 +220,13 @@ void EditorToolBar::updateToolBar(QWidget *toolBar)
|
|||||||
|
|
||||||
void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
|
void EditorToolBar::setToolbarCreationFlags(ToolbarCreationFlags flags)
|
||||||
{
|
{
|
||||||
m_ignoreEditorToolbar = flags & FlagsIgnoreIEditorToolBar;
|
m_isStandalone = flags & FlagsStandalone;
|
||||||
if (m_ignoreEditorToolbar) {
|
if (m_isStandalone) {
|
||||||
EditorManager *em = EditorManager::instance();
|
EditorManager *em = EditorManager::instance();
|
||||||
connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*)));
|
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
|
// 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.
|
// the editor, so there's no need to update the toolbar either.
|
||||||
if (!m_ignoreEditorToolbar)
|
if (!m_isStandalone)
|
||||||
updateToolBar(editor->toolBar());
|
updateToolBar(editor->toolBar());
|
||||||
|
|
||||||
updateEditorStatus(editor);
|
updateEditorStatus(editor);
|
||||||
@@ -239,12 +248,13 @@ void EditorToolBar::updateEditorListSelection(IEditor *newSelection)
|
|||||||
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(newSelection).row());
|
m_editorList->setCurrentIndex(m_editorsListModel->indexOf(newSelection).row());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorToolBar::listSelectionActivated(int row)
|
void EditorToolBar::changeActiveEditor(int row)
|
||||||
{
|
{
|
||||||
EditorManager *em = ICore::instance()->editorManager();
|
EditorManager *em = ICore::instance()->editorManager();
|
||||||
QAbstractItemModel *model = m_editorList->model();
|
QAbstractItemModel *model = m_editorList->model();
|
||||||
const QModelIndex modelIndex = model->index(row, 0);
|
const QModelIndex modelIndex = model->index(row, 0);
|
||||||
IEditor *editor = model->data(modelIndex, Qt::UserRole).value<IEditor*>();
|
IEditor *editor = model->data(modelIndex, Qt::UserRole).value<IEditor*>();
|
||||||
|
|
||||||
if (editor) {
|
if (editor) {
|
||||||
if (editor != em->currentEditor())
|
if (editor != em->currentEditor())
|
||||||
em->activateEditor(editor, EditorManager::NoModeSwitch);
|
em->activateEditor(editor, EditorManager::NoModeSwitch);
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class CORE_EXPORT EditorToolBar : public Utils::StyledBar
|
|||||||
public:
|
public:
|
||||||
explicit EditorToolBar(QWidget *parent = 0);
|
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
|
* 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 closeClicked();
|
||||||
void goBackClicked();
|
void goBackClicked();
|
||||||
void goForwardClicked();
|
void goForwardClicked();
|
||||||
|
void listSelectionActivated(int row);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void updateEditorListSelection(Core::IEditor *newSelection);
|
void updateEditorListSelection(Core::IEditor *newSelection);
|
||||||
void listSelectionActivated(int row);
|
void changeActiveEditor(int row);
|
||||||
void listContextMenu(QPoint);
|
void listContextMenu(QPoint);
|
||||||
void makeEditorWritable();
|
void makeEditorWritable();
|
||||||
|
|
||||||
@@ -123,9 +124,7 @@ private:
|
|||||||
QWidget *m_toolBarPlaceholder;
|
QWidget *m_toolBarPlaceholder;
|
||||||
QWidget *m_defaultToolBar;
|
QWidget *m_defaultToolBar;
|
||||||
|
|
||||||
bool m_ignoreEditorToolbar;
|
bool m_isStandalone;
|
||||||
|
|
||||||
friend class Internal::EditorView;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ void FormEditorW::fullInit()
|
|||||||
|
|
||||||
m_editorToolBar = createEditorToolBar();
|
m_editorToolBar = createEditorToolBar();
|
||||||
m_toolBar = Core::EditorManager::createToolBar();
|
m_toolBar = Core::EditorManager::createToolBar();
|
||||||
m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsIgnoreIEditorToolBar);
|
m_toolBar->setToolbarCreationFlags(Core::EditorToolBar::FlagsStandalone);
|
||||||
m_toolBar->setNavigationVisible(false);
|
m_toolBar->setNavigationVisible(false);
|
||||||
m_toolBar->addCenterToolBar(m_editorToolBar);
|
m_toolBar->addCenterToolBar(m_editorToolBar);
|
||||||
|
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ void DocumentWidget::setup()
|
|||||||
|
|
||||||
m_designToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
|
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->addEditor(textEditor());
|
||||||
m_fakeToolBar->addCenterToolBar(m_designToolBar);
|
m_fakeToolBar->addCenterToolBar(m_designToolBar);
|
||||||
m_fakeToolBar->setNavigationVisible(false);
|
m_fakeToolBar->setNavigationVisible(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user