Launch Menu
I'm trying to make a menu that on launch displays a list with some programs. The user can then add and delete the programs from the list. Each of the programs must have a link to launch the program.
How would I go about doing this?
Archive: Launch Menu
Launch Menu
I'm trying to make a menu that on launch displays a list with some programs. The user can then add and delete the programs from the list. Each of the programs must have a link to launch the program.
How would I go about doing this?
You can do that with the NOTIFY flag of InstallOptions. See Examples\InstallOptions\testnotify.nsi for an example. It has buttons on the page and it reacts to them.
Thanks kichik!
works perfectly
Now, how would I get this to work with my idea?
What exactly do you mean? Which part of your idea? What doesn't work for you?
Sorry for confusing you.
I'll explain in pictures:
I want it to look like this:
---------------------------------
| [New] [Remove] |
|--------------------------------
|App 1 |[Launch] |
|App 2 |[Launch] |
...
And when someone clicks the New button a popup comes up like this:
---------------------------
|Display Name: [_________]|
|Path:[__________________]|
---------------------------
Which adds it to the list.
In order to get a customized dialog with Display Name/Path, you'd probably have to use some type of plugin. (Unfortunately, I've not seen any such plugin that allows for dual inputs. The closest would be an input box plugin located at http://nsis.sourceforge.net/Dialog****plug-in. )
As for your list of programs, here's an idea:
Using InstallOptions, create a page containing a list box with buttons off the side for 'Launch', 'Add New', and remove. When the user highlights the application and clicks the 'launch' button, the appliction would launch. (Have a look at WinMessages.nsh for a list of supported commands. Info for the commands themselves can be obtained from msdn.microsoft.com.)
However, keep in mind that anything added dynamically to an InstallOptions page doesn't update the INI file at runtime. This means you'd have to read the selected value of the list box using another SendMessage command.
I've attached a screenshot of what the finished page might look like. (created using Eclipe's 'preview' function.)
Please keep in mind that I offer these as suggestions only. I'll leave it up to you to do the hard work! ;)
OK instead of having a dialog
I will use a FileRequest box and a text box under the Add button. Any plugins I might need/want?
and also:
Is it possible to save the dynamically added objects to a INI?
What is WinMessages.nsh for?
Can't I just launch with a variable and Exec?
Thanks for your help
WinMessages.nsh is a header that uses !defines to assign a hex value to a more 'meaningful' description. It's probably easier to see than explain. Open WinMessages.nsh located in ${NSISDIR}\include for an example and brief description. It's uses thoughout the examples included with NSIS.
Here's an example of how I use list boxes:
1. Whenever I add an item to the list, I use a ReadIniStr command to write the same value to the page's INI file (ListItems). Use something like this in the page's leave function:
; read the original value
ReadIniStr $0 '$PLUGINSDIR\io_file.ini' 'Field 8' 'ListItems'
;$0 now contains the original string
; Next step is to add this to the list:
${WordAdd} $0 '|' '+StingToAdd' $R0
; finally, add the full string back to the INI
WriteIniStr '$PLUGINSDIR\swap_names.ini' 'Field 8' 'ListItems' $R0
;Find out what's selected:
ReadIniStr $R1 '$PLUGINSDIR\swap_names.ini' 'Field 8' 'State'
; if nothing is selected, then error:
StrCmp $R1 '' Jump_if_error 0
; get it's index:
SendMessage $R9 ${LB_FINDSTRINGEXACT} -1 "STR:$R1" $R0
; now delete
;(note: $0 is a result var that is not used in this line):
SendMessage $R9 ${LB_DELETESTRING} $R0 0 $0
; and don't forget INI file:
ReadIniStr $R2 '$PLUGINSDIR\swap_names.ini' 'Field 8' 'ListItems'
${WordAdd} $R2 '|' '-$R1' $0
WriteIniStr '$PLUGINSDIR\swap_names.ini' 'Field 8' 'ListItems' $0
Jump_if_error:
MessageBox MB_OK "You didn't select anything to delete."
abort
Thank you
I get an error:
Invalid command: ${WordAdd}
Do I need to define this somewhere or what?
Yes you do.
Its usage is explained in the help files, Appendix E ('Useful Headers').
At the beginnig of your script, you must have the following 2 lines:
!include "WordFunc.nsh"
!insertmacro WordAdd
Thank you
:( it doesn't work :(
OK could someone explain how to adapt http://nsis.sourceforge.net/ListBox_example
???
Thanks for the help so far
Oh I already changed the end part to:
Exec '$R1'
BTW your add section doesn't work with the ListBox example
Also, your sections only change the parts after a recompile.
How would I get it to change after each run
Also, your sections only change the parts after a recompile.I'm not sure what you mean by this.
How would I get it to change after each run
BTW your add section doesn't work with the ListBox exampleLike I said in my original post, my examples were just snippits (cut and paste) of a working install script and that you'd probably have to modify them to fit your needs.
Thanks. What I meant was the ListBox items only changed after a recompile of the script.
When I click [close] it says I must have a entry, but I already have.
This is basically the same as the one I have, but yours doesn't save to the file
My bad... I forgot to include the '.ini' at the end of my file name in the leave function. The correction is posted here.
And I still don't understand your original question. The listbox is supposed to be blank each time. The idea is that the user adds things dynamically at runtime. If this is not what you want, then you'll need to modify the script, the ini file, or both to fit your needs.
I want it to save the items so when the program is started up again, it loads the items
If you want to save the listbox settings, then you'll need to either save the listitems value of Field 6 (using ReadIniStr, or make a copy of the page's ini before you exit the script. (placing it in .onInstSucess would be a good place)
Then, simply modify your main script's .onInit function to return the value (or entire INI file, however you choose to do it) so that the values are there when the page displays.
If you're having trouble, have a look at the docs and examples included with NSIS.
I put in onInit:
FileOpen $0 menu.txt r
FileRead $0 $1
WriteINIStr "menu.ini" 'Field 4' 'ListItems' $1
FileClose $0
ReadINIStr $R0 'menu.ini' 'Field 4' 'ListItems'
FileOpen $0 menu.txt w
FileWrite $0 $R0
FileClose $0
Your idea should work fine. (My other idea involved copying the entire INI from the $PLUGINSDIR in .onInstSucdss and then restoring it later in .onInit. Either way should work fine.)
Just a few points:
1. Remember to use $PLUGINSDIR\menu.ini in the ReadIniStr and WriteIniStr calls since that were it will be at runtime. (Or, you can use MUI_INSTALLOPTIONS_READ and MUI_INSTALLOPTIONS_WRITE, in which case, you'd omit $PLUGINSDIR since it's appended automatically with those 2 macros.)
2. Remember to initialize $PLUGINSDIR in .onInit before you try to write anything. MUI_INSTALLOPTIONS_EXTRACT does this for you, so insert your INI file code (above) AFTER this call and you'll be fine.
3. Remember to read/write the proper fields. I noticed your example was Field 4, but in my posting, it was field 6. Without seeing your INI file, I'm not sure if your was a typo or if you just configured your INI file slightly different than my example.
Yeah, my script is different.
Thanks for your help
Really appreciate it :-)
Is there a way to display say Xname but still have it open x:\b\t.jmd
for example
hmmm... An easy way might be to edit your page's INI file to include a section named Launch. Then in that section, define the name/real-value pairs. Like this:
[LAUNCH]
Xname=x:\b\t.jmd