1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
using AppKit;
using System;
using System.Collections.Generic;
namespace Monodoc {
public abstract class PageVisit {
public abstract void Go ();
}
delegate void SetSensitive (bool state);
public class History {
NSSegmentedCell navigation;
int pos = -1;
List<PageVisit> history = new List<PageVisit> ();
public int Count {
get { return history.Count; }
}
public bool Active {
get {
return active;
}
set {
if (value) {
navigation.SetEnabled (pos > 0, 0);
navigation.SetEnabled (pos+1 == history.Count, 1);
active = value;
}
}
}
bool active, ignoring;
public History (NSSegmentedCell navigation)
{
this.navigation = navigation;
active = true;
navigation.Activated += delegate(object sender, EventArgs e) {
var control = sender as NSSegmentedControl;
if (control.SelectedSegment == 0)
BackClicked ();
else
ForwardClicked ();
};
navigation.SetEnabled (false, 0);
navigation.SetEnabled (false, 1);
}
internal bool BackClicked ()
{
if (!active || pos < 1)
return false;
pos--;
PageVisit p = (PageVisit) history [pos];
ignoring = true;
p.Go ();
ignoring = false;
navigation.SetEnabled (pos > 0, 0);
navigation.SetEnabled (true, 1);
return true;
}
internal bool ForwardClicked ()
{
if (!active || pos+1 == history.Count)
return false;
pos++;
var pageVisit = history [pos];
ignoring = true;
pageVisit.Go ();
ignoring = false;
navigation.SetEnabled (pos+1 < history.Count, 1);
navigation.SetEnabled (true, 0);
return true;
}
public void AppendHistory (PageVisit page)
{
if (ignoring)
return;
pos++;
if (history.Count <= pos)
history.Add (page);
else
history [pos] = page;
navigation.SetEnabled (pos > 0, 0);
navigation.SetEnabled (false, 1);
}
public void ActivateCurrent ()
{
if (pos < 0)
return;
var pageVisit = history [pos];
pageVisit.Go ();
}
}
}
|