tdf#142978 Add quick fix action for missing alt text

Change-Id: I09234e50def6b52b9a70081f31bb45b8d7e2cdd9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150003
Tested-by: Jenkins
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de>
This commit is contained in:
Samuel Mehrbrodt
2023-04-20 11:24:51 +02:00
parent 61be351ac8
commit ccd6415902
9 changed files with 75 additions and 0 deletions
+10
View File
@@ -11,7 +11,10 @@
#pragma once
#include <sfx2/dllapi.h>
#include <vcl/weld.hxx>
#include <rtl/ustring.hxx>
#include <vector>
#include <memory>
@@ -46,8 +49,15 @@ public:
virtual bool canGotoIssue() const = 0;
virtual void gotoIssue() const = 0;
virtual bool canQuickFixIssue() const = 0;
virtual void quickFixIssue() const = 0;
virtual void setParent(weld::Window* pParent) { m_pParent = pParent; }
AccessibilityIssueID m_eIssueID;
OUString m_aIssueText;
weld::Window* m_pParent;
};
class SFX2_DLLPUBLIC AccessibilityIssueCollection
@@ -41,5 +41,18 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="accessibilityCheckEntryFixButton">
<property name="label" translatable="yes" context="accessibilitycheckentry|accessibilityCheckEntryFixButton">Fix</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</interface>
+1
View File
@@ -30,6 +30,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uwriter, \
$(call gb_Helper_optional,AVMEDIA,avmedia) \
basegfx \
comphelper \
cui \
cppu \
cppuhelper \
$(call gb_Helper_optional,DBCONNECTIVITY, \
+1
View File
@@ -56,6 +56,7 @@ $(eval $(call gb_Library_use_libraries,sw,\
comphelper \
cppu \
cppuhelper \
cui \
$(call gb_Helper_optional,DBCONNECTIVITY, \
dbtools) \
docmodel \
+2
View File
@@ -41,6 +41,8 @@
#define STR_STYLE_NO_LANGUAGE NC_("STR_STYLE_NO_LANGUAGE", "Style “%STYLE_NAME%” has no language set.")
#define STR_DOCUMENT_TITLE NC_("STR_DOCUMENT_TITLE", "Document title is not set.")
#define STR_ENTER_ALT NC_("STR_ENTER_ALT", "Enter alternative text:")
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@@ -9,9 +9,12 @@
*/
#include <AccessibilityIssue.hxx>
#include <AccessibilityCheckStrings.hrc>
#include <swtypes.hxx>
#include <wrtsh.hxx>
#include <docsh.hxx>
#include <comphelper/lok.hxx>
#include <cui/dlgname.hxx>
namespace sw
{
@@ -84,6 +87,36 @@ void AccessibilityIssue::gotoIssue() const
}
}
bool AccessibilityIssue::canQuickFixIssue() const
{
return m_eIssueObject == IssueObject::GRAPHIC || m_eIssueObject == IssueObject::OLE;
}
void AccessibilityIssue::quickFixIssue() const
{
if (!m_pDoc)
return;
switch (m_eIssueObject)
{
case IssueObject::GRAPHIC:
case IssueObject::OLE:
{
OUString aDesc = SwResId(STR_ENTER_ALT);
SvxNameDialog aNameDialog(m_pParent, "", aDesc);
if (aNameDialog.run() == RET_OK)
{
SwFlyFrameFormat* pFlyFormat
= const_cast<SwFlyFrameFormat*>(m_pDoc->FindFlyByName(m_sObjectID));
m_pDoc->SetFlyFrameTitle(*pFlyFormat, aNameDialog.GetName());
}
}
break;
default:
break;
}
}
} // end sw namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@@ -59,6 +59,9 @@ public:
bool canGotoIssue() const override;
void gotoIssue() const override;
bool canQuickFixIssue() const override;
void quickFixIssue() const override;
sal_Int32 getStart() { return m_nStart; }
sal_Int32 getEnd() { return m_nEnd; }
SwNode* getNode() { return m_pNode; }
@@ -31,6 +31,7 @@ AccessibilityCheckEntry::AccessibilityCheckEntry(
, m_xContainer(m_xBuilder->weld_container("accessibilityCheckEntryBox"))
, m_xLabel(m_xBuilder->weld_label("accessibilityCheckEntryLabel"))
, m_xGotoButton(m_xBuilder->weld_button("accessibilityCheckEntryGotoButton"))
, m_xFixButton(m_xBuilder->weld_button("accessibilityCheckEntryFixButton"))
, m_pAccessibilityIssue(rAccessibilityIssue)
{
m_xLabel->set_label(m_pAccessibilityIssue->m_aIssueText);
@@ -38,6 +39,10 @@ AccessibilityCheckEntry::AccessibilityCheckEntry(
m_xContainer->set_size_request(-1, m_xContainer->get_preferred_size().Height());
m_xGotoButton->set_visible(m_pAccessibilityIssue->canGotoIssue());
m_xGotoButton->connect_clicked(LINK(this, AccessibilityCheckEntry, GotoButtonClicked));
m_xFixButton->set_visible(m_pAccessibilityIssue->canQuickFixIssue());
m_xFixButton->connect_clicked(LINK(this, AccessibilityCheckEntry, FixButtonClicked));
m_pAccessibilityIssue->setParent(dynamic_cast<weld::Window*>(get_widget()));
}
IMPL_LINK_NOARG(AccessibilityCheckEntry, GotoButtonClicked, weld::Button&, void)
@@ -45,6 +50,11 @@ IMPL_LINK_NOARG(AccessibilityCheckEntry, GotoButtonClicked, weld::Button&, void)
m_pAccessibilityIssue->gotoIssue();
}
IMPL_LINK_NOARG(AccessibilityCheckEntry, FixButtonClicked, weld::Button&, void)
{
m_pAccessibilityIssue->quickFixIssue();
}
std::unique_ptr<PanelLayout> A11yCheckIssuesPanel::Create(weld::Widget* pParent,
SfxBindings* pBindings)
{
@@ -29,6 +29,7 @@ private:
std::unique_ptr<weld::Container> m_xContainer;
std::unique_ptr<weld::Label> m_xLabel;
std::unique_ptr<weld::Button> m_xGotoButton;
std::unique_ptr<weld::Button> m_xFixButton;
std::shared_ptr<sfx::AccessibilityIssue> const& m_pAccessibilityIssue;
@@ -39,6 +40,7 @@ public:
weld::Widget* get_widget() const { return m_xContainer.get(); }
DECL_LINK(GotoButtonClicked, weld::Button&, void);
DECL_LINK(FixButtonClicked, weld::Button&, void);
};
class A11yCheckIssuesPanel : public PanelLayout,