diff options
author | Justin Luth <justin_luth@sil.org> | 2015-08-05 15:04:28 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-08-12 14:43:04 +0000 |
commit | ff3c4f4c704977b2eec1dba1238b422537e413f3 (patch) | |
tree | b8a5ba7377a5c4fe88025d90d915d32177437d5e /sw | |
parent | ce286dd9e143431044403b78afc1d237cb11acb6 (diff) |
tdf#73691 Implement MSWord's Alt-X: toggle unicode notation
-toggles between characters and their unicode notation
-sets Alt-X as a global keyboard accelerator
-handles all of the unicode planes
-intelligently handles combining characters
-if text is selected, limits the input to that text
-implemented in Writer, Draw, Impress
Change-Id: Idcd8e7f0a4f1b81fa7f5f3200c76be19472ffa37
Reviewed-on: https://gerrit.libreoffice.org/17535
Tested-by: Samuel Mehrbrodt <s.mehrbrodt@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/uiwriter/data/unicodeAltX.odt | bin | 0 -> 19259 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 25 | ||||
-rw-r--r-- | sw/sdi/_textsh.sdi | 5 | ||||
-rw-r--r-- | sw/sdi/swriter.sdi | 25 | ||||
-rw-r--r-- | sw/source/uibase/shells/textsh1.cxx | 32 |
5 files changed, 86 insertions, 1 deletions
diff --git a/sw/qa/extras/uiwriter/data/unicodeAltX.odt b/sw/qa/extras/uiwriter/data/unicodeAltX.odt Binary files differnew file mode 100644 index 000000000000..4c96eff0120f --- /dev/null +++ b/sw/qa/extras/uiwriter/data/unicodeAltX.odt diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index cedc59654a0e..2230c76d2585 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -147,6 +147,7 @@ public: void testTdf90883TableBoxGetCoordinates(); void testEmbeddedDataSource(); void testUnoCursorPointer(); + void testUnicodeNotationToggle(); void testTextTableCellNames(); void testShapeAnchorUndo(); void testDde(); @@ -215,6 +216,7 @@ public: CPPUNIT_TEST(testTdf90883TableBoxGetCoordinates); CPPUNIT_TEST(testEmbeddedDataSource); CPPUNIT_TEST(testUnoCursorPointer); + CPPUNIT_TEST(testUnicodeNotationToggle); CPPUNIT_TEST(testTextTableCellNames); CPPUNIT_TEST(testShapeAnchorUndo); CPPUNIT_TEST(testDde); @@ -2176,6 +2178,29 @@ void SwUiWriterTest::testDde() CPPUNIT_ASSERT(xField->getString().endsWith("asdf")); } +void SwUiWriterTest::testUnicodeNotationToggle() +{ + SwDoc* pDoc = createDoc("unicodeAltX.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + OUString sOriginalDocString; + OUString sDocString; + OUString sExpectedString; + uno::Sequence<beans::PropertyValue> aPropertyValues; + + pWrtShell->EndPara(); + sOriginalDocString = pWrtShell->GetCrsr()->GetNode().GetTextNode()->GetText(); + CPPUNIT_ASSERT( sOriginalDocString.equals("uU+2b") ); + + lcl_dispatchCommand(mxComponent, ".uno:UnicodeNotationToggle", aPropertyValues); + sExpectedString = "u+"; + sDocString = pWrtShell->GetCrsr()->GetNode().GetTextNode()->GetText(); + CPPUNIT_ASSERT( sDocString.equals(sExpectedString) ); + + lcl_dispatchCommand(mxComponent, ".uno:UnicodeNotationToggle", aPropertyValues); + sDocString = pWrtShell->GetCrsr()->GetNode().GetTextNode()->GetText(); + CPPUNIT_ASSERT( sDocString.equals(sOriginalDocString) ); +} + void SwUiWriterTest::testTdf89954() { SwDoc* pDoc = createDoc("tdf89954.odt"); diff --git a/sw/sdi/_textsh.sdi b/sw/sdi/_textsh.sdi index 6080438fcd1d..f0793a18341b 100644 --- a/sw/sdi/_textsh.sdi +++ b/sw/sdi/_textsh.sdi @@ -1630,6 +1630,11 @@ interface BaseText DisableFlags="SW_DISABLE_ON_PROTECTED_CURSOR"; // e.g. disable for read-only documents ] + SID_UNICODE_NOTATION_TOGGLE + [ + ExecMethod = Execute; + ] + SID_THES [ ExecMethod = Execute ; diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index 6ecfbb873736..6fc3b750feac 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -10249,3 +10249,28 @@ SfxVoidItem RemoveTextBox FN_REMOVE_TEXT_BOX ToolBoxConfig = TRUE, GroupId = GID_DRAWING; ] + +SfxVoidItem UnicodeNotationToggle SID_UNICODE_NOTATION_TOGGLE +() +[ + /* flags: */ + AutoUpdate = FALSE, + Cachable = Cachable, + FastCall = FALSE, + HasCoreId = FALSE, + HasDialog = FALSE, + ReadOnlyDoc = FALSE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + Asynchron; + + /* config: */ + AccelConfig = TRUE, + MenuConfig = FALSE, + StatusBarConfig = FALSE, + ToolBoxConfig = FALSE, + GroupId = GID_OPTIONS; +] + diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx index 8dcff4199011..8f5e9cd64124 100644 --- a/sw/source/uibase/shells/textsh1.cxx +++ b/sw/source/uibase/shells/textsh1.cxx @@ -23,6 +23,7 @@ #include <cmdid.h> #include <helpid.h> +#include <i18nutil/unicode.hxx> #include <i18nlangtag/languagetag.hxx> #include <svl/languageoptions.hxx> #include <editeng/langitem.hxx> @@ -113,7 +114,7 @@ #include <tools/diagnose_ex.h> #include <svx/nbdtmgfact.hxx> #include <svx/nbdtmg.hxx> - +#include <SwRewriter.hxx> #include <svx/svdmodel.hxx> #include <svx/drawitem.hxx> #include <numrule.hxx> @@ -287,6 +288,35 @@ void SwTextShell::Execute(SfxRequest &rReq) pArgs->GetItemState(GetPool().GetWhich(nSlot), false, &pItem); switch( nSlot ) { + case SID_UNICODE_NOTATION_TOGGLE: + { + int nMaxUnits = 256; + if( rWrtSh.IsSelection() && !rWrtSh.IsMultiSelection() ) + nMaxUnits = rWrtSh.GetSelText().getLength(); + + int index = 0; + ToggleUnicodeCodepoint aToggle = ToggleUnicodeCodepoint(); + while( nMaxUnits-- && aToggle.AllowMoreInput(rWrtSh.GetChar(true, index-1)) ) + --index; + + OUString sReplacement = aToggle.ReplacementString(); + if( !sReplacement.isEmpty() ) + { + SwRewriter aRewriter; + aRewriter.AddRule( UndoArg1, aToggle.StringToReplace() ); + aRewriter.AddRule( UndoArg2, "->" ); + aRewriter.AddRule( UndoArg3, sReplacement ); + rWrtSh.StartUndo(UNDO_REPLACE, &aRewriter); + rWrtSh.GetCrsr()->Normalize(false); + rWrtSh.ClearMark(); + for( sal_uInt32 i=aToggle.CharsToDelete(); i > 0; --i ) + rWrtSh.DelLeft(); + rWrtSh.Insert2( sReplacement ); + rWrtSh.EndUndo(UNDO_REPLACE, &aRewriter); + } + } + break; + case SID_LANGUAGE_STATUS: { // get the language |