Make context help work also when switching user interface language.

Also avoids errors because of users messing with the "Unfiltered"
filter, which is used for e.g. context help.
The strategy now is to remove the "Unfiltered" filter from previous runs
(possibly in a different language), and re-register a fresh filter with
the name in the current language, and guaranteed to not filter out
anything.

Reviewed-by: kh1
This commit is contained in:
con
2009-11-19 11:23:52 +01:00
parent a9fa7c71fa
commit ad4c227ca4

View File

@@ -418,7 +418,7 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl++"))); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl++")));
connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomIn())); connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomIn()));
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
a = new QAction(tr("Decrease Font Size"), this); a = new QAction(tr("Decrease Font Size"), this);
cmd = am->registerAction(a, TextEditor::Constants::DECREASE_FONT_SIZE, cmd = am->registerAction(a, TextEditor::Constants::DECREASE_FONT_SIZE,
modecontext); modecontext);
@@ -572,7 +572,6 @@ void HelpPlugin::extensionsInitialized()
return; return;
} }
bool needsSetup = false;
bool assistantInternalDocRegistered = false; bool assistantInternalDocRegistered = false;
QStringList documentationToRemove; QStringList documentationToRemove;
QStringList filtersToRemove; QStringList filtersToRemove;
@@ -601,12 +600,10 @@ void HelpPlugin::extensionsInitialized()
QHelpEngineCore hc(m_helpEngine->collectionFile()); QHelpEngineCore hc(m_helpEngine->collectionFile());
hc.setupData(); hc.setupData();
foreach (const QString &ns, documentationToRemove) { foreach (const QString &ns, documentationToRemove) {
if (hc.unregisterDocumentation(ns)) hc.unregisterDocumentation(ns);
needsSetup = true;
} }
foreach (const QString &filter, filtersToRemove) { foreach (const QString &filter, filtersToRemove) {
if (hc.removeCustomFilter(filter)) hc.removeCustomFilter(filter);
needsSetup = true;
} }
if (!assistantInternalDocRegistered) { if (!assistantInternalDocRegistered) {
@@ -619,28 +616,38 @@ void HelpPlugin::extensionsInitialized()
#endif #endif
if (!hc.registerDocumentation(qchFileName)) if (!hc.registerDocumentation(qchFileName))
qDebug() << qPrintable(hc.error()); qDebug() << qPrintable(hc.error());
needsSetup = true;
} }
} }
QLatin1String key("UnfilteredFilterInserted"); const QLatin1String weAddedFilterKey("UnfilteredFilterInserted");
int i = m_helpEngine->customValue(key).toInt(); const QLatin1String previousFilterNameKey("UnfilteredFilterName");
if (i != 1) { int i = m_helpEngine->customValue(weAddedFilterKey).toInt();
{ const QString filterName = tr("Unfiltered");
QHelpEngineCore hc(m_helpEngine->collectionFile()); if (i == 1) { // we added a filter at some point
hc.setupData(); // remove previously added filter
hc.addCustomFilter(tr("Unfiltered"), QStringList()); QHelpEngineCore hc(m_helpEngine->collectionFile());
hc.setCustomValue(key, 1); hc.setupData();
QString previousFilterName = hc.customValue(previousFilterNameKey).toString();
if (!previousFilterName.isEmpty()) { // we noted down the name of the previously added filter
hc.removeCustomFilter(previousFilterName);
}
if (previousFilterName != filterName) { // potentially remove a filter with new name
hc.removeCustomFilter(filterName);
} }
bool blocked = m_helpEngine->blockSignals(true);
m_helpEngine->setCurrentFilter(tr("Unfiltered"));
m_helpEngine->blockSignals(blocked);
needsSetup = true;
} }
{
QHelpEngineCore hc(m_helpEngine->collectionFile());
hc.setupData();
hc.addCustomFilter(filterName, QStringList());
hc.setCustomValue(weAddedFilterKey, 1);
hc.setCustomValue(previousFilterNameKey, filterName);
}
bool blocked = m_helpEngine->blockSignals(true);
m_helpEngine->setCurrentFilter(filterName);
m_helpEngine->blockSignals(blocked);
if (needsSetup) m_helpEngine->setupData();
m_helpEngine->setupData();
updateFilterComboBox(); updateFilterComboBox();
m_bookmarkManager->setupBookmarkModels(); m_bookmarkManager->setupBookmarkModels();
@@ -652,7 +659,7 @@ void HelpPlugin::extensionsInitialized()
font = qVariantValue<QFont>(m_helpEngine->customValue(QLatin1String("font"), font = qVariantValue<QFont>(m_helpEngine->customValue(QLatin1String("font"),
font)); font));
webSettings->setFontFamily(QWebSettings::StandardFont, font.family()); webSettings->setFontFamily(QWebSettings::StandardFont, font.family());
webSettings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize()); webSettings->setFontSize(QWebSettings::DefaultFontSize, font.pointSize());
#endif #endif