getOption behavior

Next
 From:  dinos
5928.1 
Hi Michael,
i've had some free time and decided to have a go at a script that i'd love to have.

I'll need to use getOption to read an moi.ini option, preferably from memory.

I've run a few tests and the following works as expected:
moi.command.setOption('din_test','test');
moi.ui.commandUI.alert( moi.command.getOption('din_test') );

moi.ui.commandUI.alert( moi.command.getOption('NonRepeatingCommands', true));


BUT these ones do not:
moi.ui.commandUI.alert( moi.command.getOption('NonRepeatingCommands'));
moi.ui.commandUI.alert( moi.command.getOption('Backspace')); (or any other option outside [Commands])
moi.ui.commandUI.alert( moi.command.getOption('Backspace', true));

Is that the intended behavior of getOption?
Is there any way to read from javascript a whole block of options, for example all the [Shortcut Keys] ?

Also, thanks for DisableFileCaching :-) Makes script development a lot easier!
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
5928.2 In reply to 5928.1 
Hi dinos - the function moi.command.setOption and getOption are more for saving one single command's own data, not for reading general data from any section of the .ini file. When you use the option to read or write the option to the .ini file, they end up in the [Commands] section of the ini file, there isn't any way with this API to read other sections of the .ini file.


> moi.ui.commandUI.alert( moi.command.getOption('NonRepeatingCommands', true));

This one works just because that one particular setting also happens to be stored in the [Commands] section as well.


> Is that the intended behavior of getOption?

Yup, it's really meant as a mechanism for a command to be able to save and restore it's own private settings specific to that command with optionally persisting across sessions by also storing it in the .ini file if that last parameter is set to do that. It is pretty unusual behavior for a command to have any settings persist between sessions though, I think all default regular commands only save settings within the current session.


> Is there any way to read from javascript a whole block of options, for example all the [Shortcut Keys] ?

There is nothing directly built in for accessing blocks of the .ini file, but you could use the general purpose text file reader for that.

Something like:
code:
var file = moi.filesystem.openFileStream( moi.settings.getIniPath(), 'r' );

while ( !file.AtEOF )
{
     // Read one line of the text file into a string value.
     var text = file.readLine();

     // Do something based on what the line contains...
}

file.close();


But you should also be careful about directly accessing the .ini file with script code - it won't work for example to try and write to the ini file directly because stuff you write to it will then get overwritten when MoI writes its own regular stuff there on shutdown.

The shortcut key settings happen to be one area that uses a special table editor which is not HTML based and so there is not currently any script accessible method for accessing them though.



> Also, thanks for DisableFileCaching :-) Makes script development a lot easier!

Great, I was hoping it would be useful!

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  dinos
5928.3 In reply to 5928.2 
Thanks Michael.

I only need to read the options, not write, so moi.filesystem.openFileStream is enough for what i have in mind.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All