summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2024-10-10 20:48:10 -0400
committerJustin Luth <jluth@mail.com>2024-10-17 17:33:49 +0200
commitbc21a85029a6b31cab07a4e3d481e059120ff510 (patch)
tree7cd9d1e39bce1c0b5c7ebf4536c89b6198999435 /sw/qa
parent4df8414e919f2ff82429dfa302db9cd2d1261b26 (diff)
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 8c822b764b35a0116a0865e991a87c8315e0 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>
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/extras/uiwriter/uiwriter9.cxx16
1 files changed, 16 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter9.cxx b/sw/qa/extras/uiwriter/uiwriter9.cxx
index f97d5a572d4d..8f968353bdf8 100644
--- a/sw/qa/extras/uiwriter/uiwriter9.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter9.cxx
@@ -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