private void invertSelectedToolStripMenuItem_Click(object sender, EventArgs e) { foreach (var info in _dataSet.GetObjectInfoList()) { _dataSet.SelectObjects(!_dataSet.IsSelecting(info), info); } _dataSet.DoObjectSelectionChanged(); }
private void OnDataSetSelectedChanged(object sender, EventArgs e) { if (this.InvokeRequired) { this.Invoke(new EventHandler(OnDataSetSelectedChanged), sender, e); return; } if (_dataSet == null) { listSelect.Items.Clear(); return; } lock (_dataSet) { var targetItems = _dataSet.GetObjectInfoList(info => _targetCondition(info)); var selectedItems = _dataSet.GetObjectInfoList(info => _targetCondition(info) && _defaultSelectedCondition(info)); _targetInfoList = targetItems; _isSelectionSetting = true; try { listSelect.Items.Clear(); foreach (MotionObjectInfo info in _targetInfoList) { listSelect.Items.Add(info.Name); } listSelect.SelectedIndices.Clear(); for (int i = 0; i < targetItems.Count; i++) { MotionObjectInfo info = targetItems[i]; if (selectedItems.Contains(info)) { listSelect.SelectedIndices.Add(i); } } } finally { _isSelectionSetting = false; } } }
/// <summary> /// 外部でMotionDataSetのMotionObjectInfoの内容が変更されたので,ツリー及びオブジェクトの選択を変更する. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnObjectInfoSetChanged(object sender, EventArgs e) { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (treeViewInfo.InvokeRequired) { treeViewInfo.BeginInvoke(new EventHandler(OnObjectInfoSetChanged), sender, e); return; } MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_selectionChanging) { return; } _selectionChanging = true; try { HashSet <string> newGroups = new HashSet <string>(); newGroups.Add(""); foreach (var info in dataSet.GetObjectInfoList()) { string path = PathEx.DirName(info.Name); while (path != "") { if (!newGroups.Contains(path)) { newGroups.Add(path); } path = PathEx.DirName(path); } } HashSet <string> oldGroups = new HashSet <string>(_nodeByPath.Keys); if (newGroups.All(g => oldGroups.Contains(g)) && oldGroups.All(g => newGroups.Contains(g))) { // 変化なし } else { treeViewInfo.SuspendLayout(); try { treeViewInfo.Nodes.Clear(); _nodeByPath.Clear(); _nodeByPath[""] = new TreeNode("/"); foreach (var info in dataSet.GetObjectInfoList()) { string path = PathEx.DirName(info.Name); while (path != "") { if (!_nodeByPath.ContainsKey(path)) { _nodeByPath[path] = new TreeNode(PathEx.BaseName(path)); } path = PathEx.DirName(path); } } foreach (var pair in _nodeByPath) { string path = pair.Key; if (path != "") { string parent = PathEx.DirName(path); _nodeByPath[parent].Nodes.Add(pair.Value); } } treeViewInfo.Nodes.Add(_nodeByPath[""]); } finally { treeViewInfo.ResumeLayout(); } } this.DoSelectedGroupChanged(); this.DoUpdateObjectInfoControls(); } finally { _selectionChanging = false; } } finally { _mutex.ReleaseMutex(); } }
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(); } }
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(); } }