26#ifndef TGUI_FILE_DIALOG_HPP
27#define TGUI_FILE_DIALOG_HPP
30#include <TGUI/CopiedSharedPtr.hpp>
31#include <TGUI/Widgets/Label.hpp>
32#include <TGUI/Widgets/Button.hpp>
33#include <TGUI/Widgets/EditBox.hpp>
34#include <TGUI/Widgets/ComboBox.hpp>
35#include <TGUI/Widgets/ListView.hpp>
36#include <TGUI/Widgets/ChildWindow.hpp>
37#include <TGUI/Widgets/Panel.hpp>
38#include <TGUI/Renderers/FileDialogRenderer.hpp>
39#include <TGUI/Filesystem.hpp>
41#if !TGUI_EXPERIMENTAL_USE_STD_MODULE
47TGUI_MODULE_EXPORT
namespace tgui
49 class FileDialogIconLoader;
69 using Ptr = std::shared_ptr<FileDialog>;
70 using ConstPtr = std::shared_ptr<const FileDialog>;
72 static constexpr const char StaticWidgetType[] =
"FileDialog";
82 FileDialog(
const char* typeName = StaticWidgetType,
bool initRenderer =
true);
247 TGUI_NODISCARD
const std::vector<std::pair<String, std::vector<String>>>&
getFileTypeFilters()
const;
439 void textEntered(
char32_t key)
override;
469 TGUI_NODISCARD std::unique_ptr<DataIO::Node>
save(SavingRenderersMap& renderers)
const override;
475 void load(
const std::unique_ptr<DataIO::Node>& node,
const LoadingRenderersMap& renderers)
override;
481 bool updateTime(
Duration elapsedTime)
override;
502 void historyChanged();
508 void sortFilesInListView();
514 void filesSelected(std::vector<Filesystem::Path> filenames);
520 void updateConfirmButtonEnabled();
526 void confirmButtonPressed();
531 void addCreateFolderButton();
536 void createFolder(
const String& name);
541 void createCreateFolderDialog();
546 void destroyCreateFolderDialog();
551 bool isValidFolderName(
const String& name);
556 void identifyChildWidgets();
562 void connectSignals();
591 bool m_allowCreateFolder =
false;
593 bool m_createFolderDialogOpen =
false;
596 std::vector<Filesystem::FileInfo> m_filesInDirectory;
597 std::vector<Texture> m_fileIcons;
598 std::size_t m_sortColumnIndex = 0;
599 bool m_sortInversed =
false;
601 std::vector<Filesystem::Path> m_pathHistory;
602 std::size_t m_pathHistoryIndex = 0;
604 bool m_fileMustExist =
true;
605 bool m_selectingDirectory =
false;
606 bool m_multiSelect =
false;
608 std::vector<std::pair<String, std::vector<String>>> m_fileTypeFilters;
609 std::size_t m_selectedFileTypeFilter = 0;
611 std::shared_ptr<FileDialogIconLoader> m_iconLoader;
613 std::vector<Filesystem::Path> m_selectedFiles;
Child window widget.
Definition ChildWindow.hpp:47
std::shared_ptr< ComboBox > Ptr
Shared widget pointer.
Definition ComboBox.hpp:54
Wrapper for durations.
Definition Duration.hpp:56
std::shared_ptr< EditBox > Ptr
Shared widget pointer.
Definition EditBox.hpp:52
Definition FileDialogRenderer.hpp:37
File dialog widget.
Definition FileDialog.hpp:66
static TGUI_NODISCARD FileDialog::Ptr create(const String &title="Open file", const String &confirmButtonText="Open", bool allowCreateFolder=false)
Creates a new file dialog widget.
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.
TGUI_NODISCARD bool getSelectingDirectory() const
Returns whether the file dialog is used for selecting a file or for selecting a directory.
void setFileMustExist(bool enforceExistence)
Changes whether the file should exist or whether the filename can be a non-existent file.
TGUI_NODISCARD const String & getFilename() const
Returns the filename that is entered in the filename edit box.
TGUI_NODISCARD std::tuple< String, String, String > getListViewColumnCaptions() const
Returns the names of the list view columns.
TGUI_NODISCARD const Filesystem::Path & getPath() const
Returns the directory that is currently being shown in the file dialog.
TGUI_NODISCARD Signal & getSignal(String signalName) override
Retrieves a signal based on its name.
TGUI_NODISCARD const String & getConfirmButtonText() const
Return the text of the open/save button.
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.
void load(const std::unique_ptr< DataIO::Node > &node, const LoadingRenderersMap &renderers) override
Loads the widget from a tree of nodes.
TGUI_NODISCARD FileDialogRenderer * getSharedRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD const std::vector< Filesystem::Path > & getSelectedPaths() const
Returns the selected files/directories.
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:70
TGUI_NODISCARD Widget::Ptr clone() const override
Makes a copy of the widget if you don't know its exact type.
std::shared_ptr< FileDialog > Ptr
Shared widget pointer.
Definition FileDialog.hpp:69
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.
TGUI_NODISCARD bool getMultiSelect() const
Returns whether multiple files can be selected.
TGUI_NODISCARD bool getAllowCreateFolder() const
Return whether the file dialog allows the user to create a folder.
TGUI_NODISCARD const String & getFilenameLabelText() const
Return the text of the filename label.
static TGUI_NODISCARD FileDialog::Ptr copy(const FileDialog::ConstPtr &dialog)
Makes a copy of another file dialog.
void setIconLoader(std::shared_ptr< FileDialogIconLoader > iconLoader)
Sets a custom icon loader.
TGUI_NODISCARD 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.
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.
TGUI_NODISCARD std::size_t getFileTypeFiltersIndex() const
Returns the index of the currently selected file filter.
TGUI_NODISCARD 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.
TGUI_NODISCARD FileDialogRenderer * getRenderer() override
Returns the renderer, which gives access to functions that determine how the widget is displayed.
TGUI_NODISCARD const String & getCancelButtonText() const
Return the text of the cancel button.
TGUI_NODISCARD const String & getCreateFolderButtonText() const
Return the text of the create folder button.
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.
TGUI_NODISCARD std::shared_ptr< FileDialogIconLoader > getIconLoader() const
Gets the icon loader that is currently being used.
FileDialog(FileDialog &©) noexcept
Move constructor.
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)
FileDialog(const FileDialog ©)
Copy constructor.
TGUI_NODISCARD bool getFileMustExist() const
Returns whether the file should exist or whether the filename can be a non-existent file.
Object to represent paths on a filesystem.
Definition Filesystem.hpp:59
std::shared_ptr< Label > Ptr
Shared widget pointer.
Definition Label.hpp:47
std::shared_ptr< ListView > Ptr
Shared widget pointer.
Definition ListView.hpp:52
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:839
Signal to which the user can subscribe to get callbacks from.
Definition Signal.hpp:62
Wrapper class to store strings.
Definition String.hpp:101
Namespace that contains all TGUI functions and classes.
Definition AbsoluteOrRelativeValue.hpp:39
KeyPressed event parameters.
Definition Event.hpp:169