summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Raykowski <raykowj@gmail.com>2022-11-22 17:57:15 -0900
committerNoel Grandin <noel.grandin@collabora.co.uk>2022-11-24 08:09:42 +0100
commit8ba1c4e27376cbd73892768d1e741067918eb897 (patch)
tree76089bd4497aa862d6ed776040b0b59a3e9f6487
parentb1fad7043a7286d5d9bb33c9ed9235f044d92aed (diff)
tdf#152165 Improve the 'Read-only Content' dialog message
This patch implements user j.a.swami's suggested improvement of the messages shown in the 'Read-only Content' dialog when trying to delete a selection in the document that has folded content. In doing so, repeated code to create and run the dialog at each place it is used is replaced by a single function call. Change-Id: If79298e0ee920e60620934f1eacc98c776e5d33e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143132 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/vcl/weld.hxx2
-rw-r--r--sw/inc/strings.hrc3
-rw-r--r--sw/source/core/crsr/crsrsh.cxx26
-rw-r--r--sw/source/uibase/docvw/SidebarTxtControl.cxx6
-rw-r--r--sw/source/uibase/docvw/edtwin.cxx18
-rw-r--r--sw/source/uibase/inc/wrtsh.hxx3
-rw-r--r--sw/source/uibase/shells/textsh1.cxx5
-rw-r--r--sw/source/uibase/wrtsh/delete.cxx8
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx53
9 files changed, 74 insertions, 50 deletions
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 9bb5bfb6ed74..9047fe3aa753 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -2660,6 +2660,8 @@ public:
virtual ~MessageDialogController() override;
void set_primary_text(const OUString& rText) { m_xDialog->set_primary_text(rText); }
OUString get_primary_text() const { return m_xDialog->get_primary_text(); }
+ void set_secondary_text(const OUString& rText) { m_xDialog->set_secondary_text(rText); }
+ OUString get_secondary_text() const { return m_xDialog->get_secondary_text(); }
void set_default_response(int nResponse) { m_xDialog->set_default_response(nResponse); }
};
diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc
index 7cf98621de2e..afd0c2873fad 100644
--- a/sw/inc/strings.hrc
+++ b/sw/inc/strings.hrc
@@ -1452,6 +1452,9 @@
#define STR_MARK_COPY NC_("STR_MARK_COPY", "%1 Copy ")
+#define STR_INFORODLG_FOLDED_PRIMARY NC_("STR_INFORODLG_FOLDED_PRIMARY", "You are trying to delete folded (hidden) content.")
+#define STR_INFORODLG_FOLDED_SECONDARY NC_("STR_INFORODLG_FOLDED_SECONDARY", "To delete this content, first unfold it so you can see what you intend to delete.")
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 97df404d39ec..725c7ede3402 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -3358,31 +3358,13 @@ void SwCursorShell::SetReadOnlyAvailable( bool bFlag )
bool SwCursorShell::HasReadonlySel(bool const isReplace) const
{
+ // Treat selections that span over start or end of paragraph of an outline node
+ // with folded outline content as read-only.
if (GetViewOptions()->IsShowOutlineContentVisibilityButton())
{
- // Treat selections that span over start or end of paragraph of an outline node
- // with folded outline content as read-only.
SwWrtShell* pWrtSh = GetDoc()->GetDocShell()->GetWrtShell();
- if (pWrtSh)
- {
- for(const SwPaM& rPaM : GetCursor()->GetRingContainer())
- {
- SwPaM aPaM(*rPaM.GetMark(), *rPaM.GetPoint());
- aPaM.Normalize();
- SwNodeIndex aPointIdx(aPaM.GetPoint()->GetNode());
- SwNodeIndex aMarkIdx(aPaM.GetMark()->GetNode());
- if (aPointIdx == aMarkIdx)
- continue;
- // If any nodes in PaM are folded outline content nodes, then set read-only.
- SwOutlineNodes::size_type nPos;
- for (SwNodeIndex aIdx = aPointIdx; aIdx <= aMarkIdx; aIdx++)
- {
- if (GetDoc()->GetNodes().GetOutLineNds().Seek_Entry(&(aIdx.GetNode()), &nPos) &&
- !pWrtSh->GetAttrOutlineContentVisible(nPos))
- return true;
- }
- }
- }
+ if (pWrtSh && pWrtSh->HasFoldedOutlineContentSelected())
+ return true;
}
bool bRet = false;
// If protected area is to be ignored, then selections are never read-only.
diff --git a/sw/source/uibase/docvw/SidebarTxtControl.cxx b/sw/source/uibase/docvw/SidebarTxtControl.cxx
index 7b7002b7fbfe..bdf343bc80d1 100644
--- a/sw/source/uibase/docvw/SidebarTxtControl.cxx
+++ b/sw/source/uibase/docvw/SidebarTxtControl.cxx
@@ -332,11 +332,7 @@ bool SidebarTextControl::KeyInput( const KeyEvent& rKeyEvt )
bDone = pEditView && pEditView->PostKeyEvent(rKeyEvt);
}
else
- {
- std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetDrawingArea(), "modules/swriter/ui/inforeadonlydialog.ui"));
- std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("InfoReadonlyDialog"));
- xQuery->run();
- }
+ mrDocView.GetWrtShell().InfoReadOnlyDialog();
}
if (bDone)
mrSidebarWin.ResizeIfNecessary( aOldHeight, mrSidebarWin.GetPostItTextHeight() );
diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index 46c643a6a43e..75b489ec59ea 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -1928,9 +1928,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;
@@ -2084,9 +2082,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;
@@ -2367,8 +2363,7 @@ KEYINPUT_CHECKTABLE_INSDEL:
&& ( rKeyCode.GetFunction() == KeyFuncType::PASTE
|| rKeyCode.GetFunction() == KeyFuncType::CUT))
{
- auto xInfo(std::make_shared<weld::GenericDialogController>(GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui", "InfoReadonlyDialog"));
- weld::DialogController::runAsync(xInfo, [](int) {});
+ rSh.InfoReadOnlyDialog(true);
eKeyState = SwKeyState::End;
}
else if( m_rView.KeyInput( aKeyEvent ) )
@@ -2576,8 +2571,7 @@ KEYINPUT_CHECKTABLE_INSDEL:
}
else
{
- auto xInfo(std::make_shared<weld::GenericDialogController>(GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui", "InfoReadonlyDialog"));
- weld::DialogController::runAsync(xInfo, [](int) {});
+ rSh.InfoReadOnlyDialog(true);
eKeyState = SwKeyState::End;
}
break;
@@ -5755,9 +5749,7 @@ void SwEditWin::Command( const CommandEvent& rCEvt )
if (rSh.HasReadonlySel())
{
// Inform the user that the request has been ignored.
- auto xInfo = std::make_shared<weld::GenericDialogController>(
- GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui", "InfoReadonlyDialog");
- weld::DialogController::runAsync(xInfo, [](sal_Int32 /*nResult*/) {});
+ rSh.InfoReadOnlyDialog(true);
}
}
break;
diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx
index 61f4570a71ab..fb80f135237e 100644
--- a/sw/source/uibase/inc/wrtsh.hxx
+++ b/sw/source/uibase/inc/wrtsh.hxx
@@ -508,6 +508,9 @@ typedef bool (SwWrtShell::*FNSimpleMove)();
void MakeOutlineLevelsVisible(const int nLevel);
+ bool HasFoldedOutlineContentSelected();
+ void InfoReadOnlyDialog(bool bAsync = false);
+
std::optional<OString> getLOKPayload(int nType, int nViewId) const;
private:
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index 41a159c2a91b..d17715a826aa 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -404,10 +404,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 2a6038d6d9a6..e66797a7086d 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -283,9 +283,7 @@ bool SwWrtShell::DelLeft()
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();
+ InfoReadOnlyDialog();
}
return bRet;
}
@@ -404,9 +402,7 @@ bool SwWrtShell::DelRight(bool const isReplaceHeuristic)
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();
+ InfoReadOnlyDialog();
}
break;
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 8cfc57a7cea1..095c6d5a9d95 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -2631,4 +2631,57 @@ bool SwWrtShell::GetAttrOutlineContentVisible(const size_t nPos)
return bVisibleAttr;
}
+bool SwWrtShell::HasFoldedOutlineContentSelected()
+{
+ for(const SwPaM& rPaM : GetCursor()->GetRingContainer())
+ {
+ SwPaM aPaM(*rPaM.GetMark(), *rPaM.GetPoint());
+ aPaM.Normalize();
+ SwNodeIndex aPointIdx(aPaM.GetPoint()->GetNode());
+ SwNodeIndex aMarkIdx(aPaM.GetMark()->GetNode());
+ if (aPointIdx == aMarkIdx)
+ continue;
+ // Return true if any nodes in PaM are folded outline content nodes.
+ SwOutlineNodes::size_type nPos;
+ for (SwNodeIndex aIdx = aPointIdx; aIdx <= aMarkIdx; aIdx++)
+ {
+ if (GetDoc()->GetNodes().GetOutLineNds().Seek_Entry(&(aIdx.GetNode()), &nPos) &&
+ !GetAttrOutlineContentVisible(nPos))
+ return true;
+ }
+ }
+ return false;
+}
+
+void SwWrtShell::InfoReadOnlyDialog(bool bAsync)
+{
+ if (bAsync)
+ {
+ auto xInfo = std::make_shared<weld::MessageDialogController>(
+ GetView().GetFrameWeld(), "modules/swriter/ui/inforeadonlydialog.ui", "InfoReadonlyDialog");
+ if (GetViewOptions()->IsShowOutlineContentVisibilityButton() &&
+ HasFoldedOutlineContentSelected())
+ {
+ xInfo->set_primary_text(SwResId(STR_INFORODLG_FOLDED_PRIMARY));
+ xInfo->set_secondary_text(SwResId(STR_INFORODLG_FOLDED_SECONDARY));
+ }
+ weld::DialogController::runAsync(xInfo, [](int) {});
+ }
+ else
+ {
+ 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"));
+ if (GetViewOptions()->IsShowOutlineContentVisibilityButton() &&
+ HasFoldedOutlineContentSelected())
+ {
+ xInfo->set_primary_text(SwResId(STR_INFORODLG_FOLDED_PRIMARY));
+ xInfo->set_secondary_text(SwResId(STR_INFORODLG_FOLDED_SECONDARY));
+ }
+ xInfo->run();
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */