summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavmjong Bah <tavmjong@free.fr>2017-02-08 12:09:58 +0000
committertavmjong-free <tavmjong@free.fr>2017-02-08 12:09:58 +0000
commit116c4c4853a080ff7210de2d4e999959c0c0e0ce (patch)
tree29f465fd9f2c052ecc70abaf402f17f18c016aba
parentAllow dialog to be resizable. (Fixed inheritance.) Also basic housekeeping. (diff)
downloadinkscape-116c4c4853a080ff7210de2d4e999959c0c0e0ce.tar.gz
inkscape-116c4c4853a080ff7210de2d4e999959c0c0e0ce.zip
Add naive selector validation on entry in style dialog.
(bzr r15497)
-rw-r--r--src/attribute-rel-svg.cpp23
-rw-r--r--src/attribute-rel-svg.h1
-rw-r--r--src/ui/dialog/styledialog.cpp64
3 files changed, 64 insertions, 24 deletions
diff --git a/src/attribute-rel-svg.cpp b/src/attribute-rel-svg.cpp
index afa578061..1f4bee1b3 100644
--- a/src/attribute-rel-svg.cpp
+++ b/src/attribute-rel-svg.cpp
@@ -28,6 +28,27 @@ SPAttributeRelSVG * SPAttributeRelSVG::instance = NULL;
bool SPAttributeRelSVG::foundFile = false;
/*
+ * This function returns true if element is an SVG element.
+ */
+bool SPAttributeRelSVG::isSVGElement(Glib::ustring element)
+{
+ if (SPAttributeRelSVG::instance == NULL) {
+ SPAttributeRelSVG::instance = new SPAttributeRelSVG();
+ }
+
+ // Always valid if data file not found!
+ if( !foundFile ) return true;
+
+ // Strip off "svg:" from the element's name
+ Glib::ustring temp = element;
+ if ( temp.find("svg:") != std::string::npos ) {
+ temp.erase( temp.find("svg:"), 4 );
+ }
+
+ return (SPAttributeRelSVG::instance->attributesOfElements.count(temp) > 0);
+}
+
+/*
* This functions checks whether an element -> attribute pair is allowed or not
*/
bool SPAttributeRelSVG::findIfValid(Glib::ustring attribute, Glib::ustring element)
@@ -39,7 +60,7 @@ bool SPAttributeRelSVG::findIfValid(Glib::ustring attribute, Glib::ustring eleme
// Always valid if data file not found!
if( !foundFile ) return true;
- // Strip of "svg:" from the element's name
+ // Strip off "svg:" from the element's name
Glib::ustring temp = element;
if ( temp.find("svg:") != std::string::npos ) {
temp.erase( temp.find("svg:"), 4 );
diff --git a/src/attribute-rel-svg.h b/src/attribute-rel-svg.h
index 74c6d3b60..c0a9cd215 100644
--- a/src/attribute-rel-svg.h
+++ b/src/attribute-rel-svg.h
@@ -22,6 +22,7 @@ typedef std::map<Glib::ustring, std::set<Glib::ustring> > hashList;
*/
class SPAttributeRelSVG {
public:
+ static bool isSVGElement(Glib::ustring element);
static bool findIfValid(Glib::ustring attribute, Glib::ustring element);
private:
diff --git a/src/ui/dialog/styledialog.cpp b/src/ui/dialog/styledialog.cpp
index 8d56e10e7..7b68cfe53 100644
--- a/src/ui/dialog/styledialog.cpp
+++ b/src/ui/dialog/styledialog.cpp
@@ -16,8 +16,11 @@
#include "sp-object.h"
#include "selection.h"
#include "xml/attribute-record.h"
+#include "attribute-rel-svg.h"
+
+#include <glibmm/i18n.h>
#include <glibmm/regex.h>
-
+
using Inkscape::Util::List;
using Inkscape::XML::AttributeRecord;
@@ -169,45 +172,60 @@ void StyleDialog::_addSelector()
* is added to a new style element.
*/
Gtk::Dialog *textDialogPtr = new Gtk::Dialog();
- Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() );
textDialogPtr->add_button("Add", Gtk::RESPONSE_OK);
+
+ Gtk::Entry *textEditPtr = manage ( new Gtk::Entry() );
textDialogPtr->get_vbox()->pack_start(*textEditPtr, Gtk::PACK_SHRINK);
+ Gtk::Label *textLabelPtr = manage ( new Gtk::Label(
+ _("Invalid entry: Not an id (#), class (.), or element CSS selector.")
+ ) );
+ textDialogPtr->get_vbox()->pack_start(*textLabelPtr, Gtk::PACK_SHRINK);
+
/**
* By default, the entrybox contains 'Class1' as text. However, if object(s)
* is(are) selected and user clicks '+' at the bottom of dialog, the
* entrybox will have the id(s) of the selected objects as text.
*/
if (_desktop->getSelection()->isEmpty()) {
- textEditPtr->set_text("Class1");
- }
- else {
+ textEditPtr->set_text(".Class1");
+ } else {
Inkscape::Selection* selection = _desktop->getSelection();
- std::vector<SPObject*> selected = std::vector<SPObject *>(selection
- ->objects().begin(),
- selection->
- objects().end());
+ std::vector<SPObject*> selected =
+ std::vector<SPObject *>(selection->objects().begin(),
+ selection->objects().end());
textEditPtr->set_text(_setClassAttribute(selected));
}
textDialogPtr->set_size_request(200, 100);
- textDialogPtr->show_all();
- int result = textDialogPtr->run();
+ textEditPtr->show();
+ textLabelPtr->hide();
+ textDialogPtr->show();
- /**
- * @brief selectorName
- * This string stores selector name. The text from entrybox is saved as name
- * for selector. If the entrybox is empty, the text (thus selectorName) is
- * set to ".Class1"
- */
- if (!textEditPtr->get_text().empty()) {
+ int result = -1;
+ bool invalid = true;
+
+ while (invalid) {
+ result = textDialogPtr->run();
+
+ /**
+ * @brief selectorName
+ * This string stores selector name. The text from entrybox is saved as name
+ * for selector. If the entrybox is empty, the text (thus selectorName) is
+ * set to ".Class1"
+ */
_selectorName = textEditPtr->get_text();
- }
- else {
- _selectorName = ".Class1";
- }
- del->set_sensitive(true);
+ del->set_sensitive(true);
+
+ if (_selectorName[0] == '.' ||
+ _selectorName[0] == '#' ||
+ SPAttributeRelSVG::isSVGElement( _selectorName ) ) {
+ invalid = false;
+ } else {
+ textLabelPtr->show();
+ }
+ }
/**
* The selector name objects is set to the text that the user sets in the