Kaydet (Commit) e904562a authored tarafından Caolán McNamara's avatar Caolán McNamara

Related: fdo#81641 create new styles with an initial name

instead of creating with a blank name and changing it later

this way undo of a style creation is initialized with its name and so create a
style followed by deleting a style and undoing all those steps doesn't crash

Change-Id: Ida7a34410d5d7b05edcb86950aabb3c672b82c8f
üst 965b2059
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <sfx2/tabdlg.hxx> #include <sfx2/tabdlg.hxx>
class SfxStyleSheetBase; class SfxStyleSheetBase;
class SfxStyleSheetBasePool;
class SFX2_DLLPUBLIC SfxStyleDialog: public SfxTabDialog class SFX2_DLLPUBLIC SfxStyleDialog: public SfxTabDialog
{ {
...@@ -45,6 +46,8 @@ public: ...@@ -45,6 +46,8 @@ public:
const SfxStyleSheetBase& GetStyleSheet() const { return *pStyle; } const SfxStyleSheetBase& GetStyleSheet() const { return *pStyle; }
virtual short Ok() SAL_OVERRIDE; virtual short Ok() SAL_OVERRIDE;
static OUString GenerateUnusedName(SfxStyleSheetBasePool &rPool);
}; };
#endif #endif
......
...@@ -96,16 +96,7 @@ SfxManageStyleSheetPage::SfxManageStyleSheetPage(Window* pParent, const SfxItemS ...@@ -96,16 +96,7 @@ SfxManageStyleSheetPage::SfxManageStyleSheetPage(Window* pParent, const SfxItemS
if ( pStyle->GetName().isEmpty() && pPool ) if ( pStyle->GetName().isEmpty() && pPool )
{ {
// NullString as Name -> generate Name // NullString as Name -> generate Name
OUString aNoName( SfxResId(STR_NONAME).toString() ); OUString aNoName(SfxStyleDialog::GenerateUnusedName(*pPool));
sal_uInt16 nNo = 1;
OUString aNo( aNoName );
aNoName += OUString::number( nNo );
while ( pPool->Find( aNoName ) )
{
++nNo;
aNoName = aNo;
aNoName += OUString::number( nNo );
}
pStyle->SetName( aNoName ); pStyle->SetName( aNoName );
aName = aNoName; aName = aNoName;
aFollow = pStyle->GetFollow(); aFollow = pStyle->GetFollow();
......
...@@ -147,5 +147,19 @@ IMPL_LINK( SfxStyleDialog, CancelHdl, Button *, pButton ) ...@@ -147,5 +147,19 @@ IMPL_LINK( SfxStyleDialog, CancelHdl, Button *, pButton )
return 0; return 0;
} }
OUString SfxStyleDialog::GenerateUnusedName(SfxStyleSheetBasePool &rPool)
{
OUString aNoName(SfxResId(STR_NONAME).toString());
sal_uInt16 nNo = 1;
OUString aNo(aNoName);
aNoName += OUString::number(nNo);
while (rPool.Find(aNoName))
{
++nNo;
aNoName = aNo;
aNoName += OUString::number(nNo);
}
return aNoName;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <hintids.hxx> #include <hintids.hxx>
#include <sfx2/app.hxx> #include <sfx2/app.hxx>
#include <sfx2/styledlg.hxx>
#include <svl/whiter.hxx> #include <svl/whiter.hxx>
#include <sfx2/templdlg.hxx> #include <sfx2/templdlg.hxx>
#include <sfx2/tplpitem.hxx> #include <sfx2/tplpitem.hxx>
...@@ -291,6 +292,9 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq ) ...@@ -291,6 +292,9 @@ void SwDocShell::ExecStyleSheet( SfxRequest& rReq )
false, &pItem )) false, &pItem ))
sParent = ((const SfxStringItem*)pItem)->GetValue(); sParent = ((const SfxStringItem*)pItem)->GetValue();
if (sName.isEmpty() && mxBasePool.get())
sName = SfxStyleDialog::GenerateUnusedName(*mxBasePool);
nRet = Edit( sName, sParent, nFamily, nMask, true, OString(), 0, rReq.IsAPI() ); nRet = Edit( sName, sParent, nFamily, nMask, true, OString(), 0, rReq.IsAPI() );
} }
break; break;
......
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