A whole bunch of changes, primarily:

- Basics of a Bookmarks Service
- Beginnings of Bookmarks UI
- Basics of automated content (Menu/Tree) builders
- Basics of datasource API
- Basics of command updating system
- Initial "Service Manager"
- Updates to project file to make it build from inside MSVS7, allowing debugging.
This commit is contained in:
ben%netscape.com 2001-08-01 03:48:08 +00:00
parent 5c0b6349e6
commit a73f46a423
28 changed files with 2719 additions and 355 deletions

View File

@ -9,7 +9,7 @@
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Project"
AssemblyName = "Manticore"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
@ -17,7 +17,7 @@
DelaySign = "false"
NoStandardLibraries = "true"
OutputType = "WinExe"
RootNamespace = "Project"
RootNamespace = "Silverstone.Manticore"
StartupObject = ""
>
<Config
@ -32,7 +32,7 @@
FileAlignment = "4096"
IncrementalBuild = "true"
Optimize = "false"
OutputPath = "bin\"
OutputPath = ".\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
@ -94,6 +94,10 @@
Name = "System.XML"
AssemblyName = "System.Xml"
/>
<Reference
Name = "mscorlib"
AssemblyName = "mscorlib"
/>
</References>
</Build>
<Files>
@ -116,6 +120,31 @@
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "bookmarks\BookmarksTreeView.cs"
SubType = "Component"
BuildAction = "Compile"
/>
<File
RelPath = "bookmarks\BookmarksWindow.cs"
SubType = "Form"
BuildAction = "Compile"
/>
<File
RelPath = "bookmarks\BookmarksWindow.resx"
DependentUpon = "BookmarksWindow.cs"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "bookmarks\FileBookmark.cs"
SubType = "Form"
BuildAction = "Compile"
/>
<File
RelPath = "bookmarks\FileBookmark.resx"
DependentUpon = "FileBookmark.cs"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "browser\aboutdialog.cs"
SubType = "Form"
@ -193,16 +222,55 @@
DependentUpon = "RestoreSessionSettings.cs"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "core\DataStore.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "core\FileLocator.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "core\preferences.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "layout\layoutabstraction.cs"
SubType = "Component"
RelPath = "core\ServiceManager.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "defaults\bookmarks.xml"
BuildAction = "Content"
/>
<File
RelPath = "defaults\default-prefs.xml"
BuildAction = "Content"
/>
<File
RelPath = "defaults\user-prefs.xml"
BuildAction = "Content"
/>
<File
RelPath = "layout\layoutabstraction.cs"
SubType = "UserControl"
BuildAction = "Compile"
/>
<File
RelPath = "resources\bookmark.png"
BuildAction = "Content"
/>
<File
RelPath = "resources\bookmark-folder-closed.png"
BuildAction = "Content"
/>
<File
RelPath = "resources\bookmark-folder-open.png"
BuildAction = "Content"
/>
<File
RelPath = "resources\manticore.png"
BuildAction = "Content"
@ -211,11 +279,31 @@
RelPath = "resources\manticore.psd"
BuildAction = "None"
/>
<File
RelPath = "toolkit\CommandUpdater.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "toolkit\ContentBuilder.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "toolkit\ManticoreDialog.cs"
SubType = "Form"
BuildAction = "Compile"
/>
<File
RelPath = "toolkit\ManticoreWindow.cs"
SubType = "Form"
BuildAction = "Compile"
/>
<File
RelPath = "toolkit\MenuBuilder.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "toolkit\ProgressMeter.cs"
SubType = "Component"
@ -236,6 +324,16 @@
SubType = "Component"
BuildAction = "Compile"
/>
<File
RelPath = "toolkit\toolkit.toolbars.resx"
DependentUpon = "toolkit.toolbars.cs"
BuildAction = "EmbeddedResource"
/>
<File
RelPath = "toolkit\TreeBuilder.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>

View File

@ -42,42 +42,30 @@ namespace Silverstone.Manticore.App
using Silverstone.Manticore.Browser;
using Silverstone.Manticore.Core;
using Silverstone.Manticore.Bookmarks;
public class ManticoreApp
{
// XXX Need to do something here more similar
// to what mozilla does here for parameterized
// window types.
private Hashtable mBrowserWindows;
private Preferences mPreferences;
private Bookmarks mBookmarks;
public Preferences Prefs {
get {
return mPreferences;
private static BrowserWindow mMostRecentBrowserWindow = null;
public static BrowserWindow MostRecentBrowserWindow
{
get
{
return mMostRecentBrowserWindow;
}
set
{
mMostRecentBrowserWindow = value;
}
}
public Bookmarks BM {
get {
return mBookmarks;
}
}
public ManticoreApp()
{
mBrowserWindows = new Hashtable();
// Initialize default and user preferences
mPreferences = new Preferences();
mPreferences.InitializeDefaults();
mPreferences.LoadUserPreferences();
// Initialize bookmarks
mBookmarks = new Bookmarks(this);
mBookmarks.LoadBookmarks();
if (!RestoreSession())
OpenBrowser();
@ -90,7 +78,7 @@ namespace Silverstone.Manticore.App
SaveSession();
// Flush preferences to disk.
mPreferences.FlushUserPreferences();
ServiceManager.Preferences.FlushUserPreferences();
Application.Exit();
}
@ -101,8 +89,8 @@ namespace Silverstone.Manticore.App
/// </summary>
private void SaveSession()
{
if (mPreferences.GetIntPref("browser.homepage.mode") == 2) {
bool isLastPageOnly = mPreferences.GetIntPref("browser.session.windowmode") == 0;
if (ServiceManager.Preferences.GetIntPref("browser.homepage.mode") == 2) {
bool isLastPageOnly = ServiceManager.Preferences.GetIntPref("browser.session.windowmode") == 0;
// XXX need to get all windows of type browser.
IEnumerator browsers = mBrowserWindows.Values.GetEnumerator();
int count = 0;
@ -115,11 +103,11 @@ namespace Silverstone.Manticore.App
BrowserWindow currWindow = browsers.Current as BrowserWindow;
String pref = "browser.session.windows.";
pref += currWindow.Type + count++;
mPreferences.SetStringPref(pref, currWindow.URL);
mPreferences.SetIntPref(pref + ".left", currWindow.Left);
mPreferences.SetIntPref(pref + ".top", currWindow.Top);
mPreferences.SetIntPref(pref + ".width", currWindow.Width);
mPreferences.SetIntPref(pref + ".height", currWindow.Height);
ServiceManager.Preferences.SetStringPref(pref, currWindow.URL);
ServiceManager.Preferences.SetIntPref(pref + ".left", currWindow.Left);
ServiceManager.Preferences.SetIntPref(pref + ".top", currWindow.Top);
ServiceManager.Preferences.SetIntPref(pref + ".width", currWindow.Width);
ServiceManager.Preferences.SetIntPref(pref + ".height", currWindow.Height);
}
// XXX need to save session histories.
}
@ -131,15 +119,15 @@ namespace Silverstone.Manticore.App
/// <returns>Whether or not a session was restored.</returns>
private bool RestoreSession()
{
if (mPreferences.GetIntPref("browser.homepage.mode") == 2) {
IEnumerator branch = mPreferences.GetBranch("browser.session.windows");
if (ServiceManager.Preferences.GetIntPref("browser.homepage.mode") == 2) {
IEnumerator branch = ServiceManager.Preferences.GetBranch("browser.session.windows");
while (branch.MoveNext()) {
String pref = branch.Current as String;
String url = mPreferences.GetStringPref(pref);
int x = mPreferences.GetIntPref(pref + ".left");
int y = mPreferences.GetIntPref(pref + ".top");
int width = mPreferences.GetIntPref(pref + ".width");
int height = mPreferences.GetIntPref(pref + ".height");
String url = ServiceManager.Preferences.GetStringPref(pref);
int x = ServiceManager.Preferences.GetIntPref(pref + ".left");
int y = ServiceManager.Preferences.GetIntPref(pref + ".top");
int width = ServiceManager.Preferences.GetIntPref(pref + ".width");
int height = ServiceManager.Preferences.GetIntPref(pref + ".height");
// Create a new browser with the applicable url at the applicable
// location.
@ -148,7 +136,7 @@ namespace Silverstone.Manticore.App
window.Size = new Size(width, height);
}
// XXX need to reinit session histories.
mPreferences.RemoveBranch("browser.session.windows");
ServiceManager.Preferences.RemoveBranch("browser.session.windows");
return true;
}
return false;

View File

@ -0,0 +1,172 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Bookmarks
{
using System;
using System.Drawing;
using System.Windows.Forms;
using Silverstone.Manticore.Core;
using Silverstone.Manticore.Toolkit;
/// <summary>
/// A Bookmarks Tree widget
/// </summary>
public class BookmarksTreeView : ManticoreTreeView
{
protected BaseTreeBuilder mBuilder;
public BookmarksTreeView(String aRoot)
{
mBuilder = new BaseTreeBuilder(this, null);
mBuilder.Root = aRoot;
mBuilder.DataStore = DataStoreRegistry.GetDataStore("Bookmarks");
mBuilder.DataStore.AddObserver(mBuilder);
// Use bright green as transparent colour
mIconTransparentColor = ColorTranslator.FromOle(0x00FF00);
ImageList = new ImageList();
// Built in Bookmark icons
ImageList.Images.Add(Image.FromFile(@"resources\bookmark-folder-closed.png"), mIconTransparentColor);
ImageList.Images.Add(Image.FromFile(@"resources\bookmark-folder-open.png"), mIconTransparentColor);
ImageList.Images.Add(Image.FromFile(@"resources\bookmark.png"), mIconTransparentColor);
// Don't draw lines to root
ShowRootLines = false;
ShowPlusMinus = true;
AfterLabelEdit += new NodeLabelEditEventHandler(OnAfterLabelEdit);
AfterExpand += new TreeViewEventHandler(OnAfterExpand);
AfterCollapse += new TreeViewEventHandler(OnAfterCollapse);
}
public void Build()
{
mBuilder.Build();
}
public String Root
{
get
{
return mBuilder.Root;
}
set
{
if (mBuilder.Root != value)
mBuilder.Root = value;
}
}
public override int GetIconIndex(CommandTarget aTarget)
{
int index = 2;
if (aTarget.IsContainer)
{
index = 0;
if (aTarget.IsOpen)
index = 1;
}
int fileIndex = GetIconIndex(aTarget.IconURL);
if (fileIndex != -1)
index = fileIndex;
return index;
}
/// <summary>
/// Retrieves the single root |ManticoreTreeNode| in the TreeView.
/// </summary>
/// <returns></returns>
protected ManticoreTreeNode GetRootItem()
{
if (Nodes.Count == 0)
return null;
return Nodes[0] as ManticoreTreeNode;
}
public void NewFolder()
{
ManticoreTreeNode root = GetRootItem();
if (root != null)
{
ManticoreTreeNode temp = new ManticoreTreeNode("New Folder", null);
root.Nodes.Add(temp);
LabelEdit = true;
temp.BeginEdit();
}
}
protected void OnAfterLabelEdit(Object sender, NodeLabelEditEventArgs e)
{
ManticoreTreeNode root = GetRootItem();
if (root != null)
{
ManticoreTreeNode temp = e.Node as ManticoreTreeNode;
String parentID = root.Data as String;
Bookmarks bmks = ServiceManager.Bookmarks;
String bookmarkID = bmks.CreateBookmark(e.Label, parentID, -1);
bmks.SetBookmarkAttribute(bookmarkID, "container", "true");
bmks.SetBookmarkAttribute(bookmarkID, "open", "true");
e.Node.Text = "FruitLoop";
e.Node.EndEdit(false);
root.Nodes.Remove(temp);
LabelEdit = false;
}
else
e.Node.EndEdit(true);
}
protected void OnAfterExpand(Object sender, TreeViewEventArgs e)
{
ManticoreTreeNode node = e.Node as ManticoreTreeNode;
String nodeID = node.Data as String;
Bookmarks bmks = ServiceManager.Bookmarks;
bmks.SetBookmarkAttribute(nodeID, "open", "true");
node.ImageIndex = 1;
}
protected void OnAfterCollapse(Object sender, TreeViewEventArgs e)
{
ManticoreTreeNode node = e.Node as ManticoreTreeNode;
String nodeID = node.Data as String;
Bookmarks bmks = ServiceManager.Bookmarks;
bmks.SetBookmarkAttribute(nodeID, "open", "false");
node.ImageIndex = 0;
}
}
}

View File

@ -0,0 +1,138 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Bookmarks
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Silverstone.Manticore.Toolkit;
/// <summary>
/// Summary description for BookmarksWindow.
/// </summary>
public class BookmarksWindow : ManticoreWindow
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private ManticoreTreeView treeView1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private BaseTreeBuilder mBuilder = null;
public BookmarksWindow()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// treeView1
//
treeView1 = new ManticoreTreeView();
treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
treeView1.ImageIndex = -1;
treeView1.Name = "treeView1";
treeView1.SelectedImageIndex = -1;
treeView1.Size = new System.Drawing.Size(584, 409);
treeView1.TabIndex = 1;
mBuilder = new BaseTreeBuilder(treeView1, null);
mBuilder.Build();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).BeginInit();
this.SuspendLayout();
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 409);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1});
this.statusBar1.Size = new System.Drawing.Size(584, 20);
this.statusBar1.TabIndex = 0;
this.statusBar1.Text = "statusBar1";
//
// statusBarPanel1
//
this.statusBarPanel1.Text = "statusBarPanel1";
//
// BookmarksWindow
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(584, 429);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.treeView1,
this.statusBar1});
this.Name = "BookmarksWindow";
this.Text = "Bookmarks for %USER%";
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
this.ResumeLayout(false);
}
#endregion
}
}

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" targetNamespace="" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<data name="$this.Name">
<value>BookmarksWindow</value>
</data>
<resheader name="ResMimeType">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="Version">
<value>1.0.0.0</value>
</resheader>
<resheader name="Reader">
<value>System.Resources.ResXResourceReader</value>
</resheader>
<resheader name="Writer">
<value>System.Resources.ResXResourceWriter</value>
</resheader>
</root>

View File

@ -0,0 +1,253 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Bookmarks
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Silverstone.Manticore.Toolkit;
using Silverstone.Manticore.Core;
/// <summary>
/// Summary description for FileBookmark.
/// </summary>
public class FileBookmark : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private BookmarksTreeView mFolderTree;
private System.Windows.Forms.Button mOKButton;
private System.Windows.Forms.Button mCancelButton;
private System.Windows.Forms.Button mUseDefaultButton;
private System.Windows.Forms.TextBox mLocationField;
private System.Windows.Forms.Button mNewFolderButton;
private System.Windows.Forms.TextBox mNameField;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public FileBookmark(String aURL, String aTitle)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
mNameField.Text = aTitle;
mLocationField.Text = aURL;
//
// folderTree
//
mFolderTree = new BookmarksTreeView("BookmarksRoot");
mFolderTree.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
mFolderTree.ImageIndex = -1;
mFolderTree.Location = new System.Drawing.Point(64, 88);
mFolderTree.Name = "folderTree";
mFolderTree.SelectedImageIndex = -1;
mFolderTree.Size = new System.Drawing.Size(208, 144);
mFolderTree.TabIndex = 5;
Controls.Add(mFolderTree);
mFolderTree.Build();
Bitmap bmp = new Bitmap(@"resources\bookmark.png");
bmp.MakeTransparent(ColorTranslator.FromOle(0x00FF00));
// this.Icon = new Icon(
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool aDisposing)
{
if (aDisposing && components != null)
components.Dispose();
base.Dispose(aDisposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mLocationField = new System.Windows.Forms.TextBox();
this.mCancelButton = new System.Windows.Forms.Button();
this.mNameField = new System.Windows.Forms.TextBox();
this.mNewFolderButton = new System.Windows.Forms.Button();
this.mUseDefaultButton = new System.Windows.Forms.Button();
this.mOKButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// mLocationField
//
this.mLocationField.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.mLocationField.Location = new System.Drawing.Point(64, 48);
this.mLocationField.Name = "mLocationField";
this.mLocationField.Size = new System.Drawing.Size(296, 20);
this.mLocationField.TabIndex = 3;
this.mLocationField.Text = "";
//
// mCancelButton
//
this.mCancelButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.mCancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.mCancelButton.Location = new System.Drawing.Point(288, 248);
this.mCancelButton.Name = "mCancelButton";
this.mCancelButton.TabIndex = 9;
this.mCancelButton.Text = "Cancel";
//
// mNameField
//
this.mNameField.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.mNameField.Location = new System.Drawing.Point(64, 16);
this.mNameField.Name = "mNameField";
this.mNameField.Size = new System.Drawing.Size(296, 20);
this.mNameField.TabIndex = 1;
this.mNameField.Text = "";
//
// mNewFolderButton
//
this.mNewFolderButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.mNewFolderButton.Location = new System.Drawing.Point(280, 88);
this.mNewFolderButton.Name = "mNewFolderButton";
this.mNewFolderButton.Size = new System.Drawing.Size(80, 23);
this.mNewFolderButton.TabIndex = 6;
this.mNewFolderButton.Text = "Ne&w Folder...";
this.mNewFolderButton.Click += new System.EventHandler(this.mNewFolderButton_Click);
//
// mUseDefaultButton
//
this.mUseDefaultButton.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
this.mUseDefaultButton.Location = new System.Drawing.Point(280, 120);
this.mUseDefaultButton.Name = "mUseDefaultButton";
this.mUseDefaultButton.Size = new System.Drawing.Size(80, 23);
this.mUseDefaultButton.TabIndex = 7;
this.mUseDefaultButton.Text = "Use &Default";
//
// mOKButton
//
this.mOKButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
this.mOKButton.Location = new System.Drawing.Point(208, 248);
this.mOKButton.Name = "mOKButton";
this.mOKButton.TabIndex = 8;
this.mOKButton.Text = "OK";
this.mOKButton.Click += new System.EventHandler(this.mOKButton_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(8, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(38, 13);
this.label1.TabIndex = 0;
this.label1.Text = "&Name:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(8, 48);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(50, 13);
this.label2.TabIndex = 2;
this.label2.Text = "&Location:";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(8, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(53, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Create in:";
//
// FileBookmark
//
this.AcceptButton = this.mOKButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.mCancelButton;
this.ClientSize = new System.Drawing.Size(376, 277);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.mCancelButton,
this.mOKButton,
this.mUseDefaultButton,
this.mNewFolderButton,
this.label3,
this.label2,
this.label1,
this.mLocationField,
this.mNameField});
this.MinimumSize = new System.Drawing.Size(384, 300);
this.Name = "FileBookmark";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
this.Text = "File Bookmark";
this.ResumeLayout(false);
}
#endregion
private void mNewFolderButton_Click(object sender, System.EventArgs e)
{
mFolderTree.NewFolder();
}
private void mOKButton_Click(object sender, System.EventArgs e)
{
String destinationFolder = "Bookmarks"; // XXX Parameterize this
ManticoreTreeNode node = mFolderTree.SelectedNode as ManticoreTreeNode;
if (node != null)
destinationFolder = node.Data as String;
Bookmarks bmks = ServiceManager.Bookmarks;
String bookmarkID = bmks.CreateBookmark(mNameField.Text, destinationFolder, -1);
bmks.SetBookmarkAttribute(bookmarkID, "url", mLocationField.Text);
Close();
}
}
}

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" targetNamespace="" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<data name="$this.Name">
<value>FileBookmark</value>
</data>
<resheader name="ResMimeType">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="Version">
<value>1.0.0.0</value>
</resheader>
<resheader name="Reader">
<value>System.Resources.ResXResourceReader</value>
</resheader>
<resheader name="Writer">
<value>System.Resources.ResXResourceWriter</value>
</resheader>
</root>

View File

@ -39,34 +39,63 @@ namespace Silverstone.Manticore.Bookmarks
using System.Xml;
using System.IO;
using System.Collections;
using Silverstone.Manticore.Core;
using Silverstone.Manticore.App;
public class Bookmarks
public class Bookmarks : IDataStore
{
private XmlDocument mBookmarksDoc;
private XmlDocument mBookmarksDocument;
private String mBookmarksFile;
private ManticoreApp mApplication;
private Queue mObservers = null;
private bool mBookmarksLoaded = false;
public Bookmarks(ManticoreApp aApplication)
///////////////////////////////////////////////////////////////////////////
// Bookmarks implementation
public Bookmarks()
{
mApplication = aApplication;
mBookmarksDocument = new XmlDocument();
}
mBookmarksDoc = new XmlDocument();
mBookmarksFile = mApplication.Prefs.GetStringPref("browser.bookmarksfile");
// XXX Need to do windows profile stuff here
if (mBookmarksFile == "")
mBookmarksFile = "bookmarks.xml";
~Bookmarks()
{
mBookmarksDocument.Save(mBookmarksFile);
}
public void LoadBookmarks()
{
// First of all, the user may have chosen to place the bookmark file
// in a specific location.
mBookmarksFile = ServiceManager.Preferences.GetStringPref("browser.bookmarksfile");
// Otherwise, look in the profile directory.
if (mBookmarksFile == "")
mBookmarksFile = FileLocator.GetManticorePath("LocalBookmarks");
// Support remote bookmarks by setting up an asynchronous load & parse.
XmlTextReader reader = new XmlTextReader(mBookmarksFile);
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.MoveToContent();
String xml = reader.ReadOuterXml();
reader.Close();
mBookmarksDoc.LoadXml(xml);
try
{
mBookmarksDocument.Load(mBookmarksFile);
}
catch (XmlException)
{
// Something went wrong, we'll just assume a malformed or non-existant
// preferences file, blow it away and insert a new one. Could potentially
// be dangerous.
try
{
File.Copy(@"defaults\bookmarks.xml", mBookmarksFile, true);
}
catch (DirectoryNotFoundException)
{
String manticoreAppData = FileLocator.GetManticorePath("AppData");
Directory.CreateDirectory(manticoreAppData);
File.Copy(@"defaults\bookmarks.xml", mBookmarksFile, true);
}
}
mBookmarksLoaded = true;
}
public void ImportBookmarks()
@ -74,9 +103,29 @@ namespace Silverstone.Manticore.Bookmarks
// Import a Netscape bookmarks file.
}
public void CreateBookmark(Bookmark aBookmark, Bookmark aBookmarkFolder)
public String CreateBookmark(String aLabel, String aParentID, int aPosition)
{
XmlElement parentElt = GetElementById(aParentID);
XmlElement childElt = mBookmarksDocument.CreateElement("item");
childElt.SetAttribute("label", aLabel);
String bookmarkID = Bookmarks.GenerateID();
childElt.SetAttribute("id", bookmarkID);
if (aPosition != -1)
parentElt.InsertBefore(childElt, parentElt.ChildNodes[aPosition]);
else
parentElt.AppendChild(childElt);
CommandTarget target = new CommandTarget(aLabel, "", bookmarkID, false);
CommandTarget parentTarget = new CommandTarget("", "", aParentID, true);
IEnumerator observers = mObservers.GetEnumerator();
while (observers.MoveNext())
{
IDataStoreObserver idso = observers.Current as IDataStoreObserver;
idso.OnNodeAdded(target, parentTarget, -1);
}
return bookmarkID;
}
public void DeleteBookmark(Bookmark aBookmark)
@ -84,12 +133,137 @@ namespace Silverstone.Manticore.Bookmarks
}
public String GenerateID()
/// <summary>
/// Retrieve the string value of a given Bookmark property. We expose this API
/// so as not to have to expose the internal DOM implementation of Bookmarks.
/// </summary>
/// <param name="aBookmarkID"></param>
/// <param name="aAttribute"></param>
/// <returns></returns>
public String GetBookmarkAttribute(String aBookmarkID, String aAttribute)
{
// Generate a random ID for a bookmark item
return "";
XmlElement elt = GetElementById(aBookmarkID);
return elt.GetAttribute(aAttribute);
}
public void SetBookmarkAttribute(String aBookmarkID, String aAttribute, String aValue)
{
XmlElement elt = GetElementById(aBookmarkID);
CommandTarget oldTarget = new CommandTarget();
switch (aAttribute)
{
case "label":
oldTarget.Label = elt.GetAttribute(aAttribute);
break;
case "icon":
oldTarget.IconURL = elt.GetAttribute(aAttribute);
break;
case "container":
oldTarget.IsContainer = elt.GetAttribute(aAttribute) == "true";
break;
case "open":
oldTarget.IsOpen = elt.GetAttribute(aAttribute) == "true";
break;
}
oldTarget.Data = aBookmarkID;
elt.SetAttribute(aAttribute, aValue);
// Enumerate the attributes presentation cares about and set the attribute on the
// target if it is being changed.
// XXX could optimize this.
CommandTarget newTarget = new CommandTarget();
switch (aAttribute)
{
case "label":
newTarget.Label = aValue;
break;
case "icon":
newTarget.IconURL = aValue;
break;
case "container":
newTarget.IsContainer = aValue == "true";
break;
case "open":
newTarget.IsOpen = aValue == "true";
break;
}
newTarget.Data = aBookmarkID;
IEnumerator observers = mObservers.GetEnumerator();
while (observers.MoveNext())
{
IDataStoreObserver idso = observers.Current as IDataStoreObserver;
idso.OnNodeChanged(oldTarget, newTarget);
}
}
public static String GenerateID()
{
// Generate a random ID for a bookmark item
Random rand = new Random();
return String.Format("NC:Bookmark${0:X}", rand.Next());
}
///////////////////////////////////////////////////////////////////////////
// IDataStore implementation
public void GetElements(String aContainerID, out IEnumerator aElements)
{
XmlElement container = GetElementById(aContainerID);
if (container == null)
container = mBookmarksDocument.DocumentElement.FirstChild as XmlElement;
int itemCount = container.ChildNodes.Count;
Queue items = new Queue();
for (int i = 0; i < itemCount; ++i)
{
XmlElement currElt = container.ChildNodes[i] as XmlElement;
// If the bookmark does not have an ID, generate one and set it.
if (!currElt.HasAttribute("id") || currElt.GetAttribute("id") == "")
currElt.SetAttribute("id", Bookmarks.GenerateID());
CommandTarget target = new CommandTarget();
target.Label = currElt.GetAttribute("label");
target.AccessKey = currElt.GetAttribute("accesskey");
target.Data = currElt.GetAttribute("id");
target.IsContainer = currElt.HasChildNodes;
target.IconURL = currElt.GetAttribute("icon");
target.IsOpen = currElt.GetAttribute("open") == "true";
items.Enqueue(target);
}
aElements = items.GetEnumerator();
}
public void AddObserver(IDataStoreObserver aObserver)
{
if (mObservers == null)
mObservers = new Queue();
mObservers.Enqueue(aObserver);
}
/// <summary>
/// XXX This is a hack, is really bad and inefficient and should go away when we figure
/// out how to make XmlDocument.GetElementById to work.
/// </summary>
/// <param name="aID"></param>
/// <returns></returns>
public XmlElement GetElementById(String aID)
{
XmlNodeList list = mBookmarksDocument.GetElementsByTagName("item");
int count = list.Count;
for (int i = 0; i < count; ++i)
{
XmlElement elt = list[i] as XmlElement;
if (elt != null)
{
if (elt.GetAttribute("id") == aID)
return elt;
}
}
return null;
}
}
public class Bookmark
@ -113,6 +287,5 @@ namespace Silverstone.Manticore.Bookmarks
FileSystemObject,
PersonalToolbarFolder
}
}

View File

@ -93,66 +93,66 @@ namespace Silverstone.Manticore.Browser
/// </summary>
private void InitializeComponent()
{
this.urlText = new System.Windows.Forms.TextBox();
this.cancelButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.openButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// urlText
//
this.urlText.Location = new System.Drawing.Point(16, 32);
this.urlText.Name = "urlText";
this.urlText.Size = new System.Drawing.Size(272, 20);
this.urlText.TabIndex = 1;
this.urlText.Text = "";
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(216, 64);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(72, 24);
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "Cancel";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(264, 24);
this.label1.TabIndex = 0;
this.label1.Text = "Enter a URL:";
//
// openButton
//
this.openButton.Location = new System.Drawing.Point(136, 64);
this.openButton.Name = "openButton";
this.openButton.Size = new System.Drawing.Size(72, 24);
this.openButton.TabIndex = 2;
this.openButton.Text = "Open";
//
// OpenDialog
//
this.AcceptButton = this.openButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(298, 98);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.cancelButton,
this.openButton,
this.urlText,
this.label1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "OpenDialog";
this.ShowInTaskbar = false;
this.Text = "Open Location";
this.ResumeLayout(false);
this.urlText = new System.Windows.Forms.TextBox();
this.cancelButton = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.openButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// urlText
//
this.urlText.Location = new System.Drawing.Point(16, 32);
this.urlText.Name = "urlText";
this.urlText.Size = new System.Drawing.Size(272, 20);
this.urlText.TabIndex = 1;
this.urlText.Text = "";
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(216, 64);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(72, 24);
this.cancelButton.TabIndex = 2;
this.cancelButton.Text = "Cancel";
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(264, 24);
this.label1.TabIndex = 0;
this.label1.Text = "Enter a URL:";
//
// openButton
//
this.openButton.Location = new System.Drawing.Point(136, 64);
this.openButton.Name = "openButton";
this.openButton.Size = new System.Drawing.Size(72, 24);
this.openButton.TabIndex = 2;
this.openButton.Text = "Open";
//
// OpenDialog
//
this.AcceptButton = this.openButton;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(302, 98);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.cancelButton,
this.openButton,
this.urlText,
this.label1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "OpenDialog";
this.ShowInTaskbar = false;
this.Text = "Open Location";
this.ResumeLayout(false);
}
}
#endregion
}
}

View File

@ -79,7 +79,7 @@ namespace Silverstone.Manticore.Browser
mPanels = new Hashtable();
BrowserWindow window = mOpener as BrowserWindow;
mPrefs = window.mApplication.Prefs;
mPrefs = ServiceManager.Preferences;
//
// Initialize all the preference panels.

View File

@ -1,114 +1,110 @@
<?xml version="1.0"?>
<menubar id="mainMenu"
xmlns="http://www.silverstone.net.nz/2001/manticore/uidl">
<?xml version="1.0" ?>
<menubar id="mainMenu" xmlns="http://www.silverstone.net.nz/2001/manticore/uidl">
<menu label="File" accesskey="f">
<menu label="New Window" accesskey="n" command="file-new-window"/>
<menu label="Open..." accesskey="o" command="file-open"/>
<menuseparator/>
<menu label="Close" accesskey="c" command="file-close"/>
<menu label="Save As..." accesskey="a" command="file-save-as"/>
<menu label="New Window" accesskey="n" command="file-new-window" />
<menu label="Open..." accesskey="o" command="file-open" />
<menuseparator />
<menu label="Close" accesskey="c" command="file-close" />
<menu label="Save As..." accesskey="a" command="file-save-as" />
<menu label="Save" accesskey="s">
<menu label="Images..." accesskey="i" command="file-save-images"/>
<menu label="Form..." accesskey="f" command="file-save-form"/>
<menu label="Images..." accesskey="i" command="file-save-images" />
<menu label="Form..." accesskey="f" command="file-save-form" />
</menu>
<menuseparator/>
<menu label="Send Page..." accesskey="g" command="file-send-page"/>
<menu label="Send Link..." accesskey="l" command="file-send-link"/>
<menuseparator/>
<menu label="Page Setup" acccesskey="u" command="file-page-setup"/>
<menu label="Print..." accesskey="p" command="file-print"/>
<menu label="Print Preview" accesskey="v" command="file-print-preview"/>
<menuseparator/>
<menu label="Properties" accesskey="r" command="file-properties"/>
<menuseparator/>
<menu label="Exit" accesskey="x" command="file-exit"/>
<menuseparator />
<menu label="Send Page..." accesskey="g" command="file-send-page" />
<menu label="Send Link..." accesskey="l" command="file-send-link" />
<menuseparator />
<menu label="Page Setup" acccesskey="u" command="file-page-setup" />
<menu label="Print..." accesskey="p" command="file-print" />
<menu label="Print Preview" accesskey="v" command="file-print-preview" />
<menuseparator />
<menu label="Properties" accesskey="r" command="file-properties" />
<menuseparator />
<menu label="Exit" accesskey="x" command="file-exit" />
</menu>
<menu label="Edit" accesskey="e">
<menu label="Undo" accesskey="u" command="edit-undo"/>
<menu label="Redo" accesskey="r" command="edit-redo"/>
<menuseparator/>
<menu label="Cut" accesskey="t" command="edit-cut"/>
<menu label="Copy" accesskey="c" command="edit-copy"/>
<menu label="Paste" accesskey="p" command="edit-paste"/>
<menu label="Delete" accesskey="d" command="edit-delete"/>
<menuseparator/>
<menu label="Select All" accesskey="a" command="edit-select-all"/>
<menuseparator/>
<menu label="Find..." accesskey="f" command="edit-find"/>
<menu label="Find Again" accesskey="g" command="edit-find-again"/>
<menu label="Undo" accesskey="u" command="edit-undo" />
<menu label="Redo" accesskey="r" command="edit-redo" />
<menuseparator />
<menu label="Cut" accesskey="t" command="edit-cut" />
<menu label="Copy" accesskey="c" command="edit-copy" />
<menu label="Paste" accesskey="p" command="edit-paste" />
<menu label="Delete" accesskey="d" command="edit-delete" />
<menuseparator />
<menu label="Select All" accesskey="a" command="edit-select-all" />
<menuseparator />
<menu label="Find..." accesskey="f" command="edit-find" />
<menu label="Find Again" accesskey="g" command="edit-find-again" />
</menu>
<menu label="View" accesskey="view">
<menu label="Toolbars" accesskey="t">
<menu label="Navigation Toolbar"/>
<menu label="Location Toolbar"/>
<menu label="Personal Toolbar"/>
<menu label="Navigation Toolbar" />
<menu label="Location Toolbar" />
<menu label="Personal Toolbar" />
</menu>
<menu label="Status Bar" accesskey="b" command="view-statusbar"/>
<menu label="Status Bar" accesskey="b" command="view-statusbar" />
<menu label="SideBar" accesskey="i">
<menu label="Bookmarks"/>
<menu label="History"/>
<menu label="Bookmarks" />
<menu label="History" />
</menu>
<menuseparator/>
<menuseparator />
<menu label="Go" accesskey="g">
<menu label="Back" accesskey="b" command="view-go=back"/>
<menu label="Back to"/>
<menu label="Forward" accesskey="f" command="view-go-forward"/>
<menu label="Forward to"/>
<menuseparator/>
<menu label="Home" accesskey="h" command="view-go-home"/>
<menuseparator/>
<menu label="History" accesskey="i" command="view-go-history"/>
<menu label="Back" accesskey="b" command="view-go=back" />
<menu label="Back to" />
<menu label="Forward" accesskey="f" command="view-go-forward" />
<menu label="Forward to" />
<menuseparator />
<menu label="Home" accesskey="h" command="view-go-home" />
<menuseparator />
<menu label="History" accesskey="i" command="view-go-history" />
</menu>
<menu label="Reload" accesskey="r" command="view-reload"/>
<menu label="Stop" accesskey="s" command="view-stop"/>
<menuseparator/>
<menu label="Reload" accesskey="r" command="view-reload" />
<menu label="Stop" accesskey="s" command="view-stop" />
<menuseparator />
<menu label="Text Size" accesskey="t">
<menu label="50%" accesskey="5" command="view-text-50%"/>
<menu label="75%" accesskey="7" command="view-text-75%"/>
<menu label="90%" accesskey="9" command="view-text-90%"/>
<menu label="100% (Original size)" accesskey="o" command="view-text-100%"/>
<menu label="125%" accesskey="1" command="view-text-125%"/>
<menu label="175%" accesskey="5" command="view-text-175%"/>
<menu label="200%" accesskey="2" command="view-text-200%"/>
<menuseparator/>
<menu label="Larger" accesskey="l" command="view-text-larger"/>
<menu label="Smaller" accesskey="s" command="view-text-smaller"/>
<menuseparator/>
<menu label="Other (#%)" accesskey="t" command="view-text-other"/>
<menu label="50%" accesskey="5" command="view-text-50%" />
<menu label="75%" accesskey="7" command="view-text-75%" />
<menu label="90%" accesskey="9" command="view-text-90%" />
<menu label="100% (Original size)" accesskey="o" command="view-text-100%" />
<menu label="125%" accesskey="1" command="view-text-125%" />
<menu label="175%" accesskey="5" command="view-text-175%" />
<menu label="200%" accesskey="2" command="view-text-200%" />
<menuseparator />
<menu label="Larger" accesskey="l" command="view-text-larger" />
<menu label="Smaller" accesskey="s" command="view-text-smaller" />
<menuseparator />
<menu label="Other (#%)" accesskey="t" command="view-text-other" />
</menu>
<menu label="Use Stylesheet" accesskey="y"/>
<menuseparator/>
<menu label="Encoding" accesskey="e"/>
<menuseparator/>
<menu label="Use Stylesheet" accesskey="y" />
<menuseparator />
<menu label="Encoding" accesskey="e" />
<menuseparator />
<menu label="Select Layout Engine">
<menu label="Mozilla" command="view-layout-gecko"/>
<menu label="Internet Explorer" command="view-layout-ie"/>
</menu>
<menu label="Mozilla" command="view-layout-gecko" />
<menu label="Internet Explorer" command="view-layout-ie" />
</menu>
</menu>
<menu label="Bookmarks" accesskey="b">
<menu label="Add Bookmark" accesskey="a" command="bookmarks-add"/>
<menu label="File Bookmark..." accesskey="i" command="bookmarks-file"/>
<menuseparator/>
<menu label="Find in Bookmarks..." accesskey="f" command="bookmarks-find"/>
<menu label="Manage Bookmarks" accesskey="m" command="bookmarks-manage"/>
<menu label="Add Bookmark" accesskey="a" command="bookmarks-add" />
<menu label="File Bookmark..." accesskey="i" command="bookmarks-file" />
<menuseparator />
<menu label="Find in Bookmarks..." accesskey="f" command="bookmarks-find" />
<menu label="Manage Bookmarks" accesskey="m" command="bookmarks-manage" />
<menuseparator />
<menubuilder id="Bookmarks" datastore="Bookmarks" />
</menu>
<menu label="Tools" accesskey="t">
<menu label="Mail" accesskey="m" command="tools-mail"/>
<menuseparator/>
<menu label="Search the Web" accesskey="s" command="tools-search"/>
<menuseparator/>
<menu label="History" accesskey="h" command="tools-history"/>
<menu label="JavaScript Console" accesskey="j" command="tools-jsconsole"/>
<menu label="Java Console" accesskey="c" command="tools-jconsole"/>
<menuseparator/>
<menu label="Options" accesskey="o" command="tools-options"/>
<menu label="Mail" accesskey="m" command="tools-mail" />
<menuseparator />
<menu label="Search the Web" accesskey="s" command="tools-search" />
<menuseparator />
<menu label="History" accesskey="h" command="tools-history" />
<menu label="JavaScript Console" accesskey="j" command="tools-jsconsole" />
<menu label="Java Console" accesskey="c" command="tools-jconsole" />
<menuseparator />
<menu label="Options" accesskey="o" command="tools-options" />
</menu>
<menu label="Help" accesskey="h">
<menu label="About Manticore..." accesskey="a" command="help-about"/>
</menu>
<menu label="About Manticore..." accesskey="a" command="help-about" />
</menu>
</menubar>

View File

@ -39,15 +39,17 @@ namespace Silverstone.Manticore.Browser
using System.Drawing;
using System.Windows.Forms;
using Silverstone.Manticore.Core;
using Silverstone.Manticore.App;
using Silverstone.Manticore.Toolkit;
using Silverstone.Manticore.Layout;
using Silverstone.Manticore.Bookmarks;
public class BrowserWindow : ManticoreWindow
public class BrowserWindow : ManticoreWindow, IController
{
private System.ComponentModel.Container components;
private BrowserMenuBuilder mMenuBuilder;
private MenuBuilder mMenuBuilder;
private BrowserToolbarBuilder mToolbarBuilder;
private WebBrowser mWebBrowser;
@ -55,10 +57,15 @@ namespace Silverstone.Manticore.Browser
private StatusBar mStatusBar;
private StatusBarPanel mProgressMeter;
private StatusBarPanel mStatusPanel;
protected internal ManticoreApp mApplication;
private ManticoreApp mApplication;
private String mSessionURL = "";
/// <summary>
/// Webpage Title
/// </summary>
private String mTitle = "";
public BrowserWindow(ManticoreApp aApp)
{
Init(aApp);
@ -79,6 +86,7 @@ namespace Silverstone.Manticore.Browser
InitializeComponent();
this.Closed += new EventHandler(OnFormClosed);
this.GotFocus += new EventHandler(OnSetFocus);
}
public void OnFormClosed(Object sender, EventArgs e)
@ -86,6 +94,11 @@ namespace Silverstone.Manticore.Browser
mApplication.WindowClosed(this);
}
public void OnSetFocus(Object sender, EventArgs e)
{
ManticoreApp.MostRecentBrowserWindow = this;
}
public override void Dispose()
{
base.Dispose();
@ -102,8 +115,9 @@ namespace Silverstone.Manticore.Browser
this.Text = "Manticore"; // XXX localize
mMenuBuilder = new BrowserMenuBuilder("browser\\browser-menu.xml", this);
mMenuBuilder = new MenuBuilder("browser\\browser-menu.xml", this);
mMenuBuilder.Build();
mMenuBuilder.OnCommand += new EventHandler(OnMenuCommand);
// Show the resize handle
this.SizeGripStyle = SizeGripStyle.Auto;
@ -146,9 +160,14 @@ namespace Silverstone.Manticore.Browser
}
}
public void LoadURL(String aURL)
{
mWebBrowser.LoadURL(aURL, false);
}
private void LoadStartPage(object sender, EventArgs e)
{
int startMode = mApplication.Prefs.GetIntPref("browser.homepage.mode");
int startMode = ServiceManager.Preferences.GetIntPref("browser.homepage.mode");
switch (startMode) {
case 0:
// Don't initialize jack.
@ -164,6 +183,7 @@ namespace Silverstone.Manticore.Browser
}
}
///////////////////////////////////////////////////////////////////////////
// Menu Command Handlers
public void OpenNewBrowser()
@ -202,6 +222,7 @@ namespace Silverstone.Manticore.Browser
public void OnTitleChange(String aTitle)
{
mTitle = aTitle;
this.Text = (aTitle == "about:blank") ? "Manticore" : aTitle + " - Manticore";
}
@ -216,10 +237,30 @@ namespace Silverstone.Manticore.Browser
// return window.currentLayoutEngine;
return new Object();
}
public void DoCommand(String s)
/// <summary>
/// Fired when a |MenuItem| built by the |MenuBuilder| is selected.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void OnMenuCommand(Object sender, EventArgs e)
{
switch (s)
ManticoreMenuItem item = sender as ManticoreMenuItem;
DoCommand(item.Command, item.Data);
}
///////////////////////////////////////////////////////////////////////////
// IController Implementation
public void DoCommand(String aCommand)
{
DoCommand(aCommand, null);
}
public void DoCommand(String aCommand, Object aData)
{
Console.WriteLine(aCommand);
switch (aCommand)
{
case "file-new-window":
OpenNewBrowser();
@ -251,6 +292,25 @@ namespace Silverstone.Manticore.Browser
case "view-layout-ie":
mWebBrowser.SwitchLayoutEngine("trident");
break;
case "bookmarks-manage":
BookmarksWindow bm = new BookmarksWindow();
bm.Show();
break;
case "bookmarks-item":
String url = ServiceManager.Bookmarks.GetBookmarkAttribute(aData as String, "url");
LoadURL(url);
break;
case "bookmarks-add":
// XXX need to allow user to customize this.
Bookmarks bmks = ServiceManager.Bookmarks;
String bookmarkID = bmks.CreateBookmark(mTitle, "Bookmarks", -1);
bmks.SetBookmarkAttribute(bookmarkID, "url", URL);
break;
case "bookmarks-file":
// XXX work on this
FileBookmark fpWindow = new FileBookmark(URL, mTitle);
fpWindow.ShowDialog();
break;
case "help-about":
AboutDialog aboutDialog = new AboutDialog(this);
aboutDialog.ShowDialog();
@ -261,18 +321,17 @@ namespace Silverstone.Manticore.Browser
break;
}
}
}
public class BrowserMenuBuilder : MenuBuilder
{
public BrowserMenuBuilder(String aFile, Form aForm) : base(aFile, aForm)
public bool SupportsCommand(String aCommand)
{
// XXX implement me
return true;
}
public override void OnCommand(Object sender, EventArgs e)
public bool IsCommandEnabled(String aCommand)
{
CommandMenuItem item = sender as CommandMenuItem;
(mForm as BrowserWindow).DoCommand(item.Command);
// XXX implement me
return true;
}
}

View File

@ -0,0 +1,275 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Core
{
using System;
using System.Collections;
using Silverstone.Manticore.Bookmarks;
public interface IDataStore
{
void GetElements(String aContainerID, out IEnumerator aElements);
void AddObserver(IDataStoreObserver aObserver);
}
/// <summary>
/// Provides a means for a client to observe changes to a data store.
/// </summary>
public interface IDataStoreObserver
{
void OnNodeChanging(Object aOldNode, Object aNewNode);
void OnNodeChanged(Object aOldNode, Object aNewNode);
void OnNodeAdding(Object aNewNode, Object aParentNode, int aIndex);
void OnNodeAdded(Object aNewNode, Object aParentNode, int aIndex);
void OnNodeRemoving(Object aNodeRemoving);
void OnNodeRemoved(Object aNodeRemoved);
}
public class CommandTarget
{
public CommandTarget()
{
}
public CommandTarget(String aLabel, String aAccessKey, Object aData, bool aIsContainer)
{
Label = aLabel;
AccessKey = aAccessKey;
Data = aData;
IsContainer = aIsContainer;
}
private String mLabel = "";
private String mAccesskey = "";
private String mIconURL = "";
private bool mIsContainer = false;
private bool mIsOpen = false;
private Object mData = new Object();
public String Label
{
get
{
return mLabel;
}
set
{
if (mLabel != value)
mLabel = value;
}
}
public String AccessKey
{
get
{
return mAccesskey;
}
set
{
if (mAccesskey != value)
mAccesskey = value;
}
}
public bool IsContainer
{
get
{
return mIsContainer;
}
set
{
mIsContainer = value;
}
}
public bool IsOpen
{
get
{
return mIsOpen;
}
set
{
mIsOpen = value;
}
}
public String IconURL
{
get
{
return mIconURL;
}
set
{
mIconURL = value;
}
}
public Object Data
{
get
{
return mData;
}
set
{
if (!mData.Equals(value))
mData = value;
}
}
}
public class DataStoreRegistry
{
public static IDataStore GetDataStore(String aDataStore)
{
switch (aDataStore)
{
case "Bookmarks":
// Need to replace this with a call to svc mgr.
return ServiceManager.Bookmarks as IDataStore;
}
return null;
}
}
public class SampleDataStore : IDataStore
{
private String mPrefix = "Goats";
private Hashtable mTargets = null;
private Hashtable mObservers = null;
public SampleDataStore()
{
mTargets = new Hashtable();
SetStuff();
}
public void AddObserver(IDataStoreObserver aObserver)
{
if (mObservers == null)
mObservers = new Hashtable();
mObservers.Add(aObserver.GetHashCode(), aObserver);
}
public void DoCommand(String aCommand, String aResourceID)
{
}
private void SetStuff()
{
CommandTarget tgt1 = new CommandTarget(mPrefix + "1", "1", "foopy1" as Object, false);
mTargets.Add(tgt1.GetHashCode(), tgt1);
CommandTarget tgt2 = new CommandTarget(mPrefix + "2", "2", "foopy2" as Object, false);
mTargets.Add(tgt2.GetHashCode(), tgt2);
CommandTarget tgt3 = new CommandTarget(mPrefix + "3", "3", "foopy3" as Object, false);
mTargets.Add(tgt3.GetHashCode(), tgt3);
CommandTarget tgt4 = new CommandTarget(mPrefix + "4", "4", "foopy4" as Object, false);
mTargets.Add(tgt4.GetHashCode(), tgt4);
}
public void ChangePrefix(String aPrefix)
{
/*
CommandTarget[] oldTargets = new CommandTarget[4];
mTargets.Values.CopyTo(oldTargets, 0);
mPrefix = aPrefix;
SetStuff();
IEnumerator targets = mTargets.Values.GetEnumerator();
int i = 0;
while (targets.MoveNext()) {
IEnumerator observers = mObservers.Values.GetEnumerator();
while (observers.MoveNext()) {
IDataStoreObserver idso = observers.Current as IDataStoreObserver;
idso.OnNodeChanged(oldTargets[i++], targets.Current as CommandTarget);
}
}
*/
}
public void RemoveOdd()
{
IEnumerator targets = mTargets.Values.GetEnumerator();
while (targets.MoveNext())
{
IEnumerator observers = mObservers.Values.GetEnumerator();
while (observers.MoveNext())
{
IDataStoreObserver idso = observers.Current as IDataStoreObserver;
CommandTarget current = targets.Current as CommandTarget;
if (Int32.Parse(current.AccessKey) % 2 != 0)
{
mTargets.Remove(current.Data.GetHashCode());
idso.OnNodeRemoved(targets.Current as CommandTarget);
}
}
}
}
public void AddItems()
{
CommandTarget tgt5 = new CommandTarget(mPrefix + "5", "5", "foopy5" as Object, false);
mTargets.Add(tgt5.GetHashCode(), tgt5);
CommandTarget tgt6 = new CommandTarget(mPrefix + "6", "6", "foopy6" as Object, false);
mTargets.Add(tgt6.GetHashCode(), tgt6);
}
public void GetElements(String aContainerID, out IEnumerator aElements)
{
switch (aContainerID)
{
case "root":
aElements = mTargets.Values.GetEnumerator();
break;
case "goats":
aElements = mTargets.Values.GetEnumerator();
break;
default:
aElements = mTargets.Values.GetEnumerator();
break;
}
}
}
}

View File

@ -37,6 +37,7 @@ namespace Silverstone.Manticore.Core
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
/// <summary>
/// Locate special folders
@ -100,15 +101,27 @@ namespace Silverstone.Manticore.Core
public static String GetManticorePath(String aPath)
{
String path = "";
switch (aPath) {
String appData = "";
switch (aPath)
{
case "AppData":
path = FileLocator.GetFolderPath(FileLocator.SpecialFolders.ssfAPPDATA);
path += @"\Manticore\";
break;
case "UserPrefs":
String appData = FileLocator.GetManticorePath("AppData");
appData = FileLocator.GetManticorePath("AppData");
path += appData + @"user-prefs.xml";
break;
case "LocalBookmarks":
appData = FileLocator.GetManticorePath("AppData");
if (appData != "")
path += appData + @"bookmarks.xml";
break;
case "Application":
path = Application.ExecutablePath;
int lastSlash = path.LastIndexOf(@"\");
path = path.Substring(0, lastSlash + 1);
break;
}
return path;
}

View File

@ -0,0 +1,74 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Core
{
/// <summary>
/// Access point to application-global services.
/// </summary>
public class ServiceManager
{
private static Silverstone.Manticore.Core.Preferences mPreferences = null;
public static Silverstone.Manticore.Core.Preferences Preferences
{
get
{
// Initialize default and user preferences
if (mPreferences == null)
{
mPreferences = new Preferences();
mPreferences.InitializeDefaults();
mPreferences.LoadUserPreferences();
}
return mPreferences;
}
}
private static Silverstone.Manticore.Bookmarks.Bookmarks mBookmarks = null;
public static Silverstone.Manticore.Bookmarks.Bookmarks Bookmarks
{
get
{
// Start the Bookmarks Service if it has not already been initialized
if (mBookmarks == null)
{
mBookmarks = new Silverstone.Manticore.Bookmarks.Bookmarks();
mBookmarks.LoadBookmarks();
}
return mBookmarks;
}
}
}
}

View File

@ -289,14 +289,16 @@ namespace Silverstone.Manticore.Core
public Object Current
{
get {
get
{
return Preferences.ResolvePref(mCurrent) as Object;
}
}
public bool MoveNext()
{
if (mCurrent != null) {
if (mCurrent != null)
{
if (mCurrent.NextSibling != null)
mCurrent = mCurrent.NextSibling as XmlElement;
else

View File

@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<!DOCTYPE item [
<!ELEMENT item ANY >
<!ATTLIST item label CDATA #REQUIRED >
<!ATTLIST item url CDATA #IMPLIED >
<!ATTLIST item container CDATA #IMPLIED >
<!ATTLIST item open CDATA #IMPLIED >
<!ATTLIST item id ID #REQUIRED >
]>
<item xmlns="http://www.silverstone.net.nz/2001/manticore/uidl" id="BookmarksRoot">
<item container="true" open="true" label="Bookmarks" id="Bookmarks" icon="resources/bookmarks-folder-closed.png">
<item label="mantic0re.com" url="http://www.mantic0re.com/" />
</item>
</item>

View File

@ -49,6 +49,7 @@ namespace Silverstone.Manticore.Layout
using AxMOZILLACONTROLLib;
using MOZILLACONTROLLib;
using Silverstone.Manticore.Core;
using Silverstone.Manticore.Browser;
public class WebBrowser : UserControl
@ -110,8 +111,9 @@ namespace Silverstone.Manticore.Layout
public void RealizeLayoutEngine()
{
if (gecko == null && trident == null) {
String layoutEngine = mBrowserWindow.mApplication.Prefs.GetStringPref("browser.layoutengine");
if (gecko == null && trident == null)
{
String layoutEngine = ServiceManager.Preferences.GetStringPref("browser.layoutengine");
if (layoutEngine == "")
layoutEngine = "gecko";
SwitchLayoutEngine(layoutEngine);
@ -162,7 +164,7 @@ namespace Silverstone.Manticore.Layout
// Add appropriate content area listeners
AddListeners();
mBrowserWindow.mApplication.Prefs.SetStringPref("browser.layoutengine", id);
ServiceManager.Preferences.SetStringPref("browser.layoutengine", id);
LoadURL(url, false);
}
@ -252,7 +254,7 @@ namespace Silverstone.Manticore.Layout
public void GoHome()
{
// XXX - need to implement "Home" preference
String homepageURL = mBrowserWindow.mApplication.Prefs.GetStringPref("browser.homepage");
String homepageURL = ServiceManager.Preferences.GetStringPref("browser.homepage");
LoadURL(homepageURL, false);
}
@ -357,7 +359,25 @@ namespace Silverstone.Manticore.Layout
if (webBrowser != null)
e.ppDisp = webBrowser;
}
private bool mFileDownloadGecko = false;
private bool mFileDownloadTrident = false;
private void AddFileDownloadListener()
{
if (gecko != null && !mFileDownloadGecko)
{
mFileDownloadGecko = true;
}
else if (trident != null && !mFileDownloadTrident)
{
trident.FileDownload += new AxSHDocVw.DWebBrowserEvents2_FileDownloadEventHandler(OnFileDownloadTrident);
mFileDownloadTrident = true;
}
}
public void OnFileDownloadTrident(Object sender, AxSHDocVw.DWebBrowserEvents2_FileDownloadEvent e)
{
e.cancel = false;
}
}
}

View File

@ -41,19 +41,24 @@ CLEANUP = *.exe *.pdb
DEBUG=FALSE
_CS_WINFORMS_IMPORTS=/R:System.DLL /R:System.Windows.Forms.DLL \
/R:System.Drawing.DLL
_CS_BASE_IMPORTS=/R:System.DLL
_CS_WINFORMS_IMPORTS=/R:System.Windows.Forms.DLL /R:System.Drawing.DLL
_CS_XML_IMPORTS=/R:System.Data.DLL /R:System.XML.DLL
_CS_LAYOUT_IMPORTS=/R:AxSHDocVw.DLL /R:MSHTML.DLL /R:AxMOZILLACONTROLLib.DLL /R:MOZILLACONTROLLib.dll
_CS_SHELL_IMPORTS=
_IMPORTS=$(_CS_WINFORMS_IMPORTS) $(_CS_XMLIMPORTS) $(_CS_LAYOUT_IMPORTS) $(_CS_SHELL_IMPORTS)
_IMPORTS=$(_CS_BASE_IMPORTS) $(_CS_WINFORMS_IMPORTS) $(_CS_XMLIMPORTS) $(_CS_LAYOUT_IMPORTS)
_DEBUG_FLAGS=/optimize+
!if defined(MOZ_DEBUG)
_DEBUG_FLAGS=/debug+
!endif
!if defined(WINDIR)
_WINDIR=$(WINDIR)
!else
_WINDIR=C:\WINNT
!endif
_OUT_FILE=manticore.exe
_COMPILE_CMD=csc /nologo /t:exe /out:$(_OUT_FILE) $(_DEBUG_FLAGS) $(_IMPORTS)
@ -69,12 +74,18 @@ FILES = app.cs \
layout\layoutabstraction.cs \
toolkit\toolkit.menus.cs \
toolkit\toolkit.toolbars.cs \
toolkit\ContentBuilder.cs \
toolkit\MenuBuilder.cs \
toolkit\TreeBuilder.cs \
toolkit\ManticoreDialog.cs \
toolkit\ManticoreWindow.cs \
toolkit\ProgressMeter.cs \
core\DataStore.cs \
core\preferences.cs \
core\FileLocator.cs \
bookmarks\bookmarks.cs
bookmarks\bookmarks.cs \
bookmarks\BookmarksWindow.cs \
$(NULL)
SUBDIR = WIN32_O.OBJ
!if defined(MOZ_DEBUG)
@ -86,11 +97,9 @@ app:
# this stuff sucks. need to make paths less hard coded
bindings:
aximp c:\WINNT\system32\shdocvw.dll
tlbimp mshtml.tlb
tlbimp $(MOZ_SRC)\system32\shell32.dll
echo $(_WINDIR)\system32\shdocvw.dll
aximp $(_WINDIR)\system32\shdocvw.dll
aximp $(MOZ_SRC)\mozilla\dist\$(SUBDIR)\bin\mozctl.dll
tlbimp $(MOZ_SRC)\mozilla\dist\$(SUBDIR)\bin\mozctl.dll
# XXX fix me
clean:

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -0,0 +1,61 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com>
*
*/
namespace Silverstone.Manticore.Toolkit
{
using System;
public interface IController
{
void DoCommand(String aCommand);
void DoCommand(String aCommand, Object aData);
bool IsCommandEnabled(String aCommand);
bool SupportsCommand(String aCommand);
}
/// <summary>
/// Summary description for CommandUpdater.
/// </summary>
public class CommandUpdater
{
public CommandUpdater()
{
//
// TODO: Add constructor logic here
//
}
}
}

View File

@ -0,0 +1,81 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Toolkit
{
using System;
using System.Windows.Forms;
using System.Collections;
using Silverstone.Manticore.Core;
/// <summary>
/// Summary description for ContentBuilder.
/// </summary>
public class ContentBuilder
{
protected IDataStore mDataStore = null;
protected String mRoot = null;
public ContentBuilder()
{
}
public virtual void Build()
{
}
public IDataStore DataStore
{
get {
return mDataStore;
}
set {
mDataStore = value;
}
}
public String Root
{
get {
return mRoot;
}
set {
Console.WriteLine(value);
mRoot = value;
}
}
}
}

View File

@ -0,0 +1,360 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Toolkit
{
using System;
using System.Windows.Forms;
using System.Collections;
using Silverstone.Manticore.Core;
public abstract class DynamicMenuBuilder : ContentBuilder, IDataStoreObserver
{
/// <summary>
/// The |MenuItem| that is the parent of the content builder
/// </summary>
protected MenuItem mParent = null;
protected Menu.MenuItemCollection mParentItems = null;
/// <summary>
/// |mBefore| and |mAfter| define the static boundaries within which
/// the DynamicMenuBuilder operates. Used if the builder builds items
/// which are siblings to static |MenuItem|s.
/// </summary>
protected MenuItem mBefore = null;
protected MenuItem mAfter = null;
/// <summary>
/// All of this builder's |MenuItem|s, keyed by DataStore id.
/// </summary>
protected Hashtable mMenus = null;
/// <summary>
/// This is the default point of insertion of new menus. Initially, this
/// is the index of |mBefore|, or 0 if |mBefore| is null. As items are added,
/// it is incremented.
/// </summary>
protected int mInsertionPoint = 0;
public DynamicMenuBuilder(MainMenu aMainMenu, MenuItem aParent)
{
if (aParent != null)
{
mParent = aParent;
mParentItems = aParent.MenuItems;
}
else
mParentItems = aMainMenu.MenuItems;
InitializeComponent();
}
public DynamicMenuBuilder(MainMenu aMainMenu, MenuItem aParent, MenuItem aBefore, MenuItem aAfter)
{
if (aParent != null)
{
mParent = aParent;
mParentItems = aParent.MenuItems;
}
else
mParentItems = aMainMenu.MenuItems;
// XXX we do jack shit to handle this at the moment. TBD.
mBefore = aBefore;
mAfter = aAfter;
ResetInsertionPoint();
InitializeComponent();
}
private void ResetInsertionPoint()
{
if (mBefore != null)
{
// The insertion point is the position immediately after |mBefore|
mInsertionPoint = mParentItems.IndexOf(mBefore) + 1;
}
else
mInsertionPoint = 0;
}
protected virtual void InitializeComponent()
{
mMenus = new Hashtable();
// XXX for now, just be stupid and generate everything when the root
// menu is opened.
mParent.Popup += new EventHandler(OnParentPopup);
}
protected void OnParentPopup(Object sender, EventArgs e)
{
// XXX make this smarter.
Build();
}
///////////////////////////////////////////////////////////////////////////
// ContentBuilder Implementation
public void OnNodeChanging(Object aOldNode, Object aNewNode)
{
// Not Implemented.
}
public void OnNodeChanged(Object aOldNode, Object aNewNode)
{
// Enumerate each of the properties that affect FE presentation, test
// for difference, and update the FE if necessary.
CommandTarget oldTarget = aOldNode as CommandTarget;
CommandTarget newTarget = aNewNode as CommandTarget;
if (oldTarget == null && newTarget == null)
return;
// Check for Label/AccessKey change.
if (newTarget.Label != oldTarget.Label || newTarget.AccessKey != oldTarget.AccessKey)
{
int itemKey = newTarget.Data.GetHashCode();
if (mMenus.ContainsKey(itemKey))
{
ManticoreMenuItem item = mMenus[itemKey] as ManticoreMenuItem;
// Re-generate AccessKey and update display Text
item.Text = ManticoreMenuItem.GenerateAccessKeyString(newTarget.Label, newTarget.AccessKey);;
}
}
}
public void OnNodeAdding(Object aNewNode, Object aParentNode, int aIndex)
{
// Not Implemented.
}
public void OnNodeAdded(Object aChildNode, Object aParentNode, int aIndex)
{
// A new Element has been added somewhere. We must find the
// parent menu and append it. To interoperate with the Content Builder,
// the DataStore must provide |CommandTarget|s to this method.
CommandTarget childTarget = aChildNode as CommandTarget;
CommandTarget parentTarget = aParentNode as CommandTarget;
if (childTarget == null && parentTarget == null)
return;
int childKey = childTarget.Data.GetHashCode();
if (!mMenus.ContainsKey(childKey))
{
int parentKey = parentTarget.Data.GetHashCode();
ManticoreMenuItem parentMenu;
if (mMenus.ContainsKey(parentKey))
parentMenu = mMenus[parentKey] as ManticoreMenuItem;
else
parentMenu = mParent as ManticoreMenuItem;
if (parentMenu != null)
{
String label = childTarget.Label;
if (childTarget.AccessKey != "")
label = ManticoreMenuItem.GenerateAccessKeyString(childTarget.Label,
childTarget.AccessKey);
ManticoreMenuItem childMenu = new ManticoreMenuItem(label,
new EventHandler(OnCommandInternal),
"bookmarks-item", childTarget.Data);
if (parentMenu != null)
{
int pos = aIndex == -1 ? parentMenu.MenuItems.Count : aIndex;
parentMenu.MenuItems.Add(pos, childMenu);
mMenus.Add(childKey, childMenu);
}
}
}
}
public void OnNodeRemoving(Object aNodeRemoving)
{
// Not Implemented.
}
public void OnNodeRemoved(Object aNodeRemoved)
{
CommandTarget childTarget = aNodeRemoved as CommandTarget;
// Remove |MenuItem| representation of |aChildNode|.
int childKey = childTarget.Data.GetHashCode();
if (mMenus.ContainsKey(childKey))
{
ManticoreMenuItem childMenu = mMenus[childKey] as ManticoreMenuItem;
ManticoreMenuItem parentMenu = childMenu.Parent as ManticoreMenuItem;
parentMenu.MenuItems.Remove(childMenu);
mMenus.Remove(childKey);
}
}
/// <summary>
/// Build content. Builds all content if |LazyState| is set to false.
/// </summary>
public override void Build()
{
if (mDataStore == null || mRoot == null)
throw new Exception();
// XXX implement acknowledgement of |LazyState|
Recurse(mRoot, mParentItems);
}
public void Recurse(String aRoot, Menu.MenuItemCollection aParentItems)
{
IEnumerator items;
mDataStore.GetElements(aRoot, out items);
items.Reset();
MenuItem item;
while (items.MoveNext())
{
// |id| is the item's unique identifier within the DataStore.
// The handling code can use this to probe for more information
// about the selected item.
CommandTarget current = items.Current as CommandTarget;
if (current != null)
{
String id = current.Data as String;
int idKey = id.GetHashCode();
if (!mMenus.ContainsKey(idKey))
{
item = new ManticoreMenuItem(current.Label,
new EventHandler(OnCommandInternal),
"bookmarks-item", id);
if (aRoot != Root)
aParentItems.Add(item);
else
aParentItems.Add(mInsertionPoint++, item);
mMenus.Add(id.GetHashCode(), item);
if (current.IsContainer)
Recurse(current.Data as String, item.MenuItems);
}
}
}
ResetInsertionPoint();
}
/// <summary>
/// Clients wishing to observe for |MenuItem| selection will want to listen to
/// this event.
/// </summary>
public event EventHandler OnCommand;
/// <summary>
/// Calls |OnCommand| EventHandler on interested clients indicating a generated
/// |MenuItem| has been selected.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void OnCommandInternal(Object sender, EventArgs e)
{
if (OnCommand != null)
OnCommand(sender, e);
}
///////////////////////////////////////////////////////////////////////////
//
public MenuItem Parent
{
get
{
return mParent;
}
set
{
mParent = value;
}
}
public MenuItem Before
{
get
{
return mBefore;
}
set
{
mBefore = value;
}
}
public MenuItem After
{
get
{
return mAfter;
}
set
{
mAfter = value;
}
}
}
public class BaseMenuBuilder : DynamicMenuBuilder
{
public BaseMenuBuilder(MainMenu aMainMenu,
MenuItem aParent) : base(aMainMenu, aParent)
{
InitializeComponent();
}
public BaseMenuBuilder(MainMenu aMainMenu,
MenuItem aParent,
MenuItem aBefore,
MenuItem aAfter) : base(aMainMenu, aParent, aBefore, aAfter)
{
InitializeComponent();
}
protected override void InitializeComponent()
{
base.InitializeComponent();
mDataStore = new SampleDataStore();
mDataStore.AddObserver(this as IDataStoreObserver);
}
}
}

View File

@ -0,0 +1,355 @@
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Manticore.
*
* The Initial Developer of the Original Code is
* Silverstone Interactive. Portions created by Silverstone Interactive are
* Copyright (C) 2001 Silverstone Interactive.
*
* Alternatively, the contents of this file may be used under the
* terms of the GNU Public License (the "GPL"), in which case the
* provisions of the GPL are applicable instead of those above.
* If you wish to allow use of your version of this file only
* under the terms of the GPL and not to allow others to use your
* version of this file under the MPL, indicate your decision by
* deleting the provisions above and replace them with the notice
* and other provisions required by the GPL. If you do not delete
* the provisions above, a recipient may use your version of this
* file under either the MPL or the GPL.
*
* Contributor(s):
* Ben Goodger <ben@netscape.com> (Original Author)
*
*/
namespace Silverstone.Manticore.Toolkit
{
using System;
using System.Windows.Forms;
using System.Collections;
using Silverstone.Manticore.Core;
public abstract class DynamicTreeBuilder : ContentBuilder, IDataStoreObserver
{
/// <summary>
/// The |TreeNode| that is the parent of the content builder
/// </summary>
protected TreeNode mParent = null;
protected TreeNodeCollection mParentNodes = null;
/// <summary>
/// |mBefore| and |mAfter| define the static boundaries within which
/// the DynamicTreeBuilder operates. Used if the builder builds items
/// which are siblings to static |TreeNode|s.
/// </summary>
protected TreeNode mBefore = null;
protected TreeNode mAfter = null;
/// <summary>
/// The containing |TreeView|
/// </summary>
protected ManticoreTreeView mTreeView = null;
/// <summary>
/// All of this builder's |TreeNode|s, keyed by DataStore id.
/// </summary>
protected Hashtable mNodes = null;
/// <summary>
/// This is the default point of insertion of new nodes. Initially, this
/// is the index of |mBefore|, or 0 if |mBefore| is null. As items are added,
/// it is incremented.
/// </summary>
protected int mInsertionPoint = 0;
public DynamicTreeBuilder(ManticoreTreeView aTreeView, TreeNode aParent)
{
if (aTreeView == null)
throw new Exception();
if (aParent != null)
{
mParent = aParent;
mParentNodes = aParent.Nodes;
}
else
mParentNodes = aTreeView.Nodes;
mTreeView = aTreeView;
InitializeComponent();
}
public DynamicTreeBuilder(ManticoreTreeView aTreeView, TreeNode aParent, TreeNode aBefore, TreeNode aAfter)
{
mParent = aParent;
mTreeView = aTreeView;
// XXX we do jack shit to handle this at the moment. TBD.
mBefore = aBefore;
mAfter = aAfter;
ResetInsertionPoint();
InitializeComponent();
}
private void ResetInsertionPoint()
{
if (mBefore != null)
{
// The insertion point is the position immediately after |mBefore|
mInsertionPoint = mParentNodes.IndexOf(mBefore) + 1;
}
else
mInsertionPoint = 0;
}
protected virtual void InitializeComponent()
{
mNodes = new Hashtable();
// XXX for now, just be stupid and generate everything when the root
// menu is opened.
mTreeView.BeforeExpand += new TreeViewCancelEventHandler(OnBeforeExpand);
}
/// <summary>
/// Overridden by clients to provide command handling for built menus.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void OnBeforeExpand(Object sender, TreeViewCancelEventArgs e)
{
// XXX make this smarter.
Build();
}
///////////////////////////////////////////////////////////////////////////
// ContentBuilder Implementation
public void OnNodeChanging(Object aOldNode, Object aNewNode)
{
// Not Implemented.
}
public void OnNodeChanged(Object aOldNode, Object aNewNode)
{
// Enumerate each of the properties that affect FE presentation, test
// for difference, and update the FE if necessary.
CommandTarget oldTarget = aOldNode as CommandTarget;
CommandTarget newTarget = aNewNode as CommandTarget;
if (oldTarget == null && newTarget == null)
return;
int itemKey = newTarget.Data.GetHashCode();
if (mNodes.ContainsKey(itemKey))
{
ManticoreTreeNode item = mNodes[itemKey] as ManticoreTreeNode;
// Check for Label/AccessKey change.
if (newTarget.Label != oldTarget.Label)
item.Text = newTarget.Label;
if (newTarget.IsContainer)
item.ImageIndex = mTreeView.GetIconIndex(newTarget);
}
}
public void OnNodeAdding(Object aNewNode, Object aParentNode, int aIndex)
{
// Not Implemented.
}
public void OnNodeAdded(Object aChildNode, Object aParentNode, int aIndex)
{
// A new Element has been added somewhere. We must find the
// parent menu and append it. To interoperate with the Content Builder,
// the DataStore must provide |CommandTarget|s to this method.
CommandTarget childTarget = aChildNode as CommandTarget;
CommandTarget parentTarget = aParentNode as CommandTarget;
if (childTarget == null && parentTarget == null)
return;
int childKey = childTarget.Data.GetHashCode();
if (!mNodes.ContainsKey(childKey))
{
int parentKey = parentTarget.Data.GetHashCode();
ManticoreTreeNode parentNode;
if (mNodes.ContainsKey(parentKey))
parentNode = mNodes[parentKey] as ManticoreTreeNode;
else
parentNode = mParent as ManticoreTreeNode;
if (parentNode != null)
{
ManticoreTreeNode childNode = new ManticoreTreeNode(childTarget.Label,
childTarget.Data);
if (parentNode != null)
{
int imageIndex = mTreeView.GetIconIndex(childTarget);
if (imageIndex > -1)
childNode.ImageIndex = imageIndex;
parentNode.Nodes.Insert(aIndex, childNode);
if (childTarget.IsContainer && childTarget.IsOpen)
childNode.Expand();
mNodes.Add(childKey, childNode);
}
}
}
}
public void OnNodeRemoving(Object aNodeRemoving)
{
// Not Implemented.
}
public void OnNodeRemoved(Object aNodeRemoved)
{
CommandTarget childTarget = aNodeRemoved as CommandTarget;
// Remove |MenuItem| representation of |aChildNode|.
int childKey = childTarget.Data.GetHashCode();
if (mNodes.ContainsKey(childKey))
{
ManticoreTreeNode childNode = mNodes[childKey] as ManticoreTreeNode;
ManticoreTreeNode parentNode = childNode.Parent as ManticoreTreeNode;
if (parentNode != null)
parentNode.Nodes.Remove(childNode);
else
mTreeView.Nodes.Remove(childNode);
mNodes.Remove(childKey);
}
}
/// <summary>
/// Build content. Builds all content if |LazyState| is set to false.
/// </summary>
public override void Build()
{
if (mDataStore == null || mRoot == null)
throw new Exception();
// XXX implement acknowledgement of |LazyState|
Recurse(mRoot, mParentNodes);
}
public void Recurse(String aRoot, TreeNodeCollection aNodes)
{
IEnumerator items;
mDataStore.GetElements(aRoot, out items);
items.Reset();
ManticoreTreeNode node;
while (items.MoveNext())
{
// |id| is the item's unique identifier within the DataStore.
// The handling code can use this to probe for more information
// about the selected item.
CommandTarget current = items.Current as CommandTarget;
if (current != null)
{
String id = current.Data as String;
int idKey = id.GetHashCode();
if (!mNodes.ContainsKey(idKey))
{
node = new ManticoreTreeNode(current.Label, id);
int imageIndex = mTreeView.GetIconIndex(current);
if (imageIndex > -1)
node.ImageIndex = imageIndex;
aNodes.Insert(mInsertionPoint++, node);
if (current.IsContainer && current.IsOpen)
node.Expand();
mNodes.Add(id.GetHashCode(), node);
// If we're a container, recurse
if (current.IsContainer)
Recurse(id, node.Nodes);
}
}
}
ResetInsertionPoint();
}
///////////////////////////////////////////////////////////////////////////
//
public TreeNode Parent
{
get
{
return mParent;
}
set
{
mParent = value;
}
}
public TreeNode Before
{
get
{
return mBefore;
}
set
{
mBefore = value;
}
}
public TreeNode After
{
get
{
return mAfter;
}
set
{
mAfter = value;
}
}
}
public class BaseTreeBuilder : DynamicTreeBuilder
{
public BaseTreeBuilder(ManticoreTreeView aTreeView, TreeNode aParent) : base(aTreeView, aParent)
{
InitializeComponent();
}
public BaseTreeBuilder(ManticoreTreeView aTreeView,
TreeNode aParent,
TreeNode aBefore,
TreeNode aAfter) : base(aTreeView, aParent, aBefore, aAfter)
{
InitializeComponent();
}
protected override void InitializeComponent()
{
base.InitializeComponent();
mDataStore = new SampleDataStore();
mDataStore.AddObserver(this as IDataStoreObserver);
}
}
}

View File

@ -44,18 +44,26 @@ namespace Silverstone.Manticore.Toolkit
using System.IO;
using System.Xml;
public abstract class MenuBuilder
using Silverstone.Manticore.Core;
using Silverstone.Manticore.Toolkit;
public class MenuBuilder
{
protected internal String mMenuFile;
protected internal Form mForm;
protected String mMenuFile = "";
protected Form mForm = null;
protected MainMenu mMainMenu = null;
public Hashtable mItems;
public Hashtable mBuilders;
public event EventHandler OnCommand;
public MenuBuilder(String aFile, Form aForm)
{
mMenuFile = aFile;
mForm = aForm;
mItems = new Hashtable();
mBuilders = new Hashtable();
}
public void Build()
@ -66,11 +74,12 @@ namespace Silverstone.Manticore.Toolkit
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.MoveToContent();
MainMenu mainMenu = new MainMenu();
Recurse(reader, mainMenu);
mForm.Menu = mainMenu;
mMainMenu = new MainMenu();
Recurse(reader, mMainMenu);
mForm.Menu = mMainMenu;
}
protected MenuItem mCurrentMenuItem;
protected void Recurse(XmlTextReader reader, Menu root)
{
String inner = reader.ReadInnerXml();
@ -80,67 +89,190 @@ namespace Silverstone.Manticore.Toolkit
XmlParserContext ctxt = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
XmlTextReader reader2 = new XmlTextReader(inner, XmlNodeType.Element, ctxt);
MenuItem menuitem;
while (reader2.Read()) {
if (reader2.NodeType == XmlNodeType.Element) {
switch (reader2.LocalName) {
case "menu":
// Menuitem. Find the name, accesskey, command and id strings
String[] values = new String[3] {"", "", ""};
String[] names = new String[3] {"label", "accesskey", "command"};
for (int i = 0; i < names.Length; ++i) {
if (reader2.MoveToAttribute(names[i]) &&
while (reader2.Read())
{
if (reader2.NodeType == XmlNodeType.Element)
{
switch (reader2.LocalName)
{
case "menu":
// Menuitem. Find the name, accesskey, command and id strings
String[] values = new String[3] {"", "", ""};
String[] names = new String[3] {"label", "accesskey", "command"};
for (int i = 0; i < names.Length; ++i)
{
if (reader2.MoveToAttribute(names[i]) &&
reader2.ReadAttributeValue())
values[i] = reader2.Value; // XXX need to handle entities
values[i] = reader2.Value; // XXX need to handle entities
reader2.MoveToElement();
}
// Handle Accesskey
values[0] = ManticoreMenuItem.GenerateAccessKeyString(values[0], values[1]);
// Create menu item and attach an event handler
// BLUESKY - should we support data stored in the XML file as an attribute?
mCurrentMenuItem = new ManticoreMenuItem(values[0],
new EventHandler(OnCommandInternal),
values[2], "");
if (values[2] != "")
mItems.Add(values[2], mCurrentMenuItem);
root.MenuItems.Add(mCurrentMenuItem);
Recurse(reader2, mCurrentMenuItem);
break;
case "menuseparator":
mCurrentMenuItem = new MenuItem("-");
root.MenuItems.Add(mCurrentMenuItem);
break;
case "menubuilder":
String id = "";
if (reader2.MoveToAttribute("id") &&
reader2.ReadAttributeValue())
id = reader2.Value;
reader2.MoveToElement();
}
String datastore = "";
if (reader2.MoveToAttribute("datastore") &&
reader2.ReadAttributeValue())
datastore = reader2.Value;
// Handle Accesskey
int idx = values[0].ToLower().IndexOf(values[1].ToLower());
if (idx != -1)
values[0] = values[0].Insert(idx, "&");
else
values[0] += " (&" + values[1].ToUpper() + ")";
// Create menu item and attach an event handler
menuitem = new CommandMenuItem(values[0],
new EventHandler(OnCommand),
values[2]);
if (values[2] != "")
mItems.Add(values[2], menuitem);
root.MenuItems.Add(menuitem);
Recurse(reader2, menuitem);
break;
case "menuseparator":
menuitem = new MenuItem("-");
root.MenuItems.Add(menuitem);
break;
BaseMenuBuilder builder = new BaseMenuBuilder(mMainMenu, root as MenuItem, mCurrentMenuItem, null);
builder.Root = id;
builder.DataStore = DataStoreRegistry.GetDataStore(datastore);
builder.DataStore.AddObserver(builder);
builder.OnCommand += new EventHandler(OnCommandInternal);
mBuilders.Add(builder.GetHashCode(), builder);
break;
}
}
}
}
public abstract void OnCommand(Object sender, EventArgs e);
protected void OnCommandInternal(Object sender, EventArgs e)
{
if (OnCommand != null)
OnCommand(sender, e);
}
}
public class CommandMenuItem : MenuItem
// XXX should be "ManticoreMenuItem"
public class ManticoreMenuItem : MenuItem
{
private string mCommand;
public string Command
private String mCommand;
/// <summary>
/// The Command String associated with this item. Used with |IController|
/// </summary>
public String Command
{
get {
get
{
return mCommand;
}
}
public CommandMenuItem(String label,
EventHandler handler,
String cmd) : base(label, handler)
/// <summary>
/// Any data associated with this item. Useful to hold DataStore ID references.
/// </summary>
private Object mData;
public Object Data
{
mCommand = cmd;
get
{
return mData;
}
}
public static String GenerateAccessKeyString(String aLabel, String aAccessKey)
{
int idx = aLabel.ToLower().IndexOf(aAccessKey.ToLower());
if (idx != -1)
return aLabel.Insert(idx, "&");
else
return aLabel + " (&" + aAccessKey.ToUpper() + ")";
}
public ManticoreMenuItem(String aLabel, EventHandler aHandler, String aCommand, Object aData) : base(aLabel, aHandler)
{
mCommand = aCommand;
mData = aData;
}
}
public class ManticoreTreeNode : TreeNode
{
private Object mData;
public Object Data
{
get
{
return mData;
}
}
public ManticoreTreeNode(String aLabel, Object aData) : base(aLabel)
{
mData = aData;
}
}
public class ManticoreTreeView : TreeView
{
/// <summary>
/// Holds imageURL->imageIndex mapping of images
/// </summary>
protected Hashtable mImages = null;
/// <summary>
/// Number of images currently hashed (current image index)
/// </summary>
protected int mImageCount = 0;
/// <summary>
/// Transparent colour used in icons. We could be pedantic and allow this
/// to come from the datastore, but this'll do for now.
/// </summary>
protected Color mIconTransparentColor;
public int GetIconIndex(String aIconURL)
{
if (aIconURL == "")
return -1;
if (mImages == null)
mImages = new Hashtable();
int key = aIconURL.GetHashCode();
if (!mImages.ContainsKey(key))
{
if (ImageList == null)
ImageList = new ImageList();
Console.WriteLine(mIconTransparentColor);
try
{
ImageList.Images.Add(Image.FromFile(aIconURL), mIconTransparentColor);
mImages.Add(key, mImageCount);
}
catch (FileNotFoundException)
{
// If the file can't be found, don't add it to the list.
return -1;
}
return mImageCount++;
}
else
return (int) mImages[key];
}
/// <summary>
/// Client overrides to provide special Icons for the particular treeview.
/// </summary>
/// <param name="aCommandTarget"></param>
/// <returns></returns>
public virtual int GetIconIndex(CommandTarget aCommandTarget)
{
return -1;
}
}
}

View File

@ -54,9 +54,9 @@ namespace Silverstone.Manticore.Toolkit
public Hashtable mItems;
public ToolbarBuilder(String file, Form form)
{
{
mToolbarFile = file;
mForm = form;
mForm = form;
mItems = new Hashtable();
}
@ -67,62 +67,64 @@ namespace Silverstone.Manticore.Toolkit
reader.WhitespaceHandling = WhitespaceHandling.None;
reader.MoveToContent();
while (reader.Read()) {
if (reader.NodeType == XmlNodeType.Element) {
switch (reader.LocalName)
{
case "toolstrip":
// The next <toolbar/> we encounter should be created on a new row.
break;
case "toolbar":
//
String[] tbvalues = new String[4] {"", "", "", ""};
String[] tbnames = new String[4] {"id", "label", "description", "visible"};
for (int i = 0; i < tbnames.Length; ++i)
{
if (reader.MoveToAttribute(tbnames[i]) &&
reader.ReadAttributeValue())
tbvalues[i] = reader.Value; // XXX need to handle entities
reader.MoveToElement();
}
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.LocalName)
{
case "toolstrip":
// The next <toolbar/> we encounter should be created on a new row.
break;
case "toolbar":
//
String[] tbvalues = new String[4] {"", "", "", ""};
String[] tbnames = new String[4] {"id", "label", "description", "visible"};
for (int i = 0; i < tbnames.Length; ++i)
{
if (reader.MoveToAttribute(tbnames[i]) &&
reader.ReadAttributeValue())
tbvalues[i] = reader.Value; // XXX need to handle entities
reader.MoveToElement();
}
String key = tbvalues[0];
String label = tbvalues[1];
String visible = tbvalues[3];
String key = tbvalues[0];
String label = tbvalues[1];
String visible = tbvalues[3];
// Create and add a new toolbar.
mCurrentToolbar = new ToolBar();
mCurrentToolbar.Dock = DockStyle.Top;
mCurrentToolbar.Appearance = ToolBarAppearance.Flat;
mForm.Controls.Add(mCurrentToolbar);
// Create and add a new toolbar.
mCurrentToolbar = new ToolBar();
mCurrentToolbar.Dock = DockStyle.Top;
mCurrentToolbar.Appearance = ToolBarAppearance.Flat;
mForm.Controls.Add(mCurrentToolbar);
mCurrentToolbar.ButtonClick += new ToolBarButtonClickEventHandler(this.OnCommand);
break;
case "toolbarseparator":
{
ToolBarButton button = new ToolBarButton();
button.Style = ToolBarButtonStyle.Separator;
mCurrentToolbar.Buttons.Add(button);
break;
}
case "toolbarbutton":
{
String[] tbbvalues = new String[2] {"", ""};
String[] tbbnames = new String[2] {"label", "command"};
for (int i = 0; i < tbbnames.Length; ++i)
{
if (reader.MoveToAttribute(tbbnames[i]) &&
reader.ReadAttributeValue())
tbbvalues[i] = reader.Value; // XXX need to handle entities
reader.MoveToElement();
}
mCurrentToolbar.ButtonClick += new ToolBarButtonClickEventHandler(this.OnCommand);
break;
case "toolbarseparator":
{
ToolBarButton button = new ToolBarButton();
button.Style = ToolBarButtonStyle.Separator;
mCurrentToolbar.Buttons.Add(button);
break;
}
case "toolbarbutton":
{
String[] tbbvalues = new String[2] {"", ""};
String[] tbbnames = new String[2] {"label", "command"};
for (int i = 0; i < tbbnames.Length; ++i)
{
if (reader.MoveToAttribute(tbbnames[i]) &&
reader.ReadAttributeValue())
tbbvalues[i] = reader.Value; // XXX need to handle entities
reader.MoveToElement();
}
ToolBarButton button = new CommandButtonItem(tbbvalues[1]);
button.Text = tbbvalues[0];
mCurrentToolbar.Buttons.Add(button);
break;
}
}
ToolBarButton button = new CommandButtonItem(tbbvalues[1]);
button.Text = tbbvalues[0];
mCurrentToolbar.Buttons.Add(button);
break;
}
}
}
}
}
@ -146,5 +148,4 @@ namespace Silverstone.Manticore.Toolkit
mCommand = cmd;
}
}
}
}