From ec8d0b742153e4715efd13fb19607c3167cc2092 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sat, 6 Aug 2011 20:48:21 +0200 Subject: Extensions. New "indent" attribute to add an indent level to extension elements. Filters. Adding the new "indent" attribute to parameters groups. (bzr r10529) --- src/extension/param/enum.cpp | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'src/extension/param/enum.cpp') diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index 9ed5aac16..e25559eeb 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -49,7 +49,7 @@ public: ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, bool gui_hidden, const gchar * gui_tip, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) : - Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext) + Parameter(name, guitext, desc, scope, gui_hidden, gui_tip, ext), _indent(0) { choices = NULL; _value = NULL; @@ -62,7 +62,9 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g if (!strcmp(chname, INKSCAPE_EXTENSION_NS "item") || !strcmp(chname, INKSCAPE_EXTENSION_NS "_item")) { Glib::ustring newguitext, newvalue; const char * contents = NULL; - if (node->firstChild()) contents = node->firstChild()->content(); + if (node->firstChild()) { + contents = node->firstChild()->content(); + } if (contents != NULL) { // don't translate when 'item' but do translate when '_item' // NOTE: internal extensions use build_from_mem and don't need _item but @@ -80,10 +82,11 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g continue; const char * val = node->attribute("value"); - if (val != NULL) + if (val != NULL) { newvalue = val; - else + } else { newvalue = contents; + } if ( (!newguitext.empty()) && (!newvalue.empty()) ) { // logical error if this is not true here choices = g_slist_append( choices, new enumentry(newvalue, newguitext) ); @@ -95,18 +98,26 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g // Initialize _value with the default value from xml // for simplicity : default to the contents of the first xml-child const char * defaultval = NULL; - if (xml->firstChild() && xml->firstChild()->firstChild()) + if (xml->firstChild() && xml->firstChild()->firstChild()) { defaultval = xml->firstChild()->attribute("value"); + } + + const char * indent = xml->attribute("indent"); + if (indent != NULL) { + _indent = atoi(indent) * 12; + } gchar * pref_name = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring paramval = prefs->getString(extension_pref_root + pref_name); g_free(pref_name); - if (!paramval.empty()) + if (!paramval.empty()) { defaultval = paramval.data(); - if (defaultval != NULL) + } + if (defaultval != NULL) { _value = g_strdup(defaultval); + } return; } @@ -139,7 +150,9 @@ ParamComboBox::~ParamComboBox (void) const gchar * ParamComboBox::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) { - if (in == NULL) return NULL; /* Can't have NULL string */ + if (in == NULL) { + return NULL; /* Can't have NULL string */ + } Glib::ustring settext; for (GSList * list = choices; list != NULL; list = g_slist_next(list)) { @@ -150,7 +163,9 @@ ParamComboBox::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node } } if (!settext.empty()) { - if (_value != NULL) g_free(_value); + if (_value != NULL) { + g_free(_value); + } _value = g_strdup(settext.data()); gchar * prefname = this->pref_name(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -221,13 +236,15 @@ ParamComboBoxEntry::changed (void) Gtk::Widget * ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) { - if (_gui_hidden) return NULL; + if (_gui_hidden) { + return NULL; + } Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4)); Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT)); label->show(); - hbox->pack_start(*label, false, false); + hbox->pack_start(*label, false, false, _indent); ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node, changeSignal)); // add choice strings: @@ -240,7 +257,9 @@ ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s settext = entr->guitext; } } - if (!settext.empty()) combo->set_active_text(settext); + if (!settext.empty()) { + combo->set_active_text(settext); + } combo->show(); hbox->pack_start(*combo, true, true); -- cgit v1.2.3 From af07ce24271fc904e432cdf77714f49b8cbc8db8 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 18 Dec 2011 22:54:08 -0800 Subject: Const correctness fixes that also correct bug #893146. Fixed bugs: - https://launchpad.net/bugs/893146 (bzr r10783) --- src/extension/param/enum.cpp | 89 +++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 42 deletions(-) (limited to 'src/extension/param/enum.cpp') diff --git a/src/extension/param/enum.cpp b/src/extension/param/enum.cpp index e25559eeb..755cc92ad 100644 --- a/src/extension/param/enum.cpp +++ b/src/extension/param/enum.cpp @@ -7,6 +7,7 @@ /* * Author: * Johan Engelen + * Jon A. Cruz * * Copyright (C) 2006-2007 Johan Engelen * @@ -118,8 +119,6 @@ ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const g if (defaultval != NULL) { _value = g_strdup(defaultval); } - - return; } ParamComboBox::~ParamComboBox (void) @@ -134,21 +133,22 @@ ParamComboBox::~ParamComboBox (void) } -/** \brief A function to set the \c _value - \param in The value to set - \param doc A document that should be used to set the value. - \param node The node where the value may be placed - - This function sets ONLY the internal value, but it also sets the value - in the preferences structure. To put it in the right place, \c PREF_DIR - and \c pref_name() are used. - - 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(). -*/ -const gchar * -ParamComboBox::set (const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) +/** + * A function to set the \c _value. + * + * This function sets ONLY the internal value, but it also sets the value + * in the preferences structure. To put it in the right place, \c PREF_DIR + * and \c pref_name() are used. + * + * 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. + * @param doc A document that should be used to set the value. + * @param node The node where the value may be placed. + */ +const gchar *ParamComboBox::set(const gchar * in, SPDocument * /*doc*/, Inkscape::XML::Node * /*node*/) { if (in == NULL) { return NULL; /* Can't have NULL string */ @@ -181,22 +181,15 @@ ParamComboBox::changed (void) { } - -/** - \brief A function to get the value of the parameter in string form - \return A string with the 'value' as command line argument -*/ -void -ParamComboBox::string (std::string &string) +void ParamComboBox::string(std::string &string) const { string += _value; - return; } -/** \brief A special category of Gtk::Entry to handle string parameteres */ +/** A special category of Gtk::Entry to handle string parameteres. */ class ParamComboBoxEntry : public Gtk::ComboBoxText { private: ParamComboBox * _pref; @@ -204,10 +197,11 @@ private: Inkscape::XML::Node * _node; sigc::signal * _changeSignal; public: - /** \brief Build a string preference for the given parameter - \param pref Where to get the string from, and where to put it - when it changes. - */ + /** + * Build a string preference for the given parameter. + * @param pref Where to get the string from, and where to put it + * when it changes. + */ ParamComboBoxEntry (ParamComboBox * pref, SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) : Gtk::ComboBoxText(), _pref(pref), _doc(doc), _node(node), _changeSignal(changeSignal) { this->signal_changed().connect(sigc::mem_fun(this, &ParamComboBoxEntry::changed)); @@ -215,11 +209,12 @@ public: void changed (void); }; -/** \brief Respond to the text box changing - - This function responds to the box changing by grabbing the value - from the text box and putting it in the parameter. -*/ +/** + * Respond to the text box changing. + * + * This function responds to the box changing by grabbing the value + * from the text box and putting it in the parameter. + */ void ParamComboBoxEntry::changed (void) { @@ -231,12 +226,11 @@ ParamComboBoxEntry::changed (void) } /** - \brief Creates a combobox widget for an enumeration parameter -*/ -Gtk::Widget * -ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) + * Creates a combobox widget for an enumeration parameter. + */ +Gtk::Widget *ParamComboBox::get_widget(SPDocument * doc, Inkscape::XML::Node * node, sigc::signal * changeSignal) { - if (_gui_hidden) { + if (_gui_hidden) { return NULL; } @@ -270,5 +264,16 @@ ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node, sigc::s } -} /* namespace Extension */ -} /* namespace Inkscape */ +} // namespace Extension +} // namespace Inkscape + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- cgit v1.2.3