From 617c08b80f214285f1049e4e118c0054e849cead Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Sun, 23 Oct 2011 16:18:41 +0100 Subject: truncate playlist label if needs be --- src/playlists-menu-item.vala | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/playlists-menu-item.vala') diff --git a/src/playlists-menu-item.vala b/src/playlists-menu-item.vala index 9cb7ac7..4666a50 100644 --- a/src/playlists-menu-item.vala +++ b/src/playlists-menu-item.vala @@ -49,7 +49,8 @@ public class PlaylistsMenuitem : PlayerItem continue; Dbusmenu.Menuitem menuitem = new Menuitem(); - menuitem.property_set (MENUITEM_PROP_LABEL, detail.name); + menuitem.property_set (MENUITEM_PROP_LABEL, + truncate_item_label_if_needs_be (detail.name)); menuitem.property_set (MENUITEM_PROP_ICON_NAME, "playlist-symbolic"); menuitem.property_set (MENUITEM_PATH, (string)detail.path); @@ -86,12 +87,14 @@ public class PlaylistsMenuitem : PlayerItem { foreach ( Dbusmenu.Menuitem item in this.current_playlists.values ){ if (new_detail.path == item.property_get (MENUITEM_PATH)){ - item.property_set (MENUITEM_PROP_LABEL, new_detail.name); + item.property_set (MENUITEM_PROP_LABEL, + truncate_item_label_if_needs_be (new_detail.name)); } } // If its active make sure the name is updated on the root item. if (this.root_item.property_get (MENUITEM_PATH) == new_detail.path) { - this.root_item.property_set (MENUITEM_PROP_LABEL, new_detail.name); + this.root_item.property_set (MENUITEM_PROP_LABEL, + truncate_item_label_if_needs_be (new_detail.name)); } } @@ -115,7 +118,8 @@ public class PlaylistsMenuitem : PlayerItem { var update = detail.name; if ( update == "" ) update = _("Choose Playlist"); - this.root_item.property_set (MENUITEM_PROP_LABEL, update); + this.root_item.property_set (MENUITEM_PROP_LABEL, + truncate_item_label_if_needs_be(update)); this.root_item.property_set (MENUITEM_PATH, detail.path); } @@ -129,6 +133,16 @@ public class PlaylistsMenuitem : PlayerItem this.owner.mpris_bridge.activate_playlist ( (GLib.ObjectPath)this.current_playlists[menu_item_id].property_get (MENUITEM_PATH) ); } + private string truncate_item_label_if_needs_be(string item_label) + { + var result = item_label; + if (item_label.char_count(-1) > 17){ + result = item_label.slice ((long)0, (long)15); + result += "…"; + } + return result; + } + public static HashSet attributes_format() { HashSet attrs = new HashSet(); -- cgit v1.2.3