示例#1
0
        private static List <ICommand> HelpScreen(UmlWindow umlWindow)
        {
            new Popup(umlWindow, @"*  *  ****  *     ****    
*  *  *     *     *  *    
****  **    *     ****    
*  *  *     *     *       
*  *  ****  ****  *       
space ................ (un)select object at cursor or choose object
s .................... select an object
cursor keys........... move cursor or selected object
shift + cursor ....... move object under cursor
r .................... rotate selected object (only text label)
ctrl + cursor ........ Resize selected object (only box)
b .................... Create a Box
e .................... Edit element at cursor (box/label/note)
c .................... Create a connection line between boxes
i .................... InsertMode
  d ..................   Create a Database
  n ..................   Create a note
  t ..................   Create a text label
  u ..................   Create a user
l .................... Create a free-style line
., ................... Change the style (only box)
x / Del............... Delete selected object
enter ................ Enter command mode
Esc .................. Abort input / InsertMode
ctrl+c ............... Exit program");
            return(Noop);
        }
示例#2
0
        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");
            }
        }
示例#3
0
        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();
        }
示例#4
0
        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();
        }
示例#5
0
        private static void ShowLogo(UmlWindow umlWindow)
        {
            var logo = new PopupNoButton(umlWindow, @"
          _____  _____ ______ _____   _    _ __  __ _      
    /\   / ____|/ ____|__   _|_   _| | |  | |  \/  | |     
   /  \  | (___ | |      | |   | |   | |  | | \  / | |     
  / /\ \  \___ \| |      | |   | |   | |  | | |\/| | |     
 / ____ \ ____) | |____ _| |_ _| |_  | |__| | |  | | |____ 
/_/    \_\_____/ \_____|_____|_____|  \____/|_|  |_|______|
                                     by Kasper B. Graversen
")
            {
                BackGround = ConsoleColor.Black
            };
        }
示例#6
0
        private static List <ICommand> SelectDeselect(int?selected, State state, UmlWindow umlWindow)
        {
            if (selected.HasValue)
            {
                return(Lst(new ClearSelection()));
            }

            var obj = state.Canvas.GetOccupants(state.TheCurser.Pos).ToOption()
                      .Match(x => Lst(new SelectObject(x, false)),
                             () => {
                PrintIdsAndLetUserSelectObject(state, umlWindow);
                return(Noop);
            });

            return(obj);
        }
示例#7
0
        private static List <ICommand> ChangeStyleUnderCursor(State state, UmlWindow umlWindow, StyleChangeKind change)
        {
            var id = state.Canvas.GetOccupants(state.TheCurser.Pos);

            if (!id.HasValue)
            {
                return(Noop);
            }

            var elem = state.Model.Objects.Single(x => x.Id == id);

            if (elem is IStyleChangeable)
            {
                return(Lst(new ChangeStyle(elem.Id, change)));
            }
            new Popup(umlWindow, "Only works on boxes");
            return(Noop);
        }
示例#8
0
        private static void CreateWindow(bool showLogo)
        {
            var state = new State {
                TheCurser = new Cursor(new Coord(10, 10))
            };

            var man     = new WindowManager($"AsciiUML {Version} (c) Kasper B. Graversen 2016-", State.MaxX, State.MaxY);
            var topmenu = new TopMenu(man, state);
            //var umlWindow = new UmlWindow(topmenu, state);
            var umlWindow = new UmlWindow(topmenu, TempModelForPlayingAround(state));

            umlWindow.Focus();

            if (showLogo)
            {
                ShowLogo(umlWindow);
            }

            man.Start();
        }
示例#9
0
        static void Main(string[] args)
        {
            var state = new State
            {
                TheCurser = new Cursor(new Coord(10, 10))
            };

            var man       = new WindowManager("AsciiUML (c) Kasper B. Graversen 2016-");
            var topmenu   = new TopMenu(man, state);
            var umlWindow = new UmlWindow(topmenu, state);

            //var umlWindow = new UmlWindow(topmenu, TempModelForPlayingAround(state));
            umlWindow.Focus();
            //ShowLogo(umlWindow);

            var title = new TitledWindow(umlWindow, "Connect objects");
            var f     = new ConnectForm(title, new Coord(5, 5));

            f.Focus();
            man.Start();
        }
示例#10
0
        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();
        }
示例#11
0
        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();
        }
示例#12
0
        public (bool, List <ICommand>) HandleKeyPress(State state, ConsoleKeyInfo key, List <List <ICommand> > commandLog, UmlWindow umlWindow)
        {
            switch (key.Key)
            {
            case ConsoleKey.C:
                return(true, Noop);

            case ConsoleKey.D:
                return(true, Lst(new CreateDatabase(state.TheCurser.Pos)));

            case ConsoleKey.N:
                CreateNote(state, umlWindow);
                return(true, Noop);

            case ConsoleKey.T:
                CreateText(state, umlWindow);
                return(true, Noop);

            case ConsoleKey.U:
                CreateUmlUser(state, umlWindow);
                return(true, Noop);

            case ConsoleKey.Escape:
                return(true, Noop);
            }
            return(false, Noop);
        }
示例#13
0
        private static Option <List <ICommand> > HandleKeys(State state, ConsoleKeyInfo key, List <List <ICommand> > commandLog,
                                                            UmlWindow umlWindow)
        {
            var model    = state.Model;
            var selected = state.SelectedIndexInModel;

            switch (key.Key)
            {
            case ConsoleKey.UpArrow:
                if (state.TheCurser.Pos.Y > 0)
                {
                    return(MoveCursorAndSelectPaintable(Vector.DeltaNorth));
                }
                break;

            case ConsoleKey.DownArrow:
                if (state.TheCurser.Pos.Y < State.MaxY - 2)
                {
                    return(MoveCursorAndSelectPaintable(Vector.DeltaSouth));
                }
                break;

            case ConsoleKey.LeftArrow:
                if (state.TheCurser.Pos.X > 0)
                {
                    return(MoveCursorAndSelectPaintable(Vector.DeltaWest));
                }
                break;

            case ConsoleKey.RightArrow:
                if (state.TheCurser.Pos.X < State.MaxX - 2)
                {
                    return(MoveCursorAndSelectPaintable(Vector.DeltaEast));
                }
                break;

            case ConsoleKey.Spacebar:
                return(SelectDeselect(selected, state, umlWindow));

            case ConsoleKey.S:
                PrintIdsAndLetUserSelectObject(state, umlWindow);
                return(OptNoop);

            case ConsoleKey.X:
            case ConsoleKey.Delete:
                return(Lst(new DeleteSelectedElement()));

            case ConsoleKey.H:
                return(HelpScreen(umlWindow));

            case ConsoleKey.I:
                handlerState = HandlerState.Insert;
                return(Lst(new SetTopmenuText("INSERTMODE> d: database | t: text | n: note | u: user")));

            case ConsoleKey.B:
                CreateBox(state, umlWindow);
                break;

            case ConsoleKey.E:
                EditUnderCursor(state, umlWindow);
                break;

            case ConsoleKey.C:
                ConnectObjects(state, umlWindow);
                return(OptNoop);

            case ConsoleKey.L:
                return(SlopedLine(state));

            case ConsoleKey.R:
                return(Rotate(selected, model));

            case ConsoleKey.Enter:
                CommandMode(state, commandLog, umlWindow);
                return(OptNoop);

            case ConsoleKey.OemPeriod:
                return(ChangeStyleUnderCursor(state, umlWindow, StyleChangeKind.Next));

            case ConsoleKey.OemComma:
                return(ChangeStyleUnderCursor(state, umlWindow, StyleChangeKind.Previous));
            }
            return(Noop);
        }
示例#14
0
        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();
        }
示例#15
0
        public static List <ICommand> HandleKeyPress(State state, ConsoleKeyInfo key, List <List <ICommand> > commandLog, UmlWindow umlWindow)
        {
            switch (handlerState)
            {
            case HandlerState.Normal:
                return(ControlKeys(state, key, commandLog)
                       .IfNone(() => ShiftKeys(state, key)
                               .IfNone(() => HandleKeys(state, key, commandLog, umlWindow)
                                       .IfNone(() => Noop))));

            case HandlerState.Insert:
                (var done, var cmds) = new KeyHandlerInsertState().HandleKeyPress(state, key, commandLog, umlWindow);

                if (done)
                {
                    handlerState = HandlerState.Normal;
                    cmds         = cmds.Concat(Lst(new ClearTopmenuText())).ToList();
                }
                return(cmds);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }