Make preferences dialog work (PrefPanel class for preference panel switching, loading of preferences, saving of preferences, initial Browser Display panel)
This commit is contained in:
ben%netscape.com 2001-07-02 07:07:08 +00:00
Родитель 1c50a2a718
Коммит d495f6f7ae
10 изменённых файлов: 272 добавлений и 53 удалений

Просмотреть файл

@ -37,8 +37,8 @@ namespace Silverstone.Manticore.App
// Initialize default and user preferences
mPreferences = new Preferences();
mPreferences.InitializeDefaults("default-prefs.xml");
mPreferences.LoadPreferencesFile("user-prefs.xml");
mPreferences.InitializeDefaults();
mPreferences.LoadUserPreferences();
// Initialize bookmarks
mBookmarks = new Bookmarks(this);
@ -52,7 +52,7 @@ namespace Silverstone.Manticore.App
public void Quit()
{
// Flush preferences to disk.
mPreferences.FlushPreferencesFile("user-prefs.xml");
mPreferences.FlushUserPreferences();
Application.Exit();
}
@ -70,11 +70,12 @@ namespace Silverstone.Manticore.App
}
// Opens and displays a new browser window
public void OpenNewBrowser()
public BrowserWindow OpenNewBrowser()
{
BrowserWindow window = new BrowserWindow(this);
mBrowserWindows.Add(window.GetHashCode(), window);
window.Show();
return window;
}
public static void Main(string[] args)

Просмотреть файл

@ -1,13 +1,16 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Silverstone.Manticore.Browser
{
/// <summary>
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using Silverstone.Manticore.Core;
/// <summary>
/// Summary description for BrowserDisplayPanel.
/// </summary>
public class BrowserDisplayPanel : PrefPanel
@ -28,12 +31,99 @@ namespace Silverstone.Manticore.Browser
/// </summary>
private System.ComponentModel.Container components = null;
public BrowserDisplayPanel()
/// <summary>
/// LAME - the window that invoked the preferences dialog
/// </summary>
private Form mOpener = null;
/// <summary>
/// Construct a BrowserDisplayPanel
/// </summary>
/// <param name="aParent"></param>
/// <param name="aOpener">
/// The window that opened the preferencs dialog. We'd really rather get rid of
/// this and replace it with calls to a window-mediator service.
/// </param>
/// <param name="aPrefs">
/// The preferences handle from the application object. We want to get rid of this
/// and use some kind of global preferences service.
/// </param>
public BrowserDisplayPanel(Form aParent, Form aOpener, Preferences aPrefs) : base(aParent, aPrefs)
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
Console.WriteLine("Done initializeing browser display panel");
mOpener = aOpener;
restoreSessionSettingsButton.Enabled = false;
radioButton3.Click += new EventHandler(OnStartupModeRadio);
radioButton2.Click += new EventHandler(OnStartupModeRadio);
radioButton1.Click += new EventHandler(OnStartupModeRadio);
restoreSessionSettingsButton.Click += new EventHandler(OnRestoreSessionSettings);
button2.Click += new EventHandler(OnUseCurrent);
}
public void OnUseCurrent(object sender, EventArgs e)
{
// XXX what we really want to do here is use a window-mediator like
// entity to find the most recent browser window. This will surely
// fail miserably if the opening window isn't a browser.
BrowserWindow window = mOpener as BrowserWindow;
if (window != null)
textBox1.Text = window.URL;
}
public void OnRestoreSessionSettings(object sender, EventArgs e)
{
RestoreSessionSettings dlg = new RestoreSessionSettings(mParent);
dlg.ShowDialog();
// XXX fill in code to remember session settings here
}
public void OnStartupModeRadio(object sender, EventArgs e)
{
// Enable the Restore Session Settings button when the Restore Settings
// startup mode is enabled.
restoreSessionSettingsButton.Enabled = radioButton3.Checked;
}
public override void Load()
{
String homepageURL = mPrefs.GetStringPref("browser.homepage");
textBox1.Text = homepageURL;
int startMode = mPrefs.GetIntPref("browser.homepage.mode");
switch (startMode) {
case 0:
radioButton3.Checked = true;
restoreSessionSettingsButton.Enabled = true;
break;
case 2:
radioButton2.Checked = true;
break;
case 1:
default:
radioButton1.Checked = true;
break;
}
}
public override void Save()
{
mPrefs.SetStringPref("browser.homepage", textBox1.Text != "" ? textBox1.Text : "about:blank");
int mode = 1;
if (radioButton3.Checked)
mode = 0;
else if (radioButton2.Checked)
mode = 2;
mPrefs.SetIntPref("browser.homepage.mode", mode);
// XXX need to save session setting prefs when implemented.
}
/// <summary>
@ -41,14 +131,9 @@ namespace Silverstone.Manticore.Browser
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
if (disposing && components != null)
components.Dispose();
base.Dispose(disposing);
}
#region Component Designer generated code
@ -135,7 +220,7 @@ namespace Silverstone.Manticore.Browser
this.radioButton2,
this.radioButton1});
this.groupBox2.Location = new System.Drawing.Point(8, 0);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Name = "startupModeGroup";
this.groupBox2.Size = new System.Drawing.Size(312, 104);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
@ -151,7 +236,7 @@ namespace Silverstone.Manticore.Browser
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(16, 72);
this.radioButton3.Name = "radioButton3";
this.radioButton3.Name = "restoreSessionRadio";
this.radioButton3.Size = new System.Drawing.Size(152, 16);
this.radioButton3.TabIndex = 2;
this.radioButton3.Text = "Restore previous session";
@ -159,7 +244,7 @@ namespace Silverstone.Manticore.Browser
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(16, 48);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Name = "blankPageRadio";
this.radioButton2.Size = new System.Drawing.Size(112, 16);
this.radioButton2.TabIndex = 1;
this.radioButton2.Text = "Show blank page";
@ -167,7 +252,7 @@ namespace Silverstone.Manticore.Browser
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(16, 24);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Name = "homePageRadio";
this.radioButton1.Size = new System.Drawing.Size(120, 16);
this.radioButton1.TabIndex = 0;
this.radioButton1.Text = "Show home page";

Просмотреть файл

@ -41,6 +41,8 @@ namespace Silverstone.Manticore.Browser
using System.Data;
using System.Windows.Forms;
using Silverstone.Manticore.Core;
/// <summary>
/// Summary description for UserControl1.
/// </summary>
@ -51,14 +53,32 @@ namespace Silverstone.Manticore.Browser
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
/// Whether or not this panel has been shown before. We defer
/// reading preferences and populating UI for preferences panels
/// that have not yet been shown.
/// </summary>
private bool mGenerated = false;
public PrefPanel()
/// <summary>
/// Preferences handle
/// </summary>
// LAME - need to use global service thingy.
protected internal Preferences mPrefs;
/// <summary>
/// Parent window (Preferences dialog)
/// </summary>
protected internal Form mParent;
public PrefPanel(Form aParent, Preferences aPrefs)
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
Console.WriteLine("Pref panel startup");
// LAME oh so lame.
mPrefs = aPrefs;
mParent = aParent;
// All preferences panels have these properties initially.
this.Location = new System.Drawing.Point(160, 16);
@ -78,16 +98,30 @@ namespace Silverstone.Manticore.Browser
/// <param name="e"></param>
public void VisibilityChanged(Object sender, EventArgs e)
{
Console.WriteLine("Visibility changed!");
if (!mGenerated) {
// The first time we display the panel, read the values
// for UI elements from preferences and fill the controls.
Load();
mGenerated = true;
}
}
public void Save()
/// <summary>
/// Implemented by derived class. Reads preferences for each UI element
/// the first time this panel is shown, and populates the UI appropriately.
/// </summary>
public virtual void Load()
{
// Implemented by derived class
}
/// <summary>
/// Implemented by derived class. Takes data from UI elements (which may
/// be user-manipulated) and saves preferences.
/// </summary>
public virtual void Save()
{
// Implemented by derived class
}
/// <summary>

Просмотреть файл

@ -44,6 +44,7 @@ namespace Silverstone.Manticore.Browser
using System.Xml;
using Silverstone.Manticore.Toolkit;
using Silverstone.Manticore.Core;
/// <summary>
/// Summary description for Form1.
@ -62,6 +63,9 @@ namespace Silverstone.Manticore.Browser
private Hashtable mPanels = null;
private PrefPanel mCurrentPanel = null;
// LAME find a way to do global application service.
private Preferences mPrefs = null;
public PrefsDialog(Form aOpener) : base(aOpener)
{
//
@ -69,9 +73,14 @@ namespace Silverstone.Manticore.Browser
//
InitializeComponent();
okButton.Click += new EventHandler(OnOK);
mNodes = new Hashtable();
mPanels = new Hashtable();
BrowserWindow window = mOpener as BrowserWindow;
mPrefs = window.mApplication.Prefs;
//
// Initialize all the preference panels.
//
@ -91,6 +100,20 @@ namespace Silverstone.Manticore.Browser
treeView1.ExpandAll();
}
public void OnOK(object sender, EventArgs e)
{
// Call |Save| on each preferences panel...
IEnumerator panels = mPanels.Values.GetEnumerator();
while (panels.MoveNext()) {
PrefPanel currPanel = panels.Current as PrefPanel;
currPanel.Save();
}
// ... then flush preferences to disk for safe keepin'.
// XXX not just yet.
// mPrefs.FlushUserPreferences();
}
public void OnTreeSelect(Object sender, TreeViewEventArgs e)
{
TreeNode selectedNode = e.Node;
@ -99,7 +122,6 @@ namespace Silverstone.Manticore.Browser
if (mCurrentPanel != null)
mCurrentPanel.Visible = false;
if (newPanel != null) {
Console.WriteLine("toggling visibility of panel");
newPanel.Visible = true;
mCurrentPanel = newPanel;
}
@ -116,8 +138,9 @@ namespace Silverstone.Manticore.Browser
/// </summary>
public void InitializePanels()
{
BrowserDisplayPanel bdp = new BrowserDisplayPanel();
BrowserDisplayPanel bdp = new BrowserDisplayPanel(this, mOpener, mPrefs);
mPanels.Add("browser-display", bdp);
this.Controls.Add(bdp);
}
/// <summary>
@ -251,21 +274,9 @@ namespace Silverstone.Manticore.Browser
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Text = "Options";
this.Load += new System.EventHandler(this.PrefsDialog_Load);
this.ResumeLayout(false);
}
#endregion
private void restoreSessionSettingsButton_Click(object sender, System.EventArgs e)
{
RestoreSessionSettings dlg = new RestoreSessionSettings(this);
dlg.ShowDialog();
}
private void PrefsDialog_Load(object sender, System.EventArgs e)
{
}
}
}

Просмотреть файл

@ -123,6 +123,18 @@ namespace Silverstone.Manticore.Browser
this.VisibleChanged += new EventHandler(LoadStartPage);
}
/// <summary>
/// The currently loaded document's URL.
/// </summary>
public String URL {
get {
return mWebBrowser.URL;
}
set {
mWebBrowser.URL = value;
}
}
private void LoadStartPage(object sender, EventArgs e)
{
int startMode = mApplication.Prefs.GetIntPref("browser.homepage.mode");
@ -160,6 +172,11 @@ namespace Silverstone.Manticore.Browser
mApplication.Quit();
}
public Object GetCurrentLayoutEngine()
{
return mWebBrowser.GetCurrentLayoutEngine();
}
private int previousProgress = 0;
public void OnProgress(int aProgress, int aProgressMax)
{
@ -172,13 +189,19 @@ namespace Silverstone.Manticore.Browser
public void OnTitleChange(String aTitle)
{
this.Text = aTitle + " - Manticore";
this.Text = (aTitle == "about:blank") ? "Manticore" : aTitle + " - Manticore";
}
public void OnStatusTextChange(String aStatusText)
{
mStatusPanel.Text = aStatusText;
}
public Object OnNewWindow()
{
BrowserWindow window = mApplication.OpenNewBrowser();
return window.GetCurrentLayoutEngine();
}
public void DoCommand(String s)
{

Просмотреть файл

@ -52,10 +52,11 @@ namespace Silverstone.Manticore.Core
mPrefsDocument = new XmlDocument();
}
public void InitializeDefaults(String aDefaults)
public void InitializeDefaults()
{
// Do we ever want to support multiple defaults files? For now, no.
ReadDocument(aDefaults, mDefaultsDocument);
// XXX need a better place for this file.
ReadDocument("default-prefs.xml", mDefaultsDocument);
}
private void ReadDocument(String aFile, XmlDocument aDocument)
@ -78,19 +79,28 @@ namespace Silverstone.Manticore.Core
mPrefsDocument.NodeInserted += new XmlNodeChangedEventHandler(OnNodeInserted);
}
public void LoadUserPreferences()
{
// XXX this needs to go into Documents and Settings
LoadPreferencesFile("user-prefs.xml");
}
public void FlushUserPreferences()
{
// XXX this needs to go into Documents and Settings
FlushPreferencesFile("user-prefs.xml");
}
public void OnNodeChanged(object sender, XmlNodeChangedEventArgs e)
{
Console.WriteLine(e.ToString());
}
public void OnNodeRemoved(object sender, XmlNodeChangedEventArgs e)
{
Console.WriteLine(e.ToString());
}
public void OnNodeInserted(object sender, XmlNodeChangedEventArgs e)
{
Console.WriteLine(e.ToString());
}
public void FlushPreferencesFile(String aFile)

Просмотреть файл

@ -124,6 +124,15 @@ namespace Silverstone.Manticore.Layout
LoadURL(url, false);
}
public Object GetCurrentLayoutEngine()
{
if (gecko != null)
return gecko;
else if (trident != null)
return trident;
return null;
}
public void LoadURL(String url, Boolean bypassCache)
{
// XXX - neither IE nor Mozilla implement all of the
@ -139,6 +148,21 @@ namespace Silverstone.Manticore.Layout
trident.Navigate(url, ref o, ref o, ref o, ref o);
}
public String URL
{
get {
if (gecko != null)
return gecko.LocationURL;
else if (trident != null)
return trident.LocationURL;
return "";
}
set {
LoadURL(value, false);
// XXX why can't we return |value| here?
}
}
public void RefreshPage()
{
// XXX Should take a refresh level and use Refresh2.
@ -189,6 +213,7 @@ namespace Silverstone.Manticore.Layout
AddProgressListener();
AddTitleChangeListener();
AddStatusChangeListener();
AddNewWindowListener();
}
private bool mProgressChangeGecko = false;
@ -257,6 +282,34 @@ namespace Silverstone.Manticore.Layout
mBrowserWindow.OnStatusTextChange(e.text);
}
private bool mNewWindowGecko = false;
private bool mNewWindowTrident = false;
private void AddNewWindowListener()
{
if (gecko != null && !mNewWindowGecko) {
gecko.NewWindow2 += new AxMOZILLACONTROLLib.DWebBrowserEvents2_NewWindow2EventHandler(OnNewWindowGecko);
mNewWindowGecko = true;
}
else if (trident != null && !mNewWindowTrident) {
trident.NewWindow2 += new AxSHDocVw.DWebBrowserEvents2_NewWindow2EventHandler(OnNewWindowTrident);
mNewWindowTrident = true;
}
}
public void OnNewWindowGecko(Object sender, AxMOZILLACONTROLLib.DWebBrowserEvents2_NewWindow2Event e)
{
Object browser = mBrowserWindow.OnNewWindow();
AxMozillaBrowser webBrowser = browser as AxMozillaBrowser;
if (webBrowser != null)
e.ppDisp = webBrowser;
}
public void OnNewWindowTrident(Object sender, AxSHDocVw.DWebBrowserEvents2_NewWindow2Event e)
{
Object browser = mBrowserWindow.OnNewWindow();
AxWebBrowser webBrowser = browser as AxWebBrowser;
if (webBrowser != null)
e.ppDisp = webBrowser;
}
}
}

Просмотреть файл

@ -42,7 +42,7 @@ namespace Silverstone.Manticore.Toolkit
/// </summary>
public class ManticoreDialog : Form
{
private Form mOpener;
protected internal Form mOpener;
public ManticoreDialog(Form aOpener) : base()
{

Просмотреть файл

@ -12,7 +12,6 @@ namespace Silverstone.Manticore.Toolkit
{
public ManticoreProgressMeter()
{
Console.WriteLine("Progressmeter!");
this.Style = StatusBarPanelStyle.OwnerDraw;
}

Просмотреть файл

@ -2,5 +2,8 @@
<browser>
<layoutengine value="trident" />
<bookmarksfile value="bookmarks.xml" />
<homepage value="http://abcnews.go.com/" xmlns="">
<mode value="1" />
</homepage>
</browser>
</preferences>