diff options
Diffstat (limited to 'cui/source/customize/CustomNotebookbarGenerator.cxx')
-rw-r--r-- | cui/source/customize/CustomNotebookbarGenerator.cxx | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/cui/source/customize/CustomNotebookbarGenerator.cxx b/cui/source/customize/CustomNotebookbarGenerator.cxx index 365c7f9f00d5..e1851a72506a 100644 --- a/cui/source/customize/CustomNotebookbarGenerator.cxx +++ b/cui/source/customize/CustomNotebookbarGenerator.cxx @@ -29,6 +29,7 @@ #include <com/sun/star/frame/ModuleManager.hpp> #include <unotools/confignode.hxx> #include <libxml/parser.h> +#include <o3tl/string_view.hxx> #define aUIPropertiesCount 3 @@ -41,20 +42,15 @@ static OUString lcl_activeAppName(vcl::EnumContext::Application eApp) switch (eApp) { case vcl::EnumContext::Application::Writer: - return "ActiveWriter"; - break; + return u"ActiveWriter"_ustr; case vcl::EnumContext::Application::Calc: - return "ActiveCalc"; - break; + return u"ActiveCalc"_ustr; case vcl::EnumContext::Application::Impress: - return "ActiveImpress"; - break; + return u"ActiveImpress"_ustr; case vcl::EnumContext::Application::Draw: - return "ActiveDraw"; - break; + return u"ActiveDraw"_ustr; default: return OUString(); - break; } } @@ -63,31 +59,29 @@ static OUString lcl_getAppName(vcl::EnumContext::Application eApp) switch (eApp) { case vcl::EnumContext::Application::Writer: - return "Writer"; - break; + return u"Writer"_ustr; case vcl::EnumContext::Application::Calc: - return "Calc"; - break; + return u"Calc"_ustr; case vcl::EnumContext::Application::Impress: - return "Impress"; - break; + return u"Impress"_ustr; case vcl::EnumContext::Application::Draw: - return "Draw"; - break; + return u"Draw"_ustr; default: return OUString(); - break; } } static OUString getAppNameRegistryPath() { vcl::EnumContext::Application eApp = vcl::EnumContext::Application::Any; - const Reference<frame::XFrame>& xFrame - = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); - const Reference<frame::XModuleManager> xModuleManager - = frame::ModuleManager::create(::comphelper::getProcessComponentContext()); - eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); + + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + { + const Reference<frame::XFrame>& xFrame = pViewFrame->GetFrame().GetFrameInterface(); + const Reference<frame::XModuleManager> xModuleManager + = frame::ModuleManager::create(::comphelper::getProcessComponentContext()); + eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xFrame)); + } OUString sAppName(lcl_getAppName(eApp)); return "org.openoffice.Office.UI.ToolbarMode/Applications/" + sAppName; @@ -95,8 +89,8 @@ static OUString getAppNameRegistryPath() static OUString customizedUIPathBuffer() { - OUString sDirPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( - "bootstrap") ":UserInstallation}/user/config/soffice.cfg/"); + OUString sDirPath(u"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE( + "bootstrap") ":UserInstallation}/user/config/soffice.cfg/"_ustr); rtl::Bootstrap::expandMacros(sDirPath); return sDirPath; } @@ -190,14 +184,18 @@ static xmlDocPtr notebookbarXMLParser(const OString& rDocName, const OString& rU void CustomNotebookbarGenerator::modifyCustomizedUIFile(const Sequence<OUString>& sUIItemProperties) { - OString sCustomizedUIPath = getSystemPath(getCustomizedUIPath()); + const OUString sUIPath = getCustomizedUIPath(); + if (osl::File(sUIPath).open(osl_File_OpenFlag_Read) != osl::FileBase::E_None) + createCustomizedUIFile(); + + const OString sCustomizedUIPath = getSystemPath(sUIPath); for (auto const& aValue : sUIItemProperties) { std::vector<OString> aProperties(aUIPropertiesCount); for (sal_Int32 aIndex = 0; aIndex < aUIPropertiesCount; aIndex++) { sal_Int32 nPos = aIndex; - OUString sToken = aValue.getToken(nPos, ',', nPos); + std::u16string_view sToken = o3tl::getToken(aValue, nPos, ',', nPos); aProperties[aIndex] = OUStringToOString(sToken, RTL_TEXTENCODING_UTF8); } xmlDocPtr doc = notebookbarXMLParser(sCustomizedUIPath, aProperties[0], aProperties[1], @@ -219,7 +217,8 @@ void CustomNotebookbarGenerator::getFileNameAndAppName(OUString& sAppName, return; const auto xContext = comphelper::getProcessComponentContext(); - utl::OConfigurationTreeRoot aRoot(xContext, "org.openoffice.Office.UI.ToolbarMode/", false); + utl::OConfigurationTreeRoot aRoot(xContext, u"org.openoffice.Office.UI.ToolbarMode/"_ustr, + false); const Reference<frame::XFrame>& xFrame = pFrame->GetFrame().GetFrameInterface(); const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create(xContext); @@ -259,25 +258,25 @@ Sequence<OUString> CustomNotebookbarGenerator::getCustomizedUIItem(OUString sNot const utl::OConfigurationTreeRoot aAppNode(::comphelper::getProcessComponentContext(), aPath, false); - const utl::OConfigurationNode aModesNode = aAppNode.openNode("Modes"); + const utl::OConfigurationNode aModesNode = aAppNode.openNode(u"Modes"_ustr); const utl::OConfigurationNode aModeNode(aModesNode.openNode(sNotebookbarConfigType)); - const Any aValue = aModeNode.getNodeValue("UIItemProperties"); + const Any aValue = aModeNode.getNodeValue(u"UIItemProperties"_ustr); Sequence<OUString> aValues; aValue >>= aValues; return aValues; } -void CustomNotebookbarGenerator::setCustomizedUIItem(Sequence<OUString> sUIItemProperties, - OUString sNotebookbarConfigType) +void CustomNotebookbarGenerator::setCustomizedUIItem(const Sequence<OUString>& rUIItemProperties, + const OUString& rNotebookbarConfigType) { OUString aPath = getAppNameRegistryPath(); const utl::OConfigurationTreeRoot aAppNode(::comphelper::getProcessComponentContext(), aPath, true); - const utl::OConfigurationNode aModesNode = aAppNode.openNode("Modes"); - const utl::OConfigurationNode aModeNode(aModesNode.openNode(sNotebookbarConfigType)); + const utl::OConfigurationNode aModesNode = aAppNode.openNode(u"Modes"_ustr); + const utl::OConfigurationNode aModeNode(aModesNode.openNode(rNotebookbarConfigType)); - css::uno::Any aUIItemProperties(makeAny(sUIItemProperties)); - aModeNode.setNodeValue("UIItemProperties", aUIItemProperties); + css::uno::Any aUIItemProperties(rUIItemProperties); + aModeNode.setNodeValue(u"UIItemProperties"_ustr, aUIItemProperties); aAppNode.commit(); } |