forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowPositionList.cs
80 lines (73 loc) · 2.56 KB
/
WindowPositionList.cs
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
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace GitUI
{
/// <summary>
/// Stores the state and position of a single window
/// </summary>
[DebuggerDisplay("Rect={Rect} State={State}")]
public class WindowPosition
{
public WindowPosition(Rectangle rect, FormWindowState state)
{
Rect = rect;
State = state;
}
public Rectangle Rect { get; private set; }
public FormWindowState State { get; private set; }
}
/// <summary>
/// A Hashtable for storing WindowPosition objects with the ability to
/// serialize them to the user's settings.
/// </summary>
public class WindowPositionList : Hashtable, IXmlSerializable
{
#region IXmlSerializable Members
public XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
reader.Read();
while (reader.NodeType != XmlNodeType.EndElement)
{
reader.ReadStartElement("window");
var name = reader.ReadElementString("name");
var state =
(FormWindowState) TypeDescriptor.GetConverter(typeof (FormWindowState))
.ConvertFromString(reader.ReadElementString("state"));
var rect =
(Rectangle) TypeDescriptor.GetConverter(typeof (Rectangle))
.ConvertFromString(reader.ReadElementString("position"));
reader.ReadEndElement();
Add(name, new WindowPosition(rect, state));
}
reader.ReadEndElement();
}
public void WriteXml(XmlWriter writer)
{
foreach (var key in Keys)
{
var position = (WindowPosition) this[key];
writer.WriteStartElement("window");
writer.WriteElementString("name", (String) key);
writer.WriteElementString(
"state",
TypeDescriptor.GetConverter(position.State).ConvertToString(position.State));
writer.WriteElementString(
"position",
TypeDescriptor.GetConverter(position.Rect).ConvertToString(position.Rect));
writer.WriteEndElement();
}
}
#endregion
}
}