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

Keyboard macros or custom scripts

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

Postby Avila » Fri Sep 23, 2016 6:47 am

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   Expand viewCollapse view
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
Avila
 
Posts: 3
Joined: Fri Sep 23, 2016 6:08 am
Location: Brasil

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

Postby Villeroy » Sat Sep 24, 2016 7:41 pm

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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 25767
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby Avila » Sun Sep 25, 2016 12:52 am

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
Avila
 
Posts: 3
Joined: Fri Sep 23, 2016 6:08 am
Location: Brasil

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

Postby F3K Total » Sun Sep 25, 2016 10:08 am

Hi,
this code should work for you.
Code: Select all   Expand viewCollapse view
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 7 OOo, AOO, LOLinux Mint OOo, AOO, LO
F3K Total
Volunteer
 
Posts: 896
Joined: Fri Dec 16, 2011 8:20 pm

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

Postby Villeroy » Sun Sep 25, 2016 10:35 am

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, OpenOffice 4.x & LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 25767
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby Avila » Sun Sep 25, 2016 6:39 pm

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
Avila
 
Posts: 3
Joined: Fri Sep 23, 2016 6:08 am
Location: Brasil


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 7 guests