[Solved] How to program "Don't display this dialog again"

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Avila
Posts: 3
Joined: Fri Sep 23, 2016 6:08 am
Location: Brasil

[Solved] How to program "Don't display this dialog again"

Post by Avila »

Hi!

I'm new to programming, i have a dialog with a label as my main text and a checkbox with label "Don't display this again.".
So I want that when the document is open, it loads the dialog, and if user checks the checkbox, it won't load again.

I'm trying the code below but obviously it doesn't work because when the sub starts, display is set to true.

Code: Select all

Sub demo
Dim display As Boolean
	DialogLibraries.LoadLibrary("Macros")
	dlgDemo = CreateUnoDialog(DialogLibraries.Macros.dlgDemo)
	chbShow = dlgDemo.getControl("chbShow")
	
	display = true
		If display Then
			dlgDemo.Execute()
		End If

		If chbShow.State = 1 Then
			display = false
		End If
End Sub
So, how can I do that?

I would appreciate some help, as I said, I'm new to programming and I'm always getting stuck.
Last edited by Avila on Sun Sep 25, 2016 6:40 pm, edited 2 times in total.
LibreOffice 5.2 on elementaryOS 0.4
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to program "Don't display this dialog again" checkbo

Post by Villeroy »

You've got to store the option state somewhere in some text file, basic module, in the office registry, in the Windows registry or in a document.
I would appreciate some help, as I said, I'm new to programming and I'm always getting stuck.
This (office suite and Basic language) is one of the worst thinkable environments to learn programming.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Avila
Posts: 3
Joined: Fri Sep 23, 2016 6:08 am
Location: Brasil

Re: How to program "Don't display this dialog again" checkbo

Post by Avila »

Villeroy, thank you so much for answering!
You've got to store the option state somewhere in some text file, basic module, in the office registry, in the Windows registry or in a document.
I'll search about this, saving it on a text file and reading it looks the easier way.
Before reading your answer, I realized that I could just remove the "OnLoad" event from "ThisDocument".

When Xraying ThisDocument I could see that it has the method "removeDocumentEventListener ( Listener as com.sun.star.document.XDocumentEventListener )".

I checked OpenOffice API page for the interface XDocumentEventListener (https://www.openoffice.org/api/docs/com ... tener.html), it has one method called documentEventOcurred, and I just don't know what to do with it haha.

Could you point me some tutorial about this? Or maybe explain me how can I remove the event, what do I have to pass as parameter.

It looks better if I don't need to save a txt file for storing the value.
This (office suite and Basic language) is one of the worst thinkable environments to learn programming.
I agree. I'm also learning Java reading "Head First Java", and watching videos of a brazilian teacher on YouTube/cursosemvideo.
I have to learn Basic because I'm already using it in the company I work.

I'm sorry if you don't understand something that I wrote. English isn't my native language.

Thank you for your attention!
LibreOffice 5.2 on elementaryOS 0.4
F3K Total
Volunteer
Posts: 1038
Joined: Fri Dec 16, 2011 8:20 pm

Re: How to program "Don't display this dialog again" checkbo

Post by F3K Total »

Hi,
this code should work for you.

Code: Select all

Sub demo
Dim display As Boolean
       DialogLibraries.LoadLibrary("Macros")
       dlgDemo = CreateUnoDialog(DialogLibraries.Macros.dlgDemo)
       UDP = ThisComponent.DocumentProperties.UserDefinedProperties
       if not UDP.PropertySetInfo.hasPropertyByName("bShowStartDialog")then
           UDP.addProperty("bShowStartDialog",0,True)
       endif
       UDP = ThisComponent.DocumentProperties.UserDefinedProperties
       display = UDP.bShowStartDialog
       If display Then
           dlgDemo.Execute()
           chbShow = dlgDemo.getControl("chbShow")
           If chbShow.State = 1 Then
               UDP.bShowStartDialog = false
           End If
       End If
End Sub
R
  • MMove 1.0.6
  • Extension for easy, exact positioning of shapes, pictures, controls, frames ...
  • my current system
  • Windows 10 AOO, LOLinux Mint AOO, LO
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to program "Don't display this dialog again" checkbo

Post by Villeroy »

F3K Total saves a value in the user defined properties of the current document which is OK if the macro operates on this particular document. See menu:File>Properties>Custome Properties...
Regarding your second question, there are 2 types of events.
1) Script events are stored with the model of your document, dialog or office registry. You can see these events in the GUI and point them easily to some script code.
2) Runtime events (is this the correct term?) are not stored anywhere. They are added and removed by your running program via some method addXXXListener or removeXXXListener.
Most of the time you want to use script events, particulatly when writing macros. Extensions work differently.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Avila
Posts: 3
Joined: Fri Sep 23, 2016 6:08 am
Location: Brasil

Re: How to program "Don't display this dialog again" checkbo

Post by Avila »

F3K Total wrote:this code should work for you.
Worked perfectly!
Villeroy wrote:F3K Total saves a value in the user defined properties of the current document which is OK if the macro operates on this particular document. See menu:File>Properties>Custome Properties...
I didn't know that I could store values this way, Good to know.

Thank you so much guys! Helped me a lot.
LibreOffice 5.2 on elementaryOS 0.4
Post Reply