diff --git a/src/plugins/coreplugin/dialogs/ioptionspage.cpp b/src/plugins/coreplugin/dialogs/ioptionspage.cpp index 175e8289600..2662dfc843c 100644 --- a/src/plugins/coreplugin/dialogs/ioptionspage.cpp +++ b/src/plugins/coreplugin/dialogs/ioptionspage.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -309,4 +310,16 @@ const QList IOptionsPageProvider::allOptionsPagesProvide return g_optionsPagesProviders; } +static QHash g_preselectedOptionPageItems; + +void setPreselectedOptionsPageItem(Id page, Id item) +{ + g_preselectedOptionPageItems.insert(page, item); +} + +Id preselectedOptionsPageItem(Id page) +{ + return g_preselectedOptionPageItems.value(page); +} + } // Core diff --git a/src/plugins/coreplugin/dialogs/ioptionspage.h b/src/plugins/coreplugin/dialogs/ioptionspage.h index e230cab904c..f5dd87229d9 100644 --- a/src/plugins/coreplugin/dialogs/ioptionspage.h +++ b/src/plugins/coreplugin/dialogs/ioptionspage.h @@ -119,4 +119,9 @@ protected: Utils::FilePath m_categoryIconPath; }; +// Which part of the settings page to pre-select, if applicable. In practice, this will +// usually be an item in some sort of (list) view. +void CORE_EXPORT setPreselectedOptionsPageItem(Utils::Id page, Utils::Id item); +Utils::Id CORE_EXPORT preselectedOptionsPageItem(Utils::Id page); + } // namespace Core diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp index 2b213950f7c..7c950382b96 100644 --- a/src/plugins/coreplugin/icore.cpp +++ b/src/plugins/coreplugin/icore.cpp @@ -477,6 +477,24 @@ bool ICore::showOptionsDialog(const Id page, QWidget *parent) return executeSettingsDialog(parent ? parent : dialogParent(), page); } +/*! + Opens the options dialog on the specified \a page. The dialog's \a parent + defaults to dialogParent(). If the dialog is already shown when this method + is called, it is just switched to the specified \a page. + Pre-selects some part of the dialog specified by \a item which the dialog + knows how to interpret. + + Returns whether the user accepted the dialog. + + \sa msgShowOptionsDialog() + \sa msgShowOptionsDialogToolTip() +*/ +bool ICore::showOptionsDialog(const Utils::Id page, Utils::Id item, QWidget *parent) +{ + setPreselectedOptionsPageItem(page, item); + return showOptionsDialog(page, parent); +} + /*! Returns the text to use on buttons that open the options dialog. diff --git a/src/plugins/coreplugin/icore.h b/src/plugins/coreplugin/icore.h index 17c850f20d4..124845b3134 100644 --- a/src/plugins/coreplugin/icore.h +++ b/src/plugins/coreplugin/icore.h @@ -55,6 +55,7 @@ public: const QVariantMap &extraVariables = {}); static bool showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr); + static bool showOptionsDialog(const Utils::Id page, Utils::Id item, QWidget *parent = nullptr); static QString msgShowOptionsDialog(); static QString msgShowOptionsDialogToolTip(); diff --git a/src/plugins/projectexplorer/kitoptionspage.cpp b/src/plugins/projectexplorer/kitoptionspage.cpp index e3c84549ca8..26fba483917 100644 --- a/src/plugins/projectexplorer/kitoptionspage.cpp +++ b/src/plugins/projectexplorer/kitoptionspage.cpp @@ -50,15 +50,6 @@ bool KitSettingsSortModel::lessThan(const QModelIndex &source_left, namespace Internal { -// Page pre-selection - -static Id selectedKitId; - -void setSelectectKitId(const Id &kitId) -{ - selectedKitId = kitId; -} - class KitManagerConfigWidget; class KitNode : public TreeItem @@ -595,7 +586,8 @@ KitOptionsPageWidget::KitOptionsPageWidget() void KitOptionsPageWidget::scrollToSelectedKit() { - QModelIndex index = m_sortModel->mapFromSource(m_model->indexOf(selectedKitId)); + QModelIndex index = m_sortModel->mapFromSource( + m_model->indexOf(Core::preselectedOptionsPageItem(Constants::KITS_SETTINGS_PAGE_ID))); m_selectionModel->select(index, QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent diff --git a/src/plugins/projectexplorer/kitoptionspage.h b/src/plugins/projectexplorer/kitoptionspage.h index 8734024574f..e6058eced19 100644 --- a/src/plugins/projectexplorer/kitoptionspage.h +++ b/src/plugins/projectexplorer/kitoptionspage.h @@ -24,9 +24,4 @@ private: QStringList m_sortedCategories; }; -namespace Internal { - -void setSelectectKitId(const Utils::Id &kitId); - -} // Internal } // ProjectExplorer diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index f745cced786..b9e47c1332e 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -914,7 +914,7 @@ public: while (treeItem) { const Id kitId = Id::fromSetting(treeItem->data(0, KitIdRole)); if (kitId.isValid()) { - setSelectectKitId(kitId); + Core::setPreselectedOptionsPageItem(Constants::KITS_SETTINGS_PAGE_ID, kitId); break; } treeItem = treeItem->parent(); diff --git a/src/plugins/projectexplorer/targetsetupwidget.cpp b/src/plugins/projectexplorer/targetsetupwidget.cpp index 48a380f9bed..3ccf02b38de 100644 --- a/src/plugins/projectexplorer/targetsetupwidget.cpp +++ b/src/plugins/projectexplorer/targetsetupwidget.cpp @@ -182,8 +182,7 @@ void TargetSetupWidget::manageKit() if (!m_kit) return; - setSelectectKitId(m_kit->id()); - Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, parentWidget()); + Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, m_kit->id(), parentWidget()); } void TargetSetupWidget::setProjectPath(const FilePath &projectPath)