Skip to content

Commit

Permalink
Merge pull request dlrudie#74 from TheLastRar/master
Browse files Browse the repository at this point in the history
SetNotifyIconText adjustments
  • Loading branch information
David Rudie committed Jan 21, 2016
2 parents 2056f92 + af99b56 commit 6b00078
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Snip/TextHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ public static void SetNotifyIconText(string text)
{
if (!string.IsNullOrEmpty(text))
{
int maxLength = 120; // 128 max length minus 8 to stop issues with string length crashing the program
text = text.Trim(); //trim trailing spaces

int maxLength = 127; // 128 max length

if (text.Length >= maxLength)
{
int nextSpace = text.LastIndexOf(' ', maxLength);
maxLength -= 4; //need to ensure space to append " ..." to the end of the string

//LastIndexOf will search backwards from the specified index, this means that
//we search maxLength + 1 characters to find the specified char (space)
//this index gets treated as a length (from index 0) in text.Substring,
//which implicitly removes the space from the resultant string
int nextSpace = text.LastIndexOf(' ', maxLength);

text = string.Format(CultureInfo.CurrentCulture, "{0} ...", text.Substring(0, (nextSpace > 0) ? nextSpace : maxLength).Trim());
}
Expand Down

0 comments on commit 6b00078

Please sign in to comment.