github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

NoahRic / EditorItemTemplates

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Item templates for editor extensions for Visual Studio 2010. — Read more

  cancel

http://blogs.msdn.com/noahric

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Added mising items to the .csproj file. 
NoahRic (author)
Wed Jan 27 00:50:21 -0800 2010
commit  c5357931db781e3b0dad76592c64807c73b676c6
tree    3ce0db08820990edbcf6a832fb3bbb10b78b32f0
parent  3e712cdd4872b7d6e72dff5dc392935ee9a63fca
EditorItemTemplates / CommandFilter.cs CommandFilter.cs
100644 71 lines (57 sloc) 2.665 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// A command filter for the editor. Command filters get an opportunity to observe and handle commands before and after the editor acts on them.
 
using System;
using System.ComponentModel.Composition;
using System.Runtime.InteropServices;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
using Microsoft.VisualStudio.Utilities;
 
namespace EditorItemTemplates
{
[Export(typeof(IVsTextViewCreationListener))]
    // TODO: Pick a more specific content type, like "csharp", if applicable
[ContentType("code")]
[TextViewRole(PredefinedTextViewRoles.Interactive)]
    class VsTextViewCreationListener : IVsTextViewCreationListener
    {
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            CommandFilter filter = new CommandFilter();
 
            IOleCommandTarget next;
            if (ErrorHandler.Succeeded(textViewAdapter.AddCommandFilter(filter, out next)))
                filter.Next = next;
        }
    }
 
    class CommandFilter : IOleCommandTarget
    {
        /// <summary>
        /// The next command target in the filter chain (provided by <see cref="IVsTextView.AddCommandFilter"/>).
        /// </summary>
        internal IOleCommandTarget Next { get; set; }
 
        public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut)
        {
            // TODO: Command handling before passing commands to the Next command target
 
            // Pass the command on to our next command target (if we want it the editor to handle it)
            int hresult = Next.Exec(ref pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
 
            // TODO: Command handling after passing commands to the Next command target.
 
            return hresult;
        }
 
        public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            // TODO: If we want to block or enable commands that the editor handles by default, do it before passing commands to Next
 
            return Next.QueryStatus(ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
        }
 
        #region Private helpers
 
        /// <summary>
        /// Get the char for a <see cref="VSConstants.VSStd2KCmdID.TYPECHAR"/> command.
        /// </summary>
        /// <param name="pvaIn">The "pvaIn" arg passed to <see cref="Exec"/>.</param>
        char GetTypedChar(IntPtr pvaIn)
        {
            return (char)(ushort)Marshal.GetObjectForNativeVariant(pvaIn);
        }
 
        #endregion
    }
}
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server