OSDN Git Service

不要な ListView.SelectedIndices への参照を削除
[opentween/open-tween.git] / OpenTween / ControlTransaction.cs
index b9e6317..2031159 100644 (file)
@@ -19,6 +19,8 @@
 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
 // Boston, MA 02110-1301, USA.
 
+#nullable enable
+
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -34,24 +36,16 @@ namespace OpenTween
     public static class ControlTransaction
     {
         public static IDisposable Update(ListView control)
-        {
-            return new Transaction<ListView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
-        }
+            => new Transaction<ListView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
 
         public static IDisposable Update(ListBox control)
-        {
-            return new Transaction<ListBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
-        }
+            => new Transaction<ListBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
 
         public static IDisposable Update(ComboBox control)
-        {
-            return new Transaction<ComboBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
-        }
+            => new Transaction<ComboBox>(control, x => x.BeginUpdate(), x => x.EndUpdate());
 
         public static IDisposable Update(TreeView control)
-        {
-            return new Transaction<TreeView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
-        }
+            => new Transaction<TreeView>(control, x => x.BeginUpdate(), x => x.EndUpdate());
 
         public static IDisposable Update(Control control)
         {
@@ -63,19 +57,13 @@ namespace OpenTween
         }
 
         public static IDisposable Layout(Control control)
-        {
-            return Layout(control, performLayout: true);
-        }
+            => Layout(control, performLayout: true);
 
         public static IDisposable Layout(Control control, bool performLayout)
-        {
-            return new Transaction<Control>(control, x => x.SuspendLayout(), x => x.ResumeLayout(performLayout));
-        }
+            => new Transaction<Control>(control, x => x.SuspendLayout(), x => x.ResumeLayout(performLayout));
 
         public static IDisposable Init(ISupportInitialize control)
-        {
-            return new Transaction<ISupportInitialize>(control, x => x.BeginInit(), x => x.EndInit());
-        }
+            => new Transaction<ISupportInitialize>(control, x => x.BeginInit(), x => x.EndInit());
 
         public static IDisposable Cursor(Control control, Cursor newCursor)
         {
@@ -84,6 +72,20 @@ namespace OpenTween
             return new Transaction<Control>(control, x => x.Cursor = newCursor, x => x.Cursor = oldCursor);
         }
 
+        public static IDisposable Enabled(Control control)
+        {
+            var oldState = control.Enabled;
+
+            return new Transaction<Control>(control, x => x.Enabled = true, x => x.Enabled = oldState);
+        }
+
+        public static IDisposable Disabled(Control control)
+        {
+            var oldState = control.Enabled;
+
+            return new Transaction<Control>(control, x => x.Enabled = false, x => x.Enabled = oldState);
+        }
+
         private class Transaction<T> : IDisposable
         {
             private readonly T control;
@@ -102,9 +104,7 @@ namespace OpenTween
             }
 
             public void Dispose()
-            {
-                this.endTransaction(this.control);
-            }
+                => this.endTransaction(this.control);
         }
     }
 }