Created
June 12, 2009 16:37
-
-
Save noahrichards/128747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.Composition; | |
using Microsoft.VisualStudio.Utilities; | |
using Microsoft.VisualStudio.Text.Editor; | |
using Microsoft.VisualStudio.Text.Outlining; | |
using System.Windows.Input; | |
using Microsoft.VisualStudio.Text; | |
namespace CollapseAllButThis | |
{ | |
[Export(typeof(IKeyProcessorProvider))] | |
[ContentType("code")] | |
[Name("CollapseAllButThisKeyProc")] | |
[Order(Before = "VisualStudioKeyProcessor")] | |
internal sealed class CollapseAllKeyProvider : IKeyProcessorProvider | |
{ | |
[Import] | |
internal IOutliningManagerService OutliningManagerService; | |
public KeyProcessor GetAssociatedProcessor(IWpfTextViewHost wpfTextViewHost) | |
{ | |
var outliningManager = OutliningManagerService.GetOutliningManager(wpfTextViewHost.TextView.TextViewModel); | |
if (outliningManager != null) | |
return new CollapseAllKeyProc(wpfTextViewHost.TextView, outliningManager); | |
return null; | |
} | |
} | |
internal sealed class CollapseAllKeyProc : KeyProcessor | |
{ | |
private ITextView textView; | |
private IOutliningManager outliningManager; | |
public CollapseAllKeyProc(ITextView textView, IOutliningManager outliningManager) | |
{ | |
this.textView = textView; | |
this.outliningManager = outliningManager; | |
} | |
public override void KeyDown(KeyEventArgs args) | |
{ | |
if (args.Key == Key.D1 && | |
(Keyboard.Modifiers & ModifierKeys.Control) != 0) | |
{ | |
var point = textView.Caret.Position.BufferPosition; | |
outliningManager.CollapseAll(new SnapshotSpan(textView.TextSnapshot, 0, textView.TextSnapshot.Length), | |
collapsible => !collapsible.Extent.GetSpan(textView.TextSnapshot).Contains(point)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment