5ffe3dcb89bccf3b3d72e5254caac96cc932c41f
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 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
410 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
411 grids_present = true;
412 }
413 _grids_notebook.show_all();
415 if (grids_present)
416 _grids_button_remove.show();
417 else
418 _grids_button_remove.hide();
419 }
421 /**
422 * Build grid page of dialog.
423 */
424 void
425 DocumentProperties::build_gridspage()
426 {
427 /// \todo FIXME: gray out snapping when grid is off.
428 /// Dissenting view: you want snapping without grid.
430 SPDesktop *dt = getDesktop();
431 SPNamedView *nv = sp_desktop_namedview(dt);
433 _grids_label_crea.set_markup(_("<b>Creation</b>"));
434 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
435 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
436 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
438 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
439 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
440 }
441 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
443 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
444 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
445 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
446 }
448 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
450 _grids_vbox.set_spacing(4);
451 _grids_vbox.pack_start(_grids_label_crea, false, false);
452 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
453 _grids_vbox.pack_start(_grids_space, false, false);
454 _grids_vbox.pack_start(_grids_label_def, false, false);
455 _grids_vbox.pack_start(_grids_notebook, false, false);
456 _grids_vbox.pack_start(_grids_button_remove, false, false);
457 _grids_button_remove.hide();
458 }
462 /**
463 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
464 */
465 void
466 DocumentProperties::update()
467 {
468 if (_wr.isUpdating()) return;
470 SPDesktop *dt = getDesktop();
471 SPNamedView *nv = sp_desktop_namedview(dt);
473 _wr.setUpdating (true);
474 set_sensitive (true);
476 //-----------------------------------------------------------page page
477 _rcp_bg.setRgba32 (nv->pagecolor);
478 _rcb_canb.setActive (nv->showborder);
479 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
480 _rcp_bord.setRgba32 (nv->bordercolor);
481 _rcb_shad.setActive (nv->showpageshadow);
483 if (nv->doc_units)
484 _rum_deflt.setUnit (nv->doc_units);
486 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
487 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
488 _page_sizer.setDim (doc_w_px, doc_h_px);
490 //-----------------------------------------------------------guide
491 _rcb_sgui.setActive (nv->showguides);
492 _rcp_gui.setRgba32 (nv->guidecolor);
493 _rcp_hgui.setRgba32 (nv->guidehicolor);
495 //-----------------------------------------------------------snap
497 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
498 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
499 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
500 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
501 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
502 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
503 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
504 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
505 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
506 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
507 _rsu_sno.setValue (nv->objecttolerance);
509 _rsu_sn.setValue (nv->gridtolerance);
511 _rsu_gusn.setValue (nv->guidetolerance);
513 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
515 //-----------------------------------------------------------grids page
517 update_gridspage();
519 _wr.setUpdating (false);
520 }
522 //--------------------------------------------------------------------
524 void
525 DocumentProperties::on_response (int id)
526 {
527 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
528 {
529 _rcp_bg.closeWindow();
530 _rcp_bord.closeWindow();
531 _rcp_gui.closeWindow();
532 _rcp_hgui.closeWindow();
533 }
535 if (id == Gtk::RESPONSE_CLOSE)
536 hide();
537 }
539 void
540 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
541 {
542 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
543 repr->addListener(&_repr_events, this);
544 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
545 root->addListener(&_repr_events, this);
546 update();
547 }
549 void
550 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
551 {
552 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
553 repr->addListener(&_repr_events, this);
554 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
555 root->addListener(&_repr_events, this);
556 update();
557 }
559 void
560 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
561 {
562 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
563 repr->removeListenerByData(this);
564 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
565 root->removeListenerByData(this);
566 }
568 static void
569 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
570 {
571 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
572 dialog->update_gridspage();
573 }
575 static void
576 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
577 {
578 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
579 dialog->update_gridspage();
580 }
584 /**
585 * Called when XML node attribute changed; updates dialog widgets.
586 */
587 static void
588 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
589 {
590 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
591 dialog->update();
592 }
595 /*########################################################################
596 # BUTTON CLICK HANDLERS (callbacks)
597 ########################################################################*/
599 void
600 DocumentProperties::onNewGrid()
601 {
602 SPDesktop *dt = getDesktop();
603 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
604 SPDocument *doc = sp_desktop_document(dt);
606 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
607 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
608 }
611 void
612 DocumentProperties::onRemoveGrid()
613 {
614 gint pagenum = _grids_notebook.get_current_page();
615 if (pagenum == -1) // no pages
616 return;
618 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
619 if (!page) return;
621 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
623 // find the grid with name tabtext (it's id) and delete that one.
624 SPDesktop *dt = getDesktop();
625 SPNamedView *nv = sp_desktop_namedview(dt);
626 Inkscape::CanvasGrid * found_grid = NULL;
627 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
628 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
629 gchar const *idtext = grid->repr->attribute("id");
630 if ( !strcmp(tabtext.c_str(), idtext) ) {
631 found_grid = grid;
632 break; // break out of for-loop
633 }
634 }
635 if (found_grid) {
636 // delete the grid that corresponds with the selected tab
637 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
638 found_grid->repr->parent()->removeChild(found_grid->repr);
639 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
640 }
641 }
644 } // namespace Dialog
645 } // namespace UI
646 } // namespace Inkscape
648 /*
649 Local Variables:
650 mode:c++
651 c-file-style:"stroustrup"
652 c-file-offsets:((innamespace . 0)(inline-open . 0))
653 indent-tabs-mode:nilu
654 fill-column:99
655 End:
656 */
657 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :