tdf#34804 sw: enable keyboard shortcut for CharColor and CharBackColor
The result of this patch is that a keyboard shortcut can now
set the font fore-/back-ground color using the
color shown in the toolbar/sidebar.
This is now possible thanks to Maxim's work in 7.6.2
tdf#154270 Sync toolbar button recent colors
and Andreas Heinisch's 24.8 commit 8c822b764b
tdf#72991 - Remember last used color depending in cui
This patch does 3 things:
1. SetRecentColor when the app initializes
2. Uses SID_ATTR_CHAR_COLOR's recentColor for .uno:FontColor
if no pItem was provided (i.e. a keyboard shortcut called it)
3. Uses SID_ATTR_CHAR_BACK_COLOR's recentColor for .uno:CharBackColor
if no pItem was provided
(Note that without a selection,
CharBackColor isn't so useful for a keyboard shortcut,
since it turns the drag-and-drop template on.)
Setting the recent color right away is critical for user acceptance.
Otherwise, it would only function after they first modified the color
in the toolbar/sidebar.
make CppunitTest_sw_uiwriter9 CPPUNIT_TEST_NAME=testTdf34804
Unfortunately, I can't reliably know if this request
came from an awt::KeyEvent or not, because in that case
we could just avoid CharBackColor's template altogether.
[While there is rReq.GetModifiers() as a good hint,
it is not a guarantee (in case assigned to a function key,
or CTRL held while clicking the toolbar, etc.)]
Change-Id: I7377f087dcdf7011205af005cd0d172100bade2b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174804
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
This commit is contained in:
@@ -31,7 +31,7 @@ struct SFX2_DLLPUBLIC NamedColor
|
||||
{
|
||||
}
|
||||
|
||||
model::ComplexColor getComplexColor()
|
||||
model::ComplexColor getComplexColor() const
|
||||
{
|
||||
model::ComplexColor aComplexColor;
|
||||
|
||||
|
||||
@@ -582,7 +582,7 @@ public:
|
||||
StarBASIC* GetBasic() const;
|
||||
|
||||
std::optional<NamedColor> GetRecentColor(sal_uInt16 nSlotId);
|
||||
void SetRecentColor(sal_uInt16 nSlotId, const NamedColor& rColor);
|
||||
void SetRecentColor(sal_uInt16 nSlotId, const NamedColor& rColor, bool bBroadcast = true);
|
||||
|
||||
virtual std::shared_ptr<sfx::IDocumentModelAccessor> GetDocumentModelAccessor() const;
|
||||
virtual std::set<Color> GetDocColors();
|
||||
|
||||
@@ -326,10 +326,11 @@ std::optional<NamedColor> SfxObjectShell::GetRecentColor(sal_uInt16 nSlotId)
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SfxObjectShell::SetRecentColor(sal_uInt16 nSlotId, const NamedColor& rColor)
|
||||
void SfxObjectShell::SetRecentColor(sal_uInt16 nSlotId, const NamedColor& rColor, bool bBroadcast)
|
||||
{
|
||||
pImpl->m_aRecentColors[nSlotId] = rColor;
|
||||
Broadcast(SfxHint(SfxHintId::ColorsChanged));
|
||||
if (bBroadcast)
|
||||
Broadcast(SfxHint(SfxHintId::ColorsChanged));
|
||||
}
|
||||
|
||||
std::set<Color> SfxObjectShell::GetDocColors()
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace svx
|
||||
virtual ~ToolboxButtonColorUpdaterBase();
|
||||
|
||||
void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
|
||||
void SetRecentColor(const NamedColor& rNamedColor);
|
||||
void SetRecentColor(const NamedColor& rNamedColor, bool bBroadcast = true);
|
||||
void Update( const NamedColor& rNamedColor );
|
||||
void Update( const Color& rColor, bool bForceUpdate = false );
|
||||
Color const & GetCurrentColor() const { return maCurColor; }
|
||||
|
||||
@@ -122,6 +122,7 @@ namespace svx
|
||||
o3tl::toUInt32(o3tl::getToken(aUserData, 0, ';', nIdx)));
|
||||
}
|
||||
}
|
||||
SetRecentColor(aNamedColor, /*Broadcast=*/false);
|
||||
Update(aNamedColor);
|
||||
}
|
||||
else
|
||||
@@ -149,10 +150,10 @@ namespace svx
|
||||
}
|
||||
}
|
||||
|
||||
void ToolboxButtonColorUpdaterBase::SetRecentColor(const NamedColor &rNamedColor)
|
||||
void ToolboxButtonColorUpdaterBase::SetRecentColor(const NamedColor &rNamedColor, bool bBroadcast)
|
||||
{
|
||||
if (rtl::Reference xModel = dynamic_cast<SfxBaseModel*>(mxFrame->getController()->getModel().get()))
|
||||
xModel->GetObjectShell()->SetRecentColor(mnSlotId, rNamedColor);
|
||||
xModel->GetObjectShell()->SetRecentColor(mnSlotId, rNamedColor, bBroadcast);
|
||||
else if (!mbWideButton)
|
||||
Update(rNamedColor);
|
||||
}
|
||||
|
||||
@@ -332,6 +332,22 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf159816)
|
||||
xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, /*bXSelection=*/true);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf34804)
|
||||
{
|
||||
createSwDoc();
|
||||
SwDoc* pDoc = getSwDoc();
|
||||
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
|
||||
|
||||
// Simulate a keyboard shortcut to SID_ATTR_CHAR_COLOR2 (which must use the shared button color)
|
||||
dispatchCommand(mxComponent, u".uno:FontColor"_ustr, {});
|
||||
pWrtShell->Insert(u"New World!"_ustr);
|
||||
|
||||
const uno::Reference<text::XTextRange> xRun = getRun(getParagraph(1, "New World!"), 1);
|
||||
// (This test assumes that nothing in the unit tests has modified the app's recent font color)
|
||||
// COL_DEFAULT_FONT is the default red color for the fontColor button on the toolbar.
|
||||
CPPUNIT_ASSERT_EQUAL(COL_DEFAULT_FONT, getProperty<Color>(xRun, u"CharColor"_ustr));
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(SwUiWriterTest9, testTdf139631)
|
||||
{
|
||||
// Unit test for tdf#139631
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <sfx2/htmlmode.hxx>
|
||||
#include <svl/whiter.hxx>
|
||||
#include <sfx2/bindings.hxx>
|
||||
#include <sfx2/namedcolor.hxx>
|
||||
#include <sfx2/viewfrm.hxx>
|
||||
#include <vcl/unohelp2.hxx>
|
||||
#include <vcl/weld.hxx>
|
||||
@@ -1761,6 +1762,21 @@ void SwTextShell::Execute(SfxRequest &rReq)
|
||||
|
||||
case SID_ATTR_CHAR_COLOR2:
|
||||
{
|
||||
std::unique_ptr<const SvxColorItem> pRecentColor; // manage lifecycle scope
|
||||
if (!pItem)
|
||||
{
|
||||
// no color provided: use the pre-selected color shown in the toolbar/sidebar
|
||||
const std::optional<NamedColor>& oColor
|
||||
= GetView().GetDocShell()->GetRecentColor(SID_ATTR_CHAR_COLOR);
|
||||
if (oColor.has_value())
|
||||
{
|
||||
const model::ComplexColor& rCol = (*oColor).getComplexColor();
|
||||
pRecentColor = std::make_unique<const SvxColorItem>(
|
||||
rCol.getFinalColor(), rCol, RES_CHRATR_COLOR);
|
||||
pItem = pRecentColor.get();
|
||||
}
|
||||
}
|
||||
|
||||
if (pItem)
|
||||
{
|
||||
auto* pColorItem = static_cast<const SvxColorItem*>(pItem);
|
||||
@@ -1783,7 +1799,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
|
||||
case SID_ATTR_CHAR_COLOR_BACKGROUND: // deprecated
|
||||
case SID_ATTR_CHAR_COLOR_EXT:
|
||||
{
|
||||
Color aColor;
|
||||
Color aColor = COL_TRANSPARENT;
|
||||
model::ComplexColor aComplexColor;
|
||||
|
||||
if (pItem)
|
||||
@@ -1792,8 +1808,17 @@ void SwTextShell::Execute(SfxRequest &rReq)
|
||||
aColor = pColorItem->GetValue();
|
||||
aComplexColor = pColorItem->getComplexColor();
|
||||
}
|
||||
else
|
||||
aColor = COL_TRANSPARENT;
|
||||
else if (nSlot == SID_ATTR_CHAR_BACK_COLOR)
|
||||
{
|
||||
// no color provided: use the pre-selected color shown in the toolbar/sidebar
|
||||
const std::optional<NamedColor>& oColor
|
||||
= GetView().GetDocShell()->GetRecentColor(nSlot);
|
||||
if (oColor.has_value())
|
||||
{
|
||||
aComplexColor = (*oColor).getComplexColor();
|
||||
aColor = aComplexColor.getFinalColor();
|
||||
}
|
||||
}
|
||||
|
||||
SwEditWin& rEdtWin = GetView().GetEditWin();
|
||||
if (nSlot != SID_ATTR_CHAR_COLOR_EXT)
|
||||
|
||||
Reference in New Issue
Block a user