Archive: File page similar to directory page in mui2?


File page similar to directory page in mui2?
I wonder if there is a ready-to-use file page just like mui2's directory page but accepting files instead of directories (possibly plus a file extension list). I would implement it using nsDialogs but I think the problem is so common that there are probably several solutions already. Maybe I just didn't use the right search terms to find them?


nope - it's also not all that common in an installer; last I've seen one was for a multi-thousand dollar program that let the user download big fat maintenance update files -or- point to such a file locally (e.g. if provided by the reseller on a separate disc).

But, as you mentioned, it's fairly simple to whip one up yourself with nsDialogs - can just take the template page one for the directory out of the NSIS\Contrib\ModernUI...something folder and adjust that, even :)


Ok, I'm now in the process of implementing my own, hope I can post some results soon


So here it is, layout equals the mui2 directory page. Comments welcome, e.g. on my use of some uniquely created ID to enable multiple use of the page (probably there is a better way?), or how to make the groupbox text useable in multiple languages, ideas for providing "save"-version as well, or JUST GENERALLY NOT GOOD STYLE comments are welcome ;-)


/*

NSIS Modern User Interface 2 - Extensions
Generic file page
Usage:
Var /GLOBAL filename

!define MUI_FILEPAGE_HEADER_TEXT "Title" ; mandatory as a file page should require some specific description
!define MUI_FILEPAGE_HEADER_SUBTEXT "Subtitle" ; mandatory as a file page should require some specific description
!define MUI_FILEPAGE_TEXT_TOP "Description" ; optional
!insertmacro MUI_PAGE_FILE "filename" "Extension1 description|extension1|Extension2 description|extension2|..." ; attention: use "filename" not "$filename" !

*/

Var MUI_FILEPAGE_FILEREQUESTHANDLE
Var MUI_FILEPAGE_BROWSEBUTTONHANDLE

;--------------------------------
;Page declaration

!macro MUI_PAGE_FILE FILENAME EXTENSIONS
!define MY_ID ${__LINE__}
!insertmacro MUI_PAGE_FILE_MACROS "${MY_ID}" "${FILENAME}" "${EXTENSIONS}"
!verbose push
!verbose ${MUI_VERBOSE}
Page custom MUI_CUSTOMPAGE_FILE_${MY_ID} MUI_CUSTOMPAGE_FILE_LEAVE_${MY_ID}

!verbose pop
!undef MY_ID
!macroend

!macro MUI_PAGE_FILE_MACROS ID FILENAME EXTENSIONS
Function MUI_CUSTOMPAGE_FILE_${ID}

nsDialogs::Create 1018
Pop $0

!insertmacro MUI_HEADER_TEXT "${MUI_FILEPAGE_HEADER_TEXT}" "${MUI_FILEPAGE_HEADER_SUBTEXT}"
!ifndef MUI_FILEPAGE_TEXT_TOP
!define MUI_FILEPAGE_TEXT_TOP ""
!endif

${NSD_CreateLabel} 0u 0u 100% 60u "${MUI_FILEPAGE_TEXT_TOP}"

${NSD_CreateGroupBox} 0u 70u 300u 35u "Selected File"
${NSD_CreateFileRequest} 10u 85u 210u 12u "$${FILENAME}"
Pop $MUI_FILEPAGE_FILEREQUESTHANDLE

${NSD_CreateBrowseButton} 228u 83u 60u 15u "$(^BrowseBtn)"
Pop $MUI_FILEPAGE_BROWSEBUTTONHANDLE
${NSD_OnClick} $MUI_FILEPAGE_BROWSEBUTTONHANDLE MUI_CUSTOMPAGE_FILE_BROWSE_${ID}

nsDialogs::Show

!undef MUI_FILEPAGE_HEADER_TEXT
!undef MUI_FILEPAGE_HEADER_SUBTEXT
!undef MUI_FILEPAGE_TEXT_TOP

FunctionEnd

Function MUI_CUSTOMPAGE_FILE_BROWSE_${ID}
nsDialogs::SelectFileDialog "open" "$${FILENAME}" "${EXTENSIONS}"
Pop $0
${If} $0 != ""
${NSD_SetText} $MUI_FILEPAGE_FILEREQUESTHANDLE $0
${EndIf}
FunctionEnd

Function MUI_CUSTOMPAGE_FILE_LEAVE_${ID}
Call READ_FILENAME_${ID}
FunctionEnd

Function READ_FILENAME_${ID}
${NSD_GetText} $MUI_FILEPAGE_FILEREQUESTHANDLE $${Filename}
FunctionEnd

!macroend

Please use http://nsis.pastebin.com/ or attachments to share large amounts of code.


Ok, I've put it to http://nsis.pastebin.com/sAtyhgTY
But I can't edit my original post anymore. I'll keep it in mind for future posts.