private void DoUpdateObjectInfoControls() { // フォーム以外のスレッドから呼び出された場合にフォームのスレッドで処理する if (this.InvokeRequired) { this.BeginInvoke(new Action(DoUpdateObjectInfoControls)); return; } // 多重呼び出しの禁止 if (!_mutex.WaitOne(0)) { return; } try { if (_infoContentChanging) { return; } _infoContentChanging = true; try { // _dataSetの途中変更を防ぐ MotionDataSet dataSet = _dataSet; if (dataSet == null) { return; } var infoList = dataSet.GetSelectedObjectInfoList(); // その他のコントロールの更新 if (infoList.Count == 0) { // 選択なしのとき textColor.Enabled = false; textName.Enabled = false; numericColorAlpha.Enabled = false; checkVisible.Enabled = false; textGroup.Enabled = false; textColor.BackColor = Color.White; textColor.ForeColor = Color.Black; textColor.Text = "Color"; textName.Text = "Nothing selected"; numericColorAlpha.Value = 0; checkVisible.Checked = false; } else { textColor.Enabled = true; textName.Enabled = true; numericColorAlpha.Enabled = true; checkVisible.Enabled = true; textGroup.Enabled = true; // 名前 if (infoList.Count == 1) { textName.Text = PathEx.GetRelativePath(infoList[0].Name, _currentGroup); } else { textName.Text = _defaultName; } // 色 Color color = Color.FromArgb(255, infoList[0].Color); if (infoList.All(info => color == Color.FromArgb(255, info.Color))) { textColor.BackColor = color; textColor.ForeColor = ColorEx.GetComplementaryColor(color); textColor.Text = "Color: " + ColorTranslator.ToHtml(color); } else { textColor.BackColor = Color.White; textColor.ForeColor = Color.Black; textColor.Text = "Color: ..."; } // visible bool visible = infoList[0].IsVisible; if (infoList.All(info => visible == info.IsVisible)) { checkVisible.ThreeState = false; checkVisible.Checked = visible; } else { checkVisible.ThreeState = true; checkVisible.CheckState = CheckState.Indeterminate; } // 色のアルファ int alpha = infoList[0].Color.A; if (infoList.All(info => info.Color.A == alpha)) { numericColorAlpha.Value = (int)Math.Round(100.0 * alpha / 255); numericColorAlpha.ForeColor = SystemColors.ControlText; } else { numericColorAlpha.Value = (int)Math.Round(100.0 * alpha / 255); numericColorAlpha.ForeColor = SystemColors.GrayText; } } } finally { _infoContentChanging = 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(); } }