[Libreoffice-commits] core.git: sw/source

Szymon Kłos szymon.klos at collabora.com
Mon May 1 15:19:17 UTC 2017


 sw/source/ui/misc/glossary.cxx    |   59 +++++++++++++++++++++++++++-----------
 sw/source/uibase/inc/glossary.hxx |    9 +++++
 2 files changed, 51 insertions(+), 17 deletions(-)

New commits:
commit 1c8d6e6ec2ae3e5ee38ab343b662db30f48fc7f5
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Mon May 1 13:59:51 2017 +0200

    AutoText: handle Delete key in the dialog
    
    Change-Id: Ifbd0026b097ff9fbf077dda57f874cfc59da3e45
    Reviewed-on: https://gerrit.libreoffice.org/37119
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/sw/source/ui/misc/glossary.cxx b/sw/source/ui/misc/glossary.cxx
index 192b407be077..a19a96e61bb4 100644
--- a/sw/source/ui/misc/glossary.cxx
+++ b/sw/source/ui/misc/glossary.cxx
@@ -230,6 +230,7 @@ SwGlossaryDlg::SwGlossaryDlg(SfxViewFrame* pViewFrame,
 
     m_pCategoryBox->SetDoubleClickHdl(LINK(this,SwGlossaryDlg, NameDoubleClick));
     m_pCategoryBox->SetSelectHdl(LINK(this,SwGlossaryDlg,GrpSelect));
+    m_pCategoryBox->SetDeleteHdl(LINK(this,SwGlossaryDlg,DeleteHdl));
     m_pBibBtn->SetClickHdl(LINK(this,SwGlossaryDlg,BibHdl));
 
     m_pInsertBtn->SetClickHdl(LINK(this,SwGlossaryDlg,InsertHdl));
@@ -522,23 +523,7 @@ IMPL_LINK( SwGlossaryDlg, MenuHdl, Menu *, pMn, bool )
     }
     else if (sItemIdent == "delete")
     {
-        ScopedVclPtrInstance< MessageDialog > aQuery(this, SW_RES(STR_QUERY_DELETE), VclMessageType::Question, VclButtonsType::YesNo);
-        if (RET_YES == aQuery->Execute())
-        {
-            const OUString aShortName(m_pShortNameEdit->GetText());
-            const OUString aTitle(m_pNameED->GetText());
-            if (!aTitle.isEmpty() && pGlossaryHdl->DelGlossary(aShortName))
-            {
-                SvTreeListEntry* pChild = DoesBlockExist(aTitle, aShortName);
-                OSL_ENSURE(pChild, "entry not found!");
-                SvTreeListEntry* pParent = m_pCategoryBox->GetParent(pChild);
-                m_pCategoryBox->Select(pParent);
-
-                m_pCategoryBox->GetModel()->Remove(pChild);
-                m_pNameED->SetText(OUString());
-                NameModify(*m_pNameED);
-            }
-        }
+        DeleteEntry();
     }
     else if (sItemIdent == "macro")
     {
@@ -1028,6 +1013,16 @@ void SwGlTreeListBox::ExpandedHdl()
     SvTreeListBox::ExpandedHdl();
 }
 
+void SwGlTreeListBox::KeyInput( const KeyEvent& rKEvt )
+{
+    if(m_aDeleteHdl.IsSet() && rKEvt.GetKeyCode().GetCode() == KEY_DELETE)
+    {
+        m_aDeleteHdl.Call(nullptr);
+        return;
+    }
+    SvTreeListBox::KeyInput( rKEvt );
+}
+
 OUString SwGlossaryDlg::GetCurrGrpName() const
 {
     SvTreeListEntry* pEntry = m_pCategoryBox->FirstSelected();
@@ -1069,6 +1064,11 @@ IMPL_LINK_NOARG(SwGlossaryDlg, InsertHdl, Button*, void)
     EndDialog(RET_OK);
 }
 
+IMPL_LINK_NOARG(SwGlossaryDlg, DeleteHdl, SwGlTreeListBox*, void)
+{
+    DeleteEntry();
+}
+
 void SwGlossaryDlg::ShowPreview()
 {
     //create example
@@ -1130,4 +1130,29 @@ void SwGlossaryDlg::ResumeShowAutoText()
     bResume = false;
 }
 
+void SwGlossaryDlg::DeleteEntry()
+{
+    SvTreeListEntry* pEntry = m_pCategoryBox->FirstSelected();
+
+    const OUString aTitle(m_pNameED->GetText());
+    const OUString aShortName(m_pShortNameEdit->GetText());
+    SvTreeListEntry* pChild = DoesBlockExist(aTitle, aShortName);
+    SvTreeListEntry* pParent = pChild ? m_pCategoryBox->GetParent(pChild) : nullptr;
+    const bool bExists = nullptr != pChild;
+    const bool bIsGroup = pEntry && !pParent;
+
+    ScopedVclPtrInstance< MessageDialog > aQuery(this, SW_RES(STR_QUERY_DELETE), VclMessageType::Question, VclButtonsType::YesNo);
+    if (bExists && !bIsGroup && RET_YES == aQuery->Execute())
+    {
+        if (!aTitle.isEmpty() && pGlossaryHdl->DelGlossary(aShortName))
+        {
+            OSL_ENSURE(pChild, "entry not found!");
+            m_pCategoryBox->Select(pParent);
+            m_pCategoryBox->GetModel()->Remove(pChild);
+            m_pNameED->SetText(OUString());
+            NameModify(*m_pNameED);
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/glossary.hxx b/sw/source/uibase/inc/glossary.hxx
index 7f5d328da960..bc9c87d55266 100644
--- a/sw/source/uibase/inc/glossary.hxx
+++ b/sw/source/uibase/inc/glossary.hxx
@@ -50,6 +50,8 @@ class SwGlTreeListBox : public SvTreeListBox
 
     SvTreeListEntry*  pDragEntry;
 
+    Link<SwGlTreeListBox*,void> m_aDeleteHdl;
+
     virtual DragDropMode NotifyStartDrag( TransferDataContainer& rContainer,
                                             SvTreeListEntry* ) override;
     virtual bool         NotifyAcceptDrop( SvTreeListEntry* ) override;
@@ -75,6 +77,10 @@ public:
     void Clear();
 
     virtual void ExpandedHdl() override;
+
+    virtual void KeyInput( const KeyEvent& rKEvt ) override;
+
+    void SetDeleteHdl( const Link<SwGlTreeListBox*,void>& rLink ) { m_aDeleteHdl = rLink; }
 };
 
 class SwOneExampleFrame;
@@ -129,6 +135,7 @@ class SwGlossaryDlg : public SvxStandardDialog
     DECL_LINK( PathHdl, Button *, void );
     DECL_LINK( CheckBoxHdl, Button*, void );
     DECL_LINK( PreviewLoadedHdl, SwOneExampleFrame&, void );
+    DECL_LINK( DeleteHdl, SwGlTreeListBox*, void );
 
     virtual void    Apply() override;
     void            Init();
@@ -140,6 +147,8 @@ class SwGlossaryDlg : public SvxStandardDialog
                         {rGroup = sResumeGroup; rShortName = sResumeShortName; return bResume;}
     void            SetResumeData(const OUString& rGroup, const OUString& rShortName)
                         {sResumeGroup = rGroup; sResumeShortName = rShortName; bResume = true;}
+
+    void            DeleteEntry();
 public:
     SwGlossaryDlg(SfxViewFrame* pViewFrame, SwGlossaryHdl* pGlosHdl, SwWrtShell *pWrtShell);
     virtual ~SwGlossaryDlg() override;


More information about the Libreoffice-commits mailing list