From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/actions/actions-element-a.cpp | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/actions/actions-element-a.cpp (limited to 'src/actions/actions-element-a.cpp') diff --git a/src/actions/actions-element-a.cpp b/src/actions/actions-element-a.cpp new file mode 100644 index 0000000..d35a053 --- /dev/null +++ b/src/actions/actions-element-a.cpp @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Gio::Actions for use with (for anchor or hyper link). + * + * Copyright (C) 2022 Tavmjong Bah + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#include "actions-element-a.h" + +#include + +#include // Not ! To eventually allow a headless version! +#include + +#include "inkscape-application.h" +#include "inkscape-window.h" +#include "preferences.h" + +#include "selection.h" // Selection +#include "object/sp-anchor.h" +#include "ui/dialog/dialog-container.h" + +// void anchor_add(InkscapeApplication *app) +// { +// auto selection = app->get_active_selection(); +// auto anchor = selection->group(1); +// selection->set(anchor); + +// if (app->get_active_window()) { +// app->get_active_window()->get_desktop()->getContainer()->new_dialog("ObjectAttributes"); +// } +// } + +// XML not modified. Requires GUI. +void anchor_open_link(InkscapeApplication* app) +{ + auto window = app->get_active_window(); + if (window) { + auto selection = app->get_active_selection(); + for (auto item : selection->items()) { + auto anchor = dynamic_cast(item); + if (anchor) { + const char* href = anchor->href; + if (href) { + try { + window->show_uri(href, GDK_CURRENT_TIME); + } catch (const Glib::Error &e) { + std::cerr << "anchor_open_link: cannot open " << href << " " << e.what().raw() << std::endl; + } + } + } + } + } +} + +std::vector> raw_data_element_a = +{ + // clang-format off + {"app.element-a-open-link", N_("Open link"), "Anchor", N_("Add an anchor to an object.") }, + // clang-format on +}; + +void +add_actions_element_a(InkscapeApplication* app) +{ + auto *gapp = app->gio_app(); + + // clang-format off + gapp->add_action( "element-a-open-link", sigc::bind(sigc::ptr_fun(&anchor_open_link), app)); + // clang-format on + + app->get_action_extra_data().add_data(raw_data_element_a); +} + + +/* + 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 : -- cgit v1.2.3