diff --git a/share/ui/dialog-export-prefs.glade b/share/ui/dialog-export-prefs.glade new file mode 100644 index 0000000000000000000000000000000000000000..3abee04e3b3b3d20417059178864789b153c30be --- /dev/null +++ b/share/ui/dialog-export-prefs.glade @@ -0,0 +1,69 @@ + + + + + + True + False + gear + + + False + + + True + False + vertical + + + pref_label + True + False + 10 + 10 + 5 + Export Format Options + + + False + False + 0 + + + + + True + False + + + False + True + 1 + + + + + True + False + + + + + + False + True + 2 + + + + + + + True + True + True + gear_icon + left + pref_popover + + diff --git a/share/ui/dialog-export.glade b/share/ui/dialog-export.glade index 6f91ed02b76977bee770c440b8ffc3feb2fbfbf2..c3a7bf7bf6883315de56e60d8d8115352cd28164 100644 --- a/share/ui/dialog-export.glade +++ b/share/ui/dialog-export.glade @@ -590,19 +590,7 @@ - - Hide Export Settings - True - True - False - Don't pop up the export options and use the previously used or default options. - True - - - False - True - 2 - + @@ -669,16 +657,16 @@ - + True False 5 - 10 True True + 5 True folder-open Browse export directory @@ -695,6 +683,7 @@ False Select export format center + 5 0 @@ -712,7 +701,21 @@ 0 1 - 2 + 3 + + + + + True + False + vertical + + + + + + 2 + 0 diff --git a/src/extension/extension.cpp b/src/extension/extension.cpp index 97dc1e379fb50842674892287195b101bf9c27ac..090d5190c5dc500624fb4364e128e7d1f447204f 100644 --- a/src/extension/extension.cpp +++ b/src/extension/extension.cpp @@ -360,6 +360,19 @@ Extension::get_id () const return _id; } +/** + \return The path where this extension's preferences can be found +*/ +std::string +Extension::get_pref_path() const +{ + // The preference prefix allows for the batch exporter to have + // a different set of preferences from the single exporter. + if (!_pref_prefix.empty()) + return _pref_prefix + "/" + _id; + return _id; +} + /** \return The textual name of this extension \brief Get the name of this extension - not a copy don't delete! @@ -757,7 +770,7 @@ Extension::get_param_string(const gchar *name) const { const InxParameter *param; param = get_param(name); - return param->get_string(); + return g_strdup(param->get_string().c_str()); } /** @@ -783,9 +796,7 @@ const char *Extension::get_param_string(const gchar *name, const char *alt) cons const char * Extension::get_param_optiongroup(const gchar *name) const { - const InxParameter *param; - param = get_param(name); - return param->get_optiongroup(); + return get_param_string(name); } /** @@ -886,7 +897,7 @@ Extension::set_param_float(const gchar *name, const double value) Look up in the parameters list, const then execute the function on that found parameter. */ -const char * +std::string Extension::set_param_string(const gchar *name, const char *value) { InxParameter *param; @@ -902,12 +913,10 @@ Extension::set_param_string(const gchar *name, const char *value) Look up in the parameters list, const then execute the function on that found parameter. */ -const char * +std::string Extension::set_param_optiongroup(const gchar *name, const char *value) { - InxParameter *param; - param = get_param(name); - return param->set_optiongroup(value); + return set_param_string(name, value); } /** diff --git a/src/extension/extension.h b/src/extension/extension.h index ee6f50edb1ec1bf84ca01e1f8c3eb24e402a1175..6fae275282b8cc4213ee780568f77b40d525b60d 100644 --- a/src/extension/extension.h +++ b/src/extension/extension.h @@ -137,6 +137,7 @@ private: std::vector _deps; /**< Dependencies for this extension */ static FILE *error_file; /**< This is the place where errors get reported */ std::string _error_reason; /**< Short, textual explanation for the latest error */ + std::string _pref_prefix; bool _gui; protected: @@ -168,6 +169,7 @@ public: Inkscape::XML::Node * get_repr (); gchar * get_id () const; const gchar * get_name () const; + std::string get_pref_path() const; void deactivate (); bool deactivated (); void printFailure (Glib::ustring reason); @@ -184,6 +186,7 @@ public: int get_sort_priority() const { return _priority; } void set_sort_priority(int priority) { _priority = priority; } + void set_pref_prefix(std::string prefix = "") { _pref_prefix = prefix; } /* Parameter Stuff */ private: @@ -249,8 +252,8 @@ public: bool set_param_bool (const gchar *name, const bool value); int set_param_int (const gchar *name, const int value); double set_param_float (const gchar *name, const double value); - const char *set_param_string (const gchar *name, const char *value); - const char *set_param_optiongroup (const gchar *name, const char *value); + std::string set_param_string (const gchar *name, const char *value); + std::string set_param_optiongroup (const gchar *name, const char *value); guint32 set_param_color (const gchar *name, const guint32 color); void set_param_any(const gchar *name, std::string value); void set_param_hidden(const gchar *name, bool hidden); diff --git a/src/extension/internal/template-base.cpp b/src/extension/internal/template-base.cpp index 67a9ae3f9a4436c3373b53bbad6ecc7d9bc368ee..2e059469afec380280d5b1ad51b04df6d89c73d8 100644 --- a/src/extension/internal/template-base.cpp +++ b/src/extension/internal/template-base.cpp @@ -31,7 +31,7 @@ Geom::Point TemplateBase::get_template_size(Inkscape::Extension::Template *tmod) { try { return Geom::Point(tmod->get_param_float("width"), tmod->get_param_float("height")); - } catch (InxParameter::param_not_float_param) { + } catch (InxParameter::param_wrong_type) { g_warning("Template type should provide height and width params!"); } return Geom::Point(100, 100); @@ -56,7 +56,7 @@ const Util::Unit *TemplateBase::get_template_unit(Inkscape::Extension::Template { try { return unit_table.getUnit(tmod->get_param_optiongroup("unit", "cm")); - } catch (InxParameter::param_not_optiongroup_param) { + } catch (InxParameter::param_wrong_type) { return unit_table.getUnit(tmod->get_param_string("unit", "cm")); } } diff --git a/src/extension/prefdialog/parameter-bool.cpp b/src/extension/prefdialog/parameter-bool.cpp index cedffffbcdc50868a4006bfc0057a9a8fab65d2d..493fc6842e06e9a87fe5885ca85f5fa13347aab3 100644 --- a/src/extension/prefdialog/parameter-bool.cpp +++ b/src/extension/prefdialog/parameter-bool.cpp @@ -28,24 +28,19 @@ ParamBool::ParamBool(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *e if (value) string_to_value(value); } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getBool(pref_name(), _value); } bool ParamBool::get() const { - return _value; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + return prefs->getBool(pref_name(), _default_value); } bool ParamBool::set(bool in) { - _value = in; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool(pref_name(), _value); - - return _value; + prefs->setBool(pref_name(), in); + return in; } /** @@ -94,15 +89,15 @@ void ParamBoolCheckButton::on_toggle() std::string ParamBool::value_to_string() const { - return _value ? "true" : "false"; + return get() ? "true" : "false"; } void ParamBool::string_to_value(const std::string &in) { if (in == "true") { - _value = true; + _default_value = true; } else if (in == "false") { - _value = false; + _default_value = false; } else { g_warning("Invalid default value ('%s') for parameter '%s' in extension '%s'", in.c_str(), _name, _extension->get_id()); diff --git a/src/extension/prefdialog/parameter-bool.h b/src/extension/prefdialog/parameter-bool.h index 357f6adf7a19ade56c5383278cf6f0efadd507b4..33ab4f79d61977d9addd30d0e06aff11085aa9df 100644 --- a/src/extension/prefdialog/parameter-bool.h +++ b/src/extension/prefdialog/parameter-bool.h @@ -54,11 +54,14 @@ public: * @todo investigate. Returning a value that can then be appended would probably work better/safer. */ std::string value_to_string() const override; + + bool get_bool() const override { return get(); } + bool set_bool(bool in) override { return set(in); } +protected: void string_to_value(const std::string &in) override; private: - /** Internal value. */ - bool _value = true; + bool _default_value = true; }; } // namespace Extension diff --git a/src/extension/prefdialog/parameter-color.h b/src/extension/prefdialog/parameter-color.h index 9a59d6d660e85918fa38e25af3e0a873c1f8a06e..5c60267fa9648a7e607e5e73dedcd6c8443461e6 100644 --- a/src/extension/prefdialog/parameter-color.h +++ b/src/extension/prefdialog/parameter-color.h @@ -33,7 +33,6 @@ public: ParamColor(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); ~ParamColor() override; - /** Returns \c _value, with a \i const to protect it. */ unsigned int get() const { return _color.value(); } unsigned int set(unsigned int in); @@ -44,6 +43,8 @@ public: sigc::signal *_changeSignal; + unsigned int get_color() const override { return get(); } + unsigned int set_color(unsigned int in) override { return set(in); } private: void _onColorChanged(); void _onColorButtonChanged(); diff --git a/src/extension/prefdialog/parameter-float.cpp b/src/extension/prefdialog/parameter-float.cpp index e726be7a11eade8c59c3511c8500959c1eb16932..f807918368fca51006994b90f374c284c5c657f7 100644 --- a/src/extension/prefdialog/parameter-float.cpp +++ b/src/extension/prefdialog/parameter-float.cpp @@ -37,9 +37,6 @@ ParamFloat::ParamFloat(Inkscape::XML::Node *xml, Inkscape::Extension::Extension string_to_value(value); } - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getDouble(pref_name(), _value); - // parse and apply limits const char *min = xml->attribute("min"); if (min) { @@ -51,21 +48,12 @@ ParamFloat::ParamFloat(Inkscape::XML::Node *xml, Inkscape::Extension::Extension _max = g_ascii_strtod(max, nullptr); } - if (_value < _min) { - _value = _min; - } - - if (_value > _max) { - _value = _max; - } - // parse precision const char *precision = xml->attribute("precision"); if (precision != nullptr) { _precision = strtol(precision, nullptr, 0); } - // parse appearance if (_appearance) { if (!strcmp(_appearance, "full")) { @@ -77,6 +65,13 @@ ParamFloat::ParamFloat(Inkscape::XML::Node *xml, Inkscape::Extension::Extension } } +double ParamFloat::get() const +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto value = prefs->getDouble(pref_name(), _default_value); + return std::min(std::max(value, _min), _max); +} + /** * A function to set the \c _value. * @@ -87,28 +82,20 @@ ParamFloat::ParamFloat(Inkscape::XML::Node *xml, Inkscape::Extension::Extension */ double ParamFloat::set(double in) { - _value = in; - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } - + auto value = std::min(std::max(in, _min), _max); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setDouble(pref_name(), _value); - - return _value; + prefs->setDouble(pref_name(), value); + return value; } std::string ParamFloat::value_to_string() const { - return Glib::ustring::format(std::setprecision(_precision), std::fixed, _value); + return Glib::ustring::format(std::setprecision(_precision), std::fixed, get()); } void ParamFloat::string_to_value(const std::string &in) { - _value = g_ascii_strtod(in.c_str(), nullptr); + _default_value = g_ascii_strtod(in.c_str(), nullptr); } /** A class to make an adjustment that uses Extension params. */ diff --git a/src/extension/prefdialog/parameter-float.h b/src/extension/prefdialog/parameter-float.h index 4616f93948b8df376c56f0b46bda6a55a01fcb0e..37b5aa9739411b46d6e0ee4e098b71677857f315 100644 --- a/src/extension/prefdialog/parameter-float.h +++ b/src/extension/prefdialog/parameter-float.h @@ -32,7 +32,7 @@ public: ParamFloat(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); /** Returns \c _value. */ - double get() const { return _value; } + double get() const; double set(double in); double max () { return _max; } @@ -42,11 +42,15 @@ public: Gtk::Widget *get_widget(sigc::signal *changeSignal) override; std::string value_to_string() const override; + + double get_float() const override { return get(); } + double set_float(double in) override { return set(in); } +protected: void string_to_value(const std::string &in) override; private: /** Internal value. */ - double _value = 0; + double _default_value = 0; /** limits */ // TODO: do these defaults make sense or should we be unbounded by default? diff --git a/src/extension/prefdialog/parameter-int.cpp b/src/extension/prefdialog/parameter-int.cpp index 3b5b05be6b6f9a2d75faa5507133c00bbd79d6d6..13b63702ff9df41aef6189fa1c7c878bdb779700 100644 --- a/src/extension/prefdialog/parameter-int.cpp +++ b/src/extension/prefdialog/parameter-int.cpp @@ -36,9 +36,6 @@ ParamInt::ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext string_to_value(value); } - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getInt(pref_name(), _value); - // parse and apply limits const char *min = xml->attribute("min"); if (min) { @@ -50,14 +47,6 @@ ParamInt::ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext _max = strtol(max, nullptr, 0); } - if (_value < _min) { - _value = _min; - } - - if (_value > _max) { - _value = _max; - } - // parse appearance if (_appearance) { if (!strcmp(_appearance, "full")) { @@ -69,6 +58,13 @@ ParamInt::ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext } } +int ParamInt::get() const +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto value = prefs->getInt(pref_name(), _default_value); + return std::min(std::max(value, _min), _max); +} + /** * A function to set the \c _value. * This function sets the internal value, but it also sets the value @@ -78,18 +74,10 @@ ParamInt::ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext */ int ParamInt::set(int in) { - _value = in; - if (_value > _max) { - _value = _max; - } - if (_value < _min) { - _value = _min; - } - + auto value = std::min(std::max(in, _min), _max); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setInt(pref_name(), _value); - - return _value; + prefs->setInt(pref_name(), value); + return value; } /** A class to make an adjustment that uses Extension params. */ @@ -169,13 +157,13 @@ ParamInt::get_widget(sigc::signal *changeSignal) std::string ParamInt::value_to_string() const { char value_string[32]; - snprintf(value_string, 32, "%d", _value); + snprintf(value_string, 32, "%d", get()); return value_string; } void ParamInt::string_to_value(const std::string &in) { - _value = strtol(in.c_str(), nullptr, 0); + _default_value = strtol(in.c_str(), nullptr, 0); } } // namespace Extension diff --git a/src/extension/prefdialog/parameter-int.h b/src/extension/prefdialog/parameter-int.h index bd4ed75b448ae7f618ed5e7bd74f795621f1fa66..0aa410e245a8117a579de2d8731aed3ecb3c6d05 100644 --- a/src/extension/prefdialog/parameter-int.h +++ b/src/extension/prefdialog/parameter-int.h @@ -32,7 +32,7 @@ public: ParamInt(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); /** Returns \c _value. */ - int get() const { return _value; } + int get() const; int set(int in); int max () { return _max; } @@ -41,11 +41,14 @@ public: Gtk::Widget *get_widget(sigc::signal *changeSignal) override; std::string value_to_string() const override; + + int get_int() const override { return get(); } + int set_int(int in) override { return set(in); } +protected: void string_to_value(const std::string &in) override; private: - /** Internal value. */ - int _value = 0; + int _default_value = 0; /** limits */ // TODO: do these defaults make sense or should we be unbounded by default? diff --git a/src/extension/prefdialog/parameter-notebook.cpp b/src/extension/prefdialog/parameter-notebook.cpp index 2d1b2d57ecee883bc3578ae901f6f9caa6adc840..d4488f7a5b0bbfb57be4c5127b5cf57a8c44fa56 100644 --- a/src/extension/prefdialog/parameter-notebook.cpp +++ b/src/extension/prefdialog/parameter-notebook.cpp @@ -145,51 +145,52 @@ ParamNotebook::ParamNotebook(Inkscape::XML::Node *xml, Inkscape::Extension::Exte page->_name, _name, _extension->get_id()); } } +} +Glib::ustring ParamNotebook::get() const +{ // get value (initialize with value of first page if pref is empty) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getString(pref_name()); + auto value = prefs->getString(pref_name()); - if (_value.empty()) { - if (!_children.empty()) { - ParamNotebookPage *first_page = dynamic_cast(_children[0]); - _value = first_page->_name; - } + if (!value.empty()) + return value; + + if (!_children.empty()) { + ParamNotebookPage *first_page = dynamic_cast(_children[0]); + return first_page->_name; } + return _default_value; } /** - * A function to set the \c _value. + * A function to set the \c value. * * This function sets the internal value, but it also sets the value * in the preferences structure. To put it in the right place \c pref_name() is used. * * @param in The number of the page to set as new value. */ -const Glib::ustring& ParamNotebook::set(const int in) +std::string ParamNotebook::set(const int in) { int i = in < _children.size() ? in : _children.size()-1; ParamNotebookPage *page = dynamic_cast(_children[i]); if (page) { - _value = page->_name; - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(pref_name(), _value); + return InxParameter::set(page->_name); } - - return _value; + return ""; } std::string ParamNotebook::value_to_string() const { - return _value.raw(); + return get().raw(); } void ParamNotebook::string_to_value(const std::string &in) { - _value = in; + _default_value = in; } /** A special category of Gtk::Notebook to handle notebook parameters. */ @@ -245,6 +246,7 @@ Gtk::Widget *ParamNotebook::get_widget(sigc::signal *changeSignal) // add pages (if any) and switch to previously selected page int current_page = -1; int selected_page = -1; + auto value = get(); for (auto child : _children) { ParamNotebookPage *page = dynamic_cast(child); g_assert(child); // A ParamNotebook has only children of type ParamNotebookPage. @@ -260,7 +262,7 @@ Gtk::Widget *ParamNotebook::get_widget(sigc::signal *changeSignal) notebook->append_page(*page_widget, page_text); - if (_value == page->_name) { + if (value == page->_name) { selected_page = current_page; } } diff --git a/src/extension/prefdialog/parameter-notebook.h b/src/extension/prefdialog/parameter-notebook.h index aaf886d0fc3238679c88b8ae9744db9368a5af73..d96660e7d26e0835c4aaead1d9a98dbae13ae9c1 100644 --- a/src/extension/prefdialog/parameter-notebook.h +++ b/src/extension/prefdialog/parameter-notebook.h @@ -37,8 +37,7 @@ class Extension; /** A class to represent a notebook parameter of an extension. */ class ParamNotebook : public InxParameter { private: - /** Internal value. */ - Glib::ustring _value; + Glib::ustring _default_value; /** * A class to represent the pages of a notebook parameter of an extension. @@ -60,11 +59,14 @@ public: Gtk::Widget *get_widget(sigc::signal *changeSignal) override; std::string value_to_string() const override; - void string_to_value(const std::string &in) override; - const Glib::ustring& get() { return _value; } - const Glib::ustring& set(const int in); + Glib::ustring get() const; + std::string set(const int in); + std::string get_string() const override { return get(); } + std::string set_string(const std::string &in) override { return InxParameter::set(in); } +protected: + void string_to_value(const std::string &in) override; }; /* class ParamNotebook */ diff --git a/src/extension/prefdialog/parameter-optiongroup.cpp b/src/extension/prefdialog/parameter-optiongroup.cpp index 5edd0726d501621d64050cc59965884042b7905a..c4d9b2d767c87b89da3f6c2d8023d00794189dfc 100644 --- a/src/extension/prefdialog/parameter-optiongroup.cpp +++ b/src/extension/prefdialog/parameter-optiongroup.cpp @@ -49,6 +49,8 @@ ParamOptionGroup::ParamOptionGroup(Inkscape::XML::Node *xml, Inkscape::Extension child_repr->setAttribute("name", "option"); // TODO: hack to allow options to be parameters child_repr->setAttribute("gui-text", "option"); // TODO: hack to allow options to be parameters ParamOptionGroupOption *param = new ParamOptionGroupOption(child_repr, ext, this); + if (_default_value.empty()) + _default_value = param->_value; choices.push_back(param); } else if (child_repr->type() == XML::NodeType::ELEMENT_NODE) { g_warning("Invalid child element ('%s') for parameter '%s' in extension '%s'. Expected 'option'.", @@ -80,16 +82,6 @@ ParamOptionGroup::ParamOptionGroup(Inkscape::XML::Node *xml, Inkscape::Extension } } - // get value (initialize with value of first choice if pref is empty) - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getString(pref_name()); - - if (_value.empty()) { - if (!choices.empty()) { - _value = choices[0]->_value; - } - } - // parse appearance // (we support "combo" and "radio"; "minimal" is for backwards-compatibility) if (_appearance) { @@ -113,6 +105,18 @@ ParamOptionGroup::~ParamOptionGroup () } +Glib::ustring ParamOptionGroup::get() const +{ + // get value (initialize with value of first choice if pref is empty) + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto value = prefs->getString(pref_name()); + + if (value.empty()) { + value = _default_value; + } + return value; +} + /** * A function to set the \c _value. * @@ -124,15 +128,13 @@ ParamOptionGroup::~ParamOptionGroup () const Glib::ustring &ParamOptionGroup::set(const Glib::ustring &in) { if (contains(in)) { - _value = in; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(pref_name(), _value.c_str()); + prefs->setString(pref_name(), in.c_str()); } else { g_warning("Could not set value ('%s') for parameter '%s' in extension '%s'. Not a valid choice.", in.c_str(), _name, _extension->get_id()); } - - return _value; + return in; } bool ParamOptionGroup::contains(const Glib::ustring text) const @@ -142,18 +144,17 @@ bool ParamOptionGroup::contains(const Glib::ustring text) const return true; } } - return false; } std::string ParamOptionGroup::value_to_string() const { - return _value.raw(); + return get().raw(); } void ParamOptionGroup::string_to_value(const std::string &in) { - _value = in; + _default_value = in; } /** @@ -262,13 +263,14 @@ Gtk::Widget *ParamOptionGroup::get_widget(sigc::signal *changeSignal) Gtk::Label *label = Gtk::manage(new Gtk::Label(_text, Gtk::ALIGN_START)); hbox->pack_start(*label, false, false); + auto value = get(); if (_mode == COMBOBOX) { ComboWidget *combo = Gtk::manage(new ComboWidget(this, changeSignal)); for (auto choice : choices) { combo->append(choice->_text); - if (choice->_value == _value) { + if (choice->_value == value) { combo->set_active_text(choice->_text); } } @@ -287,7 +289,7 @@ Gtk::Widget *ParamOptionGroup::get_widget(sigc::signal *changeSignal) for (auto choice : choices) { RadioWidget *radio = Gtk::manage(new RadioWidget(group, choice->_text, this, changeSignal)); radios->pack_start(*radio, true, true); - if (choice->_value == _value) { + if (choice->_value == value) { radio->set_active(); } } diff --git a/src/extension/prefdialog/parameter-optiongroup.h b/src/extension/prefdialog/parameter-optiongroup.h index a1e976e838daf7210819a07cf159fcf5e1fa6932..0169c4b0748898294253cccb74ac11cb8902b24b 100644 --- a/src/extension/prefdialog/parameter-optiongroup.h +++ b/src/extension/prefdialog/parameter-optiongroup.h @@ -52,7 +52,7 @@ public: Glib::ustring value_from_label(const Glib::ustring label); - const Glib::ustring& get() const { return _value; } + Glib::ustring get() const; const Glib::ustring &set(const Glib::ustring &in); /** @@ -61,9 +61,11 @@ public: */ bool contains(const Glib::ustring text) const; + std::string get_string() const override { return get(); } + std::string set_string(const std::string &in) override { return set(in); } + bool get_optiongroup_contains(const std::string &value) const override { return contains(value); } private: - /** \brief Internal value. */ - Glib::ustring _value; + Glib::ustring _default_value; /** appearance mode **/ AppearanceMode _mode = RADIOBUTTON; diff --git a/src/extension/prefdialog/parameter-path.cpp b/src/extension/prefdialog/parameter-path.cpp index b004f556f9fc62fee2842ab463537831ff0b0b15..eef81310ff88e59a412d81e94a8aa81ead3df730 100644 --- a/src/extension/prefdialog/parameter-path.cpp +++ b/src/extension/prefdialog/parameter-path.cpp @@ -37,16 +37,8 @@ ParamPath::ParamPath(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *e : InxParameter(xml, ext) { // get value - const char *value = nullptr; if (xml->firstChild()) { - value = xml->firstChild()->content(); - } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getString(pref_name()).raw(); - - if (_value.empty() && value) { - _value = value; + _default_value = xml->firstChild()->content(); } // parse selection mode @@ -78,8 +70,16 @@ ParamPath::ParamPath(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *e } } +std::string ParamPath::get() const +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto value = prefs->getString(pref_name()).raw(); + if (!value.empty()) + return value; + return _default_value; +} /** - * A function to set the \c _value. + * A function to set the \c value. * * This function sets the internal value, but it also sets the value * in the preferences structure. To put it in the right place \c pref_name() is used. @@ -88,26 +88,23 @@ ParamPath::ParamPath(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *e */ const std::string& ParamPath::set(const std::string &in) { - _value = in; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(pref_name(), _value); - - return _value; + prefs->setString(pref_name(), in); + return in; } std::string ParamPath::value_to_string() const { - if (!Glib::path_is_absolute(_value) && !_value.empty()) { - return Glib::build_filename(_extension->get_base_directory(), _value); - } else { - return _value; + auto value = get(); + if (!Glib::path_is_absolute(value) && !value.empty()) { + return Glib::build_filename(_extension->get_base_directory(), value); } + return value; } void ParamPath::string_to_value(const std::string &in) { - _value = in; + _default_value = in; } /** A special type of Gtk::Entry to handle path parameters. */ @@ -237,8 +234,9 @@ void ParamPath::on_button_clicked() // set current file/folder suitable for current value // (use basepath of first filename; relative paths are considered relative to .inx file's location) - if (!_value.empty()) { - std::string first_filename = _value.substr(0, _value.find("|")); + auto value = get(); + if (!value.empty()) { + std::string first_filename = value.substr(0, value.find("|")); if (!Glib::path_is_absolute(first_filename)) { first_filename = Glib::build_filename(_extension->get_base_directory(), first_filename); diff --git a/src/extension/prefdialog/parameter-path.h b/src/extension/prefdialog/parameter-path.h index 54562d073911e0b44a0cfc1838f8a865d7137496..36e192920d73bcd47b9e7d15721a5091846e7ac5 100644 --- a/src/extension/prefdialog/parameter-path.h +++ b/src/extension/prefdialog/parameter-path.h @@ -25,13 +25,16 @@ class ParamPath : public InxParameter { public: ParamPath(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); - /** \brief Returns \c _value, with a \i const to protect it. */ - const std::string& get() const { return _value; } + std::string get() const; const std::string &set(const std::string &in) override; Gtk::Widget *get_widget(sigc::signal *changeSignal) override; std::string value_to_string() const override; + + std::string get_string() const override { return get(); } + std::string set_string(const std::string &in) override { return set(in); } +protected: void string_to_value(const std::string &in) override; private: @@ -39,8 +42,7 @@ private: FILE, FOLDER, FILE_NEW, FOLDER_NEW }; - /** \brief Internal value. */ - std::string _value; + std::string _default_value; /** selection mode for the file chooser: files or folders? */ Mode _mode = FILE; diff --git a/src/extension/prefdialog/parameter-string.cpp b/src/extension/prefdialog/parameter-string.cpp index f649b2275caaad6095d8606f0ec0f789d2ffdc9c..b9fca479997158fab08a39e591ddfc164c157d14 100644 --- a/src/extension/prefdialog/parameter-string.cpp +++ b/src/extension/prefdialog/parameter-string.cpp @@ -26,23 +26,8 @@ ParamString::ParamString(Inkscape::XML::Node *xml, Inkscape::Extension::Extensio : InxParameter(xml, ext) { // get value - const char *value = nullptr; if (xml->firstChild()) { - value = xml->firstChild()->content(); - } - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _value = prefs->getString(pref_name()); - - if (_value.empty() && value) { - _value = value; - } - - // translate value - if (!_value.empty()) { - if (_translatable == YES) { // translate only if explicitly marked translatable - _value = get_translation(_value.c_str()); - } + _default_value = xml->firstChild()->content(); } // max-length @@ -65,36 +50,51 @@ ParamString::ParamString(Inkscape::XML::Node *xml, Inkscape::Extension::Extensio } } + +Glib::ustring ParamString::get() const +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + auto value = prefs->getString(pref_name()); + + if (value.empty()) { + value = _default_value; + } + + // translate value + if (!value.empty() &&_translatable == YES) { + // translate only if explicitly marked translatable + value = get_translation(value.c_str()); + } + return value; +} + /** - * A function to set the \c _value. + * A function to set the \c value. * * This function sets the internal value, but it also sets the value * in the preferences structure. To put it in the right place \c pref_name() is used. * - * To copy the data into _value the old memory must be free'd first. + * To copy the data into value the old memory must be free'd first. * It is important to note that \c g_free handles \c NULL just fine. Then * the passed in value is duplicated using \c g_strdup(). * * @param in The value to set to. */ -const Glib::ustring& ParamString::set(const Glib::ustring in) +Glib::ustring ParamString::set(const Glib::ustring in) { - _value = in; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setString(pref_name(), _value); - - return _value; + prefs->setString(pref_name(), in); + return in; } std::string ParamString::value_to_string() const { - return _value.raw(); + return get(); } void ParamString::string_to_value(const std::string &in) { - _value = in; + _default_value = in; } /** A special type of Gtk::Entry to handle string parameters. */ diff --git a/src/extension/prefdialog/parameter-string.h b/src/extension/prefdialog/parameter-string.h index ea445d8ec3fb3f4d32f522f07916f7ed0a8fe8f6..b7e8b5f760f66839553b58b87689ad63c28e1819 100644 --- a/src/extension/prefdialog/parameter-string.h +++ b/src/extension/prefdialog/parameter-string.h @@ -26,21 +26,23 @@ public: ParamString(Inkscape::XML::Node *xml, Inkscape::Extension::Extension *ext); - /** \brief Returns \c _value, with a \i const to protect it. */ - const Glib::ustring& get() const { return _value; } - const Glib::ustring& set(const Glib::ustring in); + Glib::ustring get() const; + Glib::ustring set(const Glib::ustring in); Gtk::Widget *get_widget(sigc::signal *changeSignal) override; std::string value_to_string() const override; - void string_to_value(const std::string &in) override; void setMaxLength(int maxLength) { _max_length = maxLength; } int getMaxLength() { return _max_length; } + std::string get_string() const override { return get(); } + std::string set_string(const std::string &in) override { return set(in); } +protected: + void string_to_value(const std::string &in) override; + private: - /** \brief Internal value. */ - Glib::ustring _value; + Glib::ustring _default_value; /** appearance mode **/ AppearanceMode _mode = DEFAULT; diff --git a/src/extension/prefdialog/parameter.cpp b/src/extension/prefdialog/parameter.cpp index c3594df966ed2c92b00384e3a53ad4336641e378..2821465183e37881df36ca116f4e4cdcb1aabd01 100644 --- a/src/extension/prefdialog/parameter.cpp +++ b/src/extension/prefdialog/parameter.cpp @@ -107,122 +107,6 @@ InxParameter *InxParameter::make(Inkscape::XML::Node *in_repr, Inkscape::Extensi return param; } -bool InxParameter::get_bool() const -{ - ParamBool const *boolpntr = dynamic_cast(this); - if (!boolpntr) { - throw param_not_bool_param(); - } - return boolpntr->get(); -} - -int InxParameter::get_int() const -{ - ParamInt const *intpntr = dynamic_cast(this); - if (!intpntr) { - // This allows option groups to contain integers. Consider just using this. - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - return prefs->getInt(this->pref_name()); - } - return intpntr->get(); -} - -double InxParameter::get_float() const -{ - ParamFloat const *floatpntr = dynamic_cast(this); - if (!floatpntr) { - throw param_not_float_param(); - } - return floatpntr->get(); -} - -const char *InxParameter::get_string() const -{ - ParamString const *stringpntr = dynamic_cast(this); - if (!stringpntr) { - throw param_not_string_param(); - } - return stringpntr->get().c_str(); -} - -const char *InxParameter::get_optiongroup() const -{ - ParamOptionGroup const *param = dynamic_cast(this); - if (!param) { - throw param_not_optiongroup_param(); - } - return param->get().c_str(); -} - -bool InxParameter::get_optiongroup_contains(const char *value) const -{ - ParamOptionGroup const *param = dynamic_cast(this); - if (!param) { - throw param_not_optiongroup_param(); - } - return param->contains(value); -} - -unsigned int InxParameter::get_color() const -{ - ParamColor const *param = dynamic_cast(this); - if (!param) { - throw param_not_color_param(); - } - return param->get(); -} - -bool InxParameter::set_bool(bool in) -{ - ParamBool * boolpntr = dynamic_cast(this); - if (boolpntr == nullptr) - throw param_not_bool_param(); - return boolpntr->set(in); -} - -int InxParameter::set_int(int in) -{ - ParamInt *intpntr = dynamic_cast(this); - if (intpntr == nullptr) - throw param_not_int_param(); - return intpntr->set(in); -} - -double InxParameter::set_float(double in) -{ - ParamFloat * floatpntr; - floatpntr = dynamic_cast(this); - if (floatpntr == nullptr) - throw param_not_float_param(); - return floatpntr->set(in); -} - -const char *InxParameter::set_string(const char *in) -{ - ParamString * stringpntr = dynamic_cast(this); - if (stringpntr == nullptr) - throw param_not_string_param(); - return stringpntr->set(in).c_str(); -} - -const char *InxParameter::set_optiongroup(const char *in) -{ - ParamOptionGroup *param = dynamic_cast(this); - if (!param) { - throw param_not_optiongroup_param(); - } - return param->set(in).c_str(); -} - -unsigned int InxParameter::set_color(unsigned int in) -{ - ParamColor*param = dynamic_cast(this); - if (param == nullptr) - throw param_not_color_param(); - return param->set(in); -} - - InxParameter::InxParameter(Inkscape::XML::Node *in_repr, Inkscape::Extension::Extension *ext) : InxWidget(in_repr, ext) { @@ -280,7 +164,7 @@ InxParameter::~InxParameter() Glib::ustring InxParameter::pref_name() const { - return Glib::ustring::compose("/extensions/%1.%2", _extension->get_id(), _name); + return Glib::ustring::compose("/extensions/%1.%2", _extension->get_pref_path(), _name); } std::string InxParameter::value_to_string() const diff --git a/src/extension/prefdialog/parameter.h b/src/extension/prefdialog/parameter.h index 206560af8b46bac101f4bc8fe00648e7eefe6a8f..76d9250fdf6e81c4f81dff7b559f3b1541d6cadb 100644 --- a/src/extension/prefdialog/parameter.h +++ b/src/extension/prefdialog/parameter.h @@ -40,43 +40,6 @@ public: ~InxParameter() override; - /** Wrapper to cast to the object and use its function. */ - bool get_bool() const; - - /** Wrapper to cast to the object and use it's function. */ - int get_int() const; - - /** Wrapper to cast to the object and use it's function. */ - double get_float() const; - - /** Wrapper to cast to the object and use it's function. */ - const char *get_string() const; - - /** Wrapper to cast to the object and use it's function. */ - const char *get_optiongroup() const; - bool get_optiongroup_contains(const char *value) const; - - /** Wrapper to cast to the object and use it's function. */ - unsigned int get_color() const; - - /** Wrapper to cast to the object and use it's function. */ - bool set_bool(bool in); - - /** Wrapper to cast to the object and use it's function. */ - int set_int(int in); - - /** Wrapper to cast to the object and use it's function. */ - double set_float(double in); - - /** Wrapper to cast to the object and use it's function. */ - const char *set_string(const char *in); - - /** Wrapper to cast to the object and use it's function. */ - const char *set_optiongroup(const char *in); - - /** Wrapper to cast to the object and use it's function. */ - unsigned int set_color(unsigned int in); - char const *name() const { return _name; } /** @@ -106,12 +69,14 @@ public: */ virtual std::string value_to_string() const; +protected: /** Sets the current value of the parameter from a string * * \internal Must be implemented by all derived classes. */ virtual void string_to_value(const std::string &in); +public: /** * Calls string_to_value and then saves the result in the prefs. */ @@ -124,13 +89,20 @@ public: /** An error class for when a parameter is called on a type it is not */ class param_no_name {}; class param_no_text {}; - class param_not_bool_param {}; - class param_not_color_param {}; - class param_not_float_param {}; - class param_not_int_param {}; - class param_not_optiongroup_param {}; - class param_not_string_param {}; - + class param_wrong_type {}; + + virtual bool get_bool() const { throw param_wrong_type(); } + virtual int get_int() const { throw param_wrong_type(); } + virtual double get_float() const { throw param_wrong_type(); } + virtual bool get_optiongroup_contains(const std::string &value) const { throw param_wrong_type(); } + virtual unsigned int get_color() const { throw param_wrong_type(); } + virtual std::string get_string() const { throw param_wrong_type(); } + + virtual bool set_bool(bool in) { throw param_wrong_type(); } + virtual int set_int(int in) { throw param_wrong_type(); } + virtual double set_float(double in) { throw param_wrong_type(); } + virtual std::string set_string(const std::string &in) { throw param_wrong_type(); } + virtual unsigned int set_color(unsigned int in) { throw param_wrong_type(); } protected: /** The name of this parameter. */ diff --git a/src/extension/prefdialog/widget.cpp b/src/extension/prefdialog/widget.cpp index ecc576ab722cebe6b12da5001b1f687d9ab9b19e..2318c48d09f90401f63e41607606279e076c5211 100644 --- a/src/extension/prefdialog/widget.cpp +++ b/src/extension/prefdialog/widget.cpp @@ -152,7 +152,8 @@ InxWidget::get_widget(sigc::signal * /*changeSignal*/) return nullptr; } -const char *InxWidget::get_translation(const char* msgid) { +const char *InxWidget::get_translation(const char* msgid) const +{ return _extension->get_translation(msgid, _context); } diff --git a/src/extension/prefdialog/widget.h b/src/extension/prefdialog/widget.h index 47eb8b940b707f351179321e98f044563533a74e..c77802707f05c9405e3ec88e99dc657d41e3727d 100644 --- a/src/extension/prefdialog/widget.h +++ b/src/extension/prefdialog/widget.h @@ -132,7 +132,7 @@ protected: * @param msgid String to translate * @return Translated string */ - const char *get_translation(const char* msgid); + const char *get_translation(const char* msgid) const; }; } // namespace Extension diff --git a/src/ui/dialog/export-batch.cpp b/src/ui/dialog/export-batch.cpp index f5bca28cbfdbb083a6833062f909b871ba9638f9..0309d9ea42c522f456ed0700ca4eb3e74adfbb92 100644 --- a/src/ui/dialog/export-batch.cpp +++ b/src/ui/dialog/export-batch.cpp @@ -549,29 +549,19 @@ void BatchExport::onExport() Glib::ustring filename = filename_entry->get_text(); export_list->removeExtension(filename); - // create vector of exports - int num_rows = export_list->get_rows(); - std::vector suffixs; - std::vector extensions; - std::vector dpis; - for (int i = 0; i < num_rows; i++) { - suffixs.push_back(export_list->get_suffix(i)); - extensions.push_back(export_list->getExtension(i)); - dpis.push_back(export_list->get_dpi(i)); - } - bool hide = hide_all->get_active(); auto sels = _desktop->getSelection()->items(); std::vector selected_items(sels.begin(), sels.end()); // Start Exporting Each Item + int num_rows = export_list->get_rows(); for (int j = 0; j < num_rows && !interrupted; j++) { - auto suffix = suffixs[j]; - auto omod = extensions[j]; - float dpi = dpis[j]; + auto suffix = export_list->get_suffix(j); + auto ext = export_list->getExtension(j); + float dpi = export_list->get_dpi(j); - if (!omod || omod->deactivated() || !omod->prefs()) { + if (!ext || ext->deactivated()) { continue; } @@ -622,14 +612,14 @@ void BatchExport::onExport() } if (!suffix.empty()) { - if (omod->is_raster()) { + if (ext->is_raster()) { // Put the dpi in at the user's requested location. suffix = std::regex_replace(suffix.c_str(), std::regex("\\{dpi\\}"), std::to_string((int)dpi)); } item_filename = item_filename + "_" + suffix; } - bool found = Export::unConflictFilename(_document, item_filename, omod->get_extension()); + bool found = Export::unConflictFilename(_document, item_filename, ext->get_extension()); if (!found) { continue; } @@ -643,16 +633,16 @@ void BatchExport::onExport() Glib::ustring::compose(_("Format %1, Selection %2"), j + 1, count)); - if (omod->is_raster()) { + if (ext->is_raster()) { unsigned long int width = (int)(area.width() * dpi / DPI_BASE + 0.5); unsigned long int height = (int)(area.height() * dpi / DPI_BASE + 0.5); Export::exportRaster( area, width, height, dpi, _bgnd_color_picker->get_current_color(), - item_filename, true, onProgressCallback, this, omod, hide ? &show_only : nullptr); + item_filename, true, onProgressCallback, this, ext, hide ? &show_only : nullptr); } else { auto copy_doc = _document->copy(); - Export::exportVector(omod, copy_doc.get(), item_filename, true, show_only, page); + Export::exportVector(ext, copy_doc.get(), item_filename, true, show_only, page); } } } diff --git a/src/ui/dialog/export-single.cpp b/src/ui/dialog/export-single.cpp index 27486f42870cfe350a29842c296b3bdca7b30e11..9fee552f7d79623c94af0594f5302bf92a355656 100644 --- a/src/ui/dialog/export-single.cpp +++ b/src/ui/dialog/export-single.cpp @@ -101,11 +101,14 @@ SingleExport::SingleExport(BaseObjectType *cobject, const Glib::RefPtrget_widget("si_hide_all", si_hide_all); builder->get_widget("si_show_preview", si_show_preview); - builder->get_widget("si_default_opts", si_default_opts); builder->get_widget_derived("si_preview", preview); builder->get_widget("si_preview_box", preview_box); builder->get_widget_derived("si_extention", si_extension_cb); + Gtk::Box *pref_button_box = nullptr; + builder->get_widget("si_prefs", pref_button_box); + pref_button_box->add(*si_extension_cb->getPrefButton()); + builder->get_widget("si_filename", si_filename_entry); builder->get_widget("si_export", si_export); @@ -115,7 +118,6 @@ SingleExport::SingleExport(BaseObjectType *cobject, const Glib::RefPtrget_widget("si_backgnd", button); - assert(button); _bgnd_color_picker = std::make_unique( _("Background color"), _("Color used to fill background"), 0xffffff00, true, button); @@ -218,7 +220,6 @@ void SingleExport::setup() } refreshPreview(); }); - si_default_opts->set_active(prefs->getBool("/dialogs/export/defaultopts", true)); } // Setup units combobox @@ -625,13 +626,6 @@ void SingleExport::onExport() float y1 = unit->convert(spin_buttons[SPIN_Y1]->get_value(), "px"); auto area = Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)); - bool default_opts = si_default_opts->get_active(); - prefs->setBool("/dialogs/export/defaultopts", default_opts); - if (!default_opts && !omod->prefs()) { - setExporting(false); - return; // cancel button - } - if (omod->is_raster()) { area *= _desktop->dt2doc(); unsigned long int width = int(spin_buttons[SPIN_BMWIDTH]->get_value() + 0.5); diff --git a/src/ui/dialog/export-single.h b/src/ui/dialog/export-single.h index 8be00d200686d4a6c7068884d41a8a9565573f9e..814cea0686d6c475e55b96b61bb9b7e9823684d6 100644 --- a/src/ui/dialog/export-single.h +++ b/src/ui/dialog/export-single.h @@ -99,7 +99,6 @@ private: Gtk::CheckButton *si_hide_all = nullptr; Gtk::CheckButton *si_show_preview = nullptr; - Gtk::CheckButton *si_default_opts = nullptr; ExportPreview *preview = nullptr; @@ -186,6 +185,7 @@ private: sigc::connection exportConn; sigc::connection cancelConn; sigc::connection browseConn; + sigc::connection prefsConn; sigc::connection _pages_list_changed; // Document Signals sigc::connection _page_selected_connection; diff --git a/src/ui/widget/export-lists.cpp b/src/ui/widget/export-lists.cpp index ba1da1a8bfcb123bb512efe3624fae33a5441957..888e407185b91fe571c44071287fe63902027b95 100644 --- a/src/ui/widget/export-lists.cpp +++ b/src/ui/widget/export-lists.cpp @@ -41,6 +41,7 @@ #include "ui/interface.h" #include "ui/widget/scrollprotected.h" #include "ui/widget/unit-menu.h" +#include "ui/builder-utils.h" using Inkscape::Util::unit_table; @@ -50,19 +51,45 @@ namespace Dialog { ExtensionList::ExtensionList() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - _watch_pref = prefs->createObserver("/dialogs/export/show_all_extensions", [=]() { setup(); }); + init(); } ExtensionList::ExtensionList(BaseObjectType *cobject, const Glib::RefPtr &refGlade) : Inkscape::UI::Widget::ScrollProtected(cobject, refGlade) { - // This duplication is silly, but needed because C++ can't - // both deligate the constructor, and construct for glade + init(); +} + +void ExtensionList::init() +{ + _builder = create_builder("dialog-export-prefs.glade"); + _builder->get_widget("pref_button", _pref_button); + _builder->get_widget("pref_popover", _pref_popover); + _builder->get_widget("pref_holder", _pref_holder); + + _pref_popover->signal_show().connect([this]() { + this->_pref_holder->remove(); + if (auto ext = this->getExtension()) { + if (auto gui = ext->autogui(nullptr, nullptr)) { + this->_pref_holder->add(*gui); + this->_pref_popover->grab_focus(); + } + } + }); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); _watch_pref = prefs->createObserver("/dialogs/export/show_all_extensions", [=]() { setup(); }); } +void ExtensionList::on_changed() +{ + bool has_prefs = false; + if (auto ext = this->getExtension()) { + has_prefs = (ext->widget_visible_count() > 0); + } + _pref_button->set_sensitive(has_prefs); +} + void ExtensionList::setup() { this->remove_all(); @@ -150,7 +177,7 @@ void ExportList::setup() suffix_label->show(); Gtk::Label *extension_label = Gtk::manage(new Gtk::Label(_("Format"))); - this->attach(*extension_label, _extension_col, 0, 1, 1); + this->attach(*extension_label, _extension_col, 0, 2, 1); extension_label->show(); Gtk::Label *dpi_label = Gtk::manage(new Gtk::Label(_("DPI"))); @@ -194,6 +221,7 @@ void ExportList::append_row() extension->setup(); extension->show(); this->attach(*extension, _extension_col, current_row, 1, 1); + this->attach(*extension->getPrefButton(), _prefs_col, current_row, 1, 1); // Disable DPI when not using a raster image output extension->signal_changed().connect([=]() { @@ -256,8 +284,9 @@ Glib::ustring ExportList::get_suffix(int row) Inkscape::Extension::Output *ExportList::getExtension(int row) { ExtensionList *extension_cb = dynamic_cast(this->get_child_at(_extension_col, row + 1)); - return extension_cb ? extension_cb->getExtension() : nullptr; + return extension_cb->getExtension(); } + double ExportList::get_dpi(int row) { double dpi = default_dpi; diff --git a/src/ui/widget/export-lists.h b/src/ui/widget/export-lists.h index 7b1668ca12cf73cca6f2bdae9a1cd48d5d0cedcb..d66266e211404aa3addd8d34b303624986de1386 100644 --- a/src/ui/widget/export-lists.h +++ b/src/ui/widget/export-lists.h @@ -40,17 +40,25 @@ public: ExtensionList(BaseObjectType *cobject, const Glib::RefPtr &refGlade); ~ExtensionList() override {}; -public: void setup(); Glib::ustring getFileExtension(); void setExtensionFromFilename(Glib::ustring const &filename); void removeExtension(Glib::ustring &filename); void createList(); + Gtk::MenuButton *getPrefButton() const { return _pref_button; } Inkscape::Extension::Output *getExtension(); private: + void init(); + void on_changed() override; + PrefObserver _watch_pref; std::map ext_to_mod; + + Glib::RefPtr _builder; + Gtk::MenuButton *_pref_button = nullptr; + Gtk::Popover *_pref_popover = nullptr; + Gtk::Viewport *_pref_holder = nullptr; }; class ExportList : public Gtk::Grid @@ -83,8 +91,9 @@ private: int _num_rows = 0; int _suffix_col = 0; int _extension_col = 1; - int _dpi_col = 2; - int _delete_col = 3; + int _prefs_col = 2; + int _dpi_col = 3; + int _delete_col = 4; }; } // namespace Dialog