[Libreoffice-commits] core.git: include/svx svx/source svx/uiconfig

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Thu Nov 2 06:31:00 UTC 2017


 include/svx/ClassificationDialog.hxx       |    2 
 svx/source/dialog/ClassificationDialog.cxx |  149 ++++++++++++++++++-----------
 svx/uiconfig/ui/classificationdialog.ui    |   43 ++++++--
 3 files changed, 131 insertions(+), 63 deletions(-)

New commits:
commit aa73ca2e5420dfceeccf19d7e2d5d4f367dd01da
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Wed Nov 1 19:16:54 2017 +0900

    TSCP: add recently used to advanced classification dialog
    
    Change-Id: Ic084104b28dbcc439d98cd08a89a7ddc6f291878
    Reviewed-on: https://gerrit.libreoffice.org/44158
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/svx/ClassificationDialog.hxx b/include/svx/ClassificationDialog.hxx
index a7825fef4a53..36eab811d491 100644
--- a/include/svx/ClassificationDialog.hxx
+++ b/include/svx/ClassificationDialog.hxx
@@ -30,6 +30,7 @@ private:
     VclPtr<PushButton> m_pSignButton;
     VclPtr<PushButton> m_pBoldButton;
     VclPtr<ListBox> m_pClassificationListBox;
+    VclPtr<ListBox> m_pRecentlyUsedListBox;
     VclPtr<ListBox> m_pInternationalClassificationListBox;
     VclPtr<ListBox> m_pMarkingListBox;
     VclPtr<ListBox> m_pIntellectualPropertyPartListBox;
@@ -47,6 +48,7 @@ private:
     DECL_LINK(SelectClassificationHdl, ListBox&, void);
     DECL_LINK(SelectMarkingHdl, ListBox&, void);
     DECL_LINK(SelectIPPartNumbersHdl, ListBox&, void);
+    DECL_LINK(SelectRecentlyUsedHdl, ListBox&, void);
     DECL_LINK(DoubleClickIPPartHdl, ListBox&, void);
 
     void insertField(ClassificationType eType, OUString const & rString, OUString const & rFullString);
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>


More information about the Libreoffice-commits mailing list