public void SetFocusOnEditor() { if (state != AddressBarState.Editor) { FlipState(); editor.SetFocus(); } }
public SaveRulerDialog(Ruler ruler) { ThemedButton cancelButton; ThemedButton okButton; CheckBox checkBox; EditBox editBox; window = new Window(new WindowOptions { Title = "Save Ruler", Visible = false, Style = WindowStyle.Dialog, }); WindowWidget rootWidget = new ThemedInvalidableWindowWidget(window) { LayoutBasedWindowSize = true, Padding = new Thickness(8), Layout = new VBoxLayout { Spacing = 16 }, Nodes = { new Widget { Layout = new TableLayout{ ColumnCount = 2, RowCount = 2, Spacing = 8, ColumnDefaults = { new DefaultLayoutCell(Alignment.RightCenter, 0.5f, 0), new DefaultLayoutCell(Alignment.LeftCenter, 1, 0) } }, Nodes = { new ThemedSimpleText("Ruler name"), (editBox = new ThemedEditBox{ MinWidth = 150 }), new ThemedSimpleText("Anchor to root"), (checkBox = new ThemedCheckBox()) } }, new Widget { Layout = new HBoxLayout{ Spacing = 8 }, LayoutCell = new LayoutCell(Alignment.RightCenter), Nodes = { (okButton = new ThemedButton("Ok")), (cancelButton = new ThemedButton("Cancel")), } } } }; cancelButton.Clicked += window.Close; okButton.AddChangeWatcher(() => editBox.Text, (text) => okButton.Enabled = !string.IsNullOrEmpty(text)); okButton.Clicked += () => { ruler.Name = editBox.Text; ruler.AnchorToRoot = checkBox.Checked; result = true; window.Close(); }; rootWidget.FocusScope = new KeyboardFocusScope(rootWidget); editBox.SetFocus(); }
public Result Show(Marker marker, bool canDelete) { Widget buttonsPanel; Button deleteButton; Button okButton; Button cancelButton; DropDownList actionSelector; EditBox markerIdEditor; ThemedDropDownList jumpToSelector; Result result; var window = new Window(new WindowOptions { FixedSize = true, Title = "Marker properties", Visible = false, Style = WindowStyle.Dialog }); jumpToSelector = new ThemedDropDownList(); jumpToSelector.Items.Add(new ThemedDropDownList.Item(string.Empty, null)); foreach (var m in Document.Current.Animation.Markers.Where(m => !string.IsNullOrEmpty(m.Id))) { jumpToSelector.Items.Add(new ThemedDropDownList.Item(m.Id, m)); } jumpToSelector.Text = marker.JumpTo; var rootWidget = new ThemedInvalidableWindowWidget(window) { LayoutBasedWindowSize = true, Padding = new Thickness(8), Layout = new VBoxLayout { Spacing = 16 }, Nodes = { new Widget { Layout = new TableLayout{ ColumnCount = 2, RowCount = 3, Spacing = 8, ColumnDefaults = { new DefaultLayoutCell(Alignment.RightCenter, 0.5f, 0), new DefaultLayoutCell(Alignment.LeftCenter, 1, 0) } }, Nodes = { new ThemedSimpleText("Marker Id"), (markerIdEditor = new ThemedEditBox{ Text = marker.Id, MinSize= Theme.Metrics.DefaultEditBoxSize * new Vector2(2, 1) }), new ThemedSimpleText("Action"), (actionSelector = new ThemedDropDownList{ Items = { new DropDownList.Item("Play", MarkerAction.Play), new DropDownList.Item("Jump", MarkerAction.Jump), new DropDownList.Item("Stop", MarkerAction.Stop), }, Value = marker.Action }), new ThemedSimpleText("Jump to"), jumpToSelector, } }, (buttonsPanel = new Widget{ Layout = new HBoxLayout{ Spacing = 8 }, LayoutCell = new LayoutCell(Alignment.RightCenter), Nodes = { (okButton = new ThemedButton("Ok")), (cancelButton = new ThemedButton("Cancel")), } }) } }; if (canDelete) { deleteButton = new ThemedButton("Delete"); buttonsPanel.AddNode(deleteButton); deleteButton.Clicked += () => { result = Result.Delete; window.Close(); }; } rootWidget.FocusScope = new KeyboardFocusScope(rootWidget); rootWidget.LateTasks.Add(new KeyPressHandler(Key.Escape, (input, key) => { input.ConsumeKey(key); window.Close(); })); rootWidget.LateTasks.Add(new KeyPressHandler(Key.Enter, (input, key) => { input.ConsumeKey(key); result = Result.Ok; window.Close(); })); okButton.Clicked += () => { result = Result.Ok; window.Close(); }; cancelButton.Clicked += window.Close; markerIdEditor.SetFocus(); result = Result.Cancel; window.ShowModal(); if (result == Result.Ok) { marker.Id = markerIdEditor.Text; marker.Action = (MarkerAction)actionSelector.Value; marker.JumpTo = jumpToSelector.Text; } return(result); }
private void RenameAnimation() { var index = GetSelectedAnimationIndex(); var animation = GetAnimations()[index]; var item = (Widget)scrollView.Content.Nodes[index]; var label = item["Label"]; label.Visible = false; var editor = new ThemedEditBox(); label.Parent.Nodes.Insert(label.CollectionIndex(), editor); editor.Text = animation.Id; editor.SetFocus(); editor.AddChangeWatcher(() => editor.IsFocused(), focused => { if (!focused) { var newId = editor.Text.Trim(); if (!animation.Owner.Animations.Any(a => a.Id == newId)) { RenameAnimationHelper(newId); } editor.Unlink(); label.Visible = true; } }); editor.Submitted += s => { RenameAnimationHelper(s.Trim()); editor.Unlink(); label.Visible = true; }; void RenameAnimationHelper(string newId) { string error = null; if (animation.IsLegacy) { error = "Can't rename legacy animation"; } else if (animation.Id == Animation.ZeroPoseId) { error = "Can't rename zero pose animation"; } else if (newId.IsNullOrWhiteSpace() || newId == Animation.ZeroPoseId) { error = "Invalid animation id"; } else if (TangerineDefaultCharsetAttribute.IsValid(newId, out var message) != ValidationResult.Ok) { error = message; } else if (animation.Owner.Animations.Any(a => a.Id == newId)) { error = $"An animation '{newId}' already exists"; } if (error != null) { UI.AlertDialog.Show(error, "Ok"); return; } Document.Current.History.DoTransaction(() => { var oldId = animation.Id; Core.Operations.SetProperty.Perform(animation, nameof(Animation.Id), newId); foreach (var a in animation.Owner.Animations) { foreach (var track in a.Tracks) { foreach (var animator in track.Animators) { if (animator.AnimationId == oldId) { Core.Operations.SetProperty.Perform(animator, nameof(IAnimator.AnimationId), newId); } } } } ChangeAnimatorsAnimationId(animation.OwnerNode); void ChangeAnimatorsAnimationId(Node node) { foreach (var child in node.Nodes) { foreach (var animator in child.Animators) { if (animator.AnimationId == oldId) { Core.Operations.SetProperty.Perform(animator, nameof(IAnimator.AnimationId), newId); } } if (child.ContentsPath != null) { continue; } if (child.Animations.Any(i => i.Id == oldId)) { continue; } ChangeAnimatorsAnimationId(child); } } }); } }