Code

grid: make grid names translatable. use different gridtype names in SVG that are...
authorjohanengelen <johanengelen@users.sourceforge.net>
Fri, 20 Apr 2007 15:48:51 +0000 (15:48 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Fri, 20 Apr 2007 15:48:51 +0000 (15:48 +0000)
src/desktop.cpp
src/display/canvas-grid.cpp
src/display/canvas-grid.h
src/sp-namedview.cpp
src/ui/dialog/document-properties.cpp

index bd403139ec824bf61dc996dff10c8d6039050586..d9f82934c039c13550c69a7dbee1635c0cba5bde 100644 (file)
@@ -1124,7 +1124,7 @@ void SPDesktop::toggleGrid()
     } else {
         //there is no grid present at the moment. add a rectangular grid and make it visible
         Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview);
-        Inkscape::CanvasGrid::writeNewGridToRepr(repr, "xygrid");
+        Inkscape::CanvasGrid::writeNewGridToRepr(repr, Inkscape::GRID_RECTANGULAR);
         grids_visible = true;
         sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup));
     }
index ddc0c772384287aa1b0523cce5fdd7c0c3df3451..30c858dcc6fe1219d88b9a1e243ca936a56722de 100644 (file)
@@ -31,7 +31,18 @@ namespace Inkscape {
 #define DEFAULTGRIDCOLOR    0x0000FF20
 #define DEFAULTGRIDEMPCOLOR 0x0000FF40
 
+const gchar *grid_name [] = {
+    N_("Rectangular grid"),
+    N_("Axonometric grid")
+};
+const gchar *grid_svgname [] = {
+    "xygrid",
+    "axonomgrid"
+};
 
+
+// ##########################################################
+// Grid CanvasItem
 static void grid_canvasitem_class_init (GridCanvasItemClass *klass);
 static void grid_canvasitem_init (GridCanvasItem *grid);
 static void grid_canvasitem_destroy (GtkObject *object);
@@ -162,21 +173,60 @@ CanvasGrid::~CanvasGrid()
     }
 }
 
+
+
+const char * 
+CanvasGrid::getName(GridType type)
+{
+    return _(grid_name[type]);
+}
+
+const char * 
+CanvasGrid::getSVGName(GridType type)
+{
+    return grid_svgname[type];
+}
+
+GridType
+CanvasGrid::getGridTypeFromSVGName(const char * typestr)
+{
+    if (!typestr) return GRID_RECTANGULAR;
+
+    gint t = 0;
+    for (t = GRID_MAXTYPENR; t >= 0; t--) {  //this automatically defaults to grid0 which is rectangular grid
+        if (!strcmp(typestr, grid_svgname[t])) break;
+    }
+    return (GridType) t;
+}
+
+GridType
+CanvasGrid::getGridTypeFromName(const char * typestr)
+{
+    if (!typestr) return GRID_RECTANGULAR;
+
+    gint t = 0;
+    for (t = GRID_MAXTYPENR; t >= 0; t--) {  //this automatically defaults to grid0 which is rectangular grid
+        if (!strcmp(typestr, _(grid_name[t]))) break;
+    }
+    return (GridType) t;
+}
+
+
 /*
 *  writes an <inkscape:grid> child to repr.
 */
 void
-CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype)
+CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, GridType gridtype)
 {
     if (!repr) return;
-    if (!gridtype) return;
+    if (gridtype > GRID_MAXTYPENR) return;
 
     // first create the child xml node, then hook it to repr. This order is important, to not set off listeners to repr before the new node is complete.
 
     Inkscape::XML::Document *xml_doc = sp_document_repr_doc(sp_desktop_document(SP_ACTIVE_DESKTOP));
     Inkscape::XML::Node *newnode;
     newnode = xml_doc->createElement("inkscape:grid");
-    newnode->setAttribute("type",gridtype);
+    newnode->setAttribute("type", getSVGName(gridtype));
 
     repr->appendChild(newnode);
 
@@ -189,15 +239,15 @@ CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype
 * Creates a new CanvasGrid object of type gridtype
 */
 CanvasGrid*
-CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, const char * gridtype)
+CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, GridType gridtype)
 {
     if (!in_repr) return NULL;
-    if (!gridtype) return NULL;
 
-    if (!strcmp(gridtype,"xygrid")) {
-        return (CanvasGrid*) new CanvasXYGrid(nv, in_repr);
-    } else if (!strcmp(gridtype,"axonometric")) {
-        return (CanvasGrid*) new CanvasAxonomGrid(nv, in_repr);
+    switch (gridtype) {
+        case GRID_RECTANGULAR:
+            return (CanvasGrid*) new CanvasXYGrid(nv, in_repr);
+        case GRID_AXONOMETRIC:
+            return (CanvasGrid*) new CanvasAxonomGrid(nv, in_repr);
     }
 
     return NULL;
index 0dde36935169803a8668d8a6ebfba574bd75f629..046653df2e3ae98e20cb153e2afab9b3dcf757bd 100644 (file)
@@ -34,6 +34,13 @@ struct SPNamedView;
 
 namespace Inkscape {
 
+
+enum GridType {
+    GRID_RECTANGULAR = 0,
+    GRID_AXONOMETRIC = 1
+};
+#define GRID_MAXTYPENR 1
+
 #define INKSCAPE_TYPE_GRID_CANVASITEM            (Inkscape::grid_canvasitem_get_type ())
 #define INKSCAPE_GRID_CANVASITEM(obj)            (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
 #define INKSCAPE_GRID_CANVASITEM_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
@@ -62,8 +69,13 @@ public:
     CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr);
     virtual ~CanvasGrid();
     
-    static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, const char * gridtype);
-    static void writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype);
+    static const char * getName(GridType type);
+    static const char * getSVGName(GridType type);
+    static GridType     getGridTypeFromSVGName(const char * typestr);
+    static GridType     getGridTypeFromName(const char * typestr);
+    
+    static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, GridType gridtype);
+    static void writeNewGridToRepr(Inkscape::XML::Node * repr, GridType gridtype);
 
     GridCanvasItem * createCanvasItem(SPDesktop * desktop);
     
index d8215eaa256707720dd5e22eb7891bd72252180c..809f138a8d28d526dc8b1bfd8412d2197f32e1d3 100644 (file)
@@ -430,11 +430,7 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des
     
     if (!grid) {
         //create grid object
-        const char * gridtype = repr->attribute("type");
-        if (!gridtype) {
-            gridtype = "xygrid"; // use this as default gridtype when none is specified
-            repr->setAttribute("type", gridtype);
-        }
+        Inkscape::GridType gridtype = Inkscape::CanvasGrid::getGridTypeFromSVGName(repr->attribute("type"));
         grid = Inkscape::CanvasGrid::NewGrid(nv, repr, gridtype);
         nv->grids = g_slist_append(nv->grids, grid);
     }
index f84b1192071d4276df337c34392abd0e65343d29..4a57c6bfc5013b449ce4330138ac6957bedc333e 100644 (file)
@@ -352,9 +352,10 @@ DocumentProperties::build_gridspage()
     Gtk::Label* label_crea_type = manage (new Gtk::Label);
     label_crea_type->set_markup (_("Gridtype"));
     
-    _grids_combo_gridtype.append_text(Glib::ustring("xygrid"));
-    _grids_combo_gridtype.append_text(Glib::ustring("axonometric"));
-    _grids_combo_gridtype.set_active_text(Glib::ustring("xygrid"));
+    for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
+        _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
+    }
+    _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
     
     Gtk::Label* label_def = manage (new Gtk::Label);
     label_def->set_markup (_("<b>Defined grids</b>"));
@@ -531,7 +532,7 @@ DocumentProperties::onNewGrid()
     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
 
     Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
-    CanvasGrid::writeNewGridToRepr(repr, typestring.c_str());
+    CanvasGrid::writeNewGridToRepr(repr, CanvasGrid::getGridTypeFromName(typestring.c_str()));
 }