~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/xwt/Xwt/Xwt/TreeNavigator.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// TreeNavigator.cs
 
3
//  
 
4
// Author:
 
5
//       Lluis Sanchez <lluis@xamarin.com>
 
6
// 
 
7
// Copyright (c) 2011 Xamarin Inc
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
 
 
28
using System;
 
29
using Xwt.Drawing;
 
30
using System.Collections.ObjectModel;
 
31
using System.Collections.Generic;
 
32
using Xwt.Backends;
 
33
 
 
34
namespace Xwt
 
35
{
 
36
        public struct NodePosition
 
37
        {
 
38
                internal TreePosition ParentPos;
 
39
                internal int Index;
 
40
        }
 
41
        
 
42
        public class TreeNavigator
 
43
        {
 
44
                ITreeStoreBackend backend;
 
45
                TreePosition pos;
 
46
                
 
47
                internal TreeNavigator (ITreeStoreBackend backend, TreePosition pos)
 
48
                {
 
49
                        this.backend = backend;
 
50
                        this.pos = pos;
 
51
                }
 
52
                
 
53
                public TreePosition CurrentPosition {
 
54
                        get { return pos; }
 
55
                }
 
56
                
 
57
                public TreeNavigator Clone ()
 
58
                {
 
59
                        return new TreeNavigator (backend, pos);
 
60
                }
 
61
                
 
62
                bool CommitPos (TreePosition newPosition)
 
63
                {
 
64
                        if (newPosition != null) {
 
65
                                pos = newPosition;
 
66
                                return true;
 
67
                        }
 
68
                        else
 
69
                                return false;
 
70
                }
 
71
                
 
72
                public bool MoveToFirst ()
 
73
                {
 
74
                        return CommitPos (backend.GetChild (null, 0));
 
75
                }
 
76
 
 
77
                public bool MoveNext ()
 
78
                {
 
79
                        return CommitPos (backend.GetNext (pos));
 
80
                }
 
81
 
 
82
                public bool MovePrevious ()
 
83
                {
 
84
                        return CommitPos (backend.GetPrevious (pos));
 
85
                }
 
86
 
 
87
                public bool MoveToChild ()
 
88
                {
 
89
                        return CommitPos (backend.GetChild (pos, 0));
 
90
                }
 
91
 
 
92
                public bool MoveToParent ()
 
93
                {
 
94
                        return CommitPos (backend.GetParent (pos));
 
95
                }
 
96
 
 
97
                public TreeNavigator InsertBefore ()
 
98
                {
 
99
                        pos = backend.InsertBefore (pos);
 
100
                        return this;
 
101
                }
 
102
                
 
103
                public TreeNavigator InsertAfter ()
 
104
                {
 
105
                        pos = backend.InsertAfter (pos);
 
106
                        return this;
 
107
                }
 
108
                
 
109
                public TreeNavigator AddChild ()
 
110
                {
 
111
                        pos = backend.AddChild (pos);
 
112
                        return this;
 
113
                }
 
114
                
 
115
                public TreeNavigator SetValue<T> (DataField<T> field, T data)
 
116
                {
 
117
                        backend.SetValue (pos, field.Index, data);
 
118
                        return this;
 
119
                }
 
120
                
 
121
                public T GetValue<T> (DataField<T> field)
 
122
                {
 
123
                        return (T) backend.GetValue (pos, field.Index);
 
124
                }
 
125
                
 
126
                public void Remove ()
 
127
                {
 
128
                        backend.Remove (pos);
 
129
                }
 
130
                
 
131
                public void RemoveChildren ()
 
132
                {
 
133
                        TreePosition child = backend.GetChild (pos, 0);
 
134
                        while (child != null) {
 
135
                                backend.Remove (child);
 
136
                                child = backend.GetChild (pos, 0);
 
137
                        }
 
138
                }
 
139
        }
 
140
}