#include "cmakeprojectconstants.h"
#include "cmakeproject.h"
+#include <coreplugin/infobar.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <texteditor/fontsettings.h>
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()
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QtCore/QMap>
!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();
mimedatabase.cpp \
icore.cpp \
ifile.cpp \
+ infobar.cpp \
editormanager/ieditor.cpp \
dialogs/ioptionspage.cpp \
dialogs/iwizard.cpp \
icontext.h \
icore.h \
ifile.h \
+ infobar.h \
ifilefactory.h \
imode.h \
ioutputpane.h \
#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>
#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
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,
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(),
#include <coreplugin/editortoolbar.h>
#include <coreplugin/coreconstants.h>
+#include <coreplugin/infobar.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/editormanager/ieditor.h>
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)
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);
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,
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;
}
m_toolBar->setCurrentEditor(editor);
updateEditorHistory(editor);
+
+ m_infoBarDisplay->setInfoBar(editor->file()->infoBar());
}
int EditorView::editorCount() const
class IContext;
class IFile;
class IEditor;
+class InfoBarDisplay;
class OpenEditorsModel;
class EditorToolBar;
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,
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;
#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
{
}
+InfoBar *IFile::infoBar()
+{
+ if (!m_infoBar)
+ m_infoBar = new InfoBar;
+ return m_infoBar;
+}
+
} // namespace Core
namespace Core {
class MimeType;
+class InfoBar;
class CORE_EXPORT IFile : public QObject
{
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
--- /dev/null
+/**************************************************************************
+**
+** 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
--- /dev/null
+/**************************************************************************
+**
+** 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
#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>
CPPEditorWidget::~CPPEditorWidget()
{
- if (Core::EditorManager *em = Core::EditorManager::instance())
- em->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));
-
m_semanticHighlighter->abort();
m_semanticHighlighter->wait();
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);
void CPPEditorWidget::hideRenameNotification()
{
setShowWarningMessage(false);
- Core::EditorManager::instance()->hideEditorInfoBar(QLatin1String("CppEditor.Rename"));
+ file()->infoBar()->removeInfo(QLatin1String("CppEditor.Rename"));
}
void CPPEditorWidget::markSymbolsNow()
#include <coreplugin/progressmanager/futureprogress.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
#include <ASTVisitor.h>
#include <AST.h>
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()) {
#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>
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
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)
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));
private slots:
void designerModeClicked();
- void updateEditorInfoBar(Core::IEditor *editor);
private:
const QStringList m_mimeTypes;
#include <extensionsystem/pluginspec.h>
#include <coreplugin/icore.h>
+#include <coreplugin/infobar.h>
#include <coreplugin/editormanager/editormanager.h>
#include <QtCore/QFileInfo>
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();
}
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;
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;
}
private slots:
void activateQmlDesigner();
void neverAskAgainAboutQmlDesigner();
- void updateEditorInfoBar(Core::IEditor *editor);
private:
QStringList m_mimeTypes;
#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>
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:
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();
}
#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>
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;
}
}
-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;
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());
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;
{
// restore cursor position
restoreState(d->m_tempState);
+ updateCannotDecodeInfo();
}
QByteArray BaseTextEditorWidget::saveState() const
private:
void maybeSelectLine();
+ void updateCannotDecodeInfo();
public:
void duplicateFrom(BaseTextEditorWidget *editor);
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:
#include <coreplugin/coreconstants.h>
#include <coreplugin/editormanager/editormanager.h>
+#include <coreplugin/infobar.h>
#include <QtCore/QDebug>
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()
TextEditorPlugin::instance()->initializeEditor(rc);
connect(rc, SIGNAL(configured(Core::IEditor*)),
this, SLOT(updateEditorInfoBar(Core::IEditor*)));
+ updateEditorInfoBar(rc->editor());
return rc->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)