1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <swuiidxmrk.hxx>
21 #include <hintids.hxx>
23 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
24 #include <comphelper/processfactory.hxx>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/frame/Bibliography.hpp>
28 #include <com/sun/star/i18n/IndexEntrySupplier.hpp>
29 #include <com/sun/star/util/SearchAlgorithms2.hpp>
30 #include <com/sun/star/util/SearchFlags.hpp>
31 #include <com/sun/star/uri/UriReferenceFactory.hpp>
32 #include <rtl/ustrbuf.hxx>
33 #include <i18nutil/searchopt.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/weld.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <svl/itemset.hxx>
40 #include <editeng/langitem.hxx>
41 #include <osl/diagnose.h>
42 #include <o3tl/string_view.hxx>
43 #include <swtypes.hxx>
45 #include <txttxmrk.hxx>
50 #include <swmodule.hxx>
53 #include <strings.hrc>
54 #include <svl/cjkoptions.hxx>
55 #include <sfx2/filedlghelper.hxx>
57 #include <SwRewriter.hxx>
64 static sal_Int32 nTypePos
= 1; // TOX_INDEX as standard
65 static sal_uInt16 nKey1Pos
= USHRT_MAX
;
67 static sal_uInt16 nKey2Pos
= USHRT_MAX
;
69 using namespace com::sun::star
;
70 using namespace com::sun::star::i18n
;
71 using namespace com::sun::star::lang
;
72 using namespace com::sun::star::util
;
73 using namespace ::comphelper
;
77 bool SplitUrlAndPage(const OUString
& rText
, OUString
& rUrl
, int& nPageNumber
)
79 uno::Reference
<uri::XUriReferenceFactory
> xUriReferenceFactory
80 = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
81 uno::Reference
<uri::XUriReference
> xUriRef
;
84 xUriRef
= xUriReferenceFactory
->parse(rText
);
86 catch (const uno::Exception
& rException
)
88 SAL_WARN("sw.ui", "SplitUrlAndPage: failed to parse url: " << rException
.Message
);
92 OUString
aPagePrefix("page=");
93 if (!xUriRef
->getFragment().startsWith(aPagePrefix
))
98 nPageNumber
= o3tl::toInt32(xUriRef
->getFragment().subView(aPagePrefix
.getLength()));
99 xUriRef
->clearFragment();
100 rUrl
= xUriRef
->getUriReference();
104 OUString
MergeUrlAndPage(const OUString
& rUrl
, const std::unique_ptr
<weld::SpinButton
>& xPageSB
)
106 if (!xPageSB
->get_sensitive())
111 uno::Reference
<uri::XUriReferenceFactory
> xUriReferenceFactory
112 = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
113 uno::Reference
<uri::XUriReference
> xUriRef
;
116 xUriRef
= xUriReferenceFactory
->parse(rUrl
);
118 catch (const uno::Exception
& rException
)
120 SAL_WARN("sw.ui", "MergeUrlAndPage: failed to parse url: " << rException
.Message
);
124 OUString
aFragment("page=" + OUString::number(xPageSB
->get_value()));
125 xUriRef
->setFragment(aFragment
);
126 return xUriRef
->getUriReference();
130 // dialog to insert a directory selection
131 SwIndexMarkPane::SwIndexMarkPane(std::shared_ptr
<weld::Dialog
> xDialog
, weld::Builder
& rBuilder
, bool bNewDlg
,
132 SwWrtShell
* pWrtShell
)
133 : m_xDialog(std::move(xDialog
))
135 , m_bNewMark(bNewDlg
)
137 , m_bPhoneticED0_ChangedByUser(false)
138 , m_bPhoneticED1_ChangedByUser(false)
139 , m_bPhoneticED2_ChangedByUser(false)
140 , m_nLangForPhoneticReading(LANGUAGE_CHINESE_SIMPLIFIED
)
141 , m_bIsPhoneticReadingEnabled(false)
143 , m_xTypeFT(rBuilder
.weld_label("typeft"))
144 , m_xTypeDCB(rBuilder
.weld_combo_box("typecb"))
145 , m_xNewBT(rBuilder
.weld_button("new"))
146 , m_xEntryED(rBuilder
.weld_entry("entryed"))
147 , m_xSyncED(rBuilder
.weld_button("sync"))
148 , m_xPhoneticFT0(rBuilder
.weld_label("phonetic0ft"))
149 , m_xPhoneticED0(rBuilder
.weld_entry("phonetic0ed"))
150 , m_xKey1FT(rBuilder
.weld_label("key1ft"))
151 , m_xKey1DCB(rBuilder
.weld_combo_box("key1cb"))
152 , m_xPhoneticFT1(rBuilder
.weld_label("phonetic1ft"))
153 , m_xPhoneticED1(rBuilder
.weld_entry("phonetic1ed"))
154 , m_xKey2FT(rBuilder
.weld_label("key2ft"))
155 , m_xKey2DCB(rBuilder
.weld_combo_box("key2cb"))
156 , m_xPhoneticFT2(rBuilder
.weld_label("phonetic2ft"))
157 , m_xPhoneticED2(rBuilder
.weld_entry("phonetic2ed"))
158 , m_xLevelFT(rBuilder
.weld_label("levelft"))
159 , m_xLevelNF(rBuilder
.weld_spin_button("levelnf"))
160 , m_xMainEntryCB(rBuilder
.weld_check_button("mainentrycb"))
161 , m_xApplyToAllCB(rBuilder
.weld_check_button("applytoallcb"))
162 , m_xSearchCaseSensitiveCB(rBuilder
.weld_check_button("searchcasesensitivecb"))
163 , m_xSearchCaseWordOnlyCB(rBuilder
.weld_check_button("searchcasewordonlycb"))
164 , m_xOKBT(bNewDlg
? rBuilder
.weld_button("insert") : rBuilder
.weld_button("ok"))
165 , m_xCloseBT(rBuilder
.weld_button("close"))
166 , m_xDelBT(rBuilder
.weld_button("delete"))
167 , m_xPrevSameBT(rBuilder
.weld_button("first"))
168 , m_xNextSameBT(rBuilder
.weld_button("last"))
169 , m_xPrevBT(rBuilder
.weld_button("previous"))
170 , m_xNextBT(rBuilder
.weld_button("next"))
171 , m_xForSelectedEntry(rBuilder
.weld_label("selectedentrytitle"))
175 if (SvtCJKOptions::IsCJKFontEnabled())
177 uno::Reference
< uno::XComponentContext
> xContext
= getProcessComponentContext();
179 m_xExtendedIndexEntrySupplier
= i18n::IndexEntrySupplier::create(xContext
);
181 m_xPhoneticFT0
->show();
182 m_xPhoneticED0
->show();
183 m_xPhoneticFT1
->show();
184 m_xPhoneticED1
->show();
185 m_xPhoneticFT2
->show();
186 m_xPhoneticED2
->show();
189 // tdf#129726 there are two help pages for this dialog, one for each mode,
190 // where a widget/dialog appears in both, use -insert/-edit to disambiguate
193 m_xDialog
->set_title(SwResId(STR_IDXMRK_INSERT
));
194 m_xDialog
->set_help_id(m_xDialog
->get_help_id() + "-insert");
195 m_xTypeDCB
->set_help_id(m_xTypeDCB
->get_help_id() + "-insert");
199 m_xDialog
->set_title(SwResId(STR_IDXMRK_EDIT
));
200 m_xDialog
->set_help_id(m_xDialog
->get_help_id() + "-edit");
201 m_xTypeDCB
->set_help_id(m_xTypeDCB
->get_help_id() + "-edit");
204 m_xDelBT
->connect_clicked(LINK(this,SwIndexMarkPane
, DelHdl
));
205 m_xPrevBT
->connect_clicked(LINK(this,SwIndexMarkPane
, PrevHdl
));
206 m_xPrevSameBT
->connect_clicked(LINK(this,SwIndexMarkPane
, PrevSameHdl
));
207 m_xNextBT
->connect_clicked(LINK(this,SwIndexMarkPane
, NextHdl
));
208 m_xNextSameBT
->connect_clicked(LINK(this,SwIndexMarkPane
, NextSameHdl
));
209 m_xTypeDCB
->connect_changed(LINK(this,SwIndexMarkPane
, ModifyListBoxHdl
));
210 m_xKey1DCB
->connect_changed(LINK(this,SwIndexMarkPane
, KeyDCBModifyHdl
));
211 m_xKey2DCB
->connect_changed(LINK(this,SwIndexMarkPane
, KeyDCBModifyHdl
));
212 m_xCloseBT
->connect_clicked(LINK(this,SwIndexMarkPane
, CloseHdl
));
213 m_xEntryED
->connect_changed(LINK(this,SwIndexMarkPane
, ModifyEditHdl
));
214 m_xNewBT
->connect_clicked(LINK(this, SwIndexMarkPane
, NewUserIdxHdl
));
215 m_xApplyToAllCB
->connect_toggled(LINK(this, SwIndexMarkPane
, SearchTypeHdl
));
216 m_xPhoneticED0
->connect_changed(LINK(this,SwIndexMarkPane
, PhoneticEDModifyHdl
));
217 m_xPhoneticED1
->connect_changed(LINK(this,SwIndexMarkPane
, PhoneticEDModifyHdl
));
218 m_xPhoneticED2
->connect_changed(LINK(this,SwIndexMarkPane
, PhoneticEDModifyHdl
));
219 m_xSyncED
->connect_clicked(LINK(this, SwIndexMarkPane
, SyncSelectionHdl
));
226 m_xOKBT
->connect_clicked(LINK(this, SwIndexMarkPane
, InsertHdl
));
228 m_xEntryED
->grab_focus();
231 // Newly initialise controls with the new selection
232 void SwIndexMarkPane::InitControls()
234 assert(m_pSh
&& m_pTOXMgr
&& "no shell?");
236 const SwTOXType
* pType
= m_pTOXMgr
->GetTOXType(TOX_CONTENT
);
237 assert(pType
&& "No directory type !!");
238 OUString sTmpTypeSelection
;
239 if (m_xTypeDCB
->get_active() != -1)
240 sTmpTypeSelection
= m_xTypeDCB
->get_active_text();
242 m_xTypeDCB
->append_text(pType
->GetTypeName());
245 pType
= m_pTOXMgr
->GetTOXType(TOX_INDEX
);
246 assert(pType
&& "No directory type !!");
247 m_xTypeDCB
->append_text(pType
->GetTypeName());
250 sal_uInt16 nCount
= m_pSh
->GetTOXTypeCount(TOX_USER
);
251 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
252 m_xTypeDCB
->append_text(m_pSh
->GetTOXType(TOX_USER
, i
)->GetTypeName());
254 // read keywords primary
256 std::vector
<OUString
> aArr
;
257 m_pSh
->GetTOIKeys(TOI_PRIMARY
, aArr
);
258 std::sort(aArr
.begin(), aArr
.end());
259 auto last
= std::unique(aArr
.begin(), aArr
.end());
260 for (auto it
= aArr
.begin(); it
!= last
; ++it
)
261 m_xKey1DCB
->append_text(*it
);
264 // read keywords secondary
266 std::vector
<OUString
> aArr
;
267 m_pSh
->GetTOIKeys( TOI_SECONDARY
, aArr
);
268 std::sort(aArr
.begin(), aArr
.end());
269 auto last
= std::unique(aArr
.begin(), aArr
.end());
270 for (auto it
= aArr
.begin(); it
!= last
; ++it
)
271 m_xKey2DCB
->append_text(*it
);
274 UpdateLanguageDependenciesForPhoneticReading();
277 const SwTOXMark
* pMark
= m_pTOXMgr
->GetCurTOXMark();
278 if( pMark
&& !m_bNewMark
)
282 // only if there are more than one
283 // if equal it lands at the same entry
284 m_pSh
->SttCursorMove();
286 const SwTOXMark
* pMoveMark
;
289 pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_PRV
);
290 if( pMoveMark
!= pMark
)
292 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_NXT
);
295 m_xPrevBT
->set_sensitive(pMoveMark
!= pMark
);
296 pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_NXT
);
297 if( pMoveMark
!= pMark
)
299 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_PRV
);
302 m_xNextBT
->set_sensitive(pMoveMark
!= pMark
);
310 pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_SAME_PRV
);
311 if( pMoveMark
!= pMark
)
313 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_SAME_NXT
);
316 m_xPrevSameBT
->set_sensitive(pMoveMark
!= pMark
);
317 pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_SAME_NXT
);
318 if( pMoveMark
!= pMark
)
320 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_SAME_PRV
);
323 m_xNextSameBT
->set_sensitive(pMoveMark
!= pMark
);
326 m_xNextSameBT
->show();
327 m_xPrevSameBT
->show();
329 m_pSh
->EndCursorMove();
333 m_xTypeDCB
->set_sensitive(false);
334 m_xTypeFT
->set_sensitive(false);
339 { // display current selection (first element) ????
340 if (m_pSh
->GetCursorCnt() < 2)
342 m_bSelected
= !m_pSh
->HasSelection();
343 m_aOrgStr
= m_pSh
->GetView().GetSelectionTextParam(true, false);
344 m_xEntryED
->set_text(m_aOrgStr
);
346 //to include all equal entries may only be allowed in the body and even there
347 //only when a simple selection exists
348 const FrameTypeFlags nFrameType
= m_pSh
->GetFrameType(nullptr,true);
349 m_xForSelectedEntry
->show();
350 m_xApplyToAllCB
->show();
351 m_xSearchCaseSensitiveCB
->show();
352 m_xSearchCaseWordOnlyCB
->show();
353 m_xApplyToAllCB
->set_sensitive(!m_aOrgStr
.isEmpty() &&
354 !(nFrameType
& ( FrameTypeFlags::HEADER
| FrameTypeFlags::FOOTER
| FrameTypeFlags::FLY_ANY
)));
355 SearchTypeHdl(*m_xApplyToAllCB
);
358 // index type is default
359 if (!sTmpTypeSelection
.isEmpty() && m_xTypeDCB
->find_text(sTmpTypeSelection
) != -1)
360 m_xTypeDCB
->set_active_text(sTmpTypeSelection
);
362 m_xTypeDCB
->set_active_text(m_xTypeDCB
->get_text(nTypePos
));
363 ModifyHdl(*m_xTypeDCB
);
367 void SwIndexMarkPane::UpdateLanguageDependenciesForPhoneticReading()
369 //no phonetic reading if no global cjk support
370 if( !m_xExtendedIndexEntrySupplier
.is() )
372 m_bIsPhoneticReadingEnabled
= false;
375 m_bIsPhoneticReadingEnabled
= true;
377 //get the current language
378 if(!m_bNewMark
) //if dialog is opened to iterate existing marks
380 OSL_ENSURE(m_pTOXMgr
, "need TOXMgr");
383 SwTOXMark
* pMark
= m_pTOXMgr
->GetCurTOXMark();
384 OSL_ENSURE(pMark
, "need current SwTOXMark");
387 SwTextTOXMark
* pTextTOXMark
= pMark
->GetTextTOXMark();
388 OSL_ENSURE(pTextTOXMark
, "need current SwTextTOXMark");
391 const SwTextNode
* pTextNode
= pTextTOXMark
->GetpTextNd();
392 OSL_ENSURE(pTextNode
, "need current SwTextNode");
395 sal_Int32 nTextIndex
= pTextTOXMark
->GetStart();
396 m_nLangForPhoneticReading
= pTextNode
->GetLang( nTextIndex
);
398 else //if dialog is opened to create a new mark
401 switch(m_pSh
->GetScriptType())
403 case SvtScriptType::ASIAN
: nWhich
= RES_CHRATR_CJK_LANGUAGE
; break;
404 case SvtScriptType::COMPLEX
:nWhich
= RES_CHRATR_CTL_LANGUAGE
; break;
405 default:nWhich
= RES_CHRATR_LANGUAGE
; break;
407 SfxItemSet
aLangSet(m_pSh
->GetAttrPool(), nWhich
, nWhich
);
408 m_pSh
->GetCurAttr(aLangSet
);
409 m_nLangForPhoneticReading
= static_cast<const SvxLanguageItem
&>(aLangSet
.Get(nWhich
)).GetLanguage();
414 OUString
SwIndexMarkPane::GetDefaultPhoneticReading( const OUString
& rText
)
416 if( !m_bIsPhoneticReadingEnabled
)
419 return m_xExtendedIndexEntrySupplier
->getPhoneticCandidate(rText
, LanguageTag::convertToLocale( m_nLangForPhoneticReading
));
422 void SwIndexMarkPane::Activate()
424 // display current selection (first element) ????
427 m_xSyncED
->set_sensitive(m_pSh
->GetCursorCnt() < 2);
431 IMPL_LINK_NOARG(SwIndexMarkPane
, SyncSelectionHdl
, weld::Button
&, void)
433 m_bSelected
= !m_pSh
->HasSelection();
434 m_aOrgStr
= m_pSh
->GetView().GetSelectionTextParam(true, false);
435 m_xEntryED
->set_text(m_aOrgStr
);
437 //to include all equal entries may only be allowed in the body and even there
438 //only when a simple selection exists
439 const FrameTypeFlags nFrameType
= m_pSh
->GetFrameType(nullptr,true);
440 m_xApplyToAllCB
->show();
441 m_xSearchCaseSensitiveCB
->show();
442 m_xSearchCaseWordOnlyCB
->show();
443 m_xApplyToAllCB
->set_sensitive(!m_aOrgStr
.isEmpty() &&
444 !(nFrameType
& ( FrameTypeFlags::HEADER
| FrameTypeFlags::FOOTER
| FrameTypeFlags::FLY_ANY
)));
445 SearchTypeHdl(*m_xApplyToAllCB
);
446 ModifyHdl(*m_xEntryED
);
449 // evaluate Ok-Button
450 void SwIndexMarkPane::Apply()
454 m_pSh
->ResetSelect(nullptr, false);
458 void SwIndexMarkPane::InsertUpdate()
460 m_pSh
->StartUndo(m_bDel
? SwUndoId::INDEX_ENTRY_DELETE
: SwUndoId::INDEX_ENTRY_INSERT
);
461 m_pSh
->StartAllAction();
462 SwRewriter aRewriter
;
468 if ( m_pTOXMgr
->GetCurTOXMark())
469 aRewriter
.AddRule(UndoArg1
,
470 m_pTOXMgr
->GetCurTOXMark()->GetText(m_pSh
->GetLayout()));
472 else if( !m_pSh
->HasReadonlySel() )
474 if ( m_pTOXMgr
->GetCurTOXMark())
475 aRewriter
.AddRule(UndoArg1
,
476 m_pTOXMgr
->GetCurTOXMark()->GetText(m_pSh
->GetLayout()));
479 m_pTOXMgr
->DeleteTOXMark();
480 else if( m_pTOXMgr
->GetCurTOXMark() )
484 m_pSh
->EndAllAction();
485 m_pSh
->EndUndo(m_bDel
? SwUndoId::INDEX_ENTRY_DELETE
: SwUndoId::INDEX_ENTRY_INSERT
);
487 nTypePos
= m_xTypeDCB
->find_text(m_xTypeDCB
->get_active_text());
491 nKey1Pos
= m_xKey1DCB
->find_text(m_xKey1DCB
->get_active_text());
492 nKey2Pos
= m_xKey2DCB
->find_text(m_xKey2DCB
->get_active_text());
496 static void lcl_SelectSameStrings(SwWrtShell
& rSh
, bool bWordOnly
, bool bCaseSensitive
)
500 i18nutil::SearchOptions2
aSearchOpt(
501 SearchAlgorithms_ABSOLUTE
,
502 ( bWordOnly
? SearchFlags::NORM_WORD_ONLY
: 0 ),
503 rSh
.GetSelText(), OUString(),
504 GetAppLanguageTag().getLocale(),
507 ? TransliterationFlags::NONE
508 : TransliterationFlags::IGNORE_CASE
),
509 SearchAlgorithms2::ABSOLUTE
,
515 //todo/mba: assuming that notes should not be searched
516 rSh
.Find_Text(aSearchOpt
, false/*bSearchInNotes*/, SwDocPositions::Start
, SwDocPositions::End
, bCancel
,
517 FindRanges::InSelAll
| FindRanges::InBodyOnly
);
520 void SwIndexMarkPane::InsertMark()
522 auto nPos
= m_xTypeDCB
->find_text(m_xTypeDCB
->get_active_text());
523 TOXTypes eType
= nPos
== POS_CONTENT
? TOX_CONTENT
:
524 nPos
== POS_INDEX
? TOX_INDEX
: TOX_USER
;
526 SwTOXMarkDescription
aDesc(eType
);
528 const int nLevel
= m_xLevelNF
->denormalize(m_xLevelNF
->get_value());
531 case POS_CONTENT
: break;
532 case POS_INDEX
: // keyword index mark
535 aDesc
.SetPrimKey(m_xKey1DCB
->get_active_text());
536 aDesc
.SetSecKey(m_xKey2DCB
->get_active_text());
537 aDesc
.SetMainEntry(m_xMainEntryCB
->get_active());
538 aDesc
.SetPhoneticReadingOfAltStr(m_xPhoneticED0
->get_text());
539 aDesc
.SetPhoneticReadingOfPrimKey(m_xPhoneticED1
->get_text());
540 aDesc
.SetPhoneticReadingOfSecKey(m_xPhoneticED2
->get_text());
543 default: // Userdefined index mark
545 aDesc
.SetTOUName(m_xTypeDCB
->get_active_text());
548 if (m_aOrgStr
!= m_xEntryED
->get_text())
549 aDesc
.SetAltStr(m_xEntryED
->get_text());
550 bool bApplyAll
= m_xApplyToAllCB
->get_active();
551 bool bWordOnly
= m_xSearchCaseWordOnlyCB
->get_active();
552 bool bCaseSensitive
= m_xSearchCaseSensitiveCB
->get_active();
554 m_pSh
->StartAllAction();
555 // all equal strings have to be selected here so that the
556 // entry is applied to all equal strings
559 lcl_SelectSameStrings(*m_pSh
, bWordOnly
, bCaseSensitive
);
561 aDesc
.SetLevel(nLevel
);
562 SwTOXMgr
aMgr(m_pSh
);
563 aMgr
.InsertTOXMark(aDesc
);
565 m_pSh
->Pop(SwCursorShell::PopMode::DeleteCurrent
);
567 m_pSh
->EndAllAction();
571 void SwIndexMarkPane::UpdateMark()
573 OUString
aAltText(m_xEntryED
->get_text());
574 OUString
* pAltText
= m_aOrgStr
!= m_xEntryED
->get_text() ? &aAltText
: nullptr;
575 //empty alternative texts are not allowed
576 if(pAltText
&& pAltText
->isEmpty())
581 auto nPos
= m_xTypeDCB
->find_text(m_xTypeDCB
->get_active_text());
582 TOXTypes eType
= TOX_USER
;
583 if(POS_CONTENT
== nPos
)
585 else if(POS_INDEX
== nPos
)
588 SwTOXMarkDescription
aDesc(eType
);
589 aDesc
.SetLevel(m_xLevelNF
->get_value());
591 aDesc
.SetAltStr(*pAltText
);
593 OUString
aPrim(m_xKey1DCB
->get_active_text());
595 aDesc
.SetPrimKey(aPrim
);
596 OUString
aSec(m_xKey2DCB
->get_active_text());
598 aDesc
.SetSecKey(aSec
);
600 if(eType
== TOX_INDEX
)
602 aDesc
.SetPhoneticReadingOfAltStr(m_xPhoneticED0
->get_text());
603 aDesc
.SetPhoneticReadingOfPrimKey(m_xPhoneticED1
->get_text());
604 aDesc
.SetPhoneticReadingOfSecKey(m_xPhoneticED2
->get_text());
606 aDesc
.SetMainEntry(m_xMainEntryCB
->get_visible() && m_xMainEntryCB
->get_active());
607 m_pTOXMgr
->UpdateTOXMark(aDesc
);
611 void SwIndexMarkPane::UpdateKeyBoxes()
613 OUString
aKey(m_xKey1DCB
->get_active_text());
614 auto nPos
= m_xKey1DCB
->find_text(aKey
);
615 if(nPos
== -1 && !aKey
.isEmpty())
617 m_xKey1DCB
->append_text(aKey
);
620 aKey
= m_xKey2DCB
->get_active_text();
621 nPos
= m_xKey2DCB
->find_text(aKey
);
623 if(nPos
== -1 && !aKey
.isEmpty())
625 m_xKey2DCB
->append_text(aKey
);
631 class SwNewUserIdxDlg
: public weld::GenericDialogController
633 SwIndexMarkPane
* m_pDlg
;
635 std::unique_ptr
<weld::Button
> m_xOKPB
;
636 std::unique_ptr
<weld::Entry
> m_xNameED
;
638 DECL_LINK(ModifyHdl
, weld::Entry
&, void);
641 explicit SwNewUserIdxDlg(SwIndexMarkPane
* pPane
, weld::Window
* pParent
)
642 : GenericDialogController(pParent
, "modules/swriter/ui/newuserindexdialog.ui", "NewUserIndexDialog")
644 , m_xOKPB(m_xBuilder
->weld_button("ok"))
645 , m_xNameED(m_xBuilder
->weld_entry("entry"))
647 m_xNameED
->connect_changed(LINK(this, SwNewUserIdxDlg
, ModifyHdl
));
648 m_xOKPB
->set_sensitive(false);
649 m_xNameED
->grab_focus();
651 OUString
GetName() const { return m_xNameED
->get_text(); }
656 IMPL_LINK( SwNewUserIdxDlg
, ModifyHdl
, weld::Entry
&, rEdit
, void)
658 m_xOKPB
->set_sensitive(!rEdit
.get_text().isEmpty() && !m_pDlg
->IsTOXType(rEdit
.get_text()));
661 IMPL_LINK_NOARG(SwIndexMarkPane
, NewUserIdxHdl
, weld::Button
&, void)
663 SwNewUserIdxDlg
aDlg(this, m_xDialog
.get());
664 if (aDlg
.run() == RET_OK
)
666 OUString
sNewName(aDlg
.GetName());
667 m_xTypeDCB
->append_text(sNewName
);
668 m_xTypeDCB
->set_active_text(sNewName
);
672 IMPL_LINK( SwIndexMarkPane
, SearchTypeHdl
, weld::Toggleable
&, rBox
, void)
674 const bool bEnable
= rBox
.get_active() && rBox
.get_sensitive();
675 m_xSearchCaseWordOnlyCB
->set_sensitive(bEnable
);
676 m_xSearchCaseSensitiveCB
->set_sensitive(bEnable
);
679 IMPL_LINK(SwIndexMarkPane
, InsertHdl
, weld::Button
&, rButton
, void)
682 //close the dialog if only one entry is available
683 if(!m_bNewMark
&& !m_xPrevBT
->get_visible() && !m_xNextBT
->get_visible())
687 IMPL_LINK_NOARG(SwIndexMarkPane
, CloseHdl
, weld::Button
&, void)
691 if (SfxViewFrame
* pViewFrm
= SfxViewFrame::Current())
693 pViewFrm
->GetDispatcher()->Execute(FN_INSERT_IDX_ENTRY_DLG
,
694 SfxCallMode::ASYNCHRON
|SfxCallMode::RECORD
);
699 m_xDialog
->response(RET_CLOSE
);
703 // select index type only when inserting
704 IMPL_LINK(SwIndexMarkPane
, ModifyListBoxHdl
, weld::ComboBox
&, rBox
, void)
709 IMPL_LINK(SwIndexMarkPane
, ModifyEditHdl
, weld::Entry
&, rEdit
, void)
714 void SwIndexMarkPane::ModifyHdl(const weld::Widget
& rBox
)
716 if (m_xTypeDCB
.get() == &rBox
)
719 auto nPos
= m_xTypeDCB
->find_text(m_xTypeDCB
->get_active_text());
720 bool bLevelEnable
= false,
724 bEntryHasText
= false,
725 bKey1HasText
= false,
726 bKey2HasText
= false;
727 if(nPos
== POS_INDEX
)
729 if (!m_xEntryED
->get_text().isEmpty())
730 bEntryHasText
= true;
731 m_xPhoneticED0
->set_text(GetDefaultPhoneticReading(m_xEntryED
->get_text()));
734 m_xKey1DCB
->set_active_text(m_xKey1DCB
->get_text(nKey1Pos
));
735 m_xPhoneticED1
->set_text(GetDefaultPhoneticReading(m_xKey1DCB
->get_active_text()));
736 if (!m_xKey1DCB
->get_active_text().isEmpty())
738 bKey1HasText
= bSetKey2
= bKey2Enable
= true;
739 m_xKey2DCB
->set_active_text(m_xKey2DCB
->get_text(nKey2Pos
));
740 m_xPhoneticED2
->set_text(GetDefaultPhoneticReading(m_xKey2DCB
->get_active_text()));
741 if(!m_xKey2DCB
->get_active_text().isEmpty())
748 m_xLevelNF
->set_max(MAXLEVEL
);
749 m_xLevelNF
->set_value(m_xLevelNF
->normalize(0));
752 m_xLevelFT
->set_visible(bLevelEnable
);
753 m_xLevelNF
->set_visible(bLevelEnable
);
754 m_xMainEntryCB
->set_visible(nPos
== POS_INDEX
);
756 m_xKey1FT
->set_sensitive(bKeyEnable
);
757 m_xKey1DCB
->set_sensitive(bKeyEnable
);
760 m_xKey2DCB
->set_sensitive(bKey2Enable
);
761 m_xKey2FT
->set_sensitive(bKey2Enable
);
763 m_xPhoneticFT0
->set_sensitive(bKeyEnable
&&bEntryHasText
&&m_bIsPhoneticReadingEnabled
);
764 m_xPhoneticED0
->set_sensitive(bKeyEnable
&&bEntryHasText
&&m_bIsPhoneticReadingEnabled
);
765 m_xPhoneticFT1
->set_sensitive(bKeyEnable
&&bKey1HasText
&&m_bIsPhoneticReadingEnabled
);
766 m_xPhoneticED1
->set_sensitive(bKeyEnable
&&bKey1HasText
&&m_bIsPhoneticReadingEnabled
);
767 m_xPhoneticFT2
->set_sensitive(bKeyEnable
&&bKey2HasText
&&m_bIsPhoneticReadingEnabled
);
768 m_xPhoneticED2
->set_sensitive(bKeyEnable
&&bKey2HasText
&&m_bIsPhoneticReadingEnabled
);
770 else //m_xEntryED !!m_xEntryED is not a ListBox but an Edit
772 bool bHasText
= !m_xEntryED
->get_text().isEmpty();
775 m_xPhoneticED0
->set_text(OUString());
776 m_bPhoneticED0_ChangedByUser
= false;
778 else if(!m_bPhoneticED0_ChangedByUser
)
779 m_xPhoneticED0
->set_text(GetDefaultPhoneticReading(m_xEntryED
->get_text()));
781 m_xPhoneticFT0
->set_sensitive(bHasText
&&m_bIsPhoneticReadingEnabled
);
782 m_xPhoneticED0
->set_sensitive(bHasText
&&m_bIsPhoneticReadingEnabled
);
784 m_xOKBT
->set_sensitive(!m_pSh
->HasReadonlySel() &&
785 (!m_xEntryED
->get_text().isEmpty() || m_pSh
->GetCursorCnt(false)));
788 IMPL_LINK_NOARG(SwIndexMarkPane
, NextHdl
, weld::Button
&, void)
791 m_pTOXMgr
->NextTOXMark();
795 IMPL_LINK_NOARG(SwIndexMarkPane
, NextSameHdl
, weld::Button
&, void)
798 m_pTOXMgr
->NextTOXMark(true);
802 IMPL_LINK_NOARG(SwIndexMarkPane
, PrevHdl
, weld::Button
&, void)
805 m_pTOXMgr
->PrevTOXMark();
809 IMPL_LINK_NOARG(SwIndexMarkPane
, PrevSameHdl
, weld::Button
&, void)
812 m_pTOXMgr
->PrevTOXMark(true);
816 IMPL_LINK_NOARG(SwIndexMarkPane
, DelHdl
, weld::Button
&, void)
822 if(m_pTOXMgr
->GetCurTOXMark())
826 CloseHdl(*m_xCloseBT
);
827 if (SfxViewFrame
* pViewFrm
= SfxViewFrame::Current())
828 pViewFrm
->GetBindings().Invalidate(FN_EDIT_IDX_ENTRY_DLG
);
833 void SwIndexMarkPane::UpdateDialog()
835 OSL_ENSURE(m_pSh
&& m_pTOXMgr
, "no shell?");
836 SwTOXMark
* pMark
= m_pTOXMgr
->GetCurTOXMark();
837 OSL_ENSURE(pMark
, "no current marker");
841 SwViewShell::SetCareDialog(m_xDialog
);
843 m_aOrgStr
= pMark
->GetText(m_pSh
->GetLayout());
844 m_xEntryED
->set_text(m_aOrgStr
);
847 bool bLevelEnable
= true,
850 bEntryHasText
= false,
851 bKey1HasText
= false,
852 bKey2HasText
= false;
854 TOXTypes eCurType
= pMark
->GetTOXType()->GetType();
855 if(TOX_INDEX
== eCurType
)
857 bLevelEnable
= false;
859 bKey1HasText
= bKey2Enable
= !pMark
->GetPrimaryKey().isEmpty();
860 bKey2HasText
= !pMark
->GetSecondaryKey().isEmpty();
861 bEntryHasText
= !pMark
->GetText(m_pSh
->GetLayout()).isEmpty();
862 m_xKey1DCB
->set_entry_text( pMark
->GetPrimaryKey() );
863 m_xKey2DCB
->set_entry_text( pMark
->GetSecondaryKey() );
864 m_xPhoneticED0
->set_text( pMark
->GetTextReading() );
865 m_xPhoneticED1
->set_text( pMark
->GetPrimaryKeyReading() );
866 m_xPhoneticED2
->set_text( pMark
->GetSecondaryKeyReading() );
867 m_xMainEntryCB
->set_active(pMark
->IsMainEntry());
869 else if(TOX_CONTENT
== eCurType
|| TOX_USER
== eCurType
)
871 m_xLevelNF
->set_value(m_xLevelNF
->normalize(pMark
->GetLevel()));
873 m_xKey1FT
->set_sensitive(bKeyEnable
);
874 m_xKey1DCB
->set_sensitive(bKeyEnable
);
875 m_xLevelNF
->set_max(MAXLEVEL
);
876 m_xLevelFT
->set_visible(bLevelEnable
);
877 m_xLevelNF
->set_visible(bLevelEnable
);
878 m_xMainEntryCB
->set_visible(!bLevelEnable
);
879 m_xKey2FT
->set_sensitive(bKey2Enable
);
880 m_xKey2DCB
->set_sensitive(bKey2Enable
);
882 UpdateLanguageDependenciesForPhoneticReading();
883 m_xPhoneticFT0
->set_sensitive(bKeyEnable
&&bEntryHasText
&&m_bIsPhoneticReadingEnabled
);
884 m_xPhoneticED0
->set_sensitive(bKeyEnable
&&bEntryHasText
&&m_bIsPhoneticReadingEnabled
);
885 m_xPhoneticFT1
->set_sensitive(bKeyEnable
&&bKey1HasText
&&m_bIsPhoneticReadingEnabled
);
886 m_xPhoneticED1
->set_sensitive(bKeyEnable
&&bKey1HasText
&&m_bIsPhoneticReadingEnabled
);
887 m_xPhoneticFT2
->set_sensitive(bKeyEnable
&&bKey2HasText
&&m_bIsPhoneticReadingEnabled
);
888 m_xPhoneticED2
->set_sensitive(bKeyEnable
&&bKey2HasText
&&m_bIsPhoneticReadingEnabled
);
891 m_xTypeDCB
->set_active_text(pMark
->GetTOXType()->GetTypeName());
893 // set Next - Prev - Buttons
894 m_pSh
->SttCursorMove();
895 if( m_xPrevBT
->get_visible() )
897 const SwTOXMark
* pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_PRV
);
898 if( pMoveMark
!= pMark
)
899 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_NXT
);
900 m_xPrevBT
->set_sensitive( pMoveMark
!= pMark
);
901 pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_NXT
);
902 if( pMoveMark
!= pMark
)
903 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_PRV
);
904 m_xNextBT
->set_sensitive( pMoveMark
!= pMark
);
907 if (m_xPrevSameBT
->get_visible())
909 const SwTOXMark
* pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_SAME_PRV
);
910 if( pMoveMark
!= pMark
)
911 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_SAME_NXT
);
912 m_xPrevSameBT
->set_sensitive( pMoveMark
!= pMark
);
913 pMoveMark
= &m_pSh
->GotoTOXMark( *pMark
, TOX_SAME_NXT
);
914 if( pMoveMark
!= pMark
)
915 m_pSh
->GotoTOXMark( *pMoveMark
, TOX_SAME_PRV
);
916 m_xNextSameBT
->set_sensitive( pMoveMark
!= pMark
);
919 const bool bEnable
= !m_pSh
->HasReadonlySel();
920 m_xOKBT
->set_sensitive(bEnable
);
921 m_xDelBT
->set_sensitive(bEnable
);
922 m_xEntryED
->set_sensitive(bEnable
);
923 m_xLevelNF
->set_sensitive(bEnable
);
924 m_xKey1DCB
->set_sensitive(bEnable
);
925 m_xKey2DCB
->set_sensitive(bEnable
);
927 m_pSh
->SelectTextAttr( RES_TXTATR_TOXMARK
, pMark
->GetTextTOXMark() );
928 // we need the point at the start of the attribute
931 m_pSh
->EndCursorMove();
934 // Remind whether the edit boxes for Phonetic reading are changed manually
935 IMPL_LINK(SwIndexMarkPane
, PhoneticEDModifyHdl
, weld::Entry
&, rEdit
, void)
937 if (m_xPhoneticED0
.get() == &rEdit
)
939 m_bPhoneticED0_ChangedByUser
= !rEdit
.get_text().isEmpty();
941 else if (m_xPhoneticED1
.get() == &rEdit
)
943 m_bPhoneticED1_ChangedByUser
= !rEdit
.get_text().isEmpty();
945 else if (m_xPhoneticED2
.get() == &rEdit
)
947 m_bPhoneticED2_ChangedByUser
= !rEdit
.get_text().isEmpty();
951 // Enable Disable of the 2nd key
952 IMPL_LINK( SwIndexMarkPane
, KeyDCBModifyHdl
, weld::ComboBox
&, rBox
, void )
954 if (m_xKey1DCB
.get() == &rBox
)
956 bool bEnable
= !rBox
.get_active_text().isEmpty();
959 m_xKey2DCB
->set_entry_text(OUString());
960 m_xPhoneticED1
->set_text(OUString());
961 m_xPhoneticED2
->set_text(OUString());
962 m_bPhoneticED1_ChangedByUser
= false;
963 m_bPhoneticED2_ChangedByUser
= false;
967 if (rBox
.get_popup_shown())
969 //reset bPhoneticED1_ChangedByUser if a completely new string is selected
970 m_bPhoneticED1_ChangedByUser
= false;
972 if (!m_bPhoneticED1_ChangedByUser
)
973 m_xPhoneticED1
->set_text(GetDefaultPhoneticReading(rBox
.get_active_text()));
975 m_xKey2DCB
->set_sensitive(bEnable
);
976 m_xKey2FT
->set_sensitive(bEnable
);
978 else if (m_xKey2DCB
.get() == &rBox
)
980 if (rBox
.get_active_text().isEmpty())
982 m_xPhoneticED2
->set_text(OUString());
983 m_bPhoneticED2_ChangedByUser
= false;
987 if (rBox
.get_popup_shown())
989 //reset bPhoneticED1_ChangedByUser if a completely new string is selected
990 m_bPhoneticED2_ChangedByUser
= false;
992 if(!m_bPhoneticED2_ChangedByUser
)
993 m_xPhoneticED2
->set_text(GetDefaultPhoneticReading(rBox
.get_active_text()));
997 bool bKey1HasText
= !m_xKey1DCB
->get_active_text().isEmpty();
998 bool bKey2HasText
= !m_xKey2DCB
->get_active_text().isEmpty();
1000 m_xPhoneticFT1
->set_sensitive(bKey1HasText
&& m_bIsPhoneticReadingEnabled
);
1001 m_xPhoneticED1
->set_sensitive(bKey1HasText
&& m_bIsPhoneticReadingEnabled
);
1002 m_xPhoneticFT2
->set_sensitive(bKey2HasText
&& m_bIsPhoneticReadingEnabled
);
1003 m_xPhoneticED2
->set_sensitive(bKey2HasText
&& m_bIsPhoneticReadingEnabled
);
1006 SwIndexMarkPane::~SwIndexMarkPane()
1010 void SwIndexMarkPane::ReInitDlg(SwWrtShell
& rWrtShell
, SwTOXMark
const * pCurTOXMark
)
1013 m_pTOXMgr
.reset( new SwTOXMgr(m_pSh
) );
1016 for(sal_uInt16 i
= 0; i
< m_pTOXMgr
->GetTOXMarkCount(); i
++)
1017 if(m_pTOXMgr
->GetTOXMark(i
) == pCurTOXMark
)
1019 m_pTOXMgr
->SetCurTOXMark(i
);
1026 SwIndexMarkFloatDlg::SwIndexMarkFloatDlg(SfxBindings
* _pBindings
,
1027 SfxChildWindow
* pChild
, weld::Window
*pParent
,
1028 SfxChildWinInfo
const * pInfo
, bool bNew
)
1029 : SfxModelessDialogController(_pBindings
, pChild
, pParent
,
1030 "modules/swriter/ui/indexentry.ui", "IndexEntryDialog")
1031 , m_aContent(m_xDialog
, *m_xBuilder
, bNew
, ::GetActiveWrtShell())
1033 if (SwWrtShell
* pWrtShell
= ::GetActiveWrtShell())
1034 m_aContent
.ReInitDlg(*pWrtShell
);
1038 void SwIndexMarkFloatDlg::Activate()
1040 SfxModelessDialogController::Activate();
1041 m_aContent
.Activate();
1044 void SwIndexMarkFloatDlg::ReInitDlg(SwWrtShell
& rWrtShell
)
1046 m_aContent
.ReInitDlg( rWrtShell
);
1049 SwIndexMarkModalDlg::SwIndexMarkModalDlg(weld::Window
*pParent
, SwWrtShell
& rSh
, SwTOXMark
const * pCurTOXMark
)
1050 : SfxDialogController(pParent
, "modules/swriter/ui/indexentry.ui",
1052 , m_aContent(m_xDialog
, *m_xBuilder
, false, &rSh
)
1054 m_aContent
.ReInitDlg(rSh
, pCurTOXMark
);
1057 SwIndexMarkModalDlg::~SwIndexMarkModalDlg()
1059 SwViewShell::SetCareDialog(nullptr);
1062 short SwIndexMarkModalDlg::run()
1064 short nRet
= SfxDialogController::run();
1072 class SwCreateAuthEntryDlg_Impl
: public weld::GenericDialogController
1074 std::vector
<std::unique_ptr
<weld::Builder
>> m_aBuilders
;
1076 Link
<weld::Entry
&,bool> m_aShortNameCheckLink
;
1078 SwWrtShell
& m_rWrtSh
;
1080 bool m_bNewEntryMode
;
1081 bool m_bNameAllowed
;
1083 std::vector
<std::unique_ptr
<weld::Container
>> m_aOrigContainers
;
1084 std::vector
<std::unique_ptr
<weld::Label
>> m_aFixedTexts
;
1085 std::unique_ptr
<weld::Box
> m_pBoxes
[AUTH_FIELD_END
];
1086 std::unique_ptr
<weld::Entry
> m_pEdits
[AUTH_FIELD_END
];
1087 std::unique_ptr
<weld::Button
> m_xOKBT
;
1088 std::unique_ptr
<weld::Container
> m_xBox
;
1089 std::unique_ptr
<weld::Container
> m_xLeft
;
1090 std::unique_ptr
<weld::Container
> m_xRight
;
1091 std::unique_ptr
<weld::ComboBox
> m_xTypeListBox
;
1092 std::unique_ptr
<weld::ComboBox
> m_xIdentifierBox
;
1093 std::unique_ptr
<weld::Button
> m_xLocalBrowseButton
;
1094 std::unique_ptr
<weld::CheckButton
> m_xLocalPageCB
;
1095 std::unique_ptr
<weld::SpinButton
> m_xLocalPageSB
;
1096 std::unique_ptr
<weld::ComboBox
> m_xTargetTypeListBox
;
1097 weld::Entry
* m_pTargetURLField
;
1099 DECL_LINK(IdentifierHdl
, weld::ComboBox
&, void);
1100 DECL_LINK(ShortNameHdl
, weld::Entry
&, void);
1101 DECL_LINK(EnableHdl
, weld::ComboBox
&, void);
1102 DECL_LINK(BrowseHdl
, weld::Button
&, void);
1103 DECL_LINK(PageNumHdl
, weld::Toggleable
&, void);
1104 DECL_LINK(TargetTypeHdl
, weld::ComboBox
&, void);
1107 SwCreateAuthEntryDlg_Impl(weld::Window
* pParent
,
1108 const OUString pFields
[],
1113 OUString
GetEntryText(ToxAuthorityField eField
) const;
1115 void SetCheckNameHdl(const Link
<weld::Entry
&,bool>& rLink
) {m_aShortNameCheckLink
= rLink
;}
1121 ToxAuthorityField nToxField
;
1122 const OUString pHelpId
;
1127 const TextInfo aTextInfoArr
[] =
1129 {AUTH_FIELD_IDENTIFIER
, HID_AUTH_FIELD_IDENTIFIER
},
1130 {AUTH_FIELD_AUTHORITY_TYPE
, HID_AUTH_FIELD_AUTHORITY_TYPE
},
1131 {AUTH_FIELD_AUTHOR
, HID_AUTH_FIELD_AUTHOR
},
1132 {AUTH_FIELD_TITLE
, HID_AUTH_FIELD_TITLE
},
1133 {AUTH_FIELD_YEAR
, HID_AUTH_FIELD_YEAR
},
1134 {AUTH_FIELD_PUBLISHER
, HID_AUTH_FIELD_PUBLISHER
},
1135 {AUTH_FIELD_ADDRESS
, HID_AUTH_FIELD_ADDRESS
},
1136 {AUTH_FIELD_ISBN
, HID_AUTH_FIELD_ISBN
},
1137 {AUTH_FIELD_CHAPTER
, HID_AUTH_FIELD_CHAPTER
},
1138 {AUTH_FIELD_PAGES
, HID_AUTH_FIELD_PAGES
},
1139 {AUTH_FIELD_EDITOR
, HID_AUTH_FIELD_EDITOR
},
1140 {AUTH_FIELD_EDITION
, HID_AUTH_FIELD_EDITION
},
1141 {AUTH_FIELD_BOOKTITLE
, HID_AUTH_FIELD_BOOKTITLE
},
1142 {AUTH_FIELD_VOLUME
, HID_AUTH_FIELD_VOLUME
},
1143 {AUTH_FIELD_HOWPUBLISHED
, HID_AUTH_FIELD_HOWPUBLISHED
},
1144 {AUTH_FIELD_ORGANIZATIONS
, HID_AUTH_FIELD_ORGANIZATIONS
},
1145 {AUTH_FIELD_INSTITUTION
, HID_AUTH_FIELD_INSTITUTION
},
1146 {AUTH_FIELD_SCHOOL
, HID_AUTH_FIELD_SCHOOL
},
1147 {AUTH_FIELD_REPORT_TYPE
, HID_AUTH_FIELD_REPORT_TYPE
},
1148 {AUTH_FIELD_MONTH
, HID_AUTH_FIELD_MONTH
},
1149 {AUTH_FIELD_JOURNAL
, HID_AUTH_FIELD_JOURNAL
},
1150 {AUTH_FIELD_NUMBER
, HID_AUTH_FIELD_NUMBER
},
1151 {AUTH_FIELD_SERIES
, HID_AUTH_FIELD_SERIES
},
1152 {AUTH_FIELD_ANNOTE
, HID_AUTH_FIELD_ANNOTE
},
1153 {AUTH_FIELD_NOTE
, HID_AUTH_FIELD_NOTE
},
1154 {AUTH_FIELD_URL
, HID_AUTH_FIELD_URL
},
1155 {AUTH_FIELD_TARGET_TYPE
, HID_AUTH_FIELD_TARGET_TYPE
},
1156 {AUTH_FIELD_TARGET_URL
, HID_AUTH_FIELD_TARGET_URL
},
1157 {AUTH_FIELD_LOCAL_URL
, HID_AUTH_FIELD_LOCAL_URL
},
1158 {AUTH_FIELD_CUSTOM1
, HID_AUTH_FIELD_CUSTOM1
},
1159 {AUTH_FIELD_CUSTOM2
, HID_AUTH_FIELD_CUSTOM2
},
1160 {AUTH_FIELD_CUSTOM3
, HID_AUTH_FIELD_CUSTOM3
},
1161 {AUTH_FIELD_CUSTOM4
, HID_AUTH_FIELD_CUSTOM4
},
1162 {AUTH_FIELD_CUSTOM5
, HID_AUTH_FIELD_CUSTOM5
}
1165 static OUString
lcl_FindColumnEntry(const uno::Sequence
<beans::PropertyValue
>& rFields
, std::u16string_view rColumnTitle
)
1167 for(const auto& rField
: rFields
)
1170 if(rField
.Name
== rColumnTitle
&&
1171 (rField
.Value
>>= sRet
))
1179 bool SwAuthorMarkPane::s_bIsFromComponent
= true;
1181 SwAuthorMarkPane::SwAuthorMarkPane(weld::DialogController
&rDialog
, weld::Builder
& rBuilder
, bool bNewDlg
)
1182 : m_rDialog(rDialog
)
1183 , m_bNewEntry(bNewDlg
)
1184 , m_bBibAccessInitialized(false)
1186 , m_xFromComponentRB(rBuilder
.weld_radio_button("frombibliography"))
1187 , m_xFromDocContentRB(rBuilder
.weld_radio_button("fromdocument"))
1188 , m_xAuthorFI(rBuilder
.weld_label("author"))
1189 , m_xTitleFI(rBuilder
.weld_label("title"))
1190 , m_xEntryED(rBuilder
.weld_entry("entryed"))
1191 , m_xEntryLB(rBuilder
.weld_combo_box("entrylb"))
1192 , m_xActionBT(rBuilder
.weld_button(m_bNewEntry
? OUString("insert") : OUString("modify")))
1193 , m_xCloseBT(rBuilder
.weld_button("close"))
1194 , m_xCreateEntryPB(rBuilder
.weld_button("new"))
1195 , m_xEditEntryPB(rBuilder
.weld_button("edit"))
1197 m_xActionBT
->show();
1198 m_xFromComponentRB
->set_visible(m_bNewEntry
);
1199 m_xFromDocContentRB
->set_visible(m_bNewEntry
);
1200 m_xFromComponentRB
->set_active(s_bIsFromComponent
);
1201 m_xFromDocContentRB
->set_active(!s_bIsFromComponent
);
1203 m_xActionBT
->connect_clicked(LINK(this,SwAuthorMarkPane
, InsertHdl
));
1204 m_xCloseBT
->connect_clicked(LINK(this,SwAuthorMarkPane
, CloseHdl
));
1205 m_xCreateEntryPB
->connect_clicked(LINK(this,SwAuthorMarkPane
, CreateEntryHdl
));
1206 m_xEditEntryPB
->connect_clicked(LINK(this,SwAuthorMarkPane
, CreateEntryHdl
));
1207 m_xFromComponentRB
->connect_toggled(LINK(this,SwAuthorMarkPane
, ChangeSourceHdl
));
1208 m_xFromDocContentRB
->connect_toggled(LINK(this,SwAuthorMarkPane
, ChangeSourceHdl
));
1209 m_xEntryED
->connect_changed(LINK(this,SwAuthorMarkPane
, EditModifyHdl
));
1211 m_rDialog
.set_title(SwResId(
1212 m_bNewEntry
? STR_AUTHMRK_INSERT
: STR_AUTHMRK_EDIT
));
1214 m_xEntryED
->set_visible(!m_bNewEntry
);
1215 m_xEntryLB
->set_visible(m_bNewEntry
);
1216 // tdf#90641 - sort bibliography entries by identifier
1217 m_xEntryLB
->make_sorted();
1220 m_xEntryLB
->connect_changed(LINK(this, SwAuthorMarkPane
, CompEntryHdl
));
1224 void SwAuthorMarkPane::ReInitDlg(SwWrtShell
& rWrtShell
)
1230 IMPL_LINK_NOARG(SwAuthorMarkPane
, CloseHdl
, weld::Button
&, void)
1234 if (SfxViewFrame
* pViewFrm
= SfxViewFrame::Current())
1236 pViewFrm
->GetDispatcher()->Execute(FN_INSERT_AUTH_ENTRY_DLG
,
1237 SfxCallMode::ASYNCHRON
|SfxCallMode::RECORD
);
1242 m_rDialog
.response(RET_CANCEL
);
1246 IMPL_LINK( SwAuthorMarkPane
, CompEntryHdl
, weld::ComboBox
&, rBox
, void)
1248 const OUString
sEntry(rBox
.get_active_text());
1249 if(s_bIsFromComponent
)
1251 if(m_xBibAccess
.is() && !sEntry
.isEmpty())
1253 if(m_xBibAccess
->hasByName(sEntry
))
1255 uno::Any
aEntry(m_xBibAccess
->getByName(sEntry
));
1256 uno::Sequence
<beans::PropertyValue
> aFieldProps
;
1257 if(aEntry
>>= aFieldProps
)
1259 auto nSize
= std::min(static_cast<sal_Int32
>(AUTH_FIELD_END
), aFieldProps
.getLength());
1260 for(sal_Int32 i
= 0; i
< nSize
; i
++)
1262 m_sFields
[i
] = lcl_FindColumnEntry(aFieldProps
, m_sColumnTitles
[i
]);
1270 if(!sEntry
.isEmpty())
1272 const SwAuthorityFieldType
* pFType
= static_cast<const SwAuthorityFieldType
*>(
1273 m_pSh
->GetFieldType(SwFieldIds::TableOfAuthorities
, OUString()));
1274 const SwAuthEntry
* pEntry
= pFType
? pFType
->GetEntryByIdentifier(sEntry
) : nullptr;
1275 for(int i
= 0; i
< AUTH_FIELD_END
; i
++)
1276 m_sFields
[i
] = pEntry
?
1277 pEntry
->GetAuthorField(static_cast<ToxAuthorityField
>(i
)) : OUString();
1280 if (rBox
.get_active_text().isEmpty())
1282 for(OUString
& s
: m_sFields
)
1285 m_xAuthorFI
->set_label(m_sFields
[AUTH_FIELD_AUTHOR
]);
1286 m_xTitleFI
->set_label(m_sFields
[AUTH_FIELD_TITLE
]);
1289 IMPL_LINK_NOARG(SwAuthorMarkPane
, InsertHdl
, weld::Button
&, void)
1291 //insert or update the SwAuthorityField...
1294 bool bDifferent
= false;
1295 OSL_ENSURE(!m_sFields
[AUTH_FIELD_IDENTIFIER
].isEmpty() , "No Id is set!");
1296 OSL_ENSURE(!m_sFields
[AUTH_FIELD_AUTHORITY_TYPE
].isEmpty() , "No authority type is set!");
1297 //check if the entry already exists with different content
1298 const SwAuthorityFieldType
* pFType
= static_cast<const SwAuthorityFieldType
*>(
1299 m_pSh
->GetFieldType(SwFieldIds::TableOfAuthorities
, OUString()));
1300 const SwAuthEntry
* pEntry
= pFType
?
1301 pFType
->GetEntryByIdentifier( m_sFields
[AUTH_FIELD_IDENTIFIER
])
1305 for(int i
= 0; i
< AUTH_FIELD_END
&& !bDifferent
; i
++)
1306 bDifferent
|= m_sFields
[i
] != pEntry
->GetAuthorField(static_cast<ToxAuthorityField
>(i
));
1309 std::unique_ptr
<weld::MessageDialog
> xQuery(Application::CreateMessageDialog(m_rDialog
.getDialog(),
1310 VclMessageType::Question
, VclButtonsType::YesNo
,
1311 SwResId(STR_QUERY_CHANGE_AUTH_ENTRY
)));
1312 if (RET_YES
!= xQuery
->run())
1317 SwFieldMgr
aMgr(m_pSh
);
1318 OUStringBuffer sFields
;
1319 for(OUString
& s
: m_sFields
)
1321 sFields
.append(s
+ OUStringChar(TOX_STYLE_DELIMITER
));
1327 rtl::Reference
<SwAuthEntry
> xNewData(new SwAuthEntry
);
1328 for(int i
= 0; i
< AUTH_FIELD_END
; i
++)
1329 xNewData
->SetAuthorField(static_cast<ToxAuthorityField
>(i
), m_sFields
[i
]);
1330 m_pSh
->ChangeAuthorityData(xNewData
.get());
1332 SwInsertField_Data
aData(SwFieldTypesEnum::Authority
, 0, sFields
.makeStringAndClear(), OUString(), 0 );
1333 aMgr
.InsertField( aData
);
1335 else if(aMgr
.GetCurField())
1337 aMgr
.UpdateCurField(0, sFields
.makeStringAndClear(), OUString());
1341 CloseHdl(*m_xCloseBT
);
1344 IMPL_LINK(SwAuthorMarkPane
, CreateEntryHdl
, weld::Button
&, rButton
, void)
1346 bool bCreate
= &rButton
== m_xCreateEntryPB
.get();
1347 OUString sOldId
= m_sCreatedEntry
[0];
1348 for(int i
= 0; i
< AUTH_FIELD_END
; i
++)
1349 m_sCreatedEntry
[i
] = bCreate
? OUString() : m_sFields
[i
];
1350 SwCreateAuthEntryDlg_Impl
aDlg(m_rDialog
.getDialog(),
1351 bCreate
? m_sCreatedEntry
: m_sFields
,
1352 *m_pSh
, m_bNewEntry
, bCreate
);
1355 aDlg
.SetCheckNameHdl(LINK(this, SwAuthorMarkPane
, IsEntryAllowedHdl
));
1357 if(RET_OK
!= aDlg
.run())
1360 if(bCreate
&& !sOldId
.isEmpty())
1362 m_xEntryLB
->remove_text(sOldId
);
1364 for(int i
= 0; i
< AUTH_FIELD_END
; i
++)
1366 m_sFields
[i
] = aDlg
.GetEntryText(static_cast<ToxAuthorityField
>(i
));
1367 m_sCreatedEntry
[i
] = m_sFields
[i
];
1369 if(m_bNewEntry
&& !m_xFromDocContentRB
->get_active())
1371 m_xFromDocContentRB
->set_active(true);
1372 ChangeSourceHdl(*m_xFromDocContentRB
);
1376 OSL_ENSURE(m_xEntryLB
->find_text(m_sFields
[AUTH_FIELD_IDENTIFIER
]) == -1,
1378 m_xEntryLB
->append_text(m_sFields
[AUTH_FIELD_IDENTIFIER
]);
1379 m_xEntryLB
->set_active_text(m_sFields
[AUTH_FIELD_IDENTIFIER
]);
1381 m_xEntryED
->set_text(m_sFields
[AUTH_FIELD_IDENTIFIER
]);
1382 m_xAuthorFI
->set_label(m_sFields
[AUTH_FIELD_AUTHOR
]);
1383 m_xTitleFI
->set_label(m_sFields
[AUTH_FIELD_TITLE
]);
1384 m_xActionBT
->set_sensitive(true);
1388 // When in edit mode, automatically apply the changed entry to update the field in the doc
1390 InsertHdl(*m_xActionBT
);
1394 IMPL_LINK_NOARG(SwAuthorMarkPane
, ChangeSourceHdl
, weld::Toggleable
&, void)
1396 bool bFromComp
= m_xFromComponentRB
->get_active();
1397 s_bIsFromComponent
= bFromComp
;
1398 m_xCreateEntryPB
->set_sensitive(!s_bIsFromComponent
);
1399 m_xEntryLB
->clear();
1400 if(s_bIsFromComponent
)
1402 if(!m_bBibAccessInitialized
)
1404 uno::Reference
< uno::XComponentContext
> xContext
= getProcessComponentContext();
1405 m_xBibAccess
= frame::Bibliography::create( xContext
);
1406 uno::Reference
< beans::XPropertySet
> xPropSet(m_xBibAccess
, uno::UNO_QUERY
);
1407 OUString
uPropName("BibliographyDataFieldNames");
1408 if(xPropSet
.is() && xPropSet
->getPropertySetInfo()->hasPropertyByName(uPropName
))
1410 uno::Any aNames
= xPropSet
->getPropertyValue(uPropName
);
1411 uno::Sequence
<beans::PropertyValue
> aSeq
;
1412 if( aNames
>>= aSeq
)
1414 for(const beans::PropertyValue
& rProp
: std::as_const(aSeq
))
1416 sal_Int16 nField
= 0;
1417 rProp
.Value
>>= nField
;
1418 if(nField
>= 0 && nField
< AUTH_FIELD_END
)
1419 m_sColumnTitles
[nField
] = rProp
.Name
;
1423 m_bBibAccessInitialized
= true;
1425 if(m_xBibAccess
.is())
1427 const uno::Sequence
<OUString
> aIdentifiers
= m_xBibAccess
->getElementNames();
1428 for(const OUString
& rName
: aIdentifiers
)
1429 m_xEntryLB
->append_text(rName
);
1434 const SwAuthorityFieldType
* pFType
= static_cast<const SwAuthorityFieldType
*>(
1435 m_pSh
->GetFieldType(SwFieldIds::TableOfAuthorities
, OUString()));
1438 std::vector
<OUString
> aIds
;
1439 pFType
->GetAllEntryIdentifiers( aIds
);
1440 for(const OUString
& i
: aIds
)
1441 m_xEntryLB
->append_text(i
);
1443 if(!m_sCreatedEntry
[AUTH_FIELD_IDENTIFIER
].isEmpty())
1444 m_xEntryLB
->append_text(m_sCreatedEntry
[AUTH_FIELD_IDENTIFIER
]);
1446 m_xEntryLB
->set_active(0);
1447 CompEntryHdl(*m_xEntryLB
);
1450 IMPL_LINK(SwAuthorMarkPane
, EditModifyHdl
, weld::Entry
&, rEdit
, void)
1452 Link
<weld::Entry
&,bool> aAllowed
= LINK(this, SwAuthorMarkPane
, IsEditAllowedHdl
);
1453 bool bResult
= aAllowed
.Call(rEdit
);
1454 m_xActionBT
->set_sensitive(bResult
);
1457 OUString
sEntry(rEdit
.get_text());
1458 m_sFields
[AUTH_FIELD_IDENTIFIER
] = sEntry
;
1459 m_sCreatedEntry
[AUTH_FIELD_IDENTIFIER
] = sEntry
;
1463 IMPL_LINK(SwAuthorMarkPane
, IsEntryAllowedHdl
, weld::Entry
&, rEdit
, bool)
1465 OUString sEntry
= rEdit
.get_text();
1466 bool bAllowed
= false;
1467 if(!sEntry
.isEmpty())
1469 if (m_xEntryLB
->find_text(sEntry
) != -1)
1471 else if(s_bIsFromComponent
)
1473 const SwAuthorityFieldType
* pFType
= static_cast<const SwAuthorityFieldType
*>(
1474 m_pSh
->GetFieldType(SwFieldIds::TableOfAuthorities
, OUString()));
1475 bAllowed
= !pFType
|| !pFType
->GetEntryByIdentifier(sEntry
);
1479 bAllowed
= !m_xBibAccess
.is() || !m_xBibAccess
->hasByName(sEntry
);
1485 IMPL_LINK(SwAuthorMarkPane
, IsEditAllowedHdl
, weld::Entry
&, rEdit
, bool)
1487 OUString sEntry
= rEdit
.get_text();
1488 bool bAllowed
= false;
1489 if(!sEntry
.isEmpty())
1491 if (m_xEntryLB
->find_text(sEntry
) != -1)
1493 else if(s_bIsFromComponent
)
1495 const SwAuthorityFieldType
* pFType
= static_cast<const SwAuthorityFieldType
*>(
1496 m_pSh
->GetFieldType(SwFieldIds::TableOfAuthorities
, OUString()));
1497 bAllowed
= !pFType
|| !pFType
->GetEntryByIdentifier(sEntry
);
1501 bAllowed
= !m_xBibAccess
.is() || !m_xBibAccess
->hasByName(sEntry
);
1507 void SwAuthorMarkPane::InitControls()
1509 OSL_ENSURE(m_pSh
, "no shell?");
1510 SwField
* pField
= m_pSh
->GetCurField();
1511 OSL_ENSURE(m_bNewEntry
|| pField
, "no current marker");
1514 ChangeSourceHdl(m_xFromComponentRB
->get_active() ? *m_xFromComponentRB
: *m_xFromDocContentRB
);
1515 m_xCreateEntryPB
->set_sensitive(!m_xFromComponentRB
->get_active());
1516 if(!m_xFromComponentRB
->get_active() && !m_sCreatedEntry
[0].isEmpty())
1517 for(int i
= 0; i
< AUTH_FIELD_END
; i
++)
1518 m_sFields
[i
] = m_sCreatedEntry
[i
];
1520 if(m_bNewEntry
|| !pField
|| pField
->GetTyp()->Which() != SwFieldIds::TableOfAuthorities
)
1523 const SwAuthEntry
* pEntry
= static_cast<SwAuthorityField
*>(pField
)->GetAuthEntry();
1525 OSL_ENSURE(pEntry
, "No authority entry found");
1528 for(int i
= 0; i
< AUTH_FIELD_END
; i
++)
1529 m_sFields
[i
] = pEntry
->GetAuthorField(static_cast<ToxAuthorityField
>(i
));
1531 m_xEntryED
->set_text(pEntry
->GetAuthorField(AUTH_FIELD_IDENTIFIER
));
1532 m_xAuthorFI
->set_label(pEntry
->GetAuthorField(AUTH_FIELD_AUTHOR
));
1533 m_xTitleFI
->set_label(pEntry
->GetAuthorField(AUTH_FIELD_TITLE
));
1536 void SwAuthorMarkPane::Activate()
1538 m_xActionBT
->set_sensitive(!m_pSh
->HasReadonlySel());
1543 const TranslateId STR_AUTH_FIELD_ARY
[] =
1545 STR_AUTH_FIELD_IDENTIFIER
,
1546 STR_AUTH_FIELD_AUTHORITY_TYPE
,
1547 STR_AUTH_FIELD_ADDRESS
,
1548 STR_AUTH_FIELD_ANNOTE
,
1549 STR_AUTH_FIELD_AUTHOR
,
1550 STR_AUTH_FIELD_BOOKTITLE
,
1551 STR_AUTH_FIELD_CHAPTER
,
1552 STR_AUTH_FIELD_EDITION
,
1553 STR_AUTH_FIELD_EDITOR
,
1554 STR_AUTH_FIELD_HOWPUBLISHED
,
1555 STR_AUTH_FIELD_INSTITUTION
,
1556 STR_AUTH_FIELD_JOURNAL
,
1557 STR_AUTH_FIELD_MONTH
,
1558 STR_AUTH_FIELD_NOTE
,
1559 STR_AUTH_FIELD_NUMBER
,
1560 STR_AUTH_FIELD_ORGANIZATIONS
,
1561 STR_AUTH_FIELD_PAGES
,
1562 STR_AUTH_FIELD_PUBLISHER
,
1563 STR_AUTH_FIELD_SCHOOL
,
1564 STR_AUTH_FIELD_SERIES
,
1565 STR_AUTH_FIELD_TITLE
,
1566 STR_AUTH_FIELD_TYPE
,
1567 STR_AUTH_FIELD_VOLUME
,
1568 STR_AUTH_FIELD_YEAR
,
1570 STR_AUTH_FIELD_CUSTOM1
,
1571 STR_AUTH_FIELD_CUSTOM2
,
1572 STR_AUTH_FIELD_CUSTOM3
,
1573 STR_AUTH_FIELD_CUSTOM4
,
1574 STR_AUTH_FIELD_CUSTOM5
,
1575 STR_AUTH_FIELD_ISBN
,
1576 STR_AUTH_FIELD_LOCAL_URL
,
1577 STR_AUTH_FIELD_TARGET_TYPE
,
1578 STR_AUTH_FIELD_TARGET_URL
,
1582 SwCreateAuthEntryDlg_Impl::SwCreateAuthEntryDlg_Impl(weld::Window
* pParent
,
1583 const OUString pFields
[],
1587 : GenericDialogController(pParent
, "modules/swriter/ui/createauthorentry.ui", "CreateAuthorEntryDialog")
1589 , m_bNewEntryMode(bNewEntry
)
1590 , m_bNameAllowed(true)
1591 , m_xOKBT(m_xBuilder
->weld_button("ok"))
1592 , m_xBox(m_xBuilder
->weld_container("box"))
1593 , m_xLeft(m_xBuilder
->weld_container("leftgrid"))
1594 , m_xRight(m_xBuilder
->weld_container("rightgrid"))
1595 , m_pTargetURLField(nullptr)
1598 sal_Int32
nLeftRow(0), nRightRow(0);
1599 for(int nIndex
= 0; nIndex
< AUTH_FIELD_END
; nIndex
++)
1601 //m_xBox parent just to have some parent during setup, added contents are not directly visible under m_xBox
1602 m_aBuilders
.emplace_back(Application::CreateBuilder(m_xBox
.get(), "modules/swriter/ui/bibliofragment.ui"));
1603 const TextInfo aCurInfo
= aTextInfoArr
[nIndex
];
1605 m_aOrigContainers
.emplace_back(m_aBuilders
.back()->weld_container("biblioentry"));
1606 m_aFixedTexts
.emplace_back(m_aBuilders
.back()->weld_label("label"));
1608 m_aOrigContainers
.back()->move(m_aFixedTexts
.back().get(), m_xLeft
.get());
1610 m_aOrigContainers
.back()->move(m_aFixedTexts
.back().get(), m_xRight
.get());
1611 m_aFixedTexts
.back()->set_grid_left_attach(0);
1612 m_aFixedTexts
.back()->set_grid_top_attach(bLeft
? nLeftRow
: nRightRow
);
1613 m_aFixedTexts
.back()->set_label(SwResId(STR_AUTH_FIELD_ARY
[aCurInfo
.nToxField
]));
1614 m_aFixedTexts
.back()->show();
1615 if( AUTH_FIELD_AUTHORITY_TYPE
== aCurInfo
.nToxField
)
1617 m_xTypeListBox
= m_aBuilders
.back()->weld_combo_box("listbox");
1619 m_aOrigContainers
.back()->move(m_xTypeListBox
.get(), m_xLeft
.get());
1621 m_aOrigContainers
.back()->move(m_xTypeListBox
.get(), m_xRight
.get());
1623 for (int j
= 0; j
< AUTH_TYPE_END
; j
++)
1625 m_xTypeListBox
->append_text(
1626 SwAuthorityFieldType::GetAuthTypeName(static_cast<ToxAuthorityType
>(j
)));
1628 if(!pFields
[aCurInfo
.nToxField
].isEmpty())
1630 m_xTypeListBox
->set_active(pFields
[aCurInfo
.nToxField
].toInt32());
1632 m_xTypeListBox
->set_grid_left_attach(1);
1633 m_xTypeListBox
->set_grid_top_attach(bLeft
? nLeftRow
: nRightRow
);
1634 m_xTypeListBox
->set_hexpand(true);
1635 m_xTypeListBox
->show();
1636 m_xTypeListBox
->connect_changed(LINK(this, SwCreateAuthEntryDlg_Impl
, EnableHdl
));
1637 m_xTypeListBox
->set_help_id(aCurInfo
.pHelpId
);
1638 m_aFixedTexts
.back()->set_mnemonic_widget(m_xTypeListBox
.get());
1640 else if(AUTH_FIELD_IDENTIFIER
== aCurInfo
.nToxField
&& !m_bNewEntryMode
)
1642 m_xIdentifierBox
= m_aBuilders
.back()->weld_combo_box("combobox");
1644 m_aOrigContainers
.back()->move(m_xIdentifierBox
.get(), m_xLeft
.get());
1646 m_aOrigContainers
.back()->move(m_xIdentifierBox
.get(), m_xRight
.get());
1648 m_xIdentifierBox
->connect_changed(LINK(this,
1649 SwCreateAuthEntryDlg_Impl
, IdentifierHdl
));
1651 const SwAuthorityFieldType
* pFType
= static_cast<const SwAuthorityFieldType
*>(
1652 rSh
.GetFieldType(SwFieldIds::TableOfAuthorities
, OUString()));
1655 std::vector
<OUString
> aIds
;
1656 pFType
->GetAllEntryIdentifiers( aIds
);
1657 for (const OUString
& a
: aIds
)
1658 m_xIdentifierBox
->append_text(a
);
1660 m_xIdentifierBox
->set_entry_text(pFields
[aCurInfo
.nToxField
]);
1661 m_xIdentifierBox
->set_grid_left_attach(1);
1662 m_xIdentifierBox
->set_grid_top_attach(bLeft
? nLeftRow
: nRightRow
);
1663 m_xIdentifierBox
->set_hexpand(true);
1664 m_xIdentifierBox
->show();
1665 m_xIdentifierBox
->set_help_id(aCurInfo
.pHelpId
);
1666 m_aFixedTexts
.back()->set_mnemonic_widget(m_xIdentifierBox
.get());
1668 else if (AUTH_FIELD_TARGET_TYPE
== aCurInfo
.nToxField
)
1670 m_xTargetTypeListBox
= m_aBuilders
.back()->weld_combo_box("listbox-target-type");
1672 m_aOrigContainers
.back()->move(m_xTargetTypeListBox
.get(), m_xLeft
.get());
1674 m_aOrigContainers
.back()->move(m_xTargetTypeListBox
.get(), m_xRight
.get());
1676 if(!pFields
[aCurInfo
.nToxField
].isEmpty())
1678 m_xTargetTypeListBox
->set_active(pFields
[aCurInfo
.nToxField
].toInt32());
1680 else if(m_bNewEntryMode
)
1682 // For new documents, set value to "BibliographyTableRow"
1683 m_xTargetTypeListBox
->set_active(SwAuthorityField::TargetType::BibliographyTableRow
);
1685 m_xTargetTypeListBox
->set_grid_left_attach(1);
1686 m_xTargetTypeListBox
->set_grid_top_attach(bLeft
? nLeftRow
: nRightRow
);
1687 m_xTargetTypeListBox
->set_hexpand(true);
1688 m_xTargetTypeListBox
->show();
1689 m_xTargetTypeListBox
->connect_changed(LINK(this, SwCreateAuthEntryDlg_Impl
, TargetTypeHdl
));
1690 m_xTargetTypeListBox
->set_help_id(aCurInfo
.pHelpId
);
1691 m_aFixedTexts
.back()->set_mnemonic_widget(m_xTargetTypeListBox
.get());
1695 m_pBoxes
[nIndex
] = m_aBuilders
.back()->weld_box("vbox");
1696 m_pEdits
[nIndex
] = m_aBuilders
.back()->weld_entry("entry");
1698 if (AUTH_FIELD_TARGET_URL
== aCurInfo
.nToxField
)
1700 m_pTargetURLField
= m_pEdits
[nIndex
].get();
1701 assert(m_xTargetTypeListBox
);
1702 m_pTargetURLField
->set_sensitive(
1703 m_xTargetTypeListBox
->get_active() == SwAuthorityField::TargetType::UseTargetURL
);
1707 m_aOrigContainers
.back()->move(m_pBoxes
[nIndex
].get(), m_xLeft
.get());
1709 m_aOrigContainers
.back()->move(m_pBoxes
[nIndex
].get(), m_xRight
.get());
1711 m_pBoxes
[nIndex
]->set_grid_left_attach(1);
1712 m_pBoxes
[nIndex
]->set_grid_top_attach(bLeft
? nLeftRow
: nRightRow
);
1713 m_pBoxes
[nIndex
]->set_hexpand(true);
1714 if (aCurInfo
.nToxField
== AUTH_FIELD_LOCAL_URL
)
1716 m_xLocalBrowseButton
= m_aBuilders
.back()->weld_button("browse");
1717 m_xLocalBrowseButton
->connect_clicked(
1718 LINK(this, SwCreateAuthEntryDlg_Impl
, BrowseHdl
));
1719 m_xLocalPageCB
= m_aBuilders
.back()->weld_check_button("pagecb");
1720 // Distinguish different instances of this for ui-testing.
1721 m_xLocalPageCB
->set_buildable_name(m_xLocalPageCB
->get_buildable_name()
1722 + "-local-visible");
1723 m_xLocalPageSB
= m_aBuilders
.back()->weld_spin_button("pagesb");
1726 // Now that both pEdits[nIndex] and m_xPageSB is initialized, set their values.
1727 OUString aText
= pFields
[aCurInfo
.nToxField
];
1728 if (aCurInfo
.nToxField
== AUTH_FIELD_LOCAL_URL
)
1732 if (SplitUrlAndPage(aText
, aUrl
, nPageNumber
))
1734 m_pEdits
[nIndex
]->set_text(aUrl
);
1735 m_xLocalPageCB
->set_active(true);
1736 m_xLocalPageSB
->set_sensitive(true);
1737 m_xLocalPageSB
->set_value(nPageNumber
);
1741 m_pEdits
[nIndex
]->set_text(aText
);
1746 m_pEdits
[nIndex
]->set_text(aText
);
1748 m_pEdits
[nIndex
]->show();
1749 m_pEdits
[nIndex
]->set_help_id(aCurInfo
.pHelpId
);
1751 if(AUTH_FIELD_IDENTIFIER
== aCurInfo
.nToxField
)
1753 m_pEdits
[nIndex
]->connect_changed(LINK(this, SwCreateAuthEntryDlg_Impl
, ShortNameHdl
));
1754 m_bNameAllowed
= !pFields
[nIndex
].isEmpty();
1757 m_aFixedTexts
.back()->set_sensitive(false);
1758 m_pEdits
[nIndex
]->set_sensitive(false);
1761 else if (aCurInfo
.nToxField
== AUTH_FIELD_LOCAL_URL
)
1763 m_xLocalPageCB
->show();
1764 m_xLocalPageCB
->connect_toggled(LINK(this, SwCreateAuthEntryDlg_Impl
, PageNumHdl
));
1765 m_xLocalPageSB
->show();
1768 m_aFixedTexts
.back()->set_mnemonic_widget(m_pEdits
[nIndex
].get());
1776 assert(m_xTypeListBox
&& "this will exist after the loop");
1777 EnableHdl(*m_xTypeListBox
);
1780 OUString
SwCreateAuthEntryDlg_Impl::GetEntryText(ToxAuthorityField eField
) const
1782 if( AUTH_FIELD_AUTHORITY_TYPE
== eField
)
1784 assert(m_xTypeListBox
&& "No ListBox");
1785 return OUString::number(m_xTypeListBox
->get_active());
1788 if( AUTH_FIELD_IDENTIFIER
== eField
&& !m_bNewEntryMode
)
1790 assert(m_xIdentifierBox
&& "No ComboBox");
1791 return m_xIdentifierBox
->get_active_text();
1794 if (AUTH_FIELD_TARGET_TYPE
== eField
)
1796 assert(m_xTargetTypeListBox
&& "No TargetType ListBox");
1797 return OUString::number(m_xTargetTypeListBox
->get_active());
1800 for(int nIndex
= 0; nIndex
< AUTH_FIELD_END
; nIndex
++)
1802 const TextInfo aCurInfo
= aTextInfoArr
[nIndex
];
1803 if(aCurInfo
.nToxField
== eField
)
1805 if (aCurInfo
.nToxField
== AUTH_FIELD_LOCAL_URL
)
1807 return MergeUrlAndPage(m_pEdits
[nIndex
]->get_text(), m_xLocalPageSB
);
1811 return m_pEdits
[nIndex
]->get_text();
1819 IMPL_LINK(SwCreateAuthEntryDlg_Impl
, IdentifierHdl
, weld::ComboBox
&, rBox
, void)
1821 const SwAuthorityFieldType
* pFType
= static_cast<const SwAuthorityFieldType
*>(
1822 m_rWrtSh
.GetFieldType(SwFieldIds::TableOfAuthorities
, OUString()));
1826 const SwAuthEntry
* pEntry
= pFType
->GetEntryByIdentifier(
1827 rBox
.get_active_text());
1831 for(int i
= 0; i
< AUTH_FIELD_END
; i
++)
1833 const TextInfo aCurInfo
= aTextInfoArr
[i
];
1834 if(AUTH_FIELD_IDENTIFIER
== aCurInfo
.nToxField
)
1836 if(AUTH_FIELD_AUTHORITY_TYPE
== aCurInfo
.nToxField
)
1837 m_xTypeListBox
->set_active_text(
1838 pEntry
->GetAuthorField(aCurInfo
.nToxField
));
1840 m_pEdits
[i
]->set_text(
1841 pEntry
->GetAuthorField(aCurInfo
.nToxField
));
1845 IMPL_LINK(SwCreateAuthEntryDlg_Impl
, ShortNameHdl
, weld::Entry
&, rEdit
, void)
1847 if (m_aShortNameCheckLink
.IsSet())
1849 bool bEnable
= m_aShortNameCheckLink
.Call(rEdit
);
1850 m_bNameAllowed
|= bEnable
;
1851 m_xOKBT
->set_sensitive(m_xTypeListBox
->get_active() != -1 && bEnable
);
1855 IMPL_LINK(SwCreateAuthEntryDlg_Impl
, EnableHdl
, weld::ComboBox
&, rBox
, void)
1857 m_xOKBT
->set_sensitive(m_bNameAllowed
&& rBox
.get_active() != -1);
1858 m_xLocalBrowseButton
->show();
1861 IMPL_LINK(SwCreateAuthEntryDlg_Impl
, TargetTypeHdl
, weld::ComboBox
&, rBox
, void)
1863 assert(m_pTargetURLField
);
1864 m_pTargetURLField
->set_sensitive(rBox
.get_active() == SwAuthorityField::TargetType::UseTargetURL
);
1867 IMPL_LINK(SwCreateAuthEntryDlg_Impl
, BrowseHdl
, weld::Button
&, rButton
, void)
1869 sfx2::FileDialogHelper
aFileDlg(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
1870 FileDialogFlags::NONE
, getDialog());
1872 if (&rButton
== m_xLocalBrowseButton
.get())
1874 aPath
= GetEntryText(AUTH_FIELD_LOCAL_URL
);
1876 if (!aPath
.isEmpty())
1878 aFileDlg
.SetDisplayDirectory(aPath
);
1882 OUString aBaseURL
= m_rWrtSh
.GetDoc()->GetDocShell()->getDocumentBaseURL();
1883 if (!aBaseURL
.isEmpty())
1885 aFileDlg
.SetDisplayDirectory(aBaseURL
);
1889 if (aFileDlg
.Execute() != ERRCODE_NONE
)
1894 aPath
= aFileDlg
.GetPath();
1896 for (int nIndex
= 0; nIndex
< AUTH_FIELD_END
; nIndex
++)
1898 const TextInfo
& rCurInfo
= aTextInfoArr
[nIndex
];
1899 if (rCurInfo
.nToxField
== AUTH_FIELD_LOCAL_URL
&& &rButton
== m_xLocalBrowseButton
.get())
1901 m_pEdits
[nIndex
]->set_text(aPath
);
1907 IMPL_LINK(SwCreateAuthEntryDlg_Impl
, PageNumHdl
, weld::Toggleable
&, rPageCB
, void)
1909 if (rPageCB
.get_active())
1911 m_xLocalPageSB
->set_sensitive(true);
1912 m_xLocalPageSB
->set_value(1);
1916 m_xLocalPageSB
->set_sensitive(false);
1920 SwAuthMarkFloatDlg::SwAuthMarkFloatDlg(SfxBindings
* _pBindings
,
1921 SfxChildWindow
* pChild
,
1922 weld::Window
*pParent
,
1923 SfxChildWinInfo
const * pInfo
,
1925 : SfxModelessDialogController(_pBindings
, pChild
, pParent
,
1926 "modules/swriter/ui/bibliographyentry.ui", "BibliographyEntryDialog")
1927 , m_aContent(*this, *m_xBuilder
, bNew
)
1930 if (SwWrtShell
* pWrtShell
= ::GetActiveWrtShell())
1931 m_aContent
.ReInitDlg(*pWrtShell
);
1934 void SwAuthMarkFloatDlg::Activate()
1936 SfxModelessDialogController::Activate();
1937 m_aContent
.Activate();
1940 void SwAuthMarkFloatDlg::ReInitDlg(SwWrtShell
& rWrtShell
)
1942 m_aContent
.ReInitDlg( rWrtShell
);
1945 SwAuthMarkModalDlg::SwAuthMarkModalDlg(weld::Window
*pParent
, SwWrtShell
& rSh
)
1946 : SfxDialogController(pParent
, "modules/swriter/ui/bibliographyentry.ui",
1947 "BibliographyEntryDialog")
1948 , m_aContent(*this, *m_xBuilder
, false)
1950 m_aContent
.ReInitDlg(rSh
);
1953 short SwAuthMarkModalDlg::run()
1955 short ret
= SfxDialogController::run();
1961 void SwAuthMarkModalDlg::Apply()
1963 m_aContent
.InsertHdl(*m_aContent
.m_xActionBT
);
1966 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */