Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/macdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel de Icaza <miguel@gnome.org>2010-12-30 23:11:16 +0300
committerMiguel de Icaza <miguel@gnome.org>2010-12-30 23:11:16 +0300
commit7294674c88484a0ca5d4eb8698f8bddcd20c41aa (patch)
tree5b4a97d6c06e93f9af377e1a761018497608cb32 /history.cs
parent4e746a4db53aed6783c7a135144991ed6c4c75e1 (diff)
[macdoc] history support, back/fwd images
Diffstat (limited to 'history.cs')
-rw-r--r--history.cs101
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 ();
+ }
+ }
+}