From c853ffb5b2f75f5a889ed2e3ef89b818a736e87a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:50:49 +0200 Subject: Adding upstream version 1.3+ds. Signed-off-by: Daniel Baumann --- src/actions/actions-extra-data.cpp | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 src/actions/actions-extra-data.cpp (limited to 'src/actions/actions-extra-data.cpp') diff --git a/src/actions/actions-extra-data.cpp b/src/actions/actions-extra-data.cpp new file mode 100644 index 0000000..ffce571 --- /dev/null +++ b/src/actions/actions-extra-data.cpp @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Extra data associated with actions: Label, Section, Tooltip. + * + * Copyright (C) 2020 Tavmjong Bah + * + * Extra data is indexed by "detailed action names", that is an action + * with prefix and value (if statefull). For example: + * "win.canvas-display-mode(1)" + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#include "actions-extra-data.h" + +#include + +#include + +std::vector InkActionExtraData::get_actions() +{ + std::vector action_names; + for (auto const &datum : data) { + action_names.emplace_back(datum.first); + } + return action_names; +} + +Glib::ustring +InkActionExtraData::get_label_for_action(Glib::ustring const &action_name, bool translated) +{ + Glib::ustring value; + auto search = data.find(action_name); + if (search != data.end()) { + value = translated ? _(search->second.label.c_str()) + : search->second.label; + } + return value; +} + +// TODO: Section should be translatable, too +Glib::ustring +InkActionExtraData::get_section_for_action(Glib::ustring const &action_name) { + + Glib::ustring value; + auto search = data.find(action_name); + if (search != data.end()) { + value = search->second.section; + } + return value; +} + +Glib::ustring InkActionExtraData::get_tooltip_for_action(Glib::ustring const &action_name, bool translated, + bool expanded) +{ + Glib::ustring value; + auto search = data.find(action_name); + if (search != data.end()) { + if (expanded && strncmp(action_name.c_str(), "win:tool-switch('", 17)) { + value = translated ? ("" + Glib::ustring(_(search->second.label.c_str())) + "\n" + + Glib::ustring(_(search->second.tooltip.c_str()))) + : (search->second.label + "\n" + search->second.tooltip); + } else { + value = translated ? _(search->second.tooltip.c_str()) : search->second.tooltip; + } + } + return value; +} + +void InkActionExtraData::add_data(std::vector> const &raw_data) +{ + for (auto const &raw : raw_data) { + data.emplace(raw[0], InkActionExtraDatum{ raw[1], raw[2], raw[3] }); + } +} + +/* + 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