/// <summary>
		/// Initializes this instance.
		/// </summary>
		protected override void Initialize()
		{
			base.Initialize();

			this.CommitChanges += new CommitChangesEventHandler(PluginOptionsPage_CommitChanges);
			this.RestoreDefaults += new RestoreDefaultsEventHandler(PluginOptionsPage_RestoreDefaults);
			this.Options = OptionSet.Load(Storage);
			this.SyncOptionsToForm(this.Options);
		}
		/// <summary>
		/// Loads the options from storage.
		/// </summary>
		/// <param name="storage">A storage object from which options should be loaded.</param>
		/// <returns>
		/// A populated <see cref="DX_FormatOnSave.OptionSet"/> from the storage.
		/// </returns>
		/// <exception cref="System.ArgumentNullException">
		/// Thrown if <paramref name="storage" /> is <see langword="null" />.
		/// </exception>
		public static OptionSet Load(DecoupledStorage storage)
		{
			if (storage == null)
			{
				throw new ArgumentNullException("storage");
			}
			Log.SendMsg("Loading 'format on save' options.");
			OptionSet options = new OptionSet();
			OptionSet defaults = new OptionSet();
			options.Enabled = storage.ReadBoolean(SectionGeneral, KeyEnabled, defaults.Enabled);
			Log.SendBool("Enabled", options.Enabled);
			options.LanguagesToFormat = storage.ReadEnum<DocumentLanguages>(SectionGeneral, KeyLanguagesToFormat, defaults.LanguagesToFormat);
			Log.SendEnum("Languages to format", options.LanguagesToFormat);
			return options;
		}
		/// <summary>
		/// Gets the options out of the form and turns them into an option set.
		/// </summary>
		/// <returns>
		/// An <see cref="DX_FormatOnSave.OptionSet"/> with the options as seen
		/// in the form.
		/// </returns>
		public OptionSet SyncOptionsFromForm()
		{
			OptionSet options = new OptionSet();
			options.Enabled = this.chkEnabled.Checked;
			options.LanguagesToFormat = DocumentLanguages.None;
			if (this.chkCPlusPlus.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.CPlusPlus;
			}
			if (this.chkCSharp.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.CSharp;
			}
			if (this.chkCss.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.Css;
			}
			if (this.chkHtml.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.Html;
			}
			if (this.chkJavaScript.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.JavaScript;
			}
			if (this.chkVisualBasic.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.VisualBasic;
			}
			if (this.chkXaml.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.Xaml;
			}
			if (this.chkXml.Checked)
			{
				options.LanguagesToFormat |= DocumentLanguages.Xml;
			}
			return options;
		}
		/// <summary>
		/// Refreshes the set of options being used by this plugin.
		/// </summary>
		public void RefreshOptions()
		{
			this.Options = OptionSet.Load(PluginOptionsPage.Storage);
		}
		void PluginOptionsPage_CommitChanges(object sender, CommitChangesEventArgs ea)
		{
			this.Options = this.SyncOptionsFromForm();
			this.Options.Save(Storage);
		}
		void PluginOptionsPage_RestoreDefaults(object sender, OptionsPageEventArgs ea)
		{
			OptionSet defaults = new OptionSet();
			this.SyncOptionsToForm(defaults);
			this.Options = defaults;
		}
		/// <summary>
		/// Synchronizes the options into the form. The form will display what the options contain.
		/// </summary>
		/// <param name="optionSet">The options to display.</param>
		public void SyncOptionsToForm(OptionSet optionSet)
		{
			if (optionSet == null)
			{
				throw new ArgumentNullException("optionSet");
			}
			this.chkEnabled.Checked = optionSet.Enabled;
			this.chkCPlusPlus.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.CPlusPlus) == DocumentLanguages.CPlusPlus;
			this.chkCSharp.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.CSharp) == DocumentLanguages.CSharp;
			this.chkCss.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.Css) == DocumentLanguages.Css;
			this.chkHtml.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.Html) == DocumentLanguages.Html;
			this.chkJavaScript.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.JavaScript) == DocumentLanguages.JavaScript;
			this.chkVisualBasic.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.VisualBasic) == DocumentLanguages.VisualBasic;
			this.chkXaml.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.Xaml) == DocumentLanguages.Xaml;
			this.chkXml.Checked = (optionSet.LanguagesToFormat & DocumentLanguages.Xml) == DocumentLanguages.Xml;
		}
Beispiel #8
0
 /// <summary>
 /// Refreshes the set of options being used by this plugin.
 /// </summary>
 public void RefreshOptions()
 {
     this.Options = OptionSet.Load(PluginOptionsPage.Storage);
 }