Loading...
Searching...
No Matches
Ui::CFileDialog Class Reference

File selector dialog. More...

`#include <src/ui/filedialog.h>`

## Public Member Functions

| CFileDialog ()
| Constructor.
| ~CFileDialog ()
| Destructor.

## 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.
void | StopDialog ()
| Enables other windows and deletes the dialog window.
bool | EventProcess (const Event &event)
| Event processing.
void | SetDialogType (CFileDialog::Type type)
| Set the type of dialog to use.
CFileDialog::Type | GetDialogType ()
| Get the type of dialog.

## File name settings

void | SetAutoExtension (const std::string &ext)
| Set the extension that may be appended to a file name.
void | AddOptionalExtension (const std::string &ext)
| Define extensions that will be accepted as part of a valid file name.
void | SetFilename (const std::string &filename)
| Set the filename that appears in the edit box when the dialog opens.
std::string | GetFilename ()
| Get the filename that was selected or typed.
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.

## Dialog window properties

void | SetWindowEvent (EventType type)
| Set EventType for the dialog window. If not set, a unique EventType will be used.
EventType | GetWindowEvent ()
| Get EventType for the dialog window.
void | SetWindowPos (Math::Point pos)
| Set the initial position of the window.
Math::Point | GetWindowPos ()
| Get the position of the window.
void | SetWindowDim (Math::Point dim)
| Set the initial size of the window.
Math::Point | GetWindowDim ()
| Get the size of the window.
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.

## Settings for Public and Private check boxes

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

## 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.
std::string | GetBasePath ()
| Get the initial path or Public/Private folder path.
void | SetSubFolderPath (const std::string &dir)
| Set the initial subfolder whose contents are displayed.
std::string | GetSubFolderPath ()
| Get the current subfolder shown by the dialog.

## Detailed Description

File selector dialog.

# Example usage

Create the dialog and set the type of dialog.

CFileDialog* fileDialog = new CFileDialog();
fileDialog->SetDialogType(CFileDialog::Type::Folder);
Ui::CFileDialog::Type::Folder
@ Folder
Select Folder dialog.
Definition filedialog.h:120
Ui::CFileDialog::CFileDialog
CFileDialog()
Constructor.
Definition filedialog.cpp:56
Ui::CFileDialog::SetDialogType
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();
Ui::CFileDialog::SetWindowTitle
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
Ui::CFileDialog::SetBasePath
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
Ui::CFileDialog::StartDialog
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);
Ui::CFileDialog::StopDialog
void StopDialog()
Enables other windows and deletes the dialog window.
Definition filedialog.cpp:110
Ui::CFileDialog::GetSubFolderPath
std::string GetSubFolderPath()
Get the current subfolder shown by the dialog.
Definition filedialog.cpp:184

## 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

  usePublic | If 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

  bPublic | If 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

  dir | Path 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

  dir | Path 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

  dir | Name 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

  ext | A 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

  ext | A 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

  doCheck | true to check if a file exists when the 'Save' button is pressed.

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

- src/ui/filedialog.h
- src/ui/filedialog.cpp