~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/DisplayBindings/XmlEditor/Project/Src/SelectedXmlElement.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 ICSharpCode.SharpDevelop.Editor;
 
6
 
 
7
namespace ICSharpCode.XmlEditor
 
8
{
 
9
        public class SelectedXmlElement
 
10
        {
 
11
                XmlElementPath path = new XmlElementPath();
 
12
                string selectedAttribute = String.Empty;
 
13
                string selectedAttributeValue = String.Empty;
 
14
                
 
15
                public SelectedXmlElement(ITextEditor textEditor)
 
16
                        : this(textEditor.Document.Text, textEditor.Caret.Offset)
 
17
                {
 
18
                }
 
19
                
 
20
                public SelectedXmlElement(string xml, int index)
 
21
                {
 
22
                        FindSelectedElement(xml, index);
 
23
                        FindSelectedAttribute(xml, index);
 
24
                        FindSelectedAttributeValue(xml, index);
 
25
                }
 
26
                
 
27
                void FindSelectedElement(string xml, int index)
 
28
                {
 
29
                        path = XmlParser.GetActiveElementStartPathAtIndex(xml, index);
 
30
                }
 
31
                
 
32
                void FindSelectedAttribute(string xml, int index)
 
33
                {
 
34
                        selectedAttribute = XmlParser.GetAttributeNameAtIndex(xml, index);
 
35
                }
 
36
                
 
37
                void FindSelectedAttributeValue(string xml, int index)
 
38
                {
 
39
                        selectedAttributeValue = XmlParser.GetAttributeValueAtIndex(xml, index);
 
40
                }
 
41
                
 
42
                public XmlElementPath Path {
 
43
                        get { return path; }
 
44
                }
 
45
                
 
46
                public string SelectedAttribute {
 
47
                        get { return selectedAttribute; }
 
48
                }
 
49
                
 
50
                public bool HasSelectedAttribute {
 
51
                        get { return selectedAttribute.Length > 0; }
 
52
                }
 
53
                
 
54
                public string SelectedAttributeValue {
 
55
                        get { return selectedAttributeValue; }
 
56
                }
 
57
                
 
58
                public bool HasSelectedAttributeValue {
 
59
                        get { return selectedAttributeValue.Length > 0; }
 
60
                }
 
61
        }
 
62
}