using System;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using System.ComponentModel;
namespace IReaper.Browser{
static class BrowserManager
{
static List<iReaperBrowserForm> browserList = new List<iReaperBrowserForm>();
/// <summary>
/// Tab
/// </summary>
/// <param name="url"></param>
public static void OpenWebsiteInNewTab(Uri url)
{
iReaperBrowserForm browser = new iReaperBrowserForm();
browser.Show();
browser.Url = url;
}
/// <summary>
/// Tab
/// </summary>
/// <param name="url"></param>
public static void OpenWebsiteInternal(Uri url)
{
if (browserList.Count == 0)
{ OpenWebsiteInNewTab(url); }
else
{
iReaperBrowserForm browser = Core.CoreData[CoreDataType.ActiveWebBrowser] as iReaperBrowserForm;
browser.Show();
browser.Url = url;
}
}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
public static void OpenWebsite(string url)
{
Uri uri;
if (Uri.TryCreate(url, UriKind.Absolute, out uri))
{ OpenWebsite(uri); }
}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
private static void OpenWebsiteInternally(Uri url)
{
bool useInternal = Properties.Settings.Default.UseInternalWebBrowser;
if (useInternal)//
{ OpenWebsiteInternal(url); }
else
{ OpenWebsiteExternal(url); }
}
public static void OpenWebsite(Uri uri)
{
if (SynchronizationContext.Current is System.Windows.Forms.WindowsFormsSynchronizationContext)
{
OpenWebsiteInternally(uri);
}
else
{
FileData.CourseFileData.async.Post(new SendOrPostCallback(delegate(object obj)
{
OpenWebsiteInternally(uri);
}), null);
}
}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
public static void OpenWebsiteExternal(Uri url)
{
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(delegate(object obj)
{
System.Diagnostics.Process.Start(url.AbsoluteUri);
}));
}
/// <summary>
///
/// </summary>
/// <param name="Browser"></param>
public static void RegisterBrowser(iReaperBrowserForm Browser)
{
browserList.Add(Browser);
Browser.Disposed += new EventHandler(OnBrowserDispose);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private static void OnBrowserDispose(object sender, EventArgs e)
{
iReaperBrowserForm browser = sender as iReaperBrowserForm;
if (browser == null)
{ return; }
//
browserList.Remove(browser);
//
if (browserList.Count > 0 && sender == Core.CoreData[CoreDataType.ActiveWebBrowser])
{
Core.CoreData[CoreDataType.ActiveWebBrowser] = browserList[0];
}
}
}
}
|