20#include <osl/file.hxx>
21#include <rtl/bootstrap.hxx>
22#include <config_folders.h>
31#include <officecfg/Office/Common.hxx>
39 bool bTextIsFreeForm = officecfg::Office::Common::Classification::IntellectualPropertyTextInputIsFreeForm::get();
44 if (rKeyEvent.GetKeyCode().IsMod3()
45 || rKeyEvent.GetKeyCode().IsMod2()
46 || rKeyEvent.GetKeyCode().IsMod1())
51 switch (rKeyEvent.GetKeyCode().GetCode())
71constexpr size_t RECENTLY_USED_LIMIT = 5;
73constexpr OUStringLiteral constRecentlyUsedFileName(u
"recentlyUsed.xml");
75OUString lcl_getClassificationUserPath()
77 OUString sPath(
"${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
"/" SAL_CONFIGFILE(
"bootstrap")
":UserInstallation}/user/classification/");
78 rtl::Bootstrap::expandMacros(sPath);
86 if (pPool->
Which() == EE_FEATURE_FIELD)
94 osl::File aFile(sFilename);
95 osl::FileBase::RC eRC = aFile.open(osl_File_OpenFlag_Read);
96 return osl::FileBase::E_None == eRC;
101 if (rsType ==
"CATEGORY")
103 else if (rsType ==
"INTELLECTUAL_PROPERTY_PART")
105 else if (rsType ==
"MARKING")
107 else if (rsType ==
"PARAGRAPH")
109 else if (rsType ==
"TEXT")
121 return "CATEGORY";
break;
123 return "MARKING";
break;
125 return "TEXT";
break;
127 return "INTELLECTUAL_PROPERTY_PART";
break;
129 return "PARAGRAPH";
break;
135 std::vector<ClassificationResult>
const & rResultCollection)
137 for (ClassificationResult
const & rResult : rResultCollection)
140 OUString
sType = classificationTypeToString(rResult.meType);
143 rXmlWriter.
content(rResult.msName);
146 rXmlWriter.
content(rResult.msAbbreviatedName);
149 rXmlWriter.
content(rResult.msIdentifier);
158 : GenericDialogController(pParent,
"svx/ui/classificationdialog.ui",
"AdvancedDocumentClassificationDialog")
160 , maInternationalHelper(
SfxObjectShell::Current()->getDocProperties(), false)
161 , m_bPerParagraph(bPerParagraph)
162 , m_aParagraphSignHandler(rParagraphSignHandler)
163 , m_nCurrentSelectedCategory(-1)
164 , m_xOkButton(m_xBuilder->weld_button(
"ok"))
165 , m_xSignButton(m_xBuilder->weld_button(
"signButton"))
166 , m_xToolBox(m_xBuilder->weld_toggle_button(
"toolbox"))
167 , m_xRecentlyUsedListBox(m_xBuilder->weld_combo_box(
"recentlyUsedCB"))
168 , m_xClassificationListBox(m_xBuilder->weld_combo_box(
"classificationCB"))
169 , m_xInternationalClassificationListBox(m_xBuilder->weld_combo_box(
"internationalClassificationCB"))
170 , m_xMarkingLabel(m_xBuilder->weld_label(
"markingLabel"))
171 , m_xMarkingListBox(m_xBuilder->weld_tree_view(
"markingLB"))
172 , m_xIntellectualPropertyPartListBox(m_xBuilder->weld_tree_view(
"intellectualPropertyPartLB"))
173 , m_xIntellectualPropertyPartNumberListBox(m_xBuilder->weld_tree_view(
"intellectualPropertyPartNumberLB"))
174 , m_xIntellectualPropertyPartAddButton(m_xBuilder->weld_button(
"intellectualPropertyPartAddButton"))
175 , m_xIntellectualPropertyPartEdit(m_xBuilder->weld_entry(
"intellectualPropertyPartEntry"))
176 , m_xIntellectualPropertyExpander(m_xBuilder->weld_expander(
"intellectualPropertyExpander"))
178 , m_xEditWindowWeld(new
weld::CustomWeld(*m_xBuilder,
"classificationEditWindow", *m_xEditWindow))
239 if (officecfg::Office::Common::Classification::IntellectualPropertySectionExpanded::get())
259 OUString rDescription = OUString::number(nNumber) +
": " + rContentRepresentation;
270 m_nAsyncExpandEvent =
nullptr;
271 m_xIntellectualPropertyExpander->set_expanded(
true);
302 OUString sPath = lcl_getClassificationUserPath();
303 OUString sFilePath(sPath + constRecentlyUsedFileName);
310 if (!aWalker.
open(&aFileStream))
313 if (aWalker.
name() !=
"recentlyUsedClassifications")
319 if (aWalker.
name() ==
"elementGroup")
321 std::vector<ClassificationResult> aResults;
327 if (aWalker.
name() ==
"element")
331 OUString sAbbreviatedString;
332 OUString sIdentifier;
342 if (aWalker.
name() ==
"string")
344 sString = OStringToOUString(aWalker.
content(), RTL_TEXTENCODING_UTF8);
346 else if (aWalker.
name() ==
"abbreviatedString")
348 sAbbreviatedString = OStringToOUString(aWalker.
content(), RTL_TEXTENCODING_UTF8);
350 else if (aWalker.
name() ==
"identifier")
352 sIdentifier = OStringToOUString(aWalker.
content(), RTL_TEXTENCODING_UTF8);
358 aResults.push_back({
eType, sString, sAbbreviatedString, sIdentifier });
373 OUString sPath = lcl_getClassificationUserPath();
374 osl::Directory::createPath(sPath);
375 OUString sFilePath(sPath + constRecentlyUsedFileName);
377 std::unique_ptr<SvStream> pStream;
378 pStream.reset(
new SvFileStream(sFilePath, StreamMode::STD_READWRITE | StreamMode::TRUNC));
389 writeResultToXml(aXmlWriter,
getResult());
400 writeResultToXml(aXmlWriter, rResultCollection);
412 sal_Int32 nParagraph = -1;
417 switch (rClassificationResult.meType)
421 m_xEditWindow->getEditView().InsertText(rClassificationResult.msName);
428 if (rClassificationResult.msName.isEmpty())
431 sName = rClassificationResult.msName;
433 OUString sAbbreviatedName = rClassificationResult.msAbbreviatedName;
434 if (sAbbreviatedName.isEmpty())
441 insertField(rClassificationResult.meType, sAbbreviatedName,
sName, rClassificationResult.msIdentifier);
448 insertField(rClassificationResult.meType, rClassificationResult.msName, rClassificationResult.msName, rClassificationResult.msIdentifier);
454 insertField(rClassificationResult.meType, rClassificationResult.msName, rClassificationResult.msName, rClassificationResult.msIdentifier);
486 for (sal_Int32 nParagraph = 0; nParagraph < rEditEngine.
GetParagraphCount(); ++nParagraph)
488 sal_uInt16 nFieldCount = rEditEngine.
GetFieldCount(nParagraph);
489 for (sal_uInt16 nField = 0; nField < nFieldCount; ++nField)
512 std::vector<ClassificationResult> aClassificationResults;
517 sal_Int32 nCurrentParagraph = -1;
519 std::vector<editeng::Section> aSections;
520 pEditText->GetAllSections(aSections);
537 OUString sWeightProperty =
"NORMAL";
539 sWeightProperty =
"BOLD";
548 const OUString sDisplayString = rEdEngine.
GetText(aSelection);
549 if (!sDisplayString.isEmpty())
553 if (pClassificationField)
555 aClassificationResults.push_back({ pClassificationField->
meType, pClassificationField->
msFullClassName,
565 return aClassificationResults;
570 const sal_Int32 nSelected = rBox.get_active();
571 if (nSelected < 0 || m_nCurrentSelectedCategory == nSelected)
574 std::unique_ptr<EditTextObject> pEditText(m_xEditWindow->getEditEngine().CreateTextObject());
575 std::vector<editeng::Section> aSections;
576 pEditText->GetAllSections(aSections);
579 bool bReplaceExisting =
false;
593 bReplaceExisting =
true;
598 if (bReplaceExisting)
599 m_xEditWindow->getEditView().SetSelection(aExistingFieldSelection);
601 insertCategoryField(nSelected);
604 m_xInternationalClassificationListBox->set_active(nSelected);
605 m_xClassificationListBox->set_active(nSelected);
606 m_nCurrentSelectedCategory = nSelected;
611 sal_Int32 nSelected = rBox.get_selected_index();
614 const OUString aString = maHelper.GetMarkings()[nSelected];
622 sal_Int32 nSelected = rBox.get_selected_index();
625 OUString sString = maHelper.GetIntellectualPropertyPartNumbers()[nSelected];
626 m_xIntellectualPropertyPartEdit->replace_selection(sString);
627 m_xIntellectualPropertyPartEdit->grab_focus();
634 sal_Int32 nSelected = rBox.get_active();
637 m_xEditWindow->getEditEngine().Clear();
638 readIn(m_aRecentlyUsedValuesCollection[nSelected]);
644 const sal_Int32 nSelected = rBox.get_selected_index();
647 const OUString sString = maHelper.GetIntellectualPropertyParts()[nSelected];
648 m_xIntellectualPropertyPartEdit->replace_selection(sString);
649 m_xIntellectualPropertyPartEdit->grab_focus();
656 if (&rButton == m_xSignButton.get())
658 m_aParagraphSignHandler();
660 else if (&rButton == m_xIntellectualPropertyPartAddButton.get())
662 const OUString sString = m_xIntellectualPropertyPartEdit->get_text();
675 m_xEditWindow->InvertSelectionWeight();
680 toggleWidgetsDependingOnCategory();
686 officecfg::Office::Common::Classification::IntellectualPropertySectionExpanded::set(rExpander.get_expanded(), aConfigurationChanges);
687 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)
ClassificationDialog(weld::Window *pParent, bool bPerParagraph, const std::function< void()> &rParagraphSignHandler=[]() {})
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()
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