Implement Window Mediator service
NOT PART OF BUILD
This commit is contained in:
Родитель
3f0b596d78
Коммит
4d95fe9694
|
@ -242,6 +242,11 @@
|
|||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "core\WindowMediator.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "defaults\bookmarks.xml"
|
||||
BuildAction = "Content"
|
||||
|
|
|
@ -45,29 +45,10 @@ namespace Silverstone.Manticore.App
|
|||
|
||||
public class ManticoreApp
|
||||
{
|
||||
// XXX Need to do something here more similar
|
||||
// to what mozilla does here for parameterized
|
||||
// window types.
|
||||
private Hashtable mBrowserWindows;
|
||||
private static BrowserWindow mMostRecentBrowserWindow = null;
|
||||
public static BrowserWindow MostRecentBrowserWindow
|
||||
{
|
||||
get
|
||||
{
|
||||
return mMostRecentBrowserWindow;
|
||||
}
|
||||
set
|
||||
{
|
||||
mMostRecentBrowserWindow = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ManticoreApp()
|
||||
{
|
||||
mBrowserWindows = new Hashtable();
|
||||
|
||||
if (!RestoreSession())
|
||||
OpenBrowser();
|
||||
BrowserWindow.OpenBrowser();
|
||||
|
||||
Application.Run();
|
||||
}
|
||||
|
@ -91,8 +72,8 @@ namespace Silverstone.Manticore.App
|
|||
{
|
||||
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();
|
||||
WindowMediator wm = ServiceManager.WindowMediator;
|
||||
IEnumerator browsers = wm.GetEnumeratorForType("BrowserWindow");
|
||||
int count = 0;
|
||||
while (browsers.MoveNext()) {
|
||||
if (isLastPageOnly && count > 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
/// 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;
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <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
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
/// <summary>
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
|||
/// </summary>
|
||||
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();
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
namespace Silverstone.Manticore.Core
|
||||
{
|
||||
using Silverstone.Manticore.App;
|
||||
|
||||
/// <summary>
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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>
|
||||
/// Summary description for WindowMediator.
|
||||
/// </summary>
|
||||
|
@ -10,6 +16,8 @@ namespace Silverstone.Manticore.Core
|
|||
{
|
||||
public WindowMediator()
|
||||
{
|
||||
mWindows = new Hashtable();
|
||||
mRecentWindows = new Hashtable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -18,12 +26,60 @@ namespace Silverstone.Manticore.Core
|
|||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,12 +37,14 @@ namespace Silverstone.Manticore.Toolkit
|
|||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using Silverstone.Manticore.Core;
|
||||
|
||||
/// <summary>
|
||||
/// Top level window class
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче