25#ifndef TGUI_FILE_DIALOG_HPP
26#define TGUI_FILE_DIALOG_HPP
28#include <TGUI/Config.hpp>
30#include <TGUI/Filesystem.hpp>
31#include <TGUI/Renderers/FileDialogRenderer.hpp>
32#include <TGUI/Widgets/Button.hpp>
33#include <TGUI/Widgets/ChildWindow.hpp>
34#include <TGUI/Widgets/ComboBox.hpp>
35#include <TGUI/Widgets/EditBox.hpp>
36#include <TGUI/Widgets/Label.hpp>
37#include <TGUI/Widgets/ListView.hpp>
61 class TGUI_API FileDialog :
public ChildWindow
64 using Ptr = std::shared_ptr<FileDialog>;
65 using ConstPtr = std::shared_ptr<const FileDialog>;
76 explicit FileDialog(
const char* typeName =
StaticWidgetType,
bool initRenderer =
true);
88 const String& confirmButtonText =
"Open",
89 bool allowCreateFolder =
false);
220 std::size_t defaultFilterIndex = 0);
318 const String& sizeColumnText =
"Size",
319 const String& modifiedColumnText =
"Modified");
414 void textEntered(
char32_t key)
override;
440 [[nodiscard]] std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
445 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
450 bool updateTime(
Duration elapsedTime)
override;
468 void historyChanged();
473 void sortFilesInListView();
478 void filesSelected(std::vector<Filesystem::Path> selectedFiles);
483 void updateConfirmButtonEnabled();
488 void confirmButtonPressed();
493 void addCreateFolderButton();
498 void createFolder(
const String& name);
503 void createCreateFolderDialog();
508 void destroyCreateFolderDialog();
513 [[nodiscard]]
static bool isValidFolderName(
const String& name);
518 void identifyChildWidgets();
523 void connectSignals();
550 bool m_allowCreateFolder =
false;
552 bool m_createFolderDialogOpen =
false;
555 std::vector<Filesystem::FileInfo> m_filesInDirectory;
556 std::vector<Texture> m_fileIcons;
557 std::size_t m_sortColumnIndex = 0;
558 bool m_sortInversed =
false;
560 std::vector<Filesystem::Path> m_pathHistory;
561 std::size_t m_pathHistoryIndex = 0;
563 bool m_fileMustExist =
true;
564 bool m_selectingDirectory =
false;
565 bool m_multiSelect =
false;
567 std::vector<std::pair<String, std::vector<String>>> m_fileTypeFilters;
568 std::size_t m_selectedFileTypeFilter = 0;
570 std::shared_ptr<FileDialogIconLoader> m_iconLoader;
572 std::vector<Filesystem::Path> m_selectedFiles;
std::shared_ptr< ComboBox > Ptr
Shared widget pointer.
Definition ComboBox.hpp:50
Wrapper for durations.
Definition Duration.hpp:52
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition EditBox.hpp:48
Definition FileDialogIconLoader.hpp:43
Definition FileDialogRenderer.hpp:35
FileDialog(const FileDialog &other)
Copy constructor.
SignalFileDialogPaths onFileSelect
Definition FileDialog.hpp:531
void setCancelButtonText(const String &text="Cancel")
Changes the text of the cancel button (e.g. to display it in a different language).
void setMultiSelect(bool multiSelect)
Changes whether multiple files can be selected.
void setFileTypeFilters(const std::vector< std::pair< String, std::vector< String > > > &filters, std::size_t defaultFilterIndex=0)
Changes the file filters which the user can select to only show files of a certain type.
void setFileMustExist(bool enforceExistence)
Changes whether the file should exist or whether the filename can be a non-existent file.
FileDialog(FileDialog &&other) noexcept
Move constructor.
std::size_t getFileTypeFiltersIndex() const
Returns the index of the currently selected file filter.
void setAllowCreateFolder(bool allowCreateFolder)
Adds or removes the create folder button.
void setConfirmButtonText(const String &text="Open")
Changes the text of the open/save button.
static FileDialog::Ptr create(const String &title="Open file", const String &confirmButtonText="Open", bool allowCreateFolder=false)
Creates a new file dialog widget.
std::unique_ptr< DataIO::Node > save(SavingRenderersMap &renderers) const override
Saves the widget as a tree node in order to save it to a file.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
FileDialog & operator=(const FileDialog &other)
Overload of copy assignment operator.
const String & getCreateFolderButtonText() const
Return the text of the create folder button.
const String & getConfirmButtonText() const
Return the text of the open/save button.
FileDialogRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
bool getFileMustExist() const
Returns whether the file should exist or whether the filename can be a non-existent file.
void setPath(const String &path)
Changes the directory for which the files are to be displayed.
std::shared_ptr< const FileDialog > ConstPtr
Shared constant widget pointer.
Definition FileDialog.hpp:65
std::shared_ptr< FileDialog > Ptr
Shared widget pointer.
Definition FileDialog.hpp:64
const String & getCancelButtonText() const
Return the text of the cancel button.
std::shared_ptr< FileDialogIconLoader > getIconLoader() const
Gets the icon loader that is currently being used.
const String & getFilenameLabelText() const
Return the text of the filename label.
const std::vector< std::pair< String, std::vector< String > > > & getFileTypeFilters() const
Returns the file filters which the user can select to only show files of a certain type.
bool getAllowCreateFolder() const
Return whether the file dialog allows the user to create a folder.
void setPath(const Filesystem::Path &path)
Changes the directory for which the files are to be displayed.
void setCreateFolderButtonText(const String &text="Create Folder")
Changes the text of the create folder button.
std::tuple< String, String, String > getListViewColumnCaptions() const
Returns the names of the list view columns.
const String & getFilename() const
Returns the filename that is entered in the filename edit box.
bool getMultiSelect() const
Returns whether multiple files can be selected.
FileDialogRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
void setIconLoader(std::shared_ptr< FileDialogIconLoader > iconLoader)
Sets a custom icon loader.
bool canHandleKeyPress(const Event::KeyEvent &event) override
Called by the parent of the widget to check if keyPressed would process the event.
static FileDialog::Ptr copy(const FileDialog::ConstPtr &dialog)
Makes a copy of another file dialog.
void setSelectingDirectory(bool selectDirectories)
Changes whether the file dialog is used for selecting a file or for selecting a directory.
void rendererChanged(const String &property) override
Function called when one of the properties of the renderer is changed.
FileDialog & operator=(FileDialog &&other) noexcept
Overload of move assignment operator.
Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
bool getSelectingDirectory() const
Returns whether the file dialog is used for selecting a file or for selecting a directory.
void setFilenameLabelText(const String &labelText="Filename:")
Changes the text of the filename label (e.g. to display it in a different language).
void setFilename(const String &filename)
Sets the filename that is shown at the bottom of the file dialog.
const std::vector< Filesystem::Path > & getSelectedPaths() const
Returns the selected files/directories.
void setListViewColumnCaptions(const String &nameColumnText="Name", const String &sizeColumnText="Size", const String &modifiedColumnText="Modified")
Changes the names of the list view columns (e.g. to display them in a different language).
Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
static constexpr char StaticWidgetType[]
Type name of the widget.
Definition FileDialog.hpp:67
Signal onCancel
The child window was closed or the cancel button was pressed. This signal fires before onClose.
Definition FileDialog.hpp:534
const Filesystem::Path & getPath() const
Returns the directory that is currently being shown in the file dialog.
Object to represent paths on a filesystem.
Definition Filesystem.hpp:55
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition Label.hpp:43
std::shared_ptr< ListView > Ptr
Shared widget pointer.
Definition ListView.hpp:47
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:798
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:59
Wrapper class to store strings.
Definition String.hpp:94
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:37
KeyPressed event parameters.
Definition Event.hpp:166