Beispiel #1
0
        /// <summary>
        /// Save changes to the configuration
        /// </summary>
        /// <param name="configurationFile">The configuration filename</param>
        public void SaveConfiguration(string configurationFile)
        {
            configFile.Filename = configurationFile;

            this.SetTitle();

            foreach (TreeViewItem item in tvPages.Items)
            {
                ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;

                if (page.AppliesTo(configFile.ConfigurationType))
                {
                    page.SaveConfiguration(configFile);
                }
            }

            if (configFile.Save())
            {
                if (configFile.ConfigurationType == ConfigurationType.Global)
                {
                    if (configFile.ToBoolean(PropertyNames.EnableWpfTextBoxSpellChecking))
                    {
                        VSSpellCheckEverywherePackage.Instance.ConnectSpellChecker();
                    }

                    WpfTextBox.WpfTextBoxSpellChecker.ClearCache();
                }
            }
            else
            {
                MessageBox.Show("Unable to save spell checking configuration", PackageResources.PackageTitle,
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
        /// <summary>
        /// Prevent the user from changing the selected tree view item if the page is not valid
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void tvPages_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            TreeViewItem item = (TreeViewItem)tvPages.SelectedItem;

            if (item != null)
            {
                ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;

                e.Handled = !page.IsValid;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reset the configuration for the current page or the whole file to the default settings excluding the
        /// user dictionary.
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnReset_Click(object sender, RoutedEventArgs e)
        {
            var result = MessageBox.Show("Do you want to reset the entire configuration or just this page?  " +
                                         "Click YES to reset the whole configuration, NO to reset just this page, or CANCEL to do neither.",
                                         PackageResources.PackageTitle, MessageBoxButton.YesNoCancel, MessageBoxImage.Question,
                                         MessageBoxResult.Cancel);

            if (result == MessageBoxResult.Cancel)
            {
                return;
            }

            // Pass a dummy filename to create a new configuration and then set the filename so that the pages
            // know the type of configuration file in use.
            var newConfigFile = new SpellingConfigurationFile("__ResetTemp__", new SpellCheckerConfiguration())
            {
                Filename = configFile.Filename
            };

            if (result == MessageBoxResult.Yes)
            {
                if (MessageBox.Show("Are you sure you want to reset the configuration to its default settings " +
                                    "(excluding the user dictionary)?", PackageResources.PackageTitle, MessageBoxButton.YesNo,
                                    MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
                {
                    foreach (TreeViewItem item in tvPages.Items)
                    {
                        ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;

                        if (page.AppliesTo(configFile.ConfigurationType))
                        {
                            page.LoadConfiguration(newConfigFile);
                        }
                    }

                    this.OnConfigurationChanged(sender, e);
                }
            }
            else
            {
                TreeViewItem item = (TreeViewItem)tvPages.SelectedItem;

                if (item != null)
                {
                    ((ISpellCheckerConfiguration)item.Tag).LoadConfiguration(newConfigFile);
                    this.OnConfigurationChanged(sender, e);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Change the displayed property page based on the selected tree view item
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void tvPages_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            foreach (TreeViewItem item in tvPages.Items)
            {
                ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;

                if (item.IsSelected)
                {
                    page.Control.Visibility = Visibility.Visible;
                }
                else
                {
                    page.Control.Visibility = Visibility.Collapsed;
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Save changes to the configuration
        /// </summary>
        /// <param name="configurationFile">The configuration filename</param>
        public void SaveConfiguration(string configurationFile)
        {
            configFile.Filename = configurationFile;

            this.SetTitle();

            foreach (TreeViewItem item in tvPages.Items)
            {
                ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;
                page.SaveConfiguration(configFile);
            }

            if (!configFile.Save())
            {
                MessageBox.Show("Unable to save spell checking configuration", PackageResources.PackageTitle,
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Beispiel #6
0
        /// <summary>
        /// View help for the selected property category
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void cmdHelp_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            TreeViewItem item = (TreeViewItem)tvPages.SelectedItem;

            if (item != null)
            {
                ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;

                try
                {
                    string targetUrl = "https://ewsoftware.github.io/VSSpellChecker/html/" + page.HelpUrl + ".htm";

                    Process.Start(targetUrl);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to navigate to website.  Reason: " + ex.Message,
                                    PackageResources.PackageTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }
Beispiel #7
0
        //=====================================================================

        /// <summary>
        /// This is used to load the configuration file to edit
        /// </summary>
        /// <param name="configurationFile">The configuration filename</param>
        public void LoadConfiguration(string configurationFile)
        {
            configFile = new SpellingConfigurationFile(configurationFile, null);

            this.SetTitle();

            foreach (TreeViewItem item in tvPages.Items)
            {
                ISpellCheckerConfiguration page = ((ISpellCheckerConfiguration)item.Tag);

                if (page.AppliesTo(configFile.ConfigurationType))
                {
                    item.Visibility = Visibility.Visible;
                    page.LoadConfiguration(configFile);
                }
                else
                {
                    item.Visibility = Visibility.Collapsed;
                }
            }
        }
        /// <summary>
        /// Save changes to the configuration
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            foreach (TreeViewItem item in tvPages.Items)
            {
                ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;

                if (!page.SaveConfiguration())
                {
                    item.IsSelected = true;
                    return;
                }
            }

            if (!SpellCheckerConfiguration.SaveConfiguration())
            {
                MessageBox.Show("Unable to save spell checking configuration", PackageResources.PackageTitle,
                                MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }

            this.Close();
        }
Beispiel #9
0
        /// <summary>
        /// View help for the selected property category
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void cmdHelp_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            TreeViewItem item = (TreeViewItem)tvPages.SelectedItem;

            if (item != null)
            {
                ISpellCheckerConfiguration page = (ISpellCheckerConfiguration)item.Tag;

                try
                {
                    string targetUrl = lnkProjectSite.NavigateUri.AbsoluteUri + "/wiki/" + page.HelpUrl;

                    Process.Start(targetUrl);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to navigate to website.  Reason: " + ex.Message,
                                    PackageResources.PackageTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }