24#include <osl/diagnose.h>
37#define STRING_DELIM char(0x0A)
38#define GLOS_TIMEOUT 30000
39#define FIND_MAX_GLOS 20
52 std::unique_ptr<weld::Button> m_xOk;
53 std::unique_ptr<weld::TreeView> m_xListLB;
67 : GenericDialogController(pParent,
"modules/swriter/ui/selectautotextdialog.ui",
"SelectAutoTextDialog")
68 , m_xOk(m_xBuilder->weld_button(
"ok"))
69 , m_xListLB(m_xBuilder->weld_tree_view(
"treeview"))
71 m_xListLB->set_size_request(m_xListLB->get_approximate_digit_width() * 32,
72 m_xListLB->get_height_rows(8));
73 m_xListLB->connect_row_activated(
LINK(
this, SwGlossDecideDlg, DoubleClickHdl));
74 m_xListLB->connect_changed(
LINK(
this, SwGlossDecideDlg, SelectHdl));
85 m_xOk->set_sensitive(m_xListLB->get_selected_index() != -1);
89 AutoTimer(
"SwGlossaryList"), m_bFilled(false)
106 OUString& rShortName, OUString& rGroupName )
111 std::vector<TripleString> aTripleStrings;
117 if(!rGroupName.isEmpty() && rGroupName != pGroup->
sName)
120 sal_Int32 nPosLong = 0;
121 for(sal_uInt16 j = 0; j < pGroup->
nCount; j++)
124 if(rLongName != sLong)
127 TripleString aTriple;
128 aTriple.sGroup = pGroup->
sName;
129 aTriple.sBlock = sLong;
131 aTripleStrings.push_back(aTriple);
136 nCount = aTripleStrings.size();
139 const TripleString& rTriple(aTripleStrings.front());
140 rShortName = rTriple.sShort;
141 rGroupName = rTriple.sGroup;
150 OUString sTitle = aDlg.get_title() +
" " + aTripleStrings.front().sBlock;
151 aDlg.set_title(sTitle);
154 for (
const auto& rTriple : aTripleStrings)
161 rShortName = rTriple.sShort;
162 rGroupName = rTriple.sGroup;
184 OUString sRet = pGroup->
sName;
203 OSL_ENSURE(
m_aGroupArr.size() > nGroup,
"group not available");
214 OSL_ENSURE(
m_aGroupArr.size() > nGroup,
"group not available");
225 OSL_ENSURE(
m_aGroupArr.size() > nGroup,
"group not available");
248 const std::vector<OUString> & rPathArr =
pGlossaries->GetPathArray();
252 const size_t nGroupCount =
pGlossaries->GetGroupCnt();
253 for(
size_t i = 0;
i < nGroupCount; ++
i)
256 const size_t nPath =
static_cast<size_t>(
258 if( nPath < rPathArr.size() )
261 pGroup->sName = sGrpName;
264 OUString
sName = rPathArr[nPath] +
"/" +
267 &pGroup->aDateModified,
268 &pGroup->aDateModified );
277 for(
size_t nPath = 0; nPath < rPathArr.size(); nPath++ )
279 std::vector<OUString> aFoundGroupNames;
280 std::vector<OUString> aFiles;
281 std::vector<DateTime> aDateTimeArr;
284 &sExt, &aDateTimeArr );
285 for(
size_t nFiles = 0; nFiles < aFiles.size(); ++nFiles )
287 const OUString aTitle = aFiles[ nFiles ];
290 OUString
sName( aTitle.copy( 0, aTitle.getLength() - sExt.getLength() ));
292 aFoundGroupNames.push_back(
sName);
293 sName += OUStringChar(
GLOS_DELIM) + OUString::number( o3tl::narrowing<sal_uInt16>(nPath) );
302 m_aGroupArr.push_back(std::unique_ptr<AutoTextGroup>(pFound));
316 const size_t nGroupPath =
static_cast<size_t>(
320 if( nGroupPath == nPath )
323 bool bFound = std::any_of(aFoundGroupNames.begin(), aFoundGroupNames.end(),
324 [&sCompareGroup](
const OUString& rGroupName) { return sCompareGroup == rGroupName; });
347 if(pRet->sName == rGroupName)
355 std::unique_ptr<SwTextBlocks> pBlock =
pGlossaries->GetGroupDoc(pGroup->
sName);
356 pGroup->
nCount = pBlock ? pBlock->GetCount() : 0;
360 pGroup->
sTitle = pBlock->GetName();
362 for(sal_uInt16 j = 0; j < pGroup->
nCount; j++)
375 std::vector<std::pair<OUString, sal_uInt16>>& rLongNames)
382 std::vector<std::vector<OUString>> aResults(rBeginCandidates.size());
389 for(sal_uInt16 j = 0; j < pGroup->nCount; j++)
391 OUString sBlock = pGroup->sLongNames.getToken(0,
STRING_DELIM, nIdx);
392 for (
size_t i = 0;
i < rBeginCandidates.size(); ++
i)
394 const OUString& s = rBeginCandidates[
i];
395 if (s.getLength() + 1 < sBlock.getLength()
396 && rSCmp.isEqual(sBlock.copy(0, s.getLength()), s))
398 aResults[
i].push_back(sBlock);
404 std::vector<std::pair<OUString, sal_uInt16>> aAllResults;
406 for (
size_t i = 0;
i < rBeginCandidates.size(); ++
i)
408 std::sort(aResults[
i].
begin(), aResults[
i].
end(),
409 [origWord = rBeginCandidates[
i]](
const OUString& s1,
const OUString& s2) {
410 int nRet = s1.compareToIgnoreAsciiCase(s2);
415 int n1StartsWithOrig = s1.startsWith(origWord) ? 0 : 1;
416 int n2StartsWithOrig = s2.startsWith(origWord) ? 0 : 1;
417 return n1StartsWithOrig < n2StartsWithOrig;
422 std::transform(aResults[
i].
begin(), aResults[
i].
end(), std::back_inserter(aAllResults),
423 [nLen = sal_uInt16(rBeginCandidates[
i].
getLength())](
const OUString& s) {
424 return std::make_pair(s, nLen);
428 const auto& it = std::unique(
429 aAllResults.begin(), aAllResults.end(),
430 [](
const std::pair<OUString, sal_uInt16>& s1,
const std::pair<OUString, sal_uInt16>& s2) {
431 return s1.first.equalsIgnoreAsciiCase(s2.first);
433 if (
const auto nCount = std::min<size_t>(std::distance(aAllResults.begin(), it),
FIND_MAX_GLOS))
435 rLongNames.insert(rLongNames.end(), aAllResults.begin(), aAllResults.begin() +
nCount);
Reference< XExecutableDialog > m_xDialog
weld::Window * GetFrameWeld() const
const OUString & GetAutoTextPath() const
static OUString GetExtension()
OUString GetBlockShortName(size_t nGroup, sal_uInt16 nBlock)
OUString GetGroupName(size_t nPos)
virtual void Invoke() override
virtual ~SwGlossaryList() override
std::vector< std::unique_ptr< AutoTextGroup > > m_aGroupArr
static void FillGroup(AutoTextGroup *pGroup, SwGlossaries *pGloss)
void HasLongName(const std::vector< OUString > &rBeginCandidates, std::vector< std::pair< OUString, sal_uInt16 > > &rLongNames)
OUString GetBlockLongName(size_t nGroup, sal_uInt16 nBlock)
AutoTextGroup * FindGroup(std::u16string_view rGroupName)
OUString GetGroupTitle(size_t nPos)
bool GetShortName(std::u16string_view rLongName, OUString &rShortName, OUString &rGroupName)
sal_uInt16 GetBlockCount(size_t nGroup)
void SetTimeout(sal_uInt64 nTimeoutMs)
virtual void Start(bool bStartTimer=true) override
void append_text(const OUString &rStr)
virtual void select(int pos)=0
virtual int get_selected_index() const=0
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
IMPL_LINK_NOARG(SwGlossDecideDlg, DoubleClickHdl, weld::TreeView &, bool)
const ::utl::TransliterationWrapper & GetAppCmpStrIgnore()
static std::unique_ptr< SwGlossaries > pGlossaries
SW_DLLPUBLIC SwGlossaries * GetGlossaries()
#define LINK(Instance, Class, Member)
SVL_DLLPUBLIC bool GetModifiedDateTimeOfFile(const OUString &rURL, Date *pDate, tools::Time *pTime)
bool UCB_GetFileListOfFolder(const OUString &rURL, std::vector< OUString > &rList, const OUString *pExtension, std::vector< ::DateTime > *pDateTimeList)
double getLength(const B2DPolygon &rCandidate)
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
enumrange< T >::Iterator begin(enumrange< T >)