From 2fad22c0306974ce1b4a21e9fbc3c5e8840aeff1 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 8 Jun 2011 10:45:26 +0200 Subject: [PATCH] Add restore fallback functionality, make better tr() Task-number: QTCREATORBUG-5025 Change-Id: Ia3f6fa2380dd1a93f120873f584662a267ca4d50 Reviewed-on: http://codereview.qt.nokia.com/360 Reviewed-by: Qt Sanity Bot Reviewed-by: Christian Kamm --- .../cpptools/cppcodestylesettingspage.cpp | 5 +- .../cpptools/cppcodestylesettingspage.ui | 2 +- src/plugins/cpptools/cpptoolssettings.cpp | 4 +- .../projectexplorer/editorconfiguration.cpp | 4 +- .../projectexplorer/editorconfiguration.h | 2 +- .../editorsettingspropertiespage.cpp | 19 ++-- .../editorsettingspropertiespage.h | 2 +- .../editorsettingspropertiespage.ui | 48 ++++++---- src/plugins/qmljstools/qmljstoolssettings.cpp | 2 +- .../texteditor/behaviorsettingspage.cpp | 2 +- .../texteditor/fallbackselectorwidget.cpp | 94 +++++++++++-------- .../texteditor/fallbackselectorwidget.h | 10 +- .../texteditor/tabpreferenceswidget.cpp | 1 + 13 files changed, 114 insertions(+), 81 deletions(-) diff --git a/src/plugins/cpptools/cppcodestylesettingspage.cpp b/src/plugins/cpptools/cppcodestylesettingspage.cpp index 09e365251e3..80875451c9c 100644 --- a/src/plugins/cpptools/cppcodestylesettingspage.cpp +++ b/src/plugins/cpptools/cppcodestylesettingspage.cpp @@ -234,6 +234,7 @@ CppCodeStylePreferencesWidget::CppCodeStylePreferencesWidget(QWidget *parent) m_ui->categoryTab->setCurrentIndex(0); m_ui->tabPreferencesWidget->setFlat(true); + m_ui->fallbackWidget->setLabelText(tr("Code style settings:")); } CppCodeStylePreferencesWidget::~CppCodeStylePreferencesWidget() @@ -321,15 +322,11 @@ void CppCodeStylePreferencesWidget::setCppCodeStyleSettings(const CppCodeStyleSe void CppCodeStylePreferencesWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback) { - m_ui->tabPreferencesWidget->setEnabled(!fallback); m_ui->contentGroupBox->setEnabled(!fallback); m_ui->bracesGroupBox->setEnabled(!fallback); m_ui->switchGroupBox->setEnabled(!fallback); m_ui->alignmentGroupBox->setEnabled(!fallback); - // if C++ global is used for style, use it for tab settings as well - if (fallback && m_tabPreferences && m_cppCodeStylePreferences->currentFallback()) - m_tabPreferences->setCurrentFallback(m_cppCodeStylePreferences->currentFallback()->id()); updatePreview(); } diff --git a/src/plugins/cpptools/cppcodestylesettingspage.ui b/src/plugins/cpptools/cppcodestylesettingspage.ui index 8909fced93f..e3d4623a80a 100644 --- a/src/plugins/cpptools/cppcodestylesettingspage.ui +++ b/src/plugins/cpptools/cppcodestylesettingspage.ui @@ -17,7 +17,7 @@ - + 0 diff --git a/src/plugins/cpptools/cpptoolssettings.cpp b/src/plugins/cpptools/cpptoolssettings.cpp index 439c15e5380..1efc828b8da 100644 --- a/src/plugins/cpptools/cpptoolssettings.cpp +++ b/src/plugins/cpptools/cpptoolssettings.cpp @@ -42,14 +42,14 @@ CppToolsSettings::CppToolsSettings(QObject *parent) << textEditorSettings->tabPreferences(), this); m_d->m_tabPreferences->setCurrentFallback(textEditorSettings->tabPreferences()); m_d->m_tabPreferences->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s); - m_d->m_tabPreferences->setDisplayName(tr("global C++")); + m_d->m_tabPreferences->setDisplayName(tr("Global C++", "Settings")); m_d->m_tabPreferences->setId(idKey); textEditorSettings->registerLanguageTabPreferences(CppTools::Constants::CPP_SETTINGS_ID, m_d->m_tabPreferences); m_d->m_cppCodeStylePreferences = new CppCodeStylePreferences(QList(), this); m_d->m_cppCodeStylePreferences->fromSettings(CppTools::Constants::CPP_SETTINGS_ID, s); - m_d->m_cppCodeStylePreferences->setDisplayName(tr("global C++")); + m_d->m_cppCodeStylePreferences->setDisplayName(tr("Global C++", "Settings")); m_d->m_cppCodeStylePreferences->setId(idKey); textEditorSettings->registerLanguageCodeStylePreferences(CppTools::Constants::CPP_SETTINGS_ID, m_d->m_cppCodeStylePreferences); } diff --git a/src/plugins/projectexplorer/editorconfiguration.cpp b/src/plugins/projectexplorer/editorconfiguration.cpp index a2881e51cb5..544b67c0f22 100644 --- a/src/plugins/projectexplorer/editorconfiguration.cpp +++ b/src/plugins/projectexplorer/editorconfiguration.cpp @@ -94,7 +94,7 @@ EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate) QList fallbacks; fallbacks << TextEditorSettings::instance()->tabPreferences(); m_d->m_tabPreferences = new TabPreferences(fallbacks, this); - m_d->m_tabPreferences->setDisplayName(tr("project text editor")); + m_d->m_tabPreferences->setDisplayName(tr("Project", "Settings")); m_d->m_tabPreferences->setId(kId); CodeStylePreferencesManager *manager = @@ -127,7 +127,7 @@ EditorConfiguration::EditorConfiguration() : m_d(new EditorConfigurationPrivate) IFallbackPreferences *preferences = factory->createPreferences( QList() << originalPreferences); preferences->setId(languageId + QLatin1String("Project")); - preferences->setDisplayName(tr("project %1").arg(factory->displayName())); + preferences->setDisplayName(tr("Project %1", "Settings, %1 is a language (C++ or QML)").arg(factory->displayName())); preferences->setCurrentFallback(originalPreferences); m_d->m_languageCodeStylePreferences.insert(languageId, preferences); } diff --git a/src/plugins/projectexplorer/editorconfiguration.h b/src/plugins/projectexplorer/editorconfiguration.h index 11e61309575..04b0041a0b4 100644 --- a/src/plugins/projectexplorer/editorconfiguration.h +++ b/src/plugins/projectexplorer/editorconfiguration.h @@ -62,6 +62,7 @@ public: EditorConfiguration(); ~EditorConfiguration(); + void setUseGlobalSettings(bool use); bool useGlobalSettings() const; void cloneGlobalSettings(); @@ -89,7 +90,6 @@ signals: void extraEncodingSettingsChanged(const TextEditor::ExtraEncodingSettings &); private slots: - void setUseGlobalSettings(bool use); void setStorageSettings(const TextEditor::StorageSettings &settings); void setBehaviorSettings(const TextEditor::BehaviorSettings &settings); diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp index ab685897f39..5753ee1ac12 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.cpp +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.cpp @@ -72,12 +72,10 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj const EditorConfiguration *config = m_project->editorConfiguration(); settingsToUi(config); - setGlobalSettingsEnabled(config->useGlobalSettings()); + globalSettingsActivated(config->useGlobalSettings() ? 0 : 1); - connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)), - this, SLOT(setGlobalSettingsEnabled(bool))); - connect(m_ui.useGlobalCheckBox, SIGNAL(clicked(bool)), - config, SLOT(setUseGlobalSettings(bool))); + connect(m_ui.globalSelector, SIGNAL(activated(int)), + this, SLOT(globalSettingsActivated(int))); connect(m_ui.restoreButton, SIGNAL(clicked()), this, SLOT(restoreDefaultValues())); connect(m_ui.behaviorSettingsWidget, SIGNAL(storageSettingsChanged(TextEditor::StorageSettings)), config, SLOT(setStorageSettings(TextEditor::StorageSettings))); @@ -94,17 +92,20 @@ EditorSettingsWidget::EditorSettingsWidget(Project *project) : QWidget(), m_proj void EditorSettingsWidget::settingsToUi(const EditorConfiguration *config) { m_ui.behaviorSettingsWidget->setTabPreferences(config->tabPreferences()); - m_ui.useGlobalCheckBox->setChecked(config->useGlobalSettings()); + m_ui.globalSelector->setCurrentIndex(config->useGlobalSettings() ? 0 : 1); m_ui.behaviorSettingsWidget->setAssignedCodec(config->textCodec()); m_ui.behaviorSettingsWidget->setAssignedStorageSettings(config->storageSettings()); m_ui.behaviorSettingsWidget->setAssignedBehaviorSettings(config->behaviorSettings()); m_ui.behaviorSettingsWidget->setAssignedExtraEncodingSettings(config->extraEncodingSettings()); } -void EditorSettingsWidget::setGlobalSettingsEnabled(bool enabled) +void EditorSettingsWidget::globalSettingsActivated(int index) { - m_ui.behaviorSettingsWidget->setActive(!enabled); - m_ui.restoreButton->setEnabled(!enabled); + const bool useGlobal = !index; + m_ui.behaviorSettingsWidget->setActive(!useGlobal); + m_ui.restoreButton->setEnabled(!useGlobal); + EditorConfiguration *config = m_project->editorConfiguration(); + config->setUseGlobalSettings(useGlobal); } void EditorSettingsWidget::restoreDefaultValues() diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.h b/src/plugins/projectexplorer/editorsettingspropertiespage.h index 462654877c3..3dbf192c531 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.h +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.h @@ -60,7 +60,7 @@ public: EditorSettingsWidget(Project *project); private slots: - void setGlobalSettingsEnabled(bool enabled); + void globalSettingsActivated(int index); void restoreDefaultValues(); private: diff --git a/src/plugins/projectexplorer/editorsettingspropertiespage.ui b/src/plugins/projectexplorer/editorsettingspropertiespage.ui index ce010787849..15d4fe5f34b 100644 --- a/src/plugins/projectexplorer/editorsettingspropertiespage.ui +++ b/src/plugins/projectexplorer/editorsettingspropertiespage.ui @@ -6,35 +6,56 @@ 0 0 - 368 - 98 + 401 + 111 - - + + - Use global settings + Editor settings: - - + + + + + Global + + + + + Custom + + + - + + + + Restore Global + + + + Qt::Horizontal - 224 + 3 20 - + + + + Qt::Vertical @@ -47,13 +68,6 @@ - - - - Restore Global Values - - - diff --git a/src/plugins/qmljstools/qmljstoolssettings.cpp b/src/plugins/qmljstools/qmljstoolssettings.cpp index 503f8f03f5c..758db722911 100644 --- a/src/plugins/qmljstools/qmljstoolssettings.cpp +++ b/src/plugins/qmljstools/qmljstoolssettings.cpp @@ -40,7 +40,7 @@ QmlJSToolsSettings::QmlJSToolsSettings(QObject *parent) << textEditorSettings->tabPreferences(), this); m_d->m_tabPreferences->setCurrentFallback(textEditorSettings->tabPreferences()); m_d->m_tabPreferences->fromSettings(QmlJSTools::Constants::QML_JS_SETTINGS_ID, s); - m_d->m_tabPreferences->setDisplayName(tr("global QML")); + m_d->m_tabPreferences->setDisplayName(tr("Global Qt Quick", "Settings")); m_d->m_tabPreferences->setId(idKey); textEditorSettings->registerLanguageTabPreferences(QmlJSTools::Constants::QML_JS_SETTINGS_ID, m_d->m_tabPreferences); } diff --git a/src/plugins/texteditor/behaviorsettingspage.cpp b/src/plugins/texteditor/behaviorsettingspage.cpp index 7b240f1028b..2c29ac31802 100644 --- a/src/plugins/texteditor/behaviorsettingspage.cpp +++ b/src/plugins/texteditor/behaviorsettingspage.cpp @@ -92,7 +92,7 @@ BehaviorSettingsPage::BehaviorSettingsPage(const BehaviorSettingsPageParameters m_d(new BehaviorSettingsPagePrivate(p)) { m_d->m_tabPreferences = new TabPreferences(QList(), this); - m_d->m_tabPreferences->setDisplayName(tr("global text editor")); + m_d->m_tabPreferences->setDisplayName(tr("Global", "Settings")); m_d->m_tabPreferences->setId(idKey); m_d->init(); } diff --git a/src/plugins/texteditor/fallbackselectorwidget.cpp b/src/plugins/texteditor/fallbackselectorwidget.cpp index a690c2caeb8..af931fe1371 100644 --- a/src/plugins/texteditor/fallbackselectorwidget.cpp +++ b/src/plugins/texteditor/fallbackselectorwidget.cpp @@ -5,7 +5,10 @@ #include #include #include +#include +#include #include +#include using namespace TextEditor; @@ -15,10 +18,11 @@ FallbackSelectorWidget::FallbackSelectorWidget(QWidget *parent) : QWidget(parent), m_fallbackPreferences(0), m_layout(0), - m_checkBox(0), m_comboBox(0), m_comboBoxLabel(0), - m_fallbackWidgetVisible(true) + m_restoreButton(0), + m_fallbackWidgetVisible(true), + m_labelText(tr("Settings:")) { hide(); } @@ -45,36 +49,47 @@ void FallbackSelectorWidget::setFallbackPreferences(TextEditor::IFallbackPrefere m_layout = new QHBoxLayout(this); m_layout->setContentsMargins(QMargins()); + m_restoreButton = new QToolButton(this); + QSignalMapper *mapper = new QSignalMapper(this); + m_comboBoxLabel = new QLabel(m_labelText, this); + m_comboBoxLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + m_layout->addWidget(m_comboBoxLabel); + m_comboBox = new QComboBox(this); + m_layout->addWidget(m_comboBox); + m_comboBox->addItem(tr("Custom"), QVariant::fromValue(0)); + connect(m_comboBox, SIGNAL(activated(int)), + this, SLOT(slotComboBoxActivated(int))); + + QMenu *menu = new QMenu(this); if (fallbacks.count() == 1) { - m_checkBox = new QCheckBox(this); - m_layout->addWidget(m_checkBox); - m_layout->addStretch(); - m_checkBox->setText(tr("Use %1 settings").arg(fallbacks.at(0)->displayName())); - connect(m_checkBox, SIGNAL(clicked(bool)), - this, SLOT(slotCheckBoxClicked(bool))); + IFallbackPreferences *fallback = fallbacks.first(); + m_restoreButton->setText(tr("Restore %1", "%1 is settings name (e.g. Global C++)").arg(fallback->displayName())); + connect(m_restoreButton, SIGNAL(clicked()), mapper, SLOT(map())); + mapper->setMapping(m_restoreButton, fallback); } else { - m_comboBoxLabel = new QLabel(tr("Settings:"), this); - m_layout->addWidget(m_comboBoxLabel); - m_comboBox = new QComboBox(this); - m_layout->addWidget(m_comboBox); - m_layout->setStretch(1, 1); - m_comboBox->addItem(tr("Custom"), QVariant::fromValue(0)); - connect(m_comboBox, SIGNAL(activated(int)), - this, SLOT(slotComboBoxActivated(int))); - - for (int i = 0; i < fallbacks.count(); i++) { - IFallbackPreferences *fallback = fallbacks.at(i); - QString displayName = fallback->displayName(); - if (!displayName.isEmpty()) - displayName[0] = displayName[0].toUpper(); - m_comboBox->insertItem(i, displayName, QVariant::fromValue(fallback)); - } + m_restoreButton->setText(tr("Restore")); + m_restoreButton->setPopupMode(QToolButton::InstantPopup); + m_restoreButton->setMenu(menu); } + + for (int i = 0; i < fallbacks.count(); i++) { + IFallbackPreferences *fallback = fallbacks.at(i); + const QString displayName = fallback->displayName(); + const QVariant data = QVariant::fromValue(fallback); + m_comboBox->insertItem(i, displayName, data); + QAction *restoreAction = new QAction(displayName, this); + menu->addAction(restoreAction); + connect(restoreAction, SIGNAL(triggered()), mapper, SLOT(map())); + mapper->setMapping(restoreAction, fallback); + } + m_layout->addWidget(m_restoreButton); + slotCurrentFallbackChanged(m_fallbackPreferences->currentFallback()); connect(m_fallbackPreferences, SIGNAL(currentFallbackChanged(TextEditor::IFallbackPreferences*)), this, SLOT(slotCurrentFallbackChanged(TextEditor::IFallbackPreferences*))); + connect(mapper, SIGNAL(mapped(QObject*)), this, SLOT(slotRestoreValues(QObject*))); } } @@ -90,27 +105,25 @@ void FallbackSelectorWidget::slotComboBoxActivated(int index) blockSignals(wasBlocked); } -void FallbackSelectorWidget::slotCheckBoxClicked(bool checked) -{ - TextEditor::IFallbackPreferences *fallback = 0; - if (checked && !m_fallbackPreferences->fallbacks().isEmpty()) - fallback = m_fallbackPreferences->fallbacks().first(); - - const bool wasBlocked = blockSignals(true); - m_fallbackPreferences->setCurrentFallback(fallback); - blockSignals(wasBlocked); -} - void FallbackSelectorWidget::slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *fallback) { const bool wasBlocked = blockSignals(true); if (m_comboBox) m_comboBox->setCurrentIndex(m_comboBox->findData(QVariant::fromValue(fallback))); - if (m_checkBox) - m_checkBox->setChecked(fallback); + if (m_restoreButton) + m_restoreButton->setEnabled(!fallback); blockSignals(wasBlocked); } +void FallbackSelectorWidget::slotRestoreValues(QObject *fallbackObject) +{ + TextEditor::IFallbackPreferences *fallback + = qobject_cast(fallbackObject); + if (!fallback) + return; + m_fallbackPreferences->setValue(fallback->currentValue()); +} + void FallbackSelectorWidget::setFallbacksVisible(bool on) { m_fallbackWidgetVisible = on; @@ -118,6 +131,13 @@ void FallbackSelectorWidget::setFallbacksVisible(bool on) setVisible(m_fallbackWidgetVisible && !m_fallbackPreferences->fallbacks().isEmpty()); } +void FallbackSelectorWidget::setLabelText(const QString &text) +{ + m_labelText = text; + if (m_comboBoxLabel) + m_comboBoxLabel->setText(text); +} + QString FallbackSelectorWidget::searchKeywords() const { // no useful keywords here diff --git a/src/plugins/texteditor/fallbackselectorwidget.h b/src/plugins/texteditor/fallbackselectorwidget.h index 60cea0d89b8..21e141976a1 100644 --- a/src/plugins/texteditor/fallbackselectorwidget.h +++ b/src/plugins/texteditor/fallbackselectorwidget.h @@ -11,6 +11,7 @@ class QHBoxLayout; class QComboBox; class QLabel; class QCheckBox; +class QToolButton; QT_END_NAMESPACE namespace TextEditor { @@ -27,27 +28,26 @@ public: QString searchKeywords() const; void setFallbacksVisible(bool on); + void setLabelText(const QString &text); signals: private slots: void slotComboBoxActivated(int index); - void slotCheckBoxClicked(bool checked); void slotCurrentFallbackChanged(TextEditor::IFallbackPreferences *); + void slotRestoreValues(QObject *); private: IFallbackPreferences *m_fallbackPreferences; QHBoxLayout *m_layout; - QCheckBox *m_checkBox; QComboBox *m_comboBox; QLabel *m_comboBoxLabel; + QToolButton *m_restoreButton; bool m_fallbackWidgetVisible; - QMap m_fallbackToIndex; - QMap m_indexToFallback; - + QString m_labelText; }; } // namespace TextEditor diff --git a/src/plugins/texteditor/tabpreferenceswidget.cpp b/src/plugins/texteditor/tabpreferenceswidget.cpp index c98bdbc9ff7..a18edbc2f53 100644 --- a/src/plugins/texteditor/tabpreferenceswidget.cpp +++ b/src/plugins/texteditor/tabpreferenceswidget.cpp @@ -12,6 +12,7 @@ TabPreferencesWidget::TabPreferencesWidget(QWidget *parent) : m_tabPreferences(0) { m_ui->setupUi(this); + m_ui->fallbackWidget->setLabelText(tr("Tab settings:")); } TabPreferencesWidget::~TabPreferencesWidget()