[Libreoffice-commits] .: 4 commits - sfx2/AllLangResTarget_sfx2.mk sfx2/inc sfx2/Library_sfx.mk sfx2/Package_inc.mk sfx2/source

Rafael Dominguez rdominguez at kemper.freedesktop.org
Tue Aug 14 13:46:52 PDT 2012


 sfx2/AllLangResTarget_sfx2.mk          |    1 
 sfx2/Library_sfx.mk                    |    1 
 sfx2/Package_inc.mk                    |    1 
 sfx2/inc/sfx2/templateinfodlg.hxx      |   46 +++++++++++
 sfx2/inc/templatedlg.hxx               |    1 
 sfx2/source/dialog/templateinfodlg.cxx |  130 +++++++++++++++++++++++++++++++
 sfx2/source/dialog/templateinfodlg.hrc |   11 ++
 sfx2/source/dialog/templateinfodlg.src |   25 +++++
 sfx2/source/doc/objserv.cxx            |  138 +++++++++++++++++----------------
 sfx2/source/doc/templatedlg.cxx        |    6 +
 10 files changed, 296 insertions(+), 64 deletions(-)

New commits:
commit c319e6258c34afa70ff0ab1f997ed88d53f94961
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Tue Aug 14 15:28:00 2012 -0430

    Display template preview in property dialog.
    
    Change-Id: I7479bac95a93a156889e19921373c441ef8fd881

diff --git a/sfx2/inc/sfx2/templateinfodlg.hxx b/sfx2/inc/sfx2/templateinfodlg.hxx
index dd031be..8fe7998 100644
--- a/sfx2/inc/sfx2/templateinfodlg.hxx
+++ b/sfx2/inc/sfx2/templateinfodlg.hxx
@@ -17,6 +17,9 @@ namespace svtools {
     class ODocumentInfoPreview;
 }
 
+namespace com{ namespace sun { namespace star { namespace awt   { class XWindow; } } } }
+namespace com{ namespace sun { namespace star { namespace frame { class XFrame; } } } }
+
 class SfxTemplateInfoDlg : public ModalDialog
 {
 public:
@@ -31,8 +34,11 @@ private:
 
     PushButton maBtnClose;
 
-    Window *mpPreviewView;
+    Window *mpPreviewView;  // gets released when xWindows get destroyed (dont delete in constructor)
     svtools::ODocumentInfoPreview *mpInfoView;
+
+    ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame;
+    ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > xWindow;
 };
 
 #endif // __SFX2_TEMPLATEINFODLG_HXX__
diff --git a/sfx2/source/dialog/templateinfodlg.cxx b/sfx2/source/dialog/templateinfodlg.cxx
index 2ed6794..40e3f14 100644
--- a/sfx2/source/dialog/templateinfodlg.cxx
+++ b/sfx2/source/dialog/templateinfodlg.cxx
@@ -12,11 +12,17 @@
 #include <comphelper/processfactory.hxx>
 #include <sfx2/sfxresid.hxx>
 #include <svtools/DocumentInfoPreview.hxx>
+#include <toolkit/helper/vclunohelper.hxx>
 
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/frame/XDispatchProvider.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/task/XInteractionHandler.hpp>
+#include <com/sun/star/util/URL.hpp>
+#include <com/sun/star/util/URLTransformer.hpp>
+#include <com/sun/star/util/XURLTransformer.hpp>
 
 #include "templateinfodlg.hrc"
 
@@ -25,28 +31,44 @@
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::frame;
 using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::task;
+using namespace ::com::sun::star::util;
 
 SfxTemplateInfoDlg::SfxTemplateInfoDlg (Window *pParent)
     : ModalDialog(pParent,SfxResId(DLG_TEMPLATE_INFORMATION)),
       maBtnClose(this,SfxResId(BTN_TEMPLATE_INFO_CLOSE)),
+      mpPreviewView(new Window(this)),
       mpInfoView(new svtools::ODocumentInfoPreview(this,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK))
 {
     Size aWinSize = GetOutputSizePixel();
     aWinSize.setHeight( aWinSize.getHeight() - 3*DLG_BORDER_SIZE - maBtnClose.GetOutputHeightPixel() );
     aWinSize.setWidth( (aWinSize.getWidth() - 3*DLG_BORDER_SIZE)/2 );
     mpInfoView->SetPosSizePixel(Point(DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
+
+    mpPreviewView->SetPosSizePixel(Point(aWinSize.getWidth()+2*DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
+
+    xWindow = VCLUnoHelper::GetInterface(mpPreviewView);
+
+    xFrame.set(comphelper::getProcessServiceFactory()->createInstance("com.sun.star.frame.Frame"), uno::UNO_QUERY );
+    xFrame->initialize( xWindow );
+
+    mpPreviewView->Show();
     mpInfoView->Show();
 }
 
 SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
 {
+    xFrame->dispose();
+
     delete mpInfoView;
 }
 
 void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
 {
+    assert(!rURL.isEmpty());
+
     uno::Reference<lang::XMultiServiceFactory> xContext(comphelper::getProcessServiceFactory());
 
     try
@@ -64,6 +86,38 @@ void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
         xDocProps->loadFromMedium( rURL, aProps );
 
         mpInfoView->fill( xDocProps, rURL );
+
+        // Create template preview
+        uno::Reference<util::XURLTransformer > xTrans(
+                    util::URLTransformer::create(comphelper::getProcessComponentContext()));
+
+        util::URL aURL;
+        aURL.Complete = rURL;
+        xTrans->parseStrict(aURL);
+
+        uno::Reference<frame::XDispatchProvider> xProv( xFrame, uno::UNO_QUERY );
+
+        uno::Reference<frame::XDispatch> xDisp = xProv.is() ?
+            xProv->queryDispatch( aURL, "_self", 0 ) : uno::Reference<XDispatch>();
+
+        if ( xDisp.is() )
+        {
+            mpPreviewView->EnableInput( false, true );
+
+            bool b = true;
+            uno::Sequence <beans::PropertyValue> aArgs( 4 );
+            aArgs[0].Name = "Preview";
+            aArgs[0].Value.setValue( &b, ::getBooleanCppuType() );
+            aArgs[1].Name = "ReadOnly";
+            aArgs[1].Value.setValue( &b, ::getBooleanCppuType() );
+            aArgs[2].Name = "AsTemplate";    // prevents getting an empty URL with getURL()!
+            aArgs[3].Name = "InteractionHandler";
+            aArgs[3].Value <<= xInteractionHandler;
+
+            b = false;
+            aArgs[2].Value.setValue( &b, ::getBooleanCppuType() );
+            xDisp->dispatch( aURL, aArgs );
+        }
     }
     catch ( beans::UnknownPropertyException& )
     {
commit cda4febfcf81473e7c0d4f8fe52212d282fa14d1
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Tue Aug 14 14:19:21 2012 -0430

    Display template information like author,type,keywords,etc.
    
    Change-Id: I541ba1e40bd320701fac5d75615c8c9486dfebb9

diff --git a/sfx2/inc/sfx2/templateinfodlg.hxx b/sfx2/inc/sfx2/templateinfodlg.hxx
index e827531..dd031be 100644
--- a/sfx2/inc/sfx2/templateinfodlg.hxx
+++ b/sfx2/inc/sfx2/templateinfodlg.hxx
@@ -25,6 +25,8 @@ public:
 
     ~SfxTemplateInfoDlg ();
 
+    void loadDocument (const OUString &rURL);
+
 private:
 
     PushButton maBtnClose;
diff --git a/sfx2/source/dialog/templateinfodlg.cxx b/sfx2/source/dialog/templateinfodlg.cxx
index a1535d2..2ed6794 100644
--- a/sfx2/source/dialog/templateinfodlg.cxx
+++ b/sfx2/source/dialog/templateinfodlg.cxx
@@ -9,19 +9,68 @@
 
 #include <sfx2/templateinfodlg.hxx>
 
+#include <comphelper/processfactory.hxx>
 #include <sfx2/sfxresid.hxx>
 #include <svtools/DocumentInfoPreview.hxx>
 
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
+
 #include "templateinfodlg.hrc"
 
+#define DLG_BORDER_SIZE 12
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::task;
+
 SfxTemplateInfoDlg::SfxTemplateInfoDlg (Window *pParent)
     : ModalDialog(pParent,SfxResId(DLG_TEMPLATE_INFORMATION)),
-      maBtnClose(this,SfxResId(BTN_TEMPLATE_INFO_CLOSE))
+      maBtnClose(this,SfxResId(BTN_TEMPLATE_INFO_CLOSE)),
+      mpInfoView(new svtools::ODocumentInfoPreview(this,WB_LEFT | WB_VSCROLL | WB_READONLY | WB_BORDER | WB_3DLOOK))
 {
+    Size aWinSize = GetOutputSizePixel();
+    aWinSize.setHeight( aWinSize.getHeight() - 3*DLG_BORDER_SIZE - maBtnClose.GetOutputHeightPixel() );
+    aWinSize.setWidth( (aWinSize.getWidth() - 3*DLG_BORDER_SIZE)/2 );
+    mpInfoView->SetPosSizePixel(Point(DLG_BORDER_SIZE,DLG_BORDER_SIZE),aWinSize);
+    mpInfoView->Show();
 }
 
 SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
 {
+    delete mpInfoView;
+}
+
+void SfxTemplateInfoDlg::loadDocument(const OUString &rURL)
+{
+    uno::Reference<lang::XMultiServiceFactory> xContext(comphelper::getProcessServiceFactory());
+
+    try
+    {
+        uno::Reference<task::XInteractionHandler> xInteractionHandler(
+                    xContext->createInstance("com.sun.star.task.InteractionHandler"), uno::UNO_QUERY );
+
+        uno::Sequence<beans::PropertyValue> aProps(1);
+        aProps[0].Name = "InteractionHandler";
+        aProps[0].Value <<= xInteractionHandler;
+
+        uno::Reference<document::XDocumentProperties> xDocProps(
+                    xContext->createInstance("com.sun.star.document.DocumentProperties"), uno::UNO_QUERY );
+
+        xDocProps->loadFromMedium( rURL, aProps );
+
+        mpInfoView->fill( xDocProps, rURL );
+    }
+    catch ( beans::UnknownPropertyException& )
+    {
+    }
+    catch ( uno::Exception& )
+    {
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index 80aa1a9..04bbddc 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -947,7 +947,10 @@ void SfxTemplateManagerDlg::OnTemplateEdit ()
 
 void SfxTemplateManagerDlg::OnTemplateProperties ()
 {
+    const TemplateViewItem *pItem = static_cast<const TemplateViewItem*>(*maSelTemplates.begin());
+
     SfxTemplateInfoDlg aDlg;
+    aDlg.loadDocument(pItem->getPath());
     aDlg.Execute();
 }
 
commit 0c03f7945e89e52a473a21267a4bd18970da52d3
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Tue Aug 14 12:17:35 2012 -0430

    Display template preview and information when clicking properties.
    
    Change-Id: I9a783c39f04a19cd65a292f3ebff923bb845f2c4

diff --git a/sfx2/AllLangResTarget_sfx2.mk b/sfx2/AllLangResTarget_sfx2.mk
index ce9e93e..0d16f68 100644
--- a/sfx2/AllLangResTarget_sfx2.mk
+++ b/sfx2/AllLangResTarget_sfx2.mk
@@ -64,6 +64,7 @@ $(eval $(call gb_SrsTarget_add_files,sfx/res,\
     sfx2/source/dialog/securitypage.src \
     sfx2/source/dialog/srchdlg.src \
     sfx2/source/dialog/taskpane.src \
+    sfx2/source/dialog/templateinfodlg.src \
     sfx2/source/dialog/templdlg.src \
     sfx2/source/dialog/titledockwin.src \
     sfx2/source/dialog/versdlg.src \
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index 95c68e2..50e5521 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -171,6 +171,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/dialog/styledlg \
     sfx2/source/dialog/tabdlg \
     sfx2/source/dialog/taskpane \
+    sfx2/source/dialog/templateinfodlg \
     sfx2/source/dialog/templdlg \
     sfx2/source/dialog/titledockwin \
     sfx2/source/dialog/tplcitem \
diff --git a/sfx2/Package_inc.mk b/sfx2/Package_inc.mk
index 1a71255..31f190d 100644
--- a/sfx2/Package_inc.mk
+++ b/sfx2/Package_inc.mk
@@ -119,6 +119,7 @@ $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/tbxctrl.hxx,sfx2/tbxctrl.hxx
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templdlg.hxx,sfx2/templdlg.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocnames.hrc,sfx2/templatelocnames.hrc))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateabstractview.hxx,sfx2/templateabstractview.hxx))
+$(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateinfodlg.hxx,sfx2/templateinfodlg.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templateview.hxx,sfx2/templateview.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocalview.hxx,sfx2/templatelocalview.hxx))
 $(eval $(call gb_Package_add_file,sfx2_inc,inc/sfx2/templatelocalviewitem.hxx,sfx2/templatelocalviewitem.hxx))
diff --git a/sfx2/inc/sfx2/templateinfodlg.hxx b/sfx2/inc/sfx2/templateinfodlg.hxx
new file mode 100644
index 0000000..e827531
--- /dev/null
+++ b/sfx2/inc/sfx2/templateinfodlg.hxx
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#ifndef __SFX2_TEMPLATEINFODLG_HXX__
+#define __SFX2_TEMPLATEINFODLG_HXX__
+
+#include <vcl/dialog.hxx>
+#include <vcl/button.hxx>
+
+namespace svtools {
+    class ODocumentInfoPreview;
+}
+
+class SfxTemplateInfoDlg : public ModalDialog
+{
+public:
+
+    SfxTemplateInfoDlg (Window *pParent = NULL);
+
+    ~SfxTemplateInfoDlg ();
+
+private:
+
+    PushButton maBtnClose;
+
+    Window *mpPreviewView;
+    svtools::ODocumentInfoPreview *mpInfoView;
+};
+
+#endif // __SFX2_TEMPLATEINFODLG_HXX__
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/inc/templatedlg.hxx b/sfx2/inc/templatedlg.hxx
index bed10a6..40fa0bf 100644
--- a/sfx2/inc/templatedlg.hxx
+++ b/sfx2/inc/templatedlg.hxx
@@ -17,6 +17,7 @@
 
 class Edit;
 class PopupMenu;
+class SfxTemplateInfoDlg;
 class TemplateAbstractView;
 class TemplateLocalView;
 class TemplateOnlineView;
diff --git a/sfx2/source/dialog/templateinfodlg.cxx b/sfx2/source/dialog/templateinfodlg.cxx
new file mode 100644
index 0000000..a1535d2
--- /dev/null
+++ b/sfx2/source/dialog/templateinfodlg.cxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* License, v. 2.0. If a copy of the MPL was not distributed with this
+* file, You can obtain one at http://mozilla.org/MPL/2.0/.
+*/
+
+#include <sfx2/templateinfodlg.hxx>
+
+#include <sfx2/sfxresid.hxx>
+#include <svtools/DocumentInfoPreview.hxx>
+
+#include "templateinfodlg.hrc"
+
+SfxTemplateInfoDlg::SfxTemplateInfoDlg (Window *pParent)
+    : ModalDialog(pParent,SfxResId(DLG_TEMPLATE_INFORMATION)),
+      maBtnClose(this,SfxResId(BTN_TEMPLATE_INFO_CLOSE))
+{
+}
+
+SfxTemplateInfoDlg::~SfxTemplateInfoDlg()
+{
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/dialog/templateinfodlg.hrc b/sfx2/source/dialog/templateinfodlg.hrc
new file mode 100644
index 0000000..e6069c1
--- /dev/null
+++ b/sfx2/source/dialog/templateinfodlg.hrc
@@ -0,0 +1,11 @@
+/*
+ * Copyright 2012 LibreOffice contributors.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#define DLG_TEMPLATE_INFORMATION        400
+
+#define BTN_TEMPLATE_INFO_CLOSE         11
diff --git a/sfx2/source/dialog/templateinfodlg.src b/sfx2/source/dialog/templateinfodlg.src
new file mode 100644
index 0000000..6126b21
--- /dev/null
+++ b/sfx2/source/dialog/templateinfodlg.src
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2012 LibreOffice contributors.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "templateinfodlg.hrc"
+
+ModalDialog DLG_TEMPLATE_INFORMATION
+{
+    OutputSize = TRUE;
+    SVLook = TRUE;
+    Size = MAP_APPFONT( 250, 180 );
+    Moveable = TRUE;
+    Closeable = TRUE;
+
+    PushButton BTN_TEMPLATE_INFO_CLOSE
+    {
+        Pos = MAP_APPFONT( 194, 160 );
+        Size = MAP_APPFONT( 50, 14 );
+        Text [ en-US ] = "Close";
+    };
+};
diff --git a/sfx2/source/doc/templatedlg.cxx b/sfx2/source/doc/templatedlg.cxx
index d93162a..80aa1a9 100644
--- a/sfx2/source/doc/templatedlg.cxx
+++ b/sfx2/source/doc/templatedlg.cxx
@@ -20,6 +20,7 @@
 #include <sfx2/fcontnr.hxx>
 #include <sfx2/filedlghelper.hxx>
 #include <sfx2/sfxresid.hxx>
+#include <sfx2/templateinfodlg.hxx>
 #include <sfx2/templatelocalview.hxx>
 #include <sfx2/templatelocalviewitem.hxx>
 #include <sfx2/templateonlineview.hxx>
@@ -946,6 +947,8 @@ void SfxTemplateManagerDlg::OnTemplateEdit ()
 
 void SfxTemplateManagerDlg::OnTemplateProperties ()
 {
+    SfxTemplateInfoDlg aDlg;
+    aDlg.Execute();
 }
 
 void SfxTemplateManagerDlg::OnTemplateDelete ()
commit 4fe7c4f3a98b97034e880ceebcea2b6fecd05852
Author: Rafael Dominguez <venccsralph at gmail.com>
Date:   Sun Aug 12 23:57:51 2012 -0430

    Show template manager dialog instead of save template dialog.
    
    - Only when experimental features is activated.
    
    Change-Id: Id60853b93f2766a5ff6a1c21907675891ab26396

diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 3ae76e6..352245a 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -94,6 +94,7 @@
 #include "helpid.hrc"
 
 #include "guisaveas.hxx"
+#include "templatedlg.hxx"
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::lang;
@@ -518,10 +519,10 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
                 {
                     // get statusindicator
                     uno::Reference< task::XStatusIndicator > xStatusIndicator;
-					uno::Reference < frame::XController > xCtrl( GetModel()->getCurrentController() );
-					if ( xCtrl.is() )
+                    uno::Reference < frame::XController > xCtrl( GetModel()->getCurrentController() );
+                    if ( xCtrl.is() )
                     {
-						uno::Reference< task::XStatusIndicatorFactory > xStatFactory( xCtrl->getFrame(), uno::UNO_QUERY );
+                        uno::Reference< task::XStatusIndicatorFactory > xStatFactory( xCtrl->getFrame(), uno::UNO_QUERY );
                         if( xStatFactory.is() )
                             xStatusIndicator = xStatFactory->createStatusIndicator();
                     }
@@ -799,79 +800,88 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
         case SID_DOCTEMPLATE:
         {
             // save as document templates
-            SfxDocumentTemplateDlg *pDlg = 0;
-            SfxErrorContext aEc(ERRCTX_SFX_DOCTEMPLATE,GetTitle());
-            SfxDocumentTemplates *pTemplates =  new SfxDocumentTemplates;
-
-            if ( !rReq.GetArgs() )
+            SvtMiscOptions aMiscOptions;
+            if ( aMiscOptions.IsExperimentalMode() )
+            {
+                SfxTemplateManagerDlg aDlg(NULL);
+                aDlg.Execute();
+            }
+            else
             {
-                pDlg = new SfxDocumentTemplateDlg(0, pTemplates);
-                if ( RET_OK == pDlg->Execute() && pDlg->GetTemplateName().Len())
+                SfxDocumentTemplateDlg *pDlg = 0;
+                SfxErrorContext aEc(ERRCTX_SFX_DOCTEMPLATE,GetTitle());
+                SfxDocumentTemplates *pTemplates =  new SfxDocumentTemplates;
+
+                if ( !rReq.GetArgs() )
                 {
-                    rReq.AppendItem(SfxStringItem(
-                        SID_TEMPLATE_NAME, pDlg->GetTemplateName()));
-                    rReq.AppendItem(SfxStringItem(
-                        SID_TEMPLATE_REGIONNAME, pDlg->GetRegionName()));
+                    pDlg = new SfxDocumentTemplateDlg(0, pTemplates);
+                    if ( RET_OK == pDlg->Execute() && pDlg->GetTemplateName().Len())
+                    {
+                        rReq.AppendItem(SfxStringItem(
+                            SID_TEMPLATE_NAME, pDlg->GetTemplateName()));
+                        rReq.AppendItem(SfxStringItem(
+                            SID_TEMPLATE_REGIONNAME, pDlg->GetRegionName()));
+                    }
+                    else
+                    {
+                        delete pDlg;
+                        rReq.Ignore();
+                        return;
+                    }
                 }
-                else
+
+                SFX_REQUEST_ARG(rReq, pRegionItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, sal_False);
+                SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
+                SFX_REQUEST_ARG(rReq, pRegionNrItem, SfxUInt16Item, SID_TEMPLATE_REGION, sal_False);
+                if ( (!pRegionItem && !pRegionNrItem ) || !pNameItem )
                 {
-                    delete pDlg;
+                    DBG_ASSERT( rReq.IsAPI(), "non-API call without Arguments" );
+    #ifndef DISABLE_SCRIPTING
+                    SbxBase::SetError( SbxERR_WRONG_ARGS );
+    #endif
                     rReq.Ignore();
                     return;
                 }
-            }
 
-            SFX_REQUEST_ARG(rReq, pRegionItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, sal_False);
-            SFX_REQUEST_ARG(rReq, pNameItem, SfxStringItem, SID_TEMPLATE_NAME, sal_False);
-            SFX_REQUEST_ARG(rReq, pRegionNrItem, SfxUInt16Item, SID_TEMPLATE_REGION, sal_False);
-            if ( (!pRegionItem && !pRegionNrItem ) || !pNameItem )
-            {
-                DBG_ASSERT( rReq.IsAPI(), "non-API call without Arguments" );
-#ifndef DISABLE_SCRIPTING
-                SbxBase::SetError( SbxERR_WRONG_ARGS );
-#endif
-                rReq.Ignore();
-                return;
-            }
-
-            ::rtl::OUString aTemplateName = pNameItem->GetValue();
-            ::rtl::OUString aTemplateGroup;
-            if ( pRegionItem )
-                aTemplateGroup = pRegionItem->GetValue();
-            else
-                // pRegionNrItem must not be NULL, it was just checked
-                aTemplateGroup = pTemplates->GetFullRegionName( pRegionNrItem->GetValue() );
-            // check Group and Name
-            delete pTemplates;
+                ::rtl::OUString aTemplateName = pNameItem->GetValue();
+                ::rtl::OUString aTemplateGroup;
+                if ( pRegionItem )
+                    aTemplateGroup = pRegionItem->GetValue();
+                else
+                    // pRegionNrItem must not be NULL, it was just checked
+                    aTemplateGroup = pTemplates->GetFullRegionName( pRegionNrItem->GetValue() );
+                // check Group and Name
+                delete pTemplates;
 
-            sal_Bool bOk = sal_False;
-            try
-            {
-                uno::Reference< frame::XStorable > xStorable( GetModel(), uno::UNO_QUERY_THROW );
-                uno::Reference< frame::XDocumentTemplates > xTemplates(
-                                frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) );
+                sal_Bool bOk = sal_False;
+                try
+                {
+                    uno::Reference< frame::XStorable > xStorable( GetModel(), uno::UNO_QUERY_THROW );
+                    uno::Reference< frame::XDocumentTemplates > xTemplates(
+                                    frame::DocumentTemplates::create(comphelper::getProcessComponentContext()) );
 
-                bOk = xTemplates->storeTemplate( aTemplateGroup, aTemplateName, xStorable );
-            }
-            catch( uno::Exception& )
-            {
-            }
+                    bOk = xTemplates->storeTemplate( aTemplateGroup, aTemplateName, xStorable );
+                }
+                catch( uno::Exception& )
+                {
+                }
 
-            DELETEX(pDlg);
+                DELETEX(pDlg);
 
-            rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
-            if ( bOk )
-            {
-                // update the Organizer runtime cache from the template
-                // component if the cache has already been created
-                // TODO/LATER: get rid of this cache duplication
-                SfxDocumentTemplates aTemplates;
-                aTemplates.ReInitFromComponent();
-            }
-            else
-            {
-                ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
-                return;
+                rReq.SetReturnValue( SfxBoolItem( 0, bOk ) );
+                if ( bOk )
+                {
+                    // update the Organizer runtime cache from the template
+                    // component if the cache has already been created
+                    // TODO/LATER: get rid of this cache duplication
+                    SfxDocumentTemplates aTemplates;
+                    aTemplates.ReInitFromComponent();
+                }
+                else
+                {
+                    ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
+                    return;
+                }
             }
 
             break;


More information about the Libreoffice-commits mailing list