From 43e8e880dc25a52b6a929b9c5eebfbe348c43e95 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 15 Jan 2010 00:52:22 +0000 Subject: Escape underscores in port matrix menus correctly so that track names etc. with underscores get displayed properly. git-svn-id: svn://localhost/ardour2/branches/3.0@6491 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/port_matrix.cc | 12 ++++++++---- gtk2_ardour/utils.cc | 18 ++++++++++++++++++ gtk2_ardour/utils.h | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/port_matrix.cc b/gtk2_ardour/port_matrix.cc index 247d750534..209c4760f1 100644 --- a/gtk2_ardour/port_matrix.cc +++ b/gtk2_ardour/port_matrix.cc @@ -35,6 +35,7 @@ #include "port_matrix_component.h" #include "i18n.h" #include "gui_thread.h" +#include "utils.h" using namespace std; using namespace Gtk; @@ -393,7 +394,10 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t) if (can_rename_channels (bc[dim].bundle)) { - snprintf (buf, sizeof (buf), _("Rename '%s'..."), bc[dim].bundle->channel_name (bc[dim].channel).c_str()); + snprintf ( + buf, sizeof (buf), _("Rename '%s'..."), + escape_underscores (bc[dim].bundle->channel_name (bc[dim].channel)).c_str() + ); sub.push_back ( MenuElem ( buf, @@ -445,7 +449,7 @@ PortMatrix::popup_menu (BundleChannel column, BundleChannel row, uint32_t t) } } - items.push_back (MenuElem (bc[dim].bundle->name().c_str(), *m)); + items.push_back (MenuElem (escape_underscores (bc[dim].bundle->name()).c_str(), *m)); need_separator = true; } @@ -807,7 +811,7 @@ PortMatrix::add_remove_option (Menu_Helpers::MenuList& m, boost::weak_ptrchannel_name (c).c_str()); + snprintf (buf, sizeof (buf), _("Remove '%s'"), escape_underscores (b->channel_name (c)).c_str()); m.push_back (MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::remove_channel_proxy), w, c))); } @@ -822,6 +826,6 @@ PortMatrix::add_disassociate_option (Menu_Helpers::MenuList& m, boost::weak_ptr< } char buf [64]; - snprintf (buf, sizeof (buf), _("%s all from '%s'"), disassociation_verb().c_str(), b->channel_name (c).c_str()); + snprintf (buf, sizeof (buf), _("%s all from '%s'"), disassociation_verb().c_str(), escape_underscores (b->channel_name (c)).c_str()); m.push_back (MenuElem (buf, sigc::bind (sigc::mem_fun (*this, &PortMatrix::disassociate_all_on_channel), w, c, d))); } diff --git a/gtk2_ardour/utils.cc b/gtk2_ardour/utils.cc index 9aba168ef1..b8d7569414 100644 --- a/gtk2_ardour/utils.cc +++ b/gtk2_ardour/utils.cc @@ -1016,3 +1016,21 @@ pixbuf_from_ustring(const ustring& name, Pango::FontDescription* font, int clip_ return buf; } + +/** Replace _ with __ in a string; for use with menu item text to make underscores displayed correctly */ +string +escape_underscores (string const & s) +{ + string o; + string::size_type const N = s.length (); + + for (string::size_type i = 0; i < N; ++i) { + if (s[i] == '_') { + o += "__"; + } else { + o += s[i]; + } + } + + return o; +} diff --git a/gtk2_ardour/utils.h b/gtk2_ardour/utils.h index e742e89cd5..9ee66729fc 100644 --- a/gtk2_ardour/utils.h +++ b/gtk2_ardour/utils.h @@ -95,4 +95,6 @@ Glib::RefPtr pixbuf_from_ustring (const Glib::ustring& name, void resize_window_to_proportion_of_monitor (Gtk::Window*, int, int); +std::string escape_underscores (std::string const &); + #endif /* __ardour_gtk_utils_h__ */ -- cgit v1.2.3