23#include <com/sun/star/frame/XStorable.hpp>
24#include <com/sun/star/linguistic2/XDictionary.hpp>
25#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
51 if (aTmp.indexOf(
'[') > -1)
53 OUStringBuffer aTmp2 ( aTmp.getLength() );
55 for (sal_Int32
i = 0;
i < aTmp.getLength();
i++)
65 aTmp = aTmp2.makeStringAndClear();
67 return aTmp.replaceAll(
"=",
"");
79 nLen = sText.getLength();
80 sText = sText.replaceAll(
" ",
" ");
82 while ( sText.getLength() < nLen );
90enum CDE_RESULT { CDE_EQUAL, CDE_SIMILAR, CDE_DIFFERENT };
94static CDE_RESULT
cmpDicEntry_Impl( std::u16string_view rText1, std::u16string_view rText2 )
96 CDE_RESULT eRes = CDE_DIFFERENT;
113 : GenericDialogController(pParent,
"cui/ui/optnewdictionarydialog.ui",
"OptNewDictionaryDialog")
114 , m_xNameEdit(m_xBuilder->weld_entry(
"nameedit"))
115 , m_xLanguageLB(new
SvxLanguageBox(m_xBuilder->weld_combo_box(
"language")))
116 , m_xExceptBtn(m_xBuilder->weld_check_button(
"except"))
117 , m_xOKBtn(m_xBuilder->weld_button(
"ok"))
127 m_xLanguageLB->SetLanguageList(SvxLanguageListFlags::ALL,
true,
true);
139 Sequence< Reference< XDictionary > > aDics;
141 aDics = xDicList->getDictionaries();
142 const Reference< XDictionary > *pDic = aDics.getConstArray();
143 sal_Int32
nCount = aDics.getLength();
148 if ( sDict.equalsIgnoreAsciiCase( pDic[
i]->getName()) )
151 if ( sDict.indexOf(
"/") != -1 || sDict.indexOf(
"\\") != -1 )
155 VclMessageType::Info, VclButtonsType::Ok,
156 CuiResId(RID_CUISTR_OPT_INVALID_DICT_NAME)));
158 m_xNameEdit->grab_focus();
166 VclMessageType::Info, VclButtonsType::Ok,
167 CuiResId(RID_CUISTR_OPT_DOUBLE_DICTS)));
169 m_xNameEdit->grab_focus();
178 DictionaryType
eType = m_xExceptBtn->get_active() ?
179 DictionaryType_NEGATIVE : DictionaryType_POSITIVE;
184 m_xNewDic = xDicList->createDictionary(sDict, aLocale,
eType,
aURL);
185 m_xNewDic->setActive(
true);
200 if (xDicList.is() && m_xNewDic.is())
202 xDicList->addDictionary(m_xNewDic);
206 aDics = xDicList->getDictionaries();
214 m_xOKBtn->set_sensitive(!m_xNameEdit->get_text().isEmpty());
220 : GenericDialogController(pParent,
"cui/ui/editdictionarydialog.ui",
"EditDictionaryDialog")
222 , bFirstSelect(false)
224 , bDicIsReadonly(false)
225 , m_xAllDictsLB(m_xBuilder->weld_combo_box(
"book"))
226 , m_xLangFT(m_xBuilder->weld_label(
"lang_label"))
227 , m_xLangLB(new
SvxLanguageBox(m_xBuilder->weld_combo_box(
"lang")))
228 , m_xWordED(m_xBuilder->weld_entry(
"word"))
229 , m_xReplaceFT(m_xBuilder->weld_label(
"replace_label"))
230 , m_xReplaceED(m_xBuilder->weld_entry(
"replace"))
231 , m_xSingleColumnLB(m_xBuilder->weld_tree_view(
"words"))
232 , m_xDoubleColumnLB(m_xBuilder->weld_tree_view(
"replaces"))
233 , m_xNewReplacePB(m_xBuilder->weld_button(
"newreplace"))
234 , m_xDeletePB(m_xBuilder->weld_button(
"delete"))
248 m_xNewReplacePB->set_size_request(std::max(nNewWidth, nReplaceWidth), -1);
256 std::vector<int> aWidths
279 const Reference< XDictionary > *pDic =
aDics.getConstArray();
282 OUString aLookUpEntry;
285 Reference< XDictionary > xDic = pDic[
i];
288 bool bNegative = xDic->getDictionaryType() == DictionaryType_NEGATIVE;
289 OUString aDicName( xDic->getName() );
290 const OUString aTxt( ::GetDicInfoStr( aDicName,
294 if (rName == aDicName)
299 m_xLangLB->SetLanguageList( SvxLanguageListFlags::ALL,
true,
true );
311 Reference< XDictionary > xDic;
338 std::vector<int> aWidths;
339 int x,
y, width, height;
340 if (m_xReplaceED->get_extents_relative_to(*m_pWordsLB,
x,
y, width, height))
342 aWidths.push_back(
x);
343 m_xDoubleColumnLB->set_column_fixed_widths(aWidths);
352 Reference< XDictionary >
const &xDic )
360 || !xStor->hasLocation()
361 || !xStor->isReadonly() )
380 for (j = 0; j <
nCount; ++j)
383 sal_Int32 nCmpRes = pCollator->
395 if (nEntry != -1 && nLBPos != -1)
399 Reference<XDictionary> xDic =
aDics.getConstArray()[nLBPos];
400 if (xDic->remove(sTmpShort))
410 int nPos = m_xAllDictsLB->get_active();
414 m_xNewReplacePB->set_sensitive(
false );
415 m_xDeletePB->set_sensitive(
false );
417 ShowWords_Impl(
nPos );
419 Reference< XDictionary >
const & xDic = aDics[
nPos ];
423 SetDicReadonly_Impl(xDic);
424 bool bEnable = !IsDicReadonly_Impl();
425 m_xLangFT->set_sensitive( bEnable );
426 m_xLangLB->set_sensitive( bEnable );
431 int nDicPos = m_xAllDictsLB->get_active();
433 Reference< XDictionary >
const & xDic = aDics[ nDicPos ];
436 if ( nLang == nOldLang )
440 VclMessageType::Question, VclButtonsType::YesNo,
441 CuiResId(RID_CUISTR_CONFIRM_SET_LANGUAGE)));
442 OUString sTxt(xBox->get_primary_text());
443 sTxt = sTxt.replaceFirst(
"%1", m_xAllDictsLB->get_active_text());
444 xBox->set_primary_text(sTxt);
449 bool bNegativ = xDic->getDictionaryType() == DictionaryType_NEGATIVE;
451 const OUString
sName(
452 ::GetDicInfoStr( xDic->getName(),
455 m_xAllDictsLB->remove(nDicPos);
456 m_xAllDictsLB->insert_text(nDicPos,
sName);
457 m_xAllDictsLB->set_active(nDicPos);
460 SetLanguage_Impl( nOldLang );
465 Reference< XDictionary > xDic =
aDics.getConstArray()[
nId ];
472 bool bIsNegative = xDic->getDictionaryType() != DictionaryType_POSITIVE;
483 }
else if (!bLangNone) {
487 if(bIsNegative || !bLangNone)
514 Sequence< Reference< XDictionaryEntry > >
aEntries( xDic->getEntries() );
515 const Reference< XDictionaryEntry > *pEntry =
aEntries.getConstArray();
517 std::vector<OUString> aSortedDicEntries;
518 aSortedDicEntries.reserve(
nCount);
521 OUString
aStr = pEntry[
i]->getDictionaryWord();
522 if(!pEntry[
i]->getReplacementText().isEmpty())
524 aStr +=
"\t" + pEntry[
i]->getReplacementText();
526 aSortedDicEntries.push_back(
aStr);
531 std::sort(aSortedDicEntries.begin(), aSortedDicEntries.end(),
532 [&] (OUString
const & lhs, OUString
const & rhs)
534 sal_Int32 nCmpRes = pCollator->
535 compareString( getNormDicEntry_Impl(lhs), getNormDicEntry_Impl( rhs ) );
541 for (OUString
const & rStr : aSortedDicEntries)
546 OUString sReplace = rStr.getToken(1,
'\t');
566 int nEntry = rBox.get_selected_index();
572 OUString sTmpShort(rBox.get_text(nEntry, 0));
575 if (m_xWordED->get_text() != sTmpShort)
576 m_xWordED->set_text(sTmpShort);
577 if (&rBox == m_xDoubleColumnLB.get())
578 m_xReplaceED->set_text(rBox.get_text(nEntry, 1));
582 bFirstSelect =
false;
586 m_xNewReplacePB->set_sensitive(
false);
587 m_xDeletePB->set_sensitive(nEntry != -1 && !IsDicReadonly_Impl());
597 return NewDelHdl(&rDictEdit);
615 OUString sEntry(aNewWord);
620 if (
nPos != -1 && !aNewWord.isEmpty())
623 Reference< XDictionary >
const & xDic =
aDics[
nPos ];
628 bool bIsNegEntry = xDic->getDictionaryType() == DictionaryType_NEGATIVE;
631 if(!aReplaceStr.isEmpty())
632 aRplcText = aReplaceStr;
640 aNewWord, bIsNegEntry,
644 if (DictionaryError::NONE != nAddRes)
647 if (DictionaryError::NONE == nAddRes && !sEntry.isEmpty())
655 if (!aReplaceStr.isEmpty())
662 if(!aReplaceStr.isEmpty())
686 OUString rEntry = rEdt.get_text();
688 sal_Int32 nWordLen = rEntry.getLength();
689 const OUString& rRepString =
fixSpace(m_xReplaceED->get_text());
691 bool bEnableNewReplace =
false;
692 bool bEnableDelete =
false;
693 OUString aNewReplaceText = sNew;
695 if (&rEdt == m_xWordED.get())
700 bool bTmpSelEntry=
false;
701 CDE_RESULT eCmpRes = CDE_DIFFERENT;
703 bool bDoubleColumn = m_pWordsLB == m_xDoubleColumnLB.get();
707 OUString aTestStr(m_pWordsLB->get_text(
i, 0));
709 if(CDE_DIFFERENT != eCmpRes)
711 if(!rRepString.isEmpty())
714 m_pWordsLB->set_cursor(
i);
717 m_xReplaceED->set_text(m_pWordsLB->get_text(
i, 1));
719 if (CDE_SIMILAR == eCmpRes)
721 aNewReplaceText = sModify;
722 bEnableNewReplace =
true;
732 m_pWordsLB->scroll_to_row(
i);
736 aNewReplaceText = sNew;
737 bEnableNewReplace =
true;
743 m_pWordsLB->unselect_all();
744 aNewReplaceText = sNew;
745 bEnableNewReplace =
true;
747 bEnableDelete = CDE_DIFFERENT != eCmpRes;
749 else if (m_pWordsLB->n_children() > 0)
752 m_pWordsLB->scroll_to_row(0);
756 else if(&rEdt == m_xReplaceED.get())
758 OUString aReplaceText;
760 int nFirstSel = m_pWordsLB->get_selected_index();
763 aWordText = m_pWordsLB->get_text(nFirstSel, 0);
764 aReplaceText = m_pWordsLB->get_text(nFirstSel, 1);
766 aNewReplaceText = sModify;
767 bEnableDelete =
true;
772 if (!
fixSpace(m_xWordED->get_text()).isEmpty() && bIsChange)
773 bEnableNewReplace =
true;
776 m_xNewReplacePB->set_label(aNewReplaceText);
777 m_xNewReplacePB->set_sensitive(bEnableNewReplace && !IsDicReadonly_Impl());
778 m_xDeletePB->set_sensitive(bEnableDelete && !IsDicReadonly_Impl());
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
const CollatorWrapper * getCollator() const
LanguageType getLanguageType(bool bResolveSystem=true) const
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static css::uno::Reference< css::linguistic2::XSearchableDictionaryList > GetDictionaryList()
std::unique_ptr< weld::TreeView > m_xSingleColumnLB
void ShowWords_Impl(sal_uInt16 nId)
void SetLanguage_Impl(LanguageType nLanguage)
int GetLBInsertPos(std::u16string_view rDicWord)
virtual ~SvxEditDictionaryDialog() override
std::unique_ptr< weld::Label > m_xLangFT
css::uno::Sequence< css::uno::Reference< css::linguistic2::XDictionary > > aDics
std::unique_ptr< weld::Label > m_xReplaceFT
std::unique_ptr< weld::TreeView > m_xDoubleColumnLB
void RemoveDictEntry(int nEntry)
std::unique_ptr< weld::Button > m_xNewReplacePB
SvxEditDictionaryDialog(weld::Window *pParent, std::u16string_view rName)
void SetDicReadonly_Impl(css::uno::Reference< css::linguistic2::XDictionary > const &xDic)
bool NewDelHdl(const weld::Widget *)
weld::TreeView * m_pWordsLB
bool IsDicReadonly_Impl() const
std::unique_ptr< weld::Entry > m_xWordED
std::unique_ptr< SvxLanguageBox > m_xLangLB
std::unique_ptr< weld::ComboBox > m_xAllDictsLB
std::unique_ptr< weld::Entry > m_xReplaceED
std::unique_ptr< weld::Button > m_xDeletePB
std::unique_ptr< SvxLanguageBox > m_xLanguageLB
std::unique_ptr< weld::Entry > m_xNameEdit
std::unique_ptr< weld::Button > m_xOKBtn
SvxNewDictionaryDialog(weld::Window *pParent)
std::shared_ptr< weld::Dialog > m_xDialog
virtual void scroll_to_row(int row)=0
virtual void set_text(int row, const OUString &rText, int col=-1)=0
virtual OUString get_text(int row, int col=-1) const=0
void append_text(const OUString &rStr)
virtual int n_children() const=0
void insert_text(int pos, const OUString &rStr)
virtual void remove(int pos)=0
virtual void select(int pos)=0
virtual void set_cursor(int pos)=0
virtual int get_selected_index() const=0
OUString CuiResId(TranslateId aKey)
#define DBG_ASSERT(sCon, aError)
SVXCORE_DLLPUBLIC std::locale SvxResLocale()
ScXMLEditAttributeMap::Entry const aEntries[]
#define LINK(Instance, Class, Member)
OString stripEnd(const OString &rIn, char c)
OUString GetWritableDictionaryURL(std::u16string_view rDicName)
DictionaryError AddEntryToDic(uno::Reference< XDictionary > const &rxDic, const OUString &rWord, bool bIsNeg, const OUString &rRplcTxt, bool bStripDot)
static CDE_RESULT cmpDicEntry_Impl(std::u16string_view rText1, std::u16string_view rText2)
static OUString fixSpace(OUString sText)
static OUString getNormDicEntry_Impl(std::u16string_view rText)
IMPL_LINK(SvxEditDictionaryDialog, SelectHdl, weld::TreeView &, rBox, void)
IMPL_LINK_NOARG(SvxNewDictionaryDialog, OKHdl_Impl, weld::Button &, void)
SVX_DLLPUBLIC const ErrMsgCode RID_SVXERRCTX[]
#define ERRCTX_SVX_LINGU_DICTIONARY
#define ERRCODE_SVX_LINGU_DICT_NOTWRITEABLE
short SvxDicError(weld::Window *pParent, linguistic::DictionaryError nError)