Page 1 of 1

Relative URL in a dialog

Posted: Fri Nov 03, 2017 9:52 pm
by Lucrecia
My dialog has 2 buttons with images and they are saved in the folder "images" of my extension.
In my pc the dialog shows the two images in their respective buttons but when executing the extension in another pc the images are lost.
Please can you tell me how to change the absolute reference of the image so that my extension works well on other PCs.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="Dialog1" dlg:left="159" dlg:top="91" dlg:width="80" dlg:height="53" dlg:help-text="&0.Dialog1.HelpText" dlg:closeable="true" dlg:moveable="true" dlg:title="&1.Dialog1.Title">
<dlg:bulletinboard>

     <dlg:button dlg:id="CommandButton1" dlg:tab-index="0" dlg:left="8" dlg:top="3" dlg:width="28" dlg:height="28" dlg:value="&15.Dialog1.CommandButton1.Label" dlg:image-src="file:///C:/Users/Lucrecia/Desktop/plug%20final%20lucre/DropCaps/images/DropCaps.png">
      <script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.script:DropCaps.DropCaps.setDropCaps?language=Basic&location=application" script:language="Script"/>
     </dlg:button>

     <dlg:button dlg:id="CommandButton2" dlg:tab-index="1" dlg:left="41" dlg:top="3" dlg:width="28" dlg:height="28" dlg:value="&16.Dialog1.CommandButton2.Label" dlg:image-src="file:///C:/Users/Lucrecia/Desktop/plug%20final%20lucre/DropCaps/images/NoneDropCaps.png">
      <script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.script:DropCaps.DropCaps.rmvDropCaps?language=Basic&location=application" script:language="Script"/>
     </dlg:button>

     <dlg:button dlg:id="CommandButton3" dlg:tab-index="3" dlg:left="15" dlg:top="38" dlg:width="55" dlg:height="14" dlg:help-text="&111.Dialog1.CommandButton3.HelpText" dlg:value="Cancel">
      <script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.script:DropCaps.DropCaps.Cancelar_Dialogo?language=Basic&location=application" script:language="Script"/>
     </dlg:button>
</dlg:bulletinboard>
</dlg:window>
here my full extension
https://drive.google.com/open?id=0B_PjB ... Xg1VGZfMzQ

Re: Relative URL in a dialog

Posted: Sat Nov 04, 2017 9:59 pm
by musikai
Hi,
I'm also new to this but after reading some documents here are some thoughts:
Files that are to be used have to be declared in the Manifest.xml (in META-INF-Folder). There the Addons.xcu is also declared.
As your Addons.xcu contains info about images in "image" path they are also copied to the extension install path.
This install path will be unique on every machine. So to use an image from there you have to find out the path.
There is a macro to find out the path of your extension by its name: the extensionidentifier that you can read in description.xml. On your extension it reads "org.broffice.DropCaps"
Here is the macro to find the install path (with your ExtensionIdentifier):

Code: Select all

function GetExtensionInstPfad
Dim sService as string, sExtensionIdentifier as string, sPackageLocation as string
dim oPackageInfoProvider as variant
sExtensionIdentifier = "org.broffice.DropCaps"
sService = "com.sun.star.deployment.PackageInformationProvider"
oPackageInfoProvider = GetDefaultContext.getValueByName("/singletons/" & sService)
sPackageLocation = oPackageInfoProvider.getPackageLocation(sExtensionIdentifier)
GetExtensionInstPfad = sPackageLocation
End function
(To get a path from this function the extension has to be installed.)

For the images in your dialog you can't statically set them via the dialog editor but have to assign them on runtime.
Here you can find some code how to do this:
viewtopic.php?f=20&t=67700
In that thread there is mentioned another elegant way to create, save and use images directly in the basic code.

I haven't tested all stuff here, but hope it might be useful to you.