Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/2108

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/08/2108/1

Templates Manager: UI for renaming templates and folders, fdo#60579

After thinking this was a feature regression, I finally discovered that
the old template manager couldn't rename templates. This commit is
bringing back some previously unused code dropped in an ealier commit.

Even though this is a UI change, no new string is added by this commit.

Conflicts:
        sfx2/inc/sfx2/templateview.hxx
        sfx2/source/control/templatelocalview.cxx
        sfx2/source/control/templateview.cxx

Change-Id: I2e4a89c2e68f7e04b0fca3fc161920505ac715b4
---
M sfx2/inc/sfx2/doctempl.hxx
M sfx2/inc/sfx2/templatelocalview.hxx
M sfx2/inc/sfx2/templateview.hxx
M sfx2/inc/sfx2/templateviewitem.hxx
M sfx2/inc/sfx2/thumbnailview.hxx
M sfx2/inc/sfx2/thumbnailviewitem.hxx
M sfx2/source/control/templatelocalview.cxx
M sfx2/source/control/templateview.cxx
M sfx2/source/control/templateviewitem.cxx
M sfx2/source/control/thumbnailview.cxx
M sfx2/source/control/thumbnailviewitem.cxx
M sfx2/source/doc/doctempl.cxx
12 files changed, 257 insertions(+), 5 deletions(-)



diff --git a/sfx2/inc/sfx2/doctempl.hxx b/sfx2/inc/sfx2/doctempl.hxx
index 507117c..b9ca56d 100644
--- a/sfx2/inc/sfx2/doctempl.hxx
+++ b/sfx2/inc/sfx2/doctempl.hxx
@@ -96,6 +96,21 @@
     sal_Bool            InsertDir(const String &rText, sal_uInt16 nRegion);
     sal_Bool            SetName(const String &rName, sal_uInt16 nRegion, sal_uInt16 nIdx);
 
+    /** Change the name of an entry or a directory
+
+        \param rName
+            The new name to set
+        \param nRegion
+            The id of the region to rename or containing the template to rename
+        \param nIdx
+            The id of the template to rename or USHRT_MAX to rename the region.
+
+        \return
+            sal_True if the action could be performed, sal_False otherwise
+
+    */
+    sal_Bool            SetName(const rtl::OUString &rName, sal_uInt16 nRegion, sal_uInt16 nIdx);
+
     sal_Bool            CopyTo(sal_uInt16 nRegion, sal_uInt16 nIdx, const String &rName) const;
     sal_Bool            CopyFrom(sal_uInt16 nRegion, sal_uInt16 nIdx, String &rName);
 
diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index e11c42b..dbf00ef 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -71,6 +71,8 @@
 
     bool isTemplateNameUnique (const sal_uInt16 nRegionItemId, const OUString &rName) const;
 
+    virtual void renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle);
+
 private:
 
     virtual void OnItemDblClicked (ThumbnailViewItem *pRegionItem);
diff --git a/sfx2/inc/sfx2/templateview.hxx b/sfx2/inc/sfx2/templateview.hxx
index 6e81ea4..07b8487 100644
--- a/sfx2/inc/sfx2/templateview.hxx
+++ b/sfx2/inc/sfx2/templateview.hxx
@@ -39,6 +39,8 @@
     void setDblClickHdl (const Link &rLink) { maDblClickHdl = rLink; }
 
     void setCloseHdl (const Link &rLink) { maAllButton.SetClickHdl(rLink); }
+    void setMasterView(TemplateAbstractView* pMasterView) { mpMasterView = pMasterView; }
+    virtual void renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle);
 
 protected:
 
@@ -47,6 +49,7 @@
     virtual void OnItemDblClicked (ThumbnailViewItem *pItem);
 
 private:
+    TemplateAbstractView* mpMasterView;
 
     Control    maButtons;
     PushButton maAllButton;
diff --git a/sfx2/inc/sfx2/templateviewitem.hxx b/sfx2/inc/sfx2/templateviewitem.hxx
index b19a060..0a3cb3e 100644
--- a/sfx2/inc/sfx2/templateviewitem.hxx
+++ b/sfx2/inc/sfx2/templateviewitem.hxx
@@ -42,6 +42,10 @@
 
     virtual void Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
                         const ThumbnailItemAttributes *pAttrs);
+
+    sal_uInt16    mnRegionId;
+    sal_uInt16    mnDocId;
+
 private:
 
     rtl::OUString maPath;
diff --git a/sfx2/inc/sfx2/thumbnailview.hxx b/sfx2/inc/sfx2/thumbnailview.hxx
index 9548bd1..a33e762 100644
--- a/sfx2/inc/sfx2/thumbnailview.hxx
+++ b/sfx2/inc/sfx2/thumbnailview.hxx
@@ -238,6 +238,8 @@
 
     virtual void Resize();
 
+    virtual void renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle);
+
 protected:
 
     virtual void MouseButtonDown( const MouseEvent& rMEvt );
diff --git a/sfx2/inc/sfx2/thumbnailviewitem.hxx b/sfx2/inc/sfx2/thumbnailviewitem.hxx
index 18b7eae..2acc8de 100644
--- a/sfx2/inc/sfx2/thumbnailviewitem.hxx
+++ b/sfx2/inc/sfx2/thumbnailviewitem.hxx
@@ -25,6 +25,7 @@
 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
 #include <osl/mutex.hxx>
 #include <vcl/bitmapex.hxx>
+#include <vcl/vclmedit.hxx>
 #include "sfx2/dllapi.h"
 
 #include <com/sun/star/accessibility/XAccessible.hpp>
@@ -88,12 +89,17 @@
 
     void setHighlight (bool state);
 
+    void setEditTitle (bool edit, bool bChangeFocus = true);
+    void updateTitleEditSize ();
+    virtual void setTitle (const rtl::OUString& rTitle);
+
     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
                         GetAccessible( bool bIsTransientChildrenDisabled );
 
     void setDrawArea (const Rectangle &area);
 
     const Rectangle& getDrawArea () const { return maDrawArea; }
+    Rectangle getTextArea () const;
 
     virtual void calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
                                          const long nPadding, sal_uInt32 nMaxTextLenght,
@@ -118,6 +124,9 @@
     Point maPrev1Pos;
     Rectangle maDrawArea;
     Link maClickHdl;
+    bool mbEditTitle;
+    VclMultiLineEdit* mpTitleED;
+    Rectangle maTextEditMaxArea;
 };
 
 #endif // THUMBNAILVIEWITEM_HXX
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index 76516d7..2bbf0d0 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -37,6 +37,7 @@
       mpDocTemplates(new SfxDocumentTemplates)
 {
     mpItemView->SetColor(GetSettings().GetStyleSettings().GetFieldColor());
+    mpItemView->setMasterView(this);
 }
 
 TemplateLocalView::~TemplateLocalView()
@@ -63,7 +64,7 @@
             OUString aName = mpDocTemplates->GetName(i,j);
             OUString aURL = mpDocTemplates->GetPath(i,j);
 
-            TemplateItemProperties aProperties;;
+            TemplateItemProperties aProperties;
             aProperties.nId = j+1;
             aProperties.nDocId = j;
             aProperties.nRegionId = i;
@@ -604,6 +605,24 @@
     showOverlay(true);
 }
 
+void TemplateLocalView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle)
+{
+    sal_uInt16 nRegionId = 0;
+    sal_uInt16 nDocId = USHRT_MAX;
+    TemplateViewItem* pDocItem = dynamic_cast<TemplateViewItem*>( pItem );
+    TemplateContainerItem* pContainerItem = dynamic_cast<TemplateContainerItem*>( pItem );
+    if ( pDocItem )
+    {
+        nRegionId = pDocItem->mnRegionId;
+        nDocId = pDocItem->mnDocId;
+    }
+    else if ( pContainerItem )
+    {
+        nRegionId = pContainerItem->mnId - 1;
+    }
+    mpDocTemplates->SetName( sNewTitle, nRegionId, nDocId );
+}
+
 static void lcl_updateThumbnails (TemplateContainerItem *pItem)
 {
     pItem->maPreview1.Clear();
diff --git a/sfx2/source/control/templateview.cxx b/sfx2/source/control/templateview.cxx
index 9758065..90e86ec 100644
--- a/sfx2/source/control/templateview.cxx
+++ b/sfx2/source/control/templateview.cxx
@@ -9,6 +9,7 @@
 
 #include "templatedlg.hxx"
 #include <sfx2/templateview.hxx>
+#include <sfx2/templateabstractview.hxx>
 
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 #include <basegfx/point/b2dpoint.hxx>
@@ -34,6 +35,7 @@
 
 TemplateView::TemplateView (Window *pParent)
     : ThumbnailView(pParent,WB_VSCROLL),
+      mpMasterView(NULL),
       maButtons(this, SfxResId(CONTROL_BUTTONS)),
       maAllButton(&maButtons, SfxResId(BTN_ALL_TEMPLATES)),
       maFTName(&maButtons, SfxResId(FT_NAME)),
@@ -61,6 +63,8 @@
         const TemplateItemProperties *pCur = &rTemplates[i];
 
         pItem->mnId = pCur->nId;
+        pItem->mnDocId = pCur->nDocId;
+        pItem->mnRegionId = pCur->nRegionId;
         pItem->maTitle = pCur->aName;
         pItem->setPath(pCur->aPath);
         pItem->maPreview1 = pCur->aThumbnail;
@@ -101,6 +105,12 @@
     maDblClickHdl.Call(pItem);
 }
 
+void TemplateView::renameItem(ThumbnailViewItem* pItem, rtl::OUString sNewTitle)
+{
+    if (mpMasterView)
+        mpMasterView->renameItem(pItem, sNewTitle);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 
 
diff --git a/sfx2/source/control/templateviewitem.cxx b/sfx2/source/control/templateviewitem.cxx
index 9f06ebb..94ce4d3 100644
--- a/sfx2/source/control/templateviewitem.cxx
+++ b/sfx2/source/control/templateviewitem.cxx
@@ -28,7 +28,9 @@
 using namespace drawinglayer::primitive2d;
 
 TemplateViewItem::TemplateViewItem (ThumbnailView &rView)
-    : ThumbnailViewItem(rView)
+    : ThumbnailViewItem(rView),
+      mnRegionId(USHRT_MAX),
+      mnDocId(USHRT_MAX)
 {
 }
 
diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx
index 62324a7..9a29381 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -505,6 +505,9 @@
                     deselectItems( );
                 pItem->setSelection(true);
 
+                bool bClickOnTitle = pItem->getTextArea().IsInside(rMEvt.GetPosPixel());
+                pItem->setEditTitle(bClickOnTitle);
+
                 if (!pItem->isHighlighted())
                     DrawItem(pItem);
 
@@ -881,6 +884,7 @@
     {
         if (mItemList[i]->isSelected())
         {
+            mItemList[i]->setEditTitle(false);
             mItemList[i]->setSelection(false);
 
             maItemStateHdl.Call(mItemList[i]);
@@ -976,6 +980,11 @@
     Invalidate();
 }
 
+void ThumbnailView::renameItem(ThumbnailViewItem*, rtl::OUString)
+{
+    // Do nothing by default
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 
 
diff --git a/sfx2/source/control/thumbnailviewitem.cxx b/sfx2/source/control/thumbnailviewitem.cxx
index 2e6eb96..c228bab 100644
--- a/sfx2/source/control/thumbnailviewitem.cxx
+++ b/sfx2/source/control/thumbnailviewitem.cxx
@@ -19,6 +19,7 @@
 
 #include <sfx2/thumbnailviewitem.hxx>
 
+#include "thumbnailview.hxx"
 #include "thumbnailviewacc.hxx"
 
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
@@ -42,6 +43,66 @@
 using namespace drawinglayer::attribute;
 using namespace drawinglayer::primitive2d;
 
+class ResizableMultiLineEdit : public VclMultiLineEdit
+{
+    private:
+        ThumbnailViewItem* mpItem;
+        bool mbIsInGrabFocus;
+
+    public:
+        ResizableMultiLineEdit (Window* pParent, ThumbnailViewItem* pItem);
+        ~ResizableMultiLineEdit ();
+
+        void SetInGrabFocus(bool bInGrabFocus) { mbIsInGrabFocus = bInGrabFocus; }
+
+        virtual long PreNotify(NotifyEvent& rNEvt);
+        virtual void Modify();
+};
+
+ResizableMultiLineEdit::ResizableMultiLineEdit (Window* pParent, ThumbnailViewItem* pItem) :
+    VclMultiLineEdit (pParent, WB_CENTER | WB_BORDER),
+    mpItem(pItem),
+    mbIsInGrabFocus(false)
+{
+}
+
+ResizableMultiLineEdit::~ResizableMultiLineEdit ()
+{
+}
+
+long ResizableMultiLineEdit::PreNotify(NotifyEvent& rNEvt)
+{
+    long nDone = 0;
+    if( rNEvt.GetType() == EVENT_KEYINPUT )
+    {
+        const KeyEvent& rKEvt = *rNEvt.GetKeyEvent();
+        KeyCode aCode = rKEvt.GetKeyCode();
+        switch (aCode.GetCode())
+        {
+            case KEY_RETURN:
+                mpItem->setTitle( GetText() );
+            case KEY_ESCAPE:
+                mpItem->setEditTitle(false);
+                nDone = 1;
+                break;
+            default:
+                break;
+        }
+    }
+    else if ( rNEvt.GetType() == EVENT_LOSEFOCUS && !mbIsInGrabFocus )
+    {
+        mpItem->setTitle( GetText() );
+        mpItem->setEditTitle(false, false);
+    }
+    return nDone ? nDone : VclMultiLineEdit::PreNotify(rNEvt);
+}
+
+void ResizableMultiLineEdit::Modify()
+{
+    VclMultiLineEdit::Modify();
+    mpItem->updateTitleEditSize();
+}
+
 ThumbnailViewItem::ThumbnailViewItem(ThumbnailView &rView)
     : mrParent(rView)
     , mnId(0)
@@ -49,11 +110,16 @@
     , mbSelected(false)
     , mbHover(false)
     , mpxAcc(NULL)
+    , mbEditTitle(false)
+    , mpTitleED(NULL)
+    , maTextEditMaxArea()
 {
+    mpTitleED = new ResizableMultiLineEdit(&rView, this);
 }
 
 ThumbnailViewItem::~ThumbnailViewItem()
 {
+    delete mpTitleED;
     if( mpxAcc )
     {
         static_cast< ThumbnailViewItemAcc* >( mpxAcc->get() )->ParentDestroyed();
@@ -64,6 +130,8 @@
 void ThumbnailViewItem::show (bool bVisible)
 {
     mbVisible = bVisible;
+    if (!mbVisible)
+        mpTitleED->Show(false);
 }
 
 void ThumbnailViewItem::setSelection (bool state)
@@ -74,6 +142,53 @@
 void ThumbnailViewItem::setHighlight (bool state)
 {
     mbHover = state;
+}
+
+void ThumbnailViewItem::setEditTitle (bool edit, bool bChangeFocus)
+{
+    mbEditTitle = edit;
+    mpTitleED->Show(edit);
+    if (edit)
+    {
+        mpTitleED->SetText(maTitle);
+        updateTitleEditSize();
+        static_cast<ResizableMultiLineEdit*>(mpTitleED)->SetInGrabFocus(true);
+        mpTitleED->GrabFocus();
+        static_cast<ResizableMultiLineEdit*>(mpTitleED)->SetInGrabFocus(false);
+    }
+    else if (bChangeFocus)
+    {
+        mrParent.GrabFocus();
+    }
+}
+
+Rectangle ThumbnailViewItem::getTextArea() const
+{
+    Rectangle aTextArea(maTextEditMaxArea);
+
+    TextEngine aTextEngine;
+    aTextEngine.SetMaxTextWidth(maDrawArea.getWidth());
+    aTextEngine.SetText(maTitle);
+
+    long nTxtHeight = aTextEngine.GetTextHeight() + 6;
+    if (nTxtHeight < aTextArea.GetHeight())
+        aTextArea.SetSize(Size(aTextArea.GetWidth(), nTxtHeight));
+
+    return aTextArea;
+}
+
+void ThumbnailViewItem::updateTitleEditSize()
+{
+    Rectangle aTextArea = getTextArea();
+    Point aPos = aTextArea.TopLeft();
+    Size aSize = aTextArea.GetSize();
+    mpTitleED->SetPosSizePixel(aPos, aSize);
+}
+
+void ThumbnailViewItem::setTitle (const rtl::OUString& rTitle)
+{
+    mrParent.renameItem(this, rTitle);
+    maTitle = rTitle;
 }
 
 uno::Reference< accessibility::XAccessible > ThumbnailViewItem::GetAccessible( bool 
bIsTransientChildrenDisabled )
@@ -108,9 +223,15 @@
     maPrev1Pos = aPos;
 
     // Calculate text position
-    aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding + aTextDev.getTextHeight();
+    aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding * 2;
     aPos.X() = maDrawArea.Left() + (aRectSize.Width() - 
aTextDev.getTextWidth(maTitle,0,nMaxTextLenght))/2;
     maTextPos = aPos;
+
+    // Calculate the text edit max area
+    aPos = Point(maDrawArea.getX() + nPadding, maTextPos.getY());
+    Size aEditSize(maDrawArea.GetWidth() - nPadding * 2,
+                   maDrawArea.Bottom() - maTextPos.Y());
+    maTextEditMaxArea = Rectangle( aPos, aEditSize );
 }
 
 void ThumbnailViewItem::setSelectClickHdl (const Link &link)
@@ -162,8 +283,7 @@
 
     // Draw text below thumbnail
     aPos = maTextPos;
-
-    addTextPrimitives( maTitle, pAttrs, maTextPos, aSeq );
+    addTextPrimitives( maTitle, pAttrs, aPos, aSeq );
 
     pProcessor->process(aSeq);
 }
@@ -172,6 +292,8 @@
 {
     drawinglayer::primitive2d::TextLayouterDevice aTextDev;
 
+    aPos.setY(aPos.getY() + aTextDev.getTextHeight());
+
     rtl::OUString aText (rText);
 
     TextEngine aTextEngine;
diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index aa3c603..6678600 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -1098,6 +1098,61 @@
     return sal_False;
 }
 
+sal_Bool SfxDocumentTemplates::SetName( const OUString& rName, sal_uInt16 nRegion, sal_uInt16 nIdx 
)
+
+{
+    DocTemplLocker_Impl aLocker( *pImp );
+
+    if ( ! pImp->Construct() )
+        return sal_False;
+
+    RegionData_Impl *pRegion = pImp->GetRegion( nRegion );
+    DocTempl_EntryData_Impl *pEntry = NULL;
+
+    if ( !pRegion )
+        return sal_False;
+
+    uno::Reference< XDocumentTemplates > xTemplates = pImp->getDocTemplates();
+    OUString aEmpty;
+
+    if ( nIdx == USHRT_MAX )
+    {
+        if ( pRegion->GetTitle() == rName )
+            return sal_True;
+
+        // we have to rename a region
+        if ( xTemplates->renameGroup( pRegion->GetTitle(), rName ) )
+        {
+            pRegion->SetTitle( rName );
+            pRegion->SetTargetURL( aEmpty );
+            pRegion->SetHierarchyURL( aEmpty );
+            return sal_True;
+        }
+    }
+    else
+    {
+        pEntry = pRegion->GetEntry( nIdx );
+
+        if ( !pEntry )
+            return sal_False;
+
+        if ( pEntry->GetTitle() == rName )
+            return sal_True;
+
+        if ( xTemplates->renameTemplate( pRegion->GetTitle(),
+                                         pEntry->GetTitle(),
+                                         rName ) )
+        {
+            pEntry->SetTitle( rName );
+            pEntry->SetTargetURL( aEmpty );
+            pEntry->SetHierarchyURL( aEmpty );
+            return sal_True;
+        }
+    }
+
+    return sal_False;
+}
+
 //------------------------------------------------------------------------
 
 sal_Bool SfxDocumentTemplates::SetName

-- 
To view, visit https://gerrit.libreoffice.org/2108
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2e4a89c2e68f7e04b0fca3fc161920505ac715b4
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Bosdonnat Cedric <cedric.bosdonnat@free.fr>

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.