Page 1 of 1

[Solved] IF Text Selected Italics ELSE Type ī ENDIF

PostPosted: Thu Jan 24, 2008 11:32 pm
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   Expand viewCollapse view
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

Re: IF Text Selected Italics ELSE Type ī ENDIF

PostPosted: Fri Jan 25, 2008 6:49 pm
by JohnV
Assign this macro to Ctrl + I.
Code: Select all   Expand viewCollapse view
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

Re: IF Text Selected Italics ELSE Type ī ENDIF

PostPosted: Fri Jan 25, 2008 8:10 pm
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

Re: IF Text Selected Italics ELSE Type ī ENDIF

PostPosted: Fri Jan 25, 2008 11:21 pm
by JohnV
Original code above modified according to your request.

Re: IF Text Selected Italics ELSE Type ī ENDIF

PostPosted: Sat Jan 26, 2008 2:39 am
by Bhikkhu Pesala
Thanks again, John. It may be a while before I understand Oo macros, but I am beginning to get the idea.