Commit 10be8c9a authored by Orgad Shaneh's avatar Orgad Shaneh Committed by hjk
Browse files

InfoBar: Use Core::Id



Change-Id: I0918fbc20027a340facbedc685938a72d117d53b
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent 192e3f81
...@@ -84,7 +84,7 @@ void CMakeEditor::markAsChanged() ...@@ -84,7 +84,7 @@ void CMakeEditor::markAsChanged()
if (m_infoBarShown) if (m_infoBarShown)
return; return;
m_infoBarShown = true; m_infoBarShown = true;
Core::InfoBarEntry info(QLatin1String("CMakeEditor.RunCMake"), Core::InfoBarEntry info(Core::Id("CMakeEditor.RunCMake"),
tr("Changes to cmake files are shown in the project tree after building.")); tr("Changes to cmake files are shown in the project tree after building."));
info.setCustomButtonInfo(tr("Build now"), this, SLOT(build())); info.setCustomButtonInfo(tr("Build now"), this, SLOT(build()));
document()->infoBar()->addInfo(info); document()->infoBar()->addInfo(info);
......
...@@ -208,7 +208,7 @@ bool CMakeProject::parseCMakeLists() ...@@ -208,7 +208,7 @@ bool CMakeProject::parseCMakeLists()
CMakeBuildConfiguration *activeBC = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration()); CMakeBuildConfiguration *activeBC = static_cast<CMakeBuildConfiguration *>(activeTarget()->activeBuildConfiguration());
foreach (Core::IEditor *editor, Core::EditorManager::instance()->openedEditors()) foreach (Core::IEditor *editor, Core::EditorManager::instance()->openedEditors())
if (isProjectFile(editor->document()->fileName())) if (isProjectFile(editor->document()->fileName()))
editor->document()->infoBar()->removeInfo(QLatin1String("CMakeEditor.RunCMake")); editor->document()->infoBar()->removeInfo(Core::Id("CMakeEditor.RunCMake"));
// Find cbp file // Find cbp file
QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory()); QString cbpFile = CMakeManager::findCbpFile(activeBC->buildDirectory());
......
...@@ -1711,19 +1711,19 @@ void EditorManager::updateMakeWritableWarning() ...@@ -1711,19 +1711,19 @@ void EditorManager::updateMakeWritableWarning()
if (ww) { if (ww) {
// we are about to change a read-only file, warn user // we are about to change a read-only file, warn user
if (promptVCS) { if (promptVCS) {
InfoBarEntry info(QLatin1String(kMakeWritableWarning), InfoBarEntry info(Id(kMakeWritableWarning),
tr("<b>Warning:</b> This file was not opened in %1 yet.") tr("<b>Warning:</b> This file was not opened in %1 yet.")
.arg(versionControl->displayName())); .arg(versionControl->displayName()));
info.setCustomButtonInfo(tr("Open"), this, SLOT(vcsOpenCurrentEditor())); info.setCustomButtonInfo(tr("Open"), this, SLOT(vcsOpenCurrentEditor()));
curEditor->document()->infoBar()->addInfo(info); curEditor->document()->infoBar()->addInfo(info);
} else { } else {
InfoBarEntry info(QLatin1String(kMakeWritableWarning), InfoBarEntry info(Id(kMakeWritableWarning),
tr("<b>Warning:</b> You are changing a read-only file.")); tr("<b>Warning:</b> You are changing a read-only file."));
info.setCustomButtonInfo(tr("Make Writable"), this, SLOT(makeCurrentEditorWritable())); info.setCustomButtonInfo(tr("Make Writable"), this, SLOT(makeCurrentEditorWritable()));
curEditor->document()->infoBar()->addInfo(info); curEditor->document()->infoBar()->addInfo(info);
} }
} else { } else {
curEditor->document()->infoBar()->removeInfo(QLatin1String(kMakeWritableWarning)); curEditor->document()->infoBar()->removeInfo(Id(kMakeWritableWarning));
} }
} }
} }
......
...@@ -85,7 +85,7 @@ void IDocument::setRestoredFrom(const QString &name) ...@@ -85,7 +85,7 @@ void IDocument::setRestoredFrom(const QString &name)
{ {
m_autoSaveName = name; m_autoSaveName = name;
m_restored = true; m_restored = true;
InfoBarEntry info(QLatin1String(kRestoredAutoSave), InfoBarEntry info(Id(kRestoredAutoSave),
tr("File was restored from auto-saved copy. " tr("File was restored from auto-saved copy. "
"Select Save to confirm or Revert to Saved to discard changes.")); "Select Save to confirm or Revert to Saved to discard changes."));
infoBar()->addInfo(info); infoBar()->addInfo(info);
...@@ -98,7 +98,7 @@ void IDocument::removeAutoSaveFile() ...@@ -98,7 +98,7 @@ void IDocument::removeAutoSaveFile()
m_autoSaveName.clear(); m_autoSaveName.clear();
if (m_restored) { if (m_restored) {
m_restored = false; m_restored = false;
infoBar()->removeInfo(QLatin1String(kRestoredAutoSave)); infoBar()->removeInfo(Id(kRestoredAutoSave));
} }
} }
} }
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
namespace Core { namespace Core {
InfoBarEntry::InfoBarEntry(const QString &_id, const QString &_infoText) InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText)
: id(_id) : id(_id)
, infoText(_infoText) , infoText(_infoText)
, object(0) , object(0)
...@@ -77,7 +77,7 @@ void InfoBar::addInfo(const InfoBarEntry &info) ...@@ -77,7 +77,7 @@ void InfoBar::addInfo(const InfoBarEntry &info)
emit changed(); emit changed();
} }
void InfoBar::removeInfo(const QString &id) void InfoBar::removeInfo(Id id)
{ {
QMutableListIterator<InfoBarEntry> it(m_infoBarEntries); QMutableListIterator<InfoBarEntry> it(m_infoBarEntries);
while (it.hasNext()) while (it.hasNext())
...@@ -88,7 +88,7 @@ void InfoBar::removeInfo(const QString &id) ...@@ -88,7 +88,7 @@ void InfoBar::removeInfo(const QString &id)
} }
} }
bool InfoBar::containsInfo(const QString &id) const bool InfoBar::containsInfo(Id id) const
{ {
QListIterator<InfoBarEntry> it(m_infoBarEntries); QListIterator<InfoBarEntry> it(m_infoBarEntries);
while (it.hasNext()) while (it.hasNext())
...@@ -183,7 +183,7 @@ void InfoBarDisplay::update() ...@@ -183,7 +183,7 @@ void InfoBarDisplay::update()
} }
QToolButton *infoWidgetCloseButton = new QToolButton; QToolButton *infoWidgetCloseButton = new QToolButton;
infoWidgetCloseButton->setProperty("infoId", info.id); infoWidgetCloseButton->setProperty("infoId", info.id.uniqueIdentifier());
// need to connect to cancelObjectbefore connecting to cancelButtonClicked, // need to connect to cancelObjectbefore connecting to cancelButtonClicked,
// because the latter removes the button and with it any connect // because the latter removes the button and with it any connect
...@@ -216,7 +216,7 @@ void InfoBarDisplay::widgetDestroyed() ...@@ -216,7 +216,7 @@ void InfoBarDisplay::widgetDestroyed()
void InfoBarDisplay::cancelButtonClicked() void InfoBarDisplay::cancelButtonClicked()
{ {
m_infoBar->removeInfo(sender()->property("infoId").toString()); m_infoBar->removeInfo(Id::fromUniqueIdentifier(sender()->property("infoId").toInt()));
} }
} // namespace Core } // namespace Core
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#define INFOBAR_H #define INFOBAR_H
#include "core_global.h" #include "core_global.h"
#include <coreplugin/id.h>
#include <QObject> #include <QObject>
...@@ -46,14 +47,14 @@ class InfoBarDisplay; ...@@ -46,14 +47,14 @@ class InfoBarDisplay;
class CORE_EXPORT InfoBarEntry class CORE_EXPORT InfoBarEntry
{ {
public: public:
InfoBarEntry(const QString &_id, const QString &_infoText); InfoBarEntry(Id _id, const QString &_infoText);
InfoBarEntry(const InfoBarEntry &other) { *this = other; } InfoBarEntry(const InfoBarEntry &other) { *this = other; }
void setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member); void setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member);
void setCancelButtonInfo(QObject *_object, const char *_member); void setCancelButtonInfo(QObject *_object, const char *_member);
void setCancelButtonInfo(const QString &_cancelButtonText, QObject *_object, const char *_member); void setCancelButtonInfo(const QString &_cancelButtonText, QObject *_object, const char *_member);
private: private:
QString id; Id id;
QString infoText; QString infoText;
QString buttonText; QString buttonText;
QObject *object; QObject *object;
...@@ -71,8 +72,8 @@ class CORE_EXPORT InfoBar : public QObject ...@@ -71,8 +72,8 @@ class CORE_EXPORT InfoBar : public QObject
public: public:
void addInfo(const InfoBarEntry &info); void addInfo(const InfoBarEntry &info);
void removeInfo(const QString &id); void removeInfo(Id id);
bool containsInfo(const QString &id) const; bool containsInfo(Id id) const;
void clear(); void clear();
signals: signals:
......
...@@ -714,7 +714,7 @@ void QmlLiveTextPreview::showSyncWarning( ...@@ -714,7 +714,7 @@ void QmlLiveTextPreview::showSyncWarning(
foreach (TextEditor::BaseTextEditorWidget *editor, m_editors) { foreach (TextEditor::BaseTextEditorWidget *editor, m_editors) {
if (editor) { if (editor) {
Core::InfoBar *infoBar = editor->editorDocument()->infoBar(); Core::InfoBar *infoBar = editor->editorDocument()->infoBar();
Core::InfoBarEntry info(QLatin1String(INFO_OUT_OF_SYNC), errorMessage); Core::InfoBarEntry info(Core::Id(INFO_OUT_OF_SYNC), errorMessage);
BaseToolsClient *toolsClient = m_inspectorAdapter->toolsClient(); BaseToolsClient *toolsClient = m_inspectorAdapter->toolsClient();
if (toolsClient && toolsClient->supportReload()) if (toolsClient && toolsClient->supportReload())
info.setCustomButtonInfo(tr("Reload QML"), this, info.setCustomButtonInfo(tr("Reload QML"), this,
...@@ -735,7 +735,7 @@ void QmlLiveTextPreview::removeOutofSyncInfo() ...@@ -735,7 +735,7 @@ void QmlLiveTextPreview::removeOutofSyncInfo()
foreach (TextEditor::BaseTextEditorWidget *editor, m_editors) { foreach (TextEditor::BaseTextEditorWidget *editor, m_editors) {
if (editor) { if (editor) {
Core::InfoBar *infoBar = editor->editorDocument()->infoBar(); Core::InfoBar *infoBar = editor->editorDocument()->infoBar();
infoBar->removeInfo(QLatin1String(INFO_OUT_OF_SYNC)); infoBar->removeInfo(Core::Id(INFO_OUT_OF_SYNC));
} }
} }
} }
......
...@@ -75,7 +75,7 @@ Core::IDocument *FormEditorFactory::open(const QString &fileName) ...@@ -75,7 +75,7 @@ Core::IDocument *FormEditorFactory::open(const QString &fileName)
if (!iface) if (!iface)
return 0; return 0;
if (qobject_cast<FormWindowEditor *>(iface)) { if (qobject_cast<FormWindowEditor *>(iface)) {
Core::InfoBarEntry info(QLatin1String(Constants::INFO_READ_ONLY), Core::InfoBarEntry info(Core::Id(Constants::INFO_READ_ONLY),
tr("This file can only be edited in <b>Design</b> mode.")); tr("This file can only be edited in <b>Design</b> mode."));
info.setCustomButtonInfo(tr("Switch mode"), this, SLOT(designerModeClicked())); info.setCustomButtonInfo(tr("Switch mode"), this, SLOT(designerModeClicked()));
iface->document()->infoBar()->addInfo(info); iface->document()->infoBar()->addInfo(info);
......
...@@ -222,7 +222,7 @@ void SearchResultWidget::addResults(const QList<SearchResultItem> &items, Search ...@@ -222,7 +222,7 @@ void SearchResultWidget::addResults(const QList<SearchResultItem> &items, Search
updateMatchesFoundLabel(); updateMatchesFoundLabel();
if (firstItems) { if (firstItems) {
if (showWarningMessage()) { if (showWarningMessage()) {
Core::InfoBarEntry info(QLatin1String(UNDO_WARNING_ID), tr("This change cannot be undone.")); Core::InfoBarEntry info(Core::Id(UNDO_WARNING_ID), tr("This change cannot be undone."));
info.setCustomButtonInfo(tr("Do not warn again"), this, SLOT(hideNoUndoWarning())); info.setCustomButtonInfo(tr("Do not warn again"), this, SLOT(hideNoUndoWarning()));
m_infoBar.addInfo(info); m_infoBar.addInfo(info);
} }
...@@ -240,7 +240,7 @@ void SearchResultWidget::addResults(const QList<SearchResultItem> &items, Search ...@@ -240,7 +240,7 @@ void SearchResultWidget::addResults(const QList<SearchResultItem> &items, Search
} else if (m_count > SEARCHRESULT_WARNING_LIMIT && !m_sizeWarningOverridden && !m_sizeWarningActive) { } else if (m_count > SEARCHRESULT_WARNING_LIMIT && !m_sizeWarningOverridden && !m_sizeWarningActive) {
m_sizeWarningActive = true; m_sizeWarningActive = true;
emit paused(true); emit paused(true);
Core::InfoBarEntry info(QLatin1String(SIZE_WARNING_ID), Core::InfoBarEntry info(Core::Id(SIZE_WARNING_ID),
tr("The search resulted in more than %n items, do you still want to continue?", tr("The search resulted in more than %n items, do you still want to continue?",
0, SEARCHRESULT_WARNING_LIMIT)); 0, SEARCHRESULT_WARNING_LIMIT));
info.setCancelButtonInfo(tr("Cancel"), this, SLOT(cancelAfterSizeWarning())); info.setCancelButtonInfo(tr("Cancel"), this, SLOT(cancelAfterSizeWarning()));
...@@ -367,7 +367,7 @@ void SearchResultWidget::restart() ...@@ -367,7 +367,7 @@ void SearchResultWidget::restart()
m_searchResultTreeView->clear(); m_searchResultTreeView->clear();
m_count = 0; m_count = 0;
if (m_sizeWarningActive) if (m_sizeWarningActive)
m_infoBar.removeInfo(QLatin1String(SIZE_WARNING_ID)); m_infoBar.removeInfo(Core::Id(SIZE_WARNING_ID));
m_sizeWarningActive = false; m_sizeWarningActive = false;
m_sizeWarningOverridden = false; m_sizeWarningOverridden = false;
m_cancelButton->setVisible(true); m_cancelButton->setVisible(true);
...@@ -391,7 +391,7 @@ void SearchResultWidget::setSearchAgainEnabled(bool enabled) ...@@ -391,7 +391,7 @@ void SearchResultWidget::setSearchAgainEnabled(bool enabled)
void SearchResultWidget::finishSearch(bool canceled) void SearchResultWidget::finishSearch(bool canceled)
{ {
if (m_sizeWarningActive) if (m_sizeWarningActive)
m_infoBar.removeInfo(QLatin1String(SIZE_WARNING_ID)); m_infoBar.removeInfo(Core::Id(SIZE_WARNING_ID));
m_sizeWarningActive = false; m_sizeWarningActive = false;
m_sizeWarningOverridden = false; m_sizeWarningOverridden = false;
m_replaceTextEdit->setEnabled(m_count > 0); m_replaceTextEdit->setEnabled(m_count > 0);
...@@ -409,20 +409,20 @@ void SearchResultWidget::sendRequestPopup() ...@@ -409,20 +409,20 @@ void SearchResultWidget::sendRequestPopup()
void SearchResultWidget::hideNoUndoWarning() void SearchResultWidget::hideNoUndoWarning()
{ {
setShowWarningMessage(false); setShowWarningMessage(false);
m_infoBar.removeInfo(QLatin1String(UNDO_WARNING_ID)); m_infoBar.removeInfo(Core::Id(UNDO_WARNING_ID));
} }
void SearchResultWidget::continueAfterSizeWarning() void SearchResultWidget::continueAfterSizeWarning()
{ {
m_sizeWarningOverridden = true; m_sizeWarningOverridden = true;
m_sizeWarningActive = false; m_sizeWarningActive = false;
m_infoBar.removeInfo(QLatin1String(SIZE_WARNING_ID)); m_infoBar.removeInfo(Core::Id(SIZE_WARNING_ID));
emit paused(false); emit paused(false);
} }
void SearchResultWidget::cancelAfterSizeWarning() void SearchResultWidget::cancelAfterSizeWarning()
{ {
m_infoBar.removeInfo(QLatin1String(SIZE_WARNING_ID)); m_infoBar.removeInfo(Core::Id(SIZE_WARNING_ID));
m_sizeWarningOverridden = true; m_sizeWarningOverridden = true;
m_sizeWarningActive = false; m_sizeWarningActive = false;
emit cancelled(); emit cancelled();
...@@ -460,7 +460,7 @@ void SearchResultWidget::searchAgain() ...@@ -460,7 +460,7 @@ void SearchResultWidget::searchAgain()
bool SearchResultWidget::showWarningMessage() const bool SearchResultWidget::showWarningMessage() const
{ {
if (m_dontAskAgainGroup.isEmpty() || m_infoBar.containsInfo(QLatin1String(UNDO_WARNING_ID))) if (m_dontAskAgainGroup.isEmpty() || m_infoBar.containsInfo(Core::Id(UNDO_WARNING_ID)))
return false; return false;
// read settings // read settings
QSettings *settings = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
......
...@@ -568,14 +568,13 @@ void BaseTextEditorWidget::updateCannotDecodeInfo() ...@@ -568,14 +568,13 @@ void BaseTextEditorWidget::updateCannotDecodeInfo()
{ {
setReadOnly(d->m_document->hasDecodingError()); setReadOnly(d->m_document->hasDecodingError());
if (d->m_document->hasDecodingError()) { if (d->m_document->hasDecodingError()) {
Core::InfoBarEntry info( Core::InfoBarEntry info(Core::Id(Constants::SELECT_ENCODING),
QLatin1String(Constants::SELECT_ENCODING),
tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.") tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
.arg(displayName()).arg(QString::fromLatin1(d->m_document->codec()->name()))); .arg(displayName()).arg(QString::fromLatin1(d->m_document->codec()->name())));
info.setCustomButtonInfo(tr("Select Encoding"), this, SLOT(selectEncoding())); info.setCustomButtonInfo(tr("Select Encoding"), this, SLOT(selectEncoding()));
d->m_document->infoBar()->addInfo(info); d->m_document->infoBar()->addInfo(info);
} else { } else {
d->m_document->infoBar()->removeInfo(QLatin1String(Constants::SELECT_ENCODING)); d->m_document->infoBar()->removeInfo(Core::Id(Constants::SELECT_ENCODING));
} }
} }
......
...@@ -91,7 +91,7 @@ void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor) ...@@ -91,7 +91,7 @@ void PlainTextEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
if (!file) if (!file)
return; return;
PlainTextEditorWidget *textEditor = static_cast<PlainTextEditorWidget *>(editorEditable->editorWidget()); PlainTextEditorWidget *textEditor = static_cast<PlainTextEditorWidget *>(editorEditable->editorWidget());
const QString infoSyntaxDefinition = QLatin1String(Constants::INFO_SYNTAX_DEFINITION); Core::Id infoSyntaxDefinition(Constants::INFO_SYNTAX_DEFINITION);
if (textEditor->isMissingSyntaxDefinition() && if (textEditor->isMissingSyntaxDefinition() &&
!textEditor->ignoreMissingSyntaxDefinition() && !textEditor->ignoreMissingSyntaxDefinition() &&
TextEditorSettings::instance()->highlighterSettings().alertWhenNoDefinition()) { TextEditorSettings::instance()->highlighterSettings().alertWhenNoDefinition()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment