Modify

Opened 16 years ago

Closed 13 years ago

#1533 closed Feature Request (Rejected)

FileSaveDialog/FileOpenDialog return selected filter type

Reported by: anonymous Owned by: J-Paul Mesnage
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description

As of now there is no way of telling what filter type was selected. I propose setting that information in the @extended macro.

example.

_Filesave()

Func _Filesave()
	Local $sFile, $sType

	$sFile = FileSaveDialog('Save file as...', @WorkingDir, "Text file (*.txt)|CSV file (*.csv)|HTML file (*.html)|Any files (*.*)")

	If Not @error Then

		; FileSaveDialog/FileOpenDialog could set @extended with the selected filter type index
		Switch @extended
			Case 0
				$sType = "Text file"
			Case 1
				$sType = "CSV file"
			Case 2
				$sType = "HTML file"
			Case 3
				$sType = "Any file"
		EndSwitch

		MsgBox(0, "You saved this file", "Filename: " & $sFile & @LF & "Type: " & $sType )


	EndIf
EndFunc

Attachments (0)

Change History (7)

comment:1 by TicketCleanup, 16 years ago

Version: 3.3.6.0

Automatic ticket cleanup.

comment:2 by MrCreatoR <mscreator@…>, 16 years ago

Not sure if it helps, but here is a custom API function that can retrieve selected filter (among other extra options):

$sFileOpen = _FileOpenDialog("Open File", @ScriptDir, "All Files|*.*|Scripts|*.au3", 3, "ScriptName", "au3", 2)
If Not @error Then MsgBox(64, "Info", "Selected file: " & $sFileOpen & @CRLF & "Selected Filter: " & @extended)

Func _FileOpenDialog($sTitle, $sInitDir, $sFilter = 'All (*.*)|*.*', $iOpt = 0, $sDefFile = '', $sDefExt = '', $iDefFilter = 1, $hWnd = 0)
	Local $iFileLen = 65536 ; Max chars in returned string
	
	; API flags prepare
	Local $iFlag = BitOR( _
			BitShift(BitAND($iOpt, 1), -12), BitShift(BitAND($iOpt, 2), -10), BitShift(BitAND($iOpt, 4), -7), _
			BitShift(BitAND($iOpt, 8), -10), BitShift(BitAND($iOpt, 4), -17))
	
	; Filter string to array convertion
	If Not StringInStr($sFilter, '|') Then $sFilter &= '|*.*'
	$sFilter = StringRegExpReplace($sFilter, '|+', '|')
	
	Local $asFLines = StringSplit($sFilter, '|')
	Local $i, $suFilter = ''

	For $i = 1 To $asFLines[0] Step 2
		If $i < $asFLines[0] Then _
				$suFilter &= 'wchar[' & StringLen($asFLines[$i]) + 1 & '];wchar[' & StringLen($asFLines[$i + 1]) + 1 & '];'
	Next
	
	; Create API structures
	Local $uOFN = DllStructCreate('dword;int;int;ptr;ptr;dword;dword;ptr;dword' & _
			';ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;ptr;dword;dword')
	Local $usTitle = DllStructCreate('wchar[' & StringLen($sTitle) + 1 & ']')
	Local $usInitDir = DllStructCreate('wchar[' & StringLen($sInitDir) + 1 & ']')
	Local $usFilter = DllStructCreate($suFilter & 'wchar')
	Local $usFile = DllStructCreate('wchar[' & $iFileLen & ']')
	Local $usExtn = DllStructCreate('wchar[' & StringLen($sDefExt) + 1 & ']')
	
	For $i = 1 To $asFLines[0]
		DllStructSetData($usFilter, $i, $asFLines[$i])
	Next
	
	; Set Data of API structures
	DllStructSetData($usTitle, 1, $sTitle)
	DllStructSetData($usInitDir, 1, $sInitDir)
	DllStructSetData($usFile, 1, $sDefFile)
	DllStructSetData($usExtn, 1, $sDefExt)
	DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))
	DllStructSetData($uOFN, 2, $hWnd)
	DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))
	DllStructSetData($uOFN, 7, $iDefFilter)
	DllStructSetData($uOFN, 8, DllStructGetPtr($usFile))
	DllStructSetData($uOFN, 9, $iFileLen)
	DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))
	DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))
	DllStructSetData($uOFN, 14, $iFlag)
	DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))
	DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))
	
	; Call API function
	Local $aRet = DllCall('comdlg32.dll', 'int', 'GetOpenFileNameW', 'ptr', DllStructGetPtr($uOFN))
	If Not IsArray($aRet) Or Not $aRet[0] Then Return SetError(1, 0, "")
	
	If BitAND($iOpt, 4) Then
		$i = 1
		
		While 1
			If Binary(DllStructGetData($usFile, 1, $i)) = 0 Then
				If Binary(DllStructGetData($usFile, 1, $i + 1)) = 0 Then ExitLoop
				DllStructSetData($usFile, 1, '|', $i)
			EndIf
			
			$i += 1
		WEnd
	EndIf
	
	Local $sRet = StringStripWS(DllStructGetData($usFile, 1), 3)
	Return SetExtended(DllStructGetData($uOFN, 7), $sRet)
EndFunc

comment:3 by J-Paul Mesnage, 16 years ago

Milestone: 3.3.7.0
Owner: set to J-Paul Mesnage
Resolution: Completed
Status: newclosed

Added by revision [5803] in version: 3.3.7.0

comment:4 by MrCreatoR <mscreator@…>, 15 years ago

Is this really completed?
In what version?

comment:5 by J-Paul Mesnage, 15 years ago

Resolution: Completed
Status: closedreopened

Jon revert what I did without reopening the ticket

comment:6 by TicketCleanup, 15 years ago

Milestone: 3.3.7.0

Automatic ticket cleanup.

comment:7 by Jon, 13 years ago

Resolution: Rejected
Status: reopenedclosed

Modify Ticket

Action
as closed The owner will remain J-Paul Mesnage.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.