#ifndef FileDialog_H
#define FileDialog_H

#include "Array.h"
#include "Thread.h"

namespace Framework
{
    class Text; //! Text.h

    void InitDialog();

    //! Creates a file open/save dialog
    class FileDialog : public virtual ReferenceCounter
    {
    private:
        RCArray<Text>* typeName;
        RCArray<Text>* type;
        int fileIndex;

    public:
        //! Constructor
        DLLEXPORT FileDialog();
        //! Destructor
        DLLEXPORT ~FileDialog();
        //! Clears the list of allowed file types
        DLLEXPORT void removeFileTypes();
        //! Adds an allowed file type
        //! \param name The name of the file type. Visible to the user in the
        //! select box \param typ The file type that may be selected
        DLLEXPORT void addFileType(const char* name, const char* typ);
        //! Adds an allowed file type
        //! \param name The name of the file type. Visible to the user in the
        //! select box \param typ The file type that may be selected
        DLLEXPORT void addFileType(Text* name, Text* typ);
        //! Sets the initially selected file type
        //! \param i The index of the file type. The one added first
        //! has index 0.
        DLLEXPORT void setFileTypeSelection(int i);
        //! Shows the file dialog
        //! \param open true if the dialog should be used for opening. false for
        //! saving \return The path to the selected file
        DLLEXPORT Text* show(bool open) const;
    };

    //! Manages a file open/save dialog without blocking
    class FileDialogTh : public Thread
    {
    private:
        FileDialog* dialog;
        Text* ret;
        bool open;

    public:
        //! Constructor
        DLLEXPORT FileDialogTh();
        //! Destructor
        DLLEXPORT ~FileDialogTh();
        //! Sets whether the dialog is for opening or saving
        //! \param b 1 if for opening. 0 if for saving
        DLLEXPORT void setOpen(bool b);
        //! Clears the list of allowed file types
        DLLEXPORT void removeFileTypes();
        //! Adds an allowed file type
        //! \param name The name of the file type. Visible to the user in the
        //! select box \param typ The file type that may be selected
        DLLEXPORT void addFileType(const char* name, const char* typ);
        //! Adds an allowed file type
        //! \param name The name of the file type. Visible to the user in the
        //! select box \param typ The file type that may be selected
        DLLEXPORT void addFileType(Text* name, Text* typ);
        //! Sets the initially selected file type
        //! \param i The index of the file type. The one added first
        //! has index 0.
        DLLEXPORT void setFileTypeSelection(int i);
        //! This function is called by the class itself.
        //! Use the start function to show the dialog
        DLLEXPORT void thread() override;
        //! Returns the path to the file.
        //! Only works after the thread has finished
        DLLEXPORT Text* getPfad() const;
        //! Returns the path to the file without increased reference counter.
        //! Only works after the thread has finished
        DLLEXPORT Text* zPfad() const;
    };
}; // namespace Framework

#endif