This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Catalog.cs
190 lines (162 loc) · 5.44 KB
/
Catalog.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Catalog.cs: Documentation Catalog.
//
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2008 Novell, Inc.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
namespace Monodoc.Widgets {
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
internal class Catalog : DocNode {
string path;
XmlDocument index_doc;
public Catalog () : base (null, "Monodoc Catalog") {}
public override DocViewItem CreateItem (DocView view)
{
return new ViewItem (view, this);
}
protected override void LoadChildren ()
{
foreach (XmlElement ns in index_doc.DocumentElement.SelectNodes ("Types/Namespace")) {
string ns_dir = Path.Combine (path, ns.GetAttribute ("Name"));
string file = Path.Combine (path, "ns-" + ns.GetAttribute ("Name") + ".xml");
if (!File.Exists (file))
file = ns_dir + ".xml";
if (!File.Exists (file))
continue;
AddChild (new NamespaceNode (this, file, ns_dir, ns));
}
}
public static Catalog Load (string directory_path)
{
if (!Directory.Exists (directory_path))
return null;
string index_file = System.IO.Path.Combine (directory_path, "index.xml");
if (!File.Exists (index_file))
return null;
XmlDocument doc = new XmlDocument ();
using (XmlTextReader rdr = new XmlTextReader (index_file))
doc.Load (rdr);
Catalog result = new Catalog ();
result.path = directory_path;
result.index_doc = doc;
return result;
}
public void Save ()
{
try {
if (path == null)
throw new Exception ("Path not set");
string cat_file = System.IO.Path.Combine (path, ".catalog.xml");
XmlSerializer serializer = new XmlSerializer (typeof (Catalog));
using (FileStream fs = File.Create (cat_file))
serializer.Serialize (fs, this);
} catch (Exception e) {
Console.Error.WriteLine ("Error saving settings: " + e);
}
}
class NSItem : DocViewItem {
LinkItem link;
KitchenSinkItem summ;
public NSItem (DocView view, NamespaceNode ns)
{
link = new LinkItem (view, ns.Caption, ns);
summ = new KitchenSinkItem (view, ns.Docs.Summary);
}
public override void Event (EventInfo info)
{
info.Position = Localize (info.Position);
if (link.Contains (info.Position))
link.Event (info);
else if (summ.Contains (info.Position))
summ.Event (info);
}
protected override void OnPaint (Gdk.Drawable win, Gdk.Point offset, Gdk.Rectangle clip)
{
Gdk.Point local = Globalize (offset);
link.Paint (win, local, clip);
summ.Paint (win, local, clip);
}
public override void Update (int width)
{
sz.Width = width;
link.Update (width);
if (link.Size.Width > sz.Width)
sz.Width = link.Size.Width;
link.Location = Gdk.Point.Zero;
sz.Height = link.Size.Height + Padding;
summ.Update (width);
summ.Location = new Gdk.Point (0, sz.Height);
sz.Height += summ.Size.Height;
}
}
class ViewItem : DocViewItem {
NSItem[] namespaces;
BannerItem banner;
LabelItem ns_label;
public ViewItem (DocView view, Catalog catalog)
{
banner = new BannerItem (view, catalog);
ns_label = new LabelItem (view, "Namespaces:");
namespaces = new NSItem [catalog.ChildCount];
for (int i = 0; i < catalog.ChildCount; i++)
namespaces [i] = new NSItem (view, catalog [i] as NamespaceNode);
}
const int ns_indent = 20;
public override void Update (int width)
{
sz.Width = width;
banner.Update (width);
banner.Location = Gdk.Point.Zero;
int height = banner.Size.Height + 2 * Padding;
ns_label.Update (width);
int line_height = ns_label.Size.Height;
height += line_height + Padding;
ns_label.Location = new Gdk.Point (Padding, height);
height += line_height + Padding;
width -= ns_indent;
for (int i = 0; i < namespaces.Length; i++) {
namespaces [i].Update (width);
namespaces [i].Location = new Gdk.Point (ns_indent, height + Padding);
height += namespaces [i].Size.Height + line_height;
}
sz.Height = height;
}
protected override void OnPaint (Gdk.Drawable win, Gdk.Point offset, Gdk.Rectangle clip)
{
banner.Paint (win, offset, clip);
ns_label.Paint (win, offset, clip);
foreach (NSItem item in namespaces)
item.Paint (win, offset, clip);
}
public override void Event (EventInfo info)
{
foreach (NSItem ns in namespaces) {
if (ns.Contains (info.Position))
ns.Event (info);
}
}
}
}
}