diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index a7a90396e2d5762d406baa4371cb6bfa5db52767..e57bf276b4f9481dc90fad1129b54fbce2994744 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -82,7 +82,7 @@ SOURCES += mainwindow.cpp \ imode.cpp \ editormanager/systemeditor.cpp \ designmode.cpp \ - faketoolbar.cpp + designmodetoolbar.cpp HEADERS += mainwindow.h \ editmode.h \ diff --git a/src/plugins/coreplugin/designmodetoolbar.cpp b/src/plugins/coreplugin/designmodetoolbar.cpp index 7fcfe3d4676680f999375b3c70d9140387e74ba7..34354e0cb004e3ec1ffba1841813d61acddb0873 100644 --- a/src/plugins/coreplugin/designmodetoolbar.cpp +++ b/src/plugins/coreplugin/designmodetoolbar.cpp @@ -43,6 +43,7 @@ #include <utils/parameteraction.h> #include <utils/qtcassert.h> +#include <utils/styledbar.h> #include <QtCore/QSettings> #include <QtCore/QEvent> @@ -69,61 +70,57 @@ namespace Core { /*! Mimic the look of the text editor toolbar as defined in e.g. EditorView::EditorView */ -DesignModeToolBar::DesignModeToolBar(QWidget *parent) : - QWidget(parent), - m_editorList(new QComboBox), - m_centerToolBar(0), - m_rightToolBar(new QToolBar), +EditorToolBar::EditorToolBar(QWidget *parent) : + Utils::StyledBar(parent), + m_editorList(new QComboBox(this)), + m_rightToolBar(new QToolBar(this)), m_closeButton(new QToolButton), m_lockButton(new QToolButton), + m_goBackAction(new QAction(QIcon(QLatin1String(":/help/images/previous.png")), EditorManager::tr("Go Back"), parent)), m_goForwardAction(new QAction(QIcon(QLatin1String(":/help/images/next.png")), EditorManager::tr("Go Forward"), parent)), - m_editor(0) + + m_activeToolBar(0), + m_toolBarPlaceholder(new QWidget), + m_defaultToolBar(new QWidget(this)), + m_ignoreEditorToolbar(false) { - ICore *core = ICore::instance(); + QHBoxLayout *toolBarLayout = new QHBoxLayout(this); + toolBarLayout->setMargin(0); + toolBarLayout->setSpacing(0); + toolBarLayout->addWidget(m_defaultToolBar); + m_toolBarPlaceholder->setLayout(toolBarLayout); + m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - //setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - m_editorsListModel = core->editorManager()->openedEditorsModel(); + m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + m_activeToolBar = m_defaultToolBar; + + m_editorsListModel = EditorManager::instance()->openedEditorsModel(); + connect(m_goBackAction, SIGNAL(triggered()), this, SIGNAL(goBackClicked())); + connect(m_goForwardAction, SIGNAL(triggered()), this, SIGNAL(goForwardClicked())); - // copied from EditorView::EditorView m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); m_editorList->setMinimumContentsLength(20); m_editorList->setModel(m_editorsListModel); m_editorList->setMaxVisibleItems(40); m_editorList->setContextMenuPolicy(Qt::CustomContextMenu); - QToolBar *editorListToolBar = new QToolBar; - editorListToolBar->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored); - editorListToolBar->addWidget(m_editorList); - m_lockButton->setAutoRaise(true); m_lockButton->setProperty("type", QLatin1String("dockbutton")); + m_lockButton->setVisible(false); m_closeButton->setAutoRaise(true); m_closeButton->setIcon(QIcon(":/core/images/closebutton.png")); m_closeButton->setProperty("type", QLatin1String("dockbutton")); + m_closeButton->setEnabled(false); -// ActionManager *am = core->actionManager(); -// EditorManager *em = core->editorManager(); - -// TODO back/FW buttons disabled for the time being, as the implementation would require changing editormanager. -// QToolBar *backFwToolBar = new QToolBar; -// backFwToolBar->addAction(m_goBackAction); -// backFwToolBar->addAction(m_goForwardAction); -// Command *cmd = am->registerAction(m_goBackAction, Constants::GO_BACK, editor->context()); -//#ifdef Q_WS_MAC -// cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Left"))); -//#else -// cmd->setDefaultKeySequence(QKeySequence(tr("Alt+Left"))); -//#endif -// connect(m_goBackAction, SIGNAL(triggered()), em, SLOT(goBackInNavigationHistory())); -// cmd = am->registerAction(m_goForwardAction, Constants::GO_FORWARD, editor->context()); -//#ifdef Q_WS_MAC -// cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Right"))); -//#else -// cmd->setDefaultKeySequence(QKeySequence(tr("Alt+Right"))); -//#endif -// connect(m_goForwardAction, SIGNAL(triggered()), em, SLOT(goForwardInNavigationHistory())); + m_toolBarPlaceholder->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); + + m_backButton = new QToolButton(this); + m_backButton->setDefaultAction(m_goBackAction); + + m_forwardButton= new QToolButton(this); + m_forwardButton->setDefaultAction(m_goForwardAction); m_rightToolBar->setLayoutDirection(Qt::RightToLeft); m_rightToolBar->addWidget(m_closeButton); @@ -132,55 +129,123 @@ DesignModeToolBar::DesignModeToolBar(QWidget *parent) : QHBoxLayout *toplayout = new QHBoxLayout(this); toplayout->setSpacing(0); toplayout->setMargin(0); - toplayout->setContentsMargins(0,0,0,0); - toplayout->addWidget(editorListToolBar); + toplayout->addWidget(m_backButton); + toplayout->addWidget(m_forwardButton); + toplayout->addWidget(m_editorList); + toplayout->addWidget(m_toolBarPlaceholder, 1); // Custom toolbar stretches toplayout->addWidget(m_rightToolBar); + setLayout(toplayout); + connect(m_editorList, SIGNAL(activated(int)), this, SLOT(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, SIGNAL(closeClicked())); + connect(m_closeButton, SIGNAL(clicked()), this, SLOT(closeView()), Qt::QueuedConnection); - connect(core->editorManager(), SIGNAL(currentEditorChanged(IEditor*)), SLOT(updateEditorListSelection(IEditor*))); + EditorManager *em = EditorManager::instance(); + connect(em, SIGNAL(currentEditorChanged(Core::IEditor*)), SLOT(updateEditorListSelection(Core::IEditor*))); + + ActionManager *am = ICore::instance()->actionManager(); + connect(am->command(Constants::CLOSE), SIGNAL(keySequenceChanged()), + this, SLOT(updateActionShortcuts())); + connect(am->command(Constants::GO_BACK), SIGNAL(keySequenceChanged()), + this, SLOT(updateActionShortcuts())); + connect(am->command(Constants::GO_FORWARD), SIGNAL(keySequenceChanged()), + this, SLOT(updateActionShortcuts())); - updateEditorStatus(); } -void DesignModeToolBar::setCenterToolBar(QWidget *toolBar) +void EditorToolBar::removeToolbarForEditor(IEditor *editor) { - if (toolBar) { - layout()->removeWidget(m_rightToolBar); - layout()->addWidget(toolBar); + disconnect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus())); + + QWidget *toolBar = editor->toolBar(); + if (toolBar != 0) { + if (m_activeToolBar == toolBar) { + m_activeToolBar = m_defaultToolBar; + m_activeToolBar->setVisible(true); + } + m_toolBarPlaceholder->layout()->removeWidget(toolBar); + toolBar->setVisible(false); + toolBar->setParent(0); + } +} + +void EditorToolBar::closeView() +{ + if (!currentEditor()) + return; + + EditorManager *em = ICore::instance()->editorManager(); + if (IEditor *editor = currentEditor()) { + em->closeDuplicate(editor); } + emit closeClicked(); +} + +void EditorToolBar::addEditor(IEditor *editor, ToolbarCreationFlags flags) +{ + connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus())); + QWidget *toolBar = editor->toolBar(); + + m_ignoreEditorToolbar = flags & FlagsIgnoreIEditorToolBar; + + if (toolBar && !m_ignoreEditorToolbar) + addCenterToolBar(toolBar); - layout()->addWidget(m_rightToolBar); + updateEditorStatus(editor); +} + +void EditorToolBar::addCenterToolBar(QWidget *toolBar) +{ + toolBar->setVisible(false); // will be made visible in setCurrentEditor + m_toolBarPlaceholder->layout()->addWidget(toolBar); + + updateToolBar(toolBar); +} + +void EditorToolBar::updateToolBar(QWidget *toolBar) +{ + if (!toolBar) + toolBar = m_defaultToolBar; + if (m_activeToolBar == toolBar) + return; + toolBar->setVisible(true); + m_activeToolBar->setVisible(false); + m_activeToolBar = toolBar; } -void DesignModeToolBar::setEditor(IEditor *editor) + +void EditorToolBar::setCurrentEditor(IEditor *editor) { - m_editor = editor; - m_editorList->setCurrentIndex(m_editorsListModel->indexOf(m_editor).row()); - connect(m_editor, SIGNAL(changed()), this, SLOT(updateEditorStatus())); + m_editorList->setCurrentIndex(m_editorsListModel->indexOf(editor).row()); + + // 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) + updateToolBar(editor->toolBar()); + + updateEditorStatus(editor); } -void DesignModeToolBar::updateEditorListSelection(IEditor *newSelection) +void EditorToolBar::updateEditorListSelection(IEditor *newSelection) { if (newSelection) { m_editorList->setCurrentIndex(m_editorsListModel->indexOf(newSelection).row()); } } -void DesignModeToolBar::listSelectionActivated(int row) +void EditorToolBar::listSelectionActivated(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); } else { + //em->activateEditor(model->index(index, 0), this); QString fileName = model->data(modelIndex, Qt::UserRole + 1).toString(); QByteArray kind = model->data(modelIndex, Qt::UserRole + 2).toByteArray(); editor = em->openEditor(fileName, kind, EditorManager::NoModeSwitch); @@ -190,7 +255,7 @@ void DesignModeToolBar::listSelectionActivated(int row) } } -void DesignModeToolBar::listContextMenu(QPoint pos) +void EditorToolBar::listContextMenu(QPoint pos) { QModelIndex index = m_editorsListModel->index(m_editorList->currentIndex(), 0); QString fileName = m_editorsListModel->data(index, Qt::UserRole + 1).toString(); @@ -203,31 +268,80 @@ void DesignModeToolBar::listContextMenu(QPoint pos) } } -void DesignModeToolBar::makeEditorWritable() +void EditorToolBar::makeEditorWritable() +{ + if (currentEditor()) + ICore::instance()->editorManager()->makeEditorWritable(currentEditor()); +} + +void EditorToolBar::setCanGoBack(bool canGoBack) +{ + m_goBackAction->setEnabled(canGoBack); +} + +void EditorToolBar::setCanGoForward(bool canGoForward) +{ + m_goForwardAction->setEnabled(canGoForward); +} + +void EditorToolBar::updateActionShortcuts() { - if (m_editor) - ICore::instance()->editorManager()->makeEditorWritable(m_editor); + ActionManager *am = ICore::instance()->actionManager(); + m_closeButton->setToolTip(am->command(Constants::CLOSE)->stringWithAppendedShortcut(EditorManager::tr("Close"))); + m_goBackAction->setToolTip(am->command(Constants::GO_BACK)->action()->toolTip()); + m_goForwardAction->setToolTip(am->command(Constants::GO_FORWARD)->action()->toolTip()); } -void DesignModeToolBar::updateEditorStatus() +IEditor *EditorToolBar::currentEditor() const { - if (!m_editor || !m_editor->file()) + return ICore::instance()->editorManager()->currentEditor(); +} + +void EditorToolBar::checkEditorStatus() +{ + IEditor *editor = qobject_cast<IEditor *>(sender()); + IEditor *current = currentEditor(); + + if (current == editor) + updateEditorStatus(editor); +} + +void EditorToolBar::updateEditorStatus(IEditor *editor) +{ + m_lockButton->setVisible(editor != 0); + m_closeButton->setEnabled(editor != 0); + + if (!editor || !editor->file()) { + m_editorList->setToolTip(QString()); return; + } - if (m_editor->file()->isReadOnly()) { - m_lockButton->setIcon(m_editorsListModel->lockedIcon()); - m_lockButton->setEnabled(!m_editor->file()->fileName().isEmpty()); + m_editorList->setCurrentIndex(m_editorsListModel->indexOf(editor).row()); + + if (editor->file()->isReadOnly()) { + m_lockButton->setIcon(QIcon(m_editorsListModel->lockedIcon())); + m_lockButton->setEnabled(!editor->file()->fileName().isEmpty()); m_lockButton->setToolTip(tr("Make writable")); } else { - m_lockButton->setIcon(m_editorsListModel->unlockedIcon()); + m_lockButton->setIcon(QIcon(m_editorsListModel->unlockedIcon())); m_lockButton->setEnabled(false); m_lockButton->setToolTip(tr("File is writable")); } - m_editorList->setToolTip( - m_editor->file()->fileName().isEmpty() - ? m_editor->displayName() - : QDir::toNativeSeparators(m_editor->file()->fileName()) - ); + if (editor == currentEditor()) + m_editorList->setToolTip( + currentEditor()->file()->fileName().isEmpty() + ? currentEditor()->displayName() + : QDir::toNativeSeparators(editor->file()->fileName()) + ); + +} + +void EditorToolBar::setNavigationVisible(bool isVisible) +{ + m_goBackAction->setVisible(isVisible); + m_goForwardAction->setVisible(isVisible); + m_backButton->setVisible(isVisible); + m_forwardButton->setVisible(isVisible); } } // Core diff --git a/src/plugins/coreplugin/designmodetoolbar.h b/src/plugins/coreplugin/designmodetoolbar.h index c8f9787cf68b61519e316253f04247e3c1493edb..286884b7fc789710f9963d0aa3cdda199cdb1ace 100644 --- a/src/plugins/coreplugin/designmodetoolbar.h +++ b/src/plugins/coreplugin/designmodetoolbar.h @@ -34,6 +34,8 @@ #include <QWidget> #include <QtCore/QPointer> +#include <utils/styledbar.h> + QT_BEGIN_NAMESPACE class QComboBox; class QToolButton; @@ -49,28 +51,56 @@ namespace Core { * Fakes an IEditor-like toolbar for design mode widgets such as Qt Designer and Bauhaus. * Creates a combobox for open files and lock and close buttons on the right. */ -class CORE_EXPORT DesignModeToolBar : public QWidget +class CORE_EXPORT EditorToolBar : public Utils::StyledBar { Q_OBJECT - Q_DISABLE_COPY(FakeToolBar) + Q_DISABLE_COPY(EditorToolBar) public: - explicit DesignModeToolBar(QWidget *parent = 0); - void setEditor(Core::IEditor *editor); - void setCenterToolBar(QWidget *toolBar); + explicit EditorToolBar(QWidget *parent = 0); + + enum ToolbarCreationFlags { FlagsNone = 0, FlagsIgnoreIEditorToolBar = 1 }; + + /** + * Adds an editor to listen to state changes so that the editor can be updated accordingly. + */ + void addEditor(IEditor *editor, ToolbarCreationFlags flags = FlagsNone); + + /** + * Sets the editor and adds its custom toolbar to the widget. + */ + void setCurrentEditor(IEditor *editor); + + /** + * Adds a toolbar to the widget and sets invisible by default. + */ + void addCenterToolBar(QWidget *toolBar); - void updateActions(); + void setNavigationVisible(bool isVisible); + void setCanGoBack(bool canGoBack); + void setCanGoForward(bool canGoForward); + void removeToolbarForEditor(IEditor *editor); + +public slots: + void updateEditorStatus(IEditor *editor); signals: void closeClicked(); + void goBackClicked(); + void goForwardClicked(); private slots: void updateEditorListSelection(Core::IEditor *newSelection); void listSelectionActivated(int row); void listContextMenu(QPoint); void makeEditorWritable(); - void updateEditorStatus(); + + void checkEditorStatus(); + void closeView(); + void updateActionShortcuts(); private: + void updateToolBar(QWidget *toolBar); + IEditor *currentEditor() const; Core::OpenEditorsModel *m_editorsListModel; QComboBox *m_editorList; QToolBar *m_centerToolBar; @@ -79,7 +109,14 @@ private: QToolButton *m_lockButton; QAction *m_goBackAction; QAction *m_goForwardAction; - QPointer<Core::IEditor> m_editor; + QToolButton *m_backButton; + QToolButton *m_forwardButton; + + QWidget *m_activeToolBar; + QWidget *m_toolBarPlaceholder; + QWidget *m_defaultToolBar; + + bool m_ignoreEditorToolbar; }; } diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index d511bce86e8c0e02326b2ea792c0c1bd310b99c6..460fec180194f878211f502d1556389de16b7bf5 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -443,9 +443,9 @@ void EditorManager::init() } -DesignModeToolBar *EditorManager::createFakeToolBar(QWidget *parent) +EditorToolBar *EditorManager::createToolBar(QWidget *parent) { - return new DesignModeToolBar(parent); + return new EditorToolBar(parent); } QString EditorManager::defaultExternalEditor() const diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index f8e7331644154c0fffefbb026c9ca2b6618ad192..c2084db933439ed521c51c54f1236f699375b7b9 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -57,7 +57,7 @@ class IFile; class IMode; class IVersionControl; -class DesignModeToolBar; +class EditorToolBar; enum MakeWritableResult { OpenedWithVersionControl, @@ -107,7 +107,7 @@ public: void init(); static EditorManager *instance() { return m_instance; } - static DesignModeToolBar *createFakeToolBar(QWidget *parent = 0); + static EditorToolBar *createToolBar(QWidget *parent = 0); enum OpenEditorFlag { NoActivate = 1, @@ -265,6 +265,7 @@ private: friend class Core::Internal::SplitterOrView; friend class Core::Internal::EditorView; + friend class Core::EditorToolBar; }; } // namespace Core diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index 099f596e3bb0c7845d1d1d18d730100d2cd172d0..8bfea9d752411048a6e9b938ba14c001b988e1b3 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -32,13 +32,14 @@ #include "coreimpl.h" #include "minisplitter.h" #include "openeditorsmodel.h" + +#include <coreplugin/designmodetoolbar.h> #include <coreplugin/coreconstants.h> #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/editormanager/ieditor.h> #include <coreplugin/findplaceholder.h> #include <utils/qtcassert.h> -#include <utils/styledbar.h> #include <QtCore/QDebug> #include <QtCore/QDir> @@ -70,82 +71,23 @@ using namespace Core::Internal; // ================EditorView==================== -EditorView::EditorView(OpenEditorsModel *model, QWidget *parent) : +EditorView::EditorView(QWidget *parent) : QWidget(parent), - m_model(model), - m_toolBar(new QWidget), + m_toolBar(EditorManager::createToolBar(this)), m_container(new QStackedWidget(this)), - m_editorList(new QComboBox), - m_closeButton(new QToolButton), - m_lockButton(new QToolButton), - m_defaultToolBar(new QWidget(this)), m_infoWidget(new QFrame(this)), m_editorForInfoWidget(0), m_statusHLine(new QFrame(this)), m_statusWidget(new QFrame(this)), m_currentNavigationHistoryPosition(0) { - - m_goBackAction = new QAction(QIcon(QLatin1String(":/core/images/prev.png")), tr("Go Back"), this); - connect(m_goBackAction, SIGNAL(triggered()), this, SLOT(goBackInNavigationHistory())); - m_goForwardAction = new QAction(QIcon(QLatin1String(":/core/images/next.png")), tr("Go Forward"), this); - connect(m_goForwardAction, SIGNAL(triggered()), this, SLOT(goForwardInNavigationHistory())); - QVBoxLayout *tl = new QVBoxLayout(this); tl->setSpacing(0); tl->setMargin(0); { - if (!m_model) { - m_model = CoreImpl::instance()->editorManager()->openedEditorsModel(); - } - - QToolButton *backButton = new QToolButton; - backButton->setDefaultAction(m_goBackAction); - - QToolButton *forwardButton= new QToolButton; - forwardButton->setDefaultAction(m_goForwardAction); - - m_editorList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - m_editorList->setMinimumContentsLength(20); - m_editorList->setModel(m_model); - m_editorList->setMaxVisibleItems(40); - m_editorList->setContextMenuPolicy(Qt::CustomContextMenu); - - m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - m_activeToolBar = m_defaultToolBar; - - QHBoxLayout *toolBarLayout = new QHBoxLayout; - toolBarLayout->setMargin(0); - toolBarLayout->setSpacing(0); - toolBarLayout->addWidget(m_defaultToolBar); - m_toolBar->setLayout(toolBarLayout); - m_toolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); - - m_lockButton->setAutoRaise(true); - m_lockButton->setVisible(false); - - m_closeButton->setAutoRaise(true); - m_closeButton->setIcon(QIcon(":/core/images/closebutton.png")); - m_closeButton->setEnabled(false); - - QHBoxLayout *toplayout = new QHBoxLayout; - toplayout->setSpacing(0); - toplayout->setMargin(0); - toplayout->addWidget(backButton); - toplayout->addWidget(forwardButton); - toplayout->addWidget(m_editorList); - toplayout->addWidget(m_toolBar, 1); // Custom toolbar stretches - toplayout->addWidget(m_lockButton); - toplayout->addWidget(m_closeButton); - - Utils::StyledBar *top = new Utils::StyledBar; - top->setLayout(toplayout); - tl->addWidget(top); - - connect(m_editorList, SIGNAL(activated(int)), this, SLOT(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); + connect(m_toolBar, SIGNAL(goBackClicked()), this, SLOT(goBackInNavigationHistory())); + connect(m_toolBar, SIGNAL(goForwardClicked()), this, SLOT(goForwardInNavigationHistory())); + tl->addWidget(m_toolBar); } { m_infoWidget->setFrameStyle(QFrame::Panel | QFrame::Raised); @@ -208,17 +150,7 @@ EditorView::EditorView(OpenEditorsModel *model, QWidget *parent) : tl->addWidget(m_statusWidget); } - - ActionManager *am = ICore::instance()->actionManager(); - connect(am->command(Constants::CLOSE), SIGNAL(keySequenceChanged()), - this, SLOT(updateActionShortcuts())); - connect(am->command(Constants::GO_BACK), SIGNAL(keySequenceChanged()), - this, SLOT(updateActionShortcuts())); - connect(am->command(Constants::GO_FORWARD), SIGNAL(keySequenceChanged()), - this, SLOT(updateActionShortcuts())); - - updateActionShortcuts(); - updateActions(); + updateNavigatorActions(); } EditorView::~EditorView() @@ -279,13 +211,7 @@ void EditorView::addEditor(IEditor *editor) m_container->addWidget(editor->widget()); m_widgetEditorMap.insert(editor->widget(), editor); - - QWidget *toolBar = editor->toolBar(); - if (toolBar) { - toolBar->setVisible(false); // will be made visible in setCurrentEditor - m_toolBar->layout()->addWidget(toolBar); - } - connect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus())); + m_toolBar->addEditor(editor); if (editor == currentEditor()) setCurrentEditor(editor); @@ -296,14 +222,6 @@ bool EditorView::hasEditor(IEditor *editor) const return m_editors.contains(editor); } -void EditorView::closeView() -{ - EditorManager *em = CoreImpl::instance()->editorManager(); - if (IEditor *editor = currentEditor()) { - em->closeDuplicate(editor); - } -} - void EditorView::removeEditor(IEditor *editor) { QTC_ASSERT(editor, return); @@ -318,17 +236,8 @@ void EditorView::removeEditor(IEditor *editor) m_container->removeWidget(editor->widget()); m_widgetEditorMap.remove(editor->widget()); editor->widget()->setParent(0); - disconnect(editor, SIGNAL(changed()), this, SLOT(checkEditorStatus())); - QWidget *toolBar = editor->toolBar(); - if (toolBar != 0) { - if (m_activeToolBar == toolBar) { - m_activeToolBar = m_defaultToolBar; - m_activeToolBar->setVisible(true); - } - m_toolBar->layout()->removeWidget(toolBar); - toolBar->setVisible(false); - toolBar->setParent(0); - } + m_toolBar->removeToolbarForEditor(editor); + if (wasCurrent) setCurrentEditor(m_editors.count() ? m_editors.last() : 0); } @@ -350,7 +259,7 @@ void EditorView::setCurrentEditor(IEditor *editor) if (!editor || m_container->count() <= 0 || m_container->indexOf(editor->widget()) == -1) { - updateEditorStatus(0); + m_toolBar->updateEditorStatus(0); // ### TODO the combo box m_editorList should show an empty item return; } @@ -361,57 +270,9 @@ void EditorView::setCurrentEditor(IEditor *editor) const int idx = m_container->indexOf(editor->widget()); QTC_ASSERT(idx >= 0, return); m_container->setCurrentIndex(idx); - m_editorList->setCurrentIndex(m_model->indexOf(editor).row()); - updateEditorStatus(editor); - updateToolBar(editor); - updateEditorHistory(editor); -} - -void EditorView::checkEditorStatus() -{ - IEditor *editor = qobject_cast<IEditor *>(sender()); - if (editor == currentEditor()) - updateEditorStatus(editor); -} - -void EditorView::updateEditorStatus(IEditor *editor) -{ - m_lockButton->setVisible(editor != 0); - m_closeButton->setEnabled(editor != 0); - - if (!editor) { - m_editorList->setToolTip(QString()); - return; - } + m_toolBar->setCurrentEditor(editor); - if (editor->file()->isReadOnly()) { - m_lockButton->setIcon(m_model->lockedIcon()); - m_lockButton->setEnabled(!editor->file()->fileName().isEmpty()); - m_lockButton->setToolTip(tr("Make writable")); - } else { - m_lockButton->setIcon(m_model->unlockedIcon()); - m_lockButton->setEnabled(false); - m_lockButton->setToolTip(tr("File is writable")); - } - if (currentEditor() == editor) - m_editorList->setToolTip( - editor->file()->fileName().isEmpty() - ? editor->displayName() - : QDir::toNativeSeparators(editor->file()->fileName()) - ); - -} - -void EditorView::updateToolBar(IEditor *editor) -{ - QWidget *toolBar = editor->toolBar(); - if (!toolBar) - toolBar = m_defaultToolBar; - if (m_activeToolBar == toolBar) - return; - toolBar->setVisible(true); - m_activeToolBar->setVisible(false); - m_activeToolBar = toolBar; + updateEditorHistory(editor); } int EditorView::editorCount() const @@ -424,36 +285,6 @@ QList<IEditor *> EditorView::editors() const return m_widgetEditorMap.values(); } - -void EditorView::makeEditorWritable() -{ - ICore::instance()->editorManager()->makeEditorWritable(currentEditor()); -} - -void EditorView::listSelectionActivated(int index) -{ - EditorManager *em = CoreImpl::instance()->editorManager(); - QAbstractItemModel *model = m_editorList->model(); - 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::listContextMenu(QPoint pos) -{ - QModelIndex index = m_model->index(m_editorList->currentIndex(), 0); - QString fileName = m_model->data(index, Qt::UserRole + 1).toString(); - if (fileName.isEmpty()) - return; - QMenu menu; - menu.addAction(tr("Copy full path to clipboard")); - if (menu.exec(m_editorList->mapToGlobal(pos))) { - QApplication::clipboard()->setText(QDir::toNativeSeparators(fileName)); - } -} - void EditorView::updateEditorHistory(IEditor *editor) { if (!editor) @@ -521,21 +352,13 @@ void EditorView::addCurrentPositionToNavigationHistory(IEditor *editor, const QB m_navigationHistory.takeLast(); } } - updateActions(); -} - -void EditorView::updateActions() -{ - m_goBackAction->setEnabled(canGoBack()); - m_goForwardAction->setEnabled(canGoForward()); + updateNavigatorActions(); } -void EditorView::updateActionShortcuts() +void EditorView::updateNavigatorActions() { - ActionManager *am = ICore::instance()->actionManager(); - m_closeButton->setToolTip(am->command(Constants::CLOSE)->stringWithAppendedShortcut(EditorManager::tr("Close"))); - m_goBackAction->setToolTip(am->command(Constants::GO_BACK)->action()->toolTip()); - m_goForwardAction->setToolTip(am->command(Constants::GO_FORWARD)->action()->toolTip()); + m_toolBar->setCanGoBack(canGoBack()); + m_toolBar->setCanGoForward(canGoForward()); } void EditorView::copyNavigationHistoryFrom(EditorView* other) @@ -545,7 +368,7 @@ void EditorView::copyNavigationHistoryFrom(EditorView* other) m_currentNavigationHistoryPosition = other->m_currentNavigationHistoryPosition; m_navigationHistory = other->m_navigationHistory; m_editorHistory = other->m_editorHistory; - updateActions(); + updateNavigatorActions(); } void EditorView::updateCurrentPositionInNavigationHistory() @@ -588,7 +411,7 @@ void EditorView::goBackInNavigationHistory() editor->restoreState(location.state.toByteArray()); break; } - updateActions(); + updateNavigatorActions(); } void EditorView::goForwardInNavigationHistory() @@ -611,7 +434,7 @@ void EditorView::goForwardInNavigationHistory() } } editor->restoreState(location.state.toByteArray()); - updateActions(); + updateNavigatorActions(); } @@ -620,7 +443,7 @@ SplitterOrView::SplitterOrView(OpenEditorsModel *model) Q_ASSERT(model); m_isRoot = true; m_layout = new QStackedLayout(this); - m_view = new EditorView(model); + m_view = new EditorView(); m_splitter = 0; m_layout->addWidget(m_view); } diff --git a/src/plugins/coreplugin/editormanager/editorview.h b/src/plugins/coreplugin/editormanager/editorview.h index 605449b37968010007d3ce8293ec6e92246cb8d3..a0abfb0d6038480f2871d22363fbccc85449464d 100644 --- a/src/plugins/coreplugin/editormanager/editorview.h +++ b/src/plugins/coreplugin/editormanager/editorview.h @@ -56,6 +56,7 @@ namespace Core { class IEditor; class OpenEditorsModel; +class EditorToolBar; namespace Internal { @@ -71,7 +72,7 @@ class EditorView : public QWidget Q_OBJECT public: - EditorView(OpenEditorsModel *model = 0, QWidget *parent = 0); + EditorView(QWidget *parent = 0); virtual ~EditorView(); int editorCount() const; @@ -95,28 +96,17 @@ public: QObject *object, const char *member); void hideEditorStatusBar(const QString &id); -public slots: - void closeView(); - private slots: void updateEditorStatus(Core::IEditor *editor = 0); - void checkEditorStatus(); - void makeEditorWritable(); - void listSelectionActivated(int index); - void listContextMenu(QPoint); private: + void updateNavigatorActions(); void updateToolBar(IEditor *editor); void checkProjectLoaded(IEditor *editor); - OpenEditorsModel *m_model; - QWidget *m_toolBar; - QWidget *m_activeToolBar; + EditorToolBar *m_toolBar; + QStackedWidget *m_container; - QComboBox *m_editorList; - QToolButton *m_closeButton; - QToolButton *m_lockButton; - QWidget *m_defaultToolBar; QString m_infoWidgetId; QFrame *m_infoWidget; QLabel *m_infoWidgetLabel; @@ -134,9 +124,6 @@ private: QList<EditLocation> m_editorHistory; int m_currentNavigationHistoryPosition; void updateCurrentPositionInNavigationHistory(); - QAction *m_goBackAction; - QAction *m_goForwardAction; - void updateActions(); public: @@ -146,7 +133,6 @@ public: public slots: void goBackInNavigationHistory(); void goForwardInNavigationHistory(); - void updateActionShortcuts(); public: void addCurrentPositionToNavigationHistory(IEditor *editor = 0, const QByteArray &saveState = QByteArray()); diff --git a/src/plugins/qmldesigner/designmodewidget.cpp b/src/plugins/qmldesigner/designmodewidget.cpp index ce1a55ee6221f7ce53e8b8d0aec14592c1afecf1..2f65ada9e0ffc17951e2e4efb4bdab43218c84a1 100644 --- a/src/plugins/qmldesigner/designmodewidget.cpp +++ b/src/plugins/qmldesigner/designmodewidget.cpp @@ -122,7 +122,7 @@ DocumentWidget::DocumentWidget(TextEditor::ITextEditor *textEditor, QPlainTextEd m_leftSideBar(0), m_rightSideBar(0), m_designToolBar(new QToolBar), - m_fakeToolBar(Core::EditorManager::createFakeToolBar(this)), + m_fakeToolBar(Core::EditorManager::createToolBar(this)), m_isDisabled(false), m_warningWidget(0) { @@ -203,11 +203,6 @@ void DocumentWidget::setAutoSynchronization(bool sync) } } -void DocumentWidget::closeEditor() -{ - Core::ICore::instance()->editorManager()->closeEditors(QList<IEditor*>() << textEditor()); -} - void DocumentWidget::enable() { if (debug) @@ -302,9 +297,9 @@ void DocumentWidget::setup() m_designToolBar->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored); - connect(m_fakeToolBar, SIGNAL(closeClicked()), this, SLOT(closeEditor())); - m_fakeToolBar->setEditor(textEditor()); - m_fakeToolBar->setCenterToolBar(m_designToolBar); + m_fakeToolBar->addEditor(textEditor(), Core::EditorToolBar::FlagsIgnoreIEditorToolBar); + m_fakeToolBar->addCenterToolBar(m_designToolBar); + m_fakeToolBar->setNavigationVisible(false); // right area: QWidget *centerWidget = new QWidget; diff --git a/src/plugins/qmldesigner/designmodewidget.h b/src/plugins/qmldesigner/designmodewidget.h index 978ce132a2150663aa5e02858b67336a25570ab3..ec4eb3c5a8f41b4fc931675cbb23120a3d970c99 100644 --- a/src/plugins/qmldesigner/designmodewidget.h +++ b/src/plugins/qmldesigner/designmodewidget.h @@ -62,7 +62,7 @@ QT_END_NAMESPACE namespace Core { class SideBar; class OpenEditorsModel; - class DesignModeToolBar; + class EditorToolBar; } namespace QmlDesigner { @@ -115,7 +115,6 @@ private slots: void enable(); void disable(const QList<RewriterView::Error> &errors); void updateErrorStatus(const QList<RewriterView::Error> &errors); - void closeEditor(); private: void setup(); @@ -131,7 +130,7 @@ private: Core::SideBar *m_rightSideBar; QToolBar *m_designToolBar; - Core::DesignModeToolBar *m_fakeToolBar; + Core::EditorToolBar *m_fakeToolBar; bool m_isDisabled; DocumentWarningWidget *m_warningWidget;