OSDN Git Service

SettingLocalクラスの Width* および DisplayIndex* を ColumnsWidth/ColumnsOrder に移行
authorKimura Youichi <kim.upsilon@bucyou.net>
Fri, 15 Apr 2022 14:05:25 +0000 (23:05 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Fri, 15 Apr 2022 20:04:59 +0000 (05:04 +0900)
OpenTween/Setting/SettingLocal.cs
OpenTween/Tween.cs

index 001a808..2e36365 100644 (file)
@@ -61,22 +61,109 @@ namespace OpenTween
         public string StatusText = "";
 
         public bool UseRecommendStatus = false;
-        public int Width1 = 48;
-        public int Width2 = 80;
-        public int Width3 = 290;
-        public int Width4 = 120;
-        public int Width5 = 50;
-        public int Width6 = 16;
-        public int Width7 = 32;
-        public int Width8 = 50;
-        public int DisplayIndex1 = 2;
-        public int DisplayIndex2 = 3;
-        public int DisplayIndex3 = 4;
-        public int DisplayIndex4 = 5;
-        public int DisplayIndex5 = 6;
-        public int DisplayIndex6 = 1;
-        public int DisplayIndex7 = 0;
-        public int DisplayIndex8 = 7;
+
+        [XmlIgnore]
+        public int[] ColumnsWidth { get; } = { 48, 80, 290, 120, 50, 16, 32, 50 };
+
+        public int Width1
+        {
+            get => this.ColumnsWidth[0];
+            set => this.ColumnsWidth[0] = value;
+        }
+
+        public int Width2
+        {
+            get => this.ColumnsWidth[1];
+            set => this.ColumnsWidth[1] = value;
+        }
+
+        public int Width3
+        {
+            get => this.ColumnsWidth[2];
+            set => this.ColumnsWidth[2] = value;
+        }
+
+        public int Width4
+        {
+            get => this.ColumnsWidth[3];
+            set => this.ColumnsWidth[3] = value;
+        }
+
+        public int Width5
+        {
+            get => this.ColumnsWidth[4];
+            set => this.ColumnsWidth[4] = value;
+        }
+
+        public int Width6
+        {
+            get => this.ColumnsWidth[5];
+            set => this.ColumnsWidth[5] = value;
+        }
+
+        public int Width7
+        {
+            get => this.ColumnsWidth[6];
+            set => this.ColumnsWidth[6] = value;
+        }
+
+        public int Width8
+        {
+            get => this.ColumnsWidth[7];
+            set => this.ColumnsWidth[7] = value;
+        }
+
+        [XmlIgnore]
+        public int[] ColumnsOrder { get; } = { 2, 3, 4, 5, 6, 1, 0, 7 };
+
+        public int DisplayIndex1
+        {
+            get => this.ColumnsOrder[0];
+            set => this.ColumnsOrder[0] = value;
+        }
+
+        public int DisplayIndex2
+        {
+            get => this.ColumnsOrder[1];
+            set => this.ColumnsOrder[1] = value;
+        }
+
+        public int DisplayIndex3
+        {
+            get => this.ColumnsOrder[2];
+            set => this.ColumnsOrder[2] = value;
+        }
+
+        public int DisplayIndex4
+        {
+            get => this.ColumnsOrder[3];
+            set => this.ColumnsOrder[3] = value;
+        }
+
+        public int DisplayIndex5
+        {
+            get => this.ColumnsOrder[4];
+            set => this.ColumnsOrder[4] = value;
+        }
+
+        public int DisplayIndex6
+        {
+            get => this.ColumnsOrder[5];
+            set => this.ColumnsOrder[5] = value;
+        }
+
+        public int DisplayIndex7
+        {
+            get => this.ColumnsOrder[6];
+            set => this.ColumnsOrder[6] = value;
+        }
+
+        public int DisplayIndex8
+        {
+            get => this.ColumnsOrder[7];
+            set => this.ColumnsOrder[7] = value;
+        }
+
         public string BrowserPath = "";
         public ProxyType ProxyType = ProxyType.IE;
         public string ProxyAddress = "127.0.0.1";
index d0572a6..d8c0b92 100644 (file)
@@ -399,8 +399,8 @@ namespace OpenTween
                     {
                         var widthScaleFactor = this.CurrentAutoScaleDimensions.Width / this.settings.Local.ScaleDimension.Width;
 
-                        columns[0].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width1);
-                        columns[1].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width3);
+                        columns[0].Width = ScaleBy(widthScaleFactor, this.settings.Local.ColumnsWidth[0]);
+                        columns[1].Width = ScaleBy(widthScaleFactor, this.settings.Local.ColumnsWidth[2]);
                         columns[0].DisplayIndex = 0;
                         columns[1].DisplayIndex = 1;
                     }
@@ -436,26 +436,10 @@ namespace OpenTween
                     {
                         var widthScaleFactor = this.CurrentAutoScaleDimensions.Width / this.settings.Local.ScaleDimension.Width;
 
-                        columns[0].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width1);
-                        columns[1].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width2);
-                        columns[2].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width3);
-                        columns[3].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width4);
-                        columns[4].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width5);
-                        columns[5].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width6);
-                        columns[6].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width7);
-                        columns[7].Width = ScaleBy(widthScaleFactor, this.settings.Local.Width8);
-
-                        var displayIndex = new[]
-                        {
-                            this.settings.Local.DisplayIndex1, this.settings.Local.DisplayIndex2,
-                            this.settings.Local.DisplayIndex3, this.settings.Local.DisplayIndex4,
-                            this.settings.Local.DisplayIndex5, this.settings.Local.DisplayIndex6,
-                            this.settings.Local.DisplayIndex7, this.settings.Local.DisplayIndex8,
-                        };
-
-                        foreach (var i in Enumerable.Range(0, displayIndex.Length))
+                        foreach (var (column, index) in columns.WithIndex())
                         {
-                            columns[i].DisplayIndex = displayIndex[i];
+                            column.Width = ScaleBy(widthScaleFactor, this.settings.Local.ColumnsWidth[index]);
+                            column.DisplayIndex = this.settings.Local.ColumnsOrder[index];
                         }
                     }
                     else
@@ -8483,62 +8467,24 @@ namespace OpenTween
 
         private void MyList_ColumnReordered(object sender, ColumnReorderedEventArgs e)
         {
-            var lst = (DetailsListView)sender;
-            if (this.settings.Local == null) return;
-
             if (this.iconCol)
             {
-                this.settings.Local.Width1 = lst.Columns[0].Width;
-                this.settings.Local.Width3 = lst.Columns[1].Width;
+                e.Cancel = true;
+                return;
             }
-            else
-            {
-                var darr = new int[lst.Columns.Count];
-                for (var i = 0; i < lst.Columns.Count; i++)
-                {
-                    darr[lst.Columns[i].DisplayIndex] = i;
-                }
-                MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
 
-                for (var i = 0; i < lst.Columns.Count; i++)
-                {
-                    switch (darr[i])
-                    {
-                        case 0:
-                            this.settings.Local.DisplayIndex1 = i;
-                            break;
-                        case 1:
-                            this.settings.Local.DisplayIndex2 = i;
-                            break;
-                        case 2:
-                            this.settings.Local.DisplayIndex3 = i;
-                            break;
-                        case 3:
-                            this.settings.Local.DisplayIndex4 = i;
-                            break;
-                        case 4:
-                            this.settings.Local.DisplayIndex5 = i;
-                            break;
-                        case 5:
-                            this.settings.Local.DisplayIndex6 = i;
-                            break;
-                        case 6:
-                            this.settings.Local.DisplayIndex7 = i;
-                            break;
-                        case 7:
-                            this.settings.Local.DisplayIndex8 = i;
-                            break;
-                    }
-                }
-                this.settings.Local.Width1 = lst.Columns[0].Width;
-                this.settings.Local.Width2 = lst.Columns[1].Width;
-                this.settings.Local.Width3 = lst.Columns[2].Width;
-                this.settings.Local.Width4 = lst.Columns[3].Width;
-                this.settings.Local.Width5 = lst.Columns[4].Width;
-                this.settings.Local.Width6 = lst.Columns[5].Width;
-                this.settings.Local.Width7 = lst.Columns[6].Width;
-                this.settings.Local.Width8 = lst.Columns[7].Width;
-            }
+            var lst = (DetailsListView)sender;
+            var columnsCount = lst.Columns.Count;
+
+            var darr = new int[columnsCount];
+            for (var i = 0; i < columnsCount; i++)
+                darr[lst.Columns[i].DisplayIndex] = i;
+
+            MyCommon.MoveArrayItem(darr, e.OldDisplayIndex, e.NewDisplayIndex);
+
+            for (var i = 0; i < columnsCount; i++)
+                this.settings.Local.ColumnsOrder[darr[i]] = i;
+
             this.MarkSettingLocalModified();
             this.isColumnChanged = true;
         }
@@ -8551,57 +8497,26 @@ namespace OpenTween
             var modified = false;
             if (this.iconCol)
             {
-                if (this.settings.Local.Width1 != lst.Columns[0].Width)
+                if (this.settings.Local.ColumnsWidth[0] != lst.Columns[0].Width)
                 {
-                    this.settings.Local.Width1 = lst.Columns[0].Width;
+                    this.settings.Local.ColumnsWidth[0] = lst.Columns[0].Width;
                     modified = true;
                 }
-                if (this.settings.Local.Width3 != lst.Columns[1].Width)
+                if (this.settings.Local.ColumnsWidth[2] != lst.Columns[1].Width)
                 {
-                    this.settings.Local.Width3 = lst.Columns[1].Width;
+                    this.settings.Local.ColumnsWidth[2] = lst.Columns[1].Width;
                     modified = true;
                 }
             }
             else
             {
-                if (this.settings.Local.Width1 != lst.Columns[0].Width)
-                {
-                    this.settings.Local.Width1 = lst.Columns[0].Width;
-                    modified = true;
-                }
-                if (this.settings.Local.Width2 != lst.Columns[1].Width)
+                var columnsCount = lst.Columns.Count;
+                for (var i = 0; i < columnsCount; i++)
                 {
-                    this.settings.Local.Width2 = lst.Columns[1].Width;
-                    modified = true;
-                }
-                if (this.settings.Local.Width3 != lst.Columns[2].Width)
-                {
-                    this.settings.Local.Width3 = lst.Columns[2].Width;
-                    modified = true;
-                }
-                if (this.settings.Local.Width4 != lst.Columns[3].Width)
-                {
-                    this.settings.Local.Width4 = lst.Columns[3].Width;
-                    modified = true;
-                }
-                if (this.settings.Local.Width5 != lst.Columns[4].Width)
-                {
-                    this.settings.Local.Width5 = lst.Columns[4].Width;
-                    modified = true;
-                }
-                if (this.settings.Local.Width6 != lst.Columns[5].Width)
-                {
-                    this.settings.Local.Width6 = lst.Columns[5].Width;
-                    modified = true;
-                }
-                if (this.settings.Local.Width7 != lst.Columns[6].Width)
-                {
-                    this.settings.Local.Width7 = lst.Columns[6].Width;
-                    modified = true;
-                }
-                if (this.settings.Local.Width8 != lst.Columns[7].Width)
-                {
-                    this.settings.Local.Width8 = lst.Columns[7].Width;
+                    if (this.settings.Local.ColumnsWidth[i] == lst.Columns[i].Width)
+                        continue;
+
+                    this.settings.Local.ColumnsWidth[i] = lst.Columns[i].Width;
                     modified = true;
                 }
             }