private void CloseState(object sender, EventArgs e) { TabCloseButton btn = (TabCloseButton)sender; StateEditorTabItem tItem = (StateEditorTabItem)btn.tabItem; CloseState(tItem); }
private void SelectOrOpenState(int stateIndex) { foreach (StateEditorTabItem item in stateTabControl.Items) { if (item.StateEditor.StateIndex == stateIndex) { item.IsSelected = true; UpdateStateUi(); return; } } DmiEXState state = (DmiEXState)DmiEx.States[stateIndex]; StateEditor stateEditor = new StateEditor(this, stateIndex, state); StateEditorTabItem tItem = new StateEditorTabItem(stateEditor); stateTabControl.Items.Add(tItem); StackPanel sp = new StackPanel(); TextBlock txt = new TextBlock { Text = $"\"{state.Id}\"", VerticalAlignment = VerticalAlignment.Center }; state.IdChanged += (o, e) => { txt.Text = $"\"{state.Id}\""; }; sp.Orientation = Orientation.Horizontal; sp.Children.Add(txt); TabCloseButton cBtn = new TabCloseButton(tItem); cBtn.Click += CloseState; sp.Children.Add(cBtn); tItem.Header = sp; tItem.IsSelected = true; UpdateStateUi(); }
//called when the state changed, does NOT update the image, just the ui! private void UpdateStateUi(object sender = null, EventArgs e = null) { //getting currently selected Tab StateEditorTabItem currentTab = (StateEditorTabItem)stateTabControl.SelectedItem; //building a list of all currently opened states List <int> openedStates = (from StateEditorTabItem item in stateTabControl.Items select item.StateEditor.StateIndex).ToList(); //setting proper layout for every button foreach (StateButton button in _stateButtons) { if (openedStates.Contains(button.StateIndex)) { if (currentTab != null && button.StateIndex == currentTab.StateEditor.StateIndex) { button.SetPressed(true); } else { button.SetHalfPressed(); } } else { button.SetPressed(false); } } //setting the correct state value editor if (currentTab == null) { return; } stateValueEditorGrid.Children.Clear(); stateValueEditorGrid.Children.Add(new StateValueEditor(currentTab.StateEditor.State)); }
private void CloseState(StateEditorTabItem stateTab) { stateTabControl.Items.Remove(stateTab); UpdateStateUi(); }