[PATCH libreoffice-4-0] Dont reload template information after saving.

Rafael Dominguez (via Code Review) gerrit at gerrit.libreoffice.org
Sun Apr 7 11:53:01 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3255

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/55/3255/1

Dont reload template information after saving.

Change-Id: Ib75bd4561581254f690e6dd4a2b83343c99d65af
---
M sfx2/inc/sfx2/doctempl.hxx
M sfx2/inc/sfx2/templatelocalview.hxx
M sfx2/source/control/templatelocalview.cxx
M sfx2/source/doc/doctempl.cxx
M sfx2/source/doc/templatedlg.cxx
5 files changed, 74 insertions(+), 8 deletions(-)



diff --git a/sfx2/inc/sfx2/doctempl.hxx b/sfx2/inc/sfx2/doctempl.hxx
index b9ca56d..add39df 100644
--- a/sfx2/inc/sfx2/doctempl.hxx
+++ b/sfx2/inc/sfx2/doctempl.hxx
@@ -96,6 +96,8 @@
     sal_Bool            InsertDir(const String &rText, sal_uInt16 nRegion);
     sal_Bool            SetName(const String &rName, sal_uInt16 nRegion, sal_uInt16 nIdx);
 
+    sal_Bool InsertTemplate (sal_uInt16 nSourceRegion, sal_uInt16 nIdx, const OUString &rName, const OUString &rPath);
+
     /** Change the name of an entry or a directory
 
         \param rName
diff --git a/sfx2/inc/sfx2/templatelocalview.hxx b/sfx2/inc/sfx2/templatelocalview.hxx
index f17f0f8..8490e37 100644
--- a/sfx2/inc/sfx2/templatelocalview.hxx
+++ b/sfx2/inc/sfx2/templatelocalview.hxx
@@ -81,7 +81,7 @@
                          com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel,
                          const OUString &rName);
 
-    bool saveTemplateAs (const TemplateContainerItem *pDstItem,
+    bool saveTemplateAs (TemplateContainerItem *pDstItem,
                          com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel,
                          const OUString &rName);
 
diff --git a/sfx2/source/control/templatelocalview.cxx b/sfx2/source/control/templatelocalview.cxx
index c6d32af..012fdba 100644
--- a/sfx2/source/control/templatelocalview.cxx
+++ b/sfx2/source/control/templatelocalview.cxx
@@ -695,21 +695,50 @@
                                         com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel,
                                         const OUString &rName)
 {
-    bool bRet = false;
 
     for (size_t i = 0, n = maRegions.size(); i < n; ++i)
     {
         if (maRegions[i]->mnId == nItemId)
         {
-            bRet = saveTemplateAs((const TemplateContainerItem*)maRegions[i],rModel,rName);
-            break;
+            uno::Reference< frame::XStorable > xStorable(rModel, uno::UNO_QUERY_THROW );
+
+            uno::Reference< frame::XDocumentTemplates > xTemplates(
+                            frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) );
+
+            if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(maRegions[i]->mnRegionId),rName, xStorable ))
+                return false;
+
+            sal_uInt16 nDocId = maRegions[i]->maTemplates.size();
+
+            OUString aURL = mpDocTemplates->GetTemplateTargetURLFromComponent(mpDocTemplates->GetRegionName(maRegions[i]->mnRegionId),rName);
+
+            if(!mpDocTemplates->InsertTemplate(maRegions[i]->mnRegionId,nDocId,rName,aURL))
+                return false;
+
+
+            TemplateItemProperties aTemplate;
+            aTemplate.aIsFolder = false;
+            aTemplate.nId = getNextItemId();
+            aTemplate.nDocId = nDocId;
+            aTemplate.nRegionId = maRegions[i]->mnRegionId;
+            aTemplate.aName = rName;
+            aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL,
+                                                                        TEMPLATE_THUMBNAIL_MAX_WIDTH,
+                                                                        TEMPLATE_THUMBNAIL_MAX_HEIGHT);
+            aTemplate.aPath = aURL;
+
+            maRegions[i]->maTemplates.push_back(aTemplate);
+
+            insertItem(aTemplate);
+
+            return true;
         }
     }
 
-    return bRet;
+    return false;
 }
 
-bool TemplateLocalView::saveTemplateAs(const TemplateContainerItem *pDstItem,
+bool TemplateLocalView::saveTemplateAs(TemplateContainerItem *pDstItem,
                                        com::sun::star::uno::Reference<com::sun::star::frame::XModel> &rModel,
                                        const OUString &rName)
 {
@@ -721,6 +750,25 @@
     if (!xTemplates->storeTemplate(mpDocTemplates->GetRegionName(pDstItem->mnRegionId),rName, xStorable ))
         return false;
 
+    sal_uInt16 nDocId = pDstItem->maTemplates.size();
+    OUString aURL = mpDocTemplates->GetTemplateTargetURLFromComponent(mpDocTemplates->GetRegionName(pDstItem->mnRegionId),rName);
+
+    if(!mpDocTemplates->InsertTemplate(pDstItem->mnRegionId,nDocId,rName,aURL))
+        return false;
+
+    TemplateItemProperties aTemplate;
+    aTemplate.aIsFolder = false;
+    aTemplate.nId = pDstItem->maTemplates.empty() ? 1 : pDstItem->maTemplates.back().nId+1;
+    aTemplate.nDocId = nDocId;
+    aTemplate.nRegionId = pDstItem->mnRegionId;
+    aTemplate.aName = rName;
+    aTemplate.aThumbnail = TemplateAbstractView::fetchThumbnail(aURL,
+                                                                TEMPLATE_THUMBNAIL_MAX_WIDTH,
+                                                                TEMPLATE_THUMBNAIL_MAX_HEIGHT);
+    aTemplate.aPath = aURL;
+
+    pDstItem->maTemplates.push_back(aTemplate);
+
     return true;
 }
 
diff --git a/sfx2/source/doc/doctempl.cxx b/sfx2/source/doc/doctempl.cxx
index 6678600..dd09be0 100644
--- a/sfx2/source/doc/doctempl.cxx
+++ b/sfx2/source/doc/doctempl.cxx
@@ -1098,6 +1098,24 @@
     return sal_False;
 }
 
+sal_Bool SfxDocumentTemplates::InsertTemplate(sal_uInt16 nSourceRegion, sal_uInt16 nIdx, const OUString &rName, const OUString &rPath)
+{
+    DocTemplLocker_Impl aLocker( *pImp );
+
+    if ( ! pImp->Construct() )
+        return sal_False;
+
+    RegionData_Impl *pRegion = pImp->GetRegion( nSourceRegion );
+
+    if ( !pRegion )
+        return sal_False;
+
+    size_t pos = nIdx;
+    pRegion->AddEntry( rName, rPath, &pos );
+
+    return sal_True;
+}
+
 sal_Bool SfxDocumentTemplates::SetName( const OUString& rName, sal_uInt16 nRegion, sal_uInt16 nIdx )
 
 {
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 94bbea6..9cf663c 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -1274,8 +1274,6 @@
                 }
             }
 
-            maView->reload();
-
             if (!aFolderList.isEmpty())
             {
             }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib75bd4561581254f690e6dd4a2b83343c99d65af
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Rafael Dominguez <venccsralph at gmail.com>



More information about the LibreOffice mailing list