diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-11-27 16:18:45 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-11-27 16:18:45 +0000 |
| commit | 2b769cc45cc030a4a3947e22daa174cf28bf57de (patch) | |
| tree | 52e04bdd7ce6d9cbc9e6d718196e9b14f7992729 | |
| parent | Comment out debugging output. (diff) | |
| download | inkscape-2b769cc45cc030a4a3947e22daa174cf28bf57de.tar.gz inkscape-2b769cc45cc030a4a3947e22daa174cf28bf57de.zip | |
Add a rotation action.
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/actions/actions-selection.cpp | 1 | ||||
| -rw-r--r-- | src/actions/actions-transform.cpp | 53 | ||||
| -rw-r--r-- | src/actions/actions-transform.h | 29 | ||||
| -rw-r--r-- | src/inkscape-application.cpp | 12 | ||||
| -rw-r--r-- | src/inkscape-application.h | 4 | ||||
| -rwxr-xr-x | src/selection-chemistry.cpp | 20 |
7 files changed, 112 insertions, 9 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae27d0953..5e4ca8fc8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -291,6 +291,8 @@ set(main_SRC actions/actions-output.cpp actions/actions-selection.h actions/actions-selection.cpp + actions/actions-transform.h + actions/actions-transform.cpp ) set(view_SRC inkview-main.cpp diff --git a/src/actions/actions-selection.cpp b/src/actions/actions-selection.cpp index 9a0429400..5687ebdd7 100644 --- a/src/actions/actions-selection.cpp +++ b/src/actions/actions-selection.cpp @@ -97,6 +97,7 @@ select_all(InkscapeApplication* app) if (!get_document_and_selection(app, &document, &selection)) { return; } + std::cerr << "select_all: Not implemented!" << std::endl; } void diff --git a/src/actions/actions-transform.cpp b/src/actions/actions-transform.cpp new file mode 100644 index 000000000..91f12df58 --- /dev/null +++ b/src/actions/actions-transform.cpp @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Gio::Actions for selection tied to the application and without GUI. + * + * Copyright (C) 2018 Tavmjong Bah + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#include <iostream> + +#include <giomm.h> // Not <gtkmm.h>! To eventually allow a headless version! + +#include "actions-transform.h" +#include "actions-helper.h" +#include "inkscape-application.h" + +#include "inkscape.h" // Inkscape::Application +#include "selection.h" // Selection + +void +transform_rotate(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<double> d = Glib::VariantBase::cast_dynamic<Glib::Variant<double> >(value); + auto selection = app->get_active_selection(); + selection->rotate(d.get()); +} + +void +add_actions_transform(InkscapeApplication* app) +{ + Glib::VariantType Bool( Glib::VARIANT_TYPE_BOOL); + Glib::VariantType Int( Glib::VARIANT_TYPE_INT32); + Glib::VariantType Double(Glib::VARIANT_TYPE_DOUBLE); + Glib::VariantType String(Glib::VARIANT_TYPE_STRING); + + app->add_action_with_parameter( "transform-rotate", Double, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&transform_rotate), app)); +} + + + + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/actions/actions-transform.h b/src/actions/actions-transform.h new file mode 100644 index 000000000..9b1b0dc3d --- /dev/null +++ b/src/actions/actions-transform.h @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Gio::Actions for selection tied to the application and without GUI. + * + * Copyright (C) 2018 Tavmjong Bah + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#ifndef INK_ACTIONS_TRANSFORM_H +#define INK_ACTIONS_TRANSFORM_H + +class InkscapeApplication; + +void add_actions_transform(InkscapeApplication* app); + +#endif // INK_ACTIONS_TRANSFORM_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp index fc2fbbe76..cf442ecbc 100644 --- a/src/inkscape-application.cpp +++ b/src/inkscape-application.cpp @@ -24,6 +24,7 @@ #include "actions/actions-base.h" // Actions #include "actions/actions-output.h" // Actions #include "actions/actions-selection.h" // Actions +#include "actions/actions-transform.h" // Actions #ifdef WITH_DBUS # include "extension/dbus/dbus-init.h" @@ -65,6 +66,7 @@ InkscapeApplication::InkscapeApplication() add_actions_base(this); // actions that are GUI independent add_actions_output(this); // actions for file export add_actions_selection(this); // actions for object selection + add_actions_transform(this); // actions for transforming selected objects // ====================== Command Line ====================== @@ -162,6 +164,16 @@ InkscapeApplication::get_active_document() return _documents.back(); } +Inkscape::Selection* +InkscapeApplication::get_active_selection() +{ + // This should change based on last document window in focus if with GUI. But for now we're + // only using it for command line mode so return last document (the one currently be read in). + SPDocument* document = _documents.back(); + Inkscape::ActionContext context = INKSCAPE.action_context_for_document(document); + return context.getSelection(); +} + void InkscapeApplication::on_startup() { diff --git a/src/inkscape-application.h b/src/inkscape-application.h index 1385d2bb2..90553cd0d 100644 --- a/src/inkscape-application.h +++ b/src/inkscape-application.h @@ -23,6 +23,8 @@ #include <gtkmm.h> #include "document.h" +#include "selection.h" + #include "helper/action.h" #include "io/file-export-cmd.h" // File export (non-verb) @@ -37,6 +39,8 @@ public: static Glib::RefPtr<InkscapeApplication> create(); SPDocument* get_active_document(); + Inkscape::Selection* get_active_selection(); + InkFileExportCmd* file_export() { return &_file_export; } protected: diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 082ff49a7..2f77e1093 100755 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1875,9 +1875,10 @@ void ObjectSet::rotate90(bool ccw) } } - DocumentUndo::done(document(), - ccw ? SP_VERB_OBJECT_ROTATE_90_CCW : SP_VERB_OBJECT_ROTATE_90_CW, - ccw ? _("Rotate 90\xc2\xb0 CCW") : _("Rotate 90\xc2\xb0 CW")); + if (document()) + DocumentUndo::done(document(), + ccw ? SP_VERB_OBJECT_ROTATE_90_CCW : SP_VERB_OBJECT_ROTATE_90_CW, + ccw ? _("Rotate 90\xc2\xb0 CCW") : _("Rotate 90\xc2\xb0 CW")); } void ObjectSet::rotate(gdouble const angle_degrees) @@ -1891,12 +1892,13 @@ void ObjectSet::rotate(gdouble const angle_degrees) } rotateRelative(*center_, angle_degrees); - DocumentUndo::maybeDone(document(), - ( ( angle_degrees > 0 ) - ? "selector:rotate:ccw" - : "selector:rotate:cw" ), - SP_VERB_CONTEXT_SELECT, - _("Rotate")); + if (document()) + DocumentUndo::maybeDone(document(), + ( ( angle_degrees > 0 ) + ? "selector:rotate:ccw" + : "selector:rotate:cw" ), + SP_VERB_CONTEXT_SELECT, + _("Rotate")); } /* |
