diff options
author | Miguel de Icaza <miguel@gnome.org> | 2010-12-30 23:11:16 +0300 |
---|---|---|
committer | Miguel de Icaza <miguel@gnome.org> | 2010-12-30 23:11:16 +0300 |
commit | 7294674c88484a0ca5d4eb8698f8bddcd20c41aa (patch) | |
tree | 5b4a97d6c06e93f9af377e1a761018497608cb32 /history.cs | |
parent | 4e746a4db53aed6783c7a135144991ed6c4c75e1 (diff) |
[macdoc] history support, back/fwd images
Diffstat (limited to 'history.cs')
-rw-r--r-- | history.cs | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/history.cs b/history.cs new file mode 100644 index 0000000..ca5c6e4 --- /dev/null +++ b/history.cs @@ -0,0 +1,101 @@ +using MonoMac.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 void BackClicked () + { + if (!active || pos < 1) + return; + pos--; + PageVisit p = (PageVisit) history [pos]; + ignoring = true; + p.Go (); + ignoring = false; + navigation.SetEnabled (pos > 0, 0); + navigation.SetEnabled (true, 1); + } + + internal void ForwardClicked () + { + if (!active || pos+1 == history.Count) + return; + pos++; + var pageVisit = history [pos]; + ignoring = true; + pageVisit.Go (); + ignoring = false; + navigation.SetEnabled (pos+1 < history.Count, 1); + navigation.SetEnabled (true, 0); + } + + 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 (); + } + } +} |