package com.sun.glass.ui.gtk;

import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import com.sun.glass.ui.Window;

public class GtkCommonDialogs {
 
    private static native String[] _showFileChooser(
                                            long parent,
                                            String folder,
                                            String title,
                                            int type,
                                            boolean multipleMode,
                                            ExtensionFilter[] extensionFilters);
    
    private static native String _showFolderChooser(long parent,
                                                    String folder,
                                                    String title);
    
    static String[] showFileChooser(Window owner, 
                                    String folder, 
                                    String title, 
                                    int type, 
                                    boolean multipleMode, 
                                    ExtensionFilter[] extensionFilters) {
        
        if (owner != null) owner.setEnabled(false);
        String[] results = _showFileChooser(owner == null? 0L : owner.getNativeHandle(),
                folder, title, type, multipleMode, extensionFilters);  
        if (owner != null) owner.setEnabled(true);        
        return results;
    }
 
    static String showFolderChooser(Window owner, String folder, String title) {
        if (owner != null) {
            owner.setEnabled(false);
        }
        try {
            return _showFolderChooser(
                       (owner != null) ? owner.getNativeHandle() : 0,
                       folder, title);
                                                   
        } finally {
            if (owner != null) {
                owner.setEnabled(true);
            }
        }
        
    }
}