summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e69f7d7)
raw | patch | inline | side by side (parent: e69f7d7)
author | pjrm <pjrm@users.sourceforge.net> | |
Sat, 5 Jul 2008 11:21:52 +0000 (11:21 +0000) | ||
committer | pjrm <pjrm@users.sourceforge.net> | |
Sat, 5 Jul 2008 11:21:52 +0000 (11:21 +0000) |
src/selection-chemistry.cpp | patch | blob | history | |
src/selection-chemistry.h | patch | blob | history | |
src/verbs.cpp | patch | blob | history |
index 9b11ef9f62be66880862cffeb4c3136529326cb1..9695d58e91dd6ed8ac25f8dab61e3b8137025f23 100644 (file)
sp_document_done (doc, SP_VERB_OBJECT_UNSET_MASK, _("Release mask"));
}
-void fit_canvas_to_selection(SPDesktop *desktop) {
- g_return_if_fail(desktop != NULL);
+/**
+ * Returns true if an undoable change should be recorded.
+ */
+bool
+fit_canvas_to_selection(SPDesktop *desktop)
+{
+ g_return_val_if_fail(desktop != NULL, false);
SPDocument *doc = sp_desktop_document(desktop);
- g_return_if_fail(doc != NULL);
- g_return_if_fail(desktop->selection != NULL);
+ g_return_val_if_fail(doc != NULL, false);
+ g_return_val_if_fail(desktop->selection != NULL, false);
if (desktop->selection->isEmpty()) {
desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to fit canvas to."));
- return;
+ return false;
}
NR::Maybe<NR::Rect> const bbox(desktop->selection->bounds());
if (bbox && !bbox->isEmpty()) {
doc->fitToRect(*bbox);
+ return true;
+ } else {
+ return false;
}
-};
+}
-void fit_canvas_to_drawing(SPDocument *doc) {
- g_return_if_fail(doc != NULL);
+/**
+ * Fit canvas to the bounding box of the selection, as an undoable action.
+ */
+void
+verb_fit_canvas_to_selection(SPDesktop *const desktop)
+{
+ if (fit_canvas_to_selection(desktop)) {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_SELECTION,
+ _("Fit Page to Selection"));
+ }
+}
+
+bool
+fit_canvas_to_drawing(SPDocument *doc)
+{
+ g_return_val_if_fail(doc != NULL, false);
sp_document_ensure_up_to_date(doc);
SPItem const *const root = SP_ITEM(doc->root);
NR::Maybe<NR::Rect> const bbox(root->getBounds(from_2geom(sp_item_i2r_affine(root))));
if (bbox && !bbox->isEmpty()) {
doc->fitToRect(*bbox);
+ return true;
+ } else {
+ return false;
}
-};
+}
+
+void
+verb_fit_canvas_to_drawing(SPDesktop *desktop)
+{
+ if (fit_canvas_to_drawing(sp_desktop_document(desktop))) {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_DRAWING,
+ _("Fit Page to Drawing"));
+ }
+}
void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) {
g_return_if_fail(desktop != NULL);
g_return_if_fail(doc != NULL);
g_return_if_fail(desktop->selection != NULL);
- if (desktop->selection->isEmpty()) {
- fit_canvas_to_drawing(doc);
- } else {
- fit_canvas_to_selection(desktop);
+ bool const changed = ( desktop->selection->isEmpty()
+ ? fit_canvas_to_drawing(doc)
+ : fit_canvas_to_selection(desktop) );
+ if (changed) {
+ sp_document_done(sp_desktop_document(desktop), SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING,
+ _("Fit Page to Selection or Drawing"));
}
-
- sp_document_done(doc, SP_VERB_FIT_CANVAS_TO_DRAWING,
- _("Fit page to selection"));
};
static void itemtree_map(void (*f)(SPItem *, SPDesktop *), SPObject *root, SPDesktop *desktop) {
index e67d679307e2ce79fb245015055f4000524fcae3..37d8a4a0911468dd5d6a12af765e205135f29d67 100644 (file)
void sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer);
void sp_selection_unset_mask(bool apply_clip_path);
-void fit_canvas_to_selection(SPDesktop *desktop);
-void fit_canvas_to_drawing(SPDocument *doc);
-void fit_canvas_to_selection_or_drawing(SPDesktop *desktop);
+bool fit_canvas_to_selection(SPDesktop *);
+void verb_fit_canvas_to_selection(SPDesktop *);
+bool fit_canvas_to_drawing(SPDocument *);
+void verb_fit_canvas_to_drawing(SPDesktop *);
+void fit_canvas_to_selection_or_drawing(SPDesktop *);
void unlock_all(SPDesktop *dt);
void unlock_all_in_all_layers(SPDesktop *dt);
diff --git a/src/verbs.cpp b/src/verbs.cpp
index 8c5ce310b67e3089a2466b5e17e3cd612eb1c210..b92eb52c06f03969691c4aa38628e2a3c6ddf996 100644 (file)
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
switch ((long) data) {
case SP_VERB_FIT_CANVAS_TO_SELECTION:
- fit_canvas_to_selection(dt);
+ verb_fit_canvas_to_selection(dt);
break;
case SP_VERB_FIT_CANVAS_TO_DRAWING:
- fit_canvas_to_drawing(doc);
+ verb_fit_canvas_to_drawing(dt);
break;
case SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING:
fit_canvas_to_selection_or_drawing(dt);