diff options
author | Heiko Tietze <tietze.heiko@gmail.com> | 2020-08-02 17:10:00 +0200 |
---|---|---|
committer | Heiko Tietze <heiko.tietze@documentfoundation.org> | 2020-10-07 18:02:06 +0200 |
commit | ed8df0ec6ed1af600a4d31223d5bfc3f65c5d7ba (patch) | |
tree | 8ea2a707ad62fd23a32b5f25c2b955964fb4d29c /cui/source | |
parent | 0c9ccc7dbf6deb4d012e0d1e6eb934e54e0f19bc (diff) |
Resolves tdf#117463 - Dialog to show UI options
* New dialog to pick and apply one of the UI variants
* Tip-of-the-Day enhanced to execute UNO commands in order
to advertise the UI chooser on first start
Change-Id: I5e5c4a8e0fb11d11bafc99cc37b7ec244a993781
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99957
Tested-by: Jenkins
Reviewed-by: Heiko Tietze <heiko.tietze@documentfoundation.org>
Diffstat (limited to 'cui/source')
-rw-r--r-- | cui/source/dialogs/tipofthedaydlg.cxx | 31 | ||||
-rw-r--r-- | cui/source/dialogs/toolbarmodedlg.cxx | 214 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.cxx | 8 | ||||
-rw-r--r-- | cui/source/factory/dlgfact.hxx | 2 | ||||
-rw-r--r-- | cui/source/inc/toolbarmodedlg.hxx | 33 |
5 files changed, 282 insertions, 6 deletions
diff --git a/cui/source/dialogs/tipofthedaydlg.cxx b/cui/source/dialogs/tipofthedaydlg.cxx index 4775ed0578b9..c64362d35c08 100644 --- a/cui/source/dialogs/tipofthedaydlg.cxx +++ b/cui/source/dialogs/tipofthedaydlg.cxx @@ -17,18 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> #include <tipofthedaydlg.hxx> - -#include <dialmgr.hxx> -#include <officecfg/Office/Common.hxx> -#include <osl/file.hxx> -#include <rtl/bootstrap.hxx> #include <tipoftheday.hrc> + #include <vcl/graphicfilter.hxx> #include <vcl/help.hxx> #include <vcl/virdev.hxx> #include <vcl/svapp.hxx> + +#include <comphelper/dispatchcommand.hxx> +#include <comphelper/propertysequence.hxx> +#include <dialmgr.hxx> #include <i18nlangtag/languagetag.hxx> +#include <officecfg/Office/Common.hxx> +#include <osl/file.hxx> +#include <rtl/bootstrap.hxx> #include <unotools/resmgr.hxx> #include <unotools/configmgr.hxx> @@ -108,6 +112,13 @@ void TipOfTheDayDialog::UpdateTip() { m_pLink->set_visible(false); } + else if (aLink.startsWith(".uno:")) + { + m_pLink->set_uri(CuiResId(STR_UNO_EXECUTE).replaceFirst("%COMMAND", aLink)); + m_pLink->set_label(CuiResId(STR_UNO_LINK)); + m_pLink->set_visible(true); + m_pLink->connect_activate_link(LINK(this, TipOfTheDayDialog, OnLinkClick)); + } else if (aLink.startsWith("http")) { // Links may have some %PRODUCTVERSION which need to be expanded @@ -155,7 +166,15 @@ void TipOfTheDayDialog::UpdateTip() IMPL_LINK_NOARG(TipOfTheDayDialog, OnLinkClick, weld::LinkButton&, bool) { - Application::GetHelp()->Start(aLink, static_cast<weld::Widget*>(nullptr)); + if (aLink.startsWith("http")) + { + Application::GetHelp()->Start(aLink, static_cast<weld::Widget*>(nullptr)); + } + else if (aLink.startsWith(".uno:")) + { + comphelper::dispatchCommand(aLink, {}); + TipOfTheDayDialog::response(RET_OK); + } return true; } diff --git a/cui/source/dialogs/toolbarmodedlg.cxx b/cui/source/dialogs/toolbarmodedlg.cxx new file mode 100644 index 000000000000..21bd7055bd96 --- /dev/null +++ b/cui/source/dialogs/toolbarmodedlg.cxx @@ -0,0 +1,214 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include <sal/config.h> + +#include <toolbarmodedlg.hxx> +#include <toolbarmode.hrc> + +#include <com/sun/star/frame/ModuleManager.hpp> +#include <comphelper/dispatchcommand.hxx> +#include <comphelper/propertysequence.hxx> +#include <comphelper/types.hxx> +#include <dialmgr.hxx> +#include <officecfg/Office/UI/ToolbarMode.hxx> +#include <osl/file.hxx> +#include <rtl/bootstrap.hxx> +#include <sfx2/viewfrm.hxx> +#include <strings.hrc> +#include <svtools/miscopt.hxx> +#include <unotools/confignode.hxx> +#include <vcl/virdev.hxx> +#include <vcl/graphicfilter.hxx> +#include <vcl/EnumContext.hxx> +#include <vcl/weld.hxx> + +static OUString GetCurrentApp() +{ + OUString sResult; + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + { + const auto xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface(); + const auto xContext = comphelper::getProcessComponentContext(); + const auto xModuleManager = css::frame::ModuleManager::create(xContext); + switch (vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(xCurrentFrame))) + { + case vcl::EnumContext::Application::Writer: + sResult = "Writer"; + break; + case vcl::EnumContext::Application::Calc: + sResult = "Calc"; + break; + case vcl::EnumContext::Application::Impress: + sResult = "Impress"; + break; + case vcl::EnumContext::Application::Draw: + sResult = "Draw"; + break; + case vcl::EnumContext::Application::Formula: + sResult = "Formula"; + break; + case vcl::EnumContext::Application::Base: + sResult = "Base"; + break; + default: + sResult = "Unsupported"; + } + } + return sResult; +} + +static OUString GetCurrentMode() +{ + OUString sResult; + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + { + const auto xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface(); + const auto xContext = comphelper::getProcessComponentContext(); + const auto xModuleManager = css::frame::ModuleManager::create(xContext); + const utl::OConfigurationTreeRoot aAppNode( + xContext, "org.openoffice.Office.UI.ToolbarMode/Applications/" + GetCurrentApp(), true); + if (aAppNode.isValid()) + sResult = comphelper::getString(aAppNode.getNodeValue("Active")); + }; + return sResult; +} + +ToolbarmodeDialog::ToolbarmodeDialog(weld::Window* pParent) + : GenericDialogController(pParent, "cui/ui/toolbarmodedialog.ui", "ToolbarmodeDialog") + , m_pImage(m_xBuilder->weld_image("imImage")) + , m_pApply(m_xBuilder->weld_button("btnApply")) + , m_pApplyAll(m_xBuilder->weld_button("btnApplyAll")) + , m_pRadioButtons{ (m_xBuilder->weld_radio_button("rbButton1")), + (m_xBuilder->weld_radio_button("rbButton2")), + (m_xBuilder->weld_radio_button("rbButton3")), + (m_xBuilder->weld_radio_button("rbButton4")), + (m_xBuilder->weld_radio_button("rbButton5")), + (m_xBuilder->weld_radio_button("rbButton6")), + (m_xBuilder->weld_radio_button("rbButton7")), + (m_xBuilder->weld_radio_button("rbButton8")), + (m_xBuilder->weld_radio_button("rbButton9")) } + , m_pInfoLabel(m_xBuilder->weld_label("lbInfo")) +{ + static_assert(SAL_N_ELEMENTS(m_pRadioButtons) == SAL_N_ELEMENTS(TOOLBARMODES_ARRAY)); + + Link<weld::ToggleButton&, void> aLink = LINK(this, ToolbarmodeDialog, SelectToolbarmode); + + const OUString sCurrentMode = GetCurrentMode(); + for (unsigned long i = 0; i < SAL_N_ELEMENTS(m_pRadioButtons); i++) + { + m_pRadioButtons[i]->connect_toggled(aLink); + if (sCurrentMode == std::get<1>(TOOLBARMODES_ARRAY[i])) + { + m_pRadioButtons[i]->set_active(true); + UpdateImage(std::get<2>(TOOLBARMODES_ARRAY[i])); + m_pInfoLabel->set_label(CuiResId(std::get<0>(TOOLBARMODES_ARRAY[i]))); + } + } + + m_pApply->set_label(CuiResId(RID_SVXSTR_UI_APPLYALL).replaceFirst("%MODULE", GetCurrentApp())); + m_pApply->connect_clicked(LINK(this, ToolbarmodeDialog, OnApplyClick)); + m_pApplyAll->connect_clicked(LINK(this, ToolbarmodeDialog, OnApplyClick)); + + if (!SvtMiscOptions().IsExperimentalMode()) + { + m_pRadioButtons[nContextSingle]->set_visible(false); + m_pRadioButtons[nContextGroup]->set_visible(false); + } +} + +ToolbarmodeDialog::~ToolbarmodeDialog() = default; + +static bool file_exists(const OUString& fileName) +{ + osl::File aFile(fileName); + return aFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None; +} + +int ToolbarmodeDialog::GetActiveRadioButton() +{ + for (unsigned long i = 0; i < SAL_N_ELEMENTS(m_pRadioButtons); i++) + { + if (m_pRadioButtons[i]->get_active()) + return i; + } + return -1; +} + +void ToolbarmodeDialog::UpdateImage(OUString sFileName) +{ + // load image + OUString aURL("$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/toolbarmode/"); + rtl::Bootstrap::expandMacros(aURL); + aURL += sFileName; + if (sFileName.isEmpty() || !file_exists(aURL)) + return; + // draw image + Graphic aGraphic; + if (GraphicFilter::LoadGraphic(aURL, OUString(), aGraphic) == ERRCODE_NONE) + { + ScopedVclPtr<VirtualDevice> m_pVirDev = m_pImage->create_virtual_device(); + m_pVirDev->SetOutputSizePixel(aGraphic.GetSizePixel()); + m_pVirDev->DrawBitmapEx(Point(0, 0), aGraphic.GetBitmapEx()); + m_pImage->set_image(m_pVirDev.get()); + m_pVirDev.disposeAndClear(); + } +} + +IMPL_LINK_NOARG(ToolbarmodeDialog, SelectToolbarmode, weld::ToggleButton&, void) +{ + const int i = GetActiveRadioButton(); + if (i > -1) + { + UpdateImage(std::get<2>(TOOLBARMODES_ARRAY[i])); + m_pInfoLabel->set_label(CuiResId(std::get<0>(TOOLBARMODES_ARRAY[i]))); + } +} + +IMPL_LINK(ToolbarmodeDialog, OnApplyClick, weld::Button&, rButton, void) +{ + const int i = GetActiveRadioButton(); + if (i == -1) + return; + const OUString sCmd = std::get<1>(TOOLBARMODES_ARRAY[i]); + //apply to all except current module + if (&rButton == m_pApplyAll.get()) + { + std::shared_ptr<comphelper::ConfigurationChanges> aBatch( + comphelper::ConfigurationChanges::create(::comphelper::getProcessComponentContext())); + officecfg::Office::UI::ToolbarMode::ActiveWriter::set(sCmd, aBatch); + officecfg::Office::UI::ToolbarMode::ActiveCalc::set(sCmd, aBatch); + officecfg::Office::UI::ToolbarMode::ActiveImpress::set(sCmd, aBatch); + officecfg::Office::UI::ToolbarMode::ActiveDraw::set(sCmd, aBatch); + aBatch->commit(); + + OUString sCurrentApp = GetCurrentApp(); + if (SfxViewFrame* pViewFrame = SfxViewFrame::Current()) + { + const auto xCurrentFrame = pViewFrame->GetFrame().GetFrameInterface(); + const auto xContext = comphelper::getProcessComponentContext(); + const auto xModuleManager = css::frame::ModuleManager::create(xContext); + const utl::OConfigurationTreeRoot aAppNode( + xContext, "org.openoffice.Office.UI.ToolbarMode/Applications/", true); + if (sCurrentApp != "Writer") + aAppNode.setNodeValue("Writer/Active", css::uno::makeAny(sCmd)); + if (sCurrentApp != "Calc") + aAppNode.setNodeValue("Calc/Active", css::uno::makeAny(sCmd)); + if (sCurrentApp != "Impress") + aAppNode.setNodeValue("Impress/Active", css::uno::makeAny(sCmd)); + if (sCurrentApp != "Draw") + aAppNode.setNodeValue("Draw/Active", css::uno::makeAny(sCmd)); + aAppNode.commit(); + }; + } + //apply to current module + comphelper::dispatchCommand(".uno:ToolbarMode?Mode:string=" + sCmd, {}); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index 731303dc50a3..f970e4a10503 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -88,6 +88,7 @@ #include <hyphen.hxx> #include <thesdlg.hxx> #include <tipofthedaydlg.hxx> +#include <toolbarmodedlg.hxx> #include <DiagramDialog.hxx> using namespace ::com::sun::star; @@ -1679,6 +1680,13 @@ AbstractDialogFactory_Impl::CreateTipOfTheDayDialog(weld::Window* pParent) std::make_unique<TipOfTheDayDialog>(pParent)); } +VclPtr<VclAbstractDialog> +AbstractDialogFactory_Impl::CreateToolbarmodeDialog(weld::Window* pParent) +{ + return VclPtr<CuiAbstractController_Impl>::Create( + std::make_unique<ToolbarmodeDialog>(pParent)); +} + VclPtr<AbstractDiagramDialog> AbstractDialogFactory_Impl::CreateDiagramDialog(weld::Window* pParent, std::shared_ptr<DiagramDataInterface> pDiagramData) { diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx index fd11ee459d73..4d0b569108dd 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -941,6 +941,8 @@ public: virtual VclPtr<VclAbstractDialog> CreateTipOfTheDayDialog(weld::Window* pParent) override; + virtual VclPtr<VclAbstractDialog> CreateToolbarmodeDialog(weld::Window* pParent) override; + virtual VclPtr<AbstractDiagramDialog> CreateDiagramDialog( weld::Window* pParent, std::shared_ptr<DiagramDataInterface> pDiagramData) override; diff --git a/cui/source/inc/toolbarmodedlg.hxx b/cui/source/inc/toolbarmodedlg.hxx new file mode 100644 index 000000000000..40d6dc835851 --- /dev/null +++ b/cui/source/inc/toolbarmodedlg.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#pragma once + +#include <vcl/weld.hxx> + +class ToolbarmodeDialog : public weld::GenericDialogController +{ +public: + ToolbarmodeDialog(weld::Window* pWindow); + virtual ~ToolbarmodeDialog() override; + +private: + std::unique_ptr<weld::Image> m_pImage; + std::unique_ptr<weld::Button> m_pApply; + std::unique_ptr<weld::Button> m_pApplyAll; + std::unique_ptr<weld::RadioButton> m_pRadioButtons[9]; + std::unique_ptr<weld::Label> m_pInfoLabel; + + void UpdateImage(OUString sFileName); + int GetActiveRadioButton(); + DECL_LINK(SelectToolbarmode, weld::ToggleButton&, void); + DECL_LINK(OnApplyClick, weld::Button&, void); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |