[Gambas-user] Settings file - preserver comments

Bruce Steers bsteers4 at gmail.com
Tue Feb 9 07:54:41 CET 2021


On Mon, 8 Feb 2021 at 07:42, pf <petterfilip at gmail.com> wrote:

> Hi
>
>
> I use a settings file but when i write to it the comments line made with
> ; or #  at the start of the line dissapears on update of any value.
>
> I would like to keep comments if the settings file is opened in a
> texteditor so the user can get some tips on the values in the file.
>
>
> Regards
>
> Chris
>

Is this what you want Chris?

Attached is an alternative version of the Settings.class modified in such a
way that Benoit doesn't have to ;)

To test it just load the project into gambas and press some buttons and see
the file in home/.config/gambas3/AltSettings.conf
the test app shows the settings on start and sets some settings/comments
and closes when pressing a button.

To use it copy the *Settings* folder from the *.src/* folder of the
attached project to the *.src/* folder of your project.
Then unselect *gb.settings* from you project properties. that's all.

What I have done is something you can also easily do.
And it can be done with many number of other gambas components if they do
not do quite what you want.
I took the source files from the comp/gb.settings/.src/ folder of the
gambas source package.

I then made the following changes to it...

A new read/write property
*Settings.Title = "some text"* can be used anytime to set the 1st line
comment of the file (this method ALWAYS saves)

There are 3 new commands..
*GetSlotTitle(slot) As String  '* returns the comment for any slot if one
exists
*SetSlotTitle(Title As String)  ' *saves a comment for a slot below the
slot name if the slot name exists
and
*SetTitleIfChanges(title As String) ' *Sets the main 1st line comment but
will only save if other settings are modified.

Maybe this is not quite what you want but at least you can see how easy it
is to import a gambas component and modify it to suit your own needs.

It is one of the great things about gambas, so much of it is written in
gambas and quite easy to import and customise to your own needs.

Best of luck
BruceS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210209/1ec1d6d2/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AltSettings.zip
Type: application/zip
Size: 40295 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210209/1ec1d6d2/attachment-0001.zip>


More information about the User mailing list