From 629bd9dbd099af60812e80f851afb7902fc28c37 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 26 Jul 2017 21:46:51 +0200 Subject: Change GuiForm::add_file must_exists argument to flags FILE_OPEN/FILE_SAVE --- src/gui_gtk.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/gui_gtk.cc') diff --git a/src/gui_gtk.cc b/src/gui_gtk.cc index a326cea..7510f09 100644 --- a/src/gui_gtk.cc +++ b/src/gui_gtk.cc @@ -925,10 +925,10 @@ public: void add_file(std::string const& id, std::string const& label, std::string const& value, std::string const& description, - bool must_exist, + uint8_t flags, std::vector const& filter) override { values_.emplace_back(new FileValue(id, label, description, value, - must_exist, filter)); + flags, filter)); } std::string get_string(std::string const& id) const override { @@ -964,7 +964,7 @@ public: for (auto const& value : values_) { if (value->id_ == id && value->type_ == FILE) { auto v = static_cast(value.get()); - if (v->must_exist_ && v->chooser_) { + if ((v->flags_ & FILE_SAVE) == 0 && v->chooser_) { std::string ret; auto file = gtk_file_chooser_get_filename(v->chooser_); if (file) { @@ -1039,7 +1039,7 @@ public: } case FILE: { auto v = static_cast(value.get()); - if (v->must_exist_) { + if ((v->flags_ & FILE_SAVE) == 0) { gtk_widget_destroy(value->entry_); auto button = gtk_file_chooser_button_new( v->label_.c_str(), GTK_FILE_CHOOSER_ACTION_OPEN); @@ -1116,7 +1116,7 @@ public: break; case FILE: { auto v = static_cast(value.get()); - if (v->must_exist_) { + if ((v->flags_ & FILE_SAVE) == 0) { auto file = gtk_file_chooser_get_filename(v->chooser_); if (file) { v->value_ = file; @@ -1181,15 +1181,15 @@ protected: struct FileValue : public Value { std::string value_; - bool must_exist_; + uint8_t flags_; std::vector filter_; GtkFileChooser* chooser_; FileValue(std::string const& id, std::string const& label, std::string const& description, std::string const& value, - bool must_exist, std::vector const& filter) + uint8_t flags, std::vector const& filter) : Value(FILE, id, label, description), value_(value), - must_exist_(must_exist), filter_(filter) { + flags_(flags), filter_(filter) { } }; @@ -1954,6 +1954,10 @@ GuiForm* GuiForm::create(std::string const& title, return new GtkGuiForm(title, text); } +// static +uint8_t const GuiForm::FILE_OPEN = 0; +uint8_t const GuiForm::FILE_SAVE = 1; + // static GuiFormApply* GuiFormApply::create(std::string const& title, std::string const& text, -- cgit v1.2.3-70-g09d2