// supplies the default group's name
OUString SwGlossaries::GetDefName()
{ return u"standard"_ustr;
}
// supplies the number of text block groups
size_t SwGlossaries::GetGroupCnt()
{ return GetNameList().size();
}
// supplies the group's name bool SwGlossaries::FindGroupName(OUString& rGroup)
{ // if the group name doesn't contain a path, a suitable group entry // can the searched for here; const size_t nCount = GetGroupCnt(); for(size_t i = 0; i < nCount; ++i)
{ const OUString sTemp(GetGroupName(i)); if (rGroup == o3tl::getToken(sTemp, 0, GLOS_DELIM))
{
rGroup = sTemp; returntrue;
}
} // you can search two times because for more directories the case sensitive // name could occur multiple times const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore(); for(size_t i = 0; i < nCount; ++i)
{ const OUString sTemp( GetGroupName( i ));
sal_uInt16 nPath = o3tl::toUInt32(o3tl::getToken(sTemp, 1, GLOS_DELIM));
// supplies the group rName's text block document
std::unique_ptr<SwTextBlocks> SwGlossaries::GetGroupDoc(const OUString &rName, bool bCreate)
{ // insert to the list of text blocks if applicable if(bCreate && !m_GlosArr.empty())
{ if (std::none_of(m_GlosArr.begin(), m_GlosArr.end(),
[&rName](const OUString& rEntry) { return rEntry == rName; }))
{ // block not in the list
m_GlosArr.push_back(rName);
}
} return GetGlosDoc( rName, bCreate );
}
// Creates a new document with the group name. temporarily also created as file // so that groups remain there later (without access). bool SwGlossaries::NewGroupDoc(OUString& rGroupName, const OUString& rTitle)
{ const std::u16string_view sNewPath(o3tl::getToken(rGroupName, 1, GLOS_DELIM));
sal_uInt16 nNewPath = o3tl::narrowing<sal_uInt16>(o3tl::toInt32(sNewPath)); if (static_cast<size_t>(nNewPath) >= m_PathArr.size()) returnfalse; const OUString sNewFilePath(m_PathArr[nNewPath]); const OUString sNewGroup = lcl_CheckFileName(sNewFilePath, o3tl::getToken(rGroupName, 0, GLOS_DELIM))
+ OUStringChar(GLOS_DELIM) + sNewPath;
std::unique_ptr<SwTextBlocks> pBlock = GetGlosDoc( sNewGroup ); if(pBlock)
{
GetNameList().push_back(sNewGroup);
pBlock->SetName(rTitle);
rGroupName = sNewGroup; returntrue;
} returnfalse;
}
// Deletes a text block group bool SwGlossaries::DelGroupDoc(std::u16string_view rName)
{
sal_uInt16 nPath = o3tl::narrowing<sal_uInt16>(o3tl::toInt32(o3tl::getToken(rName, 1, GLOS_DELIM))); if (static_cast<size_t>(nPath) >= m_PathArr.size()) returnfalse; const std::u16string_view sBaseName(o3tl::getToken(rName, 0, GLOS_DELIM)); const OUString sFileURL = lcl_FullPathName(m_PathArr[nPath], sBaseName); const OUString aName = sBaseName + OUStringChar(GLOS_DELIM) + OUString::number(nPath); // Even if the file doesn't exist it has to be deleted from // the list of text block regions // no && because of CFfront bool bRemoved = SWUnoHelper::UCB_DeleteFile( sFileURL );
OSL_ENSURE(bRemoved, "file has not been removed");
RemoveFileFromList( aName ); return bRemoved;
}
if (bCreate || bExist)
{
pTmp.reset(new SwTextBlocks( sFileURL )); bool bOk = true; if( pTmp->GetError() )
{
ErrorHandler::HandleError( pTmp->GetError() );
bOk = ! pTmp->GetError().IsError();
}
if( bOk && pTmp->GetName().isEmpty() )
pTmp->SetName( rName );
}
}
return pTmp;
}
// access to the list of names; read in if applicable
std::vector<OUString> & SwGlossaries::GetNameList()
{ if (m_GlosArr.empty())
{ const OUString sExt( SwGlossaries::GetExtension() ); for (size_t i = 0; i < m_PathArr.size(); ++i)
{
std::vector<OUString> aFiles;
SWUnoHelper::UCB_GetFileListOfFolder(m_PathArr[i], aFiles, &sExt); for (const OUString& aTitle : aFiles)
{ const OUString sName( aTitle.subView( 0, aTitle.getLength() - sExt.getLength() )
+ OUStringChar(GLOS_DELIM) + OUString::number( static_cast<sal_Int16>(i) ));
m_GlosArr.push_back(sName);
}
} if (m_GlosArr.empty())
{ // the standard block is inside of the path's first part
m_GlosArr.emplace_back(SwGlossaries::GetDefName() + OUStringChar(GLOS_DELIM) + "0" );
}
} return m_GlosArr;
}
void SwGlossaries::RemoveFileFromList( const OUString& rGroup )
{ if (m_GlosArr.empty()) return;
auto it = std::find(m_GlosArr.begin(), m_GlosArr.end(), rGroup); if (it == m_GlosArr.end()) return;
{ // tell the UNO AutoTextGroup object that it's not valid anymore for ( UnoAutoTextGroups::iterator aLoop = m_aGlossaryGroups.begin();
aLoop != m_aGlossaryGroups.end();
)
{
rtl::Reference< SwXAutoTextGroup > xNamed( aLoop->get() ); if ( !xNamed.is() )
{
aLoop = m_aGlossaryGroups.erase(aLoop);
} elseif ( xNamed->getName() == rGroup )
{
xNamed->Invalidate(); // note that this static_cast works because we know that the array only // contains SwXAutoTextGroup implementation
m_aGlossaryGroups.erase( aLoop ); break;
} else
++aLoop;
}
}
{ // tell all our UNO AutoTextEntry objects that they're not valid anymore for ( UnoAutoTextEntries::iterator aLoop = m_aGlossaryEntries.begin();
aLoop != m_aGlossaryEntries.end();
)
{
rtl::Reference<SwXAutoTextEntry> pEntry = aLoop->get(); if ( pEntry && ( pEntry->GetGroupName() == rGroup ) )
{
pEntry->Invalidate();
aLoop = m_aGlossaryEntries.erase( aLoop );
} else
++aLoop;
}
}
m_GlosArr.erase(it);
}
OUString SwGlossaries::GetCompleteGroupName( std::u16string_view rGroupName )
{ const size_t nCount = GetGroupCnt(); // when the group name was created internally the path is here as well
sal_Int32 nIndex = 0; const std::u16string_view sGroupName(o3tl::getToken(rGroupName, 0, GLOS_DELIM, nIndex)); constbool bPathLen = !o3tl::getToken(rGroupName, 0, GLOS_DELIM, nIndex).empty(); for ( size_t i = 0; i < nCount; i++ )
{ const OUString sGrpName = GetGroupName(i); if (bPathLen)
{ if (rGroupName == sGrpName) return sGrpName;
} else
{ if (sGroupName == o3tl::getToken(sGrpName, 0, GLOS_DELIM)) return sGrpName;
}
} return OUString();
}
void SwGlossaries::InvalidateUNOOjects()
{ // invalidate all the AutoTextGroup-objects for (constauto& rGroup : m_aGlossaryGroups)
{
rtl::Reference< SwXAutoTextGroup > xGroup( rGroup.get() ); if ( xGroup.is() )
xGroup->Invalidate();
}
UnoAutoTextGroups().swap(m_aGlossaryGroups);
// invalidate all the AutoTextEntry-objects for (constauto& rEntry : m_aGlossaryEntries)
{
rtl::Reference<SwXAutoTextEntry> pEntry = rEntry.get(); if ( pEntry )
pEntry->Invalidate();
}
UnoAutoTextEntries().swap(m_aGlossaryEntries);
}
Reference< text::XAutoTextGroup > SwGlossaries::GetAutoTextGroup( std::u16string_view _rGroupName )
{ bool _bCreate = true; // first, find the name with path-extension const OUString sCompleteGroupName = GetCompleteGroupName( _rGroupName );
rtl::Reference< SwXAutoTextGroup > xGroup;
// look up the group in the cache
UnoAutoTextGroups::iterator aSearch = m_aGlossaryGroups.begin(); for ( ; aSearch != m_aGlossaryGroups.end(); )
{
rtl::Reference<SwXAutoTextGroup> pSwGroup = aSearch->get(); if ( !pSwGroup )
{ // the object is dead in the meantime -> remove from cache
aSearch = m_aGlossaryGroups.erase( aSearch ); continue;
}
if ( _rGroupName == pSwGroup->getName() )
{ // the group is already cached if ( !sCompleteGroupName.isEmpty() )
{ // the group still exists -> return it
xGroup = std::move(pSwGroup); break;
} else
{ // this group does not exist (anymore) -> release the cached UNO object for it
aSearch = m_aGlossaryGroups.erase( aSearch ); // so it won't be created below
_bCreate = false; break;
}
}
++aSearch;
}
if ( !xGroup.is() && _bCreate )
{
xGroup = new SwXAutoTextGroup( sCompleteGroupName, this ); // cache it
m_aGlossaryGroups.emplace_back( xGroup );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.