Click here to Skip to main content
15,885,985 members
Articles / Programming Languages / XML

SnippetManager Written by Tim Sneath Extended with Cool Tooltip

Rate me:
Please Sign up or sign in to vote.
3.80/5 (5 votes)
11 Mar 2003 60K   893   35   2
Ever find yourself hoarding little pieces of code that are always coming in handy? Snippet Manager is a little utility written in C# that collects all your code snippets into one convenient location, allowing you to save them into XML, or copy them into any code editor using the clipboard.

Sample Image - ExtendedSnippetManager.jpg

Introduction

I like the snippet manager written by Tim Sneath, but when I use it and have a lot of code snippets, I only can see the title of my snippet and cannot remember, what is its content. So I added the functionality of a tooltip which provides me the contents. The tooltip is limited to 24 lines.

Using the Code

I only added a simple method to SnippetUI.cs, which receives a control and a message text as arguments and attaches a tooltip to the control.

C#
/// Attaches a tooltip to a control
private void CreateToolTipForControl(Control ctl, String msg)
{
 // split by carriage return
 String[] lines = msg.Split(new char[] {'\u000D'});

 // StringBuilder is faster
 StringBuilder sb = new StringBuilder();

 // maximum lines
 int lineCount = lines.Length;
 if (lineCount > 24)
 {
  // only show 24 lines
  lineCount = 24;
 }

 for (int i = 0; i < lineCount; i++)
 {
  // tab-character
  char tab = '\u0009';

  // line-feed-character
  char lf = '\u000A';

  // must replace tabs with whitespace to show properly
  String line = lines[i].Replace(tab.ToString(), "    ");

  // must replace line-feeds to show properly
  line = line.Replace(lf.ToString(), "");

  // append String
  sb.Append(line + "\n");
 }

 // append 3 dots if text exceeds more than 24 lines
 if (lines.Length > lineCount)
 {
  sb.Append("...");
 }

 // attach tooltip to control
 toolTip1.SetToolTip(ctl, sb.ToString());
}

This method is called everytime the toolwindow synchronizes its contents.

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralHi, Pin
Chris Richner13-Mar-03 1:08
Chris Richner13-Mar-03 1:08 
GeneralRe: Hi, Pin
Andi Fleischmann13-Mar-03 2:18
Andi Fleischmann13-Mar-03 2:18 
This little application is not of my thoughts.
As explanded in the title, it's written by Tim Sneath, a microsoft guy.
I only added a feature.

I think his intention was not only to use it in conjunction with Visual Studio, rather more to use it from any application with clipboard-functionality.

I am not sure, but I think your idea is already implemented in the new Visual Studio 2003.


best regards.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.