13#include <glibmm/regex.h>
15#include <gtkmm/entry.h>
16#include <gtkmm/label.h>
17#include <gtkmm/scrolledwindow.h>
18#include <gtkmm/textview.h>
31 const char *value =
nullptr;
39 if (
_value.empty() && value) {
51 const char *max_length = xml->
attribute(
"max-length");
53 max_length = xml->
attribute(
"max_length");
64 g_warning(
"Invalid value ('%s') for appearance of parameter '%s' in extension '%s'",
96class ParamStringEntry :
public Gtk::Entry {
99 sigc::signal<void ()> *_changeSignal;
106 ParamStringEntry(
ParamString *pref, sigc::signal<
void ()> *changeSignal)
109 , _changeSignal(changeSignal)
111 this->set_text(_pref->
get());
113 this->signal_changed().connect(sigc::mem_fun(*
this, &ParamStringEntry::changed_text));
125void ParamStringEntry::changed_text()
127 Glib::ustring
data = this->get_text();
129 if (_changeSignal !=
nullptr) {
130 _changeSignal->emit();
137class ParamMultilineStringEntry :
public Gtk::TextView {
140 sigc::signal<void ()> *_changeSignal;
147 ParamMultilineStringEntry(ParamString *pref, sigc::signal<
void ()> *changeSignal)
150 , _changeSignal(changeSignal)
153 Glib::ustring value =
Glib::Regex::create(
"\\\\n")->replace_literal(_pref->get(), 0,
"\n", (Glib::Regex::MatchFlags)0);
155 this->get_buffer()->set_text(value);
156 this->get_buffer()->signal_changed().connect(sigc::mem_fun(*
this, &ParamMultilineStringEntry::changed_text));
167void ParamMultilineStringEntry::changed_text()
169 Glib::ustring
data = this->get_buffer()->get_text();
174 _pref->set(
data.c_str());
175 if (_changeSignal !=
nullptr) {
176 _changeSignal->emit();
195 auto const label = Gtk::make_managed<Gtk::Label>(
_text, Gtk::Align::START);
201 auto const textarea = Gtk::make_managed<Gtk::ScrolledWindow>();
202 textarea->set_vexpand();
203 textarea->set_has_frame(
true);
205 auto const entry = Gtk::make_managed<ParamMultilineStringEntry>(
this, changeSignal);
206 textarea->set_child(*entry);
210 Gtk::Widget *entry = Gtk::make_managed<ParamStringEntry>(
this, changeSignal);
The object that is the basis for the Extension system.
char const * get_id() const
Get the ID of this extension - not a copy don't delete!
A class to represent the parameter of an extension.
char * _name
The name of this parameter.
static constexpr int GUI_PARAM_WIDGETS_SPACING
Recommended spacing between the widgets making up a single Parameter (e.g.
Glib::ustring pref_name() const
Build preference name for the current parameter.
char * _text
Parameter text to show as the GUI label.
std::string value_to_string() const override
Gets the current value of the parameter in a string form.
const Glib::ustring & get() const
Returns _value, with a \i const to protect it.
void string_to_value(const std::string &in) override
Sets the current value of the parameter from a string.
Glib::ustring _value
Internal value.
const Glib::ustring & set(Glib::ustring in)
A function to set the _value.
ParamString(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext)
Gtk::Widget * get_widget(sigc::signal< void()> *changeSignal) override
Creates a text box for the string parameter.
AppearanceMode _mode
appearance mode
int _max_length
Maximum length of the string in characters (zero meaning unlimited).
Preference storage class.
Glib::ustring getString(Glib::ustring const &pref_path, Glib::ustring const &def="")
Retrieve an UTF-8 string.
static Preferences * get()
Access the singleton Preferences object.
void setString(Glib::ustring const &pref_path, Glib::ustring const &value)
Set an UTF-8 string value.
Interface for refcounted XML nodes.
virtual Node * firstChild()=0
Get the first child of this node.
virtual char const * attribute(char const *key) const =0
Get the string representation of a node's attribute.
virtual char const * content() const =0
Get the content of a text or comment node.
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
void pack_start(Gtk::Box &box, Gtk::Widget &child, bool const expand, bool const fill, unsigned const padding)
Adds child to box, packed with reference to the start of box.
@ HORIZONTAL
The x-dimension (0).
@ VERTICAL
The y-dimension (1).
Helpers for using Gtk::Boxes, encapsulating large changes between GTK3 & GTK4.
Singleton class to access the preferences file in a convenient way.