1
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
* The contents of this file are subject to the Mozilla Public License
4
* Version 1.1 (the "License"); you may not use this file except in
5
* compliance with the License. You may obtain a copy of the License at
6
* http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS IS" basis,
9
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10
* for the specific language governing rights and limitations under the
13
* The Original Code is Manticore.
15
* The Initial Developer of the Original Code is
16
* Silverstone Interactive. Portions created by Silverstone Interactive are
17
* Copyright (C) 2001 Silverstone Interactive.
19
* Alternatively, the contents of this file may be used under the
20
* terms of the GNU Public License (the "GPL"), in which case the
21
* provisions of the GPL are applicable instead of those above.
22
* If you wish to allow use of your version of this file only
23
* under the terms of the GPL and not to allow others to use your
24
* version of this file under the MPL, indicate your decision by
25
* deleting the provisions above and replace them with the notice
26
* and other provisions required by the GPL. If you do not delete
27
* the provisions above, a recipient may use your version of this
28
* file under either the MPL or the GPL.
31
* Ben Goodger <ben@netscape.com>
35
namespace Silverstone.Manticore.Browser
39
using System.Collections;
40
using System.ComponentModel;
41
using System.Windows.Forms;
46
using Silverstone.Manticore.Toolkit;
47
using Silverstone.Manticore.Core;
50
/// Summary description for Form1.
52
public class PrefsDialog : ManticoreDialog
54
private System.Windows.Forms.TreeView treeView1;
55
private System.Windows.Forms.Button cancelButton;
56
private System.Windows.Forms.Button okButton;
58
/// Required designer variable.
60
private System.ComponentModel.Container components = null;
62
private Hashtable mNodes = null;
63
private Hashtable mPanels = null;
64
private PrefPanel mCurrentPanel = null;
66
// LAME find a way to do global application service.
67
private Preferences mPrefs = null;
69
public PrefsDialog(Form aOpener) : base(aOpener)
72
// Required for Windows Form Designer support
74
InitializeComponent();
76
okButton.Click += new EventHandler(OnOK);
78
mNodes = new Hashtable();
79
mPanels = new Hashtable();
81
BrowserWindow window = mOpener as BrowserWindow;
82
mPrefs = ServiceManager.Preferences;
85
// Initialize all the preference panels.
89
// Add select handler for tree view so that we can
91
treeView1.AfterSelect += new TreeViewEventHandler(OnTreeSelect);
94
// Initialize the category list.
96
InitializeCategoryList();
98
// XXX - eventually we want to remember user state. This will do
100
treeView1.ExpandAll();
103
public void OnOK(object sender, EventArgs e)
105
// Call |Save| on each preferences panel...
106
IEnumerator panels = mPanels.Values.GetEnumerator();
107
while (panels.MoveNext()) {
108
PrefPanel currPanel = panels.Current as PrefPanel;
112
// ... then flush preferences to disk for safe keepin'.
114
// mPrefs.FlushUserPreferences();
117
public void OnTreeSelect(Object sender, TreeViewEventArgs e)
119
TreeNode selectedNode = e.Node;
120
String panelID = mNodes[selectedNode.GetHashCode()] as String;
121
PrefPanel newPanel = mPanels[panelID] as PrefPanel;
122
if (mCurrentPanel != null)
123
mCurrentPanel.Visible = false;
124
if (newPanel != null) {
125
newPanel.Visible = true;
126
mCurrentPanel = newPanel;
129
if (selectedNode.FirstNode != null) {
130
TreeView treeview = sender as TreeView;
131
treeview.SelectedNode = selectedNode.FirstNode;
137
/// Create all the preferences panels.
139
public void InitializePanels()
141
BrowserDisplayPanel bdp = new BrowserDisplayPanel(this, mOpener, mPrefs);
142
mPanels.Add("browser-display", bdp);
143
this.Controls.Add(bdp);
147
/// Load the category list from XML and select the initial
150
private void InitializeCategoryList()
152
mNodes = new Hashtable();
154
XmlTextReader reader;
155
reader = new XmlTextReader("browser\\PrefPanels.xml");
157
reader.WhitespaceHandling = WhitespaceHandling.None;
158
reader.MoveToContent();
160
CatListRecurse(reader, treeView1);
163
private void CatListRecurse(XmlTextReader aReader, Object aRootNode)
165
String inner = aReader.ReadInnerXml();
167
NameTable nt = new NameTable();
168
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
169
XmlParserContext ctxt = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
170
XmlTextReader reader2 = new XmlTextReader(inner, XmlNodeType.Element, ctxt);
174
while (reader2.Read()) {
175
if (reader2.NodeType == XmlNodeType.Element) {
176
switch (reader2.LocalName) {
178
// Tree node with children. Retrieve label and id. Label is
179
// used for visual presentation, id is hashed against node
180
// and is used as a key when looking for which panel to
182
String[] values = new String[2] {"", ""};
183
String[] names = new String[2] {"label", "id"};
184
for (int i = 0; i < names.Length; ++i) {
185
if (reader2.MoveToAttribute(names[i]) &&
186
reader2.ReadAttributeValue())
187
values[i] = reader2.Value;
188
reader2.MoveToElement();
191
node = new TreeNode(values[0], 0, 0);
192
if (aRootNode is TreeView) {
193
TreeView rootView = aRootNode as TreeView;
194
rootView.Nodes.Add(node);
196
else if (aRootNode is TreeNode) {
197
TreeNode rootNode = aRootNode as TreeNode;
198
rootNode.Nodes.Add(node);
201
mNodes.Add(node.GetHashCode(), values[1]);
202
CatListRecurse(reader2, node);
210
/// Clean up any resources being used.
212
protected override void Dispose( bool disposing )
216
if(components != null)
218
components.Dispose();
221
base.Dispose( disposing );
224
#region Windows Form Designer generated code
226
/// Required method for Designer support - do not modify
227
/// the contents of this method with the code editor.
229
private void InitializeComponent()
231
this.cancelButton = new System.Windows.Forms.Button();
232
this.treeView1 = new System.Windows.Forms.TreeView();
233
this.okButton = new System.Windows.Forms.Button();
234
this.SuspendLayout();
238
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
239
this.cancelButton.Location = new System.Drawing.Point(408, 296);
240
this.cancelButton.Name = "cancelButton";
241
this.cancelButton.TabIndex = 2;
242
this.cancelButton.Text = "Cancel";
243
this.cancelButton.FlatStyle = FlatStyle.System;
247
this.treeView1.ImageIndex = -1;
248
this.treeView1.Location = new System.Drawing.Point(16, 16);
249
this.treeView1.Name = "treeView1";
250
this.treeView1.SelectedImageIndex = -1;
251
this.treeView1.Size = new System.Drawing.Size(136, 264);
252
this.treeView1.TabIndex = 0;
256
this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
257
this.okButton.Location = new System.Drawing.Point(328, 296);
258
this.okButton.Name = "okButton";
259
this.okButton.TabIndex = 3;
260
this.okButton.Text = "OK";
261
this.okButton.FlatStyle = FlatStyle.System;
265
this.AcceptButton = this.okButton;
266
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
267
this.CancelButton = this.cancelButton;
268
this.ClientSize = new System.Drawing.Size(496, 328);
269
this.ControlBox = false;
270
this.Controls.AddRange(new System.Windows.Forms.Control[] {
274
this.HelpButton = true;
275
this.Name = "PrefsDialog";
276
this.ShowInTaskbar = false;
277
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
278
this.Text = "Options";
279
this.ResumeLayout(false);