EgtExecutor :
aggiunta la funzione Lua EgtDirectoryDialog per la scelta di un direttorio.
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include "/EgtDev/Include/EgtStringConverter.h"
|
||||
#include "Windowsx.h"
|
||||
#include "shlobj.h"
|
||||
|
||||
using namespace std ;
|
||||
|
||||
@@ -756,6 +757,67 @@ LuaCompareFilesLastWriteTime( lua_State* L)
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
int
|
||||
CALLBACK DirectoryBoxProc( HWND hwndDlg, UINT uMsg, LPARAM lParam, LPARAM lpData)
|
||||
{
|
||||
if ( uMsg == BFFM_INITIALIZED)
|
||||
SendMessage( hwndDlg, BFFM_SETSELECTION, TRUE, lpData) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
static int
|
||||
LuaDirectoryDialog( lua_State* L)
|
||||
{
|
||||
// 2 parametri : sText, sDir
|
||||
string sText ;
|
||||
LuaCheckParam( L, 1, sText)
|
||||
string sDir ;
|
||||
LuaCheckParam( L, 2, sDir)
|
||||
LuaClearStack( L) ;
|
||||
// se abilitata UI, emetto la finestra di dialogo
|
||||
if ( ExeGetEnableUI()) {
|
||||
// Converto i parametri nel formato wide
|
||||
AtoWEX<MAX_PATH> wsText( sText.c_str()) ;
|
||||
AtoWEX<MAX_PATH> wsDirName( sDir.c_str()) ;
|
||||
// Converto L'/' in L'\\' nel nome directory proposto
|
||||
for ( wchar_t* pC = wsDirName.m_psz ; *pC != L'\0' ; ++ pC) {
|
||||
if ( *pC == L'/')
|
||||
*pC = L'\\' ;
|
||||
}
|
||||
// Riempio la struttura dati per il dialogo
|
||||
BROWSEINFO bi = { 0} ;
|
||||
bi.hwndOwner = ExeGetMainWindowHandle() ;
|
||||
bi.lpszTitle = LPWSTR( wsText) ;
|
||||
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI ;
|
||||
bi.lpfn = DirectoryBoxProc ;
|
||||
bi.lParam = (LPARAM) LPWSTR( wsDirName) ;
|
||||
// Visualizzo il dialogo
|
||||
LPITEMIDLIST pIdl = SHBrowseForFolder( &bi) ;
|
||||
if ( pIdl != NULL) {
|
||||
// recupero la path della directory
|
||||
WCHAR wPath[MAX_PATH] ;
|
||||
if ( SHGetPathFromIDList( pIdl, wPath) != FALSE)
|
||||
LuaSetParam( L, wstrztoA( wPath)) ;
|
||||
else
|
||||
LuaSetParam( L) ;
|
||||
// free memory used
|
||||
IMalloc* pImalloc = NULL ;
|
||||
if ( SUCCEEDED( SHGetMalloc( &pImalloc))) {
|
||||
pImalloc->Free( pIdl) ;
|
||||
pImalloc->Release() ;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
LuaSetParam( L) ;
|
||||
}
|
||||
else
|
||||
LuaSetParam( L) ;
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
static int
|
||||
LuaExistsDirectory( lua_State* L)
|
||||
@@ -1287,6 +1349,7 @@ LuaInstallGeneral( LuaMgr& luaMgr)
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtEraseFile", LuaEraseFile) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtFindAllFiles", LuaFindAllFiles) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtCompareFilesLastWriteTime", LuaCompareFilesLastWriteTime) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtDirectoryDialog", LuaDirectoryDialog) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtExistsDirectory", LuaExistsDirectory) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtCreateDirectory", LuaCreateDirectory) ;
|
||||
bOk = bOk && luaMgr.RegisterFunction( "EgtEmptyDirectory", LuaEmptyDirectory) ;
|
||||
|
||||
Reference in New Issue
Block a user