[Solved] IF Text Selected Italics ELSE Type ī ENDIF

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
Bhikkhu Pesala
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am

[Solved] IF Text Selected Italics ELSE Type ī ENDIF

Post by Bhikkhu Pesala »

Is there some way to do this?

If text is selected I want Control I to make it italics as usual, but if not, I want it to type ī macron (which is what it currently does with this code:

Code: Select all

sub imacron
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Symbols"
args1(0).Value = "ī"

dispatcher.executeDispatch(document, ".uno:InsertSymbol", "", 0, args1())

end sub
Last edited by Bhikkhu Pesala on Sat Jan 26, 2008 2:39 am, edited 1 time in total.
Idiot Compassion
LibreOffice 6.0.4 on Windows 10
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: IF Text Selected Italics ELSE Type ī ENDIF

Post by JohnV »

Assign this macro to Ctrl + I.

Code: Select all

Sub CtrlI
oDoc = ThisComponent
oVC = oDoc.CurrentController.getViewCursor
If oVC.isCollapsed then
  oVC.String = "ī"
 ElseIf oVC.CharPosture = 2 then oVC.CharPosture = 0
 Else oVC.CharPosture = 2
EndIf
oVC.CollapseToEnd
End Sub
Last edited by JohnV on Sat Jan 26, 2008 8:24 am, edited 2 times in total.
User avatar
Bhikkhu Pesala
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am

Re: IF Text Selected Italics ELSE Type ī ENDIF

Post by Bhikkhu Pesala »

Thanks John. That almost works, i.e. it turns italics on for selected text, and types an ī, but it doesn't turn italics off. Can we add another ELSE clause there to turn italics off if it is already on?

Else IF oVC.CharPosture = 2
oVC.CharPosture = 0
END IF
Idiot Compassion
LibreOffice 6.0.4 on Windows 10
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: IF Text Selected Italics ELSE Type ī ENDIF

Post by JohnV »

Original code above modified according to your request.
User avatar
Bhikkhu Pesala
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am

Re: IF Text Selected Italics ELSE Type ī ENDIF

Post by Bhikkhu Pesala »

Thanks again, John. It may be a while before I understand Oo macros, but I am beginning to get the idea.
Idiot Compassion
LibreOffice 6.0.4 on Windows 10
Post Reply