summaryrefslogtreecommitdiff
path: root/sfx2/source
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-11-22 08:56:15 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-11-22 12:46:56 +0100
commit06ad764cfb36ece7f054ecb786cc0395346a6a68 (patch)
treef67c2045e736fbbdb67d18255380b2d9288d75e4 /sfx2/source
parenta73494cf130866d4e678a1f421df56cdba7441d8 (diff)
improve function-local statics in scripting..svtools
Change-Id: Idf3785a1fbc6fc5b8efbdc4cd363047709f3af91 Reviewed-on: https://gerrit.libreoffice.org/63782 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2/source')
-rw-r--r--sfx2/source/appl/sfxhelp.cxx48
-rw-r--r--sfx2/source/view/classificationhelper.cxx11
-rw-r--r--sfx2/source/view/sfxbasecontroller.cxx74
3 files changed, 52 insertions, 81 deletions
diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index d52f74aa4a96..30aa68b840f4 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -117,25 +117,24 @@ namespace {
/// Root path of the help.
OUString const & getHelpRootURL()
{
- static OUString s_instURL;
- if (!s_instURL.isEmpty())
- return s_instURL;
-
- s_instURL = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext());
- if (s_instURL.isEmpty())
+ static OUString const s_instURL = [&]()
{
- // try to determine path from default
- s_instURL = "$(instpath)/" LIBO_SHARE_HELP_FOLDER;
- }
-
- // replace anything like $(instpath);
- SvtPathOptions aOptions;
- s_instURL = aOptions.SubstituteVariable(s_instURL);
+ OUString tmp = officecfg::Office::Common::Path::Current::Help::get(comphelper::getProcessComponentContext());
+ if (tmp.isEmpty())
+ {
+ // try to determine path from default
+ tmp = "$(instpath)/" LIBO_SHARE_HELP_FOLDER;
+ }
- OUString url;
- if (osl::FileBase::getFileURLFromSystemPath(s_instURL, url) == osl::FileBase::E_None)
- s_instURL = url;
+ // replace anything like $(instpath);
+ SvtPathOptions aOptions;
+ tmp = aOptions.SubstituteVariable(tmp);
+ OUString url;
+ if (osl::FileBase::getFileURLFromSystemPath(tmp, url) == osl::FileBase::E_None)
+ tmp = url;
+ return tmp;
+ }();
return s_instURL;
}
@@ -161,13 +160,8 @@ bool impl_hasHelpInstalled()
if (comphelper::LibreOfficeKit::isActive())
return false;
- static OUString aLocaleStr;
-
- if (aLocaleStr.isEmpty())
- {
// detect installed locale
- aLocaleStr = HelpLocaleString();
- }
+ static OUString const aLocaleStr = HelpLocaleString();
OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/err.html";
bool bOK = false;
@@ -187,13 +181,8 @@ bool impl_hasHTMLHelpInstalled()
if (comphelper::LibreOfficeKit::isActive())
return false;
- static OUString aLocaleStr;
-
- if (aLocaleStr.isEmpty())
- {
- // detect installed locale
- aLocaleStr = HelpLocaleString();
- }
+ // detect installed locale
+ static OUString const aLocaleStr = HelpLocaleString();
OUString helpRootURL = getHelpRootURL() + "/" + aLocaleStr + "/text";
bool bOK = impl_checkHelpLocalePath( helpRootURL );
@@ -204,7 +193,6 @@ bool impl_hasHTMLHelpInstalled()
} // namespace
/// Return the locale we prefer for displaying help
-// static OUString const & HelpLocaleString()
static OUString const & HelpLocaleString()
{
if (comphelper::LibreOfficeKit::isActive())
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 049f8008c4e5..04b414d674c5 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -762,13 +762,12 @@ sal_Int32 SfxClassificationHelper::GetImpactLevel()
}
else if (aScale == "FIPS-199")
{
- static std::map<OUString, sal_Int32> aValues;
- if (aValues.empty())
+ static std::map<OUString, sal_Int32> const aValues
{
- aValues["Low"] = 0;
- aValues["Moderate"] = 1;
- aValues["High"] = 2;
- }
+ { "Low", 0 },
+ { "Moderate", 1 },
+ { "High", 2 }
+ };
auto itValues = aValues.find(aLevel);
if (itValues == aValues.end())
return nRet;
diff --git a/sfx2/source/view/sfxbasecontroller.cxx b/sfx2/source/view/sfxbasecontroller.cxx
index a15f07f3831c..697a78450279 100644
--- a/sfx2/source/view/sfxbasecontroller.cxx
+++ b/sfx2/source/view/sfxbasecontroller.cxx
@@ -113,56 +113,40 @@ struct GroupIDToCommandGroup
sal_Int16 const nCommandGroup;
};
-static bool bGroupIDMapInitialized = false;
-static const GroupIDToCommandGroup GroupIDCommandGroupMap[] =
-{
- { SfxGroupId::Intern , frame::CommandGroup::INTERNAL },
- { SfxGroupId::Application , frame::CommandGroup::APPLICATION },
- { SfxGroupId::Document , frame::CommandGroup::DOCUMENT },
- { SfxGroupId::View , frame::CommandGroup::VIEW },
- { SfxGroupId::Edit , frame::CommandGroup::EDIT },
- { SfxGroupId::Macro , frame::CommandGroup::MACRO },
- { SfxGroupId::Options , frame::CommandGroup::OPTIONS },
- { SfxGroupId::Math , frame::CommandGroup::MATH },
- { SfxGroupId::Navigator , frame::CommandGroup::NAVIGATOR },
- { SfxGroupId::Insert , frame::CommandGroup::INSERT },
- { SfxGroupId::Format , frame::CommandGroup::FORMAT },
- { SfxGroupId::Template , frame::CommandGroup::TEMPLATE },
- { SfxGroupId::Text , frame::CommandGroup::TEXT },
- { SfxGroupId::Frame , frame::CommandGroup::FRAME },
- { SfxGroupId::Graphic , frame::CommandGroup::GRAPHIC },
- { SfxGroupId::Table , frame::CommandGroup::TABLE },
- { SfxGroupId::Enumeration , frame::CommandGroup::ENUMERATION },
- { SfxGroupId::Data , frame::CommandGroup::DATA },
- { SfxGroupId::Special , frame::CommandGroup::SPECIAL },
- { SfxGroupId::Image , frame::CommandGroup::IMAGE },
- { SfxGroupId::Chart , frame::CommandGroup::CHART },
- { SfxGroupId::Explorer , frame::CommandGroup::EXPLORER },
- { SfxGroupId::Connector , frame::CommandGroup::CONNECTOR },
- { SfxGroupId::Modify , frame::CommandGroup::MODIFY },
- { SfxGroupId::Drawing , frame::CommandGroup::DRAWING },
- { SfxGroupId::Controls , frame::CommandGroup::CONTROLS },
- { SfxGroupId::NONE, 0 }
-};
-
typedef std::unordered_map< SfxGroupId, sal_Int16 > GroupHashMap;
sal_Int16 MapGroupIDToCommandGroup( SfxGroupId nGroupID )
{
- static GroupHashMap s_aHashMap;
-
- if ( !bGroupIDMapInitialized )
+ static GroupHashMap s_aHashMap
{
- sal_Int32 i = 0;
- while ( GroupIDCommandGroupMap[i].nGroupID != SfxGroupId::NONE )
- {
- s_aHashMap.emplace(
- GroupIDCommandGroupMap[i].nGroupID,
- GroupIDCommandGroupMap[i].nCommandGroup );
- ++i;
- }
- bGroupIDMapInitialized = true;
- }
+ { SfxGroupId::Intern , frame::CommandGroup::INTERNAL },
+ { SfxGroupId::Application , frame::CommandGroup::APPLICATION },
+ { SfxGroupId::Document , frame::CommandGroup::DOCUMENT },
+ { SfxGroupId::View , frame::CommandGroup::VIEW },
+ { SfxGroupId::Edit , frame::CommandGroup::EDIT },
+ { SfxGroupId::Macro , frame::CommandGroup::MACRO },
+ { SfxGroupId::Options , frame::CommandGroup::OPTIONS },
+ { SfxGroupId::Math , frame::CommandGroup::MATH },
+ { SfxGroupId::Navigator , frame::CommandGroup::NAVIGATOR },
+ { SfxGroupId::Insert , frame::CommandGroup::INSERT },
+ { SfxGroupId::Format , frame::CommandGroup::FORMAT },
+ { SfxGroupId::Template , frame::CommandGroup::TEMPLATE },
+ { SfxGroupId::Text , frame::CommandGroup::TEXT },
+ { SfxGroupId::Frame , frame::CommandGroup::FRAME },
+ { SfxGroupId::Graphic , frame::CommandGroup::GRAPHIC },
+ { SfxGroupId::Table , frame::CommandGroup::TABLE },
+ { SfxGroupId::Enumeration , frame::CommandGroup::ENUMERATION },
+ { SfxGroupId::Data , frame::CommandGroup::DATA },
+ { SfxGroupId::Special , frame::CommandGroup::SPECIAL },
+ { SfxGroupId::Image , frame::CommandGroup::IMAGE },
+ { SfxGroupId::Chart , frame::CommandGroup::CHART },
+ { SfxGroupId::Explorer , frame::CommandGroup::EXPLORER },
+ { SfxGroupId::Connector , frame::CommandGroup::CONNECTOR },
+ { SfxGroupId::Modify , frame::CommandGroup::MODIFY },
+ { SfxGroupId::Drawing , frame::CommandGroup::DRAWING },
+ { SfxGroupId::Controls , frame::CommandGroup::CONTROLS },
+ };
+
GroupHashMap::const_iterator pIter = s_aHashMap.find( nGroupID );
if ( pIter != s_aHashMap.end() )