File: history.cs

package info (click to toggle)
mono-tools 4.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,868 kB
  • sloc: cs: 100,909; sh: 3,845; makefile: 2,040; xml: 126
file content (112 lines) | stat: -rw-r--r-- 1,848 bytes parent folder | download | duplicates (10)
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
104
105
106
107
108
109
110
111
112
namespace Monodoc {
	
using Gtk;
using System;
using System.Collections;

public abstract class PageVisit {

	public abstract void Go ();
}

delegate void SetSensitive (bool state);

public class History {
	Gtk.Widget back, forward;

	int pos = -1;
	ArrayList history;
	public int Count {
		get { return history.Count; }
	}
	
	public bool Active {
		get 
		{
			return active;
		}
		set 
		{
			if(value) {
				if (pos > 0)
					back.Sensitive = true;
				else
					back.Sensitive = false;
				if (pos+1 == history.Count)
					forward.Sensitive = false;
				else
					forward.Sensitive = true;
			}
			active = value;
		}
	}
	private bool active;
	
	public History (Gtk.Button back, Gtk.Button forward)
	{
		this.back = back;
		this.forward = forward;

		back.Sensitive = false;
		forward.Sensitive = false;

		back.Clicked += new EventHandler (BackClicked);
		forward.Clicked += new EventHandler (ForwardClicked);
		
		history = new ArrayList ();
	}

	public void AppendHistory (PageVisit page)
	{
		pos++;
		if (history.Count <= pos)
			history.Add (page);
		else
			history [pos] = page;

		if (pos > 0)
			back.Sensitive = true;
		forward.Sensitive = false;
	}

	public void ActivateCurrent ()
	{
		if (pos < 0)
			return;
		PageVisit p = (PageVisit) history [pos];
		p.Go ();
	}

	internal void BackClicked (object o, EventArgs args)
	{
		if (!active)
			return;
		if (pos < 1)
			return;
		pos--;
		PageVisit p = (PageVisit) history [pos];
		p.Go ();
		if (pos > 0)
			back.Sensitive = true;
		else
			back.Sensitive = false;
		forward.Sensitive = true;
	}

	internal void ForwardClicked (object o, EventArgs args)
	{
		if (!active)
			return;
		if (pos+1 == history.Count)
			return;

		pos++;
		PageVisit p = (PageVisit) history [pos];
		p.Go ();
		if (pos+1 == history.Count)
			forward.Sensitive = false;
		back.Sensitive = true;
	}

}
}