~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/extensions/manticore/browser/PrefsDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
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/ 
 
7
 * 
 
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
 
11
 * License. 
 
12
 *
 
13
 * The Original Code is Manticore.
 
14
 * 
 
15
 * The Initial Developer of the Original Code is
 
16
 * Silverstone Interactive. Portions created by Silverstone Interactive are
 
17
 * Copyright (C) 2001 Silverstone Interactive. 
 
18
 *
 
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.
 
29
 *
 
30
 * Contributor(s):
 
31
 *  Ben Goodger <ben@netscape.com>
 
32
 *
 
33
 */
 
34
 
 
35
namespace Silverstone.Manticore.Browser
 
36
{
 
37
  using System;
 
38
  using System.Drawing;
 
39
  using System.Collections;
 
40
  using System.ComponentModel;
 
41
  using System.Windows.Forms;
 
42
 
 
43
  using System.IO;
 
44
  using System.Xml;
 
45
 
 
46
  using Silverstone.Manticore.Toolkit;
 
47
  using Silverstone.Manticore.Core;
 
48
 
 
49
        /// <summary>
 
50
        /// Summary description for Form1.
 
51
        /// </summary>
 
52
        public class PrefsDialog : ManticoreDialog
 
53
        {
 
54
    private System.Windows.Forms.TreeView treeView1;
 
55
    private System.Windows.Forms.Button cancelButton;
 
56
    private System.Windows.Forms.Button okButton;
 
57
                /// <summary>
 
58
                /// Required designer variable.
 
59
                /// </summary>
 
60
                private System.ComponentModel.Container components = null;
 
61
 
 
62
    private Hashtable mNodes = null;
 
63
    private Hashtable mPanels = null;
 
64
    private PrefPanel mCurrentPanel = null;
 
65
 
 
66
    // LAME find a way to do global application service. 
 
67
    private Preferences mPrefs = null;
 
68
 
 
69
                public PrefsDialog(Form aOpener) : base(aOpener)
 
70
                {
 
71
                        //
 
72
                        // Required for Windows Form Designer support
 
73
                        //
 
74
                        InitializeComponent();
 
75
 
 
76
      okButton.Click += new EventHandler(OnOK);
 
77
 
 
78
      mNodes = new Hashtable();
 
79
      mPanels = new Hashtable();
 
80
 
 
81
      BrowserWindow window = mOpener as BrowserWindow;
 
82
      mPrefs = ServiceManager.Preferences;
 
83
 
 
84
      //
 
85
      // Initialize all the preference panels.
 
86
      //
 
87
      InitializePanels();
 
88
 
 
89
      // Add select handler for tree view so that we can
 
90
      // switch panels.
 
91
      treeView1.AfterSelect += new TreeViewEventHandler(OnTreeSelect);
 
92
 
 
93
      //
 
94
      // Initialize the category list. 
 
95
      //
 
96
      InitializeCategoryList();
 
97
 
 
98
      // XXX - eventually we want to remember user state. This will do
 
99
      //       for now. 
 
100
      treeView1.ExpandAll();
 
101
    }
 
102
 
 
103
    public void OnOK(object sender, EventArgs e)
 
104
    {
 
105
      // Call |Save| on each preferences panel...
 
106
      IEnumerator panels = mPanels.Values.GetEnumerator();
 
107
      while (panels.MoveNext()) {
 
108
        PrefPanel currPanel = panels.Current as PrefPanel;
 
109
        currPanel.Save();
 
110
      }
 
111
 
 
112
      // ... then flush preferences to disk for safe keepin'.
 
113
      // XXX not just yet. 
 
114
      // mPrefs.FlushUserPreferences();
 
115
    }
 
116
 
 
117
    public void OnTreeSelect(Object sender, TreeViewEventArgs e) 
 
118
    {
 
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;
 
127
      }
 
128
      else {
 
129
        if (selectedNode.FirstNode != null) {
 
130
          TreeView treeview = sender as TreeView;
 
131
          treeview.SelectedNode = selectedNode.FirstNode;
 
132
        }
 
133
      }
 
134
    }
 
135
 
 
136
    /// <summary>
 
137
    /// Create all the preferences panels.
 
138
    /// </summary>
 
139
    public void InitializePanels() 
 
140
    {
 
141
      BrowserDisplayPanel bdp = new BrowserDisplayPanel(this, mOpener, mPrefs);
 
142
      mPanels.Add("browser-display", bdp);
 
143
      this.Controls.Add(bdp);
 
144
    }
 
145
 
 
146
    /// <summary>
 
147
    /// Load the category list from XML and select the initial
 
148
    /// panel.
 
149
    /// </summary>
 
150
    private void InitializeCategoryList() 
 
151
    {
 
152
      mNodes = new Hashtable();
 
153
 
 
154
      XmlTextReader reader;
 
155
      reader = new XmlTextReader("browser\\PrefPanels.xml");
 
156
      
 
157
      reader.WhitespaceHandling = WhitespaceHandling.None;
 
158
      reader.MoveToContent();
 
159
 
 
160
      CatListRecurse(reader, treeView1);
 
161
    }
 
162
 
 
163
    private void CatListRecurse(XmlTextReader aReader, Object aRootNode) 
 
164
    {
 
165
      String inner = aReader.ReadInnerXml();
 
166
    
 
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);
 
171
 
 
172
      TreeNode node;
 
173
 
 
174
      while (reader2.Read()) {
 
175
        if (reader2.NodeType == XmlNodeType.Element) {
 
176
          switch (reader2.LocalName) {
 
177
          case "panel":
 
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 
 
181
            // load. 
 
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();
 
189
            }
 
190
 
 
191
            node = new TreeNode(values[0], 0, 0);
 
192
            if (aRootNode is TreeView) {
 
193
              TreeView rootView = aRootNode as TreeView;
 
194
              rootView.Nodes.Add(node);
 
195
            }
 
196
            else if (aRootNode is TreeNode) {
 
197
              TreeNode rootNode = aRootNode as TreeNode;
 
198
              rootNode.Nodes.Add(node);
 
199
            }
 
200
 
 
201
            mNodes.Add(node.GetHashCode(), values[1]);
 
202
            CatListRecurse(reader2, node);
 
203
            break;
 
204
          }
 
205
        }
 
206
      }
 
207
    }
 
208
 
 
209
                /// <summary>
 
210
                /// Clean up any resources being used.
 
211
                /// </summary>
 
212
                protected override void Dispose( bool disposing )
 
213
                {
 
214
                        if( disposing )
 
215
                        {
 
216
                                if(components != null)
 
217
                                {
 
218
                                        components.Dispose();
 
219
                                }
 
220
                        }
 
221
                        base.Dispose( disposing );
 
222
                }
 
223
 
 
224
                #region Windows Form Designer generated code
 
225
                /// <summary>
 
226
                /// Required method for Designer support - do not modify
 
227
                /// the contents of this method with the code editor.
 
228
                /// </summary>
 
229
                private void InitializeComponent()
 
230
                {
 
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();
 
235
      // 
 
236
      // cancelButton
 
237
      // 
 
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;
 
244
      // 
 
245
      // treeView1
 
246
      // 
 
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;
 
253
      // 
 
254
      // okButton
 
255
      // 
 
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;
 
262
      // 
 
263
      // PrefsDialog
 
264
      // 
 
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[] {
 
271
                                                                  this.okButton,
 
272
                                                                  this.cancelButton,
 
273
                                                                  this.treeView1});
 
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);
 
280
 
 
281
    }
 
282
                #endregion
 
283
        }
 
284
}