From 405fda66f708e61a933d88a3889916b6488cd9da Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 21 May 2016 09:30:05 -0400 Subject: [PATCH] basics of printing bindings as HTML --- libs/gtkmm2ext/bindings.cc | 101 ++++++++++++++++++++++++++++ libs/gtkmm2ext/gtkmm2ext/bindings.h | 2 + 2 files changed, 103 insertions(+) diff --git a/libs/gtkmm2ext/bindings.cc b/libs/gtkmm2ext/bindings.cc index deac345418..155b2cf11c 100644 --- a/libs/gtkmm2ext/bindings.cc +++ b/libs/gtkmm2ext/bindings.cc @@ -676,6 +676,107 @@ Bindings::save (XMLNode& root) root.add_child_nocopy (*releases); } +void +Bindings::save_all_bindings_as_html (ostream& ostr) +{ + if (bindings.empty()) { + return; + } + + ostr << "\n\n"; + ostr << PROGRAM_NAME; + ostr << "\n\n\n"; + + for (list::const_iterator b = bindings.begin(); b != bindings.end(); ++b) { + (*b)->save_as_html (ostr); + } + + ostr << "\n"; + ostr << "\n"; +} + +void +Bindings::save_as_html (ostream& ostr) const +{ + ostr << "

"; + ostr << name(); + ostr << "

\n"; + + if (!press_bindings.empty() || !button_press_bindings.empty()) { + + ostr << "

"; + ostr << _("Press"); + ostr << "

\n"; + + if (!press_bindings.empty()) { + + ostr << "
\n"; + + for (KeybindingMap::const_iterator k = press_bindings.begin(); k != press_bindings.end(); ++k) { + if (k->first.name().empty()) { + continue; + } + + RefPtr action; + + if (k->second.action) { + action = k->second.action; + } else { + if (_action_map) { + action = _action_map->find_action (k->second.action_name); + } + } + + if (!action) { + continue; + } + + ostr << "
" << k->first.name() << "
\n"; + ostr << "
" << action->get_label() << "
\n"; + } + + ostr << "
\n"; + } + } + + if (!release_bindings.empty() || !release_bindings.empty()) { + + ostr << "

"; + ostr << _("Release"); + ostr << "

\n"; + + if (!release_bindings.empty()) { + ostr << "
\n"; + + for (KeybindingMap::const_iterator k = release_bindings.begin(); k != release_bindings.end(); ++k) { + + if (k->first.name().empty()) { + continue; + } + + RefPtr action; + + if (k->second.action) { + action = k->second.action; + } else { + if (_action_map) { + action = _action_map->find_action (k->second.action_name); + } + } + + if (!action) { + continue; + } + + ostr << "
" << k->first.name() << "
\n"; + ostr << "
" << action->get_label() << "
\n"; + } + + ostr << "
\n"; + } + } +} + bool Bindings::load (XMLNode const& node) { diff --git a/libs/gtkmm2ext/gtkmm2ext/bindings.h b/libs/gtkmm2ext/gtkmm2ext/bindings.h index f7437fa67b..c2a5215a68 100644 --- a/libs/gtkmm2ext/gtkmm2ext/bindings.h +++ b/libs/gtkmm2ext/gtkmm2ext/bindings.h @@ -180,6 +180,7 @@ class LIBGTKMM2EXT_API Bindings { bool load (XMLNode const& node); void load_operation (XMLNode const& node); void save (XMLNode& root); + void save_as_html (std::ostream&) const; /* GTK has the following position a Gtk::Action: * @@ -209,6 +210,7 @@ class LIBGTKMM2EXT_API Bindings { static std::list bindings; static Bindings* get_bindings (std::string const& name, ActionMap&); static void associate_all (); + static void save_all_bindings_as_html (std::ostream&); static PBD::Signal1 BindingsChanged; -- 2.30.2