Kaydet (Commit) 8a648b82 authored tarafından Mike Kaganski's avatar Mike Kaganski

tdf#38225: update API name when renaming using a base class ref

... but don't update it in case it's a predefined API name

Change-Id: I20075a4e085bdeab8374860c16e7eb2a72772c33
Reviewed-on: https://gerrit.libreoffice.org/54879Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst dedff8b9
......@@ -80,6 +80,9 @@ public:
static void BroadcastSdStyleSheetChange(SfxStyleSheetBase const * pStyleSheet, PresentationObjects ePO,
SfxStyleSheetBasePool* pSSPool);
// SfxStyleSheetBase
virtual bool SetName(const OUString& rNewName, bool bReindexNow = true) override;
// XInterface
virtual void SAL_CALL release( ) throw () override;
......
......@@ -61,6 +61,7 @@ public:
void testTdf99396TextEdit();
void testFillGradient();
void testTdf44774();
void testTdf38225();
CPPUNIT_TEST_SUITE(SdMiscTest);
CPPUNIT_TEST(testTdf96206);
......@@ -69,6 +70,7 @@ public:
CPPUNIT_TEST(testTdf99396TextEdit);
CPPUNIT_TEST(testFillGradient);
CPPUNIT_TEST(testTdf44774);
CPPUNIT_TEST(testTdf38225);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -327,6 +329,38 @@ void SdMiscTest::testTdf44774()
CPPUNIT_ASSERT_EQUAL(OUString("StyleA"), pStyle->GetParent());
}
void SdMiscTest::testTdf38225()
{
sd::DrawDocShellRef xDocShRef = new sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false,
DocumentType::Draw);
const uno::Reference<frame::XLoadable> xLoadable(xDocShRef->GetModel(), uno::UNO_QUERY_THROW);
xLoadable->initNew();
SfxStyleSheetBasePool* pSSPool = xDocShRef->GetStyleSheetPool();
// Create a new style with a name
pSSPool->Make("StyleWithName1", SfxStyleFamily::Para, SfxStyleSearchBits::UserDefined);
// Now save the file and reload
xDocShRef = saveAndReload(xDocShRef.get(), ODG);
pSSPool = xDocShRef->GetStyleSheetPool();
SfxStyleSheetBase* pStyle = pSSPool->Find("StyleWithName1", SfxStyleFamily::Para);
CPPUNIT_ASSERT(pStyle);
// Rename the style
CPPUNIT_ASSERT(pStyle->SetName("StyleWithName2"));
// Save the file and reload again
xDocShRef = saveAndReload(xDocShRef.get(), ODG);
pSSPool = xDocShRef->GetStyleSheetPool();
// The problem was that the style kept the old name upon reloading
pStyle = pSSPool->Find("StyleWithName1", SfxStyleFamily::Para);
CPPUNIT_ASSERT(!pStyle);
pStyle = pSSPool->Find("StyleWithName2", SfxStyleFamily::Para);
CPPUNIT_ASSERT(pStyle);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest);
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -582,56 +582,77 @@ bool SdStyleSheet::HasClearParentSupport() const
return true;
}
void SdStyleSheet::SetHelpId( const OUString& r, sal_uLong nId )
namespace
{
SfxStyleSheet::SetHelpId( r, nId );
struct ApiNameMap
{
OUStringLiteral mpApiName;
sal_uInt32 mnHelpId;
} const pApiNameMap[]
= { { OUStringLiteral("title"), HID_PSEUDOSHEET_TITLE },
{ OUStringLiteral("subtitle"), HID_PSEUDOSHEET_SUBTITLE },
{ OUStringLiteral("background"), HID_PSEUDOSHEET_BACKGROUND },
{ OUStringLiteral("backgroundobjects"), HID_PSEUDOSHEET_BACKGROUNDOBJECTS },
{ OUStringLiteral("notes"), HID_PSEUDOSHEET_NOTES },
{ OUStringLiteral("standard"), HID_STANDARD_STYLESHEET_NAME },
{ OUStringLiteral("objectwithoutfill"), HID_POOLSHEET_OBJWITHOUTFILL },
{ OUStringLiteral("text"), HID_POOLSHEET_TEXT },
{ OUStringLiteral("title"), HID_POOLSHEET_TITLE },
{ OUStringLiteral("headline"), HID_POOLSHEET_HEADLINE },
{ OUStringLiteral("measure"), HID_POOLSHEET_MEASURE },
{ OUStringLiteral("Filled"), HID_POOLSHEET_FILLED },
{ OUStringLiteral("Filled Blue"), HID_POOLSHEET_FILLED_BLUE },
{ OUStringLiteral("Filled Green"), HID_POOLSHEET_FILLED_GREEN },
{ OUStringLiteral("Filled Red"), HID_POOLSHEET_FILLED_RED },
{ OUStringLiteral("Filled Yellow"), HID_POOLSHEET_FILLED_YELLOW },
{ OUStringLiteral("Outlined"), HID_POOLSHEET_OUTLINE },
{ OUStringLiteral("Outlined Blue"), HID_POOLSHEET_OUTLINE_BLUE },
{ OUStringLiteral("Outlined Green"), HID_POOLSHEET_OUTLINE_GREEN },
{ OUStringLiteral("Outlined Red"), HID_POOLSHEET_OUTLINE_RED },
{ OUStringLiteral("Outlined Yellow"), HID_POOLSHEET_OUTLINE_YELLOW } };
OUString GetApiNameForHelpId(sal_uLong nId)
{
if ((nId >= HID_PSEUDOSHEET_OUTLINE1) && (nId <= HID_PSEUDOSHEET_OUTLINE9))
return "outline" + OUStringLiteral1('1' + (nId - HID_PSEUDOSHEET_OUTLINE1));
if( (nId >= HID_PSEUDOSHEET_OUTLINE1) && ( nId <= HID_PSEUDOSHEET_OUTLINE9 ) )
{
msApiName = "outline";
msApiName += OUStringLiteral1( '1' + (nId - HID_PSEUDOSHEET_OUTLINE1) );
}
else
for (const auto& i : pApiNameMap)
if (nId == i.mnHelpId)
return i.mpApiName;
return OUString();
}
sal_uInt32 GetHelpIdForApiName(const OUString& sName)
{
OUString sRest;
if (sName.startsWith("outline", &sRest))
{
static struct ApiNameMap
if (sRest.getLength() == 1)
{
OUStringLiteral mpApiName;
sal_uInt32 mnHelpId;
}
const pApiNameMap[] =
{
{ OUStringLiteral("title"), HID_PSEUDOSHEET_TITLE },
{ OUStringLiteral("subtitle"), HID_PSEUDOSHEET_SUBTITLE },
{ OUStringLiteral("background"), HID_PSEUDOSHEET_BACKGROUND },
{ OUStringLiteral("backgroundobjects"),HID_PSEUDOSHEET_BACKGROUNDOBJECTS },
{ OUStringLiteral("notes"), HID_PSEUDOSHEET_NOTES },
{ OUStringLiteral("standard"), HID_STANDARD_STYLESHEET_NAME },
{ OUStringLiteral("objectwithoutfill"),HID_POOLSHEET_OBJWITHOUTFILL },
{ OUStringLiteral("text"), HID_POOLSHEET_TEXT },
{ OUStringLiteral("title"), HID_POOLSHEET_TITLE },
{ OUStringLiteral("headline"), HID_POOLSHEET_HEADLINE },
{ OUStringLiteral("measure"), HID_POOLSHEET_MEASURE },
{ OUStringLiteral("Filled"), HID_POOLSHEET_FILLED },
{ OUStringLiteral("Filled Blue"), HID_POOLSHEET_FILLED_BLUE },
{ OUStringLiteral("Filled Green"), HID_POOLSHEET_FILLED_GREEN },
{ OUStringLiteral("Filled Red"), HID_POOLSHEET_FILLED_RED },
{ OUStringLiteral("Filled Yellow"), HID_POOLSHEET_FILLED_YELLOW },
{ OUStringLiteral("Outlined"), HID_POOLSHEET_OUTLINE },
{ OUStringLiteral("Outlined Blue"), HID_POOLSHEET_OUTLINE_BLUE },
{ OUStringLiteral("Outlined Green"), HID_POOLSHEET_OUTLINE_GREEN },
{ OUStringLiteral("Outlined Red"), HID_POOLSHEET_OUTLINE_RED },
{ OUStringLiteral("Outlined Yellow"), HID_POOLSHEET_OUTLINE_YELLOW }
};
for (std::size_t i = 0; i != SAL_N_ELEMENTS(pApiNameMap); ++i)
{
if( nId == pApiNameMap[i].mnHelpId )
{
msApiName = pApiNameMap[i].mpApiName;
break;
}
sal_Unicode ch = sRest.toChar();
if ('1' <= ch && ch <= '9')
return HID_PSEUDOSHEET_OUTLINE1 + ch - '1';
}
// No other pre-defined names start with "outline"
return 0;
}
for (const auto& i : pApiNameMap)
if (sName == i.mpApiName)
return i.mnHelpId;
return 0;
}
}
void SdStyleSheet::SetHelpId( const OUString& r, sal_uLong nId )
{
SfxStyleSheet::SetHelpId( r, nId );
const OUString sNewApiName = GetApiNameForHelpId(nId);
if (!sNewApiName.isEmpty())
msApiName = sNewApiName;
}
OUString SdStyleSheet::GetFamilyString( SfxStyleFamily eFamily )
......@@ -834,6 +855,18 @@ Sequence< OUString > SAL_CALL SdStyleSheet::getSupportedServiceNames()
return aNameSequence;
}
bool SdStyleSheet::SetName(const OUString& rNewName, bool bReindexNow)
{
const bool bResult = SfxUnoStyleSheet::SetName(rNewName, bReindexNow);
// Don't overwrite predefined API names
if (bResult && GetHelpIdForApiName(msApiName) == 0)
{
msApiName = rNewName;
Broadcast(SfxHint(SfxHintId::DataChanged));
}
return bResult;
}
// XNamed
OUString SAL_CALL SdStyleSheet::getName()
{
......@@ -846,12 +879,7 @@ void SAL_CALL SdStyleSheet::setName( const OUString& rName )
{
SolarMutexGuard aGuard;
throwIfDisposed();
if( SetName( rName ) )
{
msApiName = rName;
Broadcast(SfxHint(SfxHintId::DataChanged));
}
SetName(rName);
}
// XStyle
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment