/* ----------------------------------------------------------------- */ /// /// Replace /// /// <summary> /// 指定されたインデックスの内容を置換します。 /// </summary> /// /* ----------------------------------------------------------------- */ public void Replace <T>(int index, T item) { if (index < 0 || index >= Count) { return; } var args = new ValueCancelEventArgs <int>(index); OnReplacing(args); if (args.Cancel || VirtualMode) { return; } var focused = Items[index].Focused; var selected = Items[index].Selected; Items[index] = Converter?.Convert(item) ?? new System.Windows.Forms.ListViewItem(item.ToString()); HackAlignmentBug(); Items[index].Focused = focused; Items[index].Selected = selected; OnReplaced(new ValueEventArgs <int>(index)); }
/* ----------------------------------------------------------------- */ /// /// WhenLocked /// /// <summary> /// ファイルがロックされている時に実行されるハンドラです。 /// </summary> /// /* ----------------------------------------------------------------- */ private void WhenLocked(object sender, ValueCancelEventArgs <string> e) { var result = SyncWait(() => Views.ShowMessage( string.Format( Properties.Resources.MessageLock, System.IO.Path.GetFileName(e.Value) ), MessageBoxButtons.RetryCancel)); e.Cancel = (result == DialogResult.Cancel); }
/* ----------------------------------------------------------------- */ /// /// OnLocked /// /// <summary> /// Locked イベントを発生させます。 /// </summary> /// /* ----------------------------------------------------------------- */ protected virtual void OnLocked(ValueCancelEventArgs <string> e) { if (Locked != null) { Locked(this, e); } else { e.Cancel = true; } }
/* ----------------------------------------------------------------- */ /// /// Insert /// /// <summary> /// 指定されたインデックスに項目を追加します。 /// </summary> /// /* ----------------------------------------------------------------- */ public void Insert <T>(int index, T item) { var args = new ValueCancelEventArgs <int>(index); OnAdding(args); if (args.Cancel || VirtualMode) { return; } Items.Insert(index, Converter?.Convert(item) ?? new System.Windows.Forms.ListViewItem(item.ToString()) ); HackAlignmentBug(); OnAdded(new ValueEventArgs <int>(index)); }
/* ----------------------------------------------------------------- */ /// /// RemoveItems /// /// <summary> /// 項目を削除します。 /// </summary> /// /* ----------------------------------------------------------------- */ public void RemoveItems(IEnumerable <int> indices) { var args = new ValueCancelEventArgs <int[]>(indices.ToArray()); OnRemoving(args); if (args.Cancel || VirtualMode) { return; } foreach (var index in indices.OrderByDescending(x => x)) { if (index < 0 || index >= Count) { continue; } Items.RemoveAt(index); } OnRemoved(new ValueEventArgs <int[]>(indices.ToArray())); }
/* ----------------------------------------------------------------- */ /// /// OnRemoving /// /// <summary> /// Removing イベントを発生させます。 /// </summary> /// /* ----------------------------------------------------------------- */ protected virtual void OnRemoving(ValueCancelEventArgs <int[]> e) => Removing?.Invoke(this, e);
/* ----------------------------------------------------------------- */ /// /// OnAdding /// /// <summary> /// Adding イベントを発生させます。 /// </summary> /// /* ----------------------------------------------------------------- */ protected virtual void OnAdding(ValueCancelEventArgs <int> e) => Adding?.Invoke(this, e);
public void ValueCancelEventArgs_Cancel() { var src = new ValueCancelEventArgs <int>(1); Assert.That(src.Cancel, Is.False); }