Exemple #1
0
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            RuleDialog   dlgRule = new RuleDialog(liSettings[0]);
            DialogResult dr      = dlgRule.ShowDialog();

            if (DialogResult.OK == dr)
            {
                StRule stR = new StRule();
                RetrieveRule(dlgRule, ref stR);
                ListViewItem lvi = new ListViewItem();
                FormatRow(stR, lvi);
                kaiListView.Items.Add(lvi);
                bDirty = true;
            }
        }
Exemple #2
0
        public RuleDialog(Settings st, StRule stCurrentRule)
        {
            Settings = st;

            InitializeComponent();

            InitializeOutputCombo();

            kaiListBoxStress.DisableEdit = false;

            iCurrentItem = -1;

            comboBox.Visible = false;

            textBox.Visible = false;

            textBoxInput.Text = stCurrentRule.sInput;

            foreach (KeyValuePair <string, string> kvp in stCurrentRule.dictStressPositions)
            {
                kaiListBoxStress.Items.Add(new DataItem(kvp));
            }

            foreach (KeyValuePair <string, string> kvp in stCurrentRule.dictLeftContexts)
            {
                kaiListBoxLeftContext.Items.Add(new DataItem(kvp));
            }

            foreach (KeyValuePair <string, string> kvp in stCurrentRule.dictRightContexts)
            {
                kaiListBoxRightContext.Items.Add(new DataItem(kvp));
            }

            foreach (KeyValuePair <string, string> kvp in stCurrentRule.dictExceptions)
            {
                kaiListBoxExceptions.Items.Add(new DataItem(kvp));
            }

            foreach (KeyValuePair <string, string> kvp in stCurrentRule.dictOutputModifiers)
            {
                kaiListBoxOutputModifiers.Items.Add(new DataItem(kvp));
            }

            foreach (KeyValuePair <string, string> kvp in stCurrentRule.dictOutputSymbols)
            {
                comboBoxOut.Text = kvp.Value;
            }
        }   //  RuleDialog (StRule stCurrentRule)
Exemple #3
0
        public RuleDialog(Settings st, StRule stCurrentRule)
        {
            Settings = st;

            InitializeComponent();

            InitializeOutputCombo();

            kaiListBoxStress.DisableEdit = false;

            iCurrentItem = -1;

            comboBox.Visible = false;

            textBox.Visible = false;

            textBoxInput.Text = stCurrentRule.sInput;

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictStressPositions)
            {
                kaiListBoxStress.Items.Add (new DataItem (kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictLeftContexts)
            {
                kaiListBoxLeftContext.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictRightContexts)
            {
                kaiListBoxRightContext.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictExceptions)
            {
                kaiListBoxExceptions.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictOutputModifiers)
            {
                kaiListBoxOutputModifiers.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictOutputSymbols)
            {
                comboBoxOut.Text = kvp.Value;
            }
        }
Exemple #4
0
        }   // PromptToSave()

        private void EditRule()
        {
            ListViewItem lviOld    = kaiListView.SelectedItems[0];
            StRule       stOldRule = (StRule)lviOld.Tag;
            RuleDialog   dlgRule   = new RuleDialog(liSettings[0], stOldRule);
            DialogResult dr        = dlgRule.ShowDialog();

            if (DialogResult.OK == dr)
            {
                StRule stR = new StRule();
                RetrieveRule(dlgRule, ref stR);
                ListViewItem lviNew = new ListViewItem();
                FormatRow(stR, lviNew);
                int iAt = kaiListView.Items.IndexOf(lviOld);
                kaiListView.Items.Remove(lviOld);
                kaiListView.Items.Insert(iAt, lviNew);
                bDirty = true;
            }
        }
Exemple #5
0
        //
        // Helpers
        //
        private void RetrieveRule(RuleDialog dlgRule, ref StRule stRule)
        {
            stRule.sInput = dlgRule.InputString;

            stRule.dictStressPositions = new Dictionary <string, string> (dlgRule.StressPositions);
            stRule.dictLeftContexts    = new Dictionary <string, string> (dlgRule.LeftContexts);
            stRule.dictRightContexts   = new Dictionary <string, string> (dlgRule.RightContexts);
            stRule.dictExceptions      = new Dictionary <string, string> (dlgRule.Exceptions);
            stRule.dictOutputSymbols   = new Dictionary <string, string>();
            if (dlgRule.OutputString.Length > 0)
            {
                stRule.dictOutputSymbols["Literal"] = dlgRule.OutputString;
            }
            if ("Literal" != dlgRule.OutputSymbol.Key)
            {
                stRule.dictOutputSymbols.Add(dlgRule.OutputSymbol.Key, dlgRule.OutputSymbol.Value);
            }
            stRule.dictOutputModifiers = new Dictionary <string, string> (dlgRule.OutputModifiers);
        }
Exemple #6
0
        private void FormatRow(StRule stRule, ListViewItem lvi)
        {
            lvi.Tag  = stRule;
            lvi.Text = stRule.sInput;

            try
            {
                ListViewItem.ListViewSubItem lvsiStress = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictStressPositions.Values)
                {
                    if (lvsiStress.Text.Length > 0)
                    {
                        lvsiStress.Text += ", ";
                    }
                    lvsiStress.Text += sValue;
                }
                lvi.SubItems.Add(lvsiStress);

                ListViewItem.ListViewSubItem lvsiLeft = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictLeftContexts.Values)
                {
                    if (lvsiLeft.Text.Length > 0)
                    {
                        lvsiLeft.Text += ", ";
                    }
                    lvsiLeft.Text += sValue;
                }
                lvi.SubItems.Add(lvsiLeft);

                ListViewItem.ListViewSubItem lvsiRight = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictRightContexts.Values)
                {
                    if (lvsiRight.Text.Length > 0)
                    {
                        lvsiRight.Text += ", ";
                    }
                    lvsiRight.Text += sValue;
                }
                lvi.SubItems.Add(lvsiRight);

                ListViewItem.ListViewSubItem lvsiExceptions = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictExceptions.Values)
                {
                    if (lvsiExceptions.Text.Length > 0)
                    {
                        lvsiExceptions.Text += ", ";
                    }
                    lvsiExceptions.Text += sValue;
                }
                lvi.SubItems.Add(lvsiExceptions);

                ListViewItem.ListViewSubItem lvsiOutput = new ListViewItem.ListViewSubItem();
                foreach (KeyValuePair <string, string> kvp in stRule.dictOutputSymbols)
                {
                    lvsiOutput.Text = kvp.Value;
                }
                lvi.SubItems.Add(lvsiOutput);

                ListViewItem.ListViewSubItem lvsiOutputModifiers = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictOutputModifiers.Values)
                {
                    if (lvsiOutputModifiers.Text.Length > 0)
                    {
                        lvsiOutputModifiers.Text += ", ";
                    }
                    lvsiOutputModifiers.Text += sValue;
                }
                lvi.SubItems.Add(lvsiOutputModifiers);
            }
            catch (Exception ex)
            {
                string sText = string.Format("Error formatting rule: {0}", ex.Message);
                MessageBox.Show(sText,
                                "RuleEditor",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }
        }   //  FormatRow (...)
Exemple #7
0
        private void WriteRules(string sPath)
        {
            XmlWriterSettings xmlSettings = new XmlWriterSettings();

            xmlSettings.Indent          = true;
            xmlSettings.IndentChars     = "    ";
            xmlSettings.Encoding        = Encoding.Unicode;
            xmlSettings.NewLineHandling = NewLineHandling.Replace;

            XmlWriter xmlWriter = XmlWriter.Create(sPath, xmlSettings);

            try
            {
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteComment("This file was automatically generated by Kai transcription module.");
                xmlWriter.WriteStartElement("Language");
                xmlWriter.WriteString("Russian");

                foreach (ListViewItem lvi in kaiListView.Items)
                {
                    StRule stRule = (StRule)lvi.Tag;
                    xmlWriter.WriteStartElement("Rule");
//                    xmlWriter.WriteAttributeString ("Num", stRule.iNumber.ToString());
                    xmlWriter.WriteStartElement("Input");
                    xmlWriter.WriteStartElement("Value");
                    xmlWriter.WriteAttributeString("Value", stRule.sInput);
                    xmlWriter.WriteEndElement();    // Value
                    xmlWriter.WriteEndElement();    // Input

                    xmlWriter.WriteStartElement("Stress");
                    foreach (KeyValuePair <string, string> kvp in stRule.dictStressPositions)
                    {
                        xmlWriter.WriteStartElement(kvp.Key);
                        xmlWriter.WriteAttributeString("Caption", kvp.Value);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("LeftContext");
                    foreach (KeyValuePair <string, string> kvp in stRule.dictLeftContexts)
                    {
                        xmlWriter.WriteStartElement(kvp.Key);
                        xmlWriter.WriteAttributeString("Caption", kvp.Value);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();

                    xmlWriter.WriteStartElement("RightContext");
                    foreach (KeyValuePair <string, string> kvp in stRule.dictRightContexts)
                    {
                        xmlWriter.WriteStartElement(kvp.Key);
                        xmlWriter.WriteAttributeString("Caption", kvp.Value);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();

                    if (stRule.dictExceptions.Count > 0)
                    {
                        xmlWriter.WriteStartElement("Exception");
                        foreach (KeyValuePair <string, string> kvp in stRule.dictExceptions)
                        {
                            xmlWriter.WriteStartElement(kvp.Key);
                            xmlWriter.WriteAttributeString("Caption", kvp.Value);
                            xmlWriter.WriteEndElement();
                        }
                        xmlWriter.WriteEndElement();
                    }

                    xmlWriter.WriteStartElement("Output");
                    foreach (KeyValuePair <string, string> kvp in stRule.dictOutputSymbols)
                    {
                        xmlWriter.WriteStartElement(kvp.Key);
                        xmlWriter.WriteAttributeString("Caption", kvp.Value);
                        xmlWriter.WriteEndElement();
                    }
                    xmlWriter.WriteEndElement();

                    if (stRule.dictOutputModifiers.Count > 0)
                    {
                        xmlWriter.WriteStartElement("Modifier");
                        foreach (KeyValuePair <string, string> kvp in stRule.dictOutputModifiers)
                        {
                            xmlWriter.WriteStartElement(kvp.Key);
                            xmlWriter.WriteAttributeString("Caption", kvp.Value);
                            xmlWriter.WriteEndElement();
                        }
                        xmlWriter.WriteEndElement();
                    }

                    xmlWriter.WriteEndElement(); // rule
                }                                // foreach (ListViewItem lvi in kaiListView.Items)

                xmlWriter.WriteEndDocument();
                xmlWriter.Flush();
                xmlWriter.Close();
            }
            catch (Exception ex)
            {
                string sMsg = string.Format("Error writing rule: {0}", ex.Message);
                MessageBox.Show(sMsg,
                                "Rule Editor",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
                KaiLibCS.MfcHelpers.LogError(sMsg);
                xmlWriter.Close();
            }
        }   //  writeRules (string sPath)
Exemple #8
0
        }   //  ReadSettings()

        private void ReadRules()
        {
            kaiListView.Items.Clear();

            try
            {
                XmlReaderSettings xmlSettings = new XmlReaderSettings();
                xmlSettings.ConformanceLevel = ConformanceLevel.Document;
                xmlSettings.IgnoreComments   = true;
                xmlSettings.IgnoreWhitespace = true;

                XmlReader xmlReader = XmlReader.Create(sRulesFilePath, xmlSettings);

                xmlReader.Read();
                xmlReader.ReadStartElement("Language");
                string sLanguage = xmlReader.ReadString();
                if ("Russian" != sLanguage)
                {
                    string sMsg = string.Format("Source file: {0} is invalid", sRulesFilePath);
                    MessageBox.Show(sMsg,
                                    "Rule Editor",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    KaiLibCS.MfcHelpers.LogError(sMsg);
                    return;
                }

                while (xmlReader.IsStartElement("Rule"))
                {
                    StRule stRule = new StRule();
                    xmlReader.Read();

                    while (!xmlReader.EOF && !xmlReader.IsStartElement())
                    {
                        xmlReader.Read();
                    }

                    stRule.dictStressPositions = new Dictionary <string, string>();
                    stRule.dictLeftContexts    = new Dictionary <string, string>();
                    stRule.dictRightContexts   = new Dictionary <string, string>();
                    stRule.dictExceptions      = new Dictionary <string, string>();
                    stRule.dictOutputSymbols   = new Dictionary <string, string>();
                    stRule.dictOutputModifiers = new Dictionary <string, string>();

                    while (xmlReader.IsStartElement())
                    {
                        switch (xmlReader.LocalName)
                        {
                        case "Input":
                        {
                            Dictionary <string, string> dictInput = new Dictionary <string, string>();
                            ReadAttributes(xmlReader, dictInput);
                            stRule.sInput = dictInput["Value"];
                            break;
                        }

                        case "Stress":
                        {
                            ReadAttributes(xmlReader, stRule.dictStressPositions);
                            break;
                        }

                        case "LeftContext":
                        {
                            ReadAttributes(xmlReader, stRule.dictLeftContexts);
                            break;
                        }

                        case "RightContext":
                        {
                            ReadAttributes(xmlReader, stRule.dictRightContexts);
                            break;
                        }

                        case "Exception":
                        {
                            ReadAttributes(xmlReader, stRule.dictExceptions);
                            break;
                        }

                        case "Output":
                        {
                            ReadAttributes(xmlReader, stRule.dictOutputSymbols);
                            break;
                        }

                        case "Modifier":
                        {
                            ReadAttributes(xmlReader, stRule.dictOutputModifiers);
                            break;
                        }

                        default:
                        {
                            string sMsg = string.Format("Unknown keyword: {0} in {1}",
                                                        xmlReader.LocalName,
                                                        sRulesFilePath);
                            MessageBox.Show(sMsg,
                                            "Rule Editor",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Exclamation);
                            KaiLibCS.MfcHelpers.LogError(sMsg);
                            continue;
                        }
                        }   // switch...
                    }

                    ListViewItem lvi = new ListViewItem();
                    FormatRow(stRule, lvi);
                    kaiListView.Items.Add(lvi);

                    xmlReader.Read();
                }

                xmlReader.Close();

                if (kaiListView.SelectedItems.Count > 0)
                {
                    buttonEdit.Enabled   = true;
                    buttonDelete.Enabled = true;
                }
                else
                {
                    buttonEdit.Enabled   = false;
                    buttonDelete.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                string sMsg = string.Format("IO error: {0}", ex.Message);
                MessageBox.Show(sMsg,
                                "Rule Editor",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }

            int iCount   = liMru.Count;
            int iRemoved = 0;

            for (int iItem = 0; iItem < iCount; ++iItem)
            {
                if (sRulesFilePath == liMru[iItem - iRemoved])
                {
                    liMru.RemoveAt(iItem - iRemoved);
                    iRemoved++;
                }
            }

            liMru.Insert(0, sRulesFilePath);
            if (liMru.Count > ciMaxMruCount)
            {
                liMru.RemoveAt(liMru.Count - 1);
            }

            //
            // Re-create MRU menu
            //
            while (recentFilesToolStripMenuItem.DropDownItems.Count > 0)
            {
                recentFilesToolStripMenuItem.DropDownItems.RemoveAt(0);
            }
            foreach (string sPath in liMru)
            {
                ToolStripMenuItem mi = new ToolStripMenuItem(sPath);
                mi.DropDownItemClicked += new ToolStripItemClickedEventHandler(toolStripDropDownItem_DropDownItemClicked);
                recentFilesToolStripMenuItem.DropDownItems.Add(mi);
            }
            recentFilesToolStripMenuItem.Enabled = true;
        }   //  readRules (string sPath)
Exemple #9
0
 private void buttonAdd_Click(object sender, EventArgs e)
 {
     RuleDialog dlgRule = new RuleDialog(liSettings[0]);
     DialogResult dr = dlgRule.ShowDialog();
     if (DialogResult.OK == dr)
     {
         StRule stR = new StRule();
         RetrieveRule (dlgRule, ref stR);
         ListViewItem lvi = new ListViewItem();
         FormatRow (stR, lvi);
         kaiListView.Items.Add (lvi);
         bDirty = true;
     }
 }
Exemple #10
0
        //
        // Helpers
        //
        private void RetrieveRule(RuleDialog dlgRule, ref StRule stRule)
        {
            stRule.sInput = dlgRule.InputString;

            stRule.dictStressPositions = new Dictionary<string, string> (dlgRule.StressPositions);
            stRule.dictLeftContexts = new Dictionary<string, string> (dlgRule.LeftContexts);
            stRule.dictRightContexts = new Dictionary<string, string> (dlgRule.RightContexts);
            stRule.dictExceptions = new Dictionary<string, string> (dlgRule.Exceptions);
            stRule.dictOutputSymbols = new Dictionary<string, string>();
            if (dlgRule.OutputString.Length > 0)
            {
                stRule.dictOutputSymbols["Literal"] = dlgRule.OutputString;
            }
            if ("Literal" != dlgRule.OutputSymbol.Key)
            {
                stRule.dictOutputSymbols.Add(dlgRule.OutputSymbol.Key, dlgRule.OutputSymbol.Value);
            }
            stRule.dictOutputModifiers = new Dictionary<string, string> (dlgRule.OutputModifiers);
        }
Exemple #11
0
        private void ReadRules()
        {
            kaiListView.Items.Clear();

            try
            {
                XmlReaderSettings xmlSettings = new XmlReaderSettings();
                xmlSettings.ConformanceLevel = ConformanceLevel.Document;
                xmlSettings.IgnoreComments = true;
                xmlSettings.IgnoreWhitespace = true;

                XmlReader xmlReader = XmlReader.Create (sRulesFilePath, xmlSettings);

                xmlReader.Read();
                xmlReader.ReadStartElement("Language");
                string sLanguage = xmlReader.ReadString();
                if ("Russian" != sLanguage)
                {
                    string sMsg = string.Format ("Source file: {0} is invalid", sRulesFilePath);
                    MessageBox.Show (sMsg,
                                     "Rule Editor",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Exclamation);
                    KaiLibCS.MfcHelpers.LogError(sMsg);
                    return;
                }

                while (xmlReader.IsStartElement("Rule"))
                {
                    StRule stRule = new StRule();
                    xmlReader.Read();

                    while (!xmlReader.EOF && !xmlReader.IsStartElement())
                    {
                        xmlReader.Read();
                    }

                    stRule.dictStressPositions = new Dictionary<string, string>();
                    stRule.dictLeftContexts = new Dictionary<string, string>();
                    stRule.dictRightContexts = new Dictionary<string, string>();
                    stRule.dictExceptions = new Dictionary<string, string>();
                    stRule.dictOutputSymbols = new Dictionary<string, string>();
                    stRule.dictOutputModifiers = new Dictionary<string, string>();

                    while (xmlReader.IsStartElement())
                    {
                        switch (xmlReader.LocalName)
                        {
                            case "Input":
                            {
                                Dictionary<string, string> dictInput = new Dictionary<string, string>();
                                ReadAttributes (xmlReader, dictInput);
                                stRule.sInput = dictInput["Value"];
                                break;
                            }
                            case "Stress":
                            {
                                ReadAttributes (xmlReader, stRule.dictStressPositions);
                                break;
                            }
                            case "LeftContext":
                            {
                                ReadAttributes (xmlReader, stRule.dictLeftContexts);
                                break;
                            }
                            case "RightContext":
                            {
                                ReadAttributes (xmlReader, stRule.dictRightContexts);
                                break;
                            }
                            case "Exception":
                            {
                                ReadAttributes (xmlReader, stRule.dictExceptions);
                                break;
                            }
                            case "Output":
                            {
                                ReadAttributes (xmlReader, stRule.dictOutputSymbols);
                                break;
                            }
                            case "Modifier":
                            {
                                ReadAttributes (xmlReader, stRule.dictOutputModifiers);
                                break;
                            }
                            default:
                            {
                                string sMsg = string.Format ("Unknown keyword: {0} in {1}",
                                                             xmlReader.LocalName,
                                                             sRulesFilePath);
                                MessageBox.Show (sMsg,
                                                 "Rule Editor",
                                                 MessageBoxButtons.OK,
                                                 MessageBoxIcon.Exclamation);
                                KaiLibCS.MfcHelpers.LogError (sMsg);
                                continue;
                            }

                        }   // switch...
                    }

                    ListViewItem lvi = new ListViewItem();
                    FormatRow (stRule, lvi);
                    kaiListView.Items.Add (lvi);

                    xmlReader.Read();
                }

                xmlReader.Close();

                if (kaiListView.SelectedItems.Count > 0)
                {
                    buttonEdit.Enabled = true;
                    buttonDelete.Enabled = true;
                }
                else
                {
                    buttonEdit.Enabled = false;
                    buttonDelete.Enabled = false;
                }
            }
            catch (Exception ex)
            {
                string sMsg = string.Format ("IO error: {0}", ex.Message);
                MessageBox.Show (sMsg,
                                 "Rule Editor",
                                 MessageBoxButtons.OK,
                                 MessageBoxIcon.Exclamation);
            }

            int iCount = liMru.Count;
            int iRemoved = 0;
            for (int iItem = 0; iItem < iCount; ++iItem)
            {
                if (sRulesFilePath == liMru[iItem - iRemoved])
                {
                    liMru.RemoveAt(iItem - iRemoved);
                    iRemoved++;
                }
            }

            liMru.Insert(0, sRulesFilePath);
            if (liMru.Count > ciMaxMruCount)
            {
                liMru.RemoveAt(liMru.Count - 1);
            }

            //
            // Re-create MRU menu
            //
            while (recentFilesToolStripMenuItem.DropDownItems.Count > 0)
            {
                recentFilesToolStripMenuItem.DropDownItems.RemoveAt(0);
            }
            foreach (string sPath in liMru)
            {
                ToolStripMenuItem mi = new ToolStripMenuItem (sPath);
                mi.DropDownItemClicked += new ToolStripItemClickedEventHandler(toolStripDropDownItem_DropDownItemClicked);
                recentFilesToolStripMenuItem.DropDownItems.Add(mi);
            }
            recentFilesToolStripMenuItem.Enabled = true;
        }
Exemple #12
0
        private void FormatRow(StRule stRule, ListViewItem lvi)
        {
            lvi.Tag = stRule;
            lvi.Text = stRule.sInput;

            try
            {
                ListViewItem.ListViewSubItem lvsiStress = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictStressPositions.Values)
                {
                    if (lvsiStress.Text.Length > 0)
                    {
                        lvsiStress.Text += ", ";
                    }
                    lvsiStress.Text += sValue;
                }
                lvi.SubItems.Add(lvsiStress);

                ListViewItem.ListViewSubItem lvsiLeft = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictLeftContexts.Values)
                {
                    if (lvsiLeft.Text.Length > 0)
                    {
                        lvsiLeft.Text += ", ";
                    }
                    lvsiLeft.Text += sValue;
                }
                lvi.SubItems.Add(lvsiLeft);

                ListViewItem.ListViewSubItem lvsiRight = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictRightContexts.Values)
                {
                    if (lvsiRight.Text.Length > 0)
                    {
                        lvsiRight.Text += ", ";
                    }
                    lvsiRight.Text += sValue;
                }
                lvi.SubItems.Add(lvsiRight);

                ListViewItem.ListViewSubItem lvsiExceptions = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictExceptions.Values)
                {
                    if (lvsiExceptions.Text.Length > 0)
                    {
                        lvsiExceptions.Text += ", ";
                    }
                    lvsiExceptions.Text += sValue;
                }
                lvi.SubItems.Add (lvsiExceptions);

                ListViewItem.ListViewSubItem lvsiOutput = new ListViewItem.ListViewSubItem();
                foreach (KeyValuePair<string, string> kvp in stRule.dictOutputSymbols)
                {
                    lvsiOutput.Text = kvp.Value;
                }
                lvi.SubItems.Add(lvsiOutput);

                ListViewItem.ListViewSubItem lvsiOutputModifiers = new ListViewItem.ListViewSubItem();
                foreach (string sValue in stRule.dictOutputModifiers.Values)
                {
                    if (lvsiOutputModifiers.Text.Length > 0)
                    {
                        lvsiOutputModifiers.Text += ", ";
                    }
                    lvsiOutputModifiers.Text += sValue;
                }
                lvi.SubItems.Add(lvsiOutputModifiers);
            }
            catch (Exception ex)
            {
                string sText = string.Format("Error formatting rule: {0}", ex.Message);
                MessageBox.Show (sText,
                                 "RuleEditor",
                                 MessageBoxButtons.OK,
                                 MessageBoxIcon.Exclamation);
            }
        }
Exemple #13
0
 private void EditRule()
 {
     ListViewItem lviOld = kaiListView.SelectedItems[0];
     StRule stOldRule = (StRule)lviOld.Tag;
     RuleDialog dlgRule = new RuleDialog (liSettings[0], stOldRule);
     DialogResult dr = dlgRule.ShowDialog();
     if (DialogResult.OK == dr)
     {
         StRule stR = new StRule();
         RetrieveRule (dlgRule, ref stR);
         ListViewItem lviNew = new ListViewItem();
         FormatRow (stR, lviNew);
         int iAt = kaiListView.Items.IndexOf(lviOld);
         kaiListView.Items.Remove (lviOld);
         kaiListView.Items.Insert (iAt, lviNew);
         bDirty = true;
     }
 }