~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/monomac/samples/macdoc/AppleDocMergeWindowController.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Collections.Generic;
 
4
using System.Linq;
 
5
using System.Threading.Tasks;
 
6
using MonoMac.Foundation;
 
7
using MonoMac.AppKit;
 
8
 
 
9
namespace macdoc
 
10
{
 
11
        public partial class AppleDocMergeWindowController : MonoMac.AppKit.NSWindowController
 
12
        {
 
13
                public AppleDocMergeWindowController (IntPtr handle) : base (handle)
 
14
                {
 
15
                        Initialize ();
 
16
                }
 
17
 
 
18
                [Export ("initWithCoder:")]
 
19
                public AppleDocMergeWindowController (NSCoder coder) : base (coder)
 
20
                {
 
21
                        Initialize ();
 
22
                }
 
23
 
 
24
                public AppleDocMergeWindowController () : base ("AppleDocMergeWindow")
 
25
                {
 
26
                        Initialize ();
 
27
                }
 
28
 
 
29
                void Initialize ()
 
30
                {
 
31
                }
 
32
 
 
33
                public override void WindowDidLoad ()
 
34
                {
 
35
                        ProgressWidget.StartAnimation (this);
 
36
                }
 
37
 
 
38
                public void TrackProcessTask (Task<int> task)
 
39
                {
 
40
                        task.ContinueWith (t => {
 
41
                                var faulted = t.IsFaulted;
 
42
 
 
43
                                if (faulted)
 
44
                                        Logger.LogError ("Merger exception", t.Exception);
 
45
 
 
46
                                BeginInvokeOnMainThread (() => Finish (faulted || t.Result > 0, faulted ? 99 : t.Result));
 
47
                        });
 
48
                }
 
49
 
 
50
                void Finish (bool errored, int code)
 
51
                {
 
52
                        ProgressWidget.Hidden = true;
 
53
                        WizardButton.Hidden = false;
 
54
 
 
55
                        if (errored) {
 
56
                                WizardText.StringValue = string.Format ("There was a problem running the update (code {0}).", code);
 
57
                                WizardButton.Title = "Close";
 
58
                                WizardButton.Activated += CloseCallback;
 
59
                        } else {
 
60
                                WizardText.StringValue = "Update successful. Restart MacDoc for changes to take effect.";
 
61
                                WizardButton.Title = "Restart MacDoc";
 
62
                                WizardButton.Activated += RestartCallback;
 
63
                        }
 
64
                }
 
65
 
 
66
                void CloseCallback (object sender, EventArgs e)
 
67
                {
 
68
                        Close ();
 
69
                }
 
70
 
 
71
                void RestartCallback (object sender, EventArgs e)
 
72
                {
 
73
                        AppDelegate.RestartRequested = true;
 
74
                        NSApplication.SharedApplication.Terminate (this);
 
75
                }
 
76
 
 
77
                public new AppleDocMergeWindow Window {
 
78
                        get {
 
79
                                return (AppleDocMergeWindow)base.Window;
 
80
                        }
 
81
                }
 
82
        }
 
83
}
 
84