Page 1 of 1
Need help creating an extension for Writer
Posted: Wed Jun 01, 2022 5:11 pm
by Osgaldor
I want to create an extension in OpenOffice Basic for writer. It needs a dialog box to collect a numeric value from the user (I think I'm okay with that process) and I'd like to create a little panel to output a text message either in the toolbar section at the top or in the little bar at the bottom of the window. I can't seem to find the documentation for how to create such a small panel in the window interface. Can anyone point me in the direction of the information I'm looking for? I'd kind of like to put my extension's output in the little block at the bottom left of the window where it keeps up with the page numbers. I want to be able to change to color of the text in the output panel.
I'm a fairly experienced developer in Visual Basic, Java, Python and several others. I'm building my extension in Basic.
My extension will as the user to enter a target number of words, like for a writing goal for the day and it will keep track of the word count as they write and notify the user when they have reachedtheir desired number of words.
Re: Need help creating an extension for writer
Posted: Wed Jun 01, 2022 5:46 pm
by JeJe
You want to add an item to the status bar?
There's the proper statusbar controller method that I don't understand and you might not be able to do it with Basic anyway
https://wiki.openoffice.org/wiki/Framew ... Controller
Or you can use the following and investigate with MRI how to add an item and set it.
Code: Select all
els = thiscomponent.currentcontroller.frame.layoutmanager.elements
for i = 0 to ubound(els)
if right(els(i).resourceurl,9)= "statusbar" then
statussettings = els(i).getsettings(true)
mri statussettings
exit for
end if
next
Re: Need help creating an extension for writer
Posted: Wed Jun 01, 2022 6:11 pm
by Osgaldor
I guess I should really begin by asking how to access the current word count property since my entire extension depends on it. I'd like to keep the current word count stored in a variable called currentWordCount that I can use to compare to a wordGoal variable. Is word count a property of the Document object?
Re: Need help creating an extension for writer
Posted: Wed Jun 01, 2022 6:15 pm
by JeJe
Re: Need help creating an extension for writer
Posted: Wed Jun 01, 2022 6:28 pm
by RoryOF
In some versions of Dmitri Popov's "Writers Tools" there is a Visual Word Count; the code for that may be of help to you.
Re: Need help creating an extension for writer
Posted: Thu Jun 02, 2022 7:50 am
by Zizi64
My extension will as the user to enter a target number of words, like for a writing goal for the day and it will keep track of the word count as they write and notify the user when they have reachedtheir desired number of words.
The LibreOffice has such feature by default.
- Visible Word count feature exists in the LibreOffiice.png (4.58 KiB) Viewed 8240 times
Re: Need help creating an extension for Writer
Posted: Fri Jun 03, 2022 10:28 am
by Bidouille
Osgaldor wrote: ↑Wed Jun 01, 2022 5:11 pm
My extension will as the user to enter a target number of words, like for a writing goal for the day and it will keep track of the word count as they write and notify the user when they have reachedtheir desired number of words.
This extension already exists:
https://extensions.openoffice.org/en/pr ... controller
Don't reinvent the wheel!
.
Re: Need help creating an extension for Writer
Posted: Thu Mar 16, 2023 7:38 am
by anwar4870
To create a small panel in the OpenOffice window interface, you will need to use the OpenOffice API (Application Programming Interface). Here are the basic steps you need to follow:
Create a new dialog box: You mentioned that you are okay with creating a dialog box to collect a numeric value from the user. You can use the OpenOffice Basic "DialogLib" library to create a dialog box. You can find more information about this library in the OpenOffice Basic Guide.
Create a panel: To create a small panel in the OpenOffice window interface, you will need to use the "
Code: Select all
com.sun.star.awt.UnoControlFixedText
" control. This control allows you to display text in a fixed area on the window interface. You can use the following code to create a panel:
Code: Select all
Dim oPanel As Object
oPanel = CreateUnoControl("com.sun.star.awt.UnoControlFixedText")
oPanel.Model.PositionX = 10 ' Set the X position of the panel
oPanel.Model.PositionY = 10 ' Set the Y position of the panel
oPanel.Model.Width = 100 ' Set the width of the panel
oPanel.Model.Height = 20 ' Set the height of the panel
oPanel.Model.MultiLine = True ' Allow the text to wrap to multiple lines
oPanel.Model.BackgroundColor = RGB(255, 255, 255) ' Set the background color of the panel
Add the panel to the window: To add the panel to the window, you will need to use the "com.sun.star.frame.XStatusListener" interface. This interface allows you to add a custom status bar item to the OpenOffice window. You can use the following code to add the panel to the window:
Code: Select all
Dim oWindow As Object
oWindow = ThisComponent.CurrentController.Frame.ContainerWindow
Dim oStatusBar As Object
oStatusBar = oWindow.StatusBar
Dim oStatusListener As Object
oStatusListener = CreateUnoListener("MyStatusListener_", "com.sun.star.frame.XStatusListener")
oStatusBar.addStatusListener(oStatusListener)
Update the panel text: To update the text displayed in the panel, you will need to use the "Text" property of the control. You can use the following code to update the panel text:
Code: Select all
oPanel.Model.Text = "Your message here"
Change the text color: To change the color of the text in the panel, you will need to use the "TextColor" property of the control. You can use the following code to change the text color:
Code: Select all
oPanel.Model.TextColor = RGB(255, 0, 0) ' Set the text color to red
I hope this helps you create the small panel you need for your OpenOffice Basic extension!
Regards
Anwar
CEO
MobilesinBD
Re: Need help creating an extension for Writer
Posted: Thu Mar 16, 2023 8:09 pm
by JeJe
anwar4870 - your code is missing the CreateUnoControl function. Its better for people if you put it all together, ideally between one set of code tags in your post, rather than several and with a test sub to run it all so it can be easily tested.