Beispiel #1
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);
        }
Beispiel #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)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);
        }