summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4778e8d)
raw | patch | inline | side by side (parent: 4778e8d)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Mon, 18 Sep 2006 23:44:37 +0000 (23:44 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Mon, 18 Sep 2006 23:44:37 +0000 (23:44 +0000) |
src/extension/Makefile_insert | patch | blob | history | |
src/extension/paramenum.cpp | [new file with mode: 0644] | patch | blob |
src/extension/paramenum.h | [new file with mode: 0644] | patch | blob |
src/extension/parameter.cpp | patch | blob | history |
index 644eb82c5c7e279d3a752107a08f3ecd1be5f624..9540d863db9f2af3b43a11f89541500536a7f6d8 100644 (file)
extension/parameter.cpp \
extension/paramnotebook.h \
extension/paramnotebook.cpp \
+ extension/paramenum.h \
+ extension/paramenum.cpp \
extension/prefdialog.cpp \
extension/prefdialog.h \
extension/system.cpp \
diff --git a/src/extension/paramenum.cpp b/src/extension/paramenum.cpp
--- /dev/null
@@ -0,0 +1,218 @@
+/** \file\r
+ * extension parameter for enumerations. \r
+ *\r
+ * It uses a Gtk:ComboBoxText widget in the extension UI.\r
+ */\r
+\r
+/*\r
+ * Author:\r
+ * Johan Engelen <johan@shouraizou.nl>\r
+ *\r
+ * Copyright (C) 2006 Author\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#ifdef HAVE_CONFIG_H\r
+# include "config.h"\r
+#endif\r
+\r
+\r
+#include <gtkmm/box.h>\r
+#include <gtkmm/comboboxtext.h>\r
+#include <gtkmm/tooltips.h>\r
+#include <gtkmm/label.h>\r
+\r
+#include <glibmm/i18n.h>\r
+\r
+#include <xml/node.h>\r
+\r
+#include "extension.h"\r
+#include "prefs-utils.h"\r
+#include "document-private.h"\r
+#include "sp-object.h"\r
+\r
+#include "paramenum.h"\r
+\r
+/** \brief The root directory in the preferences database for extension\r
+ related parameters. */\r
+#define PREF_DIR "extensions"\r
+\r
+namespace Inkscape {\r
+namespace Extension {\r
+\r
+ParamComboBox::ParamComboBox (const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml) :\r
+ Parameter(name, guitext, desc, scope, ext)\r
+{ \r
+ choices = NULL;\r
+ _value = NULL;\r
+ \r
+ // Read XML tree to add enumeration items:\r
+ // printf("Extension Constructor: ");\r
+ if (xml != NULL) {\r
+ Inkscape::XML::Node *child_repr = sp_repr_children(xml);\r
+ while (child_repr != NULL) {\r
+ char const * chname = child_repr->name();\r
+ if (!strcmp(chname, "item")) {\r
+ Glib::ustring * newitem = NULL;\r
+ const char * contents = sp_repr_children(child_repr)->content();\r
+ if (contents != NULL)\r
+ newitem = new Glib::ustring(contents);\r
+ if (newitem != NULL) choices = g_slist_append(choices, newitem);\r
+ }\r
+ child_repr = sp_repr_next(child_repr);\r
+ }\r
+ }\r
+ \r
+ // Initialize _value with the default value from xml\r
+ // for simplicity : default to the contents of the first xml-child\r
+ const char * defaultval = NULL;\r
+ if (sp_repr_children(sp_repr_children(xml)) != NULL)\r
+ defaultval = sp_repr_children(sp_repr_children(xml))->content();\r
+ \r
+ gchar * pref_name = this->pref_name();\r
+ const gchar * paramval = prefs_get_string_attribute(PREF_DIR, pref_name);\r
+ g_free(pref_name);\r
+\r
+ if (paramval != NULL)\r
+ defaultval = paramval;\r
+ if (defaultval != NULL)\r
+ _value = g_strdup(defaultval); // allocate space for _value\r
+ \r
+ return;\r
+}\r
+\r
+ParamComboBox::~ParamComboBox (void)\r
+{ \r
+ //destroy choice strings\r
+ for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {\r
+ Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);\r
+ delete text;\r
+ }\r
+ g_slist_free(choices);\r
+\r
+ g_free(_value);\r
+}\r
+\r
+\r
+/** \brief A function to set the \c _value\r
+ \param in The value to set\r
+ \param doc A document that should be used to set the value.\r
+ \param node The node where the value may be placed\r
+\r
+ This function sets ONLY the internal value, but it also sets the value\r
+ in the preferences structure. To put it in the right place, \c PREF_DIR\r
+ and \c pref_name() are used.\r
+\r
+ To copy the data into _value the old memory must be free'd first.\r
+ It is important to note that \c g_free handles \c NULL just fine. Then\r
+ the passed in value is duplicated using \c g_strdup().\r
+*/\r
+const gchar *\r
+ParamComboBox::set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node)\r
+{\r
+ if (in == NULL) return NULL; /* Can't have NULL string */\r
+\r
+ if (_value != NULL)\r
+ g_free(_value);\r
+ _value = g_strdup(in);\r
+\r
+ gchar * prefname = this->pref_name();\r
+ prefs_set_string_attribute(PREF_DIR, prefname, _value);\r
+ g_free(prefname);\r
+\r
+ return _value;\r
+}\r
+\r
+\r
+/**\r
+ \brief A function to get the currentpage and the parameters in a string form\r
+ \return A string with the 'value' and all the parameters on all pages as command line arguments\r
+*/\r
+Glib::ustring *\r
+ParamComboBox::string (void)\r
+{\r
+ Glib::ustring * param_string = new Glib::ustring("");\r
+\r
+ *param_string += "\"";\r
+ *param_string += _value;\r
+ *param_string += "\"";\r
+\r
+ return param_string;\r
+}\r
+\r
+/** \brief A special category of Gtk::Entry to handle string parameteres */\r
+class ParamComboBoxEntry : public Gtk::ComboBoxText {\r
+private:\r
+ ParamComboBox * _pref;\r
+ SPDocument * _doc;\r
+ Inkscape::XML::Node * _node;\r
+public:\r
+ /** \brief Build a string preference for the given parameter\r
+ \param pref Where to get the string from, and where to put it\r
+ when it changes.\r
+ */\r
+ ParamComboBoxEntry (ParamComboBox * pref, SPDocument * doc, Inkscape::XML::Node * node) :\r
+ Gtk::ComboBoxText(), _pref(pref), _doc(doc), _node(node) {\r
+ this->signal_changed().connect(sigc::mem_fun(this, &ParamComboBoxEntry::changed));\r
+ };\r
+ void changed (void);\r
+};\r
+\r
+/** \brief Respond to the text box changing\r
+\r
+ This function responds to the box changing by grabbing the value\r
+ from the text box and putting it in the parameter.\r
+*/\r
+void\r
+ParamComboBoxEntry::changed (void)\r
+{\r
+ Glib::ustring data = this->get_active_text();\r
+ _pref->set(data.c_str(), _doc, _node);\r
+ return;\r
+}\r
+\r
+\r
+\r
+/**\r
+ \brief Creates a combobox widget for an enumeration parameter\r
+*/\r
+Gtk::Widget *\r
+ParamComboBox::get_widget (SPDocument * doc, Inkscape::XML::Node * node)\r
+{\r
+ Gtk::HBox * hbox = Gtk::manage(new Gtk::HBox(false, 4));\r
+\r
+ Gtk::Label * label = Gtk::manage(new Gtk::Label(_(_text), Gtk::ALIGN_LEFT));\r
+ label->show();\r
+ hbox->pack_start(*label, false, false);\r
+\r
+ ParamComboBoxEntry * combo = Gtk::manage(new ParamComboBoxEntry(this, doc, node));\r
+ // add choice strings: \r
+ for (GSList * list = choices; list != NULL; list = g_slist_next(list)) {\r
+ Glib::ustring * text = reinterpret_cast<Glib::ustring *>(list->data);\r
+ combo->append_text(*text);\r
+ }\r
+ combo->set_active_text(Glib::ustring(_value));\r
+\r
+ combo->show();\r
+ hbox->pack_start(*combo, true, true);\r
+\r
+ hbox->show();\r
+\r
+ return dynamic_cast<Gtk::Widget *>(hbox);\r
+}\r
+\r
+\r
+} /* namespace Extension */\r
+} /* namespace Inkscape */\r
+\r
+/*\r
+ Local Variables:\r
+ mode:c++\r
+ c-file-style:"stroustrup"\r
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+ indent-tabs-mode:nil\r
+ fill-column:99\r
+ End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
diff --git a/src/extension/paramenum.h b/src/extension/paramenum.h
--- /dev/null
@@ -0,0 +1,67 @@
+#ifndef __INK_EXTENSION_PARAMENUM_H__\r
+#define __INK_EXTENSION_PARAMENUM_H__\r
+\r
+/** \file\r
+ * Enumeration parameter for extensions.\r
+ */\r
+\r
+/*\r
+ * Author:\r
+ * Johan Engelen <johan@shouraizou.nl>\r
+ *\r
+ * Copyright (C) 2006 Author\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include <gtkmm/widget.h>\r
+\r
+#include "xml/document.h"\r
+#include "extension-forward.h"\r
+\r
+#include "parameter.h"\r
+\r
+namespace Inkscape {\r
+namespace Extension {\r
+\r
+\r
+\r
+// \brief A class to represent a notebookparameter of an extension\r
+class ParamComboBox : public Parameter {\r
+private:\r
+ /** \brief Internal value. This should point to a string that has\r
+ been allocated in memory. And should be free'd. \r
+ It is the value of the current selected string */\r
+ gchar * _value;\r
+ \r
+ GSList * choices; /**< A table to store the choice strings */\r
+ \r
+public:\r
+ ParamComboBox(const gchar * name, const gchar * guitext, const gchar * desc, const Parameter::_scope_t scope, Inkscape::Extension::Extension * ext, Inkscape::XML::Node * xml);\r
+ ~ParamComboBox(void);\r
+ Gtk::Widget * get_widget(SPDocument * doc, Inkscape::XML::Node * node);\r
+ Glib::ustring * string (void);\r
+ \r
+ const gchar * get (const SPDocument * doc, const Inkscape::XML::Node * node) { return _value; }\r
+ const gchar * set (const gchar * in, SPDocument * doc, Inkscape::XML::Node * node);\r
+}; /* class ParamComboBox */\r
+\r
+\r
+\r
+\r
+\r
+} /* namespace Extension */\r
+} /* namespace Inkscape */\r
+\r
+#endif /* __INK_EXTENSION_PARAMENUM_H__ */\r
+\r
+/*\r
+ Local Variables:\r
+ mode:c++\r
+ c-file-style:"stroustrup"\r
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+ indent-tabs-mode:nil\r
+ fill-column:99\r
+ End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
index a821a626dfec18909790205504af6d35b1496974..70f66c41660c37995e4dc63f1b332797f5358ab0 100644 (file)
#include "parameter.h"
#include "paramnotebook.h"
+#include "paramenum.h"
/** \brief The root directory in the preferences database for extension
related parameters. */
@@ -312,7 +313,7 @@ Parameter::make (Inkscape::XML::Node * in_repr, Inkscape::Extension::Extension *
} else if (!strcmp(type, "description")) {
param = new ParamDescription(name, guitext, desc, scope, in_ext, in_repr);
} else if (!strcmp(type, "enum")) {
- param = new ParamEnum(name, guitext, desc, scope, in_ext, in_repr);
+ param = new ParamComboBox(name, guitext, desc, scope, in_ext, in_repr);
} else if (!strcmp(type, "notebook")) {
param = new ParamNotebook(name, guitext, desc, scope, in_ext, in_repr);
}