/// <summary>
        /// Stores the content of the WordFormatter object (style settings used for pharagraph formatting) in an XML file
        /// </summary>
        /// <param name="filePath">The complete file path where the file will be located at</param>
        /// <param name="colorizer">The WordFormatter object to be serialized</param>
        public static void Serialize(string filePath, WordFormatter formatter)
        {
            FileStream    file   = null;
            XmlTextWriter writer = null;

            try
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(WordFormatter));
                file              = File.Create(filePath);
                writer            = new XmlTextWriter(file, Encoding.UTF8);
                writer.Formatting = Formatting.Indented;
                serializer.WriteObject(writer, formatter);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Couldn't save the file: \n" + filePath);
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
                if (filePath != null)
                {
                    file.Close();
                }
            }
        }
        /// <summary>
        /// Loads the content of a WordFormatter object  (style settings used for pharagraph formatting) from an XML file.
        /// If the deserializatoin is unsuccessful, then a WordFormatter object with the default languages and styles is returned.
        /// In either case, the returned Formatter is still not initialized, as it has no reference to a Colorizer or to a Word Application.
        /// </summary>
        /// <param name="filePath">The complete file path where the file will be located at</param>
        /// <returns>The WordFormatter object filled with the contents of the file, but without initialization</returns>
        public static WordFormatter Deserialize(string filePath)
        {
            WordFormatter       formatter;
            FileStream          fs     = null;
            XmlDictionaryReader reader = null;

            try
            {
                fs     = new FileStream(filePath, FileMode.Open);
                reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
                DataContractSerializer ser = new DataContractSerializer(typeof(WordFormatter));
                formatter = (WordFormatter)ser.ReadObject(reader, true);
            }
            catch (Exception exception)
            {
                MessageBox.Show("Couldn't load the file at:\n"
                                + filePath
                                + "\n the language independent style will be set to default");
                formatter = new WordFormatter();
                formatter.SetToDefault();
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
            // The WordFormatter object is still not initialized here! (It has no reference to a Colorizer and Word Application)
            return(formatter);
        }
 /// <summary>
 /// Loads the content of a WordFormatter object  (style settings used for pharagraph formatting) from an XML file.
 /// If the deserializatoin is unsuccessful, then a WordFormatter object with the default languages and styles is returned.
 /// In either case, the returned Formatter is still not initialized, as it has no reference to a Colorizer or to a Word Application.
 /// </summary>
 /// <param name="filePath">The complete file path where the file will be located at</param>
 /// <returns>The WordFormatter object filled with the contents of the file, but without initialization</returns>
 public static WordFormatter Deserialize(string filePath)
 {
     WordFormatter formatter;
     FileStream fs = null;
     XmlDictionaryReader reader = null;
     try
     {
         fs = new FileStream(filePath, FileMode.Open);
         reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());
         DataContractSerializer ser = new DataContractSerializer(typeof(WordFormatter));
         formatter = (WordFormatter)ser.ReadObject(reader, true);
     }
     catch (Exception exception)
     {
         MessageBox.Show("Couldn't load the file at:\n"
             + filePath
             + "\n the language independent style will be set to default");
         formatter = new WordFormatter();
         formatter.SetToDefault();
     }
     finally
     {
         if (reader != null)
             reader.Close();
         if (fs != null)
             fs.Close();
     }
     // The WordFormatter object is still not initialized here! (It has no reference to a Colorizer and Word Application)
     return formatter;
 }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            if (Directory.Exists(directoryPath))
            {
                colorizer = ColorizerSerializer.Deserialize(directoryPath + @"\default.xml");
                formatter = WordFormatterSerializer.Deserialize(directoryPath + @"\basicformat.xml");
                formatter.Initialize(colorizer, this.Application);
            }
            else // if it's the first starting of this version of the Add-In with this user
            {
                Directory.CreateDirectory(directoryPath);

                colorizer = new Colorizer();
                colorizer.LoadPredefinedLanguages();
                colorizer.Initialize();

                formatter = new WordFormatter();
                formatter.Initialize(colorizer, this.Application);
                formatter.SetToDefault();
            }

            indentFixer = new WordIndentFixer(this.Application);
            codecleaner = new CodeCleaner(this.Application);

            Globals.Ribbons.WordCodeEditorToolsRibbon.InitializeAddIn(this);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates an instance of the FrameStyleForm class. The input fields of the Form are initialized based on the formatter's existing settings.
        /// </summary>
        /// <param name="formatter_"></param>
        public FrameStyleForm(WordFormatter formatter_)
        {
            InitializeComponent();

            // fills the combobox with the avaliable fonts
            foreach (FontFamily font in FontFamily.Families)
            {
                comboBox_Font.Items.Add(font.Name);
            }

            formatter = formatter_;
            Initialize();
        }
        /// <summary>
        /// Loads back the hardcoded default values for the style settings, so that the user can return to these whenever he or she wants.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Default_button_Click(object sender, EventArgs e)
        {
            WordFormatter temp = new WordFormatter();

            temp.SetToDefault();

            BgColorButton.BackColor      = temp.FrameBgColor;
            AltColorButton.BackColor     = temp.FrameAlternatingColor;
            BorderColorButton.BackColor  = temp.FrameBorderColor;
            useAltLines_checkBox.Checked = temp.FrameAlternatingLines;
            comboBox_Font.Text           = temp.FontName;
            numericUpDown_Font.Value     = (int)temp.FontSize;
        }
        /// <summary>
        /// Creates an instance of the FrameStyleForm class. The input fields of the Form are initialized based on the formatter's existing settings.
        /// </summary>
        /// <param name="formatter_"></param>
        public FrameStyleForm(WordFormatter formatter_)
        {
            InitializeComponent();

            // fills the combobox with the avaliable fonts
            foreach (FontFamily font in FontFamily.Families)
            {
                comboBox_Font.Items.Add(font.Name);
            }

            formatter = formatter_;
            Initialize();
        }
 /// <summary>
 /// Stores the content of the WordFormatter object (style settings used for pharagraph formatting) in an XML file
 /// </summary>
 /// <param name="filePath">The complete file path where the file will be located at</param>
 /// <param name="colorizer">The WordFormatter object to be serialized</param>
 public static void Serialize(string filePath, WordFormatter formatter)
 {
     FileStream file = null;
     XmlTextWriter writer = null;
     try
     {
         DataContractSerializer serializer = new DataContractSerializer(typeof(WordFormatter));
         file = File.Create(filePath);
         writer = new XmlTextWriter(file, Encoding.UTF8);
         writer.Formatting = Formatting.Indented;
         serializer.WriteObject(writer, formatter);
     }
     catch (Exception exception)
     {
         MessageBox.Show("Couldn't save the file: \n" + filePath);
     }
     finally
     {
         if (writer != null)
             writer.Close();
         if (filePath != null)
             file.Close();
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Loads back the hardcoded default values for the style settings, so that the user can return to these whenever he or she wants.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Default_button_Click(object sender, EventArgs e)
        {
            WordFormatter temp = new WordFormatter();
            temp.SetToDefault();

            BgColorButton.BackColor = temp.FrameBgColor;
            AltColorButton.BackColor = temp.FrameAlternatingColor;
            BorderColorButton.BackColor = temp.FrameBorderColor;
            useAltLines_checkBox.Checked = temp.FrameAlternatingLines;
            comboBox_Font.Text = temp.FontName;
            numericUpDown_Font.Value = (int)temp.FontSize;
        }