sw/qa/uitest/ui/frmdlg/frmdlg.py   |   20 +++++++++++++++++++-
 sw/source/ui/frmdlg/frmpage.cxx    |   16 +++++++++++++++-
 sw/source/uibase/frmdlg/frmmgr.cxx |   25 ++++++++++++++++++-------
 sw/source/uibase/inc/frmmgr.hxx    |    2 ++
 4 files changed, 54 insertions(+), 9 deletions(-)

New commits:
commit e306352b9ddd8bddfc37f0cfaac078d9260650d6
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Nov 9 08:51:59 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Nov 9 11:37:33 2023 +0100

    sw floattable, insert UI: allow direct creation of floating tables
    
    The frame insert UI could move a table into a new fly, and then the
    frame properties allowed marking this fly as a split fly, but not in one
    step.
    
    This happened because the "split fly" checkbox is only visible when we
    have a fly that has exactly 1 table, but the "new frame" dialog has no
    fly as it still has to be created.
    
    Fix the problem by showing the "split fly" checkbox if we don't have a
    fly, but a single table is selected, because we know
    SwDoc::MakeFlyAndMove() will create a fly that has exactly one table in
    it.
    
    Extract the common code to a new
    SwFlyFrameAttrMgr::SingleTableSelected() to avoid copy&paste.
    
    Change-Id: I24129e3fb4cb6231fb10b0adda53c205dfd90d62
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159201
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/uitest/ui/frmdlg/frmdlg.py b/sw/qa/uitest/ui/frmdlg/frmdlg.py
index e30b67ff5313..4a438895572b 100644
--- a/sw/qa/uitest/ui/frmdlg/frmdlg.py
+++ b/sw/qa/uitest/ui/frmdlg/frmdlg.py
@@ -17,7 +17,7 @@ from uitest.uihelper.common import get_url_for_data_file
 
 
 class Test(UITestCase):
-    def test_content_control_dialog(self):
+    def test_uno_frame_dialog(self):
         with self.ui_test.create_doc_in_start_center("writer") as xComponent:
             # Given a document with a floating table:
             args = {
@@ -80,4 +80,22 @@ class Test(UITestCase):
                 # i.e. the width was empty instead of the size from the UI.
                 self.assertEqual(xComponent.TextFrames.Frame1.Size.Width, 
expected_mm100)
 
+    def test_insert_floating_table(self):
+        with self.ui_test.create_doc_in_start_center("writer") as xComponent:
+            # Given a Writer document with a selected (inline) table:
+            args = {
+                "Columns": 1,
+                "Rows": 1,
+            }
+            self.xUITest.executeCommandWithParameters(".uno:InsertTable", 
mkPropertyValues(args))
+            self.xUITest.executeCommand(".uno:SelectAll")
+            # When converting it to a split fly:
+            with 
self.ui_test.execute_dialog_through_command(".uno:InsertFrame") as xDialog:
+                xFlySplit = xDialog.getChild("flysplit")
+                fly_split_visible = get_state_as_dict(xFlySplit)["Visible"] == 
"true"
+            # Then make sure the inserted fly can be marked as "split allowed":
+            # Without the accompanying fix in place, this test would have 
failed, the fly had to be
+            # inserted first, only then it could be marked as "split allowed".
+            self.assertEqual(fly_split_visible, True)
+
 # vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx
index b38ac22d0d11..911df55f66d7 100644
--- a/sw/source/ui/frmdlg/frmpage.cxx
+++ b/sw/source/ui/frmdlg/frmpage.cxx
@@ -1050,9 +1050,23 @@ void SwFramePage::Reset( const SfxItemSet *rSet )
     const SwFrameFormat* pFlyFormat = pSh->GetFlyFrameFormat();
     if (!pFlyFormat || !ContainsSingleTable(*pFlyFormat) || 
ContainsChain(*pFlyFormat))
     {
+        bool bSingleTable = false;
+        if (!pFlyFormat && m_bNew)
+        {
+            // No fly is selected: check if a whole table is selected. If so, 
allow moving that into
+            // a split fly.
+            if (SwFlyFrameAttrMgr::SingleTableSelected(*pSh))
+            {
+                bSingleTable = true;
+            }
+        }
+
         // Only allow fly split if the frame contains a single table, 
otherwise it would be hard to
         // save the resulting model to Word formats.
-        m_xFlySplitCB->hide();
+        if (!bSingleTable)
+        {
+            m_xFlySplitCB->hide();
+        }
     }
 
     Init(*rSet);
diff --git a/sw/source/uibase/frmdlg/frmmgr.cxx 
b/sw/source/uibase/frmdlg/frmmgr.cxx
index a71b7ef3fb0a..eb38c1c803f7 100644
--- a/sw/source/uibase/frmdlg/frmmgr.cxx
+++ b/sw/source/uibase/frmdlg/frmmgr.cxx
@@ -625,36 +625,47 @@ void SwFlyFrameAttrMgr::SetAttrSet(const SfxItemSet& rSet)
     m_aSet.Put( rSet );
 }
 
-void SwFlyFrameAttrMgr::SetFrameSizeFromTable()
+const SwTableFormat* SwFlyFrameAttrMgr::SingleTableSelected(SwWrtShell& 
rWrtShell)
 {
-    if (!m_pOwnSh->IsTableMode())
+    if (!rWrtShell.IsTableMode())
     {
-        return;
+        return nullptr;
     }
 
     // We have a table selection.
     SwSelBoxes aBoxes;
-    GetTableSel(*m_pOwnSh, aBoxes);
+    GetTableSel(rWrtShell, aBoxes);
     if (aBoxes.empty())
     {
-        return;
+        return nullptr;
     }
 
     auto pTableNd = 
const_cast<SwTableNode*>(aBoxes[0]->GetSttNd()->FindTableNode());
     if (!pTableNd)
     {
-        return;
+        return nullptr;
     }
 
     SwTable& rTable = pTableNd->GetTable();
     if (aBoxes.size() != rTable.GetTabSortBoxes().size())
+    {
+        return nullptr;
+    }
+
+    return rTable.GetFrameFormat();
+}
+
+void SwFlyFrameAttrMgr::SetFrameSizeFromTable()
+{
+    const SwTableFormat* pTableFormat = SingleTableSelected(*m_pOwnSh);
+    if (!pTableFormat)
     {
         return;
     }
 
     // The whole table is selected: default fly width should be the table width
     // in this case.
-    m_aSet.Put(rTable.GetFrameFormat()->GetFrameSize());
+    m_aSet.Put(pTableFormat->GetFrameSize());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/inc/frmmgr.hxx b/sw/source/uibase/inc/frmmgr.hxx
index f9186bd0707b..70e66d9bf139 100644
--- a/sw/source/uibase/inc/frmmgr.hxx
+++ b/sw/source/uibase/inc/frmmgr.hxx
@@ -125,6 +125,8 @@ public:
     SfxItemSet &GetAttrSet()       { return m_aSet; }
     void                     SetAttrSet(const SfxItemSet& rSet);
     void SetFrameSizeFromTable();
+    /// Checks if we have a table selection and that covers exactly 1 full 
table.
+    static const SwTableFormat* SingleTableSelected(SwWrtShell& rWrtShell);
 
     inline const SwFormatVertOrient &GetVertOrient() const;
     inline const SwFormatHoriOrient &GetHoriOrient() const;

Reply via email to