Expand|Select|Wrap|Line Numbers
- #region Using directives
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Security.Policy;
- using System.Text;
- using System.Xml;
- using System.Xml.Serialization;
- using System.IO;
- #endregion
- namespace MyOwnTabbedBrowser
- {
- public partial class BrowserExplorer : Form
- {
- int current_tab_count = 0;
- private string theURL = String.Empty;
- ArrayList tabpages = new ArrayList();
- ArrayList webpages = new ArrayList();
- private Favourite theFavourites = new Favourite();
- public BrowserExplorer()
- {
- InitializeComponent();
- tabControl1.TabPages.Clear();
- Create_a_new_tab();
- WebBrowser webpage = GetCurrentWebBrowser();
- webpage.GoHome();
- WebBrowser thiswebpage = GetCurrentWebBrowser();
- }
- public string TheURL
- {
- get
- {
- return comboBoxurl.Text;
- }
- set
- {
- this.theURL = value;
- }
- }
- private void BrowserExplorer_FormClosing(object sender, FormClosingEventArgs e)
- {
- this.theFavourites.DoSaveFavourites();
- }
- public void BrowserExplorer_Load(object sender, EventArgs e)
- {
- this.tsBack.Enabled = false;
- this.tsbForward.Enabled = false;
- this.theFavourites = Favourite.DoLoadFavourites();
- foreach (Favourite currentItem in this.theFavourites.TheFavouritesCollection)
- {
- this.theFavouriteMenuToolStripItem.DropDown.Items.Add(currentItem.TheDisplayName);
- this.theFavouriteMenuToolStripItem.DropDown.Items[this.theFavouriteMenuToolStripItem.DropDown.Items.Count - 1].ToolTipText = currentItem.TheURL;
- }
- }
- private void addNewFavouriteToolStripMenuItem_Click(object sender, EventArgs e)
- {
- WebBrowser thiswebpage = GetCurrentWebBrowser();
- MessageBox.Show("About to add favourite, change the displaname and theUrl in code:");
- Favourite theNewFavourite = new Favourite((thiswebpage.Document.Title), (TheURL));
- theNewFavourite.DoAddFavourite(theNewFavourite);
- this.theFavouriteMenuToolStripItem.DropDown.Items.Add(theURL);
- this.theFavouriteMenuToolStripItem.DropDown.Items[this.theFavouriteMenuToolStripItem.DropDown.Items.Count - 1].ToolTipText = theNewFavourite.TheURL;
- this.theFavouriteMenuToolStripItem.DropDown.Items[this.theFavouriteMenuToolStripItem.DropDown.Items.Count - 1].Text = theNewFavourite.TheDisplayName;
- this.theFavouriteMenuToolStripItem.DropDown.ItemClicked += new ToolStripItemClickedEventHandler(DropDown_ItemClicked);
- }
- void DropDown_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- WebBrowser thiswebpage = GetCurrentWebBrowser();
- thiswebpage.Navigate(e.ClickedItem.ToolTipText);
- }
- private void theFavouriteMenuToolStripItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- WebBrowser thiswebpage = GetCurrentWebBrowser();
- //thiswebpage.Navigate(TheURL);
- }
- public class Favourite
- {
- //****************** String Declaration **********************//
- private string theDisplayName = string.Empty;
- private string theURL = string.Empty;
- private List<Favourite> theFavourites = new List<Favourite>();
- //****************** String Definition ***********************//
- public List<Favourite> TheFavouritesCollection
- {
- get
- {
- return this.theFavourites;
- }
- }
- public string TheDisplayName
- {
- get
- {
- return theDisplayName;
- }
- set
- {
- theDisplayName = value;
- }
- }
- public string TheURL
- {
- get
- {
- return this.theURL;
- }
- set
- {
- this.theURL = value;
- }
- }
- public Favourite() { }
- public Favourite(string displayName, string url)
- {
- theDisplayName = displayName;
- theURL = url;
- }
- public int CompareTo(Favourite fav)
- {
- return TheDisplayName.CompareTo(TheDisplayName);
- }
- //**************Favourite Add/Load/Save Functions ****************//
- public void DoAddFavourite(Favourite theFavToAdd)
- {
- this.theFavourites.Add(theFavToAdd);
- }
- public static Favourite DoLoadFavourites()
- {
- if (System.IO.File.Exists(System.Windows.Forms.Application.StartupPath + "\\favourites.xml"))
- {
- //deserialize Type[] theTypes = new Type[1];
- Type[] theTypes = new Type[1];
- theTypes[0] = typeof(List<Favourite>);
- XmlSerializer theSerializer = new XmlSerializer(typeof(Favourite), theTypes);
- System.IO.StreamReader theReader = new System.IO.StreamReader(System.Windows.Forms.Application.StartupPath + "\\favourites.xml");
- Favourite theFavourites = (Favourite)theSerializer.Deserialize(theReader);
- theReader.Close();
- return theFavourites;
- }
- else
- {
- return new Favourite();
- }
- }
- public void DoSaveFavourites()
- {
- //serialize Type[] theTypes = new Type[1];
- Type[] theTypes = new Type[1];
- theTypes[0] = typeof(List<Favourite>);
- XmlSerializer theSerializer = new XmlSerializer(typeof(Favourite), theTypes);
- System.IO.StreamWriter theWriter = new System.IO.StreamWriter(System.Windows.Forms.Application.StartupPath + "\\favourites.xml");
- theSerializer.Serialize(theWriter, this);
- theWriter.Close();
- }
- internal void Add(Favourite theFavToAdd)
- {
- throw new Exception("The method or operation is not implemented.");
- }
- }
- }