- SharpShell_Core_Library.zip
- SharpShell_Source_Code.zip
- SharpShell Source Code
- Dependencies
- Apex
- Apex.WinForms.dll
- SharpShell
- Info.txt
- packages
- Apex.1.5.0
- Apex.1.5.0.nupkg
- lib
- net35
- Apex.dll
- net40
- Apex.dll
- sl30
- Apex.Silverlight.dll
- sl3-wp
- Apex.WP7.dll
- sl40
- Apex.Silverlight4.dll
- sl4-wp71
- Apex.WP7.dll
- sl50
- Apex.Silverlight.dll
- ILMerge.2.12.0803
- ILMerge.2.12.0803.nupkg
- ILMerge.doc
- ILMerge.exe
- NUnit.2.6.2
- repositories.config
- Samples
- ContextMenu
- ContextMenuComponent
- Properties
- ContextMenuSample
- Properties
- CountLinesExtension
- DllContextMenuExtension
- IsolatedContextMenuComponent
- Diagnostics
- Interop
- Properties
- ServerRegistration
- SharpContextMenu
- DropHandler
- XsdDropHandler
- IconHandler
- DllIconHandler
- IconOverlayHandler
- ReadOnlyFileIconOverlayHandler
- InfoTipHandler
- FolderInfoTipHandler
- PreviewHandler
- IconPreviewHandler
- PropertySheet
- DrivePropertySheet
- ResourcesPropertySheet
- TextFilePropertySheet
- SharedAssemblyInfo.cs
- SharpShell.sln
- SharpShell
- SharpShellNativeBridge
- Todo.txt
- Tools
- ExtensionManager
- Properties
- Resources
- xsd.ico
- ServerInspector
- ServerManager
- ShellExtensionManager
- SharpShell_Tools.zip
- Apex.dll
- Apex.WinForms.dll
- ServerInspector.exe
- ServerManager.exe
- SharpShell.dll
|
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using SharpShell.Attributes;
using SharpShell.SharpContextMenu;
namespace CountLinesExtension
{
/// <summary>
/// The CountLinesExtensions is an example shell context menu extension,
/// implemented with SharpShell. It adds the command 'Count Lines' to text
/// files.
/// </summary>
[ComVisible(true)]
[COMServerAssociation(AssociationType.ClassOfExtension, ".txt")]
public class CountLinesExtension : SharpContextMenu
{
/// <summary>
/// Determines whether this instance can a shell context show menu, given the specified selected file list.
/// </summary>
/// <returns>
/// <c>true</c> if this instance should show a shell context menu for the specified file list; otherwise, <c>false</c>.
/// </returns>
protected override bool CanShowMenu()
{
// We always show the menu.
return true;
}
/// <summary>
/// Creates the context menu. This can be a single menu item or a tree of them.
/// </summary>
/// <returns>
/// The context menu for the shell context menu.
/// </returns>
protected override ContextMenuStrip CreateMenu()
{
// Create the menu strip.
var menu = new ContextMenuStrip();
// Create a 'count lines' item.
var itemCountLines = new ToolStripMenuItem
{
Text = "Count Lines...",
Image = Properties.Resources.CountLines
};
// When we click, we'll count the lines.
itemCountLines.Click += (sender, args) => CountLines();
// Add the item to the context menu.
menu.Items.Add(itemCountLines);
// Return the menu.
return menu;
}
/// <summary>
/// Counts the lines in the selected files.
/// </summary>
private void CountLines()
{
// Builder for the output.
var builder = new StringBuilder();
// Go through each file.
foreach (var filePath in SelectedItemPaths)
{
// Count the lines.
builder.AppendLine(string.Format("{0} - {1} Lines", Path.GetFileName(filePath), File.ReadAllLines(filePath).Length));
}
// Show the ouput.
MessageBox.Show(builder.ToString());
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.