Code

When no grid is defined but "toggle grid" is pressed => create a default rectangular...
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 15 Apr 2007 20:57:15 +0000 (20:57 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 15 Apr 2007 20:57:15 +0000 (20:57 +0000)
src/desktop.cpp

index a9c4e5d7f7d244c82bba42fbda1121e9bfdcff89..5ab682cd09f13e33d6c90c120d6c93965109548c 100644 (file)
@@ -1105,13 +1105,21 @@ void SPDesktop::clearWaitingCursor()
 
 void SPDesktop::toggleGrid()
 {
-    if(gridgroup) {
-        grids_visible = !grids_visible;
-        if (grids_visible) {
-            sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup));
-        } else {
-            sp_canvas_item_hide(SP_CANVAS_ITEM(gridgroup));
+    if (namedview->grids) {
+        if(gridgroup) {
+            grids_visible = !grids_visible;
+            if (grids_visible) {
+                sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup));
+            } else {
+                sp_canvas_item_hide(SP_CANVAS_ITEM(gridgroup));
+            }
         }
+    } 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");
+        grids_visible = true;
+        sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup));
     }
 }