4f8db942d41e707bdbc6dc263ba26d7505d9ff91
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::create(Behavior::BehaviorFactory behavior_factory)
76 {
77 if (_instance) return _instance;
78 _instance = new DocumentProperties(behavior_factory);
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(Behavior::BehaviorFactory behavior_factory)
94 : Dialog (behavior_factory, "dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
95 _page_page(1, 1), _page_guides(1, 1),
96 _page_snap(1, 1), _page_grids(1, 1), _page_snap_dtls(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 set_resizable (false);
102 _tt.enable();
103 get_vbox()->set_spacing (4);
104 get_vbox()->pack_start (_notebook, true, true);
106 _notebook.append_page(_page_page, _("Page"));
107 _notebook.append_page(_page_guides, _("Guides"));
108 _notebook.append_page(_page_grids, _("Grids"));
109 _notebook.append_page(_page_snap, _("Snap"));
110 _notebook.append_page(_page_snap_dtls, _("Snap details"));
112 build_page();
113 build_guides();
114 build_gridspage();
115 build_snap();
116 build_snap_dtls();
118 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
119 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
120 }
122 void
123 DocumentProperties::init()
124 {
125 update();
127 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
128 repr->addListener (&_repr_events, this);
129 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
130 root->addListener (&_repr_events, this);
132 _doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
134 g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
135 G_CALLBACK(on_activate_desktop), 0);
137 g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop",
138 G_CALLBACK(on_deactivate_desktop), 0);
140 show_all_children();
142 present();
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 _rcbsng.init (_("_Snap guides while dragging"),
364 _("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)"),
365 "inkscape:snap-guide", _wr);
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);
370 //Applies to both nodes and guides, but not to bboxes, that's why its located here
372 //Other options to locate here: e.g. visual snapping indicators on/off
374 Gtk::Label *label_i= manage (new Gtk::Label);
375 label_i->set_markup (_("<b>Snapping to intersections</b>"));
376 Gtk::Label *label_m = manage (new Gtk::Label);
377 label_m->set_markup (_("<b>Miscellaneous</b>"));
379 Gtk::Widget *const array[] =
380 {
381 label_i, 0,
382 0, 0,
383 0, 0,
384 label_m, 0,
385 0, _rcbsng._button,
386 0, _rcbic._button,
387 };
389 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
390 }
392 /**
393 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
394 */
395 void
396 DocumentProperties::update_gridspage()
397 {
398 SPDesktop *dt = SP_ACTIVE_DESKTOP;
399 SPNamedView *nv = sp_desktop_namedview(dt);
401 //remove all tabs
402 while (_grids_notebook.get_current_page() != -1) {
403 _grids_notebook.remove_page(-1);
404 }
406 //add tabs
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"));
411 }
412 _grids_notebook.show_all();
414 _page_grids.table().resize_children();
415 }
417 /**
418 * Build grid page of dialog.
419 */
420 void
421 DocumentProperties::build_gridspage()
422 {
423 _page_grids.show();
425 /// \todo FIXME: gray out snapping when grid is off.
426 /// Dissenting view: you want snapping without grid.
428 SPDesktop *dt = SP_ACTIVE_DESKTOP;
429 SPNamedView *nv = sp_desktop_namedview(dt);
431 Gtk::Label* label_crea = manage (new Gtk::Label);
432 label_crea->set_markup (_("<b>Creation</b>"));
433 Gtk::Label* label_crea_type = manage (new Gtk::Label);
434 label_crea_type->set_markup (_("Gridtype"));
436 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
437 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
438 }
439 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
441 Gtk::Label* label_def = manage (new Gtk::Label);
442 label_def->set_markup (_("<b>Defined grids</b>"));
444 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
445 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
446 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
447 }
449 Gtk::Widget *const widget_array[] =
450 {
451 label_crea, 0,
452 label_crea_type, (Gtk::Widget*) &_grids_combo_gridtype,
453 (Gtk::Widget*) &_grids_button_new, (Gtk::Widget*) &_grids_button_remove,
454 label_def, 0
455 };
456 attach_all(_page_grids.table(), widget_array, G_N_ELEMENTS(widget_array));
457 _page_grids.table().attach(_grids_notebook, 0, 3, 4, 5,
458 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
459 }
463 /**
464 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
465 */
466 void
467 DocumentProperties::update()
468 {
469 if (_wr.isUpdating()) return;
471 SPDesktop *dt = SP_ACTIVE_DESKTOP;
472 SPNamedView *nv = sp_desktop_namedview(dt);
474 _wr.setUpdating (true);
475 set_sensitive (true);
477 //-----------------------------------------------------------page page
478 _rcp_bg.setRgba32 (nv->pagecolor);
479 _rcb_canb.setActive (nv->showborder);
480 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
481 _rcp_bord.setRgba32 (nv->bordercolor);
482 _rcb_shad.setActive (nv->showpageshadow);
484 if (nv->doc_units)
485 _rum_deflt.setUnit (nv->doc_units);
487 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
488 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
489 _page_sizer.setDim (doc_w_px, doc_h_px);
491 //-----------------------------------------------------------guide
492 _rcb_sgui.setActive (nv->showguides);
493 _rcp_gui.setRgba32 (nv->guidecolor);
494 _rcp_hgui.setRgba32 (nv->guidehicolor);
496 //-----------------------------------------------------------snap
498 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
499 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
500 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
501 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
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 //-----------------------------------------------------------grids page
514 update_gridspage();
516 _wr.setUpdating (false);
517 }
519 //--------------------------------------------------------------------
521 void
522 DocumentProperties::on_response (int id)
523 {
524 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
525 {
526 _rcp_bg.closeWindow();
527 _rcp_bord.closeWindow();
528 _rcp_gui.closeWindow();
529 _rcp_hgui.closeWindow();
530 }
532 if (id == Gtk::RESPONSE_CLOSE)
533 hide();
534 }
538 static void
539 on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data)
540 {
541 if (!_instance)
542 return;
544 _instance->update_gridspage();
545 }
547 static void
548 on_child_removed(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 }
558 /**
559 * Called when XML node attribute changed; updates dialog widgets.
560 */
561 static void
562 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
563 {
564 if (!_instance)
565 return;
567 _instance->update();
568 }
570 static void
571 on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
572 {
573 if (!_instance)
574 return;
576 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
577 repr->addListener (&_repr_events, _instance);
578 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
579 root->addListener (&_repr_events, _instance);
580 _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
581 _instance->update();
582 }
584 static void
585 on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
586 {
587 if (!_instance)
588 return;
590 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
591 repr->removeListenerByData (_instance);
592 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
593 root->removeListenerByData (_instance);
594 _instance->_doc_replaced_connection.disconnect();
595 }
597 static void
598 on_doc_replaced (SPDesktop* dt, SPDocument* doc)
599 {
600 if (!_instance)
601 return;
603 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
604 repr->addListener (&_repr_events, _instance);
605 Inkscape::XML::Node *root = SP_OBJECT_REPR(doc->root);
606 root->addListener (&_repr_events, _instance);
607 _instance->update();
608 }
613 /*########################################################################
614 # BUTTON CLICK HANDLERS (callbacks)
615 ########################################################################*/
617 void
618 DocumentProperties::onNewGrid()
619 {
620 SPDesktop *dt = SP_ACTIVE_DESKTOP;
621 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
622 SPDocument *doc = sp_desktop_document(dt);
624 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
625 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
626 }
629 void
630 DocumentProperties::onRemoveGrid()
631 {
632 gint pagenum = _grids_notebook.get_current_page();
633 if (pagenum == -1) // no pages
634 return;
636 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
637 if (!page) return;
639 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
641 // find the grid with name tabtext (it's id) and delete that one.
642 SPDesktop *dt = SP_ACTIVE_DESKTOP;
643 SPNamedView *nv = sp_desktop_namedview(dt);
644 Inkscape::CanvasGrid * found_grid = NULL;
645 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
646 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
647 gchar const *idtext = grid->repr->attribute("id");
648 if ( !strcmp(tabtext.c_str(), idtext) ) {
649 found_grid = grid;
650 break; // break out of for-loop
651 }
652 }
653 if (found_grid) {
654 // delete the grid that corresponds with the selected tab
655 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
656 found_grid->repr->parent()->removeChild(found_grid->repr);
657 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
658 }
659 }
662 } // namespace Dialog
663 } // namespace UI
664 } // namespace Inkscape
666 /*
667 Local Variables:
668 mode:c++
669 c-file-style:"stroustrup"
670 c-file-offsets:((innamespace . 0)(inline-open . 0))
671 indent-tabs-mode:nilu
672 fill-column:99
673 End:
674 */
675 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :