Page 1 of 1

[Solved] Toolbar button with icon

Posted: Tue Nov 05, 2024 3:19 pm
by nilman70
Is there any possibility to add a toolbar button with icon to a new toolbar using basic code?

Re: Toolbarbutton with icon

Posted: Tue Nov 05, 2024 7:04 pm
by JeJe
Sure, what are you trying to do?
Add a new toolbar to a single Writer document or to all Writer documents?
Is it an existing Writer command or your own macro you want to call?
Different code applies depending.

Re: Toolbarbutton with icon

Posted: Wed Nov 06, 2024 7:58 am
by Zizi64
You can use a prepared Template for the new, "empty" documents. Just create the toolbar manually in scope of the document, and save it as a Template. Open that Template, when you need the additional toolbar.

Re: Toolbarbutton with icon

Posted: Wed Nov 06, 2024 10:25 am
by nilman70
JeJe wrote: Tue Nov 05, 2024 7:04 pm Sure, what are you trying to do?
Add a new toolbar to a single Writer document or to all Writer documents?
Is it an existing Writer command or your own macro you want to call?
Different code applies depending.
I have multiple template files for different languages, de, en, es, gr, etc.. And the template names would be template_de, template_en, template_es, etc. but with a common code to maintain which will depending on the language, i.e. name of the template file will create different toolbar buttons, as there are different language specific features, e.g. de has ligature or fraktur which en/es do not.
When a new writer document is opened for that template, based on the language (or name of the template), one or more different icon toolbar buttons will dynamically appear and clicking on them own macro code will get executed.
Of course, this could be done by adding all the needed buttons right in the beginning and disabling/deleting them or setting their command URL differently during the start based on the language. But I was looking into the possibility of doing all this dynamically.

Re: Toolbarbutton with icon

Posted: Wed Nov 06, 2024 11:19 am
by Bidouille
Than a template, build an OXT seems to be a better solution.
Did you have a look to code snippet? viewtopic.php?t=108470&hilit=toolbar

Re: Toolbarbutton with icon

Posted: Wed Nov 06, 2024 11:47 am
by nilman70
Bidouille wrote: Wed Nov 06, 2024 11:19 am Than a template, build an OXT seems to be a better solution.
Did you have a look to code snippet? viewtopic.php?t=108470&hilit=toolbar
Not yet, thanks, I will go through the code.

Re: Toolbarbutton with icon

Posted: Wed Nov 06, 2024 5:29 pm
by nilman70
Thanks a lot ~Bidouille, I could get that snippet running with imagebutton, listbox, etc.

Re: [Solved] Toolbar button with icon

Posted: Wed Nov 06, 2024 8:42 pm
by JeJe
That code snippet of mine crashes so I wouldn't use it -- as said in the last post if you want to use a complex control on a toolbar you should instead use a dialog and set its parent on creation to the toolbar panel.

Adding a toolbar and normal buttons though is easier. The attached document shows how to do this for a module eg Writer module/all Writer documents. Run test and it should create a toolbar with buttons. Unfortunately the page I based my code on looks to be no longer available. Doing it for one document instead of a module, from memory which can be faulty I think you may have to do something similar but use the document frame's layoutmanager.

Why not just have the same button for all languages though - and in the macro it calls identify the language and run the relevant code?

Re: [Solved] Toolbar button with icon

Posted: Thu Nov 07, 2024 11:43 am
by nilman70
Thanks ~Jeje, I will go through the code...