Commit f70ba993 authored by hjk's avatar hjk

Core: Use std::function for info bar callbacks

Change-Id: Iae7cbef053bfe86a7692e09f66af91117815d2a6
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent 2e17339b
......@@ -713,7 +713,9 @@ void AndroidManifestEditorWidget::updateInfoBar(const QString &errorMessage, int
else
text = tr("%2: Could not parse file: \"%1\".").arg(errorMessage).arg(line);
Core::InfoBarEntry infoBarEntry(infoBarId, text);
infoBarEntry.setCustomButtonInfo(tr("Goto error"), this, SLOT(gotoError()));
infoBarEntry.setCustomButtonInfo(tr("Goto error"), [this]() {
m_textEditorWidget->gotoLine(m_errorLine, m_errorColumn);
});
infoBar->removeInfo(infoBarId);
infoBar->addInfo(infoBarEntry);
......@@ -729,11 +731,6 @@ void AndroidManifestEditorWidget::hideInfoBar()
m_timerParseCheck.stop();
}
void AndroidManifestEditorWidget::gotoError()
{
m_textEditorWidget->gotoLine(m_errorLine, m_errorColumn);
}
void setApiLevel(QComboBox *box, const QDomElement &element, const QString &attribute)
{
if (!element.isNull() && element.hasAttribute(attribute)) {
......
......@@ -126,7 +126,6 @@ private slots:
void updateAddRemovePermissionButtons();
void setAppName();
void setPackageName();
void gotoError();
void updateInfoBar();
void updateSdkVersions();
void startParseCheck();
......
......@@ -54,6 +54,7 @@
#include <QTextBlock>
using namespace Core;
using namespace ProjectExplorer;
using namespace TextEditor;
namespace CMakeProjectManager {
......@@ -80,24 +81,20 @@ void CMakeEditor::finalizeInitialization()
InfoBarEntry info(infoRunCmake,
tr("Changes to cmake files are shown in the project tree after building."),
InfoBarEntry::GlobalSuppressionEnabled);
info.setCustomButtonInfo(tr("Build now"), this, SLOT(build()));
info.setCustomButtonInfo(tr("Build now"), [document]() {
foreach (Project *p, SessionManager::projects()) {
if (CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(p)) {
if (cmakeProject->isProjectFile(document->filePath())) {
ProjectExplorerPlugin::instance()->buildProject(cmakeProject);
break;
}
}
}
});
infoBar->addInfo(info);
});
}
void CMakeEditor::build()
{
foreach (ProjectExplorer::Project *p, ProjectExplorer::SessionManager::projects()) {
CMakeProject *cmakeProject = qobject_cast<CMakeProject *>(p);
if (cmakeProject) {
if (cmakeProject->isProjectFile(document()->filePath())) {
ProjectExplorer::ProjectExplorerPlugin::instance()->buildProject(cmakeProject);
break;
}
}
}
}
QString CMakeEditor::contextHelpId() const
{
int pos = position();
......
......@@ -49,9 +49,6 @@ public:
QString contextHelpId() const;
friend class CMakeEditorWidget;
public slots:
void build();
};
class CMakeEditorFactory : public TextEditor::BaseTextEditorFactory
......
......@@ -1269,12 +1269,12 @@ void EditorManagerPrivate::updateMakeWritableWarning()
InfoBarEntry info(Id(kMakeWritableWarning),
tr("<b>Warning:</b> This file was not opened in %1 yet.")
.arg(versionControl->displayName()));
info.setCustomButtonInfo(tr("Open"), d, SLOT(vcsOpenCurrentEditor()));
info.setCustomButtonInfo(tr("Open"), &vcsOpenCurrentEditor);
document->infoBar()->addInfo(info);
} else {
InfoBarEntry info(Id(kMakeWritableWarning),
tr("<b>Warning:</b> You are changing a read-only file."));
info.setCustomButtonInfo(tr("Make Writable"), d, SLOT(makeCurrentEditorWritable()));
info.setCustomButtonInfo(tr("Make Writable"), &makeCurrentEditorWritable);
document->infoBar()->addInfo(info);
}
} else {
......
......@@ -110,11 +110,12 @@ public:
static void updateWindowTitleForDocument(IDocument *document, QWidget *window);
static void vcsOpenCurrentEditor();
static void makeCurrentEditorWritable();
public slots:
static bool saveDocument(Core::IDocument *document);
static bool saveDocumentAs(Core::IDocument *document);
static void makeCurrentEditorWritable();
static void vcsOpenCurrentEditor();
static void split(Qt::Orientation orientation);
static void removeAllSplits();
......
......@@ -260,8 +260,8 @@ void SearchResultWidget::addResults(const QList<SearchResultItem> &items, Search
Core::InfoBarEntry info(sizeWarningId,
tr("The search resulted in more than %n items, do you still want to continue?",
0, SEARCHRESULT_WARNING_LIMIT));
info.setCancelButtonInfo(tr("Cancel"), this, SLOT(cancelAfterSizeWarning()));
info.setCustomButtonInfo(tr("Continue"), this, SLOT(continueAfterSizeWarning()));
info.setCancelButtonInfo(tr("Cancel"), [this]() { cancelAfterSizeWarning(); });
info.setCustomButtonInfo(tr("Continue"), [this]() { continueAfterSizeWarning(); });
m_infoBar.addInfo(info);
emit requestPopup(false/*no focus*/);
}
......
......@@ -110,14 +110,15 @@ signals:
void navigateStateChanged();
private slots:
void continueAfterSizeWarning();
void cancelAfterSizeWarning();
void handleJumpToSearchResult(const SearchResultItem &item);
void handleReplaceButton();
void cancel();
void searchAgain();
private:
void continueAfterSizeWarning();
void cancelAfterSizeWarning();
QList<SearchResultItem> checkedItems() const;
void updateMatchesFoundLabel();
......
......@@ -46,32 +46,25 @@ QSet<Id> InfoBar::globallySuppressed;
InfoBarEntry::InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression)
: id(_id)
, infoText(_infoText)
, object(0)
, buttonPressMember(0)
, cancelObject(0)
, cancelButtonPressMember(0)
, globalSuppression(_globalSuppression)
{
}
void InfoBarEntry::setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member)
void InfoBarEntry::setCustomButtonInfo(const QString &_buttonText, CallBack callBack)
{
buttonText = _buttonText;
object = _object;
buttonPressMember = _member;
m_buttonCallBack = callBack;
}
void InfoBarEntry::setCancelButtonInfo(QObject *_object, const char *_member)
void InfoBarEntry::setCancelButtonInfo(CallBack callBack)
{
cancelObject = _object;
cancelButtonPressMember = _member;
m_cancelButtonCallBack = callBack;
}
void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, QObject *_object, const char *_member)
void InfoBarEntry::setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack)
{
cancelButtonText = _cancelButtonText;
cancelObject = _object;
cancelButtonPressMember = _member;
m_cancelButtonCallBack = callBack;
}
......@@ -226,7 +219,7 @@ void InfoBarDisplay::update()
if (!info.buttonText.isEmpty()) {
QToolButton *infoWidgetButton = new QToolButton;
infoWidgetButton->setText(info.buttonText);
connect(infoWidgetButton, SIGNAL(clicked()), info.object, info.buttonPressMember);
connect(infoWidgetButton, &QAbstractButton::clicked, [info]() { info.m_buttonCallBack(); });
hbox->addWidget(infoWidgetButton);
}
......@@ -244,9 +237,8 @@ void InfoBarDisplay::update()
// need to connect to cancelObjectbefore connecting to cancelButtonClicked,
// because the latter removes the button and with it any connect
if (info.cancelObject)
connect(infoWidgetCloseButton, SIGNAL(clicked()),
info.cancelObject, info.cancelButtonPressMember);
if (info.m_cancelButtonCallBack)
connect(infoWidgetCloseButton, &QAbstractButton::clicked, info.m_cancelButtonCallBack);
connect(infoWidgetCloseButton, SIGNAL(clicked()), SLOT(cancelButtonClicked()));
if (info.cancelButtonText.isEmpty()) {
......
......@@ -36,6 +36,8 @@
#include <QObject>
#include <QSet>
#include <functional>
QT_BEGIN_NAMESPACE
class QBoxLayout;
QT_END_NAMESPACE
......@@ -56,19 +58,19 @@ public:
InfoBarEntry(Id _id, const QString &_infoText, GlobalSuppressionMode _globalSuppression = GlobalSuppressionDisabled);
InfoBarEntry(const InfoBarEntry &other) { *this = other; }
void setCustomButtonInfo(const QString &_buttonText, QObject *_object, const char *_member);
void setCancelButtonInfo(QObject *_object, const char *_member);
void setCancelButtonInfo(const QString &_cancelButtonText, QObject *_object, const char *_member);
typedef std::function<void()> CallBack;
void setCustomButtonInfo(const QString &_buttonText, CallBack callBack);
void setCancelButtonInfo(CallBack callBack);
void setCancelButtonInfo(const QString &_cancelButtonText, CallBack callBack);
private:
Id id;
QString infoText;
QString buttonText;
QObject *object;
const char *buttonPressMember;
CallBack m_buttonCallBack;
QString cancelButtonText;
QObject *cancelObject;
const char *cancelButtonPressMember;
CallBack m_cancelButtonCallBack;
GlobalSuppressionMode globalSuppression;
friend class InfoBar;
friend class InfoBarDisplay;
......
......@@ -329,8 +329,12 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const QString &input
.arg(versionControl->displayName()),
InfoBarEntry::GlobalSuppressionEnabled);
d->m_unconfiguredVcs = versionControl;
info.setCustomButtonInfo(Core::ICore::msgShowOptionsDialog(), m_instance,
SLOT(configureVcs()));
info.setCustomButtonInfo(Core::ICore::msgShowOptionsDialog(), []() {
QTC_ASSERT(d->m_unconfiguredVcs, return);
ICore::showOptionsDialog(Id(VcsBase::Constants::VCS_SETTINGS_CATEGORY),
d->m_unconfiguredVcs->id());
});
infoBar->addInfo(info);
}
return 0;
......@@ -477,13 +481,6 @@ void VcsManager::clearVersionControlCache()
emit m_instance->repositoryChanged(repo);
}
void VcsManager::configureVcs()
{
QTC_ASSERT(d->m_unconfiguredVcs, return);
ICore::showOptionsDialog(Id(VcsBase::Constants::VCS_SETTINGS_CATEGORY),
d->m_unconfiguredVcs->id());
}
void VcsManager::handleConfigurationChanges()
{
d->m_cachedAdditionalToolsPathsDirty = true;
......
......@@ -105,7 +105,6 @@ public slots:
static void clearVersionControlCache();
private slots:
static void configureVcs();
void handleConfigurationChanges();
private:
......
......@@ -718,19 +718,15 @@ void QmlLiveTextPreview::showSyncWarning(
Core::InfoBarEntry info(Core::Id(INFO_OUT_OF_SYNC), errorMessage);
BaseToolsClient *toolsClient = m_inspectorAdapter->toolsClient();
if (toolsClient && toolsClient->supportReload())
info.setCustomButtonInfo(tr("Reload QML"), this,
SLOT(reloadQml()));
info.setCustomButtonInfo(tr("Reload QML"), [this]() {
removeOutofSyncInfo();
emit reloadRequest();
});
infoBar->addInfo(info);
}
}
}
void QmlLiveTextPreview::reloadQml()
{
removeOutofSyncInfo();
emit reloadRequest();
}
void QmlLiveTextPreview::removeOutofSyncInfo()
{
foreach (TextEditor::BaseTextEditorWidget *editor, m_editors) {
......
......@@ -69,7 +69,6 @@ signals:
public slots:
void setApplyChangesToQmlInspector(bool applyChanges);
void updateDebugIds();
void reloadQml();
private slots:
void changeSelectedElements(const QList<QmlJS::AST::UiObjectMember *> offsets,
......
......@@ -41,6 +41,7 @@
#include <QCoreApplication>
#include <QDebug>
using namespace Core;
using namespace Designer::Constants;
namespace Designer {
......@@ -62,16 +63,11 @@ Core::IEditor *FormEditorFactory::createEditor()
if (data.formWindowEditor) {
Core::InfoBarEntry info(Core::Id(Constants::INFO_READ_ONLY),
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"), []() { ModeManager::activateMode(Core::Constants::MODE_DESIGN); });
data.formWindowEditor->document()->infoBar()->addInfo(info);
}
return data.formWindowEditor;
}
void FormEditorFactory::designerModeClicked()
{
Core::ModeManager::activateMode(Core::Constants::MODE_DESIGN);
}
} // namespace Internal
} // namespace Designer
......@@ -43,9 +43,6 @@ public:
FormEditorFactory();
Core::IEditor *createEditor();
private slots:
void designerModeClicked();
};
} // namespace Internal
......
......@@ -536,8 +536,12 @@ static void updateEditorInfoBar(BaseTextEditorWidget *widget)
BaseTextEditor::tr("A highlight definition was not found for this file. "
"Would you like to try to find one?"),
InfoBarEntry::GlobalSuppressionEnabled);
info.setCustomButtonInfo(BaseTextEditor::tr("Show Highlighter Options..."),
widget, SLOT(acceptMissingSyntaxDefinitionInfo()));
info.setCustomButtonInfo(BaseTextEditor::tr("Show Highlighter Options..."), [widget]() {
ICore::showOptionsDialog(Constants::TEXT_EDITOR_SETTINGS_CATEGORY,
Constants::TEXT_EDITOR_HIGHLIGHTER_SETTINGS,
widget);
});
infoBar->addInfo(info);
}
}
......@@ -943,7 +947,7 @@ void BaseTextEditorWidgetPrivate::updateCannotDecodeInfo()
InfoBarEntry info(selectEncodingId,
BaseTextEditorWidget::tr("<b>Error:</b> Could not decode \"%1\" with \"%2\"-encoding. Editing not possible.")
.arg(m_document->displayName()).arg(QString::fromLatin1(m_document->codec()->name())));
info.setCustomButtonInfo(BaseTextEditorWidget::tr("Select Encoding"), q, SLOT(selectEncoding()));
info.setCustomButtonInfo(BaseTextEditorWidget::tr("Select Encoding"), [this]() { q->selectEncoding(); });
infoBar->addInfo(info);
} else {
infoBar->removeInfo(selectEncodingId);
......@@ -7139,13 +7143,6 @@ bool BaseTextEditorWidget::isMissingSyntaxDefinition() const
return d->m_isMissingSyntaxDefinition;
}
void BaseTextEditorWidget::acceptMissingSyntaxDefinitionInfo()
{
ICore::showOptionsDialog(Constants::TEXT_EDITOR_SETTINGS_CATEGORY,
Constants::TEXT_EDITOR_HIGHLIGHTER_SETTINGS,
this);
}
// The remnants of PlainTextEditor.
void BaseTextEditorWidget::setupAsPlainEditor()
{
......
......@@ -468,8 +468,6 @@ public:
/// Abort code assistant if it is running.
void abortAssist();
Q_INVOKABLE void acceptMissingSyntaxDefinitionInfo(); // used internally
void configureMimeType(const QString &mimeType);
void configureMimeType(const Core::MimeType &mimeType);
......
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