Beispiel #1
0
        private void loadPrevious()
        {
            string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            List<string> xmlPaths;
            try
            {
                if (File.Exists(path + "\\config.xml"))
                {
                    //do you wanna build a snowman?
                    crayonsSet = xmlHandler.loadColorConfig();
                    HighLight.config(crayonsSet);
                    listBox1.Font = xmlHandler.loadFontConfig();
                    wplayer.controls.play();

                    DialogResult dialog = MessageBox.Show("Do you wanna build a snowman?", "Last session", MessageBoxButtons.YesNo);
                    if (dialog == DialogResult.Yes)
                    {

                        xmlPaths = xmlHandler.XmlLoad();
                        if (xmlPaths.Count > 0)
                        {
                            foreach (string xmlPath in xmlPaths)
                            {
                                openXMLFile(xmlPath, null);

                            }
                            tabControl1.TabPages.Remove(tabPage1);
                        }

                        focusedRichTextBox.Font = listBox1.Font;
                        Snowman snowman = new Snowman();
                        snowman.Show();
                        snowman.TopMost = true;
                        snowman.FormClosed += Snowman_FormClosed;

                    }

                }
                else
                {

                    xmlHandler.createConfig();
                    crayonsSet = HighLight.defaultColors();
                    currentTab = tabPage1;
                    focusedRichTextBox = richTextBox1;
                    focusedRichTextBox.MouseWheel += FocusedRichTextBox_MouseWheel;
                    focusedRichTextBox.vScroll += scrollSyncTxtBox1_vScroll;
                    lineNumbering();
                }
            }
            catch (ArgumentNullException ae)
            {
                listBox1.Items.Add("The config was empty, we made you another one.");
                xmlHandler.createConfig();
                crayonsSet = HighLight.defaultColors();
                currentTab = tabPage1;
                focusedRichTextBox = richTextBox1;
                focusedRichTextBox.MouseWheel += FocusedRichTextBox_MouseWheel;
                focusedRichTextBox.vScroll += scrollSyncTxtBox1_vScroll;
                lineNumbering();
            }
            return;
        }
Beispiel #2
0
        private void saveOverride(object sender, EventArgs e)
        {


            string lpath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\config.xml";
            try
            {
                if (currentTab.Tag != null)
                {

                    string path = currentTab.Tag.ToString();
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(focusedRichTextBox.Text);
                    doc.Save(path);

                    listBox1.Items.Add("File saved");
                    currentTab.Text = Path.GetFileName(path);
                }
                else
                {
                    saveFileToolStripMenuItem_Click(sender, e);
                }
                if (currentTab.Tag != null && currentTab.Tag.Equals(lpath))
                {
                    try
                    {
                        currentxsd = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\config.xsd";
                        
                        validationToolStripMenuItem.PerformClick();
                        crayonsSet = new List<string>();
                        using (XmlReader xmlReader = XmlReader.Create(lpath))
                        {
                            while (xmlReader.Read())
                            {
                                if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "nodeColor"))
                                {
                                    crayonsSet.Add(xmlReader.ReadInnerXml());
                                }
                                if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "stringColor"))
                                {
                                    crayonsSet.Add(xmlReader.ReadInnerXml());
                                }
                                if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "attributeColor"))
                                {
                                    crayonsSet.Add(xmlReader.ReadInnerXml());
                                }
                                if ((xmlReader.NodeType == XmlNodeType.Element) && (xmlReader.Name == "textColor"))
                                {
                                    crayonsSet.Add(xmlReader.ReadInnerXml());
                                }
                            }
                        }

                        HighLight.config(crayonsSet);
                        listBox1.Font = xmlHandler.loadFontConfig();
                    }catch(Exception ex)
                    {
                        listBox1.Items.Add(ex.Message);
                    }


                    /*tabControl1.TabPages.Remove(currentTab);
                    tabControl1.TabPages[0].Select();
                    currentTab = tabControl1.TabPages[0];*/
                }
            }
            catch (XmlException xe)
            {
                Console.WriteLine(xe.Message);
                listBox1.Items.Add("Invalid XML formation, can't save");
                listBox1.Items.Add(xe.Message);
            }
        }