tdf#144694 In direct SQL dialog, activate options 'Run SQL command
[LibreOffice.git] / cui / source / options / optjsearch.cxx
blob4d9048155c1721f44953eff8b8f416afd9b89dc4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/debug.hxx>
21 #include <unotools/searchopt.hxx>
22 #include <i18nutil/transliteration.hxx>
23 #include "optjsearch.hxx"
26 SvxJSearchOptionsPage::SvxJSearchOptionsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
27 : SfxTabPage(pPage, pController, u"cui/ui/optjsearchpage.ui"_ustr, u"OptJSearchPage"_ustr, &rSet)
28 , m_xMatchCase(m_xBuilder->weld_check_button(u"matchcase"_ustr))
29 , m_xMatchFullHalfWidth(m_xBuilder->weld_check_button(u"matchfullhalfwidth"_ustr))
30 , m_xMatchHiraganaKatakana(m_xBuilder->weld_check_button(u"matchhiraganakatakana"_ustr))
31 , m_xMatchContractions(m_xBuilder->weld_check_button(u"matchcontractions"_ustr))
32 , m_xMatchMinusDashChoon(m_xBuilder->weld_check_button(u"matchminusdashchoon"_ustr))
33 , m_xMatchRepeatCharMarks(m_xBuilder->weld_check_button(u"matchrepeatcharmarks"_ustr))
34 , m_xMatchVariantFormKanji(m_xBuilder->weld_check_button(u"matchvariantformkanji"_ustr))
35 , m_xMatchOldKanaForms(m_xBuilder->weld_check_button(u"matcholdkanaforms"_ustr))
36 , m_xMatchDiziDuzu(m_xBuilder->weld_check_button(u"matchdiziduzu"_ustr))
37 , m_xMatchBavaHafa(m_xBuilder->weld_check_button(u"matchbavahafa"_ustr))
38 , m_xMatchTsithichiDhizi(m_xBuilder->weld_check_button(u"matchtsithichidhizi"_ustr))
39 , m_xMatchHyuiyuByuvyu(m_xBuilder->weld_check_button(u"matchhyuiyubyuvyu"_ustr))
40 , m_xMatchSesheZeje(m_xBuilder->weld_check_button(u"matchseshezeje"_ustr))
41 , m_xMatchIaiya(m_xBuilder->weld_check_button(u"matchiaiya"_ustr))
42 , m_xMatchKiku(m_xBuilder->weld_check_button(u"matchkiku"_ustr))
43 , m_xMatchProlongedSoundMark(m_xBuilder->weld_check_button(u"matchprolongedsoundmark"_ustr))
44 , m_xIgnorePunctuation(m_xBuilder->weld_check_button(u"ignorepunctuation"_ustr))
45 , m_xIgnoreWhitespace(m_xBuilder->weld_check_button(u"ignorewhitespace"_ustr))
46 , m_xIgnoreMiddleDot(m_xBuilder->weld_check_button(u"ignoremiddledot"_ustr))
47 , nTransliterationFlags(TransliterationFlags::NONE)
48 , bSaveOptions(true)
52 SvxJSearchOptionsPage::~SvxJSearchOptionsPage()
56 std::unique_ptr<SfxTabPage> SvxJSearchOptionsPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rSet)
58 return std::make_unique<SvxJSearchOptionsPage>(pPage, pController, *rSet);
61 void SvxJSearchOptionsPage::SetTransliterationFlags( TransliterationFlags nSettings )
63 bool bVal(nSettings & TransliterationFlags::IGNORE_CASE);
64 m_xMatchCase ->set_active( bVal ); //! treat as equal uppercase/lowercase
65 bVal = bool(nSettings & TransliterationFlags::IGNORE_WIDTH);
66 m_xMatchFullHalfWidth ->set_active( bVal );
67 bVal = bool(nSettings & TransliterationFlags::IGNORE_KANA);
68 m_xMatchHiraganaKatakana ->set_active( bVal );
69 bVal = bool(nSettings & TransliterationFlags::ignoreSize_ja_JP);
70 m_xMatchContractions ->set_active( bVal );
71 bVal = bool(nSettings & TransliterationFlags::ignoreMinusSign_ja_JP);
72 m_xMatchMinusDashChoon ->set_active( bVal );
73 bVal = bool(nSettings & TransliterationFlags::ignoreIterationMark_ja_JP);
74 m_xMatchRepeatCharMarks ->set_active( bVal );
75 bVal = bool(nSettings & TransliterationFlags::ignoreTraditionalKanji_ja_JP);
76 m_xMatchVariantFormKanji ->set_active( bVal );
77 bVal = bool(nSettings & TransliterationFlags::ignoreTraditionalKana_ja_JP);
78 m_xMatchOldKanaForms ->set_active( bVal );
79 bVal = bool(nSettings & TransliterationFlags::ignoreZiZu_ja_JP);
80 m_xMatchDiziDuzu ->set_active( bVal );
81 bVal = bool(nSettings & TransliterationFlags::ignoreBaFa_ja_JP);
82 m_xMatchBavaHafa ->set_active( bVal );
83 bVal = bool(nSettings & TransliterationFlags::ignoreTiJi_ja_JP);
84 m_xMatchTsithichiDhizi ->set_active( bVal );
85 bVal = bool(nSettings & TransliterationFlags::ignoreHyuByu_ja_JP);
86 m_xMatchHyuiyuByuvyu ->set_active( bVal );
87 bVal = bool(nSettings & TransliterationFlags::ignoreSeZe_ja_JP);
88 m_xMatchSesheZeje ->set_active( bVal );
89 bVal = bool(nSettings & TransliterationFlags::ignoreIandEfollowedByYa_ja_JP);
90 m_xMatchIaiya ->set_active( bVal );
91 bVal = bool(nSettings & TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP);
92 m_xMatchKiku ->set_active( bVal );
93 bVal = bool(nSettings & TransliterationFlags::ignoreSeparator_ja_JP);
94 m_xIgnorePunctuation ->set_active( bVal );
95 bVal = bool(nSettings & TransliterationFlags::ignoreSpace_ja_JP);
96 m_xIgnoreWhitespace ->set_active( bVal );
97 bVal = bool(nSettings & TransliterationFlags::ignoreProlongedSoundMark_ja_JP);
98 m_xMatchProlongedSoundMark->set_active( bVal );
99 bVal = bool(nSettings & TransliterationFlags::ignoreMiddleDot_ja_JP);
100 m_xIgnoreMiddleDot ->set_active( bVal );
102 nTransliterationFlags = nSettings;
105 TransliterationFlags SvxJSearchOptionsPage::GetTransliterationFlags_Impl()
107 TransliterationFlags nTmp = TransliterationFlags::NONE;
108 if (m_xMatchCase->get_active()) //! treat as equal uppercase/lowercase
109 nTmp |= TransliterationFlags::IGNORE_CASE;
110 if (m_xMatchFullHalfWidth->get_active())
111 nTmp |= TransliterationFlags::IGNORE_WIDTH;
112 if (m_xMatchHiraganaKatakana->get_active())
113 nTmp |= TransliterationFlags::IGNORE_KANA;
114 if (m_xMatchContractions->get_active())
115 nTmp |= TransliterationFlags::ignoreSize_ja_JP;
116 if (m_xMatchMinusDashChoon->get_active())
117 nTmp |= TransliterationFlags::ignoreMinusSign_ja_JP;
118 if (m_xMatchRepeatCharMarks->get_active())
119 nTmp |= TransliterationFlags::ignoreIterationMark_ja_JP;
120 if (m_xMatchVariantFormKanji->get_active())
121 nTmp |= TransliterationFlags::ignoreTraditionalKanji_ja_JP;
122 if (m_xMatchOldKanaForms->get_active())
123 nTmp |= TransliterationFlags::ignoreTraditionalKana_ja_JP;
124 if (m_xMatchDiziDuzu->get_active())
125 nTmp |= TransliterationFlags::ignoreZiZu_ja_JP;
126 if (m_xMatchBavaHafa->get_active())
127 nTmp |= TransliterationFlags::ignoreBaFa_ja_JP;
128 if (m_xMatchTsithichiDhizi->get_active())
129 nTmp |= TransliterationFlags::ignoreTiJi_ja_JP;
130 if (m_xMatchHyuiyuByuvyu->get_active())
131 nTmp |= TransliterationFlags::ignoreHyuByu_ja_JP;
132 if (m_xMatchSesheZeje->get_active())
133 nTmp |= TransliterationFlags::ignoreSeZe_ja_JP;
134 if (m_xMatchIaiya->get_active())
135 nTmp |= TransliterationFlags::ignoreIandEfollowedByYa_ja_JP;
136 if (m_xMatchKiku->get_active())
137 nTmp |= TransliterationFlags::ignoreKiKuFollowedBySa_ja_JP;
138 if (m_xIgnorePunctuation->get_active())
139 nTmp |= TransliterationFlags::ignoreSeparator_ja_JP;
140 if (m_xIgnoreWhitespace->get_active())
141 nTmp |= TransliterationFlags::ignoreSpace_ja_JP;
142 if (m_xMatchProlongedSoundMark->get_active())
143 nTmp |= TransliterationFlags::ignoreProlongedSoundMark_ja_JP;
144 if (m_xIgnoreMiddleDot->get_active())
145 nTmp |= TransliterationFlags::ignoreMiddleDot_ja_JP;
147 nTransliterationFlags = nTmp;
148 return nTransliterationFlags;
152 void SvxJSearchOptionsPage::Reset( const SfxItemSet* )
154 SvtSearchOptions aOpt;
156 // read settings from configuration
157 m_xMatchCase ->set_active(!aOpt.IsMatchCase() ); //! treat as equal uppercase/lowercase
158 m_xMatchFullHalfWidth ->set_active( aOpt.IsMatchFullHalfWidthForms() );
159 m_xMatchHiraganaKatakana ->set_active( aOpt.IsMatchHiraganaKatakana() );
160 m_xMatchContractions ->set_active( aOpt.IsMatchContractions() );
161 m_xMatchMinusDashChoon ->set_active( aOpt.IsMatchMinusDashChoon() );
162 m_xMatchRepeatCharMarks ->set_active( aOpt.IsMatchRepeatCharMarks() );
163 m_xMatchVariantFormKanji ->set_active( aOpt.IsMatchVariantFormKanji() );
164 m_xMatchOldKanaForms ->set_active( aOpt.IsMatchOldKanaForms() );
165 m_xMatchDiziDuzu ->set_active( aOpt.IsMatchDiziDuzu() );
166 m_xMatchBavaHafa ->set_active( aOpt.IsMatchBavaHafa() );
167 m_xMatchTsithichiDhizi ->set_active( aOpt.IsMatchTsithichiDhizi() );
168 m_xMatchHyuiyuByuvyu ->set_active( aOpt.IsMatchHyuiyuByuvyu() );
169 m_xMatchSesheZeje ->set_active( aOpt.IsMatchSesheZeje() );
170 m_xMatchIaiya ->set_active( aOpt.IsMatchIaiya() );
171 m_xMatchKiku ->set_active( aOpt.IsMatchKiku() );
172 m_xIgnorePunctuation ->set_active( aOpt.IsIgnorePunctuation() );
173 m_xIgnoreWhitespace ->set_active( aOpt.IsIgnoreWhitespace() );
174 m_xMatchProlongedSoundMark ->set_active( aOpt.IsIgnoreProlongedSoundMark() );
175 m_xIgnoreMiddleDot ->set_active( aOpt.IsIgnoreMiddleDot() );
177 nTransliterationFlags = GetTransliterationFlags_Impl();
178 DBG_ASSERT( nTransliterationFlags == aOpt.GetTransliterationFlags(),
179 "Transliteration settings different" );
181 m_xMatchCase ->save_state();
182 m_xMatchFullHalfWidth ->save_state();
183 m_xMatchHiraganaKatakana ->save_state();
184 m_xMatchContractions ->save_state();
185 m_xMatchMinusDashChoon ->save_state();
186 m_xMatchRepeatCharMarks ->save_state();
187 m_xMatchVariantFormKanji ->save_state();
188 m_xMatchOldKanaForms ->save_state();
189 m_xMatchDiziDuzu ->save_state();
190 m_xMatchBavaHafa ->save_state();
191 m_xMatchTsithichiDhizi ->save_state();
192 m_xMatchHyuiyuByuvyu ->save_state();
193 m_xMatchSesheZeje ->save_state();
194 m_xMatchIaiya ->save_state();
195 m_xMatchKiku ->save_state();
196 m_xIgnorePunctuation ->save_state();
197 m_xIgnoreWhitespace ->save_state();
198 m_xMatchProlongedSoundMark ->save_state();
199 m_xIgnoreMiddleDot ->save_state();
202 OUString SvxJSearchOptionsPage::GetAllStrings()
204 OUString sAllStrings;
205 OUString labels[] = { u"label1"_ustr, u"label2"_ustr };
207 for (const auto& label : labels)
209 if (const auto pString = m_xBuilder->weld_label(label))
210 sAllStrings += pString->get_label() + " ";
213 OUString checkButton[] = { u"matchcase"_ustr,
214 u"matchfullhalfwidth"_ustr,
215 u"matchhiraganakatakana"_ustr,
216 u"matchcontractions"_ustr,
217 u"matchminusdashchoon"_ustr,
218 u"matchrepeatcharmarks"_ustr,
219 u"matchvariantformkanji"_ustr,
220 u"matcholdkanaforms"_ustr,
221 u"ignorepunctuation"_ustr,
222 u"ignorewhitespace"_ustr,
223 u"matchdiziduzu"_ustr,
224 u"matchbavahafa"_ustr,
225 u"matchtsithichidhizi"_ustr,
226 u"matchhyuiyubyuvyu"_ustr,
227 u"matchseshezeje"_ustr,
228 u"matchiaiya"_ustr,
229 u"matchkiku"_ustr,
230 u"matchprolongedsoundmark"_ustr,
231 u"ignoremiddledot"_ustr };
233 for (const auto& check : checkButton)
235 if (const auto pString = m_xBuilder->weld_check_button(check))
236 sAllStrings += pString->get_label() + " ";
239 return sAllStrings.replaceAll("_", "");
242 bool SvxJSearchOptionsPage::FillItemSet( SfxItemSet* )
244 TransliterationFlags nOldVal = nTransliterationFlags;
245 nTransliterationFlags = GetTransliterationFlags_Impl();
246 bool bModified = nOldVal != nTransliterationFlags;
248 if (!bSaveOptions)
249 return bModified;
251 bModified = false;
252 SvtSearchOptions aOpt;
253 bool bNewVal, bChanged;
255 bNewVal = m_xMatchCase->get_active(); //! treat as equal uppercase/lowercase
256 bChanged = m_xMatchCase->get_state_changed_from_saved();
257 if (bChanged)
259 aOpt.SetMatchCase(!bNewVal );
260 bModified = true;
262 bNewVal = m_xMatchFullHalfWidth->get_active();
263 bChanged = m_xMatchFullHalfWidth->get_state_changed_from_saved();
264 if (bChanged)
266 aOpt.SetMatchFullHalfWidthForms( bNewVal );
267 bModified = true;
269 bNewVal = m_xMatchHiraganaKatakana->get_active();
270 bChanged = m_xMatchHiraganaKatakana->get_state_changed_from_saved();
271 if (bChanged)
273 aOpt.SetMatchHiraganaKatakana( bNewVal );
274 bModified = true;
276 bNewVal = m_xMatchContractions->get_active();
277 bChanged = m_xMatchContractions->get_state_changed_from_saved();
278 if (bChanged)
280 aOpt.SetMatchContractions( bNewVal );
281 bModified = true;
283 bNewVal = m_xMatchMinusDashChoon->get_active();
284 bChanged = m_xMatchMinusDashChoon->get_state_changed_from_saved();
285 if (bChanged)
287 aOpt.SetMatchMinusDashChoon( bNewVal );
288 bModified = true;
290 bNewVal = m_xMatchRepeatCharMarks->get_active();
291 bChanged = m_xMatchRepeatCharMarks->get_state_changed_from_saved();
292 if (bChanged)
294 aOpt.SetMatchRepeatCharMarks( bNewVal );
295 bModified = true;
297 bNewVal = m_xMatchVariantFormKanji->get_active();
298 bChanged = m_xMatchVariantFormKanji->get_state_changed_from_saved();
299 if (bChanged)
301 aOpt.SetMatchVariantFormKanji( bNewVal );
302 bModified = true;
304 bNewVal = m_xMatchOldKanaForms->get_active();
305 bChanged = m_xMatchOldKanaForms->get_state_changed_from_saved();
306 if (bChanged)
308 aOpt.SetMatchOldKanaForms( bNewVal );
309 bModified = true;
311 bNewVal = m_xMatchDiziDuzu->get_active();
312 bChanged = m_xMatchDiziDuzu->get_state_changed_from_saved();
313 if (bChanged)
315 aOpt.SetMatchDiziDuzu( bNewVal );
316 bModified = true;
318 bNewVal = m_xMatchBavaHafa->get_active();
319 bChanged = m_xMatchBavaHafa->get_state_changed_from_saved();
320 if (bChanged)
322 aOpt.SetMatchBavaHafa( bNewVal );
323 bModified = true;
325 bNewVal = m_xMatchTsithichiDhizi->get_active();
326 bChanged = m_xMatchTsithichiDhizi->get_state_changed_from_saved();
327 if (bChanged)
329 aOpt.SetMatchTsithichiDhizi( bNewVal );
330 bModified = true;
332 bNewVal = m_xMatchHyuiyuByuvyu->get_active();
333 bChanged = m_xMatchHyuiyuByuvyu->get_state_changed_from_saved();
334 if (bChanged)
336 aOpt.SetMatchHyuiyuByuvyu( bNewVal );
337 bModified = true;
339 bNewVal = m_xMatchSesheZeje->get_active();
340 bChanged = m_xMatchSesheZeje->get_state_changed_from_saved();
341 if (bChanged)
343 aOpt.SetMatchSesheZeje( bNewVal );
344 bModified = true;
346 bNewVal = m_xMatchIaiya->get_active();
347 bChanged = m_xMatchIaiya->get_state_changed_from_saved();
348 if (bChanged)
350 aOpt.SetMatchIaiya( bNewVal );
351 bModified = true;
353 bNewVal = m_xMatchKiku->get_active();
354 bChanged = m_xMatchKiku->get_state_changed_from_saved();
355 if (bChanged)
357 aOpt.SetMatchKiku( bNewVal );
358 bModified = true;
360 bNewVal = m_xIgnorePunctuation->get_active();
361 bChanged = m_xIgnorePunctuation->get_state_changed_from_saved();
362 if (bChanged)
364 aOpt.SetIgnorePunctuation( bNewVal );
365 bModified = true;
367 bNewVal = m_xIgnoreWhitespace->get_active();
368 bChanged = m_xIgnoreWhitespace->get_state_changed_from_saved();
369 if (bChanged)
371 aOpt.SetIgnoreWhitespace( bNewVal );
372 bModified = true;
374 bNewVal = m_xMatchProlongedSoundMark->get_active();
375 bChanged = m_xMatchProlongedSoundMark->get_state_changed_from_saved();
376 if (bChanged)
378 aOpt.SetIgnoreProlongedSoundMark( bNewVal );
379 bModified = true;
381 bNewVal = m_xIgnoreMiddleDot->get_active();
382 bChanged = m_xIgnoreMiddleDot->get_state_changed_from_saved();
383 if (bChanged)
385 aOpt.SetIgnoreMiddleDot( bNewVal );
386 bModified = true;
389 if (bModified)
390 aOpt.Commit();
392 return bModified;
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */