officecfg/registry/schema/org/openoffice/Office/Writer.xcs | 8 + sw/UIConfig_swriter.mk | 1 sw/inc/crsrsh.hxx | 1 sw/inc/editsh.hxx | 14 ++ sw/inc/pam.hxx | 2 sw/inc/swcrsr.hxx | 2 sw/qa/uitest/writer_tests7/tdf130199.py | 62 +++++++++++++ sw/qa/unit/data/sw-dialogs-test.txt | 1 sw/source/core/crsr/crsrsh.cxx | 26 +++++ sw/source/core/crsr/pam.cxx | 43 +++++++++ sw/source/core/crsr/swcrsr.cxx | 14 ++ sw/source/core/edit/eddel.cxx | 18 +++ sw/source/uibase/docvw/SidebarTxtControl.cxx | 4 sw/source/uibase/docvw/edtwin.cxx | 8 - sw/source/uibase/inc/wrtsh.hxx | 3 sw/source/uibase/shells/textsh1.cxx | 5 - sw/source/uibase/wrtsh/delete.cxx | 13 -- sw/source/uibase/wrtsh/wrtsh1.cxx | 21 ++++ sw/uiconfig/swriter/ui/warnhiddensectiondialog.ui | 35 +++++++ 19 files changed, 255 insertions(+), 26 deletions(-)
New commits: commit 30350edcf7734c5a5d1cbc657867a2dc09cade4f Author: Balazs Varga <[email protected]> AuthorDate: Sat Apr 8 16:05:26 2023 +0200 Commit: Balazs Varga <[email protected]> CommitDate: Wed Apr 19 09:30:38 2023 +0200 tdf#130199 sw Confirm deletion of hidden sections To enhance the existing discoverability of hidden sections via Navigator by a confirmation box when a hidden section is to be deleted. Also add an option to switch on/off this warning message named "ShowWarningHiddenSection". The default setting is on. Change-Id: I91a1a32524f8d8d8fd0f230c142654df4367e729 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150231 Tested-by: Jenkins Reviewed-by: Balazs Varga <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150551 Tested-by: Balazs Varga <[email protected]> diff --git a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs index 470d9f81ba8e..0c25de006f9e 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Writer.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Writer.xcs @@ -1071,6 +1071,14 @@ </info> <value>true</value> </prop> + <prop oor:name="ShowWarningHiddenSection" oor:type="xs:boolean" oor:nillable="false"> + <!-- UIHints: Not accessible via user interface --> + <info> + <desc>Enables the writer to prevent the display of a warning dialog for hidden text (sections, etc) deletion.</desc> + <label>Show warning dialog for hidden text deletion</label> + </info> + <value>true</value> + </prop> </group> <group oor:name="NonprintingCharacter"> <info> diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk index 65de527c3b89..18957faa5785 100644 --- a/sw/UIConfig_swriter.mk +++ b/sw/UIConfig_swriter.mk @@ -288,6 +288,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\ sw/uiconfig/swriter/ui/viewoptionspage \ sw/uiconfig/swriter/ui/warndatasourcedialog \ sw/uiconfig/swriter/ui/warnemaildialog \ + sw/uiconfig/swriter/ui/warnhiddensectiondialog \ sw/uiconfig/swriter/ui/watermarkdialog \ sw/uiconfig/swriter/ui/wordcount \ sw/uiconfig/swriter/ui/wrapdialog \ diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx index eab99525856b..a0205ffe4d52 100644 --- a/sw/inc/crsrsh.hxx +++ b/sw/inc/crsrsh.hxx @@ -479,6 +479,7 @@ public: // Cursor is placed in something that is protected or selection contains // something that is protected. bool HasReadonlySel(bool isReplace = false) const; + bool HasHiddenSections() const; // Can the cursor be set to read only ranges? bool IsReadOnlyAvailable() const { return m_bSetCursorInReadOnly; } diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 3f2d34d66c2e..fec0f48909a7 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -80,6 +80,7 @@ class SwLineNumberInfo; class SwAuthEntry; class SwRewriter; class SwView; +class SwWrtShell; struct SwConversionArgs; struct SvxSwAutoFormatFlags; struct SwInsertTableOptions; @@ -629,6 +630,19 @@ public: /// Apply ViewOptions with Start-/EndAction. virtual void ApplyViewOptions( const SwViewOption &rOpt ) override; + /// Selected area has readonly content + virtual void InfoReadOnlyDialog() const + { + // override in SwWrtShell + } + + /// Selected area has hidden content + virtual bool WarnHiddenSectionDialog() const + { + // override in SwWrtShell + return true; + } + /** Query text within selection. */ void GetSelectedText( OUString &rBuf, ParaBreakType nHndlParaBreak = ParaBreakType::ToBlank ); diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx index b8fafe762040..5e112fcfc809 100644 --- a/sw/inc/pam.hxx +++ b/sw/inc/pam.hxx @@ -253,6 +253,8 @@ public: /** Is in something protected (readonly) or selection contains something protected. */ bool HasReadonlySel(bool bFormView, bool isReplace) const; + /** Is there hidden sections in the selected area. */ + bool HasHiddenSections() const; bool ContainsPosition(const SwPosition & rPos) const { diff --git a/sw/inc/swcrsr.hxx b/sw/inc/swcrsr.hxx index d3d23155ff5e..ffdc77342367 100644 --- a/sw/inc/swcrsr.hxx +++ b/sw/inc/swcrsr.hxx @@ -281,6 +281,8 @@ public: SwCursor* MakeBoxSels( SwCursor* pCurrentCursor ); // Any boxes protected? bool HasReadOnlyBoxSel() const; + // Any boxes hidden? + bool HasHiddenBoxSel() const; // Has table cursor been changed? If so, save new values immediately. bool IsCursorMovedUpdate(); diff --git a/sw/qa/uitest/writer_tests7/tdf130199.py b/sw/qa/uitest/writer_tests7/tdf130199.py new file mode 100644 index 000000000000..8f9dde57b5af --- /dev/null +++ b/sw/qa/uitest/writer_tests7/tdf130199.py @@ -0,0 +1,62 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/. +# +from uitest.framework import UITestCase +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict + +class tdf130199(UITestCase): + + def test_tdf130199(self): + + with self.ui_test.create_doc_in_start_center("writer") as document: + + # Insert an empty para + self.xUITest.executeCommand(".uno:InsertPara") + + # Insert an empty section + with self.ui_test.execute_dialog_through_command(".uno:InsertSection"): + pass + + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + + # Insert an extra empty para in the section + xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "UP"})) + self.xUITest.executeCommand(".uno:InsertPara") + + self.assertEqual(1, len(document.TextSections)) + self.assertTrue(document.TextSections.Section1.IsVisible) + + with self.ui_test.execute_dialog_through_command(".uno:EditRegion") as xDialog: + xHide = xDialog.getChild('hide') + self.assertEqual('false', get_state_as_dict(xHide)['Selected']) + + xHide.executeAction('CLICK', tuple()) + + self.assertFalse(document.TextSections.Section1.IsVisible) + + # Select everything and do not delete the section + self.xUITest.executeCommand(".uno:SelectAll") + + with self.ui_test.execute_dialog_through_command(".uno:Delete", close_button="no") as xDialog: + pass + + self.assertEqual(1, len(document.TextSections)) + self.assertFalse(document.TextSections.Section1.IsVisible) + + # Select everything and delete the section + self.xUITest.executeCommand(".uno:SelectAll") + + with self.ui_test.execute_dialog_through_command(".uno:Delete", close_button="yes") as xDialog: + pass + + self.assertEqual(0, len(document.TextSections)) + + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/qa/unit/data/sw-dialogs-test.txt b/sw/qa/unit/data/sw-dialogs-test.txt index 54fa2761b575..0af2679d739e 100644 --- a/sw/qa/unit/data/sw-dialogs-test.txt +++ b/sw/qa/unit/data/sw-dialogs-test.txt @@ -199,6 +199,7 @@ modules/swriter/ui/tokenwidget.ui modules/swriter/ui/viewoptionspage.ui modules/swriter/ui/warndatasourcedialog.ui modules/swriter/ui/warnemaildialog.ui +modules/swriter/ui/warnhiddensectiondialog.ui modules/swriter/ui/wordcount.ui modules/swriter/ui/wrapdialog.ui modules/swriter/ui/wrappage.ui diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx index e84a854c2039..2258d39a8422 100644 --- a/sw/source/core/crsr/crsrsh.cxx +++ b/sw/source/core/crsr/crsrsh.cxx @@ -3346,6 +3346,7 @@ bool SwCursorShell::HasReadonlySel(bool const isReplace) const { if ( m_pTableCursor != nullptr ) { + // TODO: handling when a table cell (cells) is selected bRet = m_pTableCursor->HasReadOnlyBoxSel() || m_pTableCursor->HasReadonlySel(GetViewOptions()->IsFormView(), isReplace); } @@ -3364,6 +3365,31 @@ bool SwCursorShell::HasReadonlySel(bool const isReplace) const return bRet; } +bool SwCursorShell::HasHiddenSections() const +{ + bool bRet = false; + + if ( m_pTableCursor != nullptr ) + { + // TODO: handling when a table cell (cells) is selected + bRet = m_pTableCursor->HasHiddenBoxSel() + || m_pTableCursor->HasHiddenSections(); + } + else + { + for(const SwPaM& rCursor : m_pCurrentCursor->GetRingContainer()) + { + if (rCursor.HasHiddenSections()) + { + bRet = true; + break; + } + } + } + + return bRet; +} + bool SwCursorShell::IsSelFullPara() const { bool bRet = false; diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx index 6c9d4b899512..b971e5b5ee2b 100644 --- a/sw/source/core/crsr/pam.cxx +++ b/sw/source/core/crsr/pam.cxx @@ -790,6 +790,49 @@ bool SwPaM::HasReadonlySel(bool bFormView, bool const isReplace) const return bRet; } +bool SwPaM::HasHiddenSections() const +{ + bool bRet = false; + + if (HasMark() && GetPoint()->nNode != GetMark()->nNode) + { + sal_uLong nSttIdx = GetMark()->nNode.GetIndex(), + nEndIdx = GetPoint()->nNode.GetIndex(); + if (nEndIdx <= nSttIdx) + { + sal_uLong nTmp = nSttIdx; + nSttIdx = nEndIdx; + nEndIdx = nTmp; + } + + // If a hidden section should be between nodes, then the + // selection needs to contain already x nodes. + // (TextNd, SectNd, TextNd, EndNd, TextNd ) + if (nSttIdx + 3 < nEndIdx) + { + const SwSectionFormats& rFormats = GetDoc()->GetSections(); + for (SwSectionFormats::size_type n = rFormats.size(); n;) + { + const SwSectionFormat* pFormat = rFormats[--n]; + if (pFormat->GetSection()->IsHidden()) + { + const SwFormatContent& rContent = pFormat->GetContent(false); + OSL_ENSURE(rContent.GetContentIdx(), "where is the SectionNode?"); + sal_uLong nIdx = rContent.GetContentIdx()->GetIndex(); + if (nSttIdx <= nIdx && nEndIdx >= nIdx + && rContent.GetContentIdx()->GetNode().GetNodes().IsDocNodes()) + { + bRet = true; + break; + } + } + } + } + } + + return bRet; +} + /// This function returns the next node in direction of search. If there is no /// left or the next is out of the area, then a null-pointer is returned. /// @param rbFirst If <true> then first time request. If so than the position of diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx index 6ad5fda4db92..d0eb51c62000 100644 --- a/sw/source/core/crsr/swcrsr.cxx +++ b/sw/source/core/crsr/swcrsr.cxx @@ -2525,4 +2525,18 @@ bool SwTableCursor::HasReadOnlyBoxSel() const return bRet; } +bool SwTableCursor::HasHiddenBoxSel() const +{ + bool bRet = false; + for (size_t n = m_SelectedBoxes.size(); n; ) + { + if (m_SelectedBoxes[--n]->GetFrameFormat()->IsHidden()) + { + bRet = true; + break; + } + } + return bRet; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/edit/eddel.cxx b/sw/source/core/edit/eddel.cxx index 28d115abde89..aa56a85ae43f 100644 --- a/sw/source/core/edit/eddel.cxx +++ b/sw/source/core/edit/eddel.cxx @@ -34,6 +34,8 @@ #include <undobj.hxx> #include <SwRewriter.hxx> #include <globals.hrc> +#include <wrtsh.hxx> +#include <officecfg/Office/Writer.hxx> #include <strings.hrc> #include <vector> @@ -136,8 +138,17 @@ bool SwEditShell::Delete(bool const isArtificialSelection) bool bRet = false; if ( !HasReadonlySel() || CursorInsideInputField() ) { - StartAllAction(); + if (HasHiddenSections() && + officecfg::Office::Writer::Content::Display::ShowWarningHiddenSection::get()) + { + if (!WarnHiddenSectionDialog()) + { + bRet = RemoveParagraphMetadataFieldAtCursor(); + return bRet; + } + } + StartAllAction(); bool bUndo = GetCursor()->GetNext() != GetCursor(); if( bUndo ) // more than one selection? { @@ -163,6 +174,11 @@ bool SwEditShell::Delete(bool const isArtificialSelection) else { bRet = RemoveParagraphMetadataFieldAtCursor(); + if (!bRet) + { + // false indicates HasReadonlySel failed + InfoReadOnlyDialog(); + } } return bRet; diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx b/sw/source/uibase/docvw/SidebarTxtControl.cxx index bdbb0e2804e4..62387bc03330 100644 --- a/sw/source/uibase/docvw/SidebarTxtControl.cxx +++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx @@ -270,9 +270,7 @@ void SidebarTextControl::KeyInput( const KeyEvent& rKeyEvt ) } else { - std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui")); - std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("InfoReadonlyDialog")); - xQuery->run(); + mrDocView.GetWrtShell().InfoReadOnlyDialog(); } } if (bDone) diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx index 08bfd444b27b..28a672963e83 100644 --- a/sw/source/uibase/docvw/edtwin.cxx +++ b/sw/source/uibase/docvw/edtwin.cxx @@ -1841,9 +1841,7 @@ KEYINPUT_CHECKTABLE_INSDEL: } else if (!rSh.IsCursorInParagraphMetadataField()) { - std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui")); - std::unique_ptr<weld::MessageDialog> xInfo(xBuilder->weld_message_dialog("InfoReadonlyDialog")); - xInfo->run(); + rSh.InfoReadOnlyDialog(); eKeyState = SwKeyState::End; } break; @@ -1996,9 +1994,7 @@ KEYINPUT_CHECKTABLE_INSDEL: } else if (!rSh.IsCursorInParagraphMetadataField()) { - std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui")); - std::unique_ptr<weld::MessageDialog> xInfo(xBuilder->weld_message_dialog("InfoReadonlyDialog")); - xInfo->run(); + rSh.InfoReadOnlyDialog(); eKeyState = SwKeyState::End; } break; diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index 7a653bf55490..decf24bb4a08 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -490,6 +490,9 @@ typedef bool (SwWrtShell:: *FNSimpleMove)(); /// Inserts a new annotation/comment at the current cursor position / selection. void InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq); + virtual void InfoReadOnlyDialog() const override; + virtual bool WarnHiddenSectionDialog() const override; + private: SAL_DLLPRIVATE void OpenMark(); diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 6de83f66cd97..c65efe7c1c12 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -377,10 +377,7 @@ void SwTextShell::Execute(SfxRequest &rReq) if (rWrtSh.HasReadonlySel() && !rWrtSh.CursorInsideInputField()) { // Only break if there's something to do; don't nag with the dialog otherwise - auto xInfo(std::make_unique<weld::GenericDialogController>( - rWrtSh.GetView().GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui", - "InfoReadonlyDialog")); - xInfo->run(); + rWrtSh.InfoReadOnlyDialog(); break; } SwRewriter aRewriter; diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 0a8a46d344ac..ec0a88e64cf0 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -279,12 +279,7 @@ bool SwWrtShell::DelLeft() if( !bRet && bSwap ) SwCursorShell::SwapPam(); CloseMark( bRet ); - if (!bRet) - { // false indicates HasReadonlySel failed - std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetView().GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui")); - std::unique_ptr<weld::MessageDialog> xInfo(xBuilder->weld_message_dialog("InfoReadonlyDialog")); - xInfo->run(); - } + return bRet; } @@ -400,12 +395,6 @@ bool SwWrtShell::DelRight(bool const isReplaceHeuristic) SwCursorShell::Right(1, CRSR_SKIP_CELLS); bRet = Delete(true); CloseMark( bRet ); - if (!bRet) - { // false indicates HasReadonlySel failed - std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetView().GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui")); - std::unique_ptr<weld::MessageDialog> xInfo(xBuilder->weld_message_dialog("InfoReadonlyDialog")); - xInfo->run(); - } break; case SelectionType::Frame: diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index b37173efc254..d8d7d77e209c 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -48,6 +48,7 @@ #include <editeng/svxacorr.hxx> #include <editeng/ulspitem.hxx> #include <vcl/graph.hxx> +#include <vcl/svapp.hxx> #include <sfx2/printer.hxx> #include <unotools/charclass.hxx> #include <comphelper/storagehelper.hxx> @@ -1996,4 +1997,24 @@ void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq) } } +void SwWrtShell::InfoReadOnlyDialog() const +{ + std::unique_ptr<weld::Builder> + xBuilder(Application::CreateBuilder(GetView().GetFrameWeld(), + "modules/swriter/ui/inforeadonlydialog.ui")); + std::unique_ptr<weld::MessageDialog> + xInfo(xBuilder->weld_message_dialog("InfoReadonlyDialog")); + xInfo->run(); +} + +bool SwWrtShell::WarnHiddenSectionDialog() const +{ + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder( + GetView().GetFrameWeld(), "modules/swriter/ui/warnhiddensectiondialog.ui")); + std::unique_ptr<weld::MessageDialog> xQuery( + xBuilder->weld_message_dialog("WarnHiddenSectionDialog")); + + return (RET_YES == xQuery->run()); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/uiconfig/swriter/ui/warnhiddensectiondialog.ui b/sw/uiconfig/swriter/ui/warnhiddensectiondialog.ui new file mode 100644 index 000000000000..19aeec830203 --- /dev/null +++ b/sw/uiconfig/swriter/ui/warnhiddensectiondialog.ui @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.20.2 --> +<interface domain="sw"> + <requires lib="gtk+" version="3.20"/> + <object class="GtkMessageDialog" id="WarnHiddenSectionDialog"> + <property name="can_focus">False</property> + <property name="title" translatable="yes" context="warnhiddensectiondialog|WarnHiddenSectionDialog">Delete hidden section(s)?</property> + <property name="resizable">False</property> + <property name="modal">True</property> + <property name="type_hint">dialog</property> + <property name="skip_taskbar_hint">True</property> + <property name="message_type">question</property> + <property name="buttons">yes-no</property> + <property name="text" translatable="yes" context="warnhiddensectiondialog|WarnHiddenSectionDialog">Would you like to delete the hidden section(s)?</property> + <property name="secondary_text" translatable="yes" context="warnhiddensectiondialog|WarnHiddenSectionDialog">There are hidden sections in the deleted area.</property> + <child internal-child="vbox"> + <object class="GtkBox" id="messagedialog-vbox"> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <property name="spacing">12</property> + <child internal-child="action_area"> + <object class="GtkButtonBox" id="messagedialog-action_area"> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">end</property> + <property name="position">0</property> + </packing> + </child> + </object> + </child> + </object> +</interface>
