Make set_selectable a GncOptionsGtkUIItem member function.

Callable from the option object with set_ui_item_selectable and from
Scheme as gnc-option-db-set-option-selectable-by-name.
This commit is contained in:
John Ralls 2021-02-18 17:13:09 -08:00
parent a21f329b1e
commit d41292fddd
7 changed files with 28 additions and 18 deletions

View File

@ -170,6 +170,13 @@ GncOptionGtkUIItem::~GncOptionGtkUIItem()
g_object_unref(m_widget);
}
void
GncOptionGtkUIItem::set_selectable(bool selectable) const noexcept
{
if (m_widget)
gtk_widget_set_sensitive (m_widget, selectable);
}
void
GncOptionGtkUIItem::clear_ui_item()
{
@ -290,24 +297,6 @@ gnc_option_changed_option_cb(GtkWidget *dummy, GncOption* option)
}
/*
* set_selectable *
* Change the selectable state of the widget that represents a
* GUI option.
*
* option - option to change widget state for
* selectable - if false, update the widget so that it
* cannot be selected by the user. If true,
* update the widget so that it can be selected.
*/
static void
set_selectable (GncOption& option, bool selectable)
{
auto widget = gnc_option_get_gtk_widget(&option);
if (widget)
gtk_widget_set_sensitive (widget, selectable);
}
// This do-nothing template is specialized for each GncOptionUIType.
template<GncOptionUIType type> GtkWidget*
create_option_widget(GncOption& option, GtkGrid*, GtkLabel*, char*, GtkWidget**,

View File

@ -50,6 +50,7 @@ public:
GncOptionGtkUIItem(const GncOptionGtkUIItem& item);
GncOptionGtkUIItem(GncOptionGtkUIItem&&) = default;
virtual ~GncOptionGtkUIItem() override;
virtual void set_selectable(bool) const noexcept override;
void clear_ui_item() override;
void set_widget(GtkWidget* widget);
virtual GtkWidget* const get_widget() const { return m_widget; }

View File

@ -51,6 +51,7 @@ public:
GncOptionUIType get_ui_type() const noexcept { return m_type; }
virtual void set_dirty(bool status) noexcept { m_dirty = status; }
virtual bool get_dirty() const noexcept { return m_dirty; }
virtual void set_selectable(bool selectable) const noexcept = 0;
virtual void clear_ui_item() = 0;
virtual void set_ui_item_from_option(GncOption& option) noexcept = 0;
virtual void set_option_from_ui_item(GncOption& option) noexcept = 0;

View File

@ -193,6 +193,13 @@ GncOption::set_ui_item(GncOptionUIItemPtr&& ui_item)
m_ui_item = std::move(ui_item);
}
void
GncOption::set_ui_item_selectable(bool selectable) const noexcept
{
if (m_ui_item)
m_ui_item->set_selectable(selectable);
}
const GncOptionUIType
GncOption::get_ui_type() const
{

View File

@ -98,6 +98,7 @@ public:
const std::string& get_docstring() const;
void set_ui_item(GncOptionUIItemPtr&& ui_elem);
const GncOptionUIType get_ui_type() const;
void set_ui_item_selectable(bool) const noexcept;
GncOptionUIItem* const get_ui_item() const;
void set_ui_item_from_option();
void set_option_from_ui_item();

View File

@ -768,6 +768,16 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
{
return optiondb->find_option(section, name);
}
void
gnc_option_db_set_option_selectable_by_name(GncOptionDBPtr& odb,
const char* section,
const char* name,
bool selectable)
{
auto option{odb->find_option(section, name)};
option->set_ui_item_selectable(selectable);
}
%}
#endif //SWIGGUILE

View File

@ -526,6 +526,7 @@ public:
~OptionUIItem() = default;
void set_dirty(bool status) noexcept override { m_dirty = status; }
bool get_dirty() const noexcept override { return m_dirty; }
void set_selectable(bool selectable) const noexcept override {}
void clear_ui_item() override { m_widget.clear(); }
void set_ui_item_from_option(GncOption& option) noexcept override
{