aa608703ad01bc58ed8bffb39d2194cf6c79afbc
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 DocumentProperties *_instance = 0;
58 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
59 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
60 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
61 static void on_doc_replaced (SPDesktop* dt, SPDocument* doc);
62 static void on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
63 static void on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
65 static Inkscape::XML::NodeEventVector const _repr_events = {
66 on_child_added, /* child_added */
67 on_child_removed, /* child_removed */
68 on_repr_attr_changed,
69 NULL, /* content_changed */
70 NULL /* order_changed */
71 };
74 DocumentProperties &
75 DocumentProperties::getInstance()
76 {
77 if (_instance) return *_instance;
78 _instance = new DocumentProperties();
79 _instance->init();
80 return *_instance;
81 }
83 void
84 DocumentProperties::destroy()
85 {
86 if (_instance)
87 {
88 delete _instance;
89 _instance = 0;
90 }
91 }
93 DocumentProperties::DocumentProperties()
94 : UI::Widget::Panel ("", "dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
95 _page_page(1, 1), _page_guides(1, 1),
96 _page_snap(1, 1), _page_snap_dtls(1, 1),
97 _grids_label_crea("", Gtk::ALIGN_LEFT),
98 _grids_button_new(_("_New"), _("Create new grid.")),
99 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
100 _grids_label_def("", Gtk::ALIGN_LEFT),
101 _prefs_path("dialogs.documentoptions")
102 {
103 _tt.enable();
104 _getContents()->set_spacing (4);
105 _getContents()->pack_start(_notebook, true, true);
107 _notebook.append_page(_page_page, _("Page"));
108 _notebook.append_page(_page_guides, _("Guides"));
109 _notebook.append_page(_grids_vbox, _("Grids"));
110 _notebook.append_page(_page_snap, _("Snap"));
111 _notebook.append_page(_page_snap_dtls, _("Snap points"));
113 build_page();
114 build_guides();
115 build_gridspage();
116 build_snap();
117 build_snap_dtls();
119 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
120 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
121 }
123 void
124 DocumentProperties::init()
125 {
126 update();
128 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
129 repr->addListener (&_repr_events, this);
130 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
131 root->addListener (&_repr_events, this);
133 _doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
135 g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
136 G_CALLBACK(on_activate_desktop), 0);
138 g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop",
139 G_CALLBACK(on_deactivate_desktop), 0);
141 show_all_children();
142 _grids_button_remove.hide();
143 }
145 DocumentProperties::~DocumentProperties()
146 {
147 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
148 repr->removeListenerByData (this);
149 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
150 root->removeListenerByData (this);
151 _doc_replaced_connection.disconnect();
152 }
154 //========================================================================
156 /**
157 * Helper function that attaches widgets in a 3xn table. The widgets come in an
158 * array that has two entries per table row. The two entries code for four
159 * possible cases: (0,0) means insert space in first column; (0, non-0) means
160 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
161 * (non-0, non-0) means two widgets in columns 2 and 3.
162 **/
163 inline void
164 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
165 {
166 for (unsigned i = 0, r = start; i < n; i += 2)
167 {
168 if (arr[i] && arr[i+1])
169 {
170 table.attach(*arr[i], 1, 2, r, r+1,
171 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
172 table.attach(*arr[i+1], 2, 3, r, r+1,
173 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
174 }
175 else
176 {
177 if (arr[i+1])
178 table.attach(*arr[i+1], 1, 3, r, r+1,
179 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
180 else if (arr[i])
181 {
182 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
183 label.set_alignment (0.0);
184 table.attach (label, 0, 3, r, r+1,
185 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
186 }
187 else
188 {
189 Gtk::HBox *space = manage (new Gtk::HBox);
190 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
191 table.attach (*space, 0, 1, r, r+1,
192 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
193 }
194 }
195 ++r;
196 }
197 }
199 void
200 DocumentProperties::build_page()
201 {
202 _page_page.show();
204 _rcp_bg.init (_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"),
205 "pagecolor", "inkscape:pageopacity", _wr);
206 _rcb_canb.init (_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false);
207 _rcb_bord.init (_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false);
208 _rcp_bord.init (_("Border _color:"), _("Page border color"),
209 _("Color of the page border"),
210 "bordercolor", "borderopacity", _wr);
211 _rcb_shad.init (_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false);
212 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
214 Gtk::Label* label_gen = manage (new Gtk::Label);
215 label_gen->set_markup (_("<b>General</b>"));
216 Gtk::Label* label_bor = manage (new Gtk::Label);
217 label_bor->set_markup (_("<b>Border</b>"));
218 Gtk::Label *label_for = manage (new Gtk::Label);
219 label_for->set_markup (_("<b>Format</b>"));
220 _page_sizer.init (_wr);
222 Gtk::Widget *const widget_array[] =
223 {
224 label_gen, 0,
225 _rum_deflt._label, _rum_deflt._sel,
226 _rcp_bg._label, _rcp_bg._cp,
227 0, 0,
228 label_for, 0,
229 0, &_page_sizer,
230 0, 0,
231 label_bor, 0,
232 0, _rcb_canb._button,
233 0, _rcb_bord._button,
234 0, _rcb_shad._button,
235 _rcp_bord._label, _rcp_bord._cp,
236 };
238 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
239 }
241 void
242 DocumentProperties::build_guides()
243 {
244 _page_guides.show();
246 _rcb_sgui.init (_("Show _guides"), _("Show or hide guides"), "showguides", _wr);
247 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
248 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
249 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
250 _("Color of a guideline when it is under mouse"),
251 "guidehicolor", "guidehiopacity", _wr);
253 _rcbsng.init (_("_Snap guides while dragging"),
254 _("While dragging a guide, snap to object nodes or bounding box corners ('Nodes' or 'Bounding box corners' must be enabled in the 'Snap' tab)"),
255 "inkscape:snap-guide", _wr);
257 Gtk::Label *label_gui = manage (new Gtk::Label);
258 label_gui->set_markup (_("<b>Guides</b>"));
260 Gtk::Widget *const widget_array[] =
261 {
262 label_gui, 0,
263 0, _rcb_sgui._button,
264 _rcp_gui._label, _rcp_gui._cp,
265 _rcp_hgui._label, _rcp_hgui._cp,
266 0, _rcbsng._button,
267 };
269 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
270 }
272 void
273 DocumentProperties::build_snap()
274 {
275 _page_snap.show();
276 //General options
277 _rcbsnbb.init (_("_Bounding box corners"),
278 _("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)"),
279 "inkscape:snap-bbox", _wr);
280 _rcbsnn.init (_("_Nodes"),
281 _("Snap nodes to grid lines, to guides, to paths, and to other nodes"),
282 "inkscape:snap-nodes", _wr);
284 //Options for snapping to objects
285 _rcbsnop.init (_("Snap to pat_hs"),
286 _("Snap nodes to object paths"),
287 "inkscape:object-paths", _wr);
288 _rcbsnon.init (_("Snap to n_odes"),
289 _("Snap nodes and guides to object nodes"),
290 "inkscape:object-nodes", _wr);
291 _rcbsnbbn.init (_("Snap to bounding box co_rners"),
292 _("Snap bounding box corners to other bounding box corners"),
293 "inkscape:bbox-nodes", _wr);
294 _rcbsnbbp.init (_("Snap to bounding box _edges"),
295 _("Snap bounding box corners and guides to bounding box edges"),
296 "inkscape:bbox-paths", _wr);
298 _rsu_sno.init (_("Snap _distance"), _("Snap at any d_istance"),
299 _("Snapping distance, in screen pixels, for snapping to objects"),
300 _("If set, objects snap to the nearest object, regardless of distance"),
301 "objecttolerance", _wr);
303 //Options for snapping to grids
304 _rsu_sn.init (_("Snap di_stance"), _("Snap at any dis_tance"),
305 _("Snapping distance, in screen pixels, for snapping to grid"),
306 _("If set, objects snap to the nearest grid line, regardless of distance"),
307 "gridtolerance", _wr);
309 //Options for snapping to guides
310 _rsu_gusn.init (_("Snap dist_ance"), _("Snap at any distan_ce"),
311 _("Snapping distance, in screen pixels, for snapping to guides"),
312 _("If set, objects snap to the nearest guide, regardless of distance"),
313 "guidetolerance", _wr);
315 //Other options to locate here: e.g. visual snapping indicators on/off
317 std::list<Gtk::ToggleButton*> slaves;
318 slaves.push_back(_rcbsnop._button);
319 slaves.push_back(_rcbsnon._button);
320 _rcbsnn.setSlaveButton(slaves);
322 slaves.clear();
323 slaves.push_back(_rcbsnbbp._button);
324 slaves.push_back(_rcbsnbbn._button);
325 _rcbsnbb.setSlaveButton(slaves);
327 Gtk::Label *label_g = manage (new Gtk::Label);
328 label_g->set_markup (_("<b>Snapping of</b>"));
329 Gtk::Label *label_o = manage (new Gtk::Label);
330 label_o->set_markup (_("<b>Snapping to objects</b>"));
331 Gtk::Label *label_gr = manage (new Gtk::Label);
332 label_gr->set_markup (_("<b>Snapping to grids</b>"));
333 Gtk::Label *label_gu = manage (new Gtk::Label);
334 label_gu->set_markup (_("<b>Snapping to guides</b>"));
335 Gtk::Label *label_m = manage (new Gtk::Label);
336 label_m->set_markup (_("<b>Miscellaneous</b>"));
338 Gtk::Widget *const array[] =
339 {
340 label_g, 0,
341 0, _rcbsnn._button,
342 0, _rcbsnbb._button,
343 0, 0,
344 0, 0,
345 0, 0,
346 0, 0,
347 label_o, 0,
348 0, _rcbsnop._button,
349 0, _rcbsnon._button,
350 0, _rcbsnbbp._button,
351 0, _rcbsnbbn._button,
352 0, _rsu_sno._vbox,
353 0, 0,
354 label_gr, 0,
355 0, _rsu_sn._vbox,
356 0, 0,
357 label_gu, 0,
358 0, _rsu_gusn._vbox
359 };
361 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
362 }
364 void
365 DocumentProperties::build_snap_dtls()
366 {
367 _page_snap_dtls.show();
369 _rcbsigg.init (_("_Grid with guides"),
370 _("Snap to grid-guide intersections"),
371 "inkscape:snap-intersection-grid-guide", _wr);
373 _rcbsils.init (_("_Line segments"),
374 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
375 "inkscape:snap-intersection-line-segments", _wr);
377 //Applies to both nodes and guides, but not to bboxes, that's why its located here
378 _rcbic.init (_("_Include the object's rotation center"),
379 _("Also snap the rotation center of an object when snapping nodes or guides"),
380 "inkscape:snap-center", _wr);
382 //Other options to locate here: e.g. visual snapping indicators on/off
384 Gtk::Label *label_i= manage (new Gtk::Label);
385 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
386 Gtk::Label *label_m = manage (new Gtk::Label);
387 label_m->set_markup (_("<b>Miscellaneous</b>"));
389 Gtk::Widget *const array[] =
390 {
391 label_i, 0,
392 0, _rcbsigg._button,
393 0, _rcbsils._button,
394 0, 0,
395 label_m, 0,
396 0, _rcbic._button,
397 };
399 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
400 }
402 /**
403 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
404 */
405 void
406 DocumentProperties::update_gridspage()
407 {
408 SPDesktop *dt = SP_ACTIVE_DESKTOP;
409 SPNamedView *nv = sp_desktop_namedview(dt);
411 //remove all tabs
412 while (_grids_notebook.get_current_page() != -1) {
413 _grids_notebook.remove_page(-1);
414 }
416 //add tabs
417 bool grids_present = false;
418 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
419 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
420 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
421 grids_present = true;
422 }
423 _grids_notebook.show_all();
425 if (grids_present)
426 _grids_button_remove.show();
427 else
428 _grids_button_remove.hide();
429 }
431 /**
432 * Build grid page of dialog.
433 */
434 void
435 DocumentProperties::build_gridspage()
436 {
437 /// \todo FIXME: gray out snapping when grid is off.
438 /// Dissenting view: you want snapping without grid.
440 SPDesktop *dt = SP_ACTIVE_DESKTOP;
441 SPNamedView *nv = sp_desktop_namedview(dt);
443 _grids_label_crea.set_markup(_("<b>Creation</b>"));
444 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
445 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
446 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
448 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
449 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
450 }
451 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
453 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
454 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
455 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
456 }
458 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
460 _grids_vbox.set_spacing(4);
461 _grids_vbox.pack_start(_grids_label_crea, false, false);
462 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
463 _grids_vbox.pack_start(_grids_space, false, false);
464 _grids_vbox.pack_start(_grids_label_def, false, false);
465 _grids_vbox.pack_start(_grids_notebook, false, false);
466 _grids_vbox.pack_start(_grids_button_remove, false, false);
467 _grids_button_remove.hide();
468 }
472 /**
473 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
474 */
475 void
476 DocumentProperties::update()
477 {
478 if (_wr.isUpdating()) return;
480 SPDesktop *dt = SP_ACTIVE_DESKTOP;
481 SPNamedView *nv = sp_desktop_namedview(dt);
483 _wr.setUpdating (true);
484 set_sensitive (true);
486 //-----------------------------------------------------------page page
487 _rcp_bg.setRgba32 (nv->pagecolor);
488 _rcb_canb.setActive (nv->showborder);
489 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
490 _rcp_bord.setRgba32 (nv->bordercolor);
491 _rcb_shad.setActive (nv->showpageshadow);
493 if (nv->doc_units)
494 _rum_deflt.setUnit (nv->doc_units);
496 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
497 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
498 _page_sizer.setDim (doc_w_px, doc_h_px);
500 //-----------------------------------------------------------guide
501 _rcb_sgui.setActive (nv->showguides);
502 _rcp_gui.setRgba32 (nv->guidecolor);
503 _rcp_hgui.setRgba32 (nv->guidehicolor);
505 //-----------------------------------------------------------snap
507 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
508 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
509 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
510 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
511 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
512 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
513 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
514 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
515 _rsu_sno.setValue (nv->objecttolerance);
517 _rsu_sn.setValue (nv->gridtolerance);
519 _rsu_gusn.setValue (nv->guidetolerance);
521 //-----------------------------------------------------------grids page
523 update_gridspage();
525 _wr.setUpdating (false);
526 }
528 //--------------------------------------------------------------------
530 void
531 DocumentProperties::on_response (int id)
532 {
533 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
534 {
535 _rcp_bg.closeWindow();
536 _rcp_bord.closeWindow();
537 _rcp_gui.closeWindow();
538 _rcp_hgui.closeWindow();
539 }
541 if (id == Gtk::RESPONSE_CLOSE)
542 hide();
543 }
547 static void
548 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
549 {
550 if (!_instance)
551 return;
553 _instance->update_gridspage();
554 }
556 static void
557 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
558 {
559 if (!_instance)
560 return;
562 _instance->update_gridspage();
563 }
567 /**
568 * Called when XML node attribute changed; updates dialog widgets.
569 */
570 static void
571 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
572 {
573 if (!_instance)
574 return;
576 _instance->update();
577 }
579 static void
580 on_activate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
581 {
582 if (!_instance)
583 return;
585 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
586 repr->addListener (&_repr_events, _instance);
587 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
588 root->addListener (&_repr_events, _instance);
589 _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
590 _instance->update();
591 }
593 static void
594 on_deactivate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
595 {
596 if (!_instance)
597 return;
599 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
600 repr->removeListenerByData (_instance);
601 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
602 root->removeListenerByData (_instance);
603 _instance->_doc_replaced_connection.disconnect();
604 }
606 static void
607 on_doc_replaced (SPDesktop* dt, SPDocument* doc)
608 {
609 if (!_instance)
610 return;
612 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
613 repr->addListener (&_repr_events, _instance);
614 Inkscape::XML::Node *root = SP_OBJECT_REPR(doc->root);
615 root->addListener (&_repr_events, _instance);
616 _instance->update();
617 }
622 /*########################################################################
623 # BUTTON CLICK HANDLERS (callbacks)
624 ########################################################################*/
626 void
627 DocumentProperties::onNewGrid()
628 {
629 SPDesktop *dt = SP_ACTIVE_DESKTOP;
630 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
631 SPDocument *doc = sp_desktop_document(dt);
633 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
634 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
635 }
638 void
639 DocumentProperties::onRemoveGrid()
640 {
641 gint pagenum = _grids_notebook.get_current_page();
642 if (pagenum == -1) // no pages
643 return;
645 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
646 if (!page) return;
648 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
650 // find the grid with name tabtext (it's id) and delete that one.
651 SPDesktop *dt = SP_ACTIVE_DESKTOP;
652 SPNamedView *nv = sp_desktop_namedview(dt);
653 Inkscape::CanvasGrid * found_grid = NULL;
654 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
655 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
656 gchar const *idtext = grid->repr->attribute("id");
657 if ( !strcmp(tabtext.c_str(), idtext) ) {
658 found_grid = grid;
659 break; // break out of for-loop
660 }
661 }
662 if (found_grid) {
663 // delete the grid that corresponds with the selected tab
664 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
665 found_grid->repr->parent()->removeChild(found_grid->repr);
666 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
667 }
668 }
671 } // namespace Dialog
672 } // namespace UI
673 } // namespace Inkscape
675 /*
676 Local Variables:
677 mode:c++
678 c-file-style:"stroustrup"
679 c-file-offsets:((innamespace . 0)(inline-open . 0))
680 indent-tabs-mode:nilu
681 fill-column:99
682 End:
683 */
684 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :