3#include <cgv/gui/property_string.h>
4#include <cgv/gui/provider.h>
5#include <cgv/utils/file.h>
49 Mode mode_ = Mode::kOpen;
51 std::string open_title_ =
"";
53 std::string save_title_ =
"";
55 std::string open_filter_ =
"";
57 std::string save_filter_ =
"";
59 std::string open_path_ =
"";
61 std::string save_path_ =
"";
64 bool mode_allows_open(
Mode mode)
const {
65 return mode == Mode::kOpenAndSave || mode == Mode::kOpen;
69 bool mode_allows_save(
Mode mode)
const {
70 return mode == Mode::kOpenAndSave || mode == Mode::kSave;
80 void extend_filter_string(
const std::string& entry, std::string& to_filter) {
81 if(!to_filter.empty())
88 void add_filter_entry(
const std::string& entry,
Mode mode) {
89 if(mode_allows_open(mode))
90 extend_filter_string(entry, open_filter_);
92 if(mode_allows_save(mode))
93 extend_filter_string(entry, save_filter_);
113 if(mode_allows_open(mode_))
116 if(mode_allows_save(mode_))
122 return mode_allows_open(mode_);
127 return mode_allows_save(mode_);
135 if(mode_allows_open(mode))
146 if(mode_allows_open(mode))
149 if(mode_allows_save(mode))
163 if(mode_allows_open(mode))
174 if(mode_allows_open(mode))
177 if(mode_allows_save(mode))
215 void add_filter(
const std::string& name,
const std::string& extension,
Mode mode = Mode::kOpenAndSave) {
216 std::string entry = name +
" (*." + extension +
"):*." + extension;
217 add_filter_entry(entry, mode);
230 void add_multi_filter(
const std::string& name,
const std::vector<std::string>& extensions,
Mode mode = Mode::kOpenAndSave) {
232 add_filter_entry(entry, mode);
237 add_filter_entry(
"All Files (*.*):*.*", mode);
257 std::string current_extension = cgv::utils::file::get_extension(
file_name);
260 if(current_extension.empty() || force) {
266 return current_extension;
272 void create_gui(
const std::string& label,
const std::string& extra_options =
"") {
287 options.
add(
"", extra_options);
A convenience class that provides a file input gui control.
bool is_save_action() const
Check whether a save action was performed.
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(const std::string &name, const std::string &extension, Mode mode=Mode::kOpenAndSave)
Add a custom filter matching a single extension.
void clear_filters()
Clear all custom filters.
file_helper()
Construct with default parameters.
void set_default_path(const std::string &path, Mode mode=Mode::kOpenAndSave)
Set the default path of the specified operation Mode.
void add_filter_for_all_files(Mode mode=Mode::kOpenAndSave)
Add a filter that matches all files.
bool can_open() const
Return true if this file_helper supports opening files, false otherwise.
const std::string & get_default_path(Mode mode=Mode::kOpenAndSave) const
Get the default path of the specified operation Mode.
file_helper(provider *p, const std::string &title, Mode mode)
Construct with arguments.
void create_gui(const std::string &label, const std::string &extra_options="")
Create the gui control for the file input.
const std::string & get_title(Mode mode=Mode::kOpenAndSave) const
Get the title of the specified operation Mode.
bool can_save() const
Return true if this file_helper supports saving files, false otherwise.
void set_title(const std::string &title, Mode mode=Mode::kOpenAndSave)
Set the title of the specified operation Mode.
std::string file_name
The current file name.
bool compare_extension(const std::string &extension) const
Compare the extension of file_name to the given string (case insensitive)
void set_file_name(const std::string &file_name)
Set the current file name.
const std::string ensure_extension(const std::string &extension, bool force=false)
Ensure the stored file_name has the given extension.
A convenience class for compiling strings of delimited key-value pairs useful for defining GUI contro...
void add(const std::string &key, T value)
Add key-value pair to end of content, converting value to string.
void add_bracketed(const std::string &key, const T value, char bracket='\'')
See add.
derive from this class to provide a gui to the current viewer
bool add_gui(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="")
Add a composed gui of the given gui_type for the given value.
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
void set_control_property(T &value, const std::string &property_name, const std::string &property_value)
Set the property value of all controls of a given class member.
static bool & ref_tree_node_visible_flag(const T &value)
return a reference to the boolean flag, that tells whether the tree node for the passed value is visi...
char to_upper(char c)
convert char to upper case
std::string join(const std::vector< std::string >::const_iterator first, const std::vector< std::string >::const_iterator last, const std::string &sep, bool trailing_sep)
joins a given range of strings, separating them by the given separator; if trailing_sep is true,...
Helper functions to process strings.