Colobot
Public Member Functions | List of all members
Ui::CFileDialog Class Reference

File selector dialog. More...

#include <src/ui/filedialog.h>

Public Member Functions

 CFileDialog ()
 Constructor. More...
 
 ~CFileDialog ()
 Destructor. More...
 

Set dialog type, starting, event processing, and stopping

enum class  Type { None , Open , Save , Folder }
 Identifies the type of dialog to display. More...
 
void StartDialog ()
 Disables other windows and creates the dialog window. More...
 
void StopDialog ()
 Enables other windows and deletes the dialog window. More...
 
bool EventProcess (const Event &event)
 Event processing. More...
 
void SetDialogType (CFileDialog::Type type)
 Set the type of dialog to use. More...
 
CFileDialog::Type GetDialogType ()
 Get the type of dialog. More...
 

File name settings

void SetAutoExtension (const std::string &ext)
 Set the extension that may be appended to a file name. More...
 
void AddOptionalExtension (const std::string &ext)
 Define extensions that will be accepted as part of a valid file name. More...
 
void SetFilename (const std::string &filename)
 Set the filename that appears in the edit box when the dialog opens. More...
 
std::string GetFilename ()
 Get the filename that was selected or typed. More...
 
void SetConfirmOverwrite (bool doCheck)
 Set whether to check if a file exists when the 'Save' button is pressed, and if the file exists, an "Overwrite existing file?" message is shown. More...
 

Dialog window properties

void SetWindowEvent (EventType type)
 Set EventType for the dialog window. If not set, a unique EventType will be used. More...
 
EventType GetWindowEvent ()
 Get EventType for the dialog window. More...
 
void SetWindowPos (Math::Point pos)
 Set the initial position of the window. More...
 
Math::Point GetWindowPos ()
 Get the position of the window. More...
 
void SetWindowDim (Math::Point dim)
 Set the initial size of the window. More...
 
Math::Point GetWindowDim ()
 Get the size of the window. More...
 
void SetWindowTitle (const std::string &name)
 Set the text for the title bar of the dialog. This setting will override the default title text for the dialog. More...
 

Settings for Public and Private check boxes

void SetUsePublicPrivate (bool usePublic)
 Set whether to create Public and Private check boxes. More...
 
void SetPublic (bool bPublic)
 Set initial state for Public and Private check boxes. More...
 
bool GetPublic ()
 Get the state of Public and Private check boxes. More...
 
void SetPublicFolder (const std::string &dir)
 Set the path for the folder associated with the Public check box. More...
 
void SetPrivateFolder (const std::string &dir)
 Set the path for the folder associated with the Private check box. More...
 

Folder settings

void SetBasePath (const std::string &dir)
 Set the initial path for the folder whose contents are displayed. This setting is overridden by Public/Private settings. More...
 
std::string GetBasePath ()
 Get the initial path or Public/Private folder path. More...
 
void SetSubFolderPath (const std::string &dir)
 Set the initial subfolder whose contents are displayed. More...
 
std::string GetSubFolderPath ()
 Get the current subfolder shown by the dialog. More...
 

Detailed Description

File selector dialog.

Example usage

Create the dialog and set the type of dialog.

CFileDialog* fileDialog = new CFileDialog();
File selector dialog.
Definition: filedialog.h:82
@ Folder
Select Folder dialog.
CFileDialog()
Constructor.
Definition: filedialog.cpp:56
void SetDialogType(CFileDialog::Type type)
Set the type of dialog to use.
Definition: filedialog.h:126

Initial settings and start the dialog.

fileDialog->SetWindowTitle("Select Player Folder");
fileDialog->SetBasePath("savegame");
fileDialog->StartDialog();
void SetWindowTitle(const std::string &name)
Set the text for the title bar of the dialog. This setting will override the default title text for t...
Definition: filedialog.h:172
void SetBasePath(const std::string &dir)
Set the initial path for the folder whose contents are displayed. This setting is overridden by Publi...
Definition: filedialog.cpp:169
void StartDialog()
Disables other windows and creates the dialog window.
Definition: filedialog.cpp:72

Handle events for the dialog.

// first check for events sent from the dialog
if (event.type == EVENT_DIALOG_STOP) // cancel or close
{
fileDialog->StopDialog();
delete fileDialog;
return true;
}
if (event.type == EVENT_DIALOG_ACTION) // ok button was pressed
{
std::string folder = fileDialog->GetSubFolderPath();
fileDialog->StopDialog();
delete fileDialog;
return true;
}
// send the event to the dialog
return m_fileDialog->EventProcess(event);
void StopDialog()
Enables other windows and deletes the dialog window.
Definition: filedialog.cpp:110
std::string GetSubFolderPath()
Get the current subfolder shown by the dialog.
Definition: filedialog.cpp:184
bool EventProcess(const Event &event)
Event processing.
Definition: filedialog.cpp:551

Member Enumeration Documentation

◆ Type

enum class Ui::CFileDialog::Type
strong

Identifies the type of dialog to display.

Enumerator
None 

Type was not set.

Open 

Open dialog.

Save 

Save dialog.

Folder 

Select Folder dialog.

Constructor & Destructor Documentation

◆ CFileDialog()

Ui::CFileDialog::CFileDialog ( )

Constructor.

◆ ~CFileDialog()

Ui::CFileDialog::~CFileDialog ( )

Destructor.

Member Function Documentation

◆ StartDialog()

void Ui::CFileDialog::StartDialog ( )

Disables other windows and creates the dialog window.

◆ StopDialog()

void Ui::CFileDialog::StopDialog ( )

Enables other windows and deletes the dialog window.

◆ EventProcess()

bool Ui::CFileDialog::EventProcess ( const Event event)

Event processing.

◆ SetDialogType()

void Ui::CFileDialog::SetDialogType ( CFileDialog::Type  type)
inline

Set the type of dialog to use.

◆ GetDialogType()

CFileDialog::Type Ui::CFileDialog::GetDialogType ( )
inline

Get the type of dialog.

◆ SetWindowEvent()

void Ui::CFileDialog::SetWindowEvent ( EventType  type)
inline

Set EventType for the dialog window. If not set, a unique EventType will be used.

◆ GetWindowEvent()

EventType Ui::CFileDialog::GetWindowEvent ( )
inline

Get EventType for the dialog window.

◆ SetWindowPos()

void Ui::CFileDialog::SetWindowPos ( Math::Point  pos)
inline

Set the initial position of the window.

◆ GetWindowPos()

Math::Point Ui::CFileDialog::GetWindowPos ( )
inline

Get the position of the window.

◆ SetWindowDim()

void Ui::CFileDialog::SetWindowDim ( Math::Point  dim)
inline

Set the initial size of the window.

◆ GetWindowDim()

Math::Point Ui::CFileDialog::GetWindowDim ( )
inline

Get the size of the window.

◆ SetWindowTitle()

void Ui::CFileDialog::SetWindowTitle ( const std::string &  name)
inline

Set the text for the title bar of the dialog. This setting will override the default title text for the dialog.

◆ SetUsePublicPrivate()

void Ui::CFileDialog::SetUsePublicPrivate ( bool  usePublic)

Set whether to create Public and Private check boxes.

Parameters
usePublicIf true, Public and Private check boxes will be added to the dialog.

◆ SetPublic()

void Ui::CFileDialog::SetPublic ( bool  bPublic)

Set initial state for Public and Private check boxes.

Parameters
bPublicIf true, the Public check box will be marked.

◆ GetPublic()

bool Ui::CFileDialog::GetPublic ( )

Get the state of Public and Private check boxes.

Returns
true if Public check box is marked and false for Private.

◆ SetPublicFolder()

void Ui::CFileDialog::SetPublicFolder ( const std::string &  dir)

Set the path for the folder associated with the Public check box.

Parameters
dirPath to 'Public' folder.

◆ SetPrivateFolder()

void Ui::CFileDialog::SetPrivateFolder ( const std::string &  dir)

Set the path for the folder associated with the Private check box.

Parameters
dirPath to 'Private' folder.

◆ SetBasePath()

void Ui::CFileDialog::SetBasePath ( const std::string &  dir)

Set the initial path for the folder whose contents are displayed. This setting is overridden by Public/Private settings.

◆ GetBasePath()

std::string Ui::CFileDialog::GetBasePath ( )

Get the initial path or Public/Private folder path.

◆ SetSubFolderPath()

void Ui::CFileDialog::SetSubFolderPath ( const std::string &  dir)

Set the initial subfolder whose contents are displayed.

Parameters
dirName of a subfolder. Ex. "subfolder/anotherFolder/oneMoreFolder"

◆ GetSubFolderPath()

std::string Ui::CFileDialog::GetSubFolderPath ( )

Get the current subfolder shown by the dialog.

Returns
A string with a folder name and subsequent folders separated by forward slash.

Returns empty string if the dialog is showing GetBasePath().

◆ SetAutoExtension()

void Ui::CFileDialog::SetAutoExtension ( const std::string &  ext)
inline

Set the extension that may be appended to a file name.

If any extensions are defined, the dialog will only show files with those extensions.

Parameters
extA string with an extension. Ex. ".txt"

◆ AddOptionalExtension()

void Ui::CFileDialog::AddOptionalExtension ( const std::string &  ext)
inline

Define extensions that will be accepted as part of a valid file name.

Parameters
extA string with an extension. Ex. ".txt"

◆ SetFilename()

void Ui::CFileDialog::SetFilename ( const std::string &  filename)

Set the filename that appears in the edit box when the dialog opens.

◆ GetFilename()

std::string Ui::CFileDialog::GetFilename ( )

Get the filename that was selected or typed.

Returns
The filename that was typed in the edit box.

◆ SetConfirmOverwrite()

void Ui::CFileDialog::SetConfirmOverwrite ( bool  doCheck)
inline

Set whether to check if a file exists when the 'Save' button is pressed, and if the file exists, an "Overwrite existing file?" message is shown.

Parameters
doChecktrue to check if a file exists when the 'Save' button is pressed.

The documentation for this class was generated from the following files: