private static void AddNewEntryToolStripMenuItemClick(object sender, EventArgs e)
        {
            var dlg = new AddToLibrary();

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                dlg.Dispose();
                return;
            }
            var tmp = new RBFLibEntry
            {
                Name      = dlg.ValueName,
                Tags      = dlg.Tags,
                TagGroups = dlg.TagGroups,
                Values    = new List <AttributeValue>()
            };

            if (RBFLibrary.GetEntry(tmp.Name) == null)
            {
                RBFLibrary.AddEntry(tmp);
            }
            else if (dlg.AddTags)
            {
                RBFLibEntry entry = RBFLibrary.GetEntry(tmp.Name);
                foreach (string t in tmp.Tags)
                {
                    RBFLibrary.AddEntryToTag(entry, t);
                }
            }
            dlg.Dispose();
        }
 private void RBFLibraryEntryRemoved(object sender, RBFLibEntry t)
 {
     if (t == m_current)
     {
         m_current = null;
         rbfEditorCore1.Clear();
     }
     _lbxEntries.Items.Remove(t);
 }
示例#3
0
 static public void AddEntryToTagGroup(RBFLibEntry entry, string taggroup)
 {
     if (taggroup == string.Empty || !s_tagGroups.ContainsKey(taggroup))
     {
         return;
     }
     string[] tags = s_tagGroups[taggroup];
     foreach (string tag in tags)
     {
         AddEntryToTag(entry, tag);
     }
 }
        private void LbxEntriesSelectedIndexChanged(object sender, EventArgs e)
        {
            if (_lbxEntries.SelectedIndex == -1)
            {
                return;
            }
            rbfEditorCore1.Clear();
            var entry = (_lbxEntries.Items[_lbxEntries.SelectedIndex]) as RBFLibEntry;

            rbfEditorCore1.Analyze(entry.Values);
            m_current         = entry;
            _tbx_subMenu.Text = m_current.Submenu ?? string.Empty;
        }
示例#5
0
        private static void AddToLibrary(string[] tags, string[] tagGroups, AttribInfo info)
        {
            RBFLibEntry entry = new RBFLibEntry();

            entry.Values    = new List <AttributeValue>();
            entry.Submenu   = info.Category;
            entry.TagGroups = tagGroups ?? new string[0];
            entry.Tags      = tags ?? new string[0];
            entry.Values.Add(info.Value);
            entry.Name = info.Value.Key;
            RBFLibrary.RemoveEntry(entry.Name);
            RBFLibrary.AddEntry(entry);
        }
示例#6
0
        static public void RemoveEntryFromTag(RBFLibEntry entry, string tag)
        {
            if (tag == string.Empty || !s_library.ContainsKey(tag))
            {
                return;
            }
            SortedDictionary <string, RBFLibEntry> entries = s_library[tag];

            if (entries.ContainsKey(entry.Name))
            {
                entries.Remove(entry.Name);
            }
        }
示例#7
0
        private void CopyIntoLibraryToolStripMenuItemClick(object sender, EventArgs e)
        {
            TreeNode selected = m_trvTables.SelectedNode;

            if (selected == null || selected.Tag == null)
            {
                return;
            }

            var dlg = new AddToLibrary();

            if (selected.Parent != null)
            {
                dlg.Tags = new[] { selected.Parent.Text + '\n' }
            }
            ;
            dlg.ValueName = selected.Text;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                dlg.Dispose();
                return;
            }
            var tmp = new RBFLibEntry
            {
                Name      = dlg.ValueName,
                Tags      = dlg.Tags,
                TagGroups = dlg.TagGroups
            };

            if (dlg.SubMenu != string.Empty)
            {
                tmp.Submenu = dlg.SubMenu;
            }
            tmp.Values = new List <AttributeValue> {
                selected.Tag as AttributeValue
            };

            if (RBFLibrary.GetEntry(tmp.Name) == null)
            {
                RBFLibrary.AddEntry(tmp);
            }
            else if (dlg.AddTags)
            {
                RBFLibEntry entry = RBFLibrary.GetEntry(tmp.Name);
                foreach (string t in tmp.Tags)
                {
                    RBFLibrary.AddEntryToTag(entry, t);
                }
            }
            dlg.Dispose();
        }
示例#8
0
 static public void RemoveEntry(RBFLibEntry entry)
 {
     s_values.Remove(entry.Name);
     foreach (string tag in entry.Tags)
     {
         RemoveEntryFromTag(entry, tag);
     }
     foreach (string taggroup in entry.TagGroups)
     {
         RemoveEntryFromTagGroup(entry, taggroup);
     }
     if (EntryRemoved != null)
     {
         EntryRemoved(null, entry);
     }
 }
示例#9
0
 static public void AddEntry(RBFLibEntry entry)
 {
     s_values.Add(entry.Name, entry);
     foreach (string tag in entry.Tags)
     {
         AddEntryToTag(entry, tag);
     }
     foreach (string taggroup in entry.TagGroups)
     {
         AddEntryToTagGroup(entry, taggroup);
     }
     if (EntryAdded != null)
     {
         EntryAdded(null, entry);
     }
 }
示例#10
0
        static public void AddEntryToTag(RBFLibEntry entry, string tag)
        {
            if (tag == string.Empty)
            {
                return;
            }
            SortedDictionary <string, RBFLibEntry> entries;

            if (!s_library.ContainsKey(tag))
            {
                entries = new SortedDictionary <string, RBFLibEntry>();
                s_library.Add(tag, entries);
            }
            else
            {
                entries = s_library[tag];
            }
            if (!entries.ContainsKey(entry.Name))
            {
                entries.Add(entry.Name, entry);
            }
        }
 private void RBFLibraryEntryAdded(object sender, RBFLibEntry t)
 {
     _lbxEntries.Items.Add(t);
 }
示例#12
0
        /// <exception cref="CopeException">Expected a XmlDeclaration at the beginning of the RBF library.</exception>
        static void ReadLibrary(Stream stream)
        {
            var settings = new XmlReaderSettings {
                IgnoreComments = true, IgnoreWhitespace = true
            };
            XmlReader reader = XmlReader.Create(stream, settings);

            if (!reader.Read() || reader.NodeType != XmlNodeType.XmlDeclaration)
            {
                throw new CopeException("Expected a XmlDeclaration at the beginning of the RBF library.");
            }
            if (!reader.Read() || reader.NodeType != XmlNodeType.Element || reader.Name != "RBFLibrary")
            {
                throw new CopeException("Expected a node with name 'RBFLibrary' as the main node.");
            }
            while (reader.Read() && reader.MoveToContent() == XmlNodeType.Element)
            {
                if (reader.Name == "Entry")
                {
                    string        name                  = null;
                    string        submenu               = null;
                    List <string> tags                  = new List <string>();
                    List <string> taggroups             = new List <string>();
                    IEnumerable <AttributeValue> values = null;

                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        if (reader.Name == "Name")
                        {
                            name = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name == "Submenu")
                        {
                            submenu = reader.ReadElementContentAsString();
                        }
                        else if (reader.Name == "Tags")
                        {
                            reader.Read();
                            while (reader.Name == "Tag")
                            {
                                tags.Add(reader.ReadElementContentAsString());
                            }
                            reader.ReadEndElement();
                        }
                        else if (reader.Name == "TagGroups")
                        {
                            reader.Read();
                            while (reader.Name == "TagGroup")
                            {
                                taggroups.Add(reader.ReadElementContentAsString());
                            }
                            reader.ReadEndElement();
                        }
                        else if (reader.Name == "Values")
                        {
                            reader.Read();
                            values = AttributeXmlReader.ReadData(reader, null);
                            reader.ReadEndElement();
                        }
                        else
                        {
                            reader.Read();
                        }
                    }
                    if (name != null && values != null && (tags.Count != 0 || taggroups.Count != 0))
                    {
                        RBFLibEntry entry = new RBFLibEntry
                        {
                            Name      = name,
                            Submenu   = submenu,
                            Tags      = tags.ToArray(),
                            TagGroups = taggroups.ToArray(),
                            Values    = new List <AttributeValue>(values)
                        };
                        AddEntry(entry);
                    }
                }
            }
        }
示例#13
0
        static void ReadLibraryLegacy(StreamReader reader)
        {
            string      line         = reader.ReadLine();
            string      value        = string.Empty;
            RBFLibEntry currentEntry = null;

            while (line != null)
            {
                if (line.StartsWith("//"))
                {
                }
                else if (line == string.Empty)
                {
                    if (value != string.Empty && currentEntry != null)
                    {
                        currentEntry.Values = CorsixStyleConverter.Parse(value);
                    }
                    value = string.Empty;
                }
                else if (line.StartsWith("[name="))
                {
                    line = line.Remove(line.Length - 1, 1).Remove(0, 6);
                    if (currentEntry != null)
                    {
                        if (currentEntry.TagGroups == null)
                        {
                            currentEntry.TagGroups = new string[0];
                        }
                        if (currentEntry.Tags == null)
                        {
                            currentEntry.Tags = new string[0];
                        }
                        s_values.Add(currentEntry.Name, currentEntry);
                    }

                    currentEntry = new RBFLibEntry {
                        Name = line
                    };
                }
                else if (line.StartsWith("[tags="))
                {
                    line = line.Remove(line.Length - 1, 1).Remove(0, 6);
                    if (line.Length > 0 && currentEntry != null)
                    {
                        currentEntry.Tags = line.Split(s_tagSeperator, StringSplitOptions.RemoveEmptyEntries);
                    }
                }
                else if (line.StartsWith("[taggroups="))
                {
                    line = line.RemoveLast(1).Remove(0, 11);
                    if (currentEntry != null)
                    {
                        currentEntry.TagGroups = line.Split(s_tagSeperator, StringSplitOptions.RemoveEmptyEntries);
                    }
                }
                else if (line.StartsWith("[sub="))
                {
                    line = line.Remove(line.Length - 1, 1).Remove(0, 5);
                    if (currentEntry != null)
                    {
                        currentEntry.Submenu = line;
                    }
                }
                else
                {
                    value += line;
                    value += '\n';
                }
                line = reader.ReadLine();
            }
            if (currentEntry != null)
            {
                if (value != string.Empty)
                {
                    currentEntry.Values = CorsixStyleConverter.Parse(value);
                }
                if (!s_values.ContainsKey(currentEntry.Name))
                {
                    s_values.Add(currentEntry.Name, currentEntry);
                }
            }
        }