Click here to Skip to main content
15,892,298 members
Articles / Programming Languages / C#

The Favalias Application

Rate me:
Please Sign up or sign in to vote.
4.92/5 (27 votes)
30 Sep 20037 min read 70.8K   2.6K   52  
Favalias application enables you to manage your favorites web sites in an XML file and to launch your favorites application using aliases. You can also make your own addins (in any .NET language) to call your own code.
// Jean-Christophe Magnon
// jcmag@yahoo.com
#region Copyright � 2003 The Favalias Group
/*
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the
 * use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not claim
 * that you wrote the original software. If you use this software in a product,
 * an acknowledgment in the product documentation is required, as shown here:
 *
 * Portions Copyright � 2003 The Favalias Group (http://sourceforge.net/projects/favalias).
 *
 * 2. Altered source versions must be plainly marked as such, and must not be 
 * misrepresented as being the original software.
 * 
 * 3. This notice may not be removed or altered from any source distribution.
*/
#endregion

using Favalias.Controllers;
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Net;
using System.Reflection;
using System.Windows.Forms;

namespace Favalias.Forms
{
	/// <summary>
	/// To manage preferences.
	/// </summary>
	public class FormPreferences : System.Windows.Forms.Form
	{
		#region UI Fields
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtFavoritesFile;
		private System.Windows.Forms.Button btnBrowseFavoritesFile;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.Button btnBrowser;
		private System.Windows.Forms.TextBox txtBrowser;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.OpenFileDialog openFileDialog2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtIPProxy;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtPortProxy;
		private System.Windows.Forms.CheckBox chkProxy;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.TextBox txtAliasesFile;
		private System.Windows.Forms.Button btnBrowseAliasesFile;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.CheckBox chkAutoHide;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TrackBar hSkinnedSlider1;
		private System.Windows.Forms.CheckBox chkCtrl;
		private System.Windows.Forms.CheckBox chkAlt;
		private System.Windows.Forms.CheckBox chkShift;
		private System.Windows.Forms.CheckBox chkWin;
		private System.Windows.Forms.ComboBox cboSkin;
		private System.Windows.Forms.Label label7;
		

		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		#endregion
		
		#region Code Fields and Properties
		private static readonly log4net.ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
		private bool _cancel = false;
		private float _opacity;
		private FormFavalias _parent;
		private bool _serializeSize;
		private string _initialSkin;
		
		#endregion

		#region Constructor
		public FormPreferences(FormFavalias parent, bool serializeSize)
		{
			this._parent = parent;
			_serializeSize = serializeSize;

			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

		}
		#endregion

		#region Overrides
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormPreferences));
			this.label1 = new System.Windows.Forms.Label();
			this.txtFavoritesFile = new System.Windows.Forms.TextBox();
			this.btnBrowseFavoritesFile = new System.Windows.Forms.Button();
			this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
			this.btnSave = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.btnBrowser = new System.Windows.Forms.Button();
			this.txtBrowser = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.openFileDialog2 = new System.Windows.Forms.OpenFileDialog();
			this.chkProxy = new System.Windows.Forms.CheckBox();
			this.txtIPProxy = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.panel1 = new System.Windows.Forms.Panel();
			this.txtPortProxy = new System.Windows.Forms.TextBox();
			this.label4 = new System.Windows.Forms.Label();
			this.txtAliasesFile = new System.Windows.Forms.TextBox();
			this.btnBrowseAliasesFile = new System.Windows.Forms.Button();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.chkAutoHide = new System.Windows.Forms.CheckBox();
			this.hSkinnedSlider1 = new System.Windows.Forms.TrackBar();
			this.label8 = new System.Windows.Forms.Label();
			this.chkCtrl = new System.Windows.Forms.CheckBox();
			this.chkAlt = new System.Windows.Forms.CheckBox();
			this.chkShift = new System.Windows.Forms.CheckBox();
			this.chkWin = new System.Windows.Forms.CheckBox();
			this.cboSkin = new System.Windows.Forms.ComboBox();
			this.label7 = new System.Windows.Forms.Label();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.hSkinnedSlider1)).BeginInit();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 15);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 14);
			this.label1.TabIndex = 0;
			this.label1.Text = "Favorites file :";
			// 
			// txtFavoritesFile
			// 
			this.txtFavoritesFile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtFavoritesFile.Location = new System.Drawing.Point(88, 12);
			this.txtFavoritesFile.Name = "txtFavoritesFile";
			this.txtFavoritesFile.Size = new System.Drawing.Size(296, 20);
			this.txtFavoritesFile.TabIndex = 1;
			this.txtFavoritesFile.Text = "";
			// 
			// btnBrowseFavoritesFile
			// 
			this.btnBrowseFavoritesFile.BackColor = System.Drawing.Color.OldLace;
			this.btnBrowseFavoritesFile.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnBrowseFavoritesFile.Location = new System.Drawing.Point(392, 11);
			this.btnBrowseFavoritesFile.Name = "btnBrowseFavoritesFile";
			this.btnBrowseFavoritesFile.Size = new System.Drawing.Size(32, 23);
			this.btnBrowseFavoritesFile.TabIndex = 2;
			this.btnBrowseFavoritesFile.Text = "...";
			this.btnBrowseFavoritesFile.Click += new System.EventHandler(this.btnBrowseFavoritesFile_Click);
			// 
			// openFileDialog1
			// 
			this.openFileDialog1.CheckFileExists = false;
			this.openFileDialog1.Filter = "XML files|*.xml|All files|*.*";
			// 
			// btnSave
			// 
			this.btnSave.BackColor = System.Drawing.Color.OldLace;
			this.btnSave.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnSave.Location = new System.Drawing.Point(115, 286);
			this.btnSave.Name = "btnSave";
			this.btnSave.TabIndex = 3;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.BackColor = System.Drawing.Color.OldLace;
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnCancel.Location = new System.Drawing.Point(243, 286);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 4;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// btnBrowser
			// 
			this.btnBrowser.BackColor = System.Drawing.Color.OldLace;
			this.btnBrowser.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnBrowser.Location = new System.Drawing.Point(392, 80);
			this.btnBrowser.Name = "btnBrowser";
			this.btnBrowser.Size = new System.Drawing.Size(32, 23);
			this.btnBrowser.TabIndex = 7;
			this.btnBrowser.Text = "...";
			this.btnBrowser.Click += new System.EventHandler(this.btnBrowser_Click);
			// 
			// txtBrowser
			// 
			this.txtBrowser.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtBrowser.Location = new System.Drawing.Point(88, 81);
			this.txtBrowser.Name = "txtBrowser";
			this.txtBrowser.Size = new System.Drawing.Size(296, 20);
			this.txtBrowser.TabIndex = 6;
			this.txtBrowser.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 83);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 16);
			this.label2.TabIndex = 5;
			this.label2.Text = "Browser :";
			// 
			// openFileDialog2
			// 
			this.openFileDialog2.Filter = "All files|*.*";
			// 
			// chkProxy
			// 
			this.chkProxy.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.chkProxy.Location = new System.Drawing.Point(8, 116);
			this.chkProxy.Name = "chkProxy";
			this.chkProxy.Size = new System.Drawing.Size(72, 24);
			this.chkProxy.TabIndex = 8;
			this.chkProxy.Text = "Proxy";
			this.chkProxy.CheckedChanged += new System.EventHandler(this.chkProxy_CheckedChanged);
			// 
			// txtIPProxy
			// 
			this.txtIPProxy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtIPProxy.Location = new System.Drawing.Point(48, 6);
			this.txtIPProxy.Name = "txtIPProxy";
			this.txtIPProxy.Size = new System.Drawing.Size(112, 20);
			this.txtIPProxy.TabIndex = 9;
			this.txtIPProxy.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 10);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(40, 12);
			this.label3.TabIndex = 10;
			this.label3.Text = "IP :";
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.txtPortProxy);
			this.panel1.Controls.Add(this.label4);
			this.panel1.Controls.Add(this.txtIPProxy);
			this.panel1.Controls.Add(this.label3);
			this.panel1.Enabled = false;
			this.panel1.Location = new System.Drawing.Point(88, 112);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(256, 32);
			this.panel1.TabIndex = 11;
			// 
			// txtPortProxy
			// 
			this.txtPortProxy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtPortProxy.Location = new System.Drawing.Point(208, 6);
			this.txtPortProxy.Name = "txtPortProxy";
			this.txtPortProxy.Size = new System.Drawing.Size(40, 20);
			this.txtPortProxy.TabIndex = 11;
			this.txtPortProxy.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(176, 10);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(40, 12);
			this.label4.TabIndex = 12;
			this.label4.Text = "Port :";
			// 
			// txtAliasesFile
			// 
			this.txtAliasesFile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtAliasesFile.Location = new System.Drawing.Point(88, 47);
			this.txtAliasesFile.Name = "txtAliasesFile";
			this.txtAliasesFile.Size = new System.Drawing.Size(296, 20);
			this.txtAliasesFile.TabIndex = 13;
			this.txtAliasesFile.Text = "";
			// 
			// btnBrowseAliasesFile
			// 
			this.btnBrowseAliasesFile.BackColor = System.Drawing.Color.OldLace;
			this.btnBrowseAliasesFile.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btnBrowseAliasesFile.Location = new System.Drawing.Point(392, 46);
			this.btnBrowseAliasesFile.Name = "btnBrowseAliasesFile";
			this.btnBrowseAliasesFile.Size = new System.Drawing.Size(32, 23);
			this.btnBrowseAliasesFile.TabIndex = 14;
			this.btnBrowseAliasesFile.Text = "...";
			this.btnBrowseAliasesFile.Click += new System.EventHandler(this.btnBrowseAliasesFile_Click);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 49);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 16);
			this.label5.TabIndex = 12;
			this.label5.Text = "Aliases file :";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(8, 162);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(80, 16);
			this.label6.TabIndex = 15;
			this.label6.Text = "Shortcut key :";
			// 
			// comboBox1
			// 
			this.comboBox1.Items.AddRange(new object[] {
														   "A",
														   "B",
														   "C",
														   "D",
														   "E",
														   "F",
														   "G",
														   "H",
														   "I",
														   "J",
														   "K",
														   "L",
														   "M",
														   "N",
														   "O",
														   "P",
														   "Q",
														   "R",
														   "S",
														   "T",
														   "U",
														   "V",
														   "W",
														   "X",
														   "Y",
														   "Z",
														   "0",
														   "1",
														   "2",
														   "3",
														   "4",
														   "5",
														   "6",
														   "7",
														   "8",
														   "9",
														   "F1",
														   "F2",
														   "F3",
														   "F4",
														   "F5",
														   "F6",
														   "F7",
														   "F8",
														   "F9",
														   "F10",
														   "F11",
														   "F12"});
			this.comboBox1.Location = new System.Drawing.Point(312, 160);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(72, 21);
			this.comboBox1.TabIndex = 17;
			// 
			// chkAutoHide
			// 
			this.chkAutoHide.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.chkAutoHide.Location = new System.Drawing.Point(8, 192);
			this.chkAutoHide.Name = "chkAutoHide";
			this.chkAutoHide.Size = new System.Drawing.Size(344, 24);
			this.chkAutoHide.TabIndex = 8;
			this.chkAutoHide.Text = "Hide the application as soon as a command is launched";
			// 
			// hSkinnedSlider1
			// 
			this.hSkinnedSlider1.AutoSize = false;
			this.hSkinnedSlider1.Location = new System.Drawing.Point(88, 256);
			this.hSkinnedSlider1.Maximum = 90;
			this.hSkinnedSlider1.Minimum = 10;
			this.hSkinnedSlider1.Name = "hSkinnedSlider1";
			this.hSkinnedSlider1.Size = new System.Drawing.Size(296, 24);
			this.hSkinnedSlider1.TabIndex = 18;
			this.hSkinnedSlider1.Text = "hSkinnedSlider1";
			this.hSkinnedSlider1.TickStyle = System.Windows.Forms.TickStyle.None;
			this.hSkinnedSlider1.Value = 10;
			this.hSkinnedSlider1.ValueChanged += new System.EventHandler(this.hSkinnedSlider1_ValueChange);
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(8, 256);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(80, 16);
			this.label8.TabIndex = 19;
			this.label8.Text = "Opacity :";
			// 
			// chkCtrl
			// 
			this.chkCtrl.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.chkCtrl.Location = new System.Drawing.Point(88, 158);
			this.chkCtrl.Name = "chkCtrl";
			this.chkCtrl.Size = new System.Drawing.Size(48, 24);
			this.chkCtrl.TabIndex = 20;
			this.chkCtrl.Text = "Ctrl +";
			// 
			// chkAlt
			// 
			this.chkAlt.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.chkAlt.Location = new System.Drawing.Point(147, 158);
			this.chkAlt.Name = "chkAlt";
			this.chkAlt.Size = new System.Drawing.Size(48, 24);
			this.chkAlt.TabIndex = 21;
			this.chkAlt.Text = "Alt +";
			// 
			// chkShift
			// 
			this.chkShift.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.chkShift.Location = new System.Drawing.Point(200, 158);
			this.chkShift.Name = "chkShift";
			this.chkShift.Size = new System.Drawing.Size(56, 24);
			this.chkShift.TabIndex = 22;
			this.chkShift.Text = "Shift +";
			// 
			// chkWin
			// 
			this.chkWin.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.chkWin.Location = new System.Drawing.Point(256, 158);
			this.chkWin.Name = "chkWin";
			this.chkWin.Size = new System.Drawing.Size(56, 24);
			this.chkWin.TabIndex = 23;
			this.chkWin.Text = "Win +";
			// 
			// cboSkin
			// 
			this.cboSkin.Items.AddRange(new object[] {
														 "Classic",
														 "Matrix"});
			this.cboSkin.Location = new System.Drawing.Point(88, 228);
			this.cboSkin.Name = "cboSkin";
			this.cboSkin.Size = new System.Drawing.Size(112, 21);
			this.cboSkin.TabIndex = 27;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(8, 228);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(80, 16);
			this.label7.TabIndex = 26;
			this.label7.Text = "Skin :";
			// 
			// FormPreferences
			// 
			this.AcceptButton = this.btnSave;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.Color.Gainsboro;
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(434, 314);
			this.Controls.Add(this.cboSkin);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.chkWin);
			this.Controls.Add(this.chkShift);
			this.Controls.Add(this.chkAlt);
			this.Controls.Add(this.chkCtrl);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.hSkinnedSlider1);
			this.Controls.Add(this.txtAliasesFile);
			this.Controls.Add(this.txtBrowser);
			this.Controls.Add(this.txtFavoritesFile);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.btnBrowseAliasesFile);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.btnBrowser);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.btnBrowseFavoritesFile);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.chkProxy);
			this.Controls.Add(this.chkAutoHide);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "FormPreferences";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Preferences";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.FormPreferences_Closing);
			this.Load += new System.EventHandler(this.FormPreferences_Load);
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.hSkinnedSlider1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		#region Controls Event Handlers
		private void btnBrowseFavoritesFile_Click(object sender, System.EventArgs e)
		{
			openFileDialog1.ShowDialog(this);
			string fileName = openFileDialog1.FileName;
			if(fileName.Length != 0)
			{
				txtFavoritesFile.Text = fileName;
			}
			openFileDialog1.Dispose();
		}

		private void btnBrowser_Click(object sender, System.EventArgs e)
		{
			openFileDialog2.ShowDialog(this);
			string browserName = openFileDialog2.FileName;
			if(browserName != "")
			{
				txtBrowser.Text = browserName;
			}
			openFileDialog2.Dispose();
		}

		private void btnBrowseAliasesFile_Click(object sender, System.EventArgs e)
		{
			openFileDialog1.ShowDialog(this);
			string fileName = openFileDialog1.FileName;
			if(fileName.Length != 0)
			{
				txtAliasesFile.Text = fileName;
			}
			openFileDialog1.Dispose();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			_cancel = true;
			this.Close();
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			Keys mod = Keys.None;
			if(chkAlt.Checked)		mod |= Keys.Alt;
			if(chkCtrl.Checked)		mod |= Keys.Control;
			if(chkShift.Checked)	mod |= Keys.Shift;
			if(chkWin.Checked)		mod |= Keys.LWin;
			Keys key = (Keys)(Enum.Parse(typeof(Keys), comboBox1.SelectedItem.ToString()));
			if(FavaliasController.changeShortcutKey(mod, key))
			{			
				FavaliasController.userPref.shortcutMod = mod;
				FavaliasController.userPref.shortcutKey = key;
				FavaliasController.userPref.favoritesFile = txtFavoritesFile.Text;
				FavaliasController.userPref.browser = txtBrowser.Text;
				FavaliasController.userPref.aliasesFile = txtAliasesFile.Text;
				FavaliasController.userPref.autoHide = chkAutoHide.Checked;
				FavaliasController.userPref.opacityDegree = _opacity;
				FavaliasController.userPref.skin = cboSkin.SelectedItem.ToString();
				
				FavaliasController.SavePreferences(_serializeSize);
				if(cboSkin.SelectedItem.ToString() != _initialSkin)
					MessageBox.Show("You must restart Favalias to load the skin", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
				this.Close();
			}
			else
				MessageBox.Show("This shortcut could not be used.\r\nChoose another one.", "Shortcut error", MessageBoxButtons.OK, MessageBoxIcon.Error);
		}

		private void chkProxy_CheckedChanged(object sender, System.EventArgs e)
		{
			if(chkProxy.Checked)
				panel1.Enabled = true;
			else
				panel1.Enabled = false;
		}

		private void hSkinnedSlider1_ValueChange(object sender, System.EventArgs e)
		{
			_opacity = hSkinnedSlider1.Value / 100F;
			if(_parent.menuTransparent.Checked)
				_parent.Opacity = _opacity;
		}

		#endregion

		#region Form Event Handlers
		private void FormPreferences_Load(object sender, System.EventArgs e)
		{
			hSkinnedSlider1.Value = (int)(FavaliasController.userPref.opacityDegree * 100);
			txtFavoritesFile.Text = FavaliasController.userPref.favoritesFile;
			txtAliasesFile.Text = FavaliasController.userPref.aliasesFile;
			txtBrowser.Text = FavaliasController.userPref.browser;
			txtIPProxy.Text = FavaliasController.userPref.proxyIP;
			txtPortProxy.Text = FavaliasController.userPref.proxyPort.ToString();
			if(FavaliasController.userPref.proxyIP != null && FavaliasController.userPref.proxyIP.Length != 0)
			{
				chkProxy.Checked = true;
				panel1.Enabled = true;
			}
			else
			{
				chkProxy.Checked = false;
				panel1.Enabled = false;
			}
			this.comboBox1.SelectedItem = FavaliasController.userPref.shortcutKey.ToString();
			if((FavaliasController.userPref.shortcutMod & Keys.Alt) == Keys.Alt)
				chkAlt.Checked = true;
			if((FavaliasController.userPref.shortcutMod & Keys.Shift) == Keys.Shift)
				chkShift.Checked = true;
			if((FavaliasController.userPref.shortcutMod & Keys.Control) == Keys.Control)
				chkCtrl.Checked = true;
			if((FavaliasController.userPref.shortcutMod & Keys.LWin) == Keys.LWin)
				chkWin.Checked = true;

			this.chkAutoHide.Checked = FavaliasController.userPref.autoHide;

			if(FavaliasController.userPref.skin != null && FavaliasController.userPref.skin.Length != 0)
				cboSkin.SelectedItem = FavaliasController.userPref.skin.ToString();
			else
				cboSkin.SelectedIndex = 0;
			_initialSkin = cboSkin.SelectedItem.ToString();
		}

		private void FormPreferences_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if(_cancel == false)
			{
				if(chkProxy.Checked)
				{
					try
					{
						GlobalProxySelection.Select = new WebProxy(Dns.Resolve(txtIPProxy.Text).HostName, Convert.ToInt32(txtPortProxy.Text));
						FavaliasController.userPref.proxyIP = txtIPProxy.Text;
						FavaliasController.userPref.proxyPort = Convert.ToInt32(txtPortProxy.Text);
					}
					catch(Exception exc)
					{
						MessageBox.Show("Invalid proxy : " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
						e.Cancel = true;
						if(log.IsErrorEnabled) log.Error(System.Reflection.MethodBase.GetCurrentMethod().Name, exc);
					}
				}
				else
				{
					FavaliasController.userPref.proxyIP = "";
					FavaliasController.userPref.proxyPort = 0;
				}
			}
		}
		#endregion

		

		

		

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
France France
I am an MCSD.NET and MCT. I give a lot of Microsoft Trainings (www.bdcworld.com) in France.

Comments and Discussions