tdf#127533 Make Tip-of-the-Day dialog non-modal and allow multiple tips to open
The Tip-of-the-Day dialog is made non-modal and stays on-top of the main window
while allowing the user to interact with the rest of application.
Change-Id: I51e1a3488ab74d8371b71a8585d1512ce051f637
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113782
Reviewed-by: Matt K <mattkse@gmail.com>
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Tested-by: Jenkins
diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx
index 9d43fd2..8356f6f 100644
--- a/cui/source/dialogs/tipofthedaydlg.cxx
+++ b/cui/source/dialogs/tipofthedaydlg.cxx
@@ -25,6 +25,7 @@
#include <vcl/commandinfoprovider.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/help.hxx>
#include <vcl/window.hxx>
#include <com/sun/star/frame/XDesktop2.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
@@ -38,6 +39,7 @@
#include <officecfg/Office/Common.hxx>
#include <osl/file.hxx>
#include <rtl/bootstrap.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <unotools/resmgr.hxx>
#include <unotools/configmgr.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
@@ -47,6 +49,7 @@ const Size ThumbSize(150, 150);
TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent)
: GenericDialogController(pParent, "cui/ui/tipofthedaydialog.ui", "TipOfTheDayDialog")
, m_pParent(pParent)
, m_pText(m_xBuilder->weld_label("lbText"))
, m_pShowTip(m_xBuilder->weld_check_button("cbShowTip"))
, m_pNext(m_xBuilder->weld_button("btnNext"))
@@ -58,6 +61,17 @@ TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent)
m_nCurrentTip = officecfg::Office::Common::Misc::LastTipOfTheDayID::get();
m_pPreview->set_size_request(ThumbSize.Width(), ThumbSize.Height());
if (pParent != nullptr)
{
css::uno::Reference<css::awt::XWindow> xWindow = pParent->GetXWindow();
if (xWindow.is())
{
VclPtr<vcl::Window> xVclWin(VCLUnoHelper::GetWindow(xWindow));
if (xVclWin != nullptr)
xVclWin->AddEventListener(LINK(this, TipOfTheDayDialog, Terminated));
}
}
const auto t0 = std::chrono::system_clock::now().time_since_epoch();
m_nDay = std::chrono::duration_cast<std::chrono::hours>(t0).count() / 24;
if (m_nDay > officecfg::Office::Common::Misc::LastTipOfTheDayShown::get())
@@ -66,6 +80,12 @@ TipOfTheDayDialog::TipOfTheDayDialog(weld::Window* pParent)
UpdateTip();
}
IMPL_LINK(TipOfTheDayDialog, Terminated, VclWindowEvent&, rEvent, void)
{
if (rEvent.GetId() == VclEventId::ObjectDying)
TipOfTheDayDialog::response(RET_OK);
}
TipOfTheDayDialog::~TipOfTheDayDialog()
{
std::shared_ptr<comphelper::ConfigurationChanges> xChanges(
@@ -74,6 +94,17 @@ TipOfTheDayDialog::~TipOfTheDayDialog()
officecfg::Office::Common::Misc::LastTipOfTheDayID::set(m_nCurrentTip, xChanges);
officecfg::Office::Common::Misc::ShowTipOfTheDay::set(m_pShowTip->get_active(), xChanges);
xChanges->commit();
if (m_pParent != nullptr)
{
css::uno::Reference<css::awt::XWindow> xWindow = m_pParent->GetXWindow();
if (xWindow.is())
{
VclPtr<vcl::Window> xVclWin(VCLUnoHelper::GetWindow(xWindow));
if (xVclWin != nullptr)
xVclWin->RemoveEventListener(LINK(this, TipOfTheDayDialog, Terminated));
}
}
}
static bool file_exists(const OUString& fileName)
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index 6d0a440..6d0e9e3 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -106,6 +106,16 @@ short CuiAbstractController_Impl::Execute()
return m_xDlg->run();
}
short CuiAbstractTipController_Impl::Execute()
{
return m_xDlg->run();
}
bool CuiAbstractTipController_Impl::StartExecuteAsync(AsyncContext& rCtx)
{
return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
}
short CuiAbstractSingleTabController_Impl::Execute()
{
return m_xDlg->run();
@@ -1682,8 +1692,8 @@ AbstractDialogFactory_Impl::CreateAboutDialog(weld::Window* pParent)
VclPtr<VclAbstractDialog>
AbstractDialogFactory_Impl::CreateTipOfTheDayDialog(weld::Window* pParent)
{
return VclPtr<CuiAbstractController_Impl>::Create(
std::make_unique<TipOfTheDayDialog>(pParent));
return VclPtr<CuiAbstractTipController_Impl>::Create(
std::make_shared<TipOfTheDayDialog>(pParent));
}
VclPtr<VclAbstractDialog>
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index 1abf426..1678d3c 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -121,6 +121,19 @@ public:
virtual short Execute() override;
};
class CuiAbstractTipController_Impl : public VclAbstractDialog
{
std::shared_ptr<weld::DialogController> m_xDlg;
public:
explicit CuiAbstractTipController_Impl(std::shared_ptr<weld::DialogController> p)
: m_xDlg(std::move(p))
{
}
virtual short Execute() override;
virtual bool StartExecuteAsync(AsyncContext& rCtx) override;
};
class CuiAbstractSingleTabController_Impl : public SfxAbstractDialog
{
std::unique_ptr<SfxSingleTabDialogController> m_xDlg;
diff --git a/cui/source/inc/tipofthedaydlg.hxx b/cui/source/inc/tipofthedaydlg.hxx
index 44ea013..f5f0ef9 100644
--- a/cui/source/inc/tipofthedaydlg.hxx
+++ b/cui/source/inc/tipofthedaydlg.hxx
@@ -21,10 +21,13 @@
#include <vcl/weld.hxx>
#include "cuigrfflt.hxx"
class VclWindowEvent;
class TipOfTheDayDialog : public weld::GenericDialogController
{
private:
CuiGraphicPreviewWindow m_aPreview;
weld::Window* m_pParent;
std::unique_ptr<weld::Label> m_pText;
std::unique_ptr<weld::CheckButton> m_pShowTip;
@@ -41,6 +44,8 @@ private:
public:
TipOfTheDayDialog(weld::Window* pWindow);
virtual ~TipOfTheDayDialog() override;
DECL_LINK(Terminated, VclWindowEvent&, void);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/uiconfig/ui/tipofthedaydialog.ui b/cui/uiconfig/ui/tipofthedaydialog.ui
index e05738d..ebf0515 100644
--- a/cui/uiconfig/ui/tipofthedaydialog.ui
+++ b/cui/uiconfig/ui/tipofthedaydialog.ui
@@ -7,7 +7,7 @@
<property name="border-width">6</property>
<property name="title" translatable="yes" context="TipOfTheDayDialog|Name">Tip of the day</property>
<property name="resizable">False</property>
<property name="modal">True</property>
<property name="modal">False</property>
<property name="window-position">center-on-parent</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
@@ -26,7 +26,7 @@
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="tooltip-text" translatable="yes" context="TipOfTheDay|Checkbox_Tooltip">Enable the dialog again at Tools > Options > General</property>
<property name="tooltip-text" translatable="yes" context="TipOfTheDay|Checkbox_Tooltip">Enable the dialog again at Tools > Options > General, or Help > Show Tip of the Day</property>
<property name="use-underline">True</property>
<property name="active">True</property>
<property name="draw-indicator">True</property>
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index 91edc7d..6138bd9 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -610,7 +610,7 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
{
SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateTipOfTheDayDialog(rReq.GetFrameWeld()));
pDlg->Execute();
pDlg->StartExecuteAsync(nullptr);
bDone = true;
break;
}