forked from qt-creator/qt-creator
Fix availability of "Link with Qt" info bar
The info bar should never appear if the button is disabled, for example because the Qt Creator directory is not accessible. Fixes: QTCREATORBUG-23900 Change-Id: I819c87f5ca51f69f34bd462fca8e877be3544100 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -823,28 +823,41 @@ static QString linkingPurposeText()
|
||||
"Linking with a Qt installation automatically registers Qt versions and kits.");
|
||||
}
|
||||
|
||||
void QtOptionsPageWidget::setupLinkWithQtButton()
|
||||
static bool canLinkWithQt(QString *toolTip)
|
||||
{
|
||||
bool canLink = true;
|
||||
bool installSettingsExist;
|
||||
const Utils::optional<QString> installSettingsValue = currentlyLinkedQtDir(
|
||||
&installSettingsExist);
|
||||
QStringList tip;
|
||||
tip << linkingPurposeText();
|
||||
if (!FilePath::fromString(Core::ICore::resourcePath()).isWritablePath()) {
|
||||
m_ui.linkWithQtButton->setEnabled(false);
|
||||
tip << tr("%1's resource directory is not writable.").arg(Core::Constants::IDE_DISPLAY_NAME);
|
||||
canLink = false;
|
||||
tip << QtOptionsPageWidget::tr("%1's resource directory is not writable.")
|
||||
.arg(Core::Constants::IDE_DISPLAY_NAME);
|
||||
}
|
||||
// guard against redirecting Qt Creator that is part of a Qt installations
|
||||
// TODO this fails for pre-releases in the online installer
|
||||
// TODO this will fail when make Qt Creator non-required in the Qt installers
|
||||
if (installSettingsExist && !installSettingsValue) {
|
||||
m_ui.linkWithQtButton->setEnabled(false);
|
||||
tip << tr("%1 is part of a Qt installation.").arg(Core::Constants::IDE_DISPLAY_NAME);
|
||||
canLink = false;
|
||||
tip << QtOptionsPageWidget::tr("%1 is part of a Qt installation.")
|
||||
.arg(Core::Constants::IDE_DISPLAY_NAME);
|
||||
}
|
||||
const QString link = installSettingsValue ? *installSettingsValue : QString();
|
||||
if (!link.isEmpty())
|
||||
tip << tr("%1 is currently linked to \"%2\".").arg(Core::Constants::IDE_DISPLAY_NAME, link);
|
||||
m_ui.linkWithQtButton->setToolTip(tip.join("\n\n"));
|
||||
tip << QtOptionsPageWidget::tr("%1 is currently linked to \"%2\".")
|
||||
.arg(Core::Constants::IDE_DISPLAY_NAME, link);
|
||||
if (toolTip)
|
||||
*toolTip = tip.join("\n\n");
|
||||
return canLink;
|
||||
}
|
||||
|
||||
void QtOptionsPageWidget::setupLinkWithQtButton()
|
||||
{
|
||||
QString tip;
|
||||
canLinkWithQt(&tip);
|
||||
m_ui.linkWithQtButton->setToolTip(tip);
|
||||
connect(m_ui.linkWithQtButton, &QPushButton::clicked, this, &QtOptionsPage::linkWithQt);
|
||||
}
|
||||
|
||||
@@ -1018,6 +1031,16 @@ QtOptionsPage::QtOptionsPage()
|
||||
setWidgetCreator([] { return new QtOptionsPageWidget; });
|
||||
}
|
||||
|
||||
bool QtOptionsPage::canLinkWithQt()
|
||||
{
|
||||
return Internal::canLinkWithQt(nullptr);
|
||||
}
|
||||
|
||||
bool QtOptionsPage::isLinkedWithQt()
|
||||
{
|
||||
return currentlyLinkedQtDir(nullptr).has_value();
|
||||
}
|
||||
|
||||
void QtOptionsPage::linkWithQt()
|
||||
{
|
||||
QtOptionsPageWidget::linkWithQt();
|
||||
|
@@ -35,6 +35,8 @@ class QtOptionsPage final : public Core::IOptionsPage
|
||||
public:
|
||||
QtOptionsPage();
|
||||
|
||||
static bool canLinkWithQt();
|
||||
static bool isLinkedWithQt();
|
||||
static void linkWithQt();
|
||||
};
|
||||
|
||||
|
@@ -122,7 +122,7 @@ static void askAboutQtInstallation()
|
||||
{
|
||||
// if the install settings exist, the Qt Creator installation is (probably) already linked to
|
||||
// a Qt installation, so don't ask
|
||||
if (QFile::exists(ICore::settings(QSettings::SystemScope)->fileName())
|
||||
if (!QtOptionsPage::canLinkWithQt() || QtOptionsPage::isLinkedWithQt()
|
||||
|| !ICore::infoBar()->canInfoBeAdded(kLinkWithQtInstallationSetting))
|
||||
return;
|
||||
|
||||
|
Reference in New Issue
Block a user