From d495f6f7ae65f48681d727793e96c413ade23d19 Mon Sep 17 00:00:00 2001 From: "ben%netscape.com" Date: Mon, 2 Jul 2001 07:07:08 +0000 Subject: [PATCH] [Not part of build] Make preferences dialog work (PrefPanel class for preference panel switching, loading of preferences, saving of preferences, initial Browser Display panel) --- extensions/manticore/app.cs | 9 +- .../manticore/browser/BrowserDisplayPanel.cs | 127 +++++++++++++++--- extensions/manticore/browser/PrefPanel.cs | 46 ++++++- extensions/manticore/browser/PrefsDialog.cs | 39 ++++-- extensions/manticore/browser/browserwindow.cs | 25 +++- extensions/manticore/core/preferences.cs | 20 ++- .../manticore/layout/layoutabstraction.cs | 53 ++++++++ .../manticore/toolkit/ManticoreDialog.cs | 2 +- extensions/manticore/toolkit/ProgressMeter.cs | 1 - extensions/manticore/user-prefs.xml | 3 + 10 files changed, 272 insertions(+), 53 deletions(-) diff --git a/extensions/manticore/app.cs b/extensions/manticore/app.cs index 278344a6dba1..6ca5cdfb7461 100644 --- a/extensions/manticore/app.cs +++ b/extensions/manticore/app.cs @@ -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) diff --git a/extensions/manticore/browser/BrowserDisplayPanel.cs b/extensions/manticore/browser/BrowserDisplayPanel.cs index 0beec30dabcc..699cf841ebcd 100644 --- a/extensions/manticore/browser/BrowserDisplayPanel.cs +++ b/extensions/manticore/browser/BrowserDisplayPanel.cs @@ -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 { - /// + using System; + using System.Collections; + using System.ComponentModel; + using System.Drawing; + using System.Data; + using System.Windows.Forms; + + using Silverstone.Manticore.Core; + + /// /// Summary description for BrowserDisplayPanel. /// public class BrowserDisplayPanel : PrefPanel @@ -28,12 +31,99 @@ namespace Silverstone.Manticore.Browser /// private System.ComponentModel.Container components = null; - public BrowserDisplayPanel() + /// + /// LAME - the window that invoked the preferences dialog + /// + private Form mOpener = null; + + /// + /// Construct a BrowserDisplayPanel + /// + /// + /// + /// 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. + /// + /// + /// The preferences handle from the application object. We want to get rid of this + /// and use some kind of global preferences service. + /// + 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. } /// @@ -41,14 +131,9 @@ namespace Silverstone.Manticore.Browser /// 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"; diff --git a/extensions/manticore/browser/PrefPanel.cs b/extensions/manticore/browser/PrefPanel.cs index 1a54d93c4364..7fb0fa256afb 100644 --- a/extensions/manticore/browser/PrefPanel.cs +++ b/extensions/manticore/browser/PrefPanel.cs @@ -41,6 +41,8 @@ namespace Silverstone.Manticore.Browser using System.Data; using System.Windows.Forms; + using Silverstone.Manticore.Core; + /// /// Summary description for UserControl1. /// @@ -51,14 +53,32 @@ namespace Silverstone.Manticore.Browser /// private System.ComponentModel.Container components = null; + /// + /// 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. + /// private bool mGenerated = false; - public PrefPanel() + /// + /// Preferences handle + /// + // LAME - need to use global service thingy. + protected internal Preferences mPrefs; + + /// + /// Parent window (Preferences dialog) + /// + 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 /// 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() + /// + /// Implemented by derived class. Reads preferences for each UI element + /// the first time this panel is shown, and populates the UI appropriately. + /// + public virtual void Load() { - + // Implemented by derived class + } + + /// + /// Implemented by derived class. Takes data from UI elements (which may + /// be user-manipulated) and saves preferences. + /// + public virtual void Save() + { + // Implemented by derived class } /// diff --git a/extensions/manticore/browser/PrefsDialog.cs b/extensions/manticore/browser/PrefsDialog.cs index ac15b98e328c..f9a083ef9be6 100644 --- a/extensions/manticore/browser/PrefsDialog.cs +++ b/extensions/manticore/browser/PrefsDialog.cs @@ -44,6 +44,7 @@ namespace Silverstone.Manticore.Browser using System.Xml; using Silverstone.Manticore.Toolkit; + using Silverstone.Manticore.Core; /// /// 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 /// public void InitializePanels() { - BrowserDisplayPanel bdp = new BrowserDisplayPanel(); + BrowserDisplayPanel bdp = new BrowserDisplayPanel(this, mOpener, mPrefs); mPanels.Add("browser-display", bdp); + this.Controls.Add(bdp); } /// @@ -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) - { - - } } } diff --git a/extensions/manticore/browser/browserwindow.cs b/extensions/manticore/browser/browserwindow.cs index 70d070570b5e..c1764221fb9d 100644 --- a/extensions/manticore/browser/browserwindow.cs +++ b/extensions/manticore/browser/browserwindow.cs @@ -123,6 +123,18 @@ namespace Silverstone.Manticore.Browser this.VisibleChanged += new EventHandler(LoadStartPage); } + /// + /// The currently loaded document's URL. + /// + 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) { diff --git a/extensions/manticore/core/preferences.cs b/extensions/manticore/core/preferences.cs index 87eb2562a74a..a9142fada63f 100644 --- a/extensions/manticore/core/preferences.cs +++ b/extensions/manticore/core/preferences.cs @@ -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) diff --git a/extensions/manticore/layout/layoutabstraction.cs b/extensions/manticore/layout/layoutabstraction.cs index de16648ab8ec..f44c079d5e21 100644 --- a/extensions/manticore/layout/layoutabstraction.cs +++ b/extensions/manticore/layout/layoutabstraction.cs @@ -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; + } + } } diff --git a/extensions/manticore/toolkit/ManticoreDialog.cs b/extensions/manticore/toolkit/ManticoreDialog.cs index 14d2e7423b0b..ef0088855727 100644 --- a/extensions/manticore/toolkit/ManticoreDialog.cs +++ b/extensions/manticore/toolkit/ManticoreDialog.cs @@ -42,7 +42,7 @@ namespace Silverstone.Manticore.Toolkit /// public class ManticoreDialog : Form { - private Form mOpener; + protected internal Form mOpener; public ManticoreDialog(Form aOpener) : base() { diff --git a/extensions/manticore/toolkit/ProgressMeter.cs b/extensions/manticore/toolkit/ProgressMeter.cs index 4d6a426e7b11..8e5d38d18059 100644 --- a/extensions/manticore/toolkit/ProgressMeter.cs +++ b/extensions/manticore/toolkit/ProgressMeter.cs @@ -12,7 +12,6 @@ namespace Silverstone.Manticore.Toolkit { public ManticoreProgressMeter() { - Console.WriteLine("Progressmeter!"); this.Style = StatusBarPanelStyle.OwnerDraw; } diff --git a/extensions/manticore/user-prefs.xml b/extensions/manticore/user-prefs.xml index 7707415f9f0d..901bc90a1037 100644 --- a/extensions/manticore/user-prefs.xml +++ b/extensions/manticore/user-prefs.xml @@ -2,5 +2,8 @@ + + + \ No newline at end of file