private static void EditUnderCursor(State state, UmlWindow umlWindow) { var id = state.Canvas.GetOccupants(state.TheCurser.Pos); if (!id.HasValue) { return; } var elem = state.Model.Objects.Single(x => x.Id == id); if (elem is IHasTextProperty property) { var text = property.Text; var input = new MultilineInputForm(umlWindow, "Edit..", "Text:", text, state.TheCurser.Pos) { OnCancel = () => { }, OnSubmit = newtext => { umlWindow.HandleCommands(Lst(new SetText(id.Value, newtext))); } }; input.Focus(); } else { new Popup(umlWindow, "Only works on labels and boxes"); } }
private static void CreateUmlUser(State state, UmlWindow umlWindow) { var input = new MultilineInputForm(umlWindow, "Text for user (optional)", "Text:", "", state.TheCurser.Pos) { OnCancel = () => { }, OnSubmit = text => { umlWindow.HandleCommands(Lst(new CreateUmlUser(state.TheCurser.Pos, text))); } }; input.Focus(); }
private static void CreateText(State state, UmlWindow umlWindow) { var input = new MultilineInputForm(umlWindow, "Create a label", "Text:", "", state.TheCurser.Pos) { OnCancel = () => { }, OnSubmit = text => { umlWindow.HandleCommands(Lst(new CreateLabel(state.TheCurser.Pos, text))); } }; input.Focus(); }
private static void ConnectObjects(State state, UmlWindow umlWindow) { state.PaintSelectableIds = true; var cmds = NoopForceRepaint; var connect = new ConnectForm(umlWindow, state.TheCurser.Pos, state.Model.Objects.Select(x => x.Id).ToArray()) { OnCancel = () => { umlWindow.HandleCommands(cmds); state.PaintSelectableIds = false; }, OnSubmit = (from, to) => { cmds.Add(new CreateLine(from, to, LineKind.Connected)); umlWindow.HandleCommands(cmds); state.PaintSelectableIds = false; } }; connect.Focus(); }
private static void PrintIdsAndLetUserSelectObject(State state, UmlWindow umlWindow) { state.PaintSelectableIds = true; var cmds = NoopForceRepaint; var selectedform = new SelectObjectForm(umlWindow, state.Model.Objects.Select(x => x.Id).ToArray(), state.TheCurser.Pos) { OnCancel = () => { umlWindow.HandleCommands(cmds); state.PaintSelectableIds = false; }, OnSubmit = selected => { if (state.Model.Objects.SingleOrDefault(b => b.Id == selected) is ISelectable) { cmds.Add(new SelectObject(selected, true)); } umlWindow.HandleCommands(cmds); state.PaintSelectableIds = false; } }; selectedform.Focus(); }
private static void CommandMode(State state, List <List <ICommand> > commandLog, UmlWindow umlWindow) { var input = new SinglelineInputForm(umlWindow, "Enter command", "commands: database, save-file, set-save-filename:", "Enter a command", 25, state.TheCurser.Pos) { OnCancel = () => { }, OnSubmit = cmd => { switch (cmd) { case "set-save-filename": var filename = new SinglelineInputForm(umlWindow, "Set state", "Filename", "Enter a filename", 20, state.TheCurser.Pos) { OnSubmit = fname => state.Config.SaveFilename = fname }; filename.Focus(); break; case "save-file": var log = Program.Serialize(commandLog); var logname = state.Config.SaveFilename + ".log"; File.WriteAllText(logname, log); var model = Program.Serialize(state.Model); File.WriteAllText(state.Config.SaveFilename, model); new Popup(umlWindow, $"file saved to \'{state.Config.SaveFilename}\'"); break; case "database": umlWindow.HandleCommands(Lst(new CreateDatabase(state.TheCurser.Pos))); break; } } }; input.Focus(); }