private void invertSelectedToolStripMenuItem_Click(object sender, EventArgs e) { foreach (var info in _dataSet.GetObjectInfoList()) { _dataSet.SelectObjects(!_dataSet.IsSelecting(info), info); } _dataSet.DoObjectSelectionChanged(); }
private string formatNameText(MotionObjectInfo info) { MotionDataSet dataSet = _dataSet; if (dataSet == null) { return(""); } string name = info.Name; if (_currentGroup != "") { name = name.Substring(_currentGroup.Length + 1); } return(formatNameText(name, dataSet.IsSelecting(info), info.IsVisible)); }
private void listObjectInfo_SelectedIndexChanged(object sender, EventArgs e) { // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_selectionChanging) { return; } _selectionChanging = true; try { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } HashSet <uint> selectedIds = new HashSet <uint>(); foreach (ListViewItem item in listObjectInfo.SelectedItems) { uint id = uint.Parse(item.SubItems[1].Text); selectedIds.Add(id); } HashSet <uint> changedIds = new HashSet <uint>(); foreach (var info in dataSet.GetObjectInfoList()) { bool selected = selectedIds.Contains(info.Id); if (dataSet.IsSelecting(info) != selected) { changedIds.Add(info.Id); dataSet.SelectObjects(selected, info); } } foreach (ListViewItem item in listObjectInfo.Items) { uint id = uint.Parse(item.SubItems[1].Text); if (changedIds.Contains(id)) { MotionObjectInfo info = dataSet.GetObjectInfoById(id); if (info != null) { item.Text = formatNameText(info); if (dataSet.IsSelecting(info)) { item.EnsureVisible(); item.Font = new Font(item.Font, FontStyle.Bold); } else { item.Font = new Font(item.Font, FontStyle.Regular); } } } } dataSet.DoObjectSelectionChanged(); this.DoUpdateObjectInfoControls(); } finally { _selectionChanging = false; } } finally { _mutex.ReleaseMutex(); } }
public void OnSelectionChanged(object sender, EventArgs e) { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (this.InvokeRequired) { this.BeginInvoke(new EventHandler(OnSelectionChanged), sender, e); return; } // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_selectionChanging) { return; } _selectionChanging = true; try { // リストビューの更新 listObjectInfo.SuspendLayout(); try { var infoList = dataSet.GetSelectedObjectInfoList(); // 選択されたオブジェクトが現在の選択グループ以外のものを含む場合にグループの選択を上位に変更 if (infoList.Count != 0) { string common = PathEx.GetCommonDir(infoList.Select(info => info.Name).ToList()); if (_currentGroup != common && !PathEx.IsSubPath(common, _currentGroup)) { _currentGroup = common; this.DoSelectedGroupChanged(); return; } } ListViewItem lastSelected = null; // 選択が変更されたオブジェクトについてのリストビューのアイテムを更新 foreach (ListViewItem item in listObjectInfo.Items) { uint id = uint.Parse(item.SubItems[1].Text); var info = dataSet.GetObjectInfoById(id); if (info != null) { if (item.Selected != dataSet.IsSelecting(info)) { if (dataSet.IsSelecting(info)) { lastSelected = item; } item.Text = formatNameText(info); item.Selected = dataSet.IsSelecting(info); item.Font = new Font(item.Font, dataSet.IsSelecting(info) ? FontStyle.Bold : FontStyle.Regular); } } } if (lastSelected != null) { lastSelected.EnsureVisible(); } } finally { listObjectInfo.ResumeLayout(); } this.DoUpdateObjectInfoControls(); } finally { _selectionChanging = false; } } finally { _mutex.ReleaseMutex(); } }
private void DoSelectedGroupChanged() { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (this.InvokeRequired) { this.Invoke(new Action(this.DoSelectedGroupChanged)); return; } MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } if (!_mutex.WaitOne(0)) { return; } try { // グループの選択 if (_currentGroup == "") { textGroup.Text = PathEx.PathSeparator.ToString(); groupBoxInformation.Text = "<Object Information>"; } else { textGroup.Text = _currentGroup; groupBoxInformation.Text = string.Format("<Object Information - {0}>", _currentGroup); } // グループ外のオブジェクトの選択をやめる foreach (var info in dataSet.GetObjectInfoList()) { if (!PathEx.IsSubPath(info.Name, _currentGroup)) { dataSet.SelectObjects(false, info); } } // 前回のフォーカスを持ったオブジェクト uint? prevFocusedId = null; ListViewItem focusedItem = listObjectInfo.FocusedItem; if (focusedItem != null) { prevFocusedId = uint.Parse(focusedItem.SubItems[1].Text); } // 現在の属するグループにEnsureVisible TreeNode currentNode; if (_nodeByPath.TryGetValue(_currentGroup, out currentNode)) { invokeControl(treeViewInfo, () => { treeViewInfo.SelectedNode = currentNode; currentNode.EnsureVisible(); }); } listObjectInfo.SuspendLayout(); try { listObjectInfo.Items.Clear(); var infoList = dataSet.GetObjectInfoListByGroup(_currentGroup); ListViewItem lastSelected = null; ListViewItem lastFocused = null; foreach (var info in infoList) { ListViewItem item = new ListViewItem(formatNameText(info)); item.UseItemStyleForSubItems = false; ListViewItem.ListViewSubItem id = new ListViewItem.ListViewSubItem(item, info.Id.ToString()); ListViewItem.ListViewSubItem type = new ListViewItem.ListViewSubItem(item, info.ObjectType.Name); item.SubItems.Add(id); item.SubItems.Add(type); id.BackColor = Color.FromArgb(255, info.Color); id.ForeColor = ColorEx.GetComplementaryColor(id.BackColor); item.Selected = dataSet.IsSelecting(info); listObjectInfo.Items.Add(item); if (dataSet.IsSelecting(info)) { lastSelected = item; } if (prevFocusedId.HasValue && info.Id == prevFocusedId.Value) { lastFocused = item; } } if (lastSelected != null) { lastSelected.EnsureVisible(); } if (lastFocused != null) { lastFocused.Focused = true; } } finally { listObjectInfo.ResumeLayout(); } dataSet.DoObjectSelectionChanged(); } finally { _mutex.ReleaseMutex(); } }
public void AttachDataSet(MotionDataSet dataSet, IEnumerable <Type> targetTypes, bool?selectedOrNotSelected) { this.AttachDataSet(dataSet, new Predicate <MotionObjectInfo>(info => targetTypes.Any(type => info.IsTypeOf(type))), new Predicate <MotionObjectInfo>(info => selectedOrNotSelected.HasValue ? dataSet.IsSelecting(info) == selectedOrNotSelected.Value : false)); }