コード例 #1
0
        public void AddTemplate(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            var template           = Helper.Settings.Data.Data.General.Templates.Templates.Where(p => p.Options.Any(x => x.Name == "nickname" && x.Values.Any(y => y.Value.ToString() == item.Text))).First();

            TableBlock block = new TableBlock(this.GetNewBlockId(), this.Data.MaxId++, template, this.Data.TemplateIndex);

            block.SetVisibleIfPossible();

            if (this.Data.Blocks.Find(x => x.Block.Options.Any(y => y.Name == "nickname" && y.Values.Any(z => z.Value.ToString() == item.Text))) != null)
            {
                MessageBox.Show("An item with the nickname of the template already exists within this document.");
                return;
            }

            // add actual block
            this.AddBlocks(new List <TableBlock> {
                block
            });
        }
コード例 #2
0
        public void ChangeBlocks(PropertyBlock[] propertyBlocks)
        {
            List <TableBlock> newBlocks = new List <TableBlock>();
            List <TableBlock> oldBlocks = new List <TableBlock>();

            for (int i = 0; i < propertyBlocks.Length; ++i)
            {
                TableBlock oldBlock = (TableBlock)this.objectListView1.SelectedObjects[i];
                TableBlock newBlock = ObjectClone.Clone(oldBlock);

                oldBlocks.Add(oldBlock);
                newBlocks.Add(newBlock);

                PropertyBlock propertyBlock = propertyBlocks[i];

                // set comments (last property option)
                string comments = (string)propertyBlock[propertyBlock.Count - 1].Value;
                newBlock.Block.Comments = comments;

                // set options
                for (int j = 0; j < propertyBlock.Count - 1; ++j)
                {
                    List <EditorIniEntry> options = newBlock.Block.Options[j].Values;

                    if (propertyBlock[j].Value is PropertySubOptions propertyOptions)
                    {
                        options.Clear();

                        // loop all sub values in the sub value collection
                        foreach (PropertyOption value in propertyOptions)
                        {
                            string text = ((string)value.Value).Trim();

                            if (!this.CanCast(text, value.Type))
                            {
                                if (Helper.Settings.Data.Data.General.AlertIncorrectPropertyType)
                                {
                                    MessageBox.Show(string.Format(Strings.InvalidIniPropertyNotificationText, value.Name, value.Type.ToString()), Strings.InvalidIniPropertyNotificationCaption, MessageBoxButtons.OK);
                                }
                                this.ChangeBlocks(newBlocks, oldBlocks);
                                return;
                            }

                            if (text.Length != 0)
                            {
                                if (text.Contains(Environment.NewLine))
                                {
                                    string[]      lines      = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                    List <object> subOptions = new List <object>();
                                    for (int k = 1; k < lines.Length; ++k)
                                    {
                                        subOptions.Add(lines[k].Trim());
                                    }

                                    options.Add(new EditorIniEntry(lines[0], subOptions));
                                }
                                else
                                {
                                    options.Add(new EditorIniEntry(text));
                                }
                            }
                        }
                    }
                    else
                    {
                        var    blk  = propertyBlock[j];
                        string text = ((string)blk.Value).Trim();
                        if (!this.CanCast(text, propertyBlock[j].Type))
                        {
                            if (Helper.Settings.Data.Data.General.AlertIncorrectPropertyType)
                            {
                                MessageBox.Show(string.Format(Strings.InvalidIniPropertyNotificationText, blk.Name, blk.Type.ToString()), Strings.InvalidIniPropertyNotificationCaption, MessageBoxButtons.OK);
                            }
                            this.ChangeBlocks(newBlocks, oldBlocks);
                            return;
                        }

                        if (text.Length != 0)
                        {
                            if (options.Count > 0)
                            {
                                // check if value is different
                                if (options[0].Value.ToString() != text)
                                {
                                    options[0].Value = text;
                                }
                            }
                            else
                            {
                                options.Add(new EditorIniEntry(text));
                            }
                        }
                        else
                        {
                            options.Clear();
                        }

                        // change data in listview
                        if (newBlock.Block.MainOptionIndex == j)
                        {
                            newBlock.Name = text;
                        }
                    }
                }

                // update block object type
                this.SetBlockType(newBlock);

                // make block visible if it can be made visible now
                if (oldBlock.ObjectType == ContentType.None)
                {
                    newBlock.SetVisibleIfPossible();
                }

                // mark block as modified
                newBlock.SetModifiedChanged();
            }

            this.ChangeBlocks(newBlocks, oldBlocks);
        }
コード例 #3
0
        private void AddBlocks(List <TableBlock> blocks)
        {
            List <TableBlock> newAdditionalBlocks = new List <TableBlock>();
            List <TableBlock> oldBlocks           = new List <TableBlock>();

            for (int i = 0; i < blocks.Count; ++i)
            {
                TableBlock block = blocks[i];

                // set block to be modified
                block.Modified = TableModified.ChangedAdded;

                // set archetype of block and make visible if possible
                if (block.Archetype == null)
                {
                    this.SetBlockType(block);
                    block.SetVisibleIfPossible();
                }

                // check if block which can only exist once already exists
                Template.Block templateBlock = Helper.Template.Data.Files[this.Data.TemplateIndex].Blocks.Values[block.Block.TemplateIndex];
                if (!templateBlock.Multiple)
                {
                    for (int j = 0; j < this.Data.Blocks.Count; ++j)
                    {
                        TableBlock existingBlock = this.Data.Blocks[j];

                        // block already exists
                        if (existingBlock.Block.TemplateIndex == block.Block.TemplateIndex)
                        {
                            block.Index = existingBlock.Index;
                            block.Id    = existingBlock.Id;

                            // overwrite block if it can only exist once
                            newAdditionalBlocks.Add(block);
                            oldBlocks.Add(existingBlock);

                            // remove overwritten block from new ones
                            blocks.RemoveAt(i);
                            --i;
                        }
                    }
                }
            }

            if (newAdditionalBlocks.Count == 0)
            {
                this.undoManager.Execute(new ChangedData
                {
                    Type      = ChangedType.Add,
                    NewBlocks = blocks,
                });
            }
            else
            {
                if (blocks.Count == 0)
                {
                    this.undoManager.Execute(new ChangedData
                    {
                        Type      = ChangedType.Edit,
                        NewBlocks = newAdditionalBlocks,
                        OldBlocks = oldBlocks,
                    });
                }
                else
                {
                    this.undoManager.Execute(new ChangedData
                    {
                        Type                = ChangedType.AddAndEdit,
                        NewBlocks           = blocks,
                        NewAdditionalBlocks = newAdditionalBlocks,
                        OldBlocks           = oldBlocks,
                    });
                }
            }
        }
コード例 #4
0
        public void ChangeBlocks(PropertyBlock[] propertyBlocks)
        {
            List <TableBlock> newBlocks = new List <TableBlock>();
            List <TableBlock> oldBlocks = new List <TableBlock>();

            for (int i = 0; i < propertyBlocks.Length; ++i)
            {
                TableBlock oldBlock = (TableBlock)objectListView1.SelectedObjects[i];
                TableBlock newBlock = ObjectClone.Clone(oldBlock);

                oldBlocks.Add(oldBlock);
                newBlocks.Add(newBlock);

                PropertyBlock propertyBlock = propertyBlocks[i];

                // set comments (last property option)
                string comments = (string)propertyBlock[propertyBlock.Count - 1].Value;
                newBlock.Block.Comments = comments;

                // set options
                for (int j = 0; j < propertyBlock.Count - 1; ++j)
                {
                    List <EditorINIEntry> options = newBlock.Block.Options[j].Values;

                    PropertySubOptions propertyOptions = propertyBlock[j].Value as PropertySubOptions;
                    if (propertyOptions != null)
                    {
                        options.Clear();

                        //loop all sub values in the sub value collection
                        foreach (PropertyOption value in propertyOptions)
                        {
                            string text = ((string)value.Value).Trim();
                            if (text.Length != 0)
                            {
                                if (text.Contains(Environment.NewLine))
                                {
                                    string[]      lines      = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                    List <object> subOptions = new List <object>();
                                    for (int k = 1; k < lines.Length; ++k)
                                    {
                                        subOptions.Add(lines[k].Trim());
                                    }

                                    options.Add(new EditorINIEntry(lines[0], subOptions));
                                }
                                else
                                {
                                    options.Add(new EditorINIEntry(text));
                                }
                            }
                        }
                    }
                    else
                    {
                        string text = ((string)propertyBlock[j].Value).Trim();
                        if (text.Length != 0)
                        {
                            if (options.Count > 0)
                            {
                                //check if value is different
                                if (options[0].Value.ToString() != text)
                                {
                                    options[0].Value = text;
                                }
                            }
                            else
                            {
                                options.Add(new EditorINIEntry(text));
                            }
                        }
                        else
                        {
                            options.Clear();
                        }

                        //change data in listview
                        if (newBlock.Block.MainOptionIndex == j)
                        {
                            newBlock.Name = text;
                        }
                    }
                }

                // update block object type
                SetBlockType(newBlock);

                // make block visible if it can be made visible now
                if (oldBlock.ObjectType == ContentType.None)
                {
                    newBlock.SetVisibleIfPossible();
                }

                // mark block as modified
                newBlock.SetModifiedChanged();
            }

            ChangeBlocks(newBlocks, oldBlocks);
        }