summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-04-20 15:48:51 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-04-20 15:48:51 +0000
commitdb4aeda163816cad5029f7a4d37ec82afac27a91 (patch)
treefccd3fa74175d29196128e8688d8d34aa0def771
parentFix emphasized gridlines bug when zoomed out. (diff)
downloadinkscape-db4aeda163816cad5029f7a4d37ec82afac27a91.tar.gz
inkscape-db4aeda163816cad5029f7a4d37ec82afac27a91.zip
grid: make grid names translatable. use different gridtype names in SVG that are not translated.
(bzr r2936)
-rw-r--r--src/desktop.cpp2
-rw-r--r--src/display/canvas-grid.cpp68
-rw-r--r--src/display/canvas-grid.h16
-rw-r--r--src/sp-namedview.cpp6
-rw-r--r--src/ui/dialog/document-properties.cpp9
5 files changed, 80 insertions, 21 deletions
diff --git a/src/desktop.cpp b/src/desktop.cpp
index bd403139e..d9f82934c 100644
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
@@ -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));
}
diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp
index ddc0c7723..30c858dcc 100644
--- a/src/display/canvas-grid.cpp
+++ b/src/display/canvas-grid.cpp
@@ -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;
diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h
index 0dde36935..046653df2 100644
--- a/src/display/canvas-grid.h
+++ b/src/display/canvas-grid.h
@@ -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);
diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp
index d8215eaa2..809f138a8 100644
--- a/src/sp-namedview.cpp
+++ b/src/sp-namedview.cpp
@@ -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);
}
diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp
index f84b11920..4a57c6bfc 100644
--- a/src/ui/dialog/document-properties.cpp
+++ b/src/ui/dialog/document-properties.cpp
@@ -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()));
}