2001-07-03 10:17:09 +04:00
|
|
|
/* -*- Mode: C#; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2001-08-01 07:49:21 +04:00
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* 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/
|
|
|
|
*
|
2001-07-03 10:17:09 +04:00
|
|
|
* 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
|
2004-04-19 02:14:17 +04:00
|
|
|
* License.
|
2001-07-03 10:17:09 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Manticore.
|
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Silverstone Interactive.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-07-03 10:17:09 +04:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2004-04-19 02:14:17 +04:00
|
|
|
* Ben Goodger <ben@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-07-03 10:17:09 +04:00
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-06-27 03:58:39 +04:00
|
|
|
|
|
|
|
namespace Silverstone.Manticore.App
|
|
|
|
{
|
|
|
|
using System;
|
|
|
|
using System.ComponentModel;
|
2001-07-03 10:14:01 +04:00
|
|
|
using System.Drawing;
|
2001-06-27 03:58:39 +04:00
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.Collections;
|
|
|
|
|
2001-06-30 05:11:21 +04:00
|
|
|
using Silverstone.Manticore.Browser;
|
|
|
|
using Silverstone.Manticore.Core;
|
2001-08-01 07:48:08 +04:00
|
|
|
|
2001-06-27 03:58:39 +04:00
|
|
|
public class ManticoreApp
|
|
|
|
{
|
|
|
|
public ManticoreApp()
|
|
|
|
{
|
2001-07-03 10:14:01 +04:00
|
|
|
if (!RestoreSession())
|
2001-11-18 07:50:25 +03:00
|
|
|
BrowserWindow.OpenBrowser();
|
2001-06-27 03:58:39 +04:00
|
|
|
|
|
|
|
Application.Run();
|
|
|
|
}
|
|
|
|
|
2001-06-30 10:31:59 +04:00
|
|
|
public void Quit()
|
2001-06-30 05:11:21 +04:00
|
|
|
{
|
2001-07-03 10:14:01 +04:00
|
|
|
// Save Session
|
|
|
|
SaveSession();
|
|
|
|
|
2001-06-30 05:11:21 +04:00
|
|
|
// Flush preferences to disk.
|
2001-08-01 07:48:08 +04:00
|
|
|
ServiceManager.Preferences.FlushUserPreferences();
|
2001-06-30 10:31:59 +04:00
|
|
|
|
|
|
|
Application.Exit();
|
|
|
|
}
|
|
|
|
|
2001-07-03 10:14:01 +04:00
|
|
|
/// <summary>
|
|
|
|
/// Saves the state of opened windows, urls, etc to preferences
|
|
|
|
/// so that state can be restored when the app is restarted.
|
|
|
|
/// </summary>
|
|
|
|
private void SaveSession()
|
|
|
|
{
|
2001-08-01 07:48:08 +04:00
|
|
|
if (ServiceManager.Preferences.GetIntPref("browser.homepage.mode") == 2) {
|
|
|
|
bool isLastPageOnly = ServiceManager.Preferences.GetIntPref("browser.session.windowmode") == 0;
|
2001-11-18 07:50:25 +03:00
|
|
|
WindowMediator wm = ServiceManager.WindowMediator;
|
|
|
|
IEnumerator browsers = wm.GetEnumeratorForType("BrowserWindow");
|
2001-07-03 10:14:01 +04:00
|
|
|
int count = 0;
|
|
|
|
while (browsers.MoveNext()) {
|
|
|
|
if (isLastPageOnly && count > 0) {
|
|
|
|
// XXX need to |getMostRecentWindow| instead of just taking the first.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserWindow currWindow = browsers.Current as BrowserWindow;
|
|
|
|
String pref = "browser.session.windows.";
|
|
|
|
pref += currWindow.Type + count++;
|
2001-08-01 07:48:08 +04:00
|
|
|
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);
|
2001-07-03 10:14:01 +04:00
|
|
|
}
|
|
|
|
// XXX need to save session histories.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Restore Session from preferences if "Restore Session" pref is set.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>Whether or not a session was restored.</returns>
|
|
|
|
private bool RestoreSession()
|
|
|
|
{
|
2001-08-01 07:48:08 +04:00
|
|
|
if (ServiceManager.Preferences.GetIntPref("browser.homepage.mode") == 2) {
|
|
|
|
IEnumerator branch = ServiceManager.Preferences.GetBranch("browser.session.windows");
|
2001-07-03 10:14:01 +04:00
|
|
|
while (branch.MoveNext()) {
|
|
|
|
String pref = branch.Current as String;
|
2001-08-01 07:48:08 +04:00
|
|
|
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");
|
2001-07-03 10:14:01 +04:00
|
|
|
|
|
|
|
// Create a new browser with the applicable url at the applicable
|
|
|
|
// location.
|
2001-11-18 07:50:25 +03:00
|
|
|
BrowserWindow window = BrowserWindow.OpenBrowserWithURL(url);
|
2001-07-03 10:14:01 +04:00
|
|
|
window.Location = new Point(x, y);
|
|
|
|
window.Size = new Size(width, height);
|
|
|
|
}
|
|
|
|
// XXX need to reinit session histories.
|
2001-08-01 07:48:08 +04:00
|
|
|
ServiceManager.Preferences.RemoveBranch("browser.session.windows");
|
2001-07-03 10:14:01 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-07-03 02:54:41 +04:00
|
|
|
[STAThread]
|
2001-06-27 03:58:39 +04:00
|
|
|
public static void Main(string[] args)
|
|
|
|
{
|
2001-11-18 07:50:25 +03:00
|
|
|
ServiceManager.mApp = new ManticoreApp();
|
2001-06-27 03:58:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|