Code Snippet Manager in C# and WPF

Hello all, today I will post a simple code snippet manager created using C# and WPF. The idea of the app is to be used when making presentations and you need to paste all kind of code snippets (html, xaml, C#, java ). The similar tool is used by Karen Corby in MIX09 presentation about creating silverlight controls.
This is my first .net application so you will see all kind of C# strangeness like using “Object” instead of “object” and String instead of “string”.
Because this was my first application I choose to use WPF not WinForms because WinForms is a lot like Swing and I’ve wanted to see “how declarative XML for the UI is better” and I can say: “hmm ok there is some big pluses”. Anyway I have little experience with Flex’s MXML too and if you ask me the MXML is a lot than XAML.
The code snipper manager application lokks like this :
The view is very simple and I can say that XAML is perfect for creating a simple views and there is tones of snippets in internet for all kinds of examples like popup for example.

The application XAML looks like this :
<Window x:Class="CodeSnippetManager.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Snipper Manager" Height="355" Width="177" Topmost="True" ResizeMode="NoResize" >
<Grid Height="309">
<ListBox Margin="0,-8,0,38" Name="listSnippets" HorizontalContentAlignment="Left"
MouseRightButtonDown="listSnippets_MouseRightButtonDown"
SelectionMode="Single" SelectionChanged="listSnippets_SelectionChanged"
MouseDoubleClick="listSnippets_MouseDoubleClick">

</ListBox>
<Popup Placement="Mouse" Name="popupHint" HorizontalAlignment="Left"
VerticalAlignment="Top" IsOpen="False" AllowsTransparency="True">
<Border BorderBrush="Black" BorderThickness="1">
<Grid Background="White">
<TextBlock Background="White"
x:Name="PopupTxt"
TextAlignment="Center"
VerticalAlignment="Center">

</TextBlock>
</Grid>
</Border>
</Popup>
<WrapPanel Height="40" Name="wrapPanel1" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button Height="26" Name="menu" Width="65" Margin="5" Click="menu_Click">Menu</Button>
<Button Height="26" Name="clear" Width="65" Margin="5" Click="new_Click">Clear</Button>
</WrapPanel>
</Grid>
</Window>

Maybe you can notice that code is short and very simple, maybe simpler than MXML in Flex and a lot simpler than Swing/SWF and JavaFX. There is no code fragments on the view and etc. But what i did not understand is why all kinds of Name x:Name and other attributes are needed. The XML schemas are strangely organized if you ask me.
Anyway the project is uploaded here http://snippetmanager.codeplex.com/Wiki/View.aspx?title=Home. You can download the source and edit it if you want or you can download the release version and try to use it.
The application have the fallowing features:
– creating and adding code snippets from the clipboard
– saving sets of snippets as XML files for usage in the future
– loading sets of snippets
– delete snippet if it is inserted by mistake
Maybe you will notice strange fonts rendering ( there is no clear type ). This is because WPF 3.5 doesnt support clear type at this moment. But clear type will be supported in the incoming .net 4.0 release. If you ask me the current fonts looks even bad than the Java Swing font rendering before 1.6 update 10 which is funny.
The Expression Blend application is written in WPF too and the fonts looks also this bad but if you use dark theme (black by default) it is harder to notice the bad looking fonts. So if you want change the application color schema to darker. I will add dark theme when I have time.
The reason why I’ve created this app is because I often need to write code in front of the students when I make presentations and I think that using a tool like this decrease the possibility to make mistakes when writing.
The idea of this app came after I watch the Karen Corby presentation in MIX09 called Building Microsoft Silverlight Controls btw you can watch it here http://videos.visitmix.com/MIX09/T16F . But because I was unable to find this app I’ve created my own.Hello all, today I will post a simple code snippet manager created using C# and WPF. The idea of the app is to be used when making presentations and you need to paste all kind of code snippets (html, xaml, C#, java ). The similar tool is used by Karen Corby in MIX09 presentation about creating silverlight controls.
This is my first .net application so you will see all kind of C# strangeness like using “Object” instead of “object” and String instead of “string”.
Because this was my first application I choose to use WPF not WinForms because WinForms is a lot like Swing and I’ve wanted to see “how declarative XML for the UI is better” and I can say: “hmm ok there is some big pluses”. Anyway I have little experience with Flex’s MXML too and if you ask me the MXML is a lot than XAML.
The code snipper manager application lokks like this :
The view is very simple and I can say that XAML is perfect for creating a simple views and there is tones of snippets in internet for all kinds of examples like popup for example.

The application XAML looks like this :
<Window x:Class="CodeSnippetManager.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Snipper Manager" Height="355" Width="177" Topmost="True" ResizeMode="NoResize" >
<Grid Height="309">
<ListBox Margin="0,-8,0,38" Name="listSnippets" HorizontalContentAlignment="Left"
MouseRightButtonDown="listSnippets_MouseRightButtonDown"
SelectionMode="Single" SelectionChanged="listSnippets_SelectionChanged"
MouseDoubleClick="listSnippets_MouseDoubleClick">

</ListBox>
<Popup Placement="Mouse" Name="popupHint" HorizontalAlignment="Left"
VerticalAlignment="Top" IsOpen="False" AllowsTransparency="True">
<Border BorderBrush="Black" BorderThickness="1">
<Grid Background="White">
<TextBlock Background="White"
x:Name="PopupTxt"
TextAlignment="Center"
VerticalAlignment="Center">

</TextBlock>
</Grid>
</Border>
</Popup>
<WrapPanel Height="40" Name="wrapPanel1" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button Height="26" Name="menu" Width="65" Margin="5" Click="menu_Click">Menu</Button>
<Button Height="26" Name="clear" Width="65" Margin="5" Click="new_Click">Clear</Button>
</WrapPanel>
</Grid>
</Window>

Maybe you can notice that code is short and very simple, maybe simpler than MXML in Flex and a lot simpler than Swing/SWF and JavaFX. There is no code fragments on the view and etc. But what i did not understand is why all kinds of Name x:Name and other attributes are needed. The XML schemas are strangely organized if you ask me.
Anyway the project is uploaded here http://snippetmanager.codeplex.com/Wiki/View.aspx?title=Home. You can download the source and edit it if you want or you can download the release version and try to use it.
The application have the fallowing features:
– creating and adding code snippets from the clipboard
– saving sets of snippets as XML files for usage in the future
– loading sets of snippets
– delete snippet if it is inserted by mistake
Maybe you will notice strange fonts rendering ( there is no clear type ). This is because WPF 3.5 doesnt support clear type at this moment. But clear type will be supported in the incoming .net 4.0 release. If you ask me the current fonts looks even bad than the Java Swing font rendering before 1.6 update 10 which is funny.
The Expression Blend application is written in WPF too and the fonts looks also this bad but if you use dark theme (black by default) it is harder to notice the bad looking fonts. So if you want change the application color schema to darker. I will add dark theme when I have time.
The reason why I’ve created this app is because I often need to write code in front of the students when I make presentations and I think that using a tool like this decrease the possibility to make mistakes when writing.
The idea of this app came after I watch the Karen Corby presentation in MIX09 called Building Microsoft Silverlight Controls btw you can watch it here http://videos.visitmix.com/MIX09/T16F . But because I was unable to find this app I’ve created my own.