Code

Use frames in the snapping tab in the document properties dialog
[inkscape.git] / src / ui / dialog / document-properties.cpp
1 /** \file
2  *
3  * Document properties dialog, Gtkmm-style
4  *
5  * Authors:
6  *   bulia byak <buliabyak@users.sf.net>
7  *   Bryce W. Harrington <bryce@bryceharrington.org>
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   Jon Phillips <jon@rejon.org>
10  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
11  *
12  * Copyright (C) 2006-2007 Johan Engelen  <johan@shouraizou.nl>
13  * Copyright (C) 2000 - 2005 Authors
14  *
15  * Released under GNU GPL.  Read the file 'COPYING' for more information
16  */
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
24 #include <gtkmm.h>
25 #include "ui/widget/color-picker.h"
26 #include "ui/widget/scalar-unit.h"
28 #include "xml/node-event-vector.h"
29 #include "helper/units.h"
30 #include "prefs-utils.h"
32 #include "inkscape.h"
33 #include "verbs.h"
34 #include "document.h"
35 #include "desktop-handles.h"
36 #include "desktop.h"
37 #include "sp-namedview.h"
39 #include "document-properties.h"
41 #include "display/canvas-grid.h"
43 using std::pair;
45 namespace Inkscape {
46 namespace UI {
47 namespace Dialog {
49 #define SPACE_SIZE_X 15
50 #define SPACE_SIZE_Y 10
52 //===================================================
54 //---------------------------------------------------
56 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
57 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
58 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
60 static Inkscape::XML::NodeEventVector const _repr_events = {
61     on_child_added, /* child_added */
62     on_child_removed, /* child_removed */
63     on_repr_attr_changed,
64     NULL, /* content_changed */
65     NULL  /* order_changed */
66 };
69 DocumentProperties &
70 DocumentProperties::getInstance()
71 {
72     DocumentProperties &instance = *new DocumentProperties();
73     instance.init();
75     return instance;
76 }
78 DocumentProperties::DocumentProperties()
79     : UI::Widget::Panel ("", "dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
80       _page_page(1, 1), _page_guides(1, 1),
81       _page_snap(1, 1), _page_snap_dtls(1, 1),
82       _grids_label_crea("", Gtk::ALIGN_LEFT),
83       _grids_button_new(_("_New"), _("Create new grid.")),
84       _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
85       _grids_label_def("", Gtk::ALIGN_LEFT),
86       _prefs_path("dialogs.documentoptions")
87 {
88     _tt.enable();
89     _getContents()->set_spacing (4);
90     _getContents()->pack_start(_notebook, true, true);
92     _notebook.append_page(_page_page,      _("Page"));
93     _notebook.append_page(_page_guides,    _("Guides"));
94     _notebook.append_page(_grids_vbox,     _("Grids"));
95     _notebook.append_page(_page_snap,      _("Snap"));
96     _notebook.append_page(_page_snap_dtls, _("Snap points"));
98     build_page();
99     build_guides();
100     build_gridspage();
101     build_snap();
102     build_snap_dtls();
104     _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
105     _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
107     signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
108     signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
109     signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
112 void
113 DocumentProperties::init()
115     update();
117     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
118     repr->addListener (&_repr_events, this);
119     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
120     root->addListener (&_repr_events, this);
122     show_all_children();
123     _grids_button_remove.hide();
126 DocumentProperties::~DocumentProperties()
128     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
129     repr->removeListenerByData (this);
130     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
131     root->removeListenerByData (this);
134 //========================================================================
136 /**
137  * Helper function that attaches widgets in a 3xn table. The widgets come in an
138  * array that has two entries per table row. The two entries code for four
139  * possible cases: (0,0) means insert space in first column; (0, non-0) means
140  * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
141  * (non-0, non-0) means two widgets in columns 2 and 3.
142 **/
143 inline void
144 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
146     for (unsigned i = 0, r = start; i < n; i += 2)
147     {
148         if (arr[i] && arr[i+1])
149         {
150             table.attach(*arr[i],   1, 2, r, r+1,
151                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
152             table.attach(*arr[i+1], 2, 3, r, r+1,
153                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
154         }
155         else
156         {
157             if (arr[i+1])
158                 table.attach(*arr[i+1], 1, 3, r, r+1,
159                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
160             else if (arr[i])
161             {
162                 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
163                 label.set_alignment (0.0);
164                 table.attach (label, 0, 3, r, r+1,
165                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
166             }
167             else
168             {
169                 Gtk::HBox *space = manage (new Gtk::HBox);
170                 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
171                 table.attach (*space, 0, 1, r, r+1,
172                       (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
173             }
174         }
175         ++r;
176     }
179 void
180 DocumentProperties::build_page()
182     _page_page.show();
184     _rcp_bg.init (_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"),
185                    "pagecolor", "inkscape:pageopacity", _wr);
186     _rcb_canb.init (_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false);
187     _rcb_bord.init (_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false);
188     _rcp_bord.init (_("Border _color:"), _("Page border color"),
189                     _("Color of the page border"),
190                     "bordercolor", "borderopacity", _wr);
191     _rcb_shad.init (_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false);
192     _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
194     Gtk::Label* label_gen = manage (new Gtk::Label);
195     label_gen->set_markup (_("<b>General</b>"));
196     Gtk::Label* label_bor = manage (new Gtk::Label);
197     label_bor->set_markup (_("<b>Border</b>"));
198     Gtk::Label *label_for = manage (new Gtk::Label);
199     label_for->set_markup (_("<b>Format</b>"));
200     _page_sizer.init (_wr);
202     Gtk::Widget *const widget_array[] =
203     {
204         label_gen,         0,
205         _rum_deflt._label, _rum_deflt._sel,
206         _rcp_bg._label,    _rcp_bg._cp,
207         0,                 0,
208         label_for,         0,
209         0,                 &_page_sizer,
210         0,                 0,
211         label_bor,         0,
212         0,                 _rcb_canb._button,
213         0,                 _rcb_bord._button,
214         0,                 _rcb_shad._button,
215         _rcp_bord._label,  _rcp_bord._cp,
216     };
218     attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
221 void
222 DocumentProperties::build_guides()
224     _page_guides.show();
226     _rcb_sgui.init (_("Show _guides"), _("Show or hide guides"), "showguides", _wr);
227     _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
228                    _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
229     _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
230                     _("Color of a guideline when it is under mouse"),
231                     "guidehicolor", "guidehiopacity", _wr);
232                     
233     _rcbsng.init (_("_Snap guides while dragging"),
234                   _("While dragging a guide, snap to object nodes or bounding box corners ('Nodes' or 'Bounding box corners' must be enabled in the 'Snap' tab)"),
235                   "inkscape:snap-guide", _wr);
236                     
237     Gtk::Label *label_gui = manage (new Gtk::Label);
238     label_gui->set_markup (_("<b>Guides</b>"));
240     Gtk::Widget *const widget_array[] =
241     {
242         label_gui,       0,
243         0,               _rcb_sgui._button,
244         _rcp_gui._label, _rcp_gui._cp,
245         _rcp_hgui._label, _rcp_hgui._cp,
246         0,                  _rcbsng._button,        
247     };
249     attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
252 void
253 DocumentProperties::build_snap()
255     _page_snap.show();
256         //General options
257         _rcbsnbb.init (_("_Bounding box corners"),
258                 _("Snap bounding box corners to grid lines, to guides, and to other bounding boxes (Snapping of bounding boxes is only available in the selector tool)"),
259                 "inkscape:snap-bbox", _wr);
260     _rcbsnn.init (_("_Nodes"),
261                 _("Snap nodes to grid lines, to guides, to paths, and to other nodes"),
262                 "inkscape:snap-nodes", _wr);
264     //Options for snapping to objects
265     _rcbsnop.init (_("Snap to pat_hs"),
266                 _("Snap nodes to object paths"),
267                 "inkscape:object-paths", _wr);
268     _rcbsnon.init (_("Snap to n_odes"),
269                 _("Snap nodes and guides to object nodes"),
270                 "inkscape:object-nodes", _wr);
271     _rcbsnbbn.init (_("Snap to bounding box co_rners"),
272                 _("Snap bounding box corners to other bounding box corners"),
273                 "inkscape:bbox-nodes", _wr);
274     _rcbsnbbp.init (_("Snap to bounding box _edges"),
275                 _("Snap bounding box corners and guides to bounding box edges"),
276                 "inkscape:bbox-paths", _wr);
278     _rsu_sno.init (_("Snap _distance"), _("Snap at any d_istance"),
279                   _("Snapping distance, in screen pixels, for snapping to objects"),
280                   _("If set, objects snap to the nearest object, regardless of distance"),
281                   "objecttolerance", _wr);
283     //Options for snapping to grids
284     _rsu_sn.init (_("Snap di_stance"), _("Snap at any dis_tance"),
285                   _("Snapping distance, in screen pixels, for snapping to grid"),
286                   _("If set, objects snap to the nearest grid line, regardless of distance"),
287                   "gridtolerance", _wr);
289         //Options for snapping to guides
290     _rsu_gusn.init (_("Snap dist_ance"), _("Snap at any distan_ce"),
291                 _("Snapping distance, in screen pixels, for snapping to guides"),
292                 _("If set, objects snap to the nearest guide, regardless of distance"),
293                 "guidetolerance", _wr);
295     //Other options to locate here: e.g. visual snapping indicators on/off
297     std::list<Gtk::ToggleButton*> slaves;
298     slaves.push_back(_rcbsnop._button);
299     slaves.push_back(_rcbsnon._button);
300     _rcbsnn.setSlaveButton(slaves);
302     slaves.clear();
303     slaves.push_back(_rcbsnbbp._button);
304     slaves.push_back(_rcbsnbbn._button);
305     _rcbsnbb.setSlaveButton(slaves);
307     Gtk::Label *label_o = manage (new Gtk::Label);
308     label_o->set_markup (_("Snap to objects"));
309     Gtk::Label *label_gr = manage (new Gtk::Label);
310     label_gr->set_markup (_("Snap to grids"));
311     Gtk::Label *label_gu = manage (new Gtk::Label);
312     label_gu->set_markup (_("Snap to guides"));
313     
314     Gtk::Widget *const array_from[] =
315     {
316         0,                  _rcbsnn._button,
317         0,                  _rcbsnbb._button
318     };
320     attach_all(_snap_table_from, array_from, G_N_ELEMENTS(array_from));
321     
322     _snap_frame_from.set_label(_("What snaps"));
323     _page_snap.pack_start (_snap_frame_from, false, false, 0);
324     _snap_table_from.resize(3, 2);
325     _snap_table_from.set_border_width (4);
326     _snap_table_from.set_row_spacings (4);
327     _snap_table_from.set_col_spacings (4);
328     _snap_frame_from.add(_snap_table_from);
329     
330     Gtk::Widget *const array_to[] =
331     {
332         label_o,            0,
333         0,                  _rcbsnop._button,
334         0,                  _rcbsnon._button,
335         0,                  _rcbsnbbp._button,
336         0,                  _rcbsnbbn._button,
337         0,                  _rsu_sno._vbox,
338         0,                  0,
339         label_gr,           0,
340         0,                  _rsu_sn._vbox,
341         0,                  0,
342         label_gu,           0,
343         0,                  _rsu_gusn._vbox
344     };
345     
346     attach_all(_snap_table_to, array_to, G_N_ELEMENTS(array_to));
347     
348     _snap_frame_to.set_label(_("What to snap to"));
349     _page_snap.pack_start (_snap_frame_to, false, false, 0);
350     _snap_table_to.resize(3, 2);
351     _snap_table_to.set_border_width (4);
352     _snap_table_to.set_row_spacings (4);
353     _snap_table_to.set_col_spacings (4);
354     _snap_frame_to.add(_snap_table_to);
355  }
357 void
358 DocumentProperties::build_snap_dtls()
360     _page_snap_dtls.show();
361         
362         _rcbsigg.init (_("_Grid with guides"),
363                 _("Snap to grid-guide intersections"),
364                 "inkscape:snap-intersection-grid-guide", _wr);
365         
366         _rcbsils.init (_("_Line segments"),
367                 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
368                 "inkscape:snap-intersection-line-segments", _wr);
369     
370     //Applies to both nodes and guides, but not to bboxes, that's why its located here
371     _rcbic.init (_("_Include the object's rotation center"),
372                 _("Also snap the rotation center of an object when snapping nodes or guides"),
373                 "inkscape:snap-center", _wr);
374     
375     //Other options to locate here: e.g. visual snapping indicators on/off
377     Gtk::Label *label_i= manage (new Gtk::Label);
378     label_i->set_markup (_("<b>Snap to intersections of</b>"));
379     Gtk::Label *label_m = manage (new Gtk::Label);
380     label_m->set_markup (_("<b>Miscellaneous</b>"));
382     Gtk::Widget *const array[] =
383     {
384         label_i,            0,
385         0,                  _rcbsigg._button,
386         0,                  _rcbsils._button,
387         0,                  0,
388         label_m,            0,
389         0,                  _rcbic._button,
390     };
392     attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
395 /**
396 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
397 */
398 void
399 DocumentProperties::update_gridspage()
401     SPDesktop *dt = getDesktop();
402     SPNamedView *nv = sp_desktop_namedview(dt);
404     //remove all tabs
405     while (_grids_notebook.get_current_page() != -1) {
406         _grids_notebook.remove_page(-1);
407     }
409     //add tabs
410     bool grids_present = false;
411     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
412         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
413         _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
414         grids_present = true;
415     }
416     _grids_notebook.show_all();
418     if (grids_present)
419         _grids_button_remove.show();
420     else
421         _grids_button_remove.hide();
424 /**
425  * Build grid page of dialog.
426  */
427 void
428 DocumentProperties::build_gridspage()
430     /// \todo FIXME: gray out snapping when grid is off.
431     /// Dissenting view: you want snapping without grid.
433     SPDesktop *dt = getDesktop();
434     SPNamedView *nv = sp_desktop_namedview(dt);
436     _grids_label_crea.set_markup(_("<b>Creation</b>"));
437     _grids_label_def.set_markup(_("<b>Defined grids</b>"));
438     _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
439     _grids_hbox_crea.pack_start(_grids_button_new, true, true);
441     for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
442         _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
443     }
444     _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
446     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
447         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
448         _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
449     }
451     _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
453     _grids_vbox.set_spacing(4);
454     _grids_vbox.pack_start(_grids_label_crea, false, false);
455     _grids_vbox.pack_start(_grids_hbox_crea, false, false);
456     _grids_vbox.pack_start(_grids_space, false, false);
457     _grids_vbox.pack_start(_grids_label_def, false, false);
458     _grids_vbox.pack_start(_grids_notebook, false, false);
459     _grids_vbox.pack_start(_grids_button_remove, false, false);
460     _grids_button_remove.hide();
465 /**
466  * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
467  */
468 void
469 DocumentProperties::update()
471     if (_wr.isUpdating()) return;
473     SPDesktop *dt = getDesktop();
474     SPNamedView *nv = sp_desktop_namedview(dt);
476     _wr.setUpdating (true);
477     set_sensitive (true);
479     //-----------------------------------------------------------page page
480     _rcp_bg.setRgba32 (nv->pagecolor);
481     _rcb_canb.setActive (nv->showborder);
482     _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
483     _rcp_bord.setRgba32 (nv->bordercolor);
484     _rcb_shad.setActive (nv->showpageshadow);
486     if (nv->doc_units)
487         _rum_deflt.setUnit (nv->doc_units);
489     double const doc_w_px = sp_document_width(sp_desktop_document(dt));
490     double const doc_h_px = sp_document_height(sp_desktop_document(dt));
491     _page_sizer.setDim (doc_w_px, doc_h_px);
493     //-----------------------------------------------------------guide
494     _rcb_sgui.setActive (nv->showguides);
495     _rcp_gui.setRgba32 (nv->guidecolor);
496     _rcp_hgui.setRgba32 (nv->guidehicolor);
498     //-----------------------------------------------------------snap
500     _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
501     _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
502     _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
503     _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
504     _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
505     _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());    
506     _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
507     _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
508     _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
509     _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
510     _rsu_sno.setValue (nv->objecttolerance);
512     _rsu_sn.setValue (nv->gridtolerance);
514     _rsu_gusn.setValue (nv->guidetolerance);
516     //-----------------------------------------------------------grids page
518     update_gridspage();
520     _wr.setUpdating (false);
523 //--------------------------------------------------------------------
525 void
526 DocumentProperties::on_response (int id)
528     if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
529     {
530         _rcp_bg.closeWindow();
531         _rcp_bord.closeWindow();
532         _rcp_gui.closeWindow();
533         _rcp_hgui.closeWindow();
534     }
536     if (id == Gtk::RESPONSE_CLOSE)
537         hide();
540 void 
541 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
543     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
544     repr->addListener(&_repr_events, this);
545     Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
546     root->addListener(&_repr_events, this);
547     update();
550 void 
551 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
553     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
554     repr->addListener(&_repr_events, this);
555     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
556     root->addListener(&_repr_events, this);
557     update();
560 void
561 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
563     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
564     repr->removeListenerByData(this);
565     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
566     root->removeListenerByData(this);
569 static void
570 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
572     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
573         dialog->update_gridspage();
576 static void
577 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
579     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
580         dialog->update_gridspage();
585 /**
586  * Called when XML node attribute changed; updates dialog widgets.
587  */
588 static void
589 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
591     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
592         dialog->update();
596 /*########################################################################
597 # BUTTON CLICK HANDLERS    (callbacks)
598 ########################################################################*/
600 void
601 DocumentProperties::onNewGrid()
603     SPDesktop *dt = getDesktop();
604     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
605     SPDocument *doc = sp_desktop_document(dt);
607     Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
608     CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
612 void
613 DocumentProperties::onRemoveGrid()
615     gint pagenum = _grids_notebook.get_current_page();
616     if (pagenum == -1) // no pages
617       return;
619     Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
620     if (!page) return;
622     Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
624     // find the grid with name tabtext (it's id) and delete that one.
625     SPDesktop *dt = getDesktop();
626     SPNamedView *nv = sp_desktop_namedview(dt);
627     Inkscape::CanvasGrid * found_grid = NULL;
628     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
629         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
630         gchar const *idtext = grid->repr->attribute("id");
631         if ( !strcmp(tabtext.c_str(), idtext) ) {
632             found_grid = grid;
633             break; // break out of for-loop
634         }
635     }
636     if (found_grid) {
637         // delete the grid that corresponds with the selected tab
638         // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
639         found_grid->repr->parent()->removeChild(found_grid->repr);
640         sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
641     }
645 } // namespace Dialog
646 } // namespace UI
647 } // namespace Inkscape
649 /*
650   Local Variables:
651   mode:c++
652   c-file-style:"stroustrup"
653   c-file-offsets:((innamespace . 0)(inline-open . 0))
654   indent-tabs-mode:nilu
655   fill-column:99
656   End:
657 */
658 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :