[Gambas-user] Settings file - preserver comments

Bruce Steers bsteers4 at gmail.com
Tue Feb 9 20:31:39 CET 2021

2 Corrections...

1:  *SetSlotTitle(Title As String)      *should be  *SetSlotTitle(Slot As
String, Title As String)*

2: when testing i commented out line 155 of Settings.class to force a save
and forgot to un-comment it before posting.
*'  If Not $bModify Then Return*
So just uncomment out that line on the last attached version or settings
will always save even if no changes.

Or use the updated version attached to this mail with a slightly better
test gui.
*SetSlotTitle(Slot,Title)* , *Title* is now Optional, if omitted it deletes
the comment.

Settings.Reload() will not refresh Settings.Title if it already exists as
it thinks it's been explicitly set.
 (just call *Settings.Title = ""* before running Settings.Reload() if you
want it to)

I'll leave it with you Chris to get it working just how you want it now :)

All the best

On Tue, 9 Feb 2021 at 06:54, Bruce Steers <bsteers4 at gmail.com> wrote:

> 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/f6790959/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AltSettings.zip
Type: application/zip
Size: 29400 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210209/f6790959/attachment-0001.zip>

More information about the User mailing list