~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/Commands/SurroundWithCommand.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.IO;
 
6
using System.Linq;
 
7
 
 
8
using ICSharpCode.AvalonEdit.AddIn.Snippets;
 
9
using ICSharpCode.AvalonEdit.Editing;
 
10
using ICSharpCode.Core;
 
11
using ICSharpCode.SharpDevelop.Editor;
 
12
using ICSharpCode.SharpDevelop.Editor.CodeCompletion;
 
13
using ICSharpCode.SharpDevelop.Gui;
 
14
 
 
15
namespace ICSharpCode.AvalonEdit.AddIn.Commands
 
16
{
 
17
        public class SurroundWithCommand : AbstractMenuCommand
 
18
        {
 
19
                /// <summary>
 
20
                /// Starts the command
 
21
                /// </summary>
 
22
                public override void Run()
 
23
                {
 
24
                        ICodeEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ICodeEditorProvider;
 
25
                        
 
26
                        if (provider == null)
 
27
                                return;
 
28
                        
 
29
                        CodeSnippetGroup group = SnippetManager.Instance.FindGroup(Path.GetExtension(provider.TextEditor.FileName));
 
30
                        
 
31
                        if (group == null)
 
32
                                return;
 
33
                        
 
34
                        DefaultCompletionItemList list = new DefaultCompletionItemList();
 
35
                        
 
36
                        list.Items.AddRange(group.Snippets.Where(i => i.HasSelection).Select(item => item.CreateCompletionItem(provider.TextEditor)));
 
37
                        
 
38
                        new CodeSnippetCompletionWindow(provider.TextEditor, list).Show();
 
39
                }
 
40
        }
 
41
}