~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/WorkflowDesigner/Project/WorkflowDisplayBinding.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 ICSharpCode.Core;
 
5
using System;
 
6
using System.Linq;
 
7
using System.Xml;
 
8
using ICSharpCode.SharpDevelop;
 
9
using ICSharpCode.SharpDevelop.Editor;
 
10
using ICSharpCode.SharpDevelop.Gui;
 
11
 
 
12
namespace ICSharpCode.WorkflowDesigner
 
13
{
 
14
        /// <summary>
 
15
        /// Display binding that attaches the workflow designer to .xaml files.
 
16
        /// </summary>
 
17
        public class WorkflowDisplayBinding : ISecondaryDisplayBinding
 
18
        {
 
19
                public bool CanAttachTo(IViewContent content)
 
20
                {
 
21
                        ITextEditorProvider p = content as ITextEditorProvider;
 
22
                        if (p != null) {
 
23
                                try {
 
24
                                        using (XmlTextReader r = new XmlTextReader(p.TextEditor.Document.CreateReader())) {
 
25
                                                r.XmlResolver = null;
 
26
                                                // find the opening of the root element:
 
27
                                                while (r.Read() && r.NodeType != XmlNodeType.Element);
 
28
                                                // attach if this is a workflow node
 
29
                                                return r.NamespaceURI == "http://schemas.microsoft.com/netfx/2009/xaml/activities";
 
30
                                        }
 
31
                                } catch (XmlException e) {
 
32
                                        LoggingService.Debug("WorkflowDisplayBinding got exception: " + e.Message);
 
33
                                        return false;
 
34
                                }
 
35
                        } else {
 
36
                                return false;
 
37
                        }
 
38
                }
 
39
                
 
40
                /// <summary>
 
41
                /// When you return true for this property, the CreateSecondaryViewContent method
 
42
                /// is called again after the LoadSolutionProjects thread has finished.
 
43
                /// </summary>
 
44
                public bool ReattachWhenParserServiceIsReady {
 
45
                        get { return false; }
 
46
                }
 
47
                
 
48
                public IViewContent[] CreateSecondaryViewContent(IViewContent viewContent)
 
49
                {
 
50
                        return new IViewContent[] { new WorkflowDesignerViewContent(viewContent.PrimaryFile) };
 
51
                }
 
52
        }
 
53
}