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

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Sun Nov 5 12:20:46 UTC 2017


 include/svx/ClassificationDialog.hxx       |    4 ++
 include/svx/ClassificationEditView.hxx     |   10 +++++++
 svx/source/dialog/ClassificationDialog.cxx |   39 +++++++++++++++++++++++++++++
 svx/uiconfig/ui/classificationdialog.ui    |    2 +
 4 files changed, 55 insertions(+)

New commits:
commit 8747abf7708e06d6f989258b1cf102c144162cfa
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sat Nov 4 12:08:32 2017 +0900

    TSCP: disable OK button if no category is present in text edit
    
    Change-Id: I638f04e904a642e4fd6700e625732e5a9a2e44de
    Reviewed-on: https://gerrit.libreoffice.org/44292
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/svx/ClassificationDialog.hxx b/include/svx/ClassificationDialog.hxx
index 164701d2c3a4..0033126f5e93 100644
--- a/include/svx/ClassificationDialog.hxx
+++ b/include/svx/ClassificationDialog.hxx
@@ -37,6 +37,7 @@ protected:
 class SVX_DLLPUBLIC ClassificationDialog : public ModalDialog
 {
 private:
+    VclPtr<PushButton> m_pOkButton;
     VclPtr<ClassificationEditView> m_pEditWindow;
     VclPtr<PushButton> m_pSignButton;
     VclPtr<PushButton> m_pBoldButton;
@@ -65,6 +66,8 @@ private:
     DECL_LINK(SelectIPPartNumbersHdl, ListBox&, void);
     DECL_LINK(SelectRecentlyUsedHdl, ListBox&, void);
     DECL_LINK(SelectIPPartHdl, ListBox&, void);
+    DECL_LINK(EditWindowModifiedHdl, LinkParamNone*, void);
+
 
     void insertField(ClassificationType eType, OUString const & rString, OUString const & rFullString, OUString const & rIdentifier = OUString());
 
@@ -74,6 +77,7 @@ private:
     void readIn(std::vector<ClassificationResult> const & rInput);
     void readRecentlyUsed();
     void writeRecentlyUsed();
+    void toggleWidgetsDependingOnCategory();
 
 public:
     ClassificationDialog(vcl::Window* pParent, bool bPerParagraph, const std::function<void()>& rParagraphSignHandler = [](){});
diff --git a/include/svx/ClassificationEditView.hxx b/include/svx/ClassificationEditView.hxx
index 2231aa63eb48..576fe8044af2 100644
--- a/include/svx/ClassificationEditView.hxx
+++ b/include/svx/ClassificationEditView.hxx
@@ -49,6 +49,16 @@ public:
     std::unique_ptr<ClassificationEditEngine> pEdEngine;
     std::unique_ptr<EditView> pEdView;
 
+    const ClassificationEditEngine& getEditEngine()
+    {
+        return *pEdEngine.get();
+    }
+
+    void SetModifyHdl(const Link<LinkParamNone*,void>& rLink)
+    {
+        pEdEngine->SetModifyHdl(rLink);
+    }
+
 protected:
     virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
     virtual void MouseMove( const MouseEvent& rMEvt ) override;
diff --git a/svx/source/dialog/ClassificationDialog.cxx b/svx/source/dialog/ClassificationDialog.cxx
index 3210d1a2f761..9458ceb95b3e 100644
--- a/svx/source/dialog/ClassificationDialog.cxx
+++ b/svx/source/dialog/ClassificationDialog.cxx
@@ -174,6 +174,7 @@ ClassificationDialog::ClassificationDialog(vcl::Window* pParent, const bool bPer
     , m_bPerParagraph(bPerParagraph)
     , m_aParagraphSignHandler(rParagraphSignHandler)
 {
+    get(m_pOkButton, "ok");
     get(m_pEditWindow, "classificationEditWindow");
     get(m_pSignButton, "signButton");
     get(m_pBoldButton, "boldButton");
@@ -232,6 +233,8 @@ ClassificationDialog::ClassificationDialog(vcl::Window* pParent, const bool bPer
 
     bool bExpand = officecfg::Office::Common::Classification::IntellectualPropertySectionExpanded::get();
     m_pIntellectualPropertyExpander->set_expanded(bExpand);
+
+    m_pEditWindow->SetModifyHdl(LINK(this, ClassificationDialog, EditWindowModifiedHdl));
 }
 
 ClassificationDialog::~ClassificationDialog()
@@ -241,6 +244,7 @@ ClassificationDialog::~ClassificationDialog()
 
 void ClassificationDialog::dispose()
 {
+    m_pOkButton.clear();
     m_pEditWindow.clear();
     m_pSignButton.clear();
     m_pBoldButton.clear();
@@ -472,6 +476,35 @@ void ClassificationDialog::readIn(std::vector<ClassificationResult> const & rInp
             break;
         }
     }
+    toggleWidgetsDependingOnCategory();
+}
+
+void ClassificationDialog::toggleWidgetsDependingOnCategory()
+{
+    const EditEngine& rEditEngine = m_pEditWindow->getEditEngine();
+
+    for (sal_Int32 nParagraph = 0; nParagraph < rEditEngine.GetParagraphCount(); ++nParagraph)
+    {
+        sal_uInt16 nFieldCount = rEditEngine.GetFieldCount(nParagraph);
+        for (sal_Int16 nField = 0; nField < nFieldCount; ++nField)
+        {
+            EFieldInfo aFieldInfo = rEditEngine.GetFieldInfo(nParagraph, nField);
+            if (aFieldInfo.pFieldItem)
+            {
+                const ClassificationField* pClassificationField = dynamic_cast<const ClassificationField*>(aFieldInfo.pFieldItem->GetField());
+                if (pClassificationField && pClassificationField->meType == ClassificationType::CATEGORY)
+                {
+                    m_pOkButton->Enable();
+                    return;
+                }
+            }
+        }
+    }
+
+    // Category field in the text edit has been deleted, so reset the list boxes
+    m_pOkButton->Disable();
+    m_pClassificationListBox->SetNoSelection();
+    m_pInternationalClassificationListBox->SetNoSelection();
 }
 
 std::vector<ClassificationResult> ClassificationDialog::getResult()
@@ -661,6 +694,12 @@ IMPL_LINK(ClassificationDialog, ButtonClicked, Button*, pButton, void)
     }
 }
 
+IMPL_LINK_NOARG(ClassificationDialog, EditWindowModifiedHdl, LinkParamNone*, void)
+{
+    toggleWidgetsDependingOnCategory();
+}
+
+
 } // end svx
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/uiconfig/ui/classificationdialog.ui b/svx/uiconfig/ui/classificationdialog.ui
index 40464427568a..ab4f449726a3 100644
--- a/svx/uiconfig/ui/classificationdialog.ui
+++ b/svx/uiconfig/ui/classificationdialog.ui
@@ -22,6 +22,8 @@
                 <property name="label">gtk-ok</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
                 <property name="receives_default">True</property>
                 <property name="use_stock">True</property>
               </object>


More information about the Libreoffice-commits mailing list