forked from qt-creator/qt-creator
qmldesigner: block local changes while initialization
- emit after the initialization - emit only if found languages are differrent Change-Id: I4f426b7bf055ef1d97e5db86bba075a032210303 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -217,42 +217,46 @@ SwitchLanguageComboboxAction::SwitchLanguageComboboxAction(QObject *parent)
|
||||
connect(ProjectExplorer::SessionManager::instance(),
|
||||
&ProjectExplorer::SessionManager::startupProjectChanged,
|
||||
this,
|
||||
&SwitchLanguageComboboxAction::refreshProjectLocales);
|
||||
&SwitchLanguageComboboxAction::updateProjectLocales);
|
||||
}
|
||||
|
||||
QWidget *SwitchLanguageComboboxAction::createWidget(QWidget *parent)
|
||||
{
|
||||
QPointer<QComboBox> comboBox = new QComboBox(parent);
|
||||
comboBox->setToolTip(tr("Switch the language used by preview."));
|
||||
comboBox->addItem(tr("Default"));
|
||||
|
||||
auto refreshComboBoxFunction = [this, comboBox] (ProjectExplorer::Project *project) {
|
||||
if (comboBox) {
|
||||
if (updateProjectLocales(project)) {
|
||||
comboBox->clear();
|
||||
comboBox->addItem(tr("Default"));
|
||||
comboBox->addItems(m_localeStrings);
|
||||
}
|
||||
}
|
||||
};
|
||||
connect(ProjectExplorer::SessionManager::instance(), &ProjectExplorer::SessionManager::startupProjectChanged,
|
||||
comboBox, refreshComboBoxFunction);
|
||||
|
||||
if (auto project = SessionManager::startupProject())
|
||||
refreshComboBoxFunction(project);
|
||||
|
||||
// do this after refreshComboBoxFunction so we do not get currentLocaleChanged signals at initialization
|
||||
connect(comboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this, comboBox](int index) {
|
||||
if (index == 0)
|
||||
if (index == 0) // == Default
|
||||
emit currentLocaleChanged("");
|
||||
else
|
||||
emit currentLocaleChanged(comboBox->currentText());
|
||||
});
|
||||
|
||||
auto refreshComboBoxFunction = [this, comboBox] (ProjectExplorer::Project *project) {
|
||||
if (comboBox) {
|
||||
refreshProjectLocales(project);
|
||||
comboBox->clear();
|
||||
comboBox->addItem(tr("Default"));
|
||||
comboBox->addItems(m_localeStrings);
|
||||
}
|
||||
};
|
||||
connect(ProjectExplorer::SessionManager::instance(),
|
||||
&ProjectExplorer::SessionManager::startupProjectChanged,
|
||||
refreshComboBoxFunction);
|
||||
|
||||
if (auto project = SessionManager::startupProject())
|
||||
refreshComboBoxFunction(project);
|
||||
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
void SwitchLanguageComboboxAction::refreshProjectLocales(Project *project)
|
||||
bool SwitchLanguageComboboxAction::updateProjectLocales(Project *project)
|
||||
{
|
||||
if (!project)
|
||||
return;
|
||||
return false;
|
||||
auto previousLocales = m_localeStrings;
|
||||
m_localeStrings.clear();
|
||||
const auto projectDirectory = project->rootProjectDirectory().toFileInfo().absoluteFilePath();
|
||||
const QDir languageDirectory(projectDirectory + "/i18n");
|
||||
@@ -263,6 +267,7 @@ void SwitchLanguageComboboxAction::refreshProjectLocales(Project *project)
|
||||
const QString locale = qmFile.left(localeEndPosition).mid(localeStartPosition);
|
||||
return locale;
|
||||
});
|
||||
return previousLocales != m_localeStrings;
|
||||
}
|
||||
|
||||
SwitchLanguageAction::SwitchLanguageAction()
|
||||
|
@@ -113,7 +113,7 @@ signals:
|
||||
protected:
|
||||
QWidget *createWidget(QWidget *parent) override;
|
||||
private:
|
||||
void refreshProjectLocales(ProjectExplorer::Project *project);
|
||||
bool updateProjectLocales(ProjectExplorer::Project *project);
|
||||
QStringList m_localeStrings;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user