show first word of comment on track's comment-button
authorRobin Gareus <robin@gareus.org>
Tue, 21 Jun 2016 16:18:54 +0000 (18:18 +0200)
committerRobin Gareus <robin@gareus.org>
Tue, 21 Jun 2016 16:18:54 +0000 (18:18 +0200)
gtk2_ardour/mixer_strip.cc
gtk2_ardour/mixer_strip.h

index 7bc48399409d989ff3c6caf2c60bcfb5d7f05266..d7007184a75ced25d34bd30f4dc5b853e085823c 100644 (file)
@@ -263,7 +263,9 @@ MixerStrip::init ()
        group_button.set_name ("mixer strip button");
 
        _comment_button.set_name (X_("mixer strip button"));
+       _comment_button.set_text_ellipsize (Pango::ELLIPSIZE_END);
        _comment_button.signal_clicked.connect (sigc::mem_fun (*this, &RouteUI::toggle_comment_editor));
+       _comment_button.signal_size_allocate().connect (sigc::mem_fun (*this, &MixerStrip::comment_button_resized));
 
        // TODO implement ArdourKnob::on_size_request properly
 #define PX_SCALE(px) std::max((float)px, rintf((float)px * UIConfiguration::instance().get_ui_scale()))
@@ -1487,33 +1489,27 @@ MixerStrip::port_connected_or_disconnected (boost::weak_ptr<Port> wa, boost::wea
 void
 MixerStrip::setup_comment_button ()
 {
-       switch (_width) {
+       std::string comment = _route->comment();
 
-       case Wide:
-               if (_route->comment().empty ()) {
-                       _comment_button.set_name ("generic button");
-                       _comment_button.set_text (_("Comments"));
-               } else {
-                       _comment_button.set_name ("comment button");
-                       _comment_button.set_text (_("*Comments*"));
-               }
-               break;
+       set_tooltip (_comment_button, comment.empty() ? _("Click to add/edit comments") : _route->comment());
 
-       case Narrow:
-               if (_route->comment().empty ()) {
-                       _comment_button.set_name ("generic button");
-                       _comment_button.set_text (_("Cmt"));
-               } else {
-                       _comment_button.set_name ("comment button");
-                       _comment_button.set_text (_("*Cmt*"));
-               }
-               break;
+       if (comment.empty ()) {
+               _comment_button.set_name ("generic button");
+               _comment_button.set_text (_width  == Wide ? _("Comments") : _("Cmt"));
+               return;
        }
 
-       set_tooltip (
-               _comment_button, _route->comment().empty() ? _("Click to add/edit comments") : _route->comment()
-               );
+       _comment_button.set_name ("comment button");
 
+       string::size_type pos = comment.find_first_of (" \t\n");
+       if (pos != string::npos) {
+               comment = comment.substr (0, pos);
+       }
+       if (comment.empty()) {
+               _comment_button.set_text (_width  == Wide ? _("Comments") : _("Cmt"));
+       } else {
+               _comment_button.set_text (comment);
+       }
 }
 
 bool
@@ -1791,6 +1787,12 @@ MixerStrip::name_button_resized (Gtk::Allocation& alloc)
        name_button.set_layout_ellipsize_width (alloc.get_width() * PANGO_SCALE);
 }
 
+void
+MixerStrip::comment_button_resized (Gtk::Allocation& alloc)
+{
+       _comment_button.set_layout_ellipsize_width (alloc.get_width() * PANGO_SCALE);
+}
+
 bool
 MixerStrip::width_button_pressed (GdkEventButton* ev)
 {
index 9bffeb419e44e6a09e35eaade2352e7fa68da2a7..0d815c4b3e5448cd36a0b0286b78870dddafe050 100644 (file)
@@ -195,6 +195,7 @@ class MixerStrip : public AxisView, public RouteUI, public Gtk::EventBox
 
        void input_button_resized (Gtk::Allocation&);
        void output_button_resized (Gtk::Allocation&);
+       void comment_button_resized (Gtk::Allocation&);
 
        ArdourButton* midi_input_enable_button;
        Gtk::HBox   input_button_box;