[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sw/source

Jan Holesovsky kendy at collabora.com
Thu Jan 18 09:59:02 UTC 2018


 sw/source/ui/dialog/swdlgfact.hxx   |    9 +
 sw/source/uibase/shells/textsh1.cxx |  166 +++++++++++++++++++-----------------
 2 files changed, 96 insertions(+), 79 deletions(-)

New commits:
commit ba5556e62ed3fda9f02aaf7d3ba23c19af7dbdfc
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Tue Jan 16 13:41:34 2018 +0100

    lokdialog: Convert the Format -> Character... dialog to async exec.
    
    Change-Id: Idd1407f54729f7be18d458db7bda7de0b0cc6ad6
    Reviewed-on: https://gerrit.libreoffice.org/47988
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx
index 63d82b707c4e..50c6929ce1f4 100644
--- a/sw/source/ui/dialog/swdlgfact.hxx
+++ b/sw/source/ui/dialog/swdlgfact.hxx
@@ -53,12 +53,17 @@ public:                                             \
     explicit        Class( DialogClass* p)          \
                      : pDlg(p)                      \
                      {}                             \
-    virtual short   Execute() override ;
+    virtual short   Execute() override;             \
+    virtual bool    StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) override;
 
 #define IMPL_ABSTDLG_BASE(Class)                    \
-short Class::Execute()                             \
+short Class::Execute()                              \
 {                                                   \
     return pDlg->Execute();                         \
+}                                                   \
+bool Class::StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) \
+{ \
+    return pDlg->StartExecuteAsync(rCtx); \
 }
 
 class SwWordCountFloatDlg;
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index f0977e1fcbda..1434c35a1e52 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -121,11 +121,13 @@
 using namespace ::com::sun::star;
 using namespace svx::sidebar;
 
-void sw_CharDialog( SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot,const SfxItemSet *pArgs, SfxRequest *pReq )
+void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> pCoreSet, bool bSel, bool bSelectionPut, SfxRequest *pReq);
+
+void sw_CharDialog(SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot, const SfxItemSet *pArgs, SfxRequest *pReq )
 {
     FieldUnit eMetric = ::GetDfltMetric(dynamic_cast<SwWebView*>( &rWrtSh.GetView()) != nullptr );
     SW_MOD()->PutItem(SfxUInt16Item(SID_ATTR_METRIC, static_cast< sal_uInt16 >(eMetric)));
-    SfxItemSet aCoreSet( rWrtSh.GetView().GetPool(),
+    std::shared_ptr<SfxItemSet> pCoreSet(new SfxItemSet( rWrtSh.GetView().GetPool(),
                         RES_CHRATR_BEGIN,      RES_CHRATR_END-1,
                         RES_TXTATR_INETFMT,    RES_TXTATR_INETFMT,
                         RES_BACKGROUND,        RES_BACKGROUND,
@@ -135,8 +137,9 @@ void sw_CharDialog( SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot,const
                         FN_PARAM_SELECTION,    FN_PARAM_SELECTION,
                         SID_HTML_MODE,         SID_HTML_MODE,
                         SID_ATTR_CHAR_WIDTH_FIT_TO_LINE,   SID_ATTR_CHAR_WIDTH_FIT_TO_LINE,
-                        0 );
-    rWrtSh.GetCurAttr( aCoreSet );
+                        0));
+    rWrtSh.GetCurAttr(*pCoreSet);
+
     bool bSel = rWrtSh.HasSelection();
     bool bSelectionPut = false;
     if(bSel || rWrtSh.IsInWord())
@@ -148,7 +151,7 @@ void sw_CharDialog( SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot,const
             if(!rWrtSh.SelectTextAttr( RES_TXTATR_INETFMT ))
                 rWrtSh.SelWrd();
         }
-        aCoreSet.Put(SfxStringItem(FN_PARAM_SELECTION, rWrtSh.GetSelText()));
+        pCoreSet->Put(SfxStringItem(FN_PARAM_SELECTION, rWrtSh.GetSelText()));
         bSelectionPut = true;
         if(!bSel)
         {
@@ -156,102 +159,111 @@ void sw_CharDialog( SwWrtShell &rWrtSh, bool bUseDialog, sal_uInt16 nSlot,const
             rWrtSh.EndAction();
         }
     }
-        aCoreSet.Put( SfxUInt16Item( SID_ATTR_CHAR_WIDTH_FIT_TO_LINE,
-                    rWrtSh.GetScalingOfSelectedText() ) );
+    pCoreSet->Put(SfxUInt16Item(SID_ATTR_CHAR_WIDTH_FIT_TO_LINE, rWrtSh.GetScalingOfSelectedText()));
 
-    ::ConvertAttrCharToGen(aCoreSet, CONV_ATTR_STD);
+    ::ConvertAttrCharToGen(*pCoreSet, CONV_ATTR_STD);
 
     // Setting the BoxInfo
-    ::PrepareBoxInfo( aCoreSet, rWrtSh );
+    ::PrepareBoxInfo(*pCoreSet, rWrtSh);
 
-    aCoreSet.Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(rWrtSh.GetView().GetDocShell())));
-    ScopedVclPtr<SfxAbstractTabDialog> pDlg;
+    pCoreSet->Put(SfxUInt16Item(SID_HTML_MODE, ::GetHtmlMode(rWrtSh.GetView().GetDocShell())));
+    VclPtr<SfxAbstractTabDialog> pDlg;
     if ( bUseDialog && GetActiveView() )
     {
         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
         OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
 
-        pDlg.disposeAndReset(pFact->CreateSwCharDlg(rWrtSh.GetView().GetWindow(), rWrtSh.GetView(), aCoreSet, SwCharDlgMode::Std));
-        OSL_ENSURE(pDlg, "Dialog creation failed!");
-        if( FN_INSERT_HYPERLINK == nSlot )
+        pDlg.reset(pFact->CreateSwCharDlg(rWrtSh.GetView().GetWindow(), rWrtSh.GetView(), *pCoreSet, SwCharDlgMode::Std));
+        if (!pDlg)
+        {
+            SAL_WARN("sw.ui", "Dialog creation failed!");
+            return;
+        }
+
+        if (nSlot == FN_INSERT_HYPERLINK)
             pDlg->SetCurPageId("hyperlink");
-    }
-    if (pDlg && nSlot == SID_CHAR_DLG_EFFECT)
-    {
-        pDlg->SetCurPageId("fonteffects");
-    }
-    else if (pDlg && (nSlot == SID_ATTR_CHAR_FONT || nSlot == SID_CHAR_DLG_FOR_PARAGRAPH))
-    {
-        pDlg->SetCurPageId("font");
-    }
-    else if (pDlg && pReq)
-    {
-        const SfxStringItem* pItem = (*pReq).GetArg<SfxStringItem>(FN_PARAM_1);
-        if (pItem)
-            pDlg->SetCurPageId(OUStringToOString(pItem->GetValue(), RTL_TEXTENCODING_UTF8));
+        else if (nSlot == SID_CHAR_DLG_EFFECT)
+            pDlg->SetCurPageId("fonteffects");
+        else if (nSlot == SID_ATTR_CHAR_FONT || nSlot == SID_CHAR_DLG_FOR_PARAGRAPH)
+            pDlg->SetCurPageId("font");
+        else if (pReq)
+        {
+            const SfxStringItem* pItem = (*pReq).GetArg<SfxStringItem>(FN_PARAM_1);
+            if (pItem)
+                pDlg->SetCurPageId(OUStringToOString(pItem->GetValue(), RTL_TEXTENCODING_UTF8));
+        }
     }
 
-    const SfxItemSet* pSet = nullptr;
-    if ( !bUseDialog )
-        pSet = pArgs;
-    else if ( pDlg && pDlg->Execute() == RET_OK ) /* #110771# pDlg can be NULL */
+    if (bUseDialog)
     {
-        pSet = pDlg->GetOutputItemSet();
-    }
+        std::shared_ptr<SfxRequest> pRequest(new SfxRequest(*pReq));
+        pReq->Ignore(); // the 'old' request is not relevant any more
 
-    if ( pSet)
+        pDlg->StartExecuteAsync([pDlg, &rWrtSh, pCoreSet, bSel, bSelectionPut, pRequest](sal_Int32 nResult){
+            if (nResult == RET_OK)
+            {
+                sw_CharDialogResult(pDlg->GetOutputItemSet(), rWrtSh, pCoreSet, bSel, bSelectionPut, pRequest.get());
+            }
+        }, pDlg);
+    }
+    else if (pArgs)
     {
-        SfxItemSet aTmpSet( *pSet );
-        ::ConvertAttrGenToChar(aTmpSet, aCoreSet, CONV_ATTR_STD);
+        sw_CharDialogResult(pArgs, rWrtSh, pCoreSet, bSel, bSelectionPut, pReq);
+    }
+}
 
-        const SfxPoolItem* pSelectionItem;
-        bool bInsert = false;
-        sal_Int32 nInsert = 0;
+void sw_CharDialogResult(const SfxItemSet* pSet, SwWrtShell &rWrtSh, std::shared_ptr<SfxItemSet> pCoreSet, bool bSel, bool bSelectionPut, SfxRequest *pReq)
+{
+    SfxItemSet aTmpSet( *pSet );
+    ::ConvertAttrGenToChar(aTmpSet, *pCoreSet, CONV_ATTR_STD);
 
-        // The old item is for unknown reasons back in the set again.
-        if( !bSelectionPut && SfxItemState::SET == aTmpSet.GetItemState(FN_PARAM_SELECTION, false, &pSelectionItem) )
-        {
-            OUString sInsert = static_cast<const SfxStringItem*>(pSelectionItem)->GetValue();
-            bInsert = !sInsert.isEmpty();
-            if(bInsert)
-            {
-                nInsert = sInsert.getLength();
-                rWrtSh.StartAction();
-                rWrtSh.Insert( sInsert );
-                rWrtSh.SetMark();
-                rWrtSh.ExtendSelection(false, sInsert.getLength());
-                SfxRequest aReq( rWrtSh.GetView().GetViewFrame(), FN_INSERT_STRING );
-                aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, sInsert ) );
-                aReq.Done();
-                SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_LEFT );
-                aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nInsert) );
-                aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, true) );
-                aReq1.Done();
-            }
-        }
-        aTmpSet.ClearItem(FN_PARAM_SELECTION);
+    const SfxPoolItem* pSelectionItem;
+    bool bInsert = false;
+    sal_Int32 nInsert = 0;
 
-        SwTextFormatColl* pColl = rWrtSh.GetCurTextFormatColl();
-        if(bSel && rWrtSh.IsSelFullPara() && pColl && pColl->IsAutoUpdateFormat())
-        {
-            rWrtSh.AutoUpdatePara(pColl, aTmpSet);
-        }
-        else
-            rWrtSh.SetAttrSet( aTmpSet );
-        if (pReq)
-            pReq->Done(aTmpSet);
+    // The old item is for unknown reasons back in the set again.
+    if( !bSelectionPut && SfxItemState::SET == aTmpSet.GetItemState(FN_PARAM_SELECTION, false, &pSelectionItem) )
+    {
+        OUString sInsert = static_cast<const SfxStringItem*>(pSelectionItem)->GetValue();
+        bInsert = !sInsert.isEmpty();
         if(bInsert)
         {
-            SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_RIGHT );
+            nInsert = sInsert.getLength();
+            rWrtSh.StartAction();
+            rWrtSh.Insert( sInsert );
+            rWrtSh.SetMark();
+            rWrtSh.ExtendSelection(false, sInsert.getLength());
+            SfxRequest aReq( rWrtSh.GetView().GetViewFrame(), FN_INSERT_STRING );
+            aReq.AppendItem( SfxStringItem( FN_INSERT_STRING, sInsert ) );
+            aReq.Done();
+            SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_LEFT );
             aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nInsert) );
-            aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, false) );
+            aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, true) );
             aReq1.Done();
-            rWrtSh.SwapPam();
-            rWrtSh.ClearMark();
-            rWrtSh.DontExpandFormat();
-            rWrtSh.EndAction();
         }
     }
+    aTmpSet.ClearItem(FN_PARAM_SELECTION);
+
+    SwTextFormatColl* pColl = rWrtSh.GetCurTextFormatColl();
+    if(bSel && rWrtSh.IsSelFullPara() && pColl && pColl->IsAutoUpdateFormat())
+    {
+        rWrtSh.AutoUpdatePara(pColl, aTmpSet);
+    }
+    else
+        rWrtSh.SetAttrSet( aTmpSet );
+    if (pReq)
+        pReq->Done(aTmpSet);
+    if(bInsert)
+    {
+        SfxRequest aReq1( rWrtSh.GetView().GetViewFrame(), FN_CHAR_RIGHT );
+        aReq1.AppendItem( SfxInt32Item(FN_PARAM_MOVE_COUNT, nInsert) );
+        aReq1.AppendItem( SfxBoolItem(FN_PARAM_MOVE_SELECTION, false) );
+        aReq1.Done();
+        rWrtSh.SwapPam();
+        rWrtSh.ClearMark();
+        rWrtSh.DontExpandFormat();
+        rWrtSh.EndAction();
+    }
 }
 
 static short lcl_AskRedlineFlags(vcl::Window *pWin)


More information about the Libreoffice-commits mailing list