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));
110 }
112 void
113 DocumentProperties::init()
114 {
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();
124 }
126 DocumentProperties::~DocumentProperties()
127 {
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);
132 }
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)
145 {
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 }
177 }
179 void
180 DocumentProperties::build_page()
181 {
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));
219 }
221 void
222 DocumentProperties::build_guides()
223 {
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);
233 _rcbsng.init (_("_Snap guides while dragging"),
234 _("While dragging a guide, snap to object nodes or bounding box corners ('Snap to nodes' or 'snap to bounding box corners' must be enabled in the 'Snap' tab)"),
235 "inkscape:snap-guide", _wr);
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));
250 }
252 void
253 DocumentProperties::build_snap()
254 {
255 _page_snap.show();
256 //General options
257 _rcbsg.init (_("Enable snapping"),
258 _("Toggle snapping on or off"),
259 "inkscape:snap-global", _wr);
260 _rcbsnbb.init (_("_Bounding box corners"),
261 _("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)"),
262 "inkscape:snap-bbox", _wr);
263 _rcbsnn.init (_("_Nodes"),
264 _("Snap nodes to grid lines, to guides, to paths, and to other nodes"),
265 "inkscape:snap-nodes", _wr);
267 //Options for snapping to objects
268 _rcbsnop.init (_("Snap to pat_hs"),
269 _("Snap nodes to object paths"),
270 "inkscape:object-paths", _wr);
271 _rcbsnon.init (_("Snap to n_odes"),
272 _("Snap nodes and guides to object nodes"),
273 "inkscape:object-nodes", _wr);
274 _rcbsnbbn.init (_("Snap to bounding box co_rners"),
275 _("Snap bounding box corners to other bounding box corners"),
276 "inkscape:bbox-nodes", _wr);
277 _rcbsnbbp.init (_("Snap to bounding box _edges"),
278 _("Snap bounding box corners and guides to bounding box edges"),
279 "inkscape:bbox-paths", _wr);
281 _rsu_sno.init (_("Snap _distance"), _("Snap at specified d_istance"),
282 _("Snapping distance, in screen pixels, for snapping to objects"),
283 _("If set, objects only snap to another object when it's within the range specified below"),
284 "objecttolerance", _wr);
286 //Options for snapping to grids
287 _rsu_sn.init (_("Snap di_stance"), _("Snap at specified dis_tance"),
288 _("Snapping distance, in screen pixels, for snapping to grid"),
289 _("If set, objects only snap to a grid line when it's within the range specified below"),
290 "gridtolerance", _wr);
292 //Options for snapping to guides
293 _rsu_gusn.init (_("Snap dist_ance"), _("Snap at specified distan_ce"),
294 _("Snapping distance, in screen pixels, for snapping to guides"),
295 _("If set, objects only snap to a guide when it's within the range specified below"),
296 "guidetolerance", _wr);
298 //Other options to locate here: e.g. visual snapping indicators on/off
300 std::list<Gtk::ToggleButton*> slaves;
301 slaves.push_back(_rcbsnop._button);
302 slaves.push_back(_rcbsnon._button);
303 _rcbsnn.setSlaveButton(slaves);
305 slaves.clear();
306 slaves.push_back(_rcbsnbbp._button);
307 slaves.push_back(_rcbsnbbn._button);
308 _rcbsnbb.setSlaveButton(slaves);
310 slaves.clear();
311 slaves.push_back(_rcbsnn._button);
312 slaves.push_back(_rcbsnbb._button);
314 _rcbsg.setSlaveButton(slaves);
316 Gtk::Label *label_g = manage (new Gtk::Label);
317 label_g->set_markup (_("<b>Snapping</b>"));
318 Gtk::Label *label_w = manage (new Gtk::Label);
319 label_w->set_markup (_("<b>What snaps</b>"));
320 Gtk::Label *label_o = manage (new Gtk::Label);
321 label_o->set_markup (_("<b>Snap to objects</b>"));
322 Gtk::Label *label_gr = manage (new Gtk::Label);
323 label_gr->set_markup (_("<b>Snap to grids</b>"));
324 Gtk::Label *label_gu = manage (new Gtk::Label);
325 label_gu->set_markup (_("<b>Snap to guides</b>"));
327 Gtk::Widget *const array[] =
328 {
329 label_g, 0,
330 0, _rcbsg._button,
331 0, 0,
332 label_w, 0,
333 0, _rcbsnn._button,
334 0, _rcbsnbb._button,
335 0, 0,
336 label_o, 0,
337 0, _rcbsnop._button,
338 0, _rcbsnon._button,
339 0, _rcbsnbbp._button,
340 0, _rcbsnbbn._button,
341 0, _rsu_sno._vbox,
342 0, 0,
343 label_gr, 0,
344 0, _rsu_sn._vbox,
345 0, 0,
346 label_gu, 0,
347 0, _rsu_gusn._vbox
348 };
350 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
351 }
353 void
354 DocumentProperties::build_snap_dtls()
355 {
356 _page_snap_dtls.show();
358 _rcbsigg.init (_("_Grid with guides"),
359 _("Snap to grid-guide intersections"),
360 "inkscape:snap-intersection-grid-guide", _wr);
362 _rcbsils.init (_("_Line segments"),
363 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
364 "inkscape:snap-intersection-line-segments", _wr);
366 //Applies to both nodes and guides, but not to bboxes, that's why its located here
367 _rcbic.init (_("_Include the object's rotation center"),
368 _("Also snap the rotation center of an object when snapping nodes or guides"),
369 "inkscape:snap-center", _wr);
371 //Other options to locate here: e.g. visual snapping indicators on/off
373 Gtk::Label *label_i= manage (new Gtk::Label);
374 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
375 Gtk::Label *label_m = manage (new Gtk::Label);
376 label_m->set_markup (_("<b>Miscellaneous</b>"));
378 Gtk::Widget *const array[] =
379 {
380 label_i, 0,
381 0, _rcbsigg._button,
382 0, _rcbsils._button,
383 0, 0,
384 label_m, 0,
385 0, _rcbic._button,
386 };
388 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
389 }
391 /**
392 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
393 */
394 void
395 DocumentProperties::update_gridspage()
396 {
397 SPDesktop *dt = getDesktop();
398 SPNamedView *nv = sp_desktop_namedview(dt);
400 //remove all tabs
401 while (_grids_notebook.get_current_page() != -1) {
402 _grids_notebook.remove_page(-1);
403 }
405 //add tabs
406 bool grids_present = false;
407 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
408 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
409 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
410 grids_present = true;
411 }
412 _grids_notebook.show_all();
414 if (grids_present)
415 _grids_button_remove.show();
416 else
417 _grids_button_remove.hide();
418 }
420 /**
421 * Build grid page of dialog.
422 */
423 void
424 DocumentProperties::build_gridspage()
425 {
426 /// \todo FIXME: gray out snapping when grid is off.
427 /// Dissenting view: you want snapping without grid.
429 SPDesktop *dt = getDesktop();
430 SPNamedView *nv = sp_desktop_namedview(dt);
432 _grids_label_crea.set_markup(_("<b>Creation</b>"));
433 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
434 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
435 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
437 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
438 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
439 }
440 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
442 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
443 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
444 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
445 }
447 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
449 _grids_vbox.set_spacing(4);
450 _grids_vbox.pack_start(_grids_label_crea, false, false);
451 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
452 _grids_vbox.pack_start(_grids_space, false, false);
453 _grids_vbox.pack_start(_grids_label_def, false, false);
454 _grids_vbox.pack_start(_grids_notebook, false, false);
455 _grids_vbox.pack_start(_grids_button_remove, false, false);
456 _grids_button_remove.hide();
457 }
461 /**
462 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
463 */
464 void
465 DocumentProperties::update()
466 {
467 if (_wr.isUpdating()) return;
469 SPDesktop *dt = getDesktop();
470 SPNamedView *nv = sp_desktop_namedview(dt);
472 _wr.setUpdating (true);
473 set_sensitive (true);
475 //-----------------------------------------------------------page page
476 _rcp_bg.setRgba32 (nv->pagecolor);
477 _rcb_canb.setActive (nv->showborder);
478 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
479 _rcp_bord.setRgba32 (nv->bordercolor);
480 _rcb_shad.setActive (nv->showpageshadow);
482 if (nv->doc_units)
483 _rum_deflt.setUnit (nv->doc_units);
485 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
486 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
487 _page_sizer.setDim (doc_w_px, doc_h_px);
489 //-----------------------------------------------------------guide
490 _rcb_sgui.setActive (nv->showguides);
491 _rcp_gui.setRgba32 (nv->guidecolor);
492 _rcp_hgui.setRgba32 (nv->guidehicolor);
494 //-----------------------------------------------------------snap
496 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
497 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
498 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
499 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
500 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
501 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
502 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
503 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
504 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
505 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
506 _rsu_sno.setValue (nv->objecttolerance);
508 _rsu_sn.setValue (nv->gridtolerance);
510 _rsu_gusn.setValue (nv->guidetolerance);
512 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
514 //-----------------------------------------------------------grids page
516 update_gridspage();
518 _wr.setUpdating (false);
519 }
521 //--------------------------------------------------------------------
523 void
524 DocumentProperties::on_response (int id)
525 {
526 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
527 {
528 _rcp_bg.closeWindow();
529 _rcp_bord.closeWindow();
530 _rcp_gui.closeWindow();
531 _rcp_hgui.closeWindow();
532 }
534 if (id == Gtk::RESPONSE_CLOSE)
535 hide();
536 }
538 void
539 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
540 {
541 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
542 repr->addListener(&_repr_events, this);
543 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
544 root->addListener(&_repr_events, this);
545 update();
546 }
548 void
549 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
550 {
551 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
552 repr->addListener(&_repr_events, this);
553 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
554 root->addListener(&_repr_events, this);
555 update();
556 }
558 void
559 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
560 {
561 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
562 repr->removeListenerByData(this);
563 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
564 root->removeListenerByData(this);
565 }
567 static void
568 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
569 {
570 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
571 dialog->update_gridspage();
572 }
574 static void
575 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
576 {
577 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
578 dialog->update_gridspage();
579 }
583 /**
584 * Called when XML node attribute changed; updates dialog widgets.
585 */
586 static void
587 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
588 {
589 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
590 dialog->update();
591 }
594 /*########################################################################
595 # BUTTON CLICK HANDLERS (callbacks)
596 ########################################################################*/
598 void
599 DocumentProperties::onNewGrid()
600 {
601 SPDesktop *dt = getDesktop();
602 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
603 SPDocument *doc = sp_desktop_document(dt);
605 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
606 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
607 }
610 void
611 DocumentProperties::onRemoveGrid()
612 {
613 gint pagenum = _grids_notebook.get_current_page();
614 if (pagenum == -1) // no pages
615 return;
617 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
618 if (!page) return;
620 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
622 // find the grid with name tabtext (it's id) and delete that one.
623 SPDesktop *dt = getDesktop();
624 SPNamedView *nv = sp_desktop_namedview(dt);
625 Inkscape::CanvasGrid * found_grid = NULL;
626 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
627 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
628 gchar const *idtext = grid->repr->attribute("id");
629 if ( !strcmp(tabtext.c_str(), idtext) ) {
630 found_grid = grid;
631 break; // break out of for-loop
632 }
633 }
634 if (found_grid) {
635 // delete the grid that corresponds with the selected tab
636 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
637 found_grid->repr->parent()->removeChild(found_grid->repr);
638 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
639 }
640 }
643 } // namespace Dialog
644 } // namespace UI
645 } // namespace Inkscape
647 /*
648 Local Variables:
649 mode:c++
650 c-file-style:"stroustrup"
651 c-file-offsets:((innamespace . 0)(inline-open . 0))
652 indent-tabs-mode:nilu
653 fill-column:99
654 End:
655 */
656 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :