mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-27 03:46:17 -06:00
System File Chooser: fixes for Windows
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
|
||||
/**
|
||||
* @author Karl Tauber
|
||||
* @since 3.6
|
||||
*/
|
||||
|
||||
// see FlatWndProc.cpp
|
||||
@@ -79,7 +80,7 @@ public:
|
||||
//---- class FilterSpec -------------------------------------------------------
|
||||
|
||||
class FilterSpec {
|
||||
JNIEnv* env;
|
||||
JNIEnv* env = NULL;
|
||||
jstring* jnames = NULL;
|
||||
jstring* jspecs = NULL;
|
||||
|
||||
@@ -89,6 +90,9 @@ public:
|
||||
|
||||
public:
|
||||
FilterSpec( JNIEnv* _env, jobjectArray fileTypes ) {
|
||||
if( fileTypes == NULL )
|
||||
return;
|
||||
|
||||
env = _env;
|
||||
count = env->GetArrayLength( fileTypes ) / 2;
|
||||
if( count <= 0 )
|
||||
@@ -165,7 +169,13 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
|
||||
if( !coInitializer.initialized )
|
||||
return NULL;
|
||||
|
||||
HWND hwndOwner = getWindowHandle( env, owner );
|
||||
// handle limitations (without this, some Win32 method fails and this method returns NULL)
|
||||
if( (optionsSet & FOS_PICKFOLDERS) != 0 ) {
|
||||
if( open )
|
||||
fileTypes = NULL; // no filter allowed for picking folders
|
||||
else
|
||||
optionsSet &= ~FOS_PICKFOLDERS; // not allowed for save dialog
|
||||
}
|
||||
|
||||
// convert Java strings to C strings
|
||||
AutoReleaseString ctitle( env, title );
|
||||
@@ -185,6 +195,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
|
||||
NULL, CLSCTX_INPROC_SERVER, open ? IID_IFileOpenDialog : IID_IFileSaveDialog,
|
||||
reinterpret_cast<LPVOID*>( &dialog ) ) );
|
||||
|
||||
// set title, etc.
|
||||
if( ctitle != NULL )
|
||||
CHECK_HRESULT( dialog->SetTitle( ctitle ) );
|
||||
if( cokButtonLabel != NULL )
|
||||
@@ -202,23 +213,26 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
|
||||
if( cdefaultExtension != NULL )
|
||||
CHECK_HRESULT( dialog->SetDefaultExtension( cdefaultExtension ) );
|
||||
|
||||
// set options
|
||||
FILEOPENDIALOGOPTIONS existingOptions;
|
||||
CHECK_HRESULT( dialog->GetOptions( &existingOptions ) );
|
||||
CHECK_HRESULT( dialog->SetOptions ( (existingOptions & ~optionsClear) | optionsSet ) );
|
||||
|
||||
if( specs.count > 0 ) {
|
||||
// initialize filter
|
||||
if( specs.count > 0 && (optionsSet & FOS_PICKFOLDERS) == 0 ) {
|
||||
CHECK_HRESULT( dialog->SetFileTypes( specs.count, specs.specs ) );
|
||||
if( fileTypeIndex > 0 )
|
||||
CHECK_HRESULT( dialog->SetFileTypeIndex( min( fileTypeIndex + 1, specs.count ) ) );
|
||||
}
|
||||
|
||||
// show dialog
|
||||
HWND hwndOwner = (owner != NULL) ? getWindowHandle( env, owner ) : NULL;
|
||||
HRESULT hr = dialog->Show( hwndOwner );
|
||||
if( hr == HRESULT_FROM_WIN32(ERROR_CANCELLED) )
|
||||
return newJavaStringArray( env, 0 );
|
||||
CHECK_HRESULT( hr );
|
||||
|
||||
// convert URLs to Java string array
|
||||
// convert shell items to Java string array
|
||||
if( open ) {
|
||||
AutoReleasePtr<IShellItemArray> shellItems;
|
||||
DWORD count;
|
||||
@@ -235,7 +249,7 @@ JNIEXPORT jobjectArray JNICALL Java_com_formdev_flatlaf_ui_FlatNativeWindowsLibr
|
||||
jstring jpath = newJavaString( env, path );
|
||||
CoTaskMemFree( path );
|
||||
|
||||
env->SetObjectArrayElement( array, 0, jpath );
|
||||
env->SetObjectArrayElement( array, i, jpath );
|
||||
env->DeleteLocalRef( jpath );
|
||||
}
|
||||
return array;
|
||||
|
||||
Reference in New Issue
Block a user