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), _page_grids(1, 1),
97 _grids_button_new(_("_New"), _("Create new grid.")),
98 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
99 _prefs_path("dialogs.documentoptions")
100 {
101 _tt.enable();
102 _getContents()->set_spacing (4);
103 _getContents()->pack_start(_notebook, true, true);
105 _notebook.append_page(_page_page, _("Page"));
106 _notebook.append_page(_page_guides, _("Guides"));
107 _notebook.append_page(_page_grids, _("Grids"));
108 _notebook.append_page(_page_snap, _("Snap"));
109 _notebook.append_page(_page_snap_dtls, _("Snap details"));
111 build_page();
112 build_guides();
113 build_gridspage();
114 build_snap();
115 build_snap_dtls();
117 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
118 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
119 }
121 void
122 DocumentProperties::init()
123 {
124 update();
126 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
127 repr->addListener (&_repr_events, this);
128 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
129 root->addListener (&_repr_events, this);
131 _doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
133 g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
134 G_CALLBACK(on_activate_desktop), 0);
136 g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop",
137 G_CALLBACK(on_deactivate_desktop), 0);
139 show_all_children();
140 }
142 DocumentProperties::~DocumentProperties()
143 {
144 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
145 repr->removeListenerByData (this);
146 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
147 root->removeListenerByData (this);
148 _doc_replaced_connection.disconnect();
149 }
151 //========================================================================
153 /**
154 * Helper function that attaches widgets in a 3xn table. The widgets come in an
155 * array that has two entries per table row. The two entries code for four
156 * possible cases: (0,0) means insert space in first column; (0, non-0) means
157 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
158 * (non-0, non-0) means two widgets in columns 2 and 3.
159 **/
160 inline void
161 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
162 {
163 for (unsigned i = 0, r = start; i < n; i += 2)
164 {
165 if (arr[i] && arr[i+1])
166 {
167 table.attach(*arr[i], 1, 2, r, r+1,
168 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
169 table.attach(*arr[i+1], 2, 3, r, r+1,
170 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
171 }
172 else
173 {
174 if (arr[i+1])
175 table.attach(*arr[i+1], 1, 3, r, r+1,
176 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
177 else if (arr[i])
178 {
179 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
180 label.set_alignment (0.0);
181 table.attach (label, 0, 3, r, r+1,
182 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
183 }
184 else
185 {
186 Gtk::HBox *space = manage (new Gtk::HBox);
187 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
188 table.attach (*space, 0, 1, r, r+1,
189 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
190 }
191 }
192 ++r;
193 }
194 }
196 void
197 DocumentProperties::build_page()
198 {
199 _page_page.show();
201 _rcp_bg.init (_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"),
202 "pagecolor", "inkscape:pageopacity", _wr);
203 _rcb_canb.init (_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false);
204 _rcb_bord.init (_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false);
205 _rcp_bord.init (_("Border _color:"), _("Page border color"),
206 _("Color of the page border"),
207 "bordercolor", "borderopacity", _wr);
208 _rcb_shad.init (_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false);
209 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
211 Gtk::Label* label_gen = manage (new Gtk::Label);
212 label_gen->set_markup (_("<b>General</b>"));
213 Gtk::Label* label_bor = manage (new Gtk::Label);
214 label_bor->set_markup (_("<b>Border</b>"));
215 Gtk::Label *label_for = manage (new Gtk::Label);
216 label_for->set_markup (_("<b>Format</b>"));
217 _page_sizer.init (_wr);
219 Gtk::Widget *const widget_array[] =
220 {
221 label_gen, 0,
222 _rum_deflt._label, _rum_deflt._sel,
223 _rcp_bg._label, _rcp_bg._cp,
224 0, 0,
225 label_for, 0,
226 0, &_page_sizer,
227 0, 0,
228 label_bor, 0,
229 0, _rcb_canb._button,
230 0, _rcb_bord._button,
231 0, _rcb_shad._button,
232 _rcp_bord._label, _rcp_bord._cp,
233 };
235 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
236 }
238 void
239 DocumentProperties::build_guides()
240 {
241 _page_guides.show();
243 _rcb_sgui.init (_("Show _guides"), _("Show or hide guides"), "showguides", _wr);
244 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
245 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
246 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
247 _("Color of a guideline when it is under mouse"),
248 "guidehicolor", "guidehiopacity", _wr);
249 Gtk::Label *label_gui = manage (new Gtk::Label);
250 label_gui->set_markup (_("<b>Guides</b>"));
252 Gtk::Widget *const widget_array[] =
253 {
254 label_gui, 0,
255 0, _rcb_sgui._button,
256 _rcp_gui._label, _rcp_gui._cp,
257 _rcp_hgui._label, _rcp_hgui._cp,
258 };
260 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
261 }
263 void
264 DocumentProperties::build_snap()
265 {
266 _page_snap.show();
267 //General options
268 _rcbsnbb.init (_("_Bounding box corners"),
269 _("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)"),
270 "inkscape:snap-bbox", _wr);
271 _rcbsnn.init (_("_Nodes"),
272 _("Snap nodes to grid lines, to guides, to paths, and to other nodes"),
273 "inkscape:snap-nodes", _wr);
275 //Options for snapping to objects
276 _rcbsnop.init (_("Snap to pat_hs"),
277 _("Snap nodes to object paths"),
278 "inkscape:object-paths", _wr);
279 _rcbsnon.init (_("Snap to n_odes"),
280 _("Snap nodes and guides to object nodes"),
281 "inkscape:object-nodes", _wr);
282 _rcbsnbbn.init (_("Snap to bounding box co_rners"),
283 _("Snap bounding box corners to other bounding box corners"),
284 "inkscape:bbox-nodes", _wr);
285 _rcbsnbbp.init (_("Snap to bounding box _edges"),
286 _("Snap bounding box corners and guides to bounding box edges"),
287 "inkscape:bbox-paths", _wr);
289 _rsu_sno.init (_("Snap _distance"), _("Snap at any d_istance"),
290 _("Snapping distance, in screen pixels, for snapping to objects"),
291 _("If set, objects snap to the nearest object, regardless of distance"),
292 "objecttolerance", _wr);
294 //Options for snapping to grids
295 _rsu_sn.init (_("Snap di_stance"), _("Snap at any dis_tance"),
296 _("Snapping distance, in screen pixels, for snapping to grid"),
297 _("If set, objects snap to the nearest grid line, regardless of distance"),
298 "gridtolerance", _wr);
300 //Options for snapping to guides
301 _rsu_gusn.init (_("Snap dist_ance"), _("Snap at any distan_ce"),
302 _("Snapping distance, in screen pixels, for snapping to guides"),
303 _("If set, objects snap to the nearest guide, regardless of distance"),
304 "guidetolerance", _wr);
306 //Other options to locate here: e.g. visual snapping indicators on/off
308 std::list<Gtk::ToggleButton*> slaves;
309 slaves.push_back(_rcbsnop._button);
310 slaves.push_back(_rcbsnon._button);
311 _rcbsnn.setSlaveButton(slaves);
313 slaves.clear();
314 slaves.push_back(_rcbsnbbp._button);
315 slaves.push_back(_rcbsnbbn._button);
316 _rcbsnbb.setSlaveButton(slaves);
318 Gtk::Label *label_g = manage (new Gtk::Label);
319 label_g->set_markup (_("<b>Snapping of</b>"));
320 Gtk::Label *label_o = manage (new Gtk::Label);
321 label_o->set_markup (_("<b>Snapping to objects</b>"));
322 Gtk::Label *label_gr = manage (new Gtk::Label);
323 label_gr->set_markup (_("<b>Snapping to grids</b>"));
324 Gtk::Label *label_gu = manage (new Gtk::Label);
325 label_gu->set_markup (_("<b>Snapping to guides</b>"));
326 Gtk::Label *label_m = manage (new Gtk::Label);
327 label_m->set_markup (_("<b>Miscellaneous</b>"));
329 Gtk::Widget *const array[] =
330 {
331 label_g, 0,
332 0, _rcbsnn._button,
333 0, _rcbsnbb._button,
334 0, 0,
335 0, 0,
336 0, 0,
337 0, 0,
338 label_o, 0,
339 0, _rcbsnop._button,
340 0, _rcbsnon._button,
341 0, _rcbsnbbp._button,
342 0, _rcbsnbbn._button,
343 0, _rsu_sno._vbox,
344 0, 0,
345 label_gr, 0,
346 0, _rsu_sn._vbox,
347 0, 0,
348 label_gu, 0,
349 0, _rsu_gusn._vbox
350 };
352 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
353 }
355 void
356 DocumentProperties::build_snap_dtls()
357 {
358 _page_snap_dtls.show();
360 _rcbsigg.init (_("_Grid with guides"),
361 _("Snap to grid-guide intersections"),
362 "inkscape:snap-intersection-grid-guide", _wr);
364 _rcbsils.init (_("_Line segments"),
365 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
366 "inkscape:snap-intersection-line-segments", _wr);
368 _rcbsng.init (_("_Snap guides while dragging"),
369 _("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)"),
370 "inkscape:snap-guide", _wr);
372 //Applies to both nodes and guides, but not to bboxes, that's why its located here
373 _rcbic.init (_("_Include the object's rotation center"),
374 _("Also snap the rotation center of an object when snapping nodes or guides"),
375 "inkscape:snap-center", _wr);
377 //Other options to locate here: e.g. visual snapping indicators on/off
379 Gtk::Label *label_i= manage (new Gtk::Label);
380 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
381 Gtk::Label *label_m = manage (new Gtk::Label);
382 label_m->set_markup (_("<b>Miscellaneous</b>"));
384 Gtk::Widget *const array[] =
385 {
386 label_i, 0,
387 0, _rcbsigg._button,
388 0, _rcbsils._button,
389 0, 0,
390 label_m, 0,
391 0, _rcbsng._button,
392 0, _rcbic._button,
393 };
395 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
396 }
398 /**
399 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
400 */
401 void
402 DocumentProperties::update_gridspage()
403 {
404 SPDesktop *dt = SP_ACTIVE_DESKTOP;
405 SPNamedView *nv = sp_desktop_namedview(dt);
407 //remove all tabs
408 while (_grids_notebook.get_current_page() != -1) {
409 _grids_notebook.remove_page(-1);
410 }
412 //add tabs
413 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
414 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
415 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
417 }
418 _grids_notebook.show_all();
420 _page_grids.table().resize_children();
421 }
423 /**
424 * Build grid page of dialog.
425 */
426 void
427 DocumentProperties::build_gridspage()
428 {
429 _page_grids.show();
431 /// \todo FIXME: gray out snapping when grid is off.
432 /// Dissenting view: you want snapping without grid.
434 SPDesktop *dt = SP_ACTIVE_DESKTOP;
435 SPNamedView *nv = sp_desktop_namedview(dt);
437 Gtk::Label* label_crea = manage (new Gtk::Label);
438 label_crea->set_markup (_("<b>Creation</b>"));
439 Gtk::Label* label_crea_type = manage (new Gtk::Label);
440 label_crea_type->set_markup (_("Gridtype"));
442 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
443 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
444 }
445 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
447 Gtk::Label* label_def = manage (new Gtk::Label);
448 label_def->set_markup (_("<b>Defined grids</b>"));
450 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
451 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
452 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
453 }
455 Gtk::Widget *const widget_array[] =
456 {
457 label_crea, 0,
458 label_crea_type, (Gtk::Widget*) &_grids_combo_gridtype,
459 (Gtk::Widget*) &_grids_button_new, (Gtk::Widget*) &_grids_button_remove,
460 label_def, 0
461 };
462 attach_all(_page_grids.table(), widget_array, G_N_ELEMENTS(widget_array));
463 _page_grids.table().attach(_grids_notebook, 0, 3, 4, 5, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
464 }
468 /**
469 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
470 */
471 void
472 DocumentProperties::update()
473 {
474 if (_wr.isUpdating()) return;
476 SPDesktop *dt = SP_ACTIVE_DESKTOP;
477 SPNamedView *nv = sp_desktop_namedview(dt);
479 _wr.setUpdating (true);
480 set_sensitive (true);
482 //-----------------------------------------------------------page page
483 _rcp_bg.setRgba32 (nv->pagecolor);
484 _rcb_canb.setActive (nv->showborder);
485 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
486 _rcp_bord.setRgba32 (nv->bordercolor);
487 _rcb_shad.setActive (nv->showpageshadow);
489 if (nv->doc_units)
490 _rum_deflt.setUnit (nv->doc_units);
492 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
493 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
494 _page_sizer.setDim (doc_w_px, doc_h_px);
496 //-----------------------------------------------------------guide
497 _rcb_sgui.setActive (nv->showguides);
498 _rcp_gui.setRgba32 (nv->guidecolor);
499 _rcp_hgui.setRgba32 (nv->guidehicolor);
501 //-----------------------------------------------------------snap
503 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
504 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
505 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
506 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
507 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
508 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
509 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
510 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
511 _rsu_sno.setValue (nv->objecttolerance);
513 _rsu_sn.setValue (nv->gridtolerance);
515 _rsu_gusn.setValue (nv->guidetolerance);
517 //-----------------------------------------------------------grids page
519 update_gridspage();
521 _wr.setUpdating (false);
522 }
524 //--------------------------------------------------------------------
526 void
527 DocumentProperties::on_response (int id)
528 {
529 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
530 {
531 _rcp_bg.closeWindow();
532 _rcp_bord.closeWindow();
533 _rcp_gui.closeWindow();
534 _rcp_hgui.closeWindow();
535 }
537 if (id == Gtk::RESPONSE_CLOSE)
538 hide();
539 }
543 static void
544 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
545 {
546 if (!_instance)
547 return;
549 _instance->update_gridspage();
550 }
552 static void
553 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void * /*data*/)
554 {
555 if (!_instance)
556 return;
558 _instance->update_gridspage();
559 }
563 /**
564 * Called when XML node attribute changed; updates dialog widgets.
565 */
566 static void
567 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
568 {
569 if (!_instance)
570 return;
572 _instance->update();
573 }
575 static void
576 on_activate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
577 {
578 if (!_instance)
579 return;
581 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
582 repr->addListener (&_repr_events, _instance);
583 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
584 root->addListener (&_repr_events, _instance);
585 _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
586 _instance->update();
587 }
589 static void
590 on_deactivate_desktop (Inkscape::Application *, SPDesktop* /*dt*/, void*)
591 {
592 if (!_instance)
593 return;
595 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
596 repr->removeListenerByData (_instance);
597 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
598 root->removeListenerByData (_instance);
599 _instance->_doc_replaced_connection.disconnect();
600 }
602 static void
603 on_doc_replaced (SPDesktop* dt, SPDocument* doc)
604 {
605 if (!_instance)
606 return;
608 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
609 repr->addListener (&_repr_events, _instance);
610 Inkscape::XML::Node *root = SP_OBJECT_REPR(doc->root);
611 root->addListener (&_repr_events, _instance);
612 _instance->update();
613 }
618 /*########################################################################
619 # BUTTON CLICK HANDLERS (callbacks)
620 ########################################################################*/
622 void
623 DocumentProperties::onNewGrid()
624 {
625 SPDesktop *dt = SP_ACTIVE_DESKTOP;
626 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
627 SPDocument *doc = sp_desktop_document(dt);
629 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
630 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
631 }
634 void
635 DocumentProperties::onRemoveGrid()
636 {
637 gint pagenum = _grids_notebook.get_current_page();
638 if (pagenum == -1) // no pages
639 return;
641 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
642 if (!page) return;
644 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
646 // find the grid with name tabtext (it's id) and delete that one.
647 SPDesktop *dt = SP_ACTIVE_DESKTOP;
648 SPNamedView *nv = sp_desktop_namedview(dt);
649 Inkscape::CanvasGrid * found_grid = NULL;
650 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
651 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
652 gchar const *idtext = grid->repr->attribute("id");
653 if ( !strcmp(tabtext.c_str(), idtext) ) {
654 found_grid = grid;
655 break; // break out of for-loop
656 }
657 }
658 if (found_grid) {
659 // delete the grid that corresponds with the selected tab
660 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
661 found_grid->repr->parent()->removeChild(found_grid->repr);
662 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
663 }
664 }
667 } // namespace Dialog
668 } // namespace UI
669 } // namespace Inkscape
671 /*
672 Local Variables:
673 mode:c++
674 c-file-style:"stroustrup"
675 c-file-offsets:((innamespace . 0)(inline-open . 0))
676 indent-tabs-mode:nilu
677 fill-column:99
678 End:
679 */
680 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :