diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-11-01 19:16:54 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2017-11-02 07:30:31 +0100 |
commit | aa73ca2e5420dfceeccf19d7e2d5d4f367dd01da (patch) | |
tree | 857cee0098ec0de68303e06d2808e70d9be256d3 /svx | |
parent | a0a287f566e548177847bdb69cba230089b44e54 (diff) |
TSCP: add recently used to advanced classification dialog
Change-Id: Ic084104b28dbcc439d98cd08a89a7ddc6f291878
Reviewed-on: https://gerrit.libreoffice.org/44158
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/dialog/ClassificationDialog.cxx | 149 | ||||
-rw-r--r-- | svx/uiconfig/ui/classificationdialog.ui | 43 |
2 files changed, 129 insertions, 63 deletions
diff --git a/svx/source/dialog/ClassificationDialog.cxx b/svx/source/dialog/ClassificationDialog.cxx index db5e7639ef9c..20dc952a47d1 100644 --- a/svx/source/dialog/ClassificationDialog.cxx +++ b/svx/source/dialog/ClassificationDialog.cxx @@ -27,6 +27,8 @@ namespace svx { namespace { +constexpr size_t RECENTLY_USED_LIMIT = 5; + const SvxFieldItem* findField(editeng::Section const & rSection) { for (SfxPoolItem const * pPool : rSection.maAttributes) @@ -61,6 +63,59 @@ bool stringToclassificationType(OString const & rsType, svx::ClassificationType return true; } +OUString getStringRepresentation(std::vector<ClassificationResult> const & rResults) +{ + OUString sRepresentation = ""; + for (ClassificationResult const & rResult : rResults) + { + switch (rResult.meType) + { + case svx::ClassificationType::CATEGORY: + case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: + case svx::ClassificationType::MARKING: + case svx::ClassificationType::TEXT: + sRepresentation += rResult.msString; + break; + + case svx::ClassificationType::PARAGRAPH: + sRepresentation += " "; + break; + } + } + return sRepresentation; +} + +void writeResultToXml(tools::XmlWriter & rXmlWriter, + std::vector<ClassificationResult> const & rResultCollection) +{ + for (ClassificationResult const & rResult : rResultCollection) + { + rXmlWriter.startElement("element"); + OUString sType; + switch(rResult.meType) + { + case svx::ClassificationType::CATEGORY: + sType = "CATEGORY"; break; + case svx::ClassificationType::MARKING: + sType = "MARKING"; break; + case svx::ClassificationType::TEXT: + sType = "TEXT"; break; + case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: + sType = "INTELLECTUAL_PROPERTY_PART"; break; + case svx::ClassificationType::PARAGRAPH: + sType = "PARAGRAPH"; break; + } + rXmlWriter.attribute("type", sType); + rXmlWriter.startElement("string"); + rXmlWriter.content(rResult.msString); + rXmlWriter.endElement(); + rXmlWriter.startElement("abbreviatedString"); + rXmlWriter.content(rResult.msAbbreviatedString); + rXmlWriter.endElement(); + rXmlWriter.endElement(); + } +} + } // end anonymous namespace ClassificationDialog::ClassificationDialog(vcl::Window* pParent, const bool bPerParagraph, const std::function<void()>& rParagraphSignHandler) @@ -73,6 +128,7 @@ ClassificationDialog::ClassificationDialog(vcl::Window* pParent, const bool bPer get(m_pEditWindow, "classificationEditWindow"); get(m_pSignButton, "signButton"); get(m_pBoldButton, "boldButton"); + get(m_pRecentlyUsedListBox, "recentlyUsedCB"); get(m_pClassificationListBox, "classificationCB"); get(m_pInternationalClassificationListBox, "internationalClassificationCB"); get(m_pMarkingListBox, "markingCB"); @@ -111,6 +167,8 @@ ClassificationDialog::ClassificationDialog(vcl::Window* pParent, const bool bPer for (const OUString& rName : maHelper.GetIntellectualPropertyParts()) m_pIntellectualPropertyPartListBox->InsertEntry(rName); m_pIntellectualPropertyPartListBox->EnableAutoSize(true); + + m_pRecentlyUsedListBox->SetSelectHdl(LINK(this, ClassificationDialog, SelectRecentlyUsedHdl)); } ClassificationDialog::~ClassificationDialog() @@ -123,6 +181,7 @@ void ClassificationDialog::dispose() m_pEditWindow.clear(); m_pSignButton.clear(); m_pBoldButton.clear(); + m_pRecentlyUsedListBox.clear(); m_pClassificationListBox.clear(); m_pInternationalClassificationListBox.clear(); m_pMarkingListBox.clear(); @@ -139,6 +198,28 @@ short ClassificationDialog::Execute() readRecentlyUsed(); readIn(m_aInitialValues); + int nNumber = 1; + if (m_aRecentlyUsedValuesCollection.empty()) + { + m_pRecentlyUsedListBox->Disable(); + } + else + { + for (std::vector<ClassificationResult> const & rResults : m_aRecentlyUsedValuesCollection) + { + OUString rContentRepresentation = getStringRepresentation(rResults); + OUString rDescription = OUString::number(nNumber) + ": "; + nNumber++; + + if (rContentRepresentation.getLength() >= 18) + rDescription += rContentRepresentation.copy(0, 17) + "..."; + else + rDescription += rContentRepresentation; + + m_pRecentlyUsedListBox->InsertEntry(rDescription); + } + } + short nResult = ModalDialog::Execute(); if (nResult == RET_OK) { @@ -246,67 +327,19 @@ void ClassificationDialog::writeRecentlyUsed() aXmlWriter.startElement("elementGroup"); - for (ClassificationResult const & rResult : getResult()) - { - aXmlWriter.startElement("element"); - OUString sType; - switch(rResult.meType) - { - case svx::ClassificationType::CATEGORY: - sType = "CATEGORY"; break; - case svx::ClassificationType::MARKING: - sType = "MARKING"; break; - case svx::ClassificationType::TEXT: - sType = "TEXT"; break; - case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: - sType = "INTELLECTUAL_PROPERTY_PART"; break; - case svx::ClassificationType::PARAGRAPH: - sType = "PARAGRAPH"; break; - } - aXmlWriter.attribute("type", sType); - aXmlWriter.startElement("string"); - aXmlWriter.content(rResult.msString); - aXmlWriter.endElement(); - aXmlWriter.startElement("abbreviatedString"); - aXmlWriter.content(rResult.msAbbreviatedString); - aXmlWriter.endElement(); - aXmlWriter.endElement(); - } + writeResultToXml(aXmlWriter, getResult()); + aXmlWriter.endElement(); - if (m_aRecentlyUsedValuesCollection.size() >= 5) + if (m_aRecentlyUsedValuesCollection.size() >= RECENTLY_USED_LIMIT) m_aRecentlyUsedValuesCollection.pop_back(); for (std::vector<ClassificationResult> const & rResultCollection : m_aRecentlyUsedValuesCollection) { aXmlWriter.startElement("elementGroup"); - for (ClassificationResult const & rResult : rResultCollection) - { - aXmlWriter.startElement("element"); - OUString sType; - switch(rResult.meType) - { - case svx::ClassificationType::CATEGORY: - sType = "CATEGORY"; break; - case svx::ClassificationType::MARKING: - sType = "MARKING"; break; - case svx::ClassificationType::TEXT: - sType = "TEXT"; break; - case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: - sType = "INTELLECTUAL_PROPERTY_PART"; break; - case svx::ClassificationType::PARAGRAPH: - sType = "PARAGRAPH"; break; - } - aXmlWriter.attribute("type", sType); - aXmlWriter.startElement("string"); - aXmlWriter.content(rResult.msString); - aXmlWriter.endElement(); - aXmlWriter.startElement("abbreviatedString"); - aXmlWriter.content(rResult.msAbbreviatedString); - aXmlWriter.endElement(); - aXmlWriter.endElement(); - } + writeResultToXml(aXmlWriter, rResultCollection); + aXmlWriter.endElement(); } @@ -498,6 +531,16 @@ IMPL_LINK(ClassificationDialog, SelectIPPartNumbersHdl, ListBox&, rBox, void) } } +IMPL_LINK(ClassificationDialog, SelectRecentlyUsedHdl, ListBox&, rBox, void) +{ + sal_Int32 nSelected = rBox.GetSelectedEntryPos(); + if (nSelected >= 0) + { + m_pEditWindow->pEdEngine->Clear(); + readIn(m_aRecentlyUsedValuesCollection[nSelected]); + } +} + IMPL_LINK(ClassificationDialog, DoubleClickIPPartHdl, ListBox&, rBox, void) { const sal_Int32 nSelected = rBox.GetSelectedEntryPos(); diff --git a/svx/uiconfig/ui/classificationdialog.ui b/svx/uiconfig/ui/classificationdialog.ui index 0d6318ddb659..e5a4788c3618 100644 --- a/svx/uiconfig/ui/classificationdialog.ui +++ b/svx/uiconfig/ui/classificationdialog.ui @@ -116,7 +116,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">0</property> + <property name="top_attach">1</property> </packing> </child> <child> @@ -128,7 +128,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">1</property> + <property name="top_attach">2</property> </packing> </child> <child> @@ -139,7 +139,7 @@ </object> <packing> <property name="left_attach">1</property> - <property name="top_attach">0</property> + <property name="top_attach">1</property> </packing> </child> <child> @@ -149,7 +149,7 @@ </object> <packing> <property name="left_attach">1</property> - <property name="top_attach">1</property> + <property name="top_attach">2</property> </packing> </child> <child> @@ -159,7 +159,7 @@ </object> <packing> <property name="left_attach">1</property> - <property name="top_attach">2</property> + <property name="top_attach">3</property> </packing> </child> <child> @@ -171,7 +171,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">2</property> + <property name="top_attach">3</property> </packing> </child> <child> @@ -184,7 +184,7 @@ <property name="homogeneous">True</property> <child> <object class="GtkButton" id="signButton"> - <property name="label" context="classificationdialog|signButton" translatable="yes">Sign Paragraph</property> + <property name="label" translatable="yes" context="classificationdialog|signButton">Sign Paragraph</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -198,7 +198,7 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">3</property> + <property name="top_attach">4</property> <property name="width">2</property> </packing> </child> @@ -212,7 +212,7 @@ <property name="homogeneous">True</property> <child> <object class="GtkButton" id="boldButton"> - <property name="label" context="classificationdialog|boldButton" translatable="yes">Bold</property> + <property name="label" translatable="yes" context="classificationdialog|boldButton">Bold</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -226,10 +226,33 @@ </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">4</property> + <property name="top_attach">5</property> <property name="width">2</property> </packing> </child> + <child> + <object class="GtkComboBoxText" id="recentlyUsedCB"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkLabel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="classificationdialog|label-Classification">Recently Used:</property> + <property name="xalign">0</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + </packing> + </child> </object> <packing> <property name="left_attach">1</property> |