Ejemplo n.º 1
0
 protected static void FireRecordDeleted(object sender, BaseRecord rec)
 {
     if (!HoldUpdates && RecordDeleted != null)
     {
         RecordDeleted(sender, new RecordChangeEventArgs(rec));
     }
 }
Ejemplo n.º 2
0
 protected static void FireRecordListUpdate(object sender, BaseRecord rec)
 {
     if (!HoldUpdates && ChildListChanged != null)
     {
         ChildListChanged(sender, new RecordChangeEventArgs(rec));
     }
 }
Ejemplo n.º 3
0
 private bool findDuplicateFormIDs(BaseRecord tn, Dictionary <uint, Record> ids)
 {
     if (tn is Record)
     {
         var r2 = (Record)tn;
         if (ids.ContainsKey(r2.FormID))
         {
             PluginTree.SelectedRecord = tn;
             MessageBox.Show("Record duplicates " + (ids[r2.FormID]).DescriptiveName);
             ids.Clear();
             return(true);
         }
         else
         {
             ids.Add(r2.FormID, r2);
         }
     }
     else
     {
         foreach (BaseRecord tn2 in tn.Records)
         {
             findDuplicateFormIDs(tn2, ids);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
 public static Plugin GetPluginFromNode(BaseRecord node)
 {
     BaseRecord tn = node;
     if (tn is Plugin) return (Plugin)tn;
     while (!(tn is Plugin) && tn != null) tn = tn.Parent;
     if (tn != null) return tn as Plugin;
     return null;
 }
Ejemplo n.º 5
0
 public override void InsertRecord(int idx, BaseRecord br)
 {
     var r = br as Plugin;
     r.Parent = this;
     if (idx < 0 || idx > pluginList.Count)
         idx = pluginList.Count;
     pluginList.Insert(idx, r);
     FireRecordListUpdate(this, null);
 }
Ejemplo n.º 6
0
 private bool IsNonConformingRecord(BaseRecord tn)
 {
     if (tn is Record)
     {
         var r = tn as Record;
         return(r != null && !r.MatchRecordStructureToRecord());
     }
     return(false);
 }
Ejemplo n.º 7
0
 public override void InsertRecord(int idx, BaseRecord br)
 {
     var sr = br as SubRecord;
     if (sr == null)
         throw new TESParserException("Record to add was not of the correct type." +
                                      Environment.NewLine + "Records can only hold Subrecords.");
     sr.Parent = this;
     SubRecords.Insert(idx, sr);
 }
Ejemplo n.º 8
0
 public override void AddRecord(BaseRecord br)
 {
     var r = br as Rec;
     if (r == null)
         throw new TESParserException("Record to add was not of the correct type." +
                                      Environment.NewLine + "Groups can only hold records or other groups.");
     r.Parent = this;
     records.Add(r);
     FireRecordListUpdate(this, this);
 }
Ejemplo n.º 9
0
        internal bool findNonConformingRecordIncremental(BaseRecord tn, bool forward, bool wrapAround)
        {
            var node = IncrementalSearch(tn, false, forward, wrapAround, IsNonConformingRecord);

            if (node != null)
            {
                PluginTree.SelectedRecord = node;
            }
            return(node != null);
        }
Ejemplo n.º 10
0
        public override bool DeleteRecord(BaseRecord br)
        {
            var sr = br as SubRecord;

            if (sr == null)
            {
                return(false);
            }
            return(SubRecords.Remove(sr));
        }
Ejemplo n.º 11
0
 public override bool DeleteRecord(BaseRecord br)
 {
     var r = br as Rec;
     if (r == null) return false;
     bool ok = records.Remove(r);
     if (ok) r.Parent = null;
     FireRecordListUpdate(this, this);
     FireRecordDeleted(this, r);
     return ok;
 }
Ejemplo n.º 12
0
 public override void AddRecord(BaseRecord br)
 {
     var p = br as Plugin;
     if (p != null)
     {
         p.Parent = this;
         pluginList.Add(p);
     }
     FireRecordListUpdate(this, null);
 }
Ejemplo n.º 13
0
 public override bool DeleteRecord(BaseRecord br)
 {
     var r = br as Rec;
     if (r == null) return false;
     bool result = records.Remove(r);
     if (result) r.Parent = null;
     InvalidateCache();
     FireRecordDeleted(this, r);
     FireRecordListUpdate(this, this);
     return result;
 }
Ejemplo n.º 14
0
        public override void AddRecord(BaseRecord br)
        {
            var p = br as Plugin;

            if (p != null)
            {
                p.Parent = this;
                pluginList.Add(p);
            }
            FireRecordListUpdate(this, null);
        }
Ejemplo n.º 15
0
 public override void AddRecord(BaseRecord br)
 {
     var r = br as Rec;
     if (r == null)
         throw new TESParserException("Record to add was not of the correct type." +
                                      Environment.NewLine + "Plugins can only hold Groups or Records.");
     r.Parent = this;
     records.Add(r);
     InvalidateCache();
     FireRecordListUpdate(this, this);
 }
Ejemplo n.º 16
0
 public override bool DeleteRecord(BaseRecord br)
 {
     var r = br as Rec;
     if (r == null) return false;
     bool result = records.Remove(r);
     if (result) r.Parent = null;
     InvalidateCache();
     FireRecordDeleted(this, r);
     FireRecordListUpdate(this, this);
     return result;
 }
Ejemplo n.º 17
0
 public override bool DeleteRecord(BaseRecord br)
 {
     var p = br as Plugin;
     if (p != null)
     {
         p.Parent = null;
         bool ok = pluginList.Remove(p);
         FireRecordListUpdate(this, this);
         return ok;
     }
     return false;
 }
Ejemplo n.º 18
0
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var r = br as Plugin;

            r.Parent = this;
            if (idx < 0 || idx > pluginList.Count)
            {
                idx = pluginList.Count;
            }
            pluginList.Insert(idx, r);
            FireRecordListUpdate(this, null);
        }
Ejemplo n.º 19
0
 public SearchSettings()
 {
     type       = SearchType.EditorID;
     startNode  = null;
     text       = null;
     first      = true;
     partial    = true;
     forward    = true;
     wrapAround = true;
     updateFunc = null;
     rectype    = null;
 }
Ejemplo n.º 20
0
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var sr = br as SubRecord;

            if (sr == null)
            {
                throw new TESParserException("Record to add was not of the correct type." +
                                             Environment.NewLine + "Records can only hold Subrecords.");
            }
            sr.Parent = this;
            SubRecords.Insert(idx, sr);
        }
Ejemplo n.º 21
0
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var r = br as Rec;
            if (r == null)
                throw new TESParserException("Record to add was not of the correct type." +
                                             Environment.NewLine + "Groups can only hold records or other groups.");
            r.Parent = this;
            if (idx < 0 || idx > records.Count)
                idx = records.Count;

            records.Insert(idx, r);
            FireRecordListUpdate(this, this);
        }
Ejemplo n.º 22
0
        public override void AddRecord(BaseRecord br)
        {
            var r = br as Rec;

            if (r == null)
            {
                throw new TESParserException("Record to add was not of the correct type." +
                                             Environment.NewLine + "Groups can only hold records or other groups.");
            }
            r.Parent = this;
            records.Add(r);
            FireRecordListUpdate(this, this);
        }
Ejemplo n.º 23
0
 public override void InsertRecord(int idx, BaseRecord br)
 {
     var r = br as Rec;
     if (r == null)
         throw new TESParserException("Record to add was not of the correct type." +
                                      Environment.NewLine + "Plugins can only hold Groups or Records.");
     r.Parent = this;
     if (idx < 0 || idx > records.Count)
         idx = records.Count;
     records.Insert(idx, r);
     InvalidateCache();
     FireRecordListUpdate(this, this);
 }
Ejemplo n.º 24
0
        public override bool DeleteRecord(BaseRecord br)
        {
            var p = br as Plugin;

            if (p != null)
            {
                p.Parent = null;
                bool ok = pluginList.Remove(p);
                FireRecordListUpdate(this, this);
                return(ok);
            }
            return(false);
        }
Ejemplo n.º 25
0
        public Plugin GetPlugin()
        {
            BaseRecord tn = this.Parent;

            while (!(tn is Plugin) && tn != null)
            {
                tn = tn.Parent;
            }
            if (tn != null)
            {
                return(tn as Plugin);
            }
            return(null);
        }
Ejemplo n.º 26
0
 public static void giveBaseRecordNewFormID(BaseRecord rec, bool updateReference, ref uint formCount, ref uint refCount)
 {
     if (rec is Record)
     {
         giveRecordNewFormID((Record)rec, updateReference, ref formCount, ref refCount);
     }
     else if (rec is GroupRecord)
     {
         foreach (BaseRecord rec2 in ((GroupRecord)rec).Records)
         {
             giveBaseRecordNewFormID(rec2, updateReference, ref formCount, ref refCount);
         }
     }
 }
Ejemplo n.º 27
0
        public override bool DeleteRecord(BaseRecord br)
        {
            var r = br as Rec;

            if (r == null)
            {
                return(false);
            }
            bool ok = records.Remove(r);

            if (ok)
            {
                r.Parent = null;
            }
            FireRecordListUpdate(this, this);
            FireRecordDeleted(this, r);
            return(ok);
        }
Ejemplo n.º 28
0
        public override void InsertRecord(int idx, BaseRecord br)
        {
            var r = br as Rec;

            if (r == null)
            {
                throw new TESParserException("Record to add was not of the correct type." +
                                             Environment.NewLine + "Groups can only hold records or other groups.");
            }
            r.Parent = this;
            if (idx < 0 || idx > records.Count)
            {
                idx = records.Count;
            }

            records.Insert(idx, r);
            FireRecordListUpdate(this, this);
        }
Ejemplo n.º 29
0
        internal BaseRecord IncrementalSearch(BaseRecord tn, bool first, bool forward, bool wrapAround,
                                              Predicate <BaseRecord> searchFunc)
        {
            using (var itr = new RecursiveRecordIterator(tn, forward))
            {
                BaseRecord startNode = null;
                Debug.Assert(tn.Equals(itr.Current));
                bool keep = first;
                do
                {
                    do
                    {
                        tn = itr.Current;
                        if (keep && searchFunc(tn))
                        {
                            return(tn);
                        }
                        keep = true;
                        if (startNode == null)
                        {
                            startNode = tn;
                        }
                        else if (startNode.Equals(tn))
                        {
                            return(null);
                        }
                    } while (itr.MoveNext());

                    if (!wrapAround)
                    {
                        break;
                    }
                    itr.Push(PluginList.All.Records[0] as BaseRecord);
                    itr.Reset();
                    wrapAround = false;// multipass protection
                } while (itr.MoveNext());
            }
            return(null);
        }
Ejemplo n.º 30
0
 private bool findDuplicateFormIDs(BaseRecord tn, Dictionary<uint, Record> ids)
 {
     if (tn is Record)
     {
         var r2 = (Record)tn;
         if (ids.ContainsKey(r2.FormID))
         {
             PluginTree.SelectedRecord = tn;
             MessageBox.Show("Record duplicates " + (ids[r2.FormID]).DescriptiveName);
             ids.Clear();
             return true;
         }
         else
         {
             ids.Add(r2.FormID, r2);
         }
     }
     else
     {
         foreach (BaseRecord tn2 in tn.Records) findDuplicateFormIDs(tn2, ids);
     }
     return false;
 }
Ejemplo n.º 31
0
 public static void giveBaseRecordNewFormID(BaseRecord rec, bool updateReference)
 {
     uint formCount = 0, refCount = 0;
     giveBaseRecordNewFormID(rec, updateReference, ref formCount, ref refCount);
 }
 /// <summary>
 /// UpdateMainTextforTH
 /// </summary>
 /// <param name="rec"></param>
 public void UpdateMainTextForTH(BaseRecord rec)
 {
     UpdateMainText(rec);
 }
Ejemplo n.º 33
0
 public virtual void InsertRecord(int index, BaseRecord br)
 {
     AddRecord(br);
 }
Ejemplo n.º 34
0
 public override int IndexOf(BaseRecord br)
 {
     return(records.IndexOf(br as Rec));
 }
Ejemplo n.º 35
0
 public virtual int IndexOf(BaseRecord br)
 {
     return(-1);
 }
Ejemplo n.º 36
0
 public abstract bool DeleteRecord(BaseRecord br);
Ejemplo n.º 37
0
 public abstract void AddRecord(BaseRecord br);
Ejemplo n.º 38
0
 public virtual void InsertRecord(int index, BaseRecord br)
 {
     AddRecord(br);
 }
Ejemplo n.º 39
0
 public abstract bool DeleteRecord(BaseRecord br);
Ejemplo n.º 40
0
 public RecordChangeEventArgs(BaseRecord rec)
 {
     record = rec;
 }
Ejemplo n.º 41
0
 public virtual int IndexOf(BaseRecord br)
 {
     return -1;
 }
Ejemplo n.º 42
0
 public static int CopyRecordsTo(BaseRecord[] src, IGroupRecord dst)
 {
     int count = 0;
     if (src != null && dst != null)
     {
         if (dst is Plugin)
         {
             var dstRec = src.Where(x => !LooseGroups.Contains(x.Name)).Select(x => x.Clone()).ToArray();
             if (dstRec.All(x => x is Record))
             {
                 // put records into appropriate groups
                 var groups = dst.Records.OfType<GroupRecord>();
                 var lookup = dstRec.GroupBy(r => r.Name).Select(g => new {key = g.Key, value = g.ToArray()})
                         .ToLookup(k => k.key, v => v.value);
                 foreach (var kvp in lookup)
                 {
                     if (LooseGroups.Contains(kvp.Key))
                     {
                         dst.AddRecords(dstRec);
                     }
                     else
                     {
                         var gr = groups.FirstOrDefault(x => x.ContentsType == kvp.Key);
                         if (gr == null)
                         {
                             gr = new GroupRecord(kvp.Key);
                             dst.AddRecord(gr);
                         }
                         foreach (var list in kvp)
                             gr.AddRecords(list);
                     }
                 }
             }
             else
             {
                 dst.AddRecords(dstRec);
             }
             // handle loose groups by creating copy of parent groups
             foreach (var srcRec in src.Where(x => LooseGroups.Contains(x.Name)))
             {
                 var dstnodes = new Stack<BaseRecord>();
                 dstnodes.Push(srcRec.Clone(recursive: true));
                 for (var n = srcRec.Parent; n is GroupRecord; n = n.Parent)
                     dstnodes.Push(n.Clone(recursive: false));
                 var par = dst as IGroupRecord;
                 foreach (var baseRecord in dstnodes)
                 {
                     if (par == null) break;
                     if (baseRecord is GroupRecord)
                     {
                         var gr = baseRecord as GroupRecord;
                         var pargr = par.Records.OfType<GroupRecord>().FirstOrDefault(x => x.IsEquivalent(gr));
                         if (pargr != null)
                         {
                             par = pargr;
                             continue;
                         }
                     }
                     par.AddRecord(baseRecord);
                     par = baseRecord as IGroupRecord;
                 }
                 count += dstnodes.Count;
             }
         }
         else
         {
             var dstRec = src.Select(x => x.Clone()).ToArray();
             dst.AddRecords(dstRec);
             count += dstRec.Count();
         }
     }
     return count;
 }
Ejemplo n.º 43
0
 protected static void FireRecordListUpdate(object sender, BaseRecord rec)
 {
     if (!HoldUpdates && ChildListChanged != null)
     {
         ChildListChanged(sender, new RecordChangeEventArgs(rec));
     }
 }
Ejemplo n.º 44
0
        private void BackgroundIncrementalSearch(BaseRecord start, bool forward)
        {
            float totalNodes = PluginList.All.Enumerate(x => x != null).Count();

            if (totalNodes == 0)
            {
                toolStripIncrInvalidRecStatus.Text      = "No Plugins Loaded";
                toolStripIncrInvalidRecStatus.ForeColor = Color.Maroon;
                if (!Properties.Settings.Default.NoWindowsSounds)
                {
                    SystemSounds.Beep.Play();
                }
                return;
            }
            int        prevCount    = 0;
            float      currentCount = 0.0f;
            BaseRecord foundNode    = null;

            toolStripIncrFindStatus.Text = "";

            // Grab selected node before searching as it can only be accessed from UI thread
            if (start == null)
            {
                start = PluginTree.SelectedRecord != null ? PluginTree.SelectedRecord : PluginTree.TopRecord;
            }

            Predicate <BaseRecord> updateFunc = n =>
            {
                if (IsBackroundProcessCanceled())     // returning true will stop it
                {
                    return(true);
                }
                var counter = (int)(++currentCount / totalNodes * 100.0f);
                if (counter != prevCount)
                {
                    prevCount = counter;
                    if (counter % 10 == 0)
                    {
                        UpdateBackgroundProgress(counter);
                    }
                }
                return(false);
            };

            var searchContext = new SearchSettings();

            var item = toolStripIncrFindType.SelectedItem as ComboHelper <SearchType, string>;

            searchContext.startNode  = start;
            searchContext.type       = item.Key;
            searchContext.text       = toolStripIncrFindText.Text;
            searchContext.partial    = !toolStripIncrFindExact.Checked;
            searchContext.wrapAround = toolStripIncrFindWrapAround.Checked;
            searchContext.first      = toolStripIncrFindText.Tag == null ? true : (bool)toolStripIncrFindText.Tag;
            searchContext.rectype    = toolStripIncrFindTypeFilter.SelectedItem as string;
            searchContext.forward    = forward;
            searchContext.updateFunc = updateFunc;

            // exclude null text searches except for when type is specified
            if (searchContext.type != SearchType.TypeEditorIdSearch && string.IsNullOrEmpty(searchContext.text))
            {
                if (!Properties.Settings.Default.NoWindowsSounds)
                {
                    SystemSounds.Beep.Play();
                }
                toolStripIncrFind.Focus();
                toolStripIncrFindText.Select();
                toolStripIncrFindText.Focus();
                return;
            }

            StartBackgroundWork(
                () => { foundNode = PerformSearch(searchContext); }
                , () =>
            {
                if (IsBackroundProcessCanceled())
                {
                    toolStripIncrFindStatus.Text      = "Search Canceled";
                    toolStripIncrFindStatus.ForeColor = Color.Black;
                }
                else
                {
                    if (foundNode != null)
                    {
                        toolStripIncrFindStatus.Text      = "Match Found";
                        toolStripIncrFindStatus.ForeColor = Color.Black;
                        PluginTree.SelectedRecord         = foundNode;
                        toolStripIncrFindText.Tag         = false;
                    }
                    else
                    {
                        toolStripIncrFindText.Tag = true;

                        toolStripIncrFindStatus.Text      = "No Matches Found";
                        toolStripIncrFindStatus.ForeColor = Color.Maroon;
                        if (!Properties.Settings.Default.NoWindowsSounds)
                        {
                            SystemSounds.Beep.Play();
                        }
                    }
                    toolStripIncrFind.Focus();
                    toolStripIncrFindText.Select();
                    toolStripIncrFindText.Focus();
                }
            }
                );
        }
Ejemplo n.º 45
0
 public RecordChangeEventArgs(BaseRecord rec)
 {
     record = rec;
 }
Ejemplo n.º 46
0
 public override int IndexOf(BaseRecord br)
 {
     return(pluginList.IndexOf(br as Plugin));
 }
Ejemplo n.º 47
0
 public override int IndexOf(BaseRecord br)
 {
     return records.IndexOf(br as Rec);
 }
Ejemplo n.º 48
0
 public override int IndexOf(BaseRecord br)
 {
     return pluginList.IndexOf(br as Plugin);
 }
Ejemplo n.º 49
0
 public override bool DeleteRecord(BaseRecord br)
 {
     var sr = br as SubRecord;
     if (sr == null) return false;
     return SubRecords.Remove(sr);
 }
Ejemplo n.º 50
0
 protected static void FireRecordDeleted(object sender, BaseRecord rec)
 {
     if (!HoldUpdates && RecordDeleted != null)
     {
         RecordDeleted(sender, new RecordChangeEventArgs(rec));
     }
 }
Ejemplo n.º 51
0
 public abstract void AddRecord(BaseRecord br);