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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140 |
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Ayende.NHibernateQueryAnalyzer.UserInterface.Interfaces;
using WeifenLuo.WinFormsUI;
namespace Ayende.NHibernateQueryAnalyzer.UserInterface
{
public partial class NQADocument : DockContent, IView
{
private readonly IView parentView;
private bool hasChanges;
private string documentTitle;
protected NQADocument()
{
InitializeComponent();
}
protected NQADocument(IView parentView)
: this()
{
this.parentView = parentView;
}
public bool HasChanges
{
get { return hasChanges; }
set
{
hasChanges = value;
SetTitle();
}
}
public virtual bool Save()
{
return false;
}
public string Title
{
get { return documentTitle; }
set
{
documentTitle = value;
SetTitle();
}
}
public void Close(bool askToSave)
{
if (askToSave == false)
HasChanges = false;
Close();
}
public virtual bool SaveAs()
{
return false;
}
public event EventHandler TitleChanged;
private void SetTitle()
{
Text = documentTitle + (HasChanges ? " *" : "");
if (TitleChanged != null)
TitleChanged(this, EventArgs.Empty);
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
if (!e.Cancel && HasChanges)
{
DialogResult response = MessageBox.Show("Do you want to save the changes?", Title, MessageBoxButtons.YesNoCancel);
switch (response)
{
case DialogResult.Cancel:
e.Cancel = true;
return;
case DialogResult.Yes:
Save();
break;
}
HasChanges = false;
}
}
/// <summary>
/// Starts the wait message by the UI. The view need to check every <c>checkInterval</c>
/// that the work was comleted (using <c>HasFinishedWork()</c> method).
/// The work should finish in shouldWaitFor, but there is no gurantee about it.
/// <c>EndWait</c> is called to end the wait.
/// </summary>
/// <param name="waitMessage">The Wait message.</param>
/// <param name="checkInterval">Check interval.</param>
/// <param name="shouldWaitFor">Should wait for.</param>
public void StartWait(string waitMessage, int checkInterval, int shouldWaitFor)
{
parentView.StartWait(waitMessage, checkInterval, shouldWaitFor);
}
public void EndWait(string endMessage)
{
parentView.EndWait(endMessage);
}
public virtual void AddException(Exception ex)
{
parentView.AddException(ex);
}
public void ShowError(string error)
{
parentView.ShowError(error);
}
/// <summary>
/// Executes the delegate in the UI thread.
/// </summary>
/// <param name="d">Delegate to execute</param>
/// <param name="parameters">Parameters.</param>
public void ExecuteInUIThread(Delegate d, params object[] parameters)
{
parentView.ExecuteInUIThread(d, parameters);
}
public bool AskYesNo(string question, string title)
{
return parentView.AskYesNo(question, title);
}
public string Ask(string question, string answer)
{
return parentView.Ask(question, answer);
}
}
} |