[Solved] IF Text Selected Italics ELSE Type ī ENDIF

Creating a macro - Writing a Script - Using the API

[Solved] IF Text Selected Italics ELSE Type ī ENDIF

Postby Bhikkhu Pesala » Thu Jan 24, 2008 11:32 pm

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
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
User avatar
Bhikkhu Pesala
 
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am

Re: IF Text Selected Italics ELSE Type ī ENDIF

Postby JohnV » Fri Jan 25, 2008 6:49 pm

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
Last edited by JohnV on Sat Jan 26, 2008 8:24 am, edited 2 times in total.
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: IF Text Selected Italics ELSE Type ī ENDIF

Postby Bhikkhu Pesala » Fri Jan 25, 2008 8:10 pm

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
User avatar
Bhikkhu Pesala
 
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am

Re: IF Text Selected Italics ELSE Type ī ENDIF

Postby JohnV » Fri Jan 25, 2008 11:21 pm

Original code above modified according to your request.
JohnV
Volunteer
 
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: IF Text Selected Italics ELSE Type ī ENDIF

Postby Bhikkhu Pesala » Sat Jan 26, 2008 2:39 am

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
User avatar
Bhikkhu Pesala
 
Posts: 1253
Joined: Mon Oct 08, 2007 1:27 am


Return to Macros and UNO API

Who is online

Users browsing this forum: Spaltersar and 5 guests