/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// set the default group; if called from the dialog // the group is created temporarily for faster access void SwGlossaryHdl::SetCurGroup(const OUString &rGrp, bool bApi, bool bAlwaysCreateNew )
{
OUString sGroup(rGrp); if (sGroup.indexOf(GLOS_DELIM)<0 && !FindGroupName(sGroup))
{
sGroup += OUStringChar(GLOS_DELIM) + "0";
} if(m_pCurGrp)
{ bool bPathEqual = false; if(!bAlwaysCreateNew)
{
INetURLObject aTemp( m_pCurGrp->GetFileName() ); const OUString sCurBase = aTemp.getBase();
aTemp.removeSegment(); const OUString sCurEntryPath = aTemp.GetMainURL(INetURLObject::DecodeMechanism::NONE); const std::vector<OUString> & rPathArr = m_rStatGlossaries.GetPathArray();
sal_uInt16 nCurrentPath = USHRT_MAX; for (size_t nPath = 0; nPath < rPathArr.size(); ++nPath)
{ if (sCurEntryPath == rPathArr[nPath])
{
nCurrentPath = o3tl::narrowing<sal_uInt16>(nPath); break;
}
} const std::u16string_view sPath = o3tl::getToken(sGroup, 1, GLOS_DELIM);
sal_uInt16 nComparePath = o3tl::narrowing<sal_uInt16>(o3tl::toInt32(sPath)); if(nCurrentPath == nComparePath &&
o3tl::getToken(sGroup, 0, GLOS_DELIM) == sCurBase)
bPathEqual = true;
}
// When path changed, the name is not reliable if(!bAlwaysCreateNew && bPathEqual) return;
}
m_aCurGrp = sGroup; if(!bApi)
{
m_pCurGrp = m_rStatGlossaries.GetGroupDoc(m_aCurGrp, true);
}
}
//The index must be determined here because rSourceShortName maybe changed in CopyBlock
sal_uInt16 nDeleteIdx = pSourceGroup->GetIndex( rSourceShortName );
OSL_ENSURE(USHRT_MAX != nDeleteIdx, "entry not found");
ErrCode nRet = pSourceGroup->CopyBlock( *pDestGroup, rSourceShortName, rLongName ); if(!nRet && bMove)
{ // the index must be existing
nRet = pSourceGroup->Delete( nDeleteIdx ) ? ERRCODE_NONE : ErrCode(1);
} return !nRet;
}
// delete an autotext-file-group bool SwGlossaryHdl::DelGroup(const OUString &rGrpName)
{
OUString sGroup(rGrpName); if (sGroup.indexOf(GLOS_DELIM)<0)
FindGroupName(sGroup); if( m_rStatGlossaries.DelGroupDoc(sGroup) )
{ if(m_pCurGrp)
{ if (m_pCurGrp->GetName() == sGroup)
m_pCurGrp.reset();
} returntrue;
} returnfalse;
}
// ask for number of autotexts
sal_uInt16 SwGlossaryHdl::GetGlossaryCnt() const
{ return m_pCurGrp ? m_pCurGrp->GetCount() : 0;
}
const OUString & SwGlossaryHdl::GetGlossaryName( sal_uInt16 nId )
{
OSL_ENSURE(nId < GetGlossaryCnt(), "Text building block array over-indexed."); return m_pCurGrp->GetLongName( nId );
}
const OUString & SwGlossaryHdl::GetGlossaryShortName(sal_uInt16 nId)
{
OSL_ENSURE(nId < GetGlossaryCnt(), "Text building block array over-indexed."); return m_pCurGrp->GetShortName( nId );
}
// expand short name bool SwGlossaryHdl::ExpandGlossary(weld::Window* pParent)
{
OSL_ENSURE(m_pWrtShell->CanInsert(), "illegal");
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
::GlossaryGetCurrGroup fnGetCurrGroup = pFact->GetGlossaryCurrGroupFunc();
OUString sGroupName( (*fnGetCurrGroup)() ); if (sGroupName.indexOf(GLOS_DELIM)<0)
FindGroupName(sGroupName);
std::unique_ptr<SwTextBlocks> pGlossary = m_rStatGlossaries.GetGroupDoc(sGroupName);
OUString aShortName;
// use this at text selection if(m_pWrtShell->SwCursorShell::HasSelection() && !m_pWrtShell->IsBlockMode())
{
aShortName = m_pWrtShell->GetSelText();
} else
{ if(m_pWrtShell->IsAddMode())
m_pWrtShell->LeaveAddMode(); elseif(m_pWrtShell->IsBlockMode())
m_pWrtShell->LeaveBlockMode(); elseif(m_pWrtShell->IsExtMode())
m_pWrtShell->LeaveExtMode(); // select word (tdf#126589: part to the left of cursor) if (m_pWrtShell->IsInWord() || m_pWrtShell->IsEndWrd())
m_pWrtShell->PrvWrd(true); // ask for word if(m_pWrtShell->IsSelection())
aShortName = m_pWrtShell->GetSelText();
} return Expand(pParent, aShortName, &m_rStatGlossaries, std::move(pGlossary));
}
bool SwGlossaryHdl::Expand(weld::Window* pParent, const OUString& rShortName,
SwGlossaries *pGlossaries,
std::unique_ptr<SwTextBlocks> pGlossary)
{
std::vector<TextBlockInfo_Impl> aFoundArr;
OUString aShortName( rShortName ); bool bCancel = false; // search for text block // - don't prefer current group depending on configuration setting const SvxAutoCorrCfg& rCfg = SvxAutoCorrCfg::Get();
sal_uInt16 nFound = (!rCfg.IsSearchInAllCategories() && pGlossary) ?
pGlossary->GetIndex( aShortName ) : USHRT_MAX; // if not found then search in all groups if (nFound == USHRT_MAX)
{ const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
SwGlossaryList* pGlossaryList = ::GetGlossaryList(); const size_t nGroupCount = pGlossaryList->GetGroupCount(); for(size_t i = 0; i < nGroupCount; ++i)
{ // get group name with path-extension const OUString sGroupName = pGlossaryList->GetGroupName(i); if (pGlossary && sGroupName == pGlossary->GetName()) continue; const sal_uInt16 nBlockCount = pGlossaryList->GetBlockCount(i); if(nBlockCount)
{ const OUString sTitle = pGlossaryList->GetGroupTitle(i); for(sal_uInt16 j = 0; j < nBlockCount; j++)
{ const OUString sLongName(pGlossaryList->GetBlockLongName(i, j)); const OUString sShortName(pGlossaryList->GetBlockShortName(i, j)); if( rSCmp.isEqual( rShortName, sShortName ))
{
aFoundArr.emplace_back(sTitle, sLongName, sGroupName);
}
}
}
} if( !aFoundArr.empty() ) // one was found
{
pGlossary.reset(); if (1 == aFoundArr.size())
{
TextBlockInfo_Impl& rData = aFoundArr.front();
pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
nFound = pGlossary->GetIndex( aShortName );
} else
{
SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
ScopedVclPtr<AbstractSwSelGlossaryDlg> pDlg(pFact->CreateSwSelGlossaryDlg(pParent, aShortName)); for(const TextBlockInfo_Impl & i : aFoundArr)
{ if (i.sTitle == "My AutoText")
pDlg->InsertGlos(SwResId(STR_MY_AUTOTEXT), i.sLongName); else
pDlg->InsertGlos(i.sTitle, i.sLongName);
}
pDlg->SelectEntryPos(0); const sal_Int32 nRet = RET_OK == pDlg->Execute() ?
pDlg->GetSelectedIdx() :
-1;
pDlg.disposeAndClear(); if (nRet != -1)
{
TextBlockInfo_Impl& rData = aFoundArr[nRet];
pGlossary = pGlossaries->GetGroupDoc(rData.sGroupName);
nFound = pGlossary->GetIndex( aShortName );
} else
{
nFound = USHRT_MAX;
bCancel = true;
}
}
}
}
// not found if (nFound == USHRT_MAX)
{ if( !bCancel )
{
pGlossary.reset();
// StartAction must not be before HasSelection and DelRight, // otherwise the possible Shell change gets delayed and // API-programs would hang. // Moreover the event macro must also not be called in an action
m_pWrtShell->StartUndo(SwUndoId::INSGLOSSARY); if( aStartMacro.HasMacro() )
m_pWrtShell->ExecMacro( aStartMacro ); if(m_pWrtShell->HasSelection())
m_pWrtShell->DelLeft();
m_pWrtShell->StartAllAction();
// cache all InputFields
SwInputFieldList aFieldLst( m_pWrtShell, true );
// StartAction must not be before HasSelection and DelRight, // otherwise the possible Shell change gets delayed and // API-programs would hang. // Moreover the event macro must also not be called in an action if( aStartMacro.HasMacro() )
m_pWrtShell->ExecMacro( aStartMacro ); if( m_pWrtShell->HasSelection() )
m_pWrtShell->DelRight();
m_pWrtShell->StartAllAction();
// cache all InputFields
SwInputFieldList aFieldLst( m_pWrtShell, true );
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.