Commit 592ffe73 authored by hjk's avatar hjk

SettingsDialog: Remove CategoryId parameter from callers

PageIds are supposed to be unique, so the CategoryId can be determined
from the PageId. Look for PageIds in the already expanded categories
first before searching through expensive categories.

Change-Id: I006beb0df6183453163ac1810fe59a306a0f52b1
Reviewed-by: default avatarChristian Stenger <christian.stenger@theqtcompany.com>
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 655eed46
......@@ -55,8 +55,7 @@ QString AndroidPotentialKit::displayName() const
void AndroidPotentialKit::executeFromMenu()
{
Core::ICore::showOptionsDialog(Constants::ANDROID_SETTINGS_CATEGORY,
Constants::ANDROID_SETTINGS_ID);
Core::ICore::showOptionsDialog(Constants::ANDROID_SETTINGS_ID);
}
QWidget *AndroidPotentialKit::createWidget(QWidget *parent) const
......@@ -120,9 +119,7 @@ AndroidPotentialKitWidget::AndroidPotentialKitWidget(QWidget *parent)
void AndroidPotentialKitWidget::openOptions()
{
Core::ICore::showOptionsDialog(Constants::ANDROID_SETTINGS_CATEGORY,
Constants::ANDROID_SETTINGS_ID,
this);
Core::ICore::showOptionsDialog(Constants::ANDROID_SETTINGS_ID, this);
}
void AndroidPotentialKitWidget::recheck()
......
......@@ -85,8 +85,7 @@ void GdbServerProviderChooser::setCurrentProviderId(const QString &id)
void GdbServerProviderChooser::manageButtonClicked()
{
Core::ICore::showOptionsDialog(Constants::BAREMETAL_SETTINGS_CATEGORY,
Constants::GDB_PROVIDERS_SETTINGS_ID, this);
Core::ICore::showOptionsDialog(Constants::GDB_PROVIDERS_SETTINGS_ID, this);
}
void GdbServerProviderChooser::currentIndexChanged(int index)
......
......@@ -289,9 +289,7 @@ bool NoKitPage::isComplete() const
void NoKitPage::showOptions()
{
Core::ICore::showOptionsDialog(Core::Id(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY),
Core::Id(ProjectExplorer::Constants::KITS_SETTINGS_PAGE_ID),
this);
Core::ICore::showOptionsDialog(ProjectExplorer::Constants::KITS_SETTINGS_PAGE_ID, this);
}
InSourceBuildPage::InSourceBuildPage(CMakeOpenProjectWizard *cmakeWizard)
......
......@@ -54,7 +54,6 @@
#include <QStyle>
#include <QStyledItemDelegate>
static const char categoryKeyC[] = "General/LastPreferenceCategory";
static const char pageKeyC[] = "General/LastPreferencePage";
const int categoryIconSize = 24;
......@@ -70,6 +69,18 @@ class Category
public:
Category() : index(-1), providerPagesCreated(false) { }
bool findPageById(const Id id, int *pageIndex) const
{
for (int j = 0; j < pages.size(); ++j) {
IOptionsPage *page = pages.at(j);
if (page->id() == id) {
*pageIndex = j;
return true;
}
}
return false;
}
Id id;
int index;
QString displayName;
......@@ -345,43 +356,49 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
m_categoryList->setFocus();
}
void SettingsDialog::showPage(Id categoryId, Id pageId)
void SettingsDialog::showPage(const Id pageId)
{
// handle the case of "show last page"
Id initialCategory = categoryId;
Id initialPage = pageId;
if (!initialCategory.isValid() && !initialPage.isValid()) {
Id initialPageId = pageId;
if (!initialPageId.isValid()) {
QSettings *settings = ICore::settings();
initialCategory = Id::fromSetting(settings->value(QLatin1String(categoryKeyC)));
initialPage = Id::fromSetting(settings->value(QLatin1String(pageKeyC)));
initialPageId = Id::fromSetting(settings->value(QLatin1String(pageKeyC)));
}
if (!initialCategory.isValid()) // no category given and no old setting
return;
int initialCategoryIndex = -1;
int initialPageIndex = -1;
const QList<Category*> &categories = m_model->categories();
for (int i = 0; i < categories.size(); ++i) {
Category *category = categories.at(i);
if (category->id == initialCategory) {
initialCategoryIndex = i;
if (initialPage.isValid()) {
if (initialPageId.isValid()) {
// First try categories without lazy items.
for (int i = 0; i < categories.size(); ++i) {
Category *category = categories.at(i);
if (category->providers.isEmpty()) { // no providers
ensureCategoryWidget(category);
for (int j = 0; j < category->pages.size(); ++j) {
IOptionsPage *page = category->pages.at(j);
if (page->id() == initialPage)
initialPageIndex = j;
if (category->findPageById(initialPageId, &initialPageIndex)) {
initialCategoryIndex = i;
break;
}
}
}
if (initialPageIndex == -1) {
// On failure, expand the remaining items.
for (int i = 0; i < categories.size(); ++i) {
Category *category = categories.at(i);
if (!category->providers.isEmpty()) { // has providers
ensureCategoryWidget(category);
if (category->findPageById(initialPageId, &initialPageIndex)) {
initialCategoryIndex = i;
break;
}
}
}
break;
}
}
QTC_ASSERT(initialCategoryIndex != -1,
qDebug("Unknown category: %s", initialCategory.name().constData()); return);
QTC_ASSERT(!initialPage.isValid() || initialPageIndex != -1,
qDebug("Unknown page: %s", initialPage.name().constData()));
QTC_ASSERT(!initialPageId.isValid() || initialPageIndex != -1,
qDebug("Unknown page: %s", initialPageId.name().constData()));
if (initialCategoryIndex != -1) {
const QModelIndex modelIndex = m_proxyModel->mapFromSource(m_model->index(initialCategoryIndex));
......@@ -588,7 +605,6 @@ void SettingsDialog::apply()
void SettingsDialog::done(int val)
{
QSettings *settings = ICore::settings();
settings->setValue(QLatin1String(categoryKeyC), m_currentCategory.toSetting());
settings->setValue(QLatin1String(pageKeyC), m_currentPage.toSetting());
ICore::saveSettings(); // save all settings
......@@ -612,12 +628,11 @@ QSize SettingsDialog::sizeHint() const
return minimumSize();
}
SettingsDialog *SettingsDialog::getSettingsDialog(QWidget *parent,
Id initialCategory, Id initialPage)
SettingsDialog *SettingsDialog::getSettingsDialog(QWidget *parent, Id initialPage)
{
if (!m_instance)
m_instance = new SettingsDialog(parent);
m_instance->showPage(initialCategory, initialPage);
m_instance->showPage(initialPage);
return m_instance;
}
......
......@@ -62,8 +62,7 @@ public:
// Returns a settings dialog. This makes sure that always only
// a single settings dialog instance is running.
// The dialog will be deleted automatically on close.
static SettingsDialog *getSettingsDialog(QWidget *parent,
Id initialCategory, Id initialPage);
static SettingsDialog *getSettingsDialog(QWidget *parent, Id initialPage);
// Run the dialog and wait for it to finish.
// Returns if the changes have been applied.
bool execDialog();
......@@ -86,7 +85,7 @@ private:
void createGui();
void showCategory(int index);
void showPage(Id categoryId, Id pageId);
void showPage(Id pageId);
void updateEnabledTabs(Category *category, const QString &searchText);
void ensureCategoryWidget(Category *category);
void disconnectTabWidgets();
......
......@@ -81,7 +81,7 @@ ExternalToolManager::ExternalToolManager()
d->m_configureSeparator->setSeparator(true);
d->m_configureAction = new QAction(ICore::msgShowOptionsDialog(), this);
connect(d->m_configureAction, &QAction::triggered, [this] {
ICore::showOptionsDialog(Constants::SETTINGS_CATEGORY_CORE, Constants::SETTINGS_ID_TOOLS);
ICore::showOptionsDialog(Constants::SETTINGS_ID_TOOLS);
});
// add the external tools menu
......
......@@ -66,11 +66,8 @@ static void showGraphicalShellError(QWidget *parent, const QString &app, const Q
QAbstractButton *settingsButton = mbox.addButton(Core::ICore::msgShowOptionsDialog(),
QMessageBox::ActionRole);
mbox.exec();
if (mbox.clickedButton() == settingsButton) {
ICore::showOptionsDialog(Constants::SETTINGS_CATEGORY_CORE,
Constants::SETTINGS_ID_ENVIRONMENT,
parent);
}
if (mbox.clickedButton() == settingsButton)
ICore::showOptionsDialog(Constants::SETTINGS_ID_ENVIRONMENT, parent);
}
void FileUtils::showInGraphicalShell(QWidget *parent, const QString &pathIn)
......
......@@ -337,9 +337,9 @@ void ICore::showNewItemDialog(const QString &title,
m_mainwindow->showNewItemDialog(title, factories, defaultLocation, extraVariables);
}
bool ICore::showOptionsDialog(const Id group, const Id page, QWidget *parent)
bool ICore::showOptionsDialog(const Id page, QWidget *parent)
{
return m_mainwindow->showOptionsDialog(group, page, parent);
return m_mainwindow->showOptionsDialog(page, parent);
}
QString ICore::msgShowOptionsDialog()
......@@ -358,14 +358,9 @@ QString ICore::msgShowOptionsDialogToolTip()
}
bool ICore::showWarningWithOptions(const QString &title, const QString &text,
const QString &details,
Id settingsCategory,
Id settingsId,
QWidget *parent)
{
return m_mainwindow->showWarningWithOptions(title, text,
details, settingsCategory,
settingsId, parent);
const QString &details, Id settingsId, QWidget *parent)
{
return m_mainwindow->showWarningWithOptions(title, text, details, settingsId, parent);
}
QSettings *ICore::settings(QSettings::Scope scope)
......
......@@ -74,13 +74,12 @@ public:
const QString &defaultLocation = QString(),
const QVariantMap &extraVariables = QVariantMap());
static bool showOptionsDialog(Id group, Id page, QWidget *parent = 0);
static bool showOptionsDialog(Id page, QWidget *parent = 0);
static QString msgShowOptionsDialog();
static QString msgShowOptionsDialogToolTip();
static bool showWarningWithOptions(const QString &title, const QString &text,
const QString &details = QString(),
Id settingsCategory = Id(),
Id settingsId = Id(),
QWidget *parent = 0);
......
......@@ -625,7 +625,7 @@ void LocatorWidget::filterSelected()
void LocatorWidget::showConfigureDialog()
{
ICore::showOptionsDialog(Constants::SETTINGS_CATEGORY_CORE, Constants::FILTER_OPTIONS_PAGE);
ICore::showOptionsDialog(Constants::FILTER_OPTIONS_PAGE);
}
void LocatorWidget::addSearchResults(int firstIndex, int endIndex)
......
......@@ -823,12 +823,12 @@ void MainWindow::showNewItemDialog(const QString &title,
emit newItemDialogRunningChanged();
}
bool MainWindow::showOptionsDialog(Id category, Id page, QWidget *parent)
bool MainWindow::showOptionsDialog(Id page, QWidget *parent)
{
emit m_coreImpl->optionsDialogRequested();
if (!parent)
parent = ICore::dialogParent();
SettingsDialog *dialog = SettingsDialog::getSettingsDialog(parent, category, page);
SettingsDialog *dialog = SettingsDialog::getSettingsDialog(parent, page);
return dialog->execDialog();
}
......@@ -1092,7 +1092,6 @@ QPrinter *MainWindow::printer() const
bool MainWindow::showWarningWithOptions(const QString &title,
const QString &text,
const QString &details,
Id settingsCategory,
Id settingsId,
QWidget *parent)
{
......@@ -1103,11 +1102,11 @@ bool MainWindow::showWarningWithOptions(const QString &title,
if (!details.isEmpty())
msgBox.setDetailedText(details);
QAbstractButton *settingsButton = 0;
if (settingsId.isValid() || settingsCategory.isValid())
if (settingsId.isValid())
settingsButton = msgBox.addButton(tr("Settings..."), QMessageBox::AcceptRole);
msgBox.exec();
if (settingsButton && msgBox.clickedButton() == settingsButton)
return showOptionsDialog(settingsCategory, settingsId);
return showOptionsDialog(settingsId);
return false;
}
......
......@@ -122,11 +122,10 @@ public slots:
const QString &defaultLocation = QString(),
const QVariantMap &extraVariables = QVariantMap());
bool showOptionsDialog(Id category = Id(), Id page = Id(), QWidget *parent = 0);
bool showOptionsDialog(Id page = Id(), QWidget *parent = 0);
bool showWarningWithOptions(const QString &title, const QString &text,
const QString &details = QString(),
Id settingsCategory = Id(),
Id settingsId = Id(),
QWidget *parent = 0);
......
......@@ -344,8 +344,7 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const QString &input
d->m_unconfiguredVcs = versionControl;
info.setCustomButtonInfo(ICore::msgShowOptionsDialog(), []() {
QTC_ASSERT(d->m_unconfiguredVcs, return);
ICore::showOptionsDialog(Id(VcsBase::Constants::VCS_SETTINGS_CATEGORY),
d->m_unconfiguredVcs->id());
ICore::showOptionsDialog(d->m_unconfiguredVcs->id());
});
infoBar->addInfo(info);
......
......@@ -170,11 +170,8 @@ bool Protocol::showConfigurationError(const Protocol *p,
settingsButton = mb.addButton(Core::ICore::msgShowOptionsDialog(), QMessageBox::AcceptRole);
mb.exec();
bool rc = false;
if (mb.clickedButton() == settingsButton) {
rc = Core::ICore::showOptionsDialog(p->settingsPage()->category(),
p->settingsPage()->id(),
parent);
}
if (mb.clickedButton() == settingsButton)
rc = Core::ICore::showOptionsDialog(p->settingsPage()->id(), parent);
return rc;
}
......
......@@ -127,8 +127,7 @@ QWidget *DebuggerKitConfigWidget::mainWidget() const
void DebuggerKitConfigWidget::manageDebuggers()
{
Core::ICore::showOptionsDialog(ProjectExplorer::Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
ProjectExplorer::Constants::DEBUGGER_SETTINGS_PAGE_ID,
Core::ICore::showOptionsDialog(ProjectExplorer::Constants::DEBUGGER_SETTINGS_PAGE_ID,
buttonWidget());
}
......
......@@ -706,7 +706,6 @@ public:
const QString &tracePointMessage = QString());
void onModeChanged(IMode *mode);
void onCoreAboutToOpen();
void showSettingsDialog();
void updateDebugWithoutDeployMenu();
void startAndDebugApplication();
......@@ -2161,11 +2160,6 @@ void DebuggerPluginPrivate::onModeChanged(IMode *mode)
m_toolTipManager.debugModeEntered();
}
void DebuggerPluginPrivate::showSettingsDialog()
{
ICore::showOptionsDialog(DEBUGGER_SETTINGS_CATEGORY, DEBUGGER_COMMON_SETTINGS_ID);
}
void DebuggerPluginPrivate::updateDebugWithoutDeployMenu()
{
const bool state = ProjectExplorerPlugin::projectExplorerSettings().deployBeforeRun;
......@@ -2990,7 +2984,7 @@ void DebuggerPluginPrivate::extensionsInitialized()
// Application interaction
connect(action(SettingsDialog), &QAction::triggered,
this, &DebuggerPluginPrivate::showSettingsDialog);
[] { ICore::showOptionsDialog(DEBUGGER_COMMON_SETTINGS_ID); });
// QML Actions
connect(action(ShowQmlObjectTree), &SavedAction::valueChanged,
......
......@@ -4426,8 +4426,7 @@ void GdbEngine::handleAdapterStartFailed(const QString &msg, Id settingsIdHint)
if (!settingsIdHint.isValid()) {
ICore::showWarningWithOptions(title, msg);
} else {
ICore::showWarningWithOptions(title, msg, QString(),
Constants::DEBUGGER_SETTINGS_CATEGORY, settingsIdHint);
ICore::showWarningWithOptions(title, msg, QString(), settingsIdHint);
}
}
notifyEngineSetupFailed();
......
......@@ -1016,7 +1016,6 @@ private slots:
void fold(int depth, bool fold);
void foldGoTo(int count, bool current);
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName);
void showSettingsDialog();
void maybeReadVimRc();
void disableBlockSelection();
void setBlockSelection(const QTextCursor&);
......@@ -1382,11 +1381,6 @@ void FakeVimPluginPrivate::maybeReadVimRc()
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
}
void FakeVimPluginPrivate::showSettingsDialog()
{
ICore::showOptionsDialog(SETTINGS_CATEGORY, SETTINGS_ID);
}
void FakeVimPluginPrivate::triggerAction(Id id)
{
Command *cmd = ActionManager::command(id);
......@@ -2007,7 +2001,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
} else if (cmd.matches(_("se"), _("set"))) {
if (cmd.args.isEmpty()) {
// :se[t]
showSettingsDialog();
ICore::showOptionsDialog(SETTINGS_ID);
} else if (cmd.args == _("ic") || cmd.args == _("ignorecase")) {
// :set nc
setActionChecked(Core::Constants::CASE_SENSITIVE, false);
......
......@@ -374,8 +374,7 @@ void GerritPlugin::openView()
while (!m_parameters->isValid()) {
Core::AsynchronousMessageBox::warning(tr("Error"),
tr("Invalid Gerrit configuration. Host, user and ssh binary are mandatory."));
const Id group = VcsBase::Constants::VCS_SETTINGS_CATEGORY;
if (!ICore::showOptionsDialog(group, "Gerrit"))
if (!ICore::showOptionsDialog("Gerrit"))
return;
}
GerritDialog *gd = new GerritDialog(m_parameters, ICore::mainWindow());
......
......@@ -42,9 +42,8 @@
using namespace ProjectExplorer;
using namespace ProjectExplorer::Internal;
ConfigTaskHandler::ConfigTaskHandler(const Task &pattern, Core::Id group, Core::Id page) :
ConfigTaskHandler::ConfigTaskHandler(const Task &pattern, Core::Id page) :
m_pattern(pattern),
m_targetGroup(group),
m_targetPage(page)
{ }
......@@ -57,7 +56,7 @@ bool ConfigTaskHandler::canHandle(const Task &task) const
void ConfigTaskHandler::handle(const Task &task)
{
Q_UNUSED(task);
Core::ICore::showOptionsDialog(m_targetGroup, m_targetPage);
Core::ICore::showOptionsDialog(m_targetPage);
}
QAction *ConfigTaskHandler::createAction(QObject *parent) const
......
......@@ -43,7 +43,7 @@ class ConfigTaskHandler : public ITaskHandler
Q_OBJECT
public:
ConfigTaskHandler(const Task &pattern, Core::Id group, Core::Id page);
ConfigTaskHandler(const Task &pattern, Core::Id page);
bool canHandle(const Task &task) const;
void handle(const Task &task);
......@@ -51,8 +51,6 @@ public:
private:
const Task m_pattern;
const Core::Id m_targetGroup;
const Core::Id m_targetPage;
};
......
......@@ -67,8 +67,7 @@ KitChooser::KitChooser(QWidget *parent) :
void KitChooser::onManageButtonClicked()
{
Core::ICore::showOptionsDialog(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
Constants::KITS_SETTINGS_PAGE_ID, this);
Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, this);
}
void KitChooser::onCurrentIndexChanged(int index)
......
......@@ -215,9 +215,7 @@ void ToolChainInformationConfigWidget::toolChainUpdated(ToolChain *tc)
void ToolChainInformationConfigWidget::manageToolChains()
{
ICore::showOptionsDialog(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
Constants::TOOLCHAIN_SETTINGS_PAGE_ID,
buttonWidget());
ICore::showOptionsDialog(Constants::TOOLCHAIN_SETTINGS_PAGE_ID, buttonWidget());
}
void ToolChainInformationConfigWidget::currentToolChainChanged(int idx)
......@@ -379,9 +377,7 @@ QWidget *DeviceInformationConfigWidget::buttonWidget() const
void DeviceInformationConfigWidget::manageDevices()
{
ICore::showOptionsDialog(Constants::DEVICE_SETTINGS_CATEGORY,
Constants::DEVICE_SETTINGS_PAGE_ID,
buttonWidget());
ICore::showOptionsDialog(Constants::DEVICE_SETTINGS_PAGE_ID, buttonWidget());
}
void DeviceInformationConfigWidget::modelAboutToReset()
......
......@@ -473,7 +473,6 @@ bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *er
addAutoReleasedObject(new VcsAnnotateTaskHandler);
addAutoReleasedObject(new RemoveTaskHandler);
addAutoReleasedObject(new ConfigTaskHandler(Task::compilerMissingTask(),
Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
Constants::KITS_SETTINGS_PAGE_ID));
addAutoReleasedObject(new CoreListener);
......
......@@ -584,9 +584,7 @@ void ProjectWizardPage::projectChanged(int index)
void ProjectWizardPage::manageVcs()
{
ICore::showOptionsDialog(VcsBase::Constants::VCS_SETTINGS_CATEGORY,
VcsBase::Constants::VCS_COMMON_SETTINGS_ID,
this);
ICore::showOptionsDialog(VcsBase::Constants::VCS_COMMON_SETTINGS_ID, this);
}
} // namespace Internal
......
......@@ -644,9 +644,7 @@ void TargetSettingsPanelWidget::openTargetPreferences()
if (KitOptionsPage *page = ExtensionSystem::PluginManager::getObject<KitOptionsPage>())
page->showKit(m_targets.at(targetIndex)->kit());
}
ICore::showOptionsDialog(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
Constants::KITS_SETTINGS_PAGE_ID,
this);
ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, this);
}
void TargetSettingsPanelWidget::importTarget()
......
......@@ -428,9 +428,7 @@ void TargetSetupPage::updateVisibility()
void TargetSetupPage::openOptions()
{
Core::ICore::instance()->showOptionsDialog(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
Constants::KITS_SETTINGS_PAGE_ID,
this);
Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, this);
}
void TargetSetupPage::import(const Utils::FileName &path)
......
......@@ -230,9 +230,7 @@ void TargetSetupWidget::manageKit()
return;
page->showKit(m_kit);
Core::ICore::showOptionsDialog(Constants::PROJECTEXPLORER_SETTINGS_CATEGORY,
Constants::KITS_SETTINGS_PAGE_ID,
this->parentWidget());
Core::ICore::showOptionsDialog(Constants::KITS_SETTINGS_PAGE_ID, parentWidget());
}
void TargetSetupWidget::setProjectPath(const QString &projectPath)
......
......@@ -80,9 +80,7 @@ bool BlackBerryPotentialKit::shouldShow()
void BlackBerryPotentialKit::openSettings(QWidget *parent)
{
Core::ICore::showOptionsDialog(Qnx::Constants::QNX_BB_CATEGORY,
Qnx::Constants::QNX_BB_SETUP_ID,
parent);
Core::ICore::showOptionsDialog(Qnx::Constants::QNX_BB_SETUP_ID, parent);
}
BlackBerryPotentialKitWidget::BlackBerryPotentialKitWidget(QWidget *parent)
......
......@@ -139,9 +139,7 @@ void QtKitConfigWidget::versionsChanged(const QList<int> &added, const QList<int
void QtKitConfigWidget::manageQtVersions()
{