cgv
Loading...
Searching...
No Matches
directory_helper.h
1#pragma once
2
3#include <cgv/gui/property_string.h>
4#include <cgv/gui/provider.h>
5
6namespace cgv {
7namespace gui {
8
30public:
32 enum class Mode {
33 kOpen,
34 kSave
35 };
36protected:
40 Mode mode_ = Mode::kOpen;
42 std::string title_ = "";
44 std::string path_ = "";
45
46public:
50 std::string directory_name = "";
51
57
62 directory_helper(provider* p, const std::string& title, Mode mode) : provider_ptr_(p), title_(title), mode_(mode) {}
63
65 bool can_open() const {
66 return mode_ == Mode::kOpen;
67 }
68
70 bool can_save() const {
71 return mode_ == Mode::kSave;
72 }
73
77 const std::string& get_title() const {
78 return title_;
79 }
80
84 void set_title(const std::string& title) {
85 title_ = title;
86
89 }
90
94 const std::string& get_default_path() const {
95 return path_;
96 }
97
101 void set_default_path(const std::string& path) {
102 path_ = path;
103
104 if(provider_ptr_)
106 }
107
111 void set_directory_name(const std::string& directory_name) {
112 this->directory_name = directory_name;
113
114 if(provider_ptr_)
115 provider_ptr_->update_member(&this->directory_name);
116 }
117
121 void create_gui(const std::string& label, const std::string& extra_options = "") {
122 property_string options;
123
124 options.add("open", can_open());
125 options.add("save", can_save());
126
127 options.add_bracketed("path", path_);
128
129 options.add("", extra_options);
130
131 if(provider_ptr_)
132 provider_ptr_->add_gui(label, directory_name, "directory", options);
133 }
134
140};
141
142}
143}
A convenience class that provides a directory input gui control.
std::string path_
The default path used for the file system dialog.
provider * provider_ptr_
The pointer to the gui provider for the control.
void set_directory_name(const std::string &directory_name)
Set the current directory name.
bool is_save_action() const
Check whether a save action was performed.
const std::string & get_default_path() const
Get the default path.
Mode mode_
Operating mode of the control that controls the visibility of open and save buttons....
void set_title(const std::string &title)
Set the title.
bool can_open() const
Return true if this directory_helper supports opening files, false otherwise.
directory_helper(provider *p, const std::string &title, Mode mode)
Construct with arguments.
bool can_save() const
Return true if this directory_helper supports saving files, false otherwise.
std::string directory_name
The current directory name This member is public to make it accessible to the GUI control flow.
directory_helper()
Construct with default parameters.
void set_default_path(const std::string &path)
Set the default path.
const std::string & get_title() const
Get the title.
void create_gui(const std::string &label, const std::string &extra_options="")
Create the gui control for the directoy input.
std::string title_
The title shown in the file system dialog.
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
Definition provider.h:64
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.
Definition provider.h:247
virtual void update_member(void *member_ptr)
call this to update all views and controls of a member
Definition provider.cxx:72
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.
Definition provider.h:343
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...
Definition provider.h:217
the cgv namespace
Definition print.h:11