Are there AutoCorrect or AutoComplete services?

Creating a macro - Writing a Script - Using the API

Are there AutoCorrect or AutoComplete services?

Postby JeJe » Sun Jan 15, 2017 12:27 am

There are services for the Spellchecker, Thesaurus and AutoText. Is there any similar services for the AutoCorrect or AutoComplete entries? Perhaps undocumented?

I've looked long and hard. I'd like to add the functionality of all these to textboxes in dialogue. I have workarounds - I can load the AutoCorrect file and parse it myself - but that's not simple. And create my own code for AutoComplete in textboxes - but it wouldn't be the same list as in the main document.

Any proper access to these please?
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1567
Joined: Wed Mar 09, 2016 2:40 pm

Re: Are there AutoCorrect or AutoComplete services?

Postby RoryOF » Sun Jan 15, 2017 12:31 am

Apache OpenOffice 4.1.10 on Xubuntu 20.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 32709
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Are there AutoCorrect or AutoComplete services?

Postby JeJe » Sun Jan 15, 2017 1:29 am

Thanks. That gets me the path to the folder with the autocorrect file

oPathSettings = CreateUnoService( "com.sun.star.util.PathSettings" )
msgbox oPathSettings.AutoCorrect

I don't know OO very well. I know I can find the file and write code myself to parse it and so on. What I'm wondering is if there's a service to get/set Autocorrect entries in that file?
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1567
Joined: Wed Mar 09, 2016 2:40 pm

Re: Are there AutoCorrect or AutoComplete services?

Postby JeJe » Sun Jan 15, 2017 1:34 am

One of my autocorrect entries is "abotu" whic is corrected to "about". Is there a way of querying the word "abotu" to see whether its an autocorrect entry? Without writing code to examine the autocorrect file myself - I know I can do that but its complicated.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1567
Joined: Wed Mar 09, 2016 2:40 pm

Re: Are there AutoCorrect or AutoComplete services?

Postby JeJe » Sun Jan 15, 2017 2:02 am

I've thought of creating a hidden docment and entering the word - then a space - but autocorrect isn't invoked then. Just when the space is entered manually.

oCursor = thisComponent.getText.createTextCursor
oText = thisComponent.getText
otext.string ="abotu"
ocursor.collapseToEnd(false)
ocursor.string =" "

Doesn't invoke autocorrect. Sendkeys might work but that's just Windows and anyway this wouldn't be efficient even if it worked.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1567
Joined: Wed Mar 09, 2016 2:40 pm

Re: Are there AutoCorrect or AutoComplete services?

Postby echo8hink » Wed Jan 25, 2017 5:19 am

There is a sample database with the LibreOffice 5 Base documentation that has an example of AutoComplete macro in formatted text boxes. I would guess it is similar to OpenOffice. I don't have the link handy, but a quick search of their site should get you there.
LibreOffice 5.4.5.1 on Linux Mint 18.3
echo8hink
 
Posts: 10
Joined: Wed Mar 02, 2016 7:59 pm

Re: Are there AutoCorrect or AutoComplete services?

Postby John_Ha » Wed Feb 15, 2017 3:49 pm

See [Tutorial] Automatic functions in Writer - enable / disable.

AutoHotKey is an extremely powerful tool which recognises text the user types and replaces it with pre-defined text or commands. AutoHotKey typed the above line for me when I typed zztutaut, my shortcut for zz_tut[orial]_aut[omatic functions]. zzsol gets ...

If this solves the problem, please click the Edit button on your original post and add [Solved] in front of your subject.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 8486
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Are there AutoCorrect or AutoComplete services?

Postby JeJe » Wed Feb 15, 2017 11:22 pm

Thanks for the two new replies/tries. All I could find for AutoComplete macros in LibreOffice is...
"LibreOffice has an AutoComplete function which activates itself in some text and list boxes. For example, enter ~/a into the URL field and the AutoComplete function displays the first file or first directory found in your home folder that starts with the letter "a"."


https://help.libreoffice.org/Common/Gen ... ut_Keys_in

What I'll probably have to settle for is

Thesausus/Spelling/find and replace - I can access all those features in code fine.
Autocomplete - do a seperate implementation of that for textboxes. The word list just won't be the same as for documents.
Autotext - instead of trying to use that, do a similar but separate text-clips thing for textboxes
Autocorrect - I can read in the autocorrect list from the text file and use that without trying to make any changes to it.
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1567
Joined: Wed Mar 09, 2016 2:40 pm

Re: Are there AutoCorrect or AutoComplete services?

Postby echo8hink » Mon Feb 20, 2017 5:11 pm

I don't know if "Autotext" is exactly what you are looking for. The example I referred to earlier is for LO5 and is in a base file named: Example_Autotext_Searchmark_Spelling.odb.

It is included in a zip file https://wiki.documentfoundation.org/images/5/52/Sample-databases.zip The code snippet below works with a textbox:

Code: Select all   Expand viewCollapse view
SUB Autotext(oEvent AS OBJECT)   'Properties: TextBox → Events → Text modified
   DIM arText()
   DIM stText AS STRING
   DIM oSelection AS NEW com.sun.star.awt.Selection
   DIM oField AS OBJECT
   DIM oAutotexts AS OBJECT
   DIM oRange AS OBJECT
   DIM oCursor AS OBJECT
   oField = oEvent.Source
   IF oField.text <> "" THEN
      arText = Split(oField.text)
      stText = arText(Ubound(arText))
      oAutotexts = createunoservice("com.sun.star.text.AutoTextContainer")
      oRange = oAutotexts.getByName("standard") 'template, standard, crdbus50, mytexts - Autotext will be started in Writer by shortcut and F3.
      IF oRange.hasByName(stText) THEN
         oAutotext = oRange.getByName(stText)  'Example: DMS is the shortcut for "Dear Madam or Sir" (Writer → Edit → AutoText)
         oCursor = oField.Model.createTextCursor()
         oCursor.gotoEnd(true)
         oCursor.goLeft(len(stText),true)
         oField.Model.insertString(oCursor,oAutotext.String,true)
         oSelection.Min = len(oField.Text)
         oSelection.Max = len(oField.Text)
         oField.setFocus
         oField.Selection = oSelection
      END IF
   END IF
END SUB
LibreOffice 5.4.5.1 on Linux Mint 18.3
echo8hink
 
Posts: 10
Joined: Wed Mar 02, 2016 7:59 pm

Re: Are there AutoCorrect or AutoComplete services?

Postby JeJe » Mon Feb 20, 2017 9:27 pm

Brilliant thanks... that helps with the Autotext bit. I've used a little of that to write autotext for a dialog textbox which will work on the F3 keypress.

Code: Select all   Expand viewCollapse view
sub keyPress(oEvt)'call this from dialog textbox keyPress event
   dim sel as new com.sun.star.awt.Selection
   Dim aLocale As New com.sun.star.lang.Locale
   dim a as new com.sun.star.i18n.Boundary
   dim testwd as string,c as object,BI
   dim oAutotexts,oAutotext,AutoTextGroup
   
   
   if oEvt.keycode = 770 then 'f3

      c=oEvt.source
      sel =c.getSelection()
      
      'Set the locale - would do something less ad hoc for a final version.
      aLocale.Language = "en" 'Use the English language
      aLocale.Country = "US" 'Use the United States as the country

      'We could search backwards for a breakchar ourselves but xBreakIterator will get the word boundary for the locale         
      BI = CreateUnoService("com.sun.star.i18n.BreakIterator")
      a =BI.getwordboundary(c.gettext,sel.max,aLocale,0,false)

      testwd=  mid(c.gettext,a.startPos+1,a.endpos - a.startpos)
      
      oAutotexts = createunoservice("com.sun.star.text.AutoTextContainer")
      
      AutoTextGroup = oAutotexts.getByName("standard") 'template, standard, crdbus50, mytexts - Autotext will be started in Writer by shortcut and F3.
      
      IF AutoTextGroup.hasByName(testwd) THEN
         oAutotext = AutoTextGroup.getByName(testwd)  'Example: DMS is the shortcut for "Dear Madam or Sir" (Writer → Edit → AutoText)
         sel.min = a.startpos
         c.insertText sel,oAutotext.string
      end if

   end if

end sub
Openoffice 4.1.6
Windows 8
JeJe
Volunteer
 
Posts: 1567
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests