OSDN Git Service

rewrite editor info bar handling
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Fri, 6 May 2011 10:48:44 +0000 (12:48 +0200)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Thu, 12 May 2011 18:10:02 +0000 (20:10 +0200)
the info about the bars is now stored in the IFile, not in the
EditorView. this is somewhat more expensive for the bars which
identically apply to all editors of one type, but fixes consistency
issues between views.

additionally, it is now possible to set several simultaneous
info bars per file, which ensures that no information is lost.

Co-authored-by: mae
21 files changed:
src/plugins/cmakeprojectmanager/cmakeeditor.cpp
src/plugins/cmakeprojectmanager/cmakeproject.cpp
src/plugins/coreplugin/coreplugin.pro
src/plugins/coreplugin/editormanager/editormanager.cpp
src/plugins/coreplugin/editormanager/editormanager.h
src/plugins/coreplugin/editormanager/editorview.cpp
src/plugins/coreplugin/editormanager/editorview.h
src/plugins/coreplugin/ifile.cpp
src/plugins/coreplugin/ifile.h
src/plugins/coreplugin/infobar.cpp [new file with mode: 0644]
src/plugins/coreplugin/infobar.h [new file with mode: 0644]
src/plugins/cppeditor/cppeditor.cpp
src/plugins/cpptools/cppfindreferences.cpp
src/plugins/designer/formeditorfactory.cpp
src/plugins/designer/formeditorfactory.h
src/plugins/qmljseditor/qmljseditorfactory.cpp
src/plugins/qmljseditor/qmljseditorfactory.h
src/plugins/qmljsinspector/qmljslivetextpreview.cpp
src/plugins/texteditor/basetexteditor.cpp
src/plugins/texteditor/basetexteditor.h
src/plugins/texteditor/plaintexteditorfactory.cpp

index ce22a20..4155a45 100644 (file)
@@ -37,6 +37,7 @@
 #include "cmakeprojectconstants.h"
 #include "cmakeproject.h"
 
+#include <coreplugin/infobar.h>
 #include <projectexplorer/projectexplorer.h>
 #include <projectexplorer/session.h>
 #include <texteditor/fontsettings.h>
@@ -77,11 +78,10 @@ QString CMakeEditor::id() const
 
 void CMakeEditor::markAsChanged()
 {
-    Core::EditorManager::instance()->
-            showEditorInfoBar(QLatin1String("CMakeEditor.RunCMake"),
-                              tr("Changes to cmake files are shown in the project tree after building."),
-                              tr("Build now"),
-                              this, SLOT(build()));
+    Core::InfoBarEntry info(QLatin1String("CMakeEditor.RunCMake"),
+                            tr("Changes to cmake files are shown in the project tree after building."));
+    info.setCustomButtonInfo(tr("Build now"), this, SLOT(build()));
+    file()->infoBar()->addInfo(info);
 }
 
 void CMakeEditor::build()
index 332d538..d61b326 100644 (file)
@@ -51,6 +51,7 @@
 #include <extensionsystem/pluginmanager.h>
 #include <utils/qtcassert.h>
 #include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/editormanager/editormanager.h>
 
 #include <QtCore/QMap>
@@ -195,7 +196,9 @@ bool CMakeProject::parseCMakeLists()
         !activeTarget()->activeBuildConfiguration())
         return false;
 
-    Core::EditorManager::instance()->hideEditorInfoBar("CMakeEditor.RunCMake");
+    foreach (Core::IEditor *editor, Core::EditorManager::instance()->openedEditors())
+        if (isProjectFile(editor->file()->fileName()))
+            editor->file()->infoBar()->removeInfo(QLatin1String("CMakeEditor.RunCMake"));
 
     // Find cbp file
     CMakeBuildConfiguration *activeBC = activeTarget()->activeBuildConfiguration();
index 33127c0..0152360 100644 (file)
@@ -71,6 +71,7 @@ SOURCES += mainwindow.cpp \
     mimedatabase.cpp \
     icore.cpp \
     ifile.cpp \
+    infobar.cpp \
     editormanager/ieditor.cpp \
     dialogs/ioptionspage.cpp \
     dialogs/iwizard.cpp \
@@ -139,6 +140,7 @@ HEADERS += mainwindow.h \
     icontext.h \
     icore.h \
     ifile.h \
+    infobar.h \
     ifilefactory.h \
     imode.h \
     ioutputpane.h \
index 0650599..5a73c4e 100644 (file)
@@ -53,6 +53,7 @@
 #include <coreplugin/editormanager/ieditorfactory.h>
 #include <coreplugin/editormanager/iexternaleditor.h>
 #include <coreplugin/icorelistener.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/imode.h>
 #include <coreplugin/settingsdatabase.h>
 #include <coreplugin/variablemanager.h>
@@ -1573,13 +1574,18 @@ void EditorManager::updateActions()
 #ifdef Q_WS_MAC
         window()->setWindowModified(curEditor->file()->isModified());
 #endif
-        if (curEditor->file()->isModified() && curEditor->file()->isReadOnly()) {
-            // we are about to change a read-only file, warn user
-            showEditorInfoBar(QLatin1String("Core.EditorManager.MakeWritable"),
-                tr("<b>Warning:</b> You are changing a read-only file."),
-                tr("Make writable"), this, SLOT(makeCurrentEditorWritable()));
-        } else {
-            hideEditorInfoBar(QLatin1String("Core.EditorManager.MakeWritable"));
+        bool ww = curEditor->file()->isModified() && curEditor->file()->isReadOnly();
+        if (ww != curEditor->file()->hasWriteWarning()) {
+            curEditor->file()->setWriteWarning(ww);
+            if (ww) {
+                // we are about to change a read-only file, warn user
+                InfoBarEntry info(QLatin1String("Core.EditorManager.MakeWritable"),
+                                  tr("<b>Warning:</b> You are changing a read-only file."));
+                info.setCustomButtonInfo(tr("Make writable"), this, SLOT(makeCurrentEditorWritable()));
+                curEditor->file()->infoBar()->addInfo(info);
+            } else {
+                curEditor->file()->infoBar()->removeInfo(QLatin1String("Core.EditorManager.MakeWritable"));
+            }
         }
 #ifdef Q_WS_MAC
     } else { // curEditor
@@ -1843,23 +1849,6 @@ void EditorManager::revertToSaved()
         QMessageBox::critical(m_d->m_core->mainWindow(), tr("File Error"), errorString);
 }
 
-void EditorManager::showEditorInfoBar(const QString &id,
-                                      const QString &infoText,
-                                      const QString &buttonText,
-                                      QObject *object, const char *buttonPressMember,
-                                      const char *cancelButtonPressMember)
-{
-    currentEditorView()->showEditorInfoBar(id, infoText, buttonText, object, buttonPressMember, cancelButtonPressMember);
-}
-
-
-void EditorManager::hideEditorInfoBar(const QString &id)
-{
-    Core::Internal::EditorView *cev = currentEditorView();
-    if (cev)
-        cev->hideEditorInfoBar(id);
-}
-
 void EditorManager::showEditorStatusBar(const QString &id,
                                       const QString &infoText,
                                       const QString &buttonText,
index 0ab68c0..68749d0 100644 (file)
@@ -165,14 +165,6 @@ public:
     Internal::OpenEditorsWindow *windowPopup() const;
     void showPopupOrSelectDocument() const;
 
-    void showEditorInfoBar(const QString &id,
-                           const QString &infoText,
-                           const QString &buttonText = QString(),
-                           QObject *object = 0, const char *buttonPressMember = 0,
-                           const char *cancelButtonPressMember = 0);
-
-    void hideEditorInfoBar(const QString &id);
-
     void showEditorStatusBar(const QString &id,
                            const QString &infoText,
                            const QString &buttonText = QString(),
index 3da16be..4491ae1 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <coreplugin/editortoolbar.h>
 #include <coreplugin/coreconstants.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/actionmanager/actionmanager.h>
 #include <coreplugin/editormanager/ieditor.h>
 
@@ -79,8 +80,7 @@ EditorView::EditorView(QWidget *parent) :
     QWidget(parent),
     m_toolBar(EditorManager::createToolBar(this)),
     m_container(new QStackedWidget(this)),
-    m_infoWidget(new QFrame(this)),
-    m_editorForInfoWidget(0),
+    m_infoBarDisplay(new InfoBarDisplay(this)),
     m_statusHLine(new QFrame(this)),
     m_statusWidget(new QFrame(this)),
     m_currentNavigationHistoryPosition(0)
@@ -95,36 +95,8 @@ EditorView::EditorView(QWidget *parent) :
         connect(m_toolBar, SIGNAL(listSelectionActivated(int)), this, SLOT(listSelectionActivated(int)));
         tl->addWidget(m_toolBar);
     }
-    {
-        QPalette pal = m_infoWidget->palette();
-        pal.setColor(QPalette::Window, QColor(255, 255, 225));
-        pal.setColor(QPalette::WindowText, Qt::black);
-
-        m_infoWidget->setPalette(pal);
-        m_infoWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
-        m_infoWidget->setLineWidth(1);
-        m_infoWidget->setAutoFillBackground(true);
-
-        QHBoxLayout *hbox = new QHBoxLayout(m_infoWidget);
-        hbox->setMargin(2);
-        m_infoWidgetLabel = new QLabel("Placeholder");
-        m_infoWidgetLabel->setWordWrap(true);
-        hbox->addWidget(m_infoWidgetLabel);
-
-        m_infoWidgetButton = new QToolButton;
-        m_infoWidgetButton->setText(tr("Placeholder"));
-        hbox->addWidget(m_infoWidgetButton);
-
-        m_infoWidgetCloseButton = new QToolButton;
-        m_infoWidgetCloseButton->setAutoRaise(true);
-        m_infoWidgetCloseButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLEAR)));
-        m_infoWidgetCloseButton->setToolTip(tr("Close"));
-
-        hbox->addWidget(m_infoWidgetCloseButton);
-
-        m_infoWidget->setVisible(false);
-        tl->addWidget(m_infoWidget);
-    }
+
+    m_infoBarDisplay->setTarget(tl, 1);
 
     tl->addWidget(m_container);
 
@@ -169,40 +141,6 @@ void EditorView::closeView()
     if (editor)
        em->closeEditor(editor);
 }
-void EditorView::showEditorInfoBar(const QString &id,
-                                   const QString &infoText,
-                                   const QString &buttonText,
-                                   QObject *object, const char *buttonPressMember,
-                                   const char *cancelButtonPressMember)
-{
-    m_infoWidgetId = id;
-    m_infoWidgetLabel->setText(infoText);
-    m_infoWidgetButton->setText(buttonText);
-
-    if (object && !buttonText.isEmpty()) {
-        m_infoWidgetButton->show();
-    } else {
-        m_infoWidgetButton->hide();
-    }
-
-    m_infoWidgetButton->disconnect();
-    if (object && buttonPressMember)
-        connect(m_infoWidgetButton, SIGNAL(clicked()), object, buttonPressMember);
-
-    m_infoWidgetCloseButton->disconnect();
-    if (object && cancelButtonPressMember)
-        connect(m_infoWidgetCloseButton, SIGNAL(clicked()), object, cancelButtonPressMember);
-    connect(m_infoWidgetCloseButton, SIGNAL(clicked()), m_infoWidget, SLOT(hide()));
-
-    m_infoWidget->setVisible(true);
-    m_editorForInfoWidget = currentEditor();
-}
-
-void EditorView::hideEditorInfoBar(const QString &id)
-{
-    if (id == m_infoWidgetId)
-        m_infoWidget->setVisible(false);
-}
 
 void EditorView::showEditorStatusBar(const QString &id,
                                      const QString &infoText,
@@ -284,15 +222,10 @@ void EditorView::listSelectionActivated(int index)
 
 void EditorView::setCurrentEditor(IEditor *editor)
 {
-    // FIXME: this keeps the editor hidden if switching from A to B and back
-    if (editor != m_editorForInfoWidget) {
-        m_infoWidget->hide();
-        m_editorForInfoWidget = 0;
-    }
-
     if (!editor || m_container->count() <= 0
         || m_container->indexOf(editor->widget()) == -1) {
         m_toolBar->updateEditorStatus(0);
+        m_infoBarDisplay->setInfoBar(0);
         // ### TODO the combo box m_editorList should show an empty item
         return;
     }
@@ -306,6 +239,8 @@ void EditorView::setCurrentEditor(IEditor *editor)
     m_toolBar->setCurrentEditor(editor);
 
     updateEditorHistory(editor);
+
+    m_infoBarDisplay->setInfoBar(editor->file()->infoBar());
 }
 
 int EditorView::editorCount() const
index 94de9a2..50d9a74 100644 (file)
@@ -55,6 +55,7 @@ namespace Core {
 class IContext;
 class IFile;
 class IEditor;
+class InfoBarDisplay;
 class OpenEditorsModel;
 class EditorToolBar;
 
@@ -84,12 +85,6 @@ public:
     bool hasEditor(IEditor *editor) const;
 
     QList<IEditor *> editors() const;
-    void showEditorInfoBar(const QString &id,
-                           const QString &infoText,
-                           const QString &buttonText,
-                           QObject *object, const char *buttonPressMember,
-                           const char *cancelButtonPressMember = 0);
-    void hideEditorInfoBar(const QString &id);
 
     void showEditorStatusBar(const QString &id,
                            const QString &infoText,
@@ -109,12 +104,7 @@ private:
     EditorToolBar *m_toolBar;
 
     QStackedWidget *m_container;
-    QString m_infoWidgetId;
-    QFrame *m_infoWidget;
-    QLabel *m_infoWidgetLabel;
-    QToolButton *m_infoWidgetButton;
-    QToolButton *m_infoWidgetCloseButton;
-    IEditor *m_editorForInfoWidget;
+    InfoBarDisplay *m_infoBarDisplay;
     QString m_statusWidgetId;
     QFrame *m_statusHLine;
     QFrame *m_statusWidget;
index 4c5fbfe..9a87306 100644 (file)
 
 #include "ifile.h"
 
+#include "infobar.h"
+
 namespace Core {
 
-IFile::IFile(QObject *parent) : QObject(parent)
+IFile::IFile(QObject *parent) : QObject(parent), m_infoBar(0), m_hasWriteWarning(false)
 {
 }
 
 IFile::~IFile()
 {
+    delete m_infoBar;
 }
 
 IFile::ReloadBehavior IFile::reloadBehavior(ChangeTrigger state, ChangeType type) const
@@ -55,4 +58,11 @@ void IFile::checkPermissions()
 {
 }
 
+InfoBar *IFile::infoBar()
+{
+    if (!m_infoBar)
+        m_infoBar = new InfoBar;
+    return m_infoBar;
+}
+
 } // namespace Core
index d8d1cc2..424de53 100644 (file)
@@ -39,6 +39,7 @@
 namespace Core {
 
 class MimeType;
+class InfoBar;
 
 class CORE_EXPORT IFile : public QObject
 {
@@ -100,11 +101,20 @@ public:
 
     virtual void checkPermissions();
 
+    bool hasWriteWarning() const { return m_hasWriteWarning; }
+    void setWriteWarning(bool has) { m_hasWriteWarning = has; }
+
+    InfoBar *infoBar();
+
 signals:
     void changed();
 
     void aboutToReload();
     void reloaded();
+
+private:
+    InfoBar *m_infoBar;
+    bool m_hasWriteWarning;
 };
 
 } // namespace Core
diff --git a/src/plugins/coreplugin/infobar.cpp b/src/plugins/coreplugin/infobar.cpp
new file mode 100644 (file)
index 0000000..29d15a0
--- /dev/null
@@ -0,0 +1,201 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this file.
+** Please review the following information to ensure the GNU Lesser General
+** Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**************************************************************************/
+
+#include "infobar.h"
+
+#include <coreplugin/coreconstants.h>
+
+#include <QtGui/QFrame>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QLabel>
+#include <QtGui/QToolButton>
+
+#include <QtCore/QVariant>
+
+namespace Core {
+
+InfoBarEntry::InfoBarEntry(const QString &_id, const QString &_infoText)
+    : id(_id)
+    , infoText(_infoText)
+    , object(0)
+    , buttonPressMember(0)
+    , cancelObject(0)
+    , cancelButtonPressMember(0)
+{
+}
+
+void InfoBarEntry::setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member)
+{
+    buttonText = _buttonText;
+    object = _object;
+    buttonPressMember = _member;
+}
+
+void InfoBarEntry::setCancelButtonInfo(QObject *_object, const char *_member)
+{
+    cancelObject = _object;
+    cancelButtonPressMember = _member;
+}
+
+
+void InfoBar::addInfo(const InfoBarEntry &info)
+{
+    m_infoBarEntries << info;
+    emit changed();
+}
+
+void InfoBar::removeInfo(const QString &id)
+{
+    QMutableListIterator<InfoBarEntry> it(m_infoBarEntries);
+    while (it.hasNext())
+        if (it.next().id == id) {
+            it.remove();
+            emit changed();
+            return;
+        }
+}
+
+void InfoBar::clear()
+{
+    if (!m_infoBarEntries.isEmpty()) {
+        m_infoBarEntries.clear();
+        emit changed();
+    }
+}
+
+
+InfoBarDisplay::InfoBarDisplay(QObject *parent)
+    : QObject(parent)
+    , m_infoBar(0)
+    , m_boxLayout(0)
+    , m_boxIndex(0)
+{
+}
+
+void InfoBarDisplay::setTarget(QBoxLayout *layout, int index)
+{
+    m_boxLayout = layout;
+    m_boxIndex = index;
+}
+
+void InfoBarDisplay::setInfoBar(InfoBar *infoBar)
+{
+    if (m_infoBar == infoBar)
+        return;
+
+    if (m_infoBar)
+        m_infoBar->disconnect(this);
+    m_infoBar = infoBar;
+    if (m_infoBar) {
+        connect(infoBar, SIGNAL(changed()), SLOT(update()));
+        connect(infoBar, SIGNAL(destroyed()), SLOT(infoBarDestroyed()));
+    }
+    update();
+}
+
+void InfoBarDisplay::infoBarDestroyed()
+{
+    m_infoBar = 0;
+    // Calling update() here causes a complicated crash on shutdown.
+    // So instead we rely on the view now being either destroyed (in which case it
+    // will delete the widgets itself) or setInfoBar() being called explicitly.
+}
+
+void InfoBarDisplay::update()
+{
+    foreach (QWidget *widget, m_infoWidgets) {
+        widget->disconnect(this); // We want no destroyed() signal now
+        delete widget;
+    }
+    m_infoWidgets.clear();
+
+    if (!m_infoBar)
+        return;
+
+    foreach (const InfoBarEntry &info, m_infoBar->m_infoBarEntries) {
+        QFrame *infoWidget = new QFrame;
+
+        QPalette pal = infoWidget->palette();
+        pal.setColor(QPalette::Window, QColor(255, 255, 225));
+        pal.setColor(QPalette::WindowText, Qt::black);
+
+        infoWidget->setPalette(pal);
+        infoWidget->setFrameStyle(QFrame::Panel | QFrame::Raised);
+        infoWidget->setLineWidth(1);
+        infoWidget->setAutoFillBackground(true);
+
+        QHBoxLayout *hbox = new QHBoxLayout(infoWidget);
+        hbox->setMargin(2);
+
+        QLabel *infoWidgetLabel = new QLabel(info.infoText);
+        infoWidgetLabel->setWordWrap(true);
+        hbox->addWidget(infoWidgetLabel);
+
+        if (!info.buttonText.isEmpty()) {
+            QToolButton *infoWidgetButton = new QToolButton;
+            infoWidgetButton->setText(info.buttonText);
+            connect(infoWidgetButton, SIGNAL(clicked()), info.object, info.buttonPressMember);
+
+            hbox->addWidget(infoWidgetButton);
+        }
+
+        QToolButton *infoWidgetCloseButton = new QToolButton;
+        infoWidgetCloseButton->setAutoRaise(true);
+        infoWidgetCloseButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_CLEAR)));
+        infoWidgetCloseButton->setToolTip(tr("Close"));
+        infoWidgetCloseButton->setProperty("infoId", info.id);
+        connect(infoWidgetCloseButton, SIGNAL(clicked()), SLOT(cancelButtonClicked()));
+
+        if (info.cancelObject)
+            connect(infoWidgetCloseButton, SIGNAL(clicked()),
+                    info.cancelObject, info.cancelButtonPressMember);
+
+        hbox->addWidget(infoWidgetCloseButton);
+
+        connect(infoWidget, SIGNAL(destroyed()), SLOT(widgetDestroyed()));
+        m_boxLayout->insertWidget(m_boxIndex, infoWidget);
+        m_infoWidgets << infoWidget;
+    }
+}
+
+void InfoBarDisplay::widgetDestroyed()
+{
+    // This means that the parent is being deleted
+    m_infoWidgets.clear();
+}
+
+void InfoBarDisplay::cancelButtonClicked()
+{
+    m_infoBar->removeInfo(sender()->property("infoId").toString());
+}
+
+} // namespace Core
diff --git a/src/plugins/coreplugin/infobar.h b/src/plugins/coreplugin/infobar.h
new file mode 100644 (file)
index 0000000..af8e123
--- /dev/null
@@ -0,0 +1,110 @@
+/**************************************************************************
+**
+** This file is part of Qt Creator
+**
+** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
+**
+** Contact: Nokia Corporation (info@qt.nokia.com)
+**
+**
+** GNU Lesser General Public License Usage
+**
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this file.
+** Please review the following information to ensure the GNU Lesser General
+** Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** Other Usage
+**
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**************************************************************************/
+
+#ifndef INFOBAR_H
+#define INFOBAR_H
+
+#include "core_global.h"
+
+#include <QtCore/QObject>
+
+QT_BEGIN_NAMESPACE
+class QBoxLayout;
+QT_END_NAMESPACE
+
+namespace Core {
+
+class InfoBar;
+class InfoBarDisplay;
+
+class CORE_EXPORT InfoBarEntry
+{
+public:
+    InfoBarEntry(const QString &_id, const QString &_infoText);
+    InfoBarEntry(const InfoBarEntry &other) { *this = other; }
+    void setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member);
+    void setCancelButtonInfo(QObject *_object, const char *_member);
+
+private:
+    QString id;
+    QString infoText;
+    QString buttonText;
+    QObject *object;
+    const char *buttonPressMember;
+    QObject *cancelObject;
+    const char *cancelButtonPressMember;
+    friend class InfoBar;
+    friend class InfoBarDisplay;
+};
+
+class CORE_EXPORT InfoBar : public QObject
+{
+    Q_OBJECT
+
+public:
+    void addInfo(const InfoBarEntry &info);
+    void removeInfo(const QString &id);
+    void clear();
+
+signals:
+    void changed();
+
+private:
+    QList<InfoBarEntry> m_infoBarEntries;
+    friend class InfoBarDisplay;
+};
+
+class CORE_EXPORT InfoBarDisplay : public QObject
+{
+    Q_OBJECT
+
+public:
+    InfoBarDisplay(QObject *parent = 0);
+    void setTarget(QBoxLayout *layout, int index);
+    void setInfoBar(InfoBar *infoBar);
+
+private slots:
+    void cancelButtonClicked();
+    void update();
+    void infoBarDestroyed();
+    void widgetDestroyed();
+
+private:
+    QList<QWidget *> m_infoWidgets;
+    InfoBar *m_infoBar;
+    QBoxLayout *m_boxLayout;
+    int m_boxIndex;
+};
+
+} // namespace Core
+
+#endif // INFOBAR_H
index ceda0a6..dc92a16 100644 (file)
@@ -68,6 +68,7 @@
 #include <cpptools/cppcodeformatter.h>
 
 #include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/actionmanager/actionmanager.h>
 #include <coreplugin/actionmanager/actioncontainer.h>
 #include <coreplugin/actionmanager/command.h>
@@ -444,9 +445,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent)
 
 CPPEditorWidget::~CPPEditorWidget()
 {
-    if (Core::EditorManager *em = Core::EditorManager::instance())
-        em->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));
-
     m_semanticHighlighter->abort();
     m_semanticHighlighter->wait();
 
@@ -685,10 +683,12 @@ void CPPEditorWidget::renameUsagesNow(const QString &replacement)
     if (Symbol *canonicalSymbol = cs(textCursor())) {
         if (canonicalSymbol->identifier() != 0) {
             if (showWarningMessage()) {
-                Core::EditorManager::instance()->showEditorInfoBar(QLatin1String("CppEditor.Rename"),
-                                                                   tr("This change cannot be undone."),
-                                                                   tr("Yes, I know what I am doing."),
-                                                                   this, SLOT(hideRenameNotification()));
+                // FIXME: abuse
+                Core::InfoBarEntry info(QLatin1String("CppEditor.Rename"),
+                                        tr("This change cannot be undone."));
+                info.setCustomButtonInfo(tr("Yes, I know what I am doing."),
+                                         this, SLOT(hideRenameNotification()));
+                file()->infoBar()->addInfo(info);
             }
 
             m_modelManager->renameUsages(canonicalSymbol, cs.context(), replacement);
@@ -727,7 +727,7 @@ void CPPEditorWidget::setShowWarningMessage(bool showWarningMessage)
 void CPPEditorWidget::hideRenameNotification()
 {
     setShowWarningMessage(false);
-    Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));
+    file()->infoBar()->removeInfo(QLatin1String("CppEditor.Rename"));
 }
 
 void CPPEditorWidget::markSymbolsNow()
index 9c23dc0..9ae5454 100644 (file)
@@ -43,6 +43,7 @@
 #include <coreplugin/progressmanager/futureprogress.h>
 #include <coreplugin/editormanager/editormanager.h>
 #include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
 
 #include <ASTVisitor.h>
 #include <AST.h>
@@ -279,7 +280,9 @@ void CppFindReferences::findAll_helper(Symbol *symbol, const LookupContext &cont
 void CppFindReferences::onReplaceButtonClicked(const QString &text,
                                                const QList<Find::SearchResultItem> &items)
 {
-    Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));
+    // FIXME: abuse
+    Core::EditorManager::instance()->currentEditor()->file()->infoBar()->removeInfo(
+            QLatin1String("CppEditor.Rename"));
 
     const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items);
     if (!fileNames.isEmpty()) {
index c023a18..6d5c5b9 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <coreplugin/coreconstants.h>
 #include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/fileiconprovider.h>
 #include <coreplugin/editormanager/editormanager.h>
 #include <coreplugin/modemanager.h>
@@ -58,8 +59,6 @@ FormEditorFactory::FormEditorFactory()
     Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
     iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/formeditor/images/qt_ui.png")),
                                                QLatin1String("ui"));
-    connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
-             SLOT(updateEditorInfoBar(Core::IEditor*)));
 }
 
 QString FormEditorFactory::id() const
@@ -75,7 +74,15 @@ QString FormEditorFactory::displayName() const
 Core::IFile *FormEditorFactory::open(const QString &fileName)
 {
     Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
-    return iface ? iface->file() : 0;
+    if (!iface)
+        return 0;
+    if (qobject_cast<FormWindowEditor *>(iface)) {
+        Core::InfoBarEntry info(Constants::INFO_READ_ONLY,
+                                tr("This file can only be edited in <b>Design</b> mode."));
+        info.setCustomButtonInfo(tr("Switch mode"), this, SLOT(designerModeClicked()));
+        iface->file()->infoBar()->addInfo(info);
+    }
+    return iface->file();
 }
 
 Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
@@ -89,17 +96,6 @@ QStringList FormEditorFactory::mimeTypes() const
     return m_mimeTypes;
 }
 
-void FormEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
-{
-    if (qobject_cast<FormWindowEditor *>(editor)) {
-        Core::EditorManager::instance()->showEditorInfoBar(Constants::INFO_READ_ONLY,
-            tr("This file can only be edited in <b>Design</b> mode."),
-            tr("Switch mode"), this, SLOT(designerModeClicked()));
-    } else {
-        Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_READ_ONLY);
-    }
-}
-
 void FormEditorFactory::designerModeClicked()
 {
     Core::ICore::instance()->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
index 1ade651..6141e3a 100644 (file)
@@ -61,7 +61,6 @@ public:
 
 private slots:
     void designerModeClicked();
-    void updateEditorInfoBar(Core::IEditor *editor);
 
 private:
     const QStringList m_mimeTypes;
index 0216c24..e309ea8 100644 (file)
@@ -41,6 +41,7 @@
 #include <extensionsystem/pluginspec.h>
 
 #include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/editormanager/editormanager.h>
 
 #include <QtCore/QFileInfo>
@@ -121,16 +122,15 @@ Core::IFile *QmlJSEditorFactory::open(const QString &fileName)
 
 Core::IEditor *QmlJSEditorFactory::createEditor(QWidget *parent)
 {
-    static bool listenerInitialized = false;
-    if (!listenerInitialized) {
-        listenerInitialized = true;
-        if (isNaggingAboutExperimentalDesignerEnabled()) {
-            connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
-                     SLOT(updateEditorInfoBar(Core::IEditor*)));
-        }
-    }
     QmlJSEditor::QmlJSTextEditorWidget *rc = new QmlJSEditor::QmlJSTextEditorWidget(parent);
     QmlJSEditorPlugin::instance()->initializeEditor(rc);
+    if (isNaggingAboutExperimentalDesignerEnabled()) {
+        Core::InfoBarEntry info(QMLDESIGNER_INFO_BAR,
+                                tr("Do you want to enable the experimental Qt Quick Designer?"));
+        info.setCustomButtonInfo(tr("Enable Qt Quick Designer"), this, SLOT(activateQmlDesigner()));
+        info.setCancelButtonInfo(this, SLOT(neverAskAgainAboutQmlDesigner()));
+        rc->file()->infoBar()->addInfo(info);
+    }
     return rc->editor();
 }
 
@@ -139,19 +139,6 @@ QStringList QmlJSEditorFactory::mimeTypes() const
     return m_mimeTypes;
 }
 
-void QmlJSEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
-{
-    if (qobject_cast<QmlJSEditorEditable *>(editor)) {
-        Core::EditorManager::instance()->showEditorInfoBar(QMLDESIGNER_INFO_BAR,
-            tr("Do you want to enable the experimental Qt Quick Designer?"),
-            tr("Enable Qt Quick Designer"), this,
-            SLOT(activateQmlDesigner()),
-            SLOT(neverAskAgainAboutQmlDesigner()));
-    } else {
-        Core::EditorManager::instance()->hideEditorInfoBar(QMLDESIGNER_INFO_BAR);
-    }
-}
-
 void QmlJSEditorFactory::activateQmlDesigner()
 {
     QString menu;
@@ -178,9 +165,9 @@ void QmlJSEditorFactory::activateQmlDesigner()
                 pm->writeSettings();
                 QMessageBox::information(Core::ICore::instance()->mainWindow(), tr("Please restart Qt Creator"),
                                          tr("Please restart Qt Creator to make the change effective."));
-                disconnect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
-                         this, SLOT(updateEditorInfoBar(Core::IEditor*)));
-                Core::EditorManager::instance()->hideEditorInfoBar(QMLDESIGNER_INFO_BAR);
+                foreach (Core::IEditor *editor, Core::EditorManager::instance()->openedEditors())
+                    if (qobject_cast<QmlJSEditorEditable *>(editor))
+                        editor->file()->infoBar()->removeInfo(QMLDESIGNER_INFO_BAR);
                 neverAskAgainAboutQmlDesigner();
                 return;
             }
index a0df26b..7a7ef53 100644 (file)
@@ -64,7 +64,6 @@ public:
 private slots:
     void activateQmlDesigner();
     void neverAskAgainAboutQmlDesigner();
-    void updateEditorInfoBar(Core::IEditor *editor);
 
 private:
     QStringList m_mimeTypes;
index 2bce4e2..3a7e1e0 100644 (file)
@@ -47,6 +47,7 @@
 #include <projectexplorer/project.h>
 
 #include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/editormanager/ieditor.h>
 #include <coreplugin/uniqueidmanager.h>
 #include <coreplugin/editormanager/editormanager.h>
@@ -568,19 +569,20 @@ void QmlJSLiveTextPreview::documentChanged(QmlJS::Document::Ptr doc)
 
 void QmlJSLiveTextPreview::showExperimentalWarning()
 {
-    Core::EditorManager *em = Core::EditorManager::instance();
-    em->showEditorInfoBar(Constants::INFO_EXPERIMENTAL,
-                          tr("You changed a QML file in Live Preview mode, which modifies the running QML application. "
-                             "In case of unexpected behavior, please reload the QML application. "
-                             ),
-                          tr("Disable Live Preview"), this, SLOT(disableLivePreview()));
+    foreach (QWeakPointer<QmlJSEditor::QmlJSTextEditorWidget> editor, m_editors)
+        if (editor) {
+            Core::InfoBarEntry info(
+                    Constants::INFO_EXPERIMENTAL,
+                    tr("You changed a QML file in Live Preview mode, which modifies the running QML application. "
+                       "In case of unexpected behavior, please reload the QML application."));
+            info.setCustomButtonInfo(tr("Disable Live Preview"), this, SLOT(disableLivePreview()));
+            editor.data()->file()->infoBar()->addInfo(info);
+        }
 }
 
 void QmlJSLiveTextPreview::showSyncWarning(UnsyncronizableChangeType unsyncronizableChangeType,
                                            const QString &elementName, unsigned line, unsigned column)
 {
-    Core::EditorManager *em = Core::EditorManager::instance();
-
     QString errorMessage;
     switch (unsyncronizableChangeType) {
         case AttributeChangeWarning:
@@ -598,18 +600,25 @@ void QmlJSLiveTextPreview::showSyncWarning(UnsyncronizableChangeType unsyncroniz
 
     errorMessage.append(tr("You can continue debugging, but behavior can be unexpected."));
 
-    em->showEditorInfoBar(Constants::INFO_OUT_OF_SYNC, errorMessage);
+    foreach (QWeakPointer<QmlJSEditor::QmlJSTextEditorWidget> editor, m_editors)
+        if (editor)
+            editor.data()->file()->infoBar()->addInfo(Core::InfoBarEntry(
+                    QLatin1String(Constants::INFO_OUT_OF_SYNC), errorMessage));
 }
 
 void QmlJSLiveTextPreview::reloadQmlViewer()
 {
-    Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_OUT_OF_SYNC);
+    foreach (QWeakPointer<QmlJSEditor::QmlJSTextEditorWidget> editor, m_editors)
+        if (editor)
+            editor.data()->file()->infoBar()->removeInfo(Constants::INFO_OUT_OF_SYNC);
     emit reloadQmlViewerRequested();
 }
 
 void QmlJSLiveTextPreview::disableLivePreview()
 {
-    Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_EXPERIMENTAL);
+    foreach (QWeakPointer<QmlJSEditor::QmlJSTextEditorWidget> editor, m_editors)
+        if (editor)
+            editor.data()->file()->infoBar()->removeInfo(Constants::INFO_OUT_OF_SYNC);
     emit disableLivePreviewRequested();
 }
 
index 59e5ed7..d89c7ce 100644 (file)
@@ -56,6 +56,7 @@
 #include <coreplugin/coreconstants.h>
 #include <coreplugin/editormanager/editormanager.h>
 #include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
 #include <coreplugin/manhattanstyle.h>
 #include <coreplugin/uniqueidmanager.h>
 #include <extensionsystem/pluginmanager.h>
@@ -252,9 +253,6 @@ BaseTextEditorWidget::BaseTextEditorWidget(QWidget *parent)
     d->m_delayedUpdateTimer->setSingleShot(true);
     connect(d->m_delayedUpdateTimer, SIGNAL(timeout()), viewport(), SLOT(update()));
 
-    connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
-            this, SLOT(currentEditorChanged(Core::IEditor*)));
-
     d->m_moveLineUndoHack = false;
 }
 
@@ -502,19 +500,6 @@ BaseTextEditor *BaseTextEditorWidget::editor() const
 }
 
 
-void BaseTextEditorWidget::currentEditorChanged(Core::IEditor *ed)
-{
-    if (ed == editor()) {
-        if (d->m_document->hasDecodingError()) {
-            Core::EditorManager::instance()->showEditorInfoBar(QLatin1String(Constants::SELECT_ENCODING),
-                tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
-                    .arg(displayName()).arg(QString::fromLatin1(d->m_document->codec()->name())),
-                tr("Select Encoding"),
-                this, SLOT(selectEncoding()));
-        }
-    }
-}
-
 void BaseTextEditorWidget::selectEncoding()
 {
     BaseTextDocument *doc = d->m_document;
@@ -527,11 +512,6 @@ void BaseTextEditorWidget::selectEncoding()
             QMessageBox::critical(this, tr("File Error"), errorString);
             break;
         }
-        setReadOnly(d->m_document->hasDecodingError());
-        if (doc->hasDecodingError())
-            currentEditorChanged(Core::EditorManager::instance()->currentEditor());
-        else
-            Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String(Constants::SELECT_ENCODING));
         break; }
     case CodecSelector::Save:
         doc->setCodec(codecSelector.selectedCodec());
@@ -560,11 +540,26 @@ bool BaseTextEditorWidget::createNew(const QString &contents)
     return true;
 }
 
+void BaseTextEditorWidget::updateCannotDecodeInfo()
+{
+    setReadOnly(d->m_document->hasDecodingError());
+    if (d->m_document->hasDecodingError()) {
+        Core::InfoBarEntry info(
+            QLatin1String(Constants::SELECT_ENCODING),
+            tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
+            .arg(displayName()).arg(QString::fromLatin1(d->m_document->codec()->name())));
+        info.setCustomButtonInfo(tr("Select Encoding"), this, SLOT(selectEncoding()));
+        d->m_document->infoBar()->addInfo(info);
+    } else {
+        d->m_document->infoBar()->removeInfo(QLatin1String(Constants::SELECT_ENCODING));
+    }
+}
+
 bool BaseTextEditorWidget::open(QString *errorString, const QString &fileName)
 {
     if (d->m_document->open(errorString, fileName)) {
         moveCursor(QTextCursor::Start);
-        setReadOnly(d->m_document->hasDecodingError());
+        updateCannotDecodeInfo();
         return true;
     }
     return false;
@@ -2122,6 +2117,7 @@ void BaseTextEditorWidget::documentReloaded()
 {
     // restore cursor position
     restoreState(d->m_tempState);
+    updateCannotDecodeInfo();
 }
 
 QByteArray BaseTextEditorWidget::saveState() const
index 6e2282d..9c49764 100644 (file)
@@ -323,6 +323,7 @@ protected:
 
 private:
     void maybeSelectLine();
+    void updateCannotDecodeInfo();
 
 public:
     void duplicateFrom(BaseTextEditorWidget *editor);
@@ -343,7 +344,6 @@ private slots:
     void setFindScope(const QTextCursor &start, const QTextCursor &end, int, int);
     bool inFindScope(const QTextCursor &cursor);
     bool inFindScope(int selectionStart, int selectionEnd);
-    void currentEditorChanged(Core::IEditor *editor);
     void inSnippetMode(bool *active);
 
 private:
index cae1300..accf655 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <coreplugin/coreconstants.h>
 #include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/infobar.h>
 
 #include <QtCore/QDebug>
 
@@ -56,9 +57,6 @@ PlainTextEditorFactory::PlainTextEditorFactory(QObject *parent)
         TextEditorActionHandler::UnCommentSelection |
         TextEditorActionHandler::UnCollapseAll);
     m_mimeTypes << QLatin1String(TextEditor::Constants::C_TEXTEDITOR_MIMETYPE_TEXT);
-
-    connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
-            this, SLOT(updateEditorInfoBar(Core::IEditor*)));
 }
 
 PlainTextEditorFactory::~PlainTextEditorFactory()
@@ -88,6 +86,7 @@ Core::IEditor *PlainTextEditorFactory::createEditor(QWidget *parent)
     TextEditorPlugin::instance()->initializeEditor(rc);
     connect(rc, SIGNAL(configured(Core::IEditor*)),
             this, SLOT(updateEditorInfoBar(Core::IEditor*)));
+    updateEditorInfoBar(rc->editor());
     return rc->editor();
 }
 
@@ -99,18 +98,17 @@ void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
         if (textEditor->isMissingSyntaxDefinition() &&
             !textEditor->ignoreMissingSyntaxDefinition() &&
             TextEditorSettings::instance()->highlighterSettings().alertWhenNoDefinition()) {
-            Core::EditorManager::instance()->showEditorInfoBar(
-                Constants::INFO_SYNTAX_DEFINITION,
-                tr("A highlight definition was not found for this file. "
-                   "Would you like to try to find one?"),
-                tr("Show highlighter options"),
-                textEditor,
-                SLOT(acceptMissingSyntaxDefinitionInfo()),
-                SLOT(ignoreMissingSyntaxDefinitionInfo()));
+            Core::InfoBarEntry info(Constants::INFO_SYNTAX_DEFINITION,
+                                    tr("A highlight definition was not found for this file. "
+                                       "Would you like to try to find one?"));
+            info.setCustomButtonInfo(tr("Show highlighter options"),
+                                     textEditor, SLOT(acceptMissingSyntaxDefinitionInfo()));
+            info.setCancelButtonInfo(textEditor, SLOT(ignoreMissingSyntaxDefinitionInfo()));
+            editor->file()->infoBar()->addInfo(info);
             return;
         }
+        editor->file()->infoBar()->removeInfo(Constants::INFO_SYNTAX_DEFINITION);
     }
-    Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_SYNTAX_DEFINITION);
 }
 
 void PlainTextEditorFactory::addMimeType(const QString &type)