2
// TreePathReference.cs
4
// Author: Jeffrey Stedfast <jeff@xamarin.com>
6
// Copyright (c) 2013 Xamarin Inc.
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
namespace MonoDevelop.Debugger
32
public sealed class TreePathReference : IDisposable
37
public TreePathReference (TreeModel model, TreePath path)
39
model.RowsReordered += HandleRowsReordered;
40
model.RowInserted += HandleRowInserted;
41
model.RowDeleted += HandleRowDeleted;
43
indices = path.Indices;
48
void HandleRowsReordered (object o, RowsReorderedArgs args)
50
int length = Model.IterNChildren (args.Iter);
51
int depth = args.Path.Depth;
53
if (length < 2 || !args.Path.IsAncestor (Path) || indices.Length <= depth)
56
for (int i = 0; i < length; i++) {
57
if (args.NewChildOrder[i] == indices[depth]) {
64
void HandleRowInserted (object o, RowInsertedArgs args)
66
var inserted = args.Path.Indices;
69
for (i = 0; i < inserted.Length - 1 && i < indices.Length - 1; i++) {
70
if (inserted[i] > indices[i]) {
71
// the inserted node is listed below the node we are watching, ignore it
75
if (inserted[i] < indices[i])
79
if (inserted[i] <= indices[i]) {
80
// the node was inserted above the node we are watching, update our position
86
void HandleRowDeleted (object o, RowDeletedArgs args)
88
var deleted = args.Path.Indices;
91
for (i = 0; i < deleted.Length && i < indices.Length; i++) {
92
if (deleted[i] > indices[i]) {
93
// the deleted node is listed below the node we are watching, ignore it
97
if (deleted[i] < indices[i]) {
98
// the deleted node is listed above the node we are watching, update our position
105
if (deleted.Length <= indices.Length) {
106
// the node we are watching (or its parent) has been deleted
111
public TreeModel Model {
115
public TreePath Path {
117
if (path == null && indices != null)
118
path = new TreePath (indices);
124
public bool IsValid {
125
get { return Model != null && indices != null; }
131
Model.RowsReordered -= HandleRowsReordered;
132
Model.RowInserted -= HandleRowInserted;
133
Model.RowDeleted -= HandleRowDeleted;
141
#region IDisposable implementation
142
public void Dispose ()