summaryrefslogtreecommitdiff
path: root/cui/source/customize/CustomNotebookbarGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'cui/source/customize/CustomNotebookbarGenerator.cxx')
-rw-r--r--cui/source/customize/CustomNotebookbarGenerator.cxx40
1 files changed, 19 insertions, 21 deletions
diff --git a/cui/source/customize/CustomNotebookbarGenerator.cxx b/cui/source/customize/CustomNotebookbarGenerator.cxx
index 365c7f9f00d5..1d013654d8f7 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
@@ -42,19 +43,14 @@ static OUString lcl_activeAppName(vcl::EnumContext::Application eApp)
{
case vcl::EnumContext::Application::Writer:
return "ActiveWriter";
- break;
case vcl::EnumContext::Application::Calc:
return "ActiveCalc";
- break;
case vcl::EnumContext::Application::Impress:
return "ActiveImpress";
- break;
case vcl::EnumContext::Application::Draw:
return "ActiveDraw";
- break;
default:
return OUString();
- break;
}
}
@@ -64,30 +60,28 @@ static OUString lcl_getAppName(vcl::EnumContext::Application eApp)
{
case vcl::EnumContext::Application::Writer:
return "Writer";
- break;
case vcl::EnumContext::Application::Calc:
return "Calc";
- break;
case vcl::EnumContext::Application::Impress:
return "Impress";
- break;
case vcl::EnumContext::Application::Draw:
return "Draw";
- break;
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;
@@ -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],
@@ -267,16 +265,16 @@ Sequence<OUString> CustomNotebookbarGenerator::getCustomizedUIItem(OUString sNot
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 aModeNode(aModesNode.openNode(rNotebookbarConfigType));
- css::uno::Any aUIItemProperties(makeAny(sUIItemProperties));
+ css::uno::Any aUIItemProperties(rUIItemProperties);
aModeNode.setNodeValue("UIItemProperties", aUIItemProperties);
aAppNode.commit();
}