a3e9d6eea745542ae1bf1a309c04633eda23ce8a
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 details"));
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);
252 Gtk::Label *label_gui = manage (new Gtk::Label);
253 label_gui->set_markup (_("<b>Guides</b>"));
255 Gtk::Widget *const widget_array[] =
256 {
257 label_gui, 0,
258 0, _rcb_sgui._button,
259 _rcp_gui._label, _rcp_gui._cp,
260 _rcp_hgui._label, _rcp_hgui._cp,
261 };
263 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
264 }
266 void
267 DocumentProperties::build_snap()
268 {
269 _page_snap.show();
270 //General options
271 _rcbsnbb.init (_("_Bounding box corners"),
272 _("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)"),
273 "inkscape:snap-bbox", _wr);
274 _rcbsnn.init (_("_Nodes"),
275 _("Snap nodes to grid lines, to guides, to paths, and to other nodes"),
276 "inkscape:snap-nodes", _wr);
278 //Options for snapping to objects
279 _rcbsnop.init (_("Snap to pat_hs"),
280 _("Snap nodes to object paths"),
281 "inkscape:object-paths", _wr);
282 _rcbsnon.init (_("Snap to n_odes"),
283 _("Snap nodes and guides to object nodes"),
284 "inkscape:object-nodes", _wr);
285 _rcbsnbbn.init (_("Snap to bounding box co_rners"),
286 _("Snap bounding box corners to other bounding box corners"),
287 "inkscape:bbox-nodes", _wr);
288 _rcbsnbbp.init (_("Snap to bounding box _edges"),
289 _("Snap bounding box corners and guides to bounding box edges"),
290 "inkscape:bbox-paths", _wr);
292 _rsu_sno.init (_("Snap _distance"), _("Snap at any d_istance"),
293 _("Snapping distance, in screen pixels, for snapping to objects"),
294 _("If set, objects snap to the nearest object, regardless of distance"),
295 "objecttolerance", _wr);
297 //Options for snapping to grids
298 _rsu_sn.init (_("Snap di_stance"), _("Snap at any dis_tance"),
299 _("Snapping distance, in screen pixels, for snapping to grid"),
300 _("If set, objects snap to the nearest grid line, regardless of distance"),
301 "gridtolerance", _wr);
303 //Options for snapping to guides
304 _rsu_gusn.init (_("Snap dist_ance"), _("Snap at any distan_ce"),
305 _("Snapping distance, in screen pixels, for snapping to guides"),
306 _("If set, objects snap to the nearest guide, regardless of distance"),
307 "guidetolerance", _wr);
309 //Other options to locate here: e.g. visual snapping indicators on/off
311 std::list<Gtk::ToggleButton*> slaves;
312 slaves.push_back(_rcbsnop._button);
313 slaves.push_back(_rcbsnon._button);
314 _rcbsnn.setSlaveButton(slaves);
316 slaves.clear();
317 slaves.push_back(_rcbsnbbp._button);
318 slaves.push_back(_rcbsnbbn._button);
319 _rcbsnbb.setSlaveButton(slaves);
321 Gtk::Label *label_g = manage (new Gtk::Label);
322 label_g->set_markup (_("<b>Snapping of</b>"));
323 Gtk::Label *label_o = manage (new Gtk::Label);
324 label_o->set_markup (_("<b>Snapping to objects</b>"));
325 Gtk::Label *label_gr = manage (new Gtk::Label);
326 label_gr->set_markup (_("<b>Snapping to grids</b>"));
327 Gtk::Label *label_gu = manage (new Gtk::Label);
328 label_gu->set_markup (_("<b>Snapping to guides</b>"));
329 Gtk::Label *label_m = manage (new Gtk::Label);
330 label_m->set_markup (_("<b>Miscellaneous</b>"));
332 Gtk::Widget *const array[] =
333 {
334 label_g, 0,
335 0, _rcbsnn._button,
336 0, _rcbsnbb._button,
337 0, 0,
338 0, 0,
339 0, 0,
340 0, 0,
341 label_o, 0,
342 0, _rcbsnop._button,
343 0, _rcbsnon._button,
344 0, _rcbsnbbp._button,
345 0, _rcbsnbbn._button,
346 0, _rsu_sno._vbox,
347 0, 0,
348 label_gr, 0,
349 0, _rsu_sn._vbox,
350 0, 0,
351 label_gu, 0,
352 0, _rsu_gusn._vbox
353 };
355 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
356 }
358 void
359 DocumentProperties::build_snap_dtls()
360 {
361 _page_snap_dtls.show();
363 _rcbsigg.init (_("_Grid with guides"),
364 _("Snap to grid-guide intersections"),
365 "inkscape:snap-intersection-grid-guide", _wr);
367 _rcbsils.init (_("_Line segments"),
368 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
369 "inkscape:snap-intersection-line-segments", _wr);
371 _rcbsng.init (_("_Snap guides while dragging"),
372 _("While dragging a guide, snap to object nodes or bounding box corners ('snap to nodes' or 'snap to bounding box corners', both on the previous tab, must be enabled)"),
373 "inkscape:snap-guide", _wr);
375 //Applies to both nodes and guides, but not to bboxes, that's why its located here
376 _rcbic.init (_("_Include the object's rotation center"),
377 _("Also snap the rotation center of an object when snapping nodes or guides"),
378 "inkscape:snap-center", _wr);
380 //Other options to locate here: e.g. visual snapping indicators on/off
382 Gtk::Label *label_i= manage (new Gtk::Label);
383 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
384 Gtk::Label *label_m = manage (new Gtk::Label);
385 label_m->set_markup (_("<b>Miscellaneous</b>"));
387 Gtk::Widget *const array[] =
388 {
389 label_i, 0,
390 0, _rcbsigg._button,
391 0, _rcbsils._button,
392 0, 0,
393 label_m, 0,
394 0, _rcbsng._button,
395 0, _rcbic._button,
396 };
398 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
399 }
401 /**
402 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
403 */
404 void
405 DocumentProperties::update_gridspage()
406 {
407 SPDesktop *dt = SP_ACTIVE_DESKTOP;
408 SPNamedView *nv = sp_desktop_namedview(dt);
410 //remove all tabs
411 while (_grids_notebook.get_current_page() != -1) {
412 _grids_notebook.remove_page(-1);
413 }
415 //add tabs
416 bool grids_present = false;
417 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
418 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
419 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
420 grids_present = true;
421 }
422 _grids_notebook.show_all();
424 if (grids_present)
425 _grids_button_remove.show();
426 else
427 _grids_button_remove.hide();
428 }
430 /**
431 * Build grid page of dialog.
432 */
433 void
434 DocumentProperties::build_gridspage()
435 {
436 /// \todo FIXME: gray out snapping when grid is off.
437 /// Dissenting view: you want snapping without grid.
439 SPDesktop *dt = SP_ACTIVE_DESKTOP;
440 SPNamedView *nv = sp_desktop_namedview(dt);
442 _grids_label_crea.set_markup(_("<b>Creation</b>"));
443 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
444 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
445 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
447 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
448 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
449 }
450 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
452 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
453 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
454 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
455 }
457 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
459 _grids_vbox.set_spacing(4);
460 _grids_vbox.pack_start(_grids_label_crea, false, false);
461 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
462 _grids_vbox.pack_start(_grids_space, false, false);
463 _grids_vbox.pack_start(_grids_label_def, false, false);
464 _grids_vbox.pack_start(_grids_notebook, false, false);
465 _grids_vbox.pack_start(_grids_button_remove, false, false);
466 _grids_button_remove.hide();
467 }
471 /**
472 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
473 */
474 void
475 DocumentProperties::update()
476 {
477 if (_wr.isUpdating()) return;
479 SPDesktop *dt = SP_ACTIVE_DESKTOP;
480 SPNamedView *nv = sp_desktop_namedview(dt);
482 _wr.setUpdating (true);
483 set_sensitive (true);
485 //-----------------------------------------------------------page page
486 _rcp_bg.setRgba32 (nv->pagecolor);
487 _rcb_canb.setActive (nv->showborder);
488 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
489 _rcp_bord.setRgba32 (nv->bordercolor);
490 _rcb_shad.setActive (nv->showpageshadow);
492 if (nv->doc_units)
493 _rum_deflt.setUnit (nv->doc_units);
495 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
496 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
497 _page_sizer.setDim (doc_w_px, doc_h_px);
499 //-----------------------------------------------------------guide
500 _rcb_sgui.setActive (nv->showguides);
501 _rcp_gui.setRgba32 (nv->guidecolor);
502 _rcp_hgui.setRgba32 (nv->guidehicolor);
504 //-----------------------------------------------------------snap
506 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
507 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
508 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
509 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
510 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
511 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
512 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
513 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
514 _rsu_sno.setValue (nv->objecttolerance);
516 _rsu_sn.setValue (nv->gridtolerance);
518 _rsu_gusn.setValue (nv->guidetolerance);
520 //-----------------------------------------------------------grids page
522 update_gridspage();
524 _wr.setUpdating (false);
525 }
527 //--------------------------------------------------------------------
529 void
530 DocumentProperties::on_response (int id)
531 {
532 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
533 {
534 _rcp_bg.closeWindow();
535 _rcp_bord.closeWindow();
536 _rcp_gui.closeWindow();
537 _rcp_hgui.closeWindow();
538 }
540 if (id == Gtk::RESPONSE_CLOSE)
541 hide();
542 }
546 static void
547 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
548 {
549 if (!_instance)
550 return;
552 _instance->update_gridspage();
553 }
555 static void
556 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
557 {
558 if (!_instance)
559 return;
561 _instance->update_gridspage();
562 }
566 /**
567 * Called when XML node attribute changed; updates dialog widgets.
568 */
569 static void
570 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
571 {
572 if (!_instance)
573 return;
575 _instance->update();
576 }
578 static void
579 on_activate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
580 {
581 if (!_instance)
582 return;
584 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
585 repr->addListener (&_repr_events, _instance);
586 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
587 root->addListener (&_repr_events, _instance);
588 _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
589 _instance->update();
590 }
592 static void
593 on_deactivate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
594 {
595 if (!_instance)
596 return;
598 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
599 repr->removeListenerByData (_instance);
600 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
601 root->removeListenerByData (_instance);
602 _instance->_doc_replaced_connection.disconnect();
603 }
605 static void
606 on_doc_replaced (SPDesktop* dt, SPDocument* doc)
607 {
608 if (!_instance)
609 return;
611 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
612 repr->addListener (&_repr_events, _instance);
613 Inkscape::XML::Node *root = SP_OBJECT_REPR(doc->root);
614 root->addListener (&_repr_events, _instance);
615 _instance->update();
616 }
621 /*########################################################################
622 # BUTTON CLICK HANDLERS (callbacks)
623 ########################################################################*/
625 void
626 DocumentProperties::onNewGrid()
627 {
628 SPDesktop *dt = SP_ACTIVE_DESKTOP;
629 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
630 SPDocument *doc = sp_desktop_document(dt);
632 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
633 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
634 }
637 void
638 DocumentProperties::onRemoveGrid()
639 {
640 gint pagenum = _grids_notebook.get_current_page();
641 if (pagenum == -1) // no pages
642 return;
644 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
645 if (!page) return;
647 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
649 // find the grid with name tabtext (it's id) and delete that one.
650 SPDesktop *dt = SP_ACTIVE_DESKTOP;
651 SPNamedView *nv = sp_desktop_namedview(dt);
652 Inkscape::CanvasGrid * found_grid = NULL;
653 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
654 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
655 gchar const *idtext = grid->repr->attribute("id");
656 if ( !strcmp(tabtext.c_str(), idtext) ) {
657 found_grid = grid;
658 break; // break out of for-loop
659 }
660 }
661 if (found_grid) {
662 // delete the grid that corresponds with the selected tab
663 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
664 found_grid->repr->parent()->removeChild(found_grid->repr);
665 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
666 }
667 }
670 } // namespace Dialog
671 } // namespace UI
672 } // namespace Inkscape
674 /*
675 Local Variables:
676 mode:c++
677 c-file-style:"stroustrup"
678 c-file-offsets:((innamespace . 0)(inline-open . 0))
679 indent-tabs-mode:nilu
680 fill-column:99
681 End:
682 */
683 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :