Add All open folder & some extra as contex menu in SaveFileDlg & OpenFileDlg of SciTE
Adds the ability to quickly select one of the open folders or one of those you use regularly.
as a destination to save the file
To test, open a few folders in the background and then select >File >Save As... to SciTE
First add your favorite folders on line 58, 59,
you can put more, but above line 60 $OpenFolders[0][0] = UBound($OpenFolders) - 1
The number on the front "002|D:\i\Pro\.AutoIT" doesn't matter, but need to have it
Thanks to @Lepes suggestion for _WinApi_GetParent function, so that only the SciTE dialogue is caught.
; https://www.autoitscript.com/forum/topic/210165-active_savefiledlg/
;----------------------------------------------------------------------------------------
; Title...........: Active_SaveFileDlg.au3
; Description.....: Add All open folder & some extra as contex menu in SaveFileDlg & OpenFileDlg of SciTE
; AutoIt Version..: 3.3.16.1 Author: ioa747
;----------------------------------------------------------------------------------------
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
;~ #NoTrayIcon
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <WinAPISysWin.au3>
#include <Misc.au3>
#include <Array.au3>
Global $hGUI, $hDlgWnd, $hScite
If _Singleton(@ScriptName, 1) = 0 Then Exit ; to avoid running it multiple times!
While WinExists("[CLASS:SciTEWindow]")
$hScite = WinGetHandle("[CLASS:SciTEWindow]")
If WinExists("[TITLE:Save File; CLASS:#32770]") Then ; ------------ Save File
$hDlgWnd = WinGetHandle("[TITLE:Save File; CLASS:#32770]")
_CallFoldersGUI("Save")
ElseIf WinExists("[TITLE:Open File; CLASS:#32770]") Then ; -------- Open File
$hDlgWnd = WinGetHandle("[TITLE:Open File; CLASS:#32770]")
_CallFoldersGUI("Open")
EndIf
Sleep(500)
WEnd
Exit
;----------------------------------------------------------------------------------------
Func _CallFoldersGUI($sDlgTitle)
If _WinAPI_GetParent($hDlgWnd) = $hScite Then
_FoldersGUI($sDlgTitle)
While WinActive($hDlgWnd) ; Loop While win exits.
Sleep(500)
WEnd
GUIDelete($hGUI)
Else
Return
EndIf
EndFunc ;==>_CallFoldersGUI
;----------------------------------------------------------------------------------------
Func _FoldersGUI($sDlgTitle)
$hGUI = GUICreate("MyGUI", 40, 40, -50, -50, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_NOACTIVATE), $hDlgWnd)
Local $idDummy = GUICtrlCreateDummy()
Local $idButton = GUICtrlCreateButton("contex button", 0, 0, 40, 40, $BS_ICON)
GUICtrlSetImage(-1, "shell32.dll", -68)
Local $idContext = GUICtrlCreateContextMenu($idButton)
Local $OpenFolders = _EnumAllOpenFolder()
; Add some extra folder (the numbers on the front don't matter)
_ArrayInsert($OpenFolders, 1, "000|") ; separator
_ArrayInsert($OpenFolders, 1, "001|D:\i\Pro\.AutoIT\_Test\005_Test") ; * <--------- Fav1 folder (get one of your own)
_ArrayInsert($OpenFolders, 1, "002|D:\i\Pro\.AutoIT") ; * <------------------------ Fav2 folder (get one of your own)
$OpenFolders[0][0] = UBound($OpenFolders) - 1
For $i = 1 To $OpenFolders[0][0]
GUICtrlCreateMenuItem($OpenFolders[$i][1], $idContext)
Next
Local $Wpos = WinGetPos($hDlgWnd)
;ConsoleWrite("$Wpos " & $Wpos[0] & "; " & $Wpos[1] & "; " & $Wpos[2] & "; " & $Wpos[3] & @CRLF)
Local $aOfset[2]
;$aOfset[0]=X ;$aOfset[1]=Y
If $sDlgTitle = "Save" Then
$aOfset[0] = 270
$aOfset[1] = 55
ElseIf $sDlgTitle = "Open" Then
$aOfset[0] = 270
$aOfset[1] = 50
EndIf
GUISetState(@SW_SHOW, $hGUI)
WinMove($hGUI, "", $Wpos[0] + $Wpos[2] - $aOfset[0], $Wpos[1] + $Wpos[3] - $aOfset[1])
Local $idMsg
While WinExists($hDlgWnd)
$Wpos = WinGetPos($hDlgWnd)
WinMove($hGUI, "", $Wpos[0] + $Wpos[2] - $aOfset[0], $Wpos[1] + $Wpos[3] - $aOfset[1])
$idMsg = GUIGetMsg()
Switch $idMsg
Case 6 To $OpenFolders[0][0] + 6
;ConsoleWrite($OpenFolders[$idMsg - 5][1] & @CRLF)
WinActivate($hDlgWnd)
If $sDlgTitle = "Save" Then
ControlCommand($hDlgWnd, "", "ToolbarWindow324", "SendCommandID", 1280)
ControlSetText($hDlgWnd, "", "Edit2", $OpenFolders[$idMsg - 5][1])
ControlSend($hDlgWnd, "", "Edit2", "{ENTER}")
ElseIf $sDlgTitle = "Open" Then
ControlCommand($hDlgWnd, "", "ToolbarWindow323", "SendCommandID", 1280)
ControlSetText($hDlgWnd, "", "Edit2", $OpenFolders[$idMsg - 5][1])
ControlSend($hDlgWnd, "", "Edit2", "{ENTER}")
EndIf
Case $idButton
GUICtrlSendToDummy($idDummy)
Case $idDummy
MouseClick("right")
;ExitLoop
EndSwitch
Sleep(10)
WEnd
GUIDelete($hGUI)
Return
EndFunc ;==>_FoldersGUI
;----------------------------------------------------------------------------------------
Func _EnumAllOpenFolder() ; enumerating all open folders
Local $oShell = ObjCreate("Shell.Application")
Local $sPath, $index = 0
Local $aArray[$oShell.Windows.Count + 1][2] = [["hWnd", "Path"]]
For $oWin In $oShell.Windows
$index += 1
$aArray[0][0] = $index
$sPath = StringTrimLeft($oWin.LocationURL, 8) ; trim 'file:///'
$sPath = StringReplace($sPath, "/", "\")
$sPath = _UnicodeURLDecode($sPath)
$aArray[$index][0] = HWnd($oWin.HWND)
$aArray[$index][1] = $sPath
Next
Return $aArray
EndFunc ;==>_EnumAllOpenFolder
;----------------------------------------------------------------------------------------
Func _UnicodeURLDecode($toDecode)
Local $strChar = "", $iOne, $iTwo
Local $aryHex = StringSplit($toDecode, "")
For $i = 1 To $aryHex[0]
If $aryHex[$i] = "%" Then
$i = $i + 1
$iOne = $aryHex[$i]
$i = $i + 1
$iTwo = $aryHex[$i]
$strChar = $strChar & Chr(Dec($iOne & $iTwo))
Else
$strChar = $strChar & $aryHex[$i]
EndIf
Next
Local $Process = StringToBinary($strChar)
Local $DecodedString = BinaryToString($Process, 4)
Return $DecodedString
EndFunc ;==>_UnicodeURLDecode
;----------------------------------------------------------------------------------------