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

Samuel Mehrbrodt s.mehrbrodt at gmail.com
Mon May 13 07:28:14 PDT 2013


 sd/source/ui/dlg/PhotoAlbumDialog.cxx |   86 +++++-----------------------------
 sd/source/ui/dlg/PhotoAlbumDialog.hxx |    2 
 2 files changed, 17 insertions(+), 71 deletions(-)

New commits:
commit 1c7af341d068e4474774077524ccc15721ea3df3
Author: Samuel Mehrbrodt <s.mehrbrodt at gmail.com>
Date:   Sat May 11 17:56:23 2013 +0200

    Related fdo#35546: Simplyfy Code in Photo Album Dialog
    
    Create a method for enabling/disabling the Up/Down/Remove buttons.
    This also fixes some wrong behavior.
    
    Change-Id: Ie40a4f3bb4402b988071b315617404c802b7e92a
    Reviewed-on: https://gerrit.libreoffice.org/3855
    Reviewed-by: Bosdonnat Cedric <cedric.bosdonnat at free.fr>
    Tested-by: Bosdonnat Cedric <cedric.bosdonnat at free.fr>

diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.cxx b/sd/source/ui/dlg/PhotoAlbumDialog.cxx
index 2771166..351a9d8 100644
--- a/sd/source/ui/dlg/PhotoAlbumDialog.cxx
+++ b/sd/source/ui/dlg/PhotoAlbumDialog.cxx
@@ -597,19 +597,6 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl)
                 OSL_FAIL("Could not find config for Create Photo Album function");
             }
 
-            if( aFilesArr.getLength() == 1)
-            {
-                pRemoveBtn->Enable();
-                pUpBtn->Disable();
-                pDownBtn->Disable();
-            }
-            else
-            {
-                pRemoveBtn->Enable();
-                pUpBtn->Enable();
-                pDownBtn->Enable();
-            }
-
             for ( sal_Int32 i = 0; i < aFilesArr.getLength(); i++ )
             {
                 // Store full path, show filename only. Use INetURLObject to display spaces in filename correctly
@@ -619,6 +606,7 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, FileHdl)
             }
         }
     }
+    EnableDisableButtons();
     return 0;
 }
 
@@ -634,12 +622,7 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, TextHdl)
     OUString sStr(SD_RESSTR(STR_PHOTO_ALBUM_TEXTBOX));
     pImagesLst->SetEntryData(nPos, (void*)new OUString(sStr));
 
-    if(pImagesLst->GetEntryCount() >= 1)
-    {
-        pRemoveBtn->Enable();
-        pUpBtn->Disable();
-        pDownBtn->Disable();
-    }
+    EnableDisableButtons();
     return 0;
 }
 
@@ -669,16 +652,9 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, UpHdl)
         pImagesLst->SetEntryData( nActPos, (void*) new OUString(sUpper));
 
         pImagesLst->SelectEntryPos(nActPos - 1);
-
-        pDownBtn->Enable();
-
     }
 
-    if(pImagesLst->GetSelectEntryPos() == 0)
-    {
-        pDownBtn->Enable();
-        pUpBtn->Disable();
-    }
+    EnableDisableButtons();
     return 0;
 }
 
@@ -707,16 +683,7 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, DownHdl)
         pImagesLst->SelectEntryPos(nActPos + 1);
 
     }
-
-    if(pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos() + 1) != OUString(""))
-    {
-        pDownBtn->Enable();
-        pUpBtn->Enable();
-    }
-    else
-    {
-        pDownBtn->Disable();
-    }
+    EnableDisableButtons();
     return 0;
 }
 
@@ -725,18 +692,7 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, RemoveHdl)
     pImagesLst->RemoveEntry( pImagesLst->GetSelectEntryPos() );
     pImg->SetImage(Image());
 
-    if(pImagesLst->GetEntryCount() >= 1)
-    {
-        pRemoveBtn->Enable();
-        pUpBtn->Disable();
-        pDownBtn->Disable();
-    }
-    else
-    {
-        pRemoveBtn->Disable();
-        pUpBtn->Disable();
-        pDownBtn->Disable();
-    }
+    EnableDisableButtons();
     return 0;
 }
 
@@ -744,27 +700,6 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
 {
     OUString* pData = (OUString*) pImagesLst->GetEntryData(pImagesLst->GetSelectEntryPos());
     OUString sImgUrl = pData ? OUString(*pData) : "";
-    // Some UI functionality: if you select the first/last item in the list,
-    // the Up/Down button gets enabled/diabled (meaning: you cannot move up/down the item)
-    // disable/enable moving up
-    if(pImagesLst->GetSelectEntryPos() == 0)
-    {
-        pUpBtn->Disable();
-    }
-    else
-    {
-        pUpBtn->Enable();
-    }
-
-    // disable/enable moving down
-    if(pImagesLst->GetEntry(pImagesLst->GetSelectEntryPos() + 1) == OUString(""))
-    {
-        pDownBtn->Disable();
-    }
-    else
-    {
-        pDownBtn->Enable();
-    }
 
     if (sImgUrl != SD_RESSTR(STR_PHOTO_ALBUM_TEXTBOX))
     {
@@ -817,7 +752,7 @@ IMPL_LINK_NOARG(SdPhotoAlbumDialog, SelectHdl)
     {
         pImg->SetImage(Image());
     }
-
+    EnableDisableButtons();
     return 0;
 }
 
@@ -893,6 +828,15 @@ short SdPhotoAlbumDialog::Execute()
     return ModalDialog::Execute();
 }
 
+void SdPhotoAlbumDialog::EnableDisableButtons()
+{
+    pRemoveBtn->Enable(pImagesLst->GetSelectEntryCount() > 0);
+    pUpBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
+                   pImagesLst->GetSelectEntryPos() != 0);
+    pDownBtn->Enable(pImagesLst->GetSelectEntryCount() > 0 &&
+                     pImagesLst->GetSelectEntryPos() < pImagesLst->GetEntryCount()-1);
+}
+
 
 } // end of namespace sd
 
diff --git a/sd/source/ui/dlg/PhotoAlbumDialog.hxx b/sd/source/ui/dlg/PhotoAlbumDialog.hxx
index 9a68ba9..3e75128 100644
--- a/sd/source/ui/dlg/PhotoAlbumDialog.hxx
+++ b/sd/source/ui/dlg/PhotoAlbumDialog.hxx
@@ -93,6 +93,8 @@ private:
     Reference< graphic::XGraphic> createXGraphicFromUrl(const OUString& sUrl,
         Reference< graphic::XGraphicProvider> xProvider);
 
+    void EnableDisableButtons();
+
     enum SlideImageLayout
     {
         FIT_TO_SLIDE=0,


More information about the Libreoffice-commits mailing list