cgv
|
A convenience class that provides a file input gui control. More...
#include <file_helper.h>
Public Types | |
enum class | Mode { kOpen , kSave , kOpenAndSave } |
Operation mode enum. More... | |
Public Member Functions | |
file_helper () | |
Construct with default parameters. | |
file_helper (provider *p, const std::string &title, Mode mode) | |
Construct with arguments. | |
bool | can_open () const |
Return true if this file_helper supports opening files, false otherwise. | |
bool | can_save () const |
Return true if this file_helper supports saving files, false otherwise. | |
const std::string & | get_title (Mode mode=Mode::kOpenAndSave) const |
Get the title of the specified operation Mode. | |
void | set_title (const std::string &title, Mode mode=Mode::kOpenAndSave) |
Set the title of the specified operation Mode. | |
const std::string & | get_default_path (Mode mode=Mode::kOpenAndSave) const |
Get the default path of the specified operation Mode. | |
void | set_default_path (const std::string &path, Mode mode=Mode::kOpenAndSave) |
Set the default path of the specified operation Mode. | |
void | set_file_name (const std::string &file_name) |
Set the current file name. | |
void | clear_filters () |
Clear all custom filters. | |
void | add_filter (const std::string &name, const std::string &extension, Mode mode=Mode::kOpenAndSave) |
Add a custom filter matching a single extension. | |
void | add_multi_filter (const std::string &name, const std::vector< std::string > &extensions, Mode mode=Mode::kOpenAndSave) |
Add a custom filter matching multiple extensions. | |
void | add_filter_for_all_files (Mode mode=Mode::kOpenAndSave) |
Add a filter that matches all files. | |
bool | compare_extension (const std::string &extension) const |
Compare the extension of file_name to the given string (case insensitive) | |
const std::string | ensure_extension (const std::string &extension, bool force=false) |
Ensure the stored file_name has the given extension. | |
void | create_gui (const std::string &label, const std::string &extra_options="") |
Create the gui control for the file input. | |
bool | is_save_action () const |
Check whether a save action was performed. | |
Public Attributes | |
std::string | file_name = "" |
The current file name. | |
A convenience class that provides a file input gui control.
Usage: Add as a member to your provider class: cgv::gui::file_helper input;
Set the provider pointer and mode in the constructor of your class: input = cgv::gui::file_helper(this, "Title", cgv::gui::file_helper::Mode::kOpenAndSave);
Set filters to match file types as needed. The first filter that is added will be selected by default when openign the dialog. input.add_filter("Text Files", "txt");
Create the gui in your create_gui method: input.create_gui("Label");
Testing for value changes in on_set(void* member_ptr): if(member_ptr == &input.file_name) { if(input.is_save_action()) { ...handle save } else { ...handle open } }
Definition at line 35 of file file_helper.h.
|
strong |
Operation mode enum.
Definition at line 38 of file file_helper.h.
|
inline |
Construct with default parameters.
Default constructor is given to enable using this class as a stack variable member in other classes. Before usage it must be re-assigned with a valid provider pointer.
Definition at line 106 of file file_helper.h.
Construct with arguments.
p | The gui provider pointer. |
title | The title shown in the file dialog. |
mode | The operating mode. |
Definition at line 112 of file file_helper.h.
|
inline |
Add a custom filter matching a single extension.
Add a filter for matching files with the given extension in the file dialog. Example: add_filter("Text Files", "txt"); will add a filter displaying "Text Files (*.txt)"
name | The display name. |
extension | The extensions matched. |
mode | The operation mode where this filter is used (defaults to kOpenAndSave). |
Definition at line 215 of file file_helper.h.
|
inline |
Add a filter that matches all files.
Definition at line 236 of file file_helper.h.
|
inline |
Add a custom filter matching multiple extensions.
Add a filter for matching files with one of the given extensions in the file dialog. Example: add_multi_filter("Table Files", { "csv", "txt" }); will add a filter displaying "Table Files (*.csv, *.txt)"
name | The display name. |
extension | The extensions matched. |
mode | The operation mode where this filter is used (defaults to kOpenAndSave). |
Definition at line 230 of file file_helper.h.
References cgv::utils::join().
|
inline |
Return true if this file_helper supports opening files, false otherwise.
Definition at line 121 of file file_helper.h.
Referenced by create_gui().
|
inline |
Return true if this file_helper supports saving files, false otherwise.
Definition at line 126 of file file_helper.h.
Referenced by create_gui().
|
inline |
Clear all custom filters.
After this method has been called new filters may be set. The gui must be redrawn manually in order for this change to take effect.
Definition at line 200 of file file_helper.h.
|
inline |
Compare the extension of file_name to the given string (case insensitive)
extension | The extension to compare against. |
Definition at line 243 of file file_helper.h.
References file_name, and cgv::utils::to_upper().
|
inline |
Create the gui control for the file input.
label | The control label |
extra_options | Additional options applied to the string input control. |
Definition at line 272 of file file_helper.h.
References cgv::gui::property_string::add(), cgv::gui::property_string::add_bracketed(), cgv::gui::provider::add_gui(), can_open(), can_save(), and file_name.
|
inline |
Ensure the stored file_name has the given extension.
When a file_name was selected through a file dialog, a user might not always input an extension. This method ensures the file_name hast the given extension and adds it if not present or in all cases when force is true.
extension | The extension string to add (without dot). |
force | Force adding the extension. |
Definition at line 256 of file file_helper.h.
References file_name, set_file_name(), and cgv::utils::to_upper().
|
inline |
Get the default path of the specified operation Mode.
mode | The operation Mode. |
Definition at line 162 of file file_helper.h.
|
inline |
Get the title of the specified operation Mode.
mode | The optional operation Mode. |
Definition at line 134 of file file_helper.h.
|
inline |
Check whether a save action was performed.
Definition at line 295 of file file_helper.h.
References file_name, and cgv::gui::provider::ref_tree_node_visible_flag().
|
inline |
Set the default path of the specified operation Mode.
path | The new defautl path. |
mode | The operation Mode. |
Definition at line 173 of file file_helper.h.
References file_name, and cgv::gui::provider::set_control_property().
|
inline |
Set the current file name.
file_name | The file name. |
Definition at line 189 of file file_helper.h.
References file_name, and cgv::gui::provider::update_member().
Referenced by ensure_extension().
|
inline |
Set the title of the specified operation Mode.
title | The new title. |
mode | The operation Mode. |
Definition at line 145 of file file_helper.h.
References file_name, and cgv::gui::provider::set_control_property().
std::string cgv::gui::file_helper::file_name = "" |
The current file name.
This member is public to make it accessible to the GUI control flow. It should never be set directly and set_file_name should be used instead.
Definition at line 100 of file file_helper.h.
Referenced by compare_extension(), create_gui(), ensure_extension(), is_save_action(), set_default_path(), set_file_name(), and set_title().