diff --git a/extensions/manticore/Manticore.csproj b/extensions/manticore/Manticore.csproj
index 8f85eb88e67c..89414a33f298 100644
--- a/extensions/manticore/Manticore.csproj
+++ b/extensions/manticore/Manticore.csproj
@@ -242,6 +242,11 @@
SubType = "Code"
BuildAction = "Compile"
/>
+
0) {
@@ -131,7 +112,7 @@ namespace Silverstone.Manticore.App
// Create a new browser with the applicable url at the applicable
// location.
- BrowserWindow window = OpenBrowserWithURL(url);
+ BrowserWindow window = BrowserWindow.OpenBrowserWithURL(url);
window.Location = new Point(x, y);
window.Size = new Size(width, height);
}
@@ -142,39 +123,10 @@ namespace Silverstone.Manticore.App
return false;
}
- public void WindowClosed(BrowserWindow aWindow)
- {
- if (mBrowserWindows.ContainsKey(aWindow.GetHashCode()))
- mBrowserWindows.Remove(aWindow.GetHashCode());
-
- // When window count drops to zero, quit.
- // XXX - a little hacky for now, will eventually reflect
- // all windows.
- if (mBrowserWindows.Count == 0)
- Quit();
- }
-
- // Opens and displays a new browser window
- public BrowserWindow OpenBrowser()
- {
- BrowserWindow window = new BrowserWindow(this);
- mBrowserWindows.Add(window.GetHashCode(), window);
- window.Show();
- return window;
- }
-
- public BrowserWindow OpenBrowserWithURL(String aURL)
- {
- BrowserWindow window = new BrowserWindow(this, aURL);
- mBrowserWindows.Add(window.GetHashCode(), window);
- window.Show();
- return window;
- }
-
[STAThread]
public static void Main(string[] args)
{
- ManticoreApp app = new ManticoreApp();
+ ServiceManager.mApp = new ManticoreApp();
}
}
}
diff --git a/extensions/manticore/bookmarks/BookmarksWindow.cs b/extensions/manticore/bookmarks/BookmarksWindow.cs
index 40ea6a5c8e8c..db972d2a90c3 100644
--- a/extensions/manticore/bookmarks/BookmarksWindow.cs
+++ b/extensions/manticore/bookmarks/BookmarksWindow.cs
@@ -44,6 +44,7 @@ namespace Silverstone.Manticore.Bookmarks
using Silverstone.Manticore.Core;
using Silverstone.Manticore.Toolkit;
using Silverstone.Manticore.Bookmarks;
+ using Silverstone.Manticore.Browser;
///
/// Summary description for BookmarksWindow.
@@ -53,19 +54,20 @@ namespace Silverstone.Manticore.Bookmarks
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.StatusBarPanel statusBarPanel1;
private BookmarksTreeView mBookmarksTree;
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.Container components = null;
private BaseTreeBuilder mBuilder = null;
public BookmarksWindow()
{
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
+ mType = "BookmarksWindow";
+
+ Init();
+ }
+
+ protected void Init()
+ {
+ // Set up UI
+ InitializeComponent();
//
// mBookmarksTree
@@ -83,24 +85,11 @@ namespace Silverstone.Manticore.Bookmarks
Controls.Add(mBookmarksTree);
mBookmarksTree.Build();
+
+ base.Init();
}
-
- ///
- /// Clean up any resources being used.
- ///
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
-
- #region Windows Form Designer generated code
+
+ #region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
@@ -152,7 +141,13 @@ namespace Silverstone.Manticore.Bookmarks
ManticoreTreeNode node = mBookmarksTree.SelectedNode as ManticoreTreeNode;
Bookmarks bmks = ServiceManager.Bookmarks;
String bookmarkURL = bmks.GetBookmarkAttribute(node.Data as String, "url");
- ManticoreApp.MostRecentBrowserWindow.LoadURL(bookmarkURL);
+ if (bookmarkURL != "")
+ {
+ WindowMediator wm = ServiceManager.WindowMediator;
+ BrowserWindow window = wm.GetMostRecentWindow("BrowserWindow") as BrowserWindow;
+ if (window != null)
+ window.LoadURL(bookmarkURL);
+ }
}
}
diff --git a/extensions/manticore/browser/browserwindow.cs b/extensions/manticore/browser/browserwindow.cs
index e22d7a89f2ac..e749aa0599ae 100644
--- a/extensions/manticore/browser/browserwindow.cs
+++ b/extensions/manticore/browser/browserwindow.cs
@@ -47,8 +47,6 @@ namespace Silverstone.Manticore.Browser
public class BrowserWindow : ManticoreWindow, IController
{
- private System.ComponentModel.Container components;
-
private MenuBuilder mMenuBuilder;
private BrowserToolbarBuilder mToolbarBuilder;
@@ -57,7 +55,6 @@ namespace Silverstone.Manticore.Browser
private StatusBar mStatusBar;
private StatusBarPanel mProgressMeter;
private StatusBarPanel mStatusPanel;
- private ManticoreApp mApplication;
private String mSessionURL = "";
@@ -66,49 +63,29 @@ namespace Silverstone.Manticore.Browser
///
private String mTitle = "";
- public BrowserWindow(ManticoreApp aApp)
+ public BrowserWindow()
{
- Init(aApp);
+ Init();
}
- public BrowserWindow(ManticoreApp aApp, String aURL)
+ public BrowserWindow(String aURL)
{
mSessionURL = aURL;
- Init(aApp);
+ mType = "BrowserWindow";
+
+ Init();
}
- private void Init(ManticoreApp aApp)
+ protected void Init()
{
- mApplication = aApp;
- mType = "Browser";
-
// Set up UI
InitializeComponent();
- this.Closed += new EventHandler(OnFormClosed);
- this.GotFocus += new EventHandler(OnSetFocus);
- }
-
- public void OnFormClosed(Object sender, EventArgs e)
- {
- mApplication.WindowClosed(this);
- }
-
- public void OnSetFocus(Object sender, EventArgs e)
- {
- ManticoreApp.MostRecentBrowserWindow = this;
- }
-
- public override void Dispose()
- {
- base.Dispose();
- components.Dispose();
+ base.Init();
}
private void InitializeComponent()
{
- this.components = new System.ComponentModel.Container();
-
// XXX read these from a settings file
this.Width = 640;
this.Height = 480;
@@ -183,13 +160,24 @@ namespace Silverstone.Manticore.Browser
}
}
+ ///////////////////////////////////////////////////////////////////////////
+ // Window Creation
+ public static BrowserWindow OpenBrowser()
+ {
+ BrowserWindow window = new BrowserWindow();
+ window.Show();
+ return window;
+ }
+
+ public static BrowserWindow OpenBrowserWithURL(String aURL)
+ {
+ BrowserWindow window = new BrowserWindow(aURL);
+ window.Show();
+ return window;
+ }
///////////////////////////////////////////////////////////////////////////
// Menu Command Handlers
- public void OpenNewBrowser()
- {
- mApplication.OpenBrowser();
- }
public void Open()
{
@@ -200,7 +188,8 @@ namespace Silverstone.Manticore.Browser
public void Quit()
{
- mApplication.Quit();
+ ManticoreApp app = ServiceManager.App;
+ app.Quit();
}
public Object currentLayoutEngine
@@ -233,8 +222,7 @@ namespace Silverstone.Manticore.Browser
public Object OnNewWindow()
{
- // BrowserWindow window = mApplication.OpenNewBrowser();
- // return window.currentLayoutEngine;
+ // XXX figure out what this does.
return new Object();
}
@@ -263,7 +251,7 @@ namespace Silverstone.Manticore.Browser
switch (aCommand)
{
case "file-new-window":
- OpenNewBrowser();
+ OpenBrowser();
break;
case "file-open":
Open();
diff --git a/extensions/manticore/core/ServiceManager.cs b/extensions/manticore/core/ServiceManager.cs
index b874d8330984..b20ce1aae5bb 100644
--- a/extensions/manticore/core/ServiceManager.cs
+++ b/extensions/manticore/core/ServiceManager.cs
@@ -34,6 +34,7 @@
namespace Silverstone.Manticore.Core
{
+ using Silverstone.Manticore.App;
///
/// Access point to application-global services.
@@ -70,5 +71,25 @@ namespace Silverstone.Manticore.Core
return mBookmarks;
}
}
+
+ private static Silverstone.Manticore.Core.WindowMediator mWindowMediator = null;
+ public static Silverstone.Manticore.Core.WindowMediator WindowMediator
+ {
+ get
+ {
+ if (mWindowMediator == null)
+ mWindowMediator = new Silverstone.Manticore.Core.WindowMediator();
+ return mWindowMediator;
+ }
+ }
+
+ internal static Silverstone.Manticore.App.ManticoreApp mApp = null;
+ public static Silverstone.Manticore.App.ManticoreApp App
+ {
+ get
+ {
+ return mApp;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/extensions/manticore/core/WindowMediator.cs b/extensions/manticore/core/WindowMediator.cs
index d4d63ecefc96..8c851a54d776 100644
--- a/extensions/manticore/core/WindowMediator.cs
+++ b/extensions/manticore/core/WindowMediator.cs
@@ -2,7 +2,13 @@
namespace Silverstone.Manticore.Core
{
using System;
-
+ using System.Collections;
+
+ using Silverstone.Manticore.Toolkit;
+
+ // XXX - TODO: need to add logic to quit application when there are
+ // no more windows
+
///
/// Summary description for WindowMediator.
///
@@ -10,6 +16,8 @@ namespace Silverstone.Manticore.Core
{
public WindowMediator()
{
+ mWindows = new Hashtable();
+ mRecentWindows = new Hashtable();
}
///
@@ -18,12 +26,60 @@ namespace Silverstone.Manticore.Core
///
public IEnumerator GetEnumerator()
{
-
+ return mWindows.GetEnumerator();
}
- // ManticoreWindow GetMostRecentWindow(String aType);
- // void SetMostRecentWindow(ManticoreWindow);
- // void RegisterWindow (ManticoreWindow);
- // void UnregisterWindow (ManticoreWindow);
- }
+ public IEnumerator GetEnumeratorForType(String aType)
+ {
+ return (mWindows[aType] as Hashtable).GetEnumerator();
+ }
+
+ protected Hashtable mWindows;
+ protected Hashtable mRecentWindows;
+
+ public ManticoreWindow GetMostRecentWindow(String aType)
+ {
+ if (mRecentWindows.ContainsKey(aType))
+ return mRecentWindows[aType] as ManticoreWindow;
+ return null;
+ }
+
+ public void SetMostRecentWindow(ManticoreWindow aWindow)
+ {
+ if (!mRecentWindows.ContainsKey(aWindow.Type))
+ mRecentWindows.Add(aWindow.Type, aWindow);
+ else
+ mRecentWindows[aWindow.Type] = aWindow;
+ }
+
+ public void RegisterWindow(ManticoreWindow aWindow)
+ {
+ if (!mWindows.ContainsKey(aWindow.Type))
+ mWindows[aWindow.Type] = new Hashtable();
+ Hashtable windowList = mWindows[aWindow.Type] as Hashtable;
+ windowList.Add(aWindow.GetHashCode(), aWindow);
+ }
+
+ public void UnregisterWindow(ManticoreWindow aWindow)
+ {
+ mWindows.Remove(aWindow.GetHashCode());
+
+ // If this is the last window of a specific type, remove it from the window list
+ Hashtable windowsForType = mWindows[aWindow.Type] as Hashtable;
+ IEnumerator e = windowsForType.GetEnumerator();
+ e.MoveNext();
+ ManticoreWindow window = e.Current as ManticoreWindow;
+ if (window == null)
+ mWindows.Remove(aWindow.Type);
+
+ ManticoreWindow mostRecentWindow = GetMostRecentWindow(aWindow.Type);
+ if (mostRecentWindow == window)
+ {
+ if (window != null)
+ SetMostRecentWindow(window);
+ else
+ mRecentWindows.Remove(aWindow.Type);
+ }
+ }
+ }
}
diff --git a/extensions/manticore/toolkit/ManticoreWindow.cs b/extensions/manticore/toolkit/ManticoreWindow.cs
index af7753a5c2cc..c5718b15d17a 100644
--- a/extensions/manticore/toolkit/ManticoreWindow.cs
+++ b/extensions/manticore/toolkit/ManticoreWindow.cs
@@ -37,12 +37,14 @@ namespace Silverstone.Manticore.Toolkit
using System;
using System.Windows.Forms;
+ using Silverstone.Manticore.Core;
+
///
/// Top level window class
///
public class ManticoreWindow : Form
{
- protected internal String mType = "";
+ protected String mType = "";
public String Type
{
@@ -58,6 +60,32 @@ namespace Silverstone.Manticore.Toolkit
public ManticoreWindow(String aType)
{
mType = aType;
- }
- }
+ }
+
+ protected void Init()
+ {
+ WindowMediator wm = ServiceManager.WindowMediator;
+ wm.RegisterWindow(this);
+
+ this.Closed += new EventHandler(OnClosed);
+ this.Activated += new EventHandler(OnActivated);
+ }
+
+ public void OnClosed(Object sender, EventArgs e)
+ {
+ WindowMediator wm = ServiceManager.WindowMediator;
+ wm.UnregisterWindow(this);
+ }
+
+ public void OnActivated(Object sender, EventArgs e)
+ {
+ WindowMediator wm = ServiceManager.WindowMediator;
+ wm.SetMostRecentWindow(this);
+ }
+
+ public override void Dispose()
+ {
+ base.Dispose();
+ }
+ }
}