20#include <osl/file.hxx>
21#include <rtl/bootstrap.hxx>
22#include <config_folders.h>
32#include <officecfg/Office/Common.hxx>
40 bool bTextIsFreeForm = officecfg::Office::Common::Classification::IntellectualPropertyTextInputIsFreeForm::get();
45 if (rKeyEvent.GetKeyCode().IsMod3()
46 || rKeyEvent.GetKeyCode().IsMod2()
47 || rKeyEvent.GetKeyCode().IsMod1())
52 switch (rKeyEvent.GetKeyCode().GetCode())
72constexpr size_t RECENTLY_USED_LIMIT = 5;
74constexpr OUStringLiteral constRecentlyUsedFileName(u
"recentlyUsed.xml");
76OUString lcl_getClassificationUserPath()
78 OUString sPath(
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE(
"bootstrap")
":UserInstallation}/user/classification/");
79 rtl::Bootstrap::expandMacros(sPath);
87 if (pPool->
Which() == EE_FEATURE_FIELD)
95 osl::File aFile(sFilename);
96 osl::FileBase::RC eRC = aFile.open(osl_File_OpenFlag_Read);
97 return osl::FileBase::E_None == eRC;
102 if (rsType ==
"CATEGORY")
104 else if (rsType ==
"INTELLECTUAL_PROPERTY_PART")
106 else if (rsType ==
"MARKING")
108 else if (rsType ==
"PARAGRAPH")
110 else if (rsType ==
"TEXT")
122 return "CATEGORY";
break;
124 return "MARKING";
break;
126 return "TEXT";
break;
128 return "INTELLECTUAL_PROPERTY_PART";
break;
130 return "PARAGRAPH";
break;
136 std::vector<ClassificationResult>
const & rResultCollection)
138 for (ClassificationResult
const & rResult : rResultCollection)
141 OUString
sType = classificationTypeToString(rResult.meType);
144 rXmlWriter.
content(rResult.msName);
147 rXmlWriter.
content(rResult.msAbbreviatedName);
150 rXmlWriter.
content(rResult.msIdentifier);
159 const bool bPerParagraph, std::function<
void()> aParagraphSignHandler)
160 : GenericDialogController(pParent,
"svx/ui/classificationdialog.ui",
"AdvancedDocumentClassificationDialog")
161 , maHelper(rDocProps)
162 , maInternationalHelper(rDocProps, false)
163 , m_bPerParagraph(bPerParagraph)
164 , m_aParagraphSignHandler(
std::move(aParagraphSignHandler))
165 , m_nCurrentSelectedCategory(-1)
166 , m_xOkButton(m_xBuilder->weld_button(
"ok"))
167 , m_xSignButton(m_xBuilder->weld_button(
"signButton"))
168 , m_xToolBox(m_xBuilder->weld_toggle_button(
"toolbox"))
169 , m_xRecentlyUsedListBox(m_xBuilder->weld_combo_box(
"recentlyUsedCB"))
170 , m_xClassificationListBox(m_xBuilder->weld_combo_box(
"classificationCB"))
171 , m_xInternationalClassificationListBox(m_xBuilder->weld_combo_box(
"internationalClassificationCB"))
172 , m_xMarkingLabel(m_xBuilder->weld_label(
"markingLabel"))
173 , m_xMarkingListBox(m_xBuilder->weld_tree_view(
"markingLB"))
174 , m_xIntellectualPropertyPartListBox(m_xBuilder->weld_tree_view(
"intellectualPropertyPartLB"))
175 , m_xIntellectualPropertyPartNumberListBox(m_xBuilder->weld_tree_view(
"intellectualPropertyPartNumberLB"))
176 , m_xIntellectualPropertyPartAddButton(m_xBuilder->weld_button(
"intellectualPropertyPartAddButton"))
177 , m_xIntellectualPropertyPartEdit(m_xBuilder->weld_entry(
"intellectualPropertyPartEntry"))
178 , m_xIntellectualPropertyExpander(m_xBuilder->weld_expander(
"intellectualPropertyExpander"))
180 , m_xEditWindowWeld(new
weld::CustomWeld(*m_xBuilder,
"classificationEditWindow", *m_xEditWindow))
241 if (officecfg::Office::Common::Classification::IntellectualPropertySectionExpanded::get())
261 OUString rDescription = OUString::number(nNumber) +
": " + rContentRepresentation;
272 m_nAsyncExpandEvent =
nullptr;
273 m_xIntellectualPropertyExpander->set_expanded(
true);
304 OUString sPath = lcl_getClassificationUserPath();
305 OUString sFilePath(sPath + constRecentlyUsedFileName);
312 if (!aWalker.
open(&aFileStream))
315 if (aWalker.
name() !=
"recentlyUsedClassifications")
321 if (aWalker.
name() ==
"elementGroup")
323 std::vector<ClassificationResult> aResults;
329 if (aWalker.
name() ==
"element")
333 OUString sAbbreviatedString;
334 OUString sIdentifier;
344 if (aWalker.
name() ==
"string")
346 sString = OStringToOUString(aWalker.
content(), RTL_TEXTENCODING_UTF8);
348 else if (aWalker.
name() ==
"abbreviatedString")
350 sAbbreviatedString = OStringToOUString(aWalker.
content(), RTL_TEXTENCODING_UTF8);
352 else if (aWalker.
name() ==
"identifier")
354 sIdentifier = OStringToOUString(aWalker.
content(), RTL_TEXTENCODING_UTF8);
360 aResults.push_back({
eType, sString, sAbbreviatedString, sIdentifier });
375 OUString sPath = lcl_getClassificationUserPath();
376 osl::Directory::createPath(sPath);
377 OUString sFilePath(sPath + constRecentlyUsedFileName);
379 std::unique_ptr<SvStream> pStream;
380 pStream.reset(
new SvFileStream(sFilePath, StreamMode::STD_READWRITE | StreamMode::TRUNC));
391 writeResultToXml(aXmlWriter,
getResult());
402 writeResultToXml(aXmlWriter, rResultCollection);
414 sal_Int32 nParagraph = -1;
419 switch (rClassificationResult.meType)
423 m_xEditWindow->getEditView().InsertText(rClassificationResult.msName);
430 if (rClassificationResult.msName.isEmpty())
433 sName = rClassificationResult.msName;
435 OUString sAbbreviatedName = rClassificationResult.msAbbreviatedName;
436 if (sAbbreviatedName.isEmpty())
443 insertField(rClassificationResult.meType, sAbbreviatedName,
sName, rClassificationResult.msIdentifier);
450 insertField(rClassificationResult.meType, rClassificationResult.msName, rClassificationResult.msName, rClassificationResult.msIdentifier);
456 insertField(rClassificationResult.meType, rClassificationResult.msName, rClassificationResult.msName, rClassificationResult.msIdentifier);
488 for (sal_Int32 nParagraph = 0; nParagraph < rEditEngine.
GetParagraphCount(); ++nParagraph)
490 sal_uInt16 nFieldCount = rEditEngine.
GetFieldCount(nParagraph);
491 for (sal_uInt16 nField = 0; nField < nFieldCount; ++nField)
514 std::vector<ClassificationResult> aClassificationResults;
519 sal_Int32 nCurrentParagraph = -1;
521 std::vector<editeng::Section> aSections;
522 pEditText->GetAllSections(aSections);
539 OUString sWeightProperty =
"NORMAL";
541 sWeightProperty =
"BOLD";
550 const OUString sDisplayString = rEdEngine.
GetText(aSelection);
551 if (!sDisplayString.isEmpty())
555 if (pClassificationField)
557 aClassificationResults.push_back({ pClassificationField->
meType, pClassificationField->
msFullClassName,
567 return aClassificationResults;
572 const sal_Int32 nSelected = rBox.get_active();
573 if (nSelected < 0 || m_nCurrentSelectedCategory == nSelected)
576 std::unique_ptr<EditTextObject> pEditText(m_xEditWindow->getEditEngine().CreateTextObject());
577 std::vector<editeng::Section> aSections;
578 pEditText->GetAllSections(aSections);
581 bool bReplaceExisting =
false;
595 bReplaceExisting =
true;
600 if (bReplaceExisting)
601 m_xEditWindow->getEditView().SetSelection(aExistingFieldSelection);
603 insertCategoryField(nSelected);
606 m_xInternationalClassificationListBox->set_active(nSelected);
607 m_xClassificationListBox->set_active(nSelected);
608 m_nCurrentSelectedCategory = nSelected;
613 sal_Int32 nSelected = rBox.get_selected_index();
616 const OUString aString = maHelper.GetMarkings()[nSelected];
624 sal_Int32 nSelected = rBox.get_selected_index();
627 OUString sString = maHelper.GetIntellectualPropertyPartNumbers()[nSelected];
628 m_xIntellectualPropertyPartEdit->replace_selection(sString);
629 m_xIntellectualPropertyPartEdit->grab_focus();
636 sal_Int32 nSelected = rBox.get_active();
639 m_xEditWindow->getEditEngine().Clear();
640 readIn(m_aRecentlyUsedValuesCollection[nSelected]);
646 const sal_Int32 nSelected = rBox.get_selected_index();
649 const OUString sString = maHelper.GetIntellectualPropertyParts()[nSelected];
650 m_xIntellectualPropertyPartEdit->replace_selection(sString);
651 m_xIntellectualPropertyPartEdit->grab_focus();
658 if (&rButton == m_xSignButton.get())
660 m_aParagraphSignHandler();
662 else if (&rButton == m_xIntellectualPropertyPartAddButton.get())
664 const OUString sString = m_xIntellectualPropertyPartEdit->get_text();
677 m_xEditWindow->InvertSelectionWeight();
682 toggleWidgetsDependingOnCategory();
688 officecfg::Office::Common::Classification::IntellectualPropertySectionExpanded::set(rExpander.get_expanded(), aConfigurationChanges);
689 aConfigurationChanges->commit();
Reference< XExecutableDialog > m_xDialog
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
OUString GetText(LineEnd eEnd=LINEEND_LF) const
std::unique_ptr< EditTextObject > CreateTextObject()
sal_Int32 GetParagraphCount() const
EFieldInfo GetFieldInfo(sal_Int32 nPara, sal_uInt16 nField) const
sal_uInt16 GetFieldCount(sal_Int32 nPara) const
virtual void SetParaAttribs(sal_Int32 nPara, const SfxItemSet &rSet)
const SfxItemSet & GetParaAttribs(sal_Int32 nPara) const
std::vector< OUString > const & GetIntellectualPropertyParts() const
std::vector< OUString > const & GetIntellectualPropertyPartNumbers() const
std::vector< OUString > GetBACIdentifiers()
const OUString & GetAbbreviatedBACName(const OUString &sFullName)
OUString GetBACNameForIdentifier(std::u16string_view sIdentifier)
std::vector< OUString > const & GetMarkings() const
std::vector< OUString > GetAbbreviatedBACNames()
std::vector< OUString > GetBACNames()
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SvxFieldData * GetField() const
FontWeight GetWeight() const
static std::shared_ptr< ConfigurationChanges > create()
void readIn(std::vector< ClassificationResult > const &rInput)
std::unique_ptr< weld::Label > m_xMarkingLabel
std::unique_ptr< weld::Button > m_xIntellectualPropertyPartAddButton
std::unique_ptr< weld::TreeView > m_xMarkingListBox
std::vector< ClassificationResult > getResult()
std::vector< ClassificationResult > m_aInitialValues
void insertCategoryField(sal_Int32 nID)
std::vector< std::vector< ClassificationResult > > m_aRecentlyUsedValuesCollection
std::unique_ptr< weld::TreeView > m_xIntellectualPropertyPartListBox
sal_Int32 m_nCurrentSelectedCategory
std::unique_ptr< weld::Button > m_xOkButton
std::unique_ptr< weld::ComboBox > m_xClassificationListBox
void toggleWidgetsDependingOnCategory()
ClassificationDialog(weld::Window *pParent, const css::uno::Reference< css::document::XDocumentProperties > &rDocProps, bool bPerParagraph, std::function< void()> aParagraphSignHandler=[]() {})
ImplSVEvent * m_nAsyncExpandEvent
SfxClassificationHelper maHelper
std::unique_ptr< weld::Button > m_xSignButton
SfxClassificationHelper maInternationalHelper
std::unique_ptr< weld::TreeView > m_xIntellectualPropertyPartNumberListBox
std::unique_ptr< ClassificationEditView > m_xEditWindow
void insertField(ClassificationType eType, OUString const &rString, OUString const &rFullString, OUString const &rIdentifier=OUString())
std::unique_ptr< weld::ComboBox > m_xInternationalClassificationListBox
std::unique_ptr< weld::Expander > m_xIntellectualPropertyExpander
~ClassificationDialog() override
void setupValues(std::vector< ClassificationResult > &&rInput)
std::unique_ptr< weld::Entry > m_xIntellectualPropertyPartEdit
const bool m_bPerParagraph
std::unique_ptr< weld::ToggleButton > m_xToolBox
std::unique_ptr< weld::ComboBox > m_xRecentlyUsedListBox
ClassificationType meType
#define SAL_CONFIGFILE(name)
constexpr TypedWhichId< SvxFieldItem > EE_FEATURE_FIELD(EE_FEATURE_NOTCONV+1)
constexpr TypedWhichId< SvxWeightItem > EE_CHAR_WEIGHT(EE_CHAR_START+4)
bool fileExists(const OString &fileName)
constexpr sal_uInt16 KEY_SEMICOLON
constexpr sal_uInt16 KEY_DELETE
constexpr sal_uInt16 KEY_SPACE
constexpr sal_uInt16 KEY_DIVIDE
constexpr sal_uInt16 KEY_BACKSPACE
#define LINK(Instance, Class, Member)
OUString convertClassificationResultToString(std::vector< svx::ClassificationResult > const &rResults)
IMPL_STATIC_LINK(ClassificationDialog, KeyInput, const KeyEvent &, rKeyEvent, bool)
IMPL_LINK(HangulHanjaConversionDialog, ClickByCharacterHdl, weld::Toggleable &, rBox, void)
IMPL_LINK_NOARG(SuggestionDisplay, SelectSuggestionValueSetHdl, ValueSet *, void)
@ INTELLECTUAL_PROPERTY_PART
std::unique_ptr< SvxFieldItem > pFieldItem
std::vector< const SfxPoolItem * > maAttributes