diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2019-11-19 09:18:11 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-12-13 13:07:21 +0100 |
commit | c434fc0d181f098a179c6dc9d1506fa806d579f1 (patch) | |
tree | 3b53ada3fffc9c91c4d28deb4062b1bedc238a99 | |
parent | 72e0d12c39faceda2e84d3321e0a11880d3b8593 (diff) |
tdf#128191 Show infobar when hyphenation info for text language is missing
During doc loading it's too early to add infobars,
thus add a mechanism to display infobars once view is ready
Change-Id: Ie963a304d2101a5bbdd59130c354d581ff7d2e9b
Reviewed-on: https://gerrit.libreoffice.org/84634
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/sfx2/infobar.hxx | 10 | ||||
-rw-r--r-- | include/sfx2/objsh.hxx | 9 | ||||
-rw-r--r-- | sfx2/source/doc/objmisc.cxx | 19 | ||||
-rw-r--r-- | sfx2/source/doc/objxtor.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/inc/objshimp.hxx | 3 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 14 | ||||
-rw-r--r-- | sw/inc/strings.hrc | 2 | ||||
-rw-r--r-- | sw/source/core/text/inftxt.cxx | 15 |
8 files changed, 70 insertions, 3 deletions
diff --git a/include/sfx2/infobar.hxx b/include/sfx2/infobar.hxx index a0dcdbd00f1d..80f4c0a0506c 100644 --- a/include/sfx2/infobar.hxx +++ b/include/sfx2/infobar.hxx @@ -26,6 +26,16 @@ enum class InfobarType { DANGER = 3 }; +class InfobarData +{ + public: + OUString msId; + OUString msPrimaryMessage; + OUString msSecondaryMessage; + InfobarType maInfobarType; + bool mbShowCloseButton; +}; + /** SfxChildWindow for positioning the InfoBar in the view. */ class SFX2_DLLPUBLIC SfxInfoBarContainerChild final : public SfxChildWindow diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index d9d184383430..0352f2f1ac2a 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -62,9 +62,11 @@ class OutputDevice; class Color; class Fraction; class SvGlobalName; +class InfobarData; enum class SfxModelFlags; enum class SfxEventHintId; +enum class InfobarType; // These values presumably must match exactly the corresponding // css::embed::Aspects ones (in offapi/com/sun/star/embed/Aspects.idl) @@ -651,6 +653,13 @@ public: static bool IsOwnStorageFormat(const SfxMedium &); + /** Append Infobar once the frame is ready. + Useful when you want to register an Infobar before the doc/frame is fully loaded. */ + void AppendInfoBarWhenReady(const OUString& sId, const OUString& sPrimaryMessage, + const OUString& sSecondaryMessage, InfobarType aInfobarType, + bool bShowCloseButton = true); + std::vector<InfobarData>& getPendingInfobars(); + SAL_DLLPRIVATE std::shared_ptr<GDIMetaFile> CreatePreviewMetaFile_Impl(bool bFullContent) const; SAL_DLLPRIVATE static bool IsPackageStorageFormat_Impl(const SfxMedium &); diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 5af5ddfdf2f0..3254eb18d7b0 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -112,6 +112,7 @@ #include <sfx2/strings.hrc> #include <workwin.hxx> #include <sfx2/sfxdlg.hxx> +#include <sfx2/infobar.hxx> #include <appbaslib.hxx> #include <openflag.hxx> #include "objstor.hxx" @@ -202,6 +203,24 @@ void SfxObjectShell::FlushDocInfo() (delay > 0) || !url.isEmpty() ); } +void SfxObjectShell::AppendInfoBarWhenReady(const OUString& sId, const OUString& sPrimaryMessage, + const OUString& sSecondaryMessage, + InfobarType aInfobarType, bool bShowCloseButton) +{ + InfobarData aInfobarData; + aInfobarData.msId = sId; + aInfobarData.msPrimaryMessage = sPrimaryMessage; + aInfobarData.msSecondaryMessage = sSecondaryMessage; + aInfobarData.maInfobarType = aInfobarType; + aInfobarData.mbShowCloseButton = bShowCloseButton; + Get_Impl()->m_aPendingInfobars.emplace_back(aInfobarData); +} + +std::vector<InfobarData>& SfxObjectShell::getPendingInfobars() +{ + return Get_Impl()->m_aPendingInfobars; +} + void SfxObjectShell::SetError(ErrCode lErr) { if (pImpl->lErr==ERRCODE_NONE) diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 1f1ead6642ed..510c35daf59f 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -99,6 +99,7 @@ #include <sfx2/sfxuno.hxx> #include <shellimpl.hxx> #include <sfx2/notebookbar/SfxNotebookBar.hxx> +#include <sfx2/infobar.hxx> #include <basic/basicmanagerrepository.hxx> diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index d52ee83d9a3c..3d7b0b69c945 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -131,6 +131,9 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess bool m_bSavingForSigning; bool m_bAllowModifiedBackAfterSigning; + /// Holds Infobars until View is fully loaded + std::vector<InfobarData> m_aPendingInfobars; + SfxObjectShell_Impl( SfxObjectShell& _rDocShell ); virtual ~SfxObjectShell_Impl(); diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 3264a1c9497a..6029bdc341e3 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1432,6 +1432,17 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) aHelper.UpdateInfobar(*this); } + // Add pending infobars + std::vector<InfobarData>& aPendingInfobars = m_xObjSh->getPendingInfobars(); + while (!aPendingInfobars.empty()) + { + InfobarData& aInfobarData = aPendingInfobars.back(); + AppendInfoBar(aInfobarData.msId, aInfobarData.msPrimaryMessage, + aInfobarData.msSecondaryMessage, aInfobarData.maInfobarType, + aInfobarData.mbShowCloseButton); + aPendingInfobars.pop_back(); + } + break; } default: break; @@ -3292,6 +3303,9 @@ VclPtr<SfxInfoBarWindow> SfxViewFrame::AppendInfoBar(const OUString& sId, if (!pChild) return nullptr; + if (HasInfoBarWithID(sId)) + return nullptr; + SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow()); auto pInfoBar = pInfoBarContainer->appendInfoBar(sId, sPrimaryMessage, sSecondaryMessage, aInfobarType, WB_LEFT | WB_VCENTER, bShowCloseButton); diff --git a/sw/inc/strings.hrc b/sw/inc/strings.hrc index 1ef224407aa5..cc421939d2e2 100644 --- a/sw/inc/strings.hrc +++ b/sw/inc/strings.hrc @@ -385,6 +385,8 @@ #define RID_STR_SYSTEM NC_("RID_STR_SYSTEM", "[System]") #define STR_MULT_INTERACT_HYPH_WARN NC_("STR_MULT_INTERACT_HYPH_WARN", "The interactive hyphenation is already active\nin a different document") #define STR_HYPH_TITLE NC_("STR_HYPH_TITLE", "Hyphenation") +#define STR_HYPH_MISSING NC_("STR_HYPH_MISSING", "Missing hyphenation info") +#define STR_HYPH_MISSING_DETAIL NC_("STR_HYPH_MISSING", "Please install the hyphenation package for locale “%1”.") // Undo #define STR_CANT_UNDO NC_("STR_CANT_UNDO", "not possible") diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx index 133266675553..357360b69ec0 100644 --- a/sw/source/core/text/inftxt.cxx +++ b/sw/source/core/text/inftxt.cxx @@ -23,6 +23,7 @@ #include <unotools/lingucfg.hxx> #include <hintids.hxx> #include <svl/ctloptions.hxx> +#include <sfx2/infobar.hxx> #include <sfx2/printer.hxx> #include <sal/log.hxx> #include <editeng/hyphenzoneitem.hxx> @@ -70,6 +71,8 @@ #include <docufld.hxx> #include <frmfmt.hxx> #include <unomid.h> +#include <docsh.hxx> +#include <strings.hrc> using namespace ::com::sun::star; using namespace ::com::sun::star::linguistic2; @@ -1459,9 +1462,15 @@ bool SwTextFormatInfo::IsHyphenate() const if (!xHyph->hasLocale(g_pBreakIt->GetLocale(eTmp))) { - // TODO: Add an infobar for this case, tdf#128191 - SAL_WARN("sw", "missing hyphenation package for locale: " - << g_pBreakIt->GetLocale(eTmp).Language); + SfxObjectShell* pShell = m_pFrame->GetDoc().GetDocShell(); + if (pShell) + { + pShell->AppendInfoBarWhenReady( + "hyphenationmissing", SwResId(STR_HYPH_MISSING), + SwResId(STR_HYPH_MISSING_DETAIL) + .replaceFirst("%1", g_pBreakIt->GetLocale(eTmp).Language), + InfobarType::WARNING); + } } return xHyph->hasLocale( g_pBreakIt->GetLocale(eTmp) ); |