Пример #1
0
        public MainWindow()
        {
            _frm = new Form(0, 0, Console.WindowWidth, Console.WindowHeight)
            {
                Title = "ToDoBeDoBeDo Task Management"
            };

            _frm.MenuBar.Menu.AddItem(new MenuItem("File")).Submenu.AddItem(new MenuItem("Close", "mnuClose")
            {
                Shortcut = 'x'
            });

            _frm.MenuBar.Menu.AddItem(new MenuItem("Edit")).Submenu.AddItems(new[] {
                new MenuItem("Add", "mnuAdd")
                {
                    Shortcut = '+'
                },
                new MenuItem("Delete", "mnuDel")
                {
                    Shortcut = '-'
                }
            });

            var mnuFilterOverdue = new MenuItem("Filter for overdue", "mnuFilterOverdue");
            var mnuFilterDue     = new MenuItem("Filter for due", "mnuFilterDue");
            var mnuFilterASAP    = new MenuItem("Filter for ASAP", "mnuFilterASAP");

            _frm.MenuBar.Menu.AddItem(new MenuItem("View")).Submenu.AddItems(new[] {
                mnuFilterOverdue, mnuFilterDue, mnuFilterASAP
            });

            _frm.MenuBar.OnSelected += (item, e) => {
                switch (item.Name)
                {
                case "mnuAdd":
                    OnNewTaskRequest();
                    _frm.MenuBar.HasFocus = false;
                    break;

                case "mnuDel":
                    if (_lstTasks.CurrentItemIndex >= 0 && MessageBox.AskForYes("Delete current item?"))
                    {
                        OnDeleteTaskRequest((string)_lstTasks.CurrentItem.Attachment);
                    }
                    _frm.MenuBar.HasFocus = false;
                    break;

                case "mnuFilterOverdue":
                case "mnuFilterDue":
                case "mnuFilterASAP":
                    item.Checked = !item.Checked;
                    OnQueryTasksRequest(Build_query());
                    break;

                case "mnuClose":
                    BashForms.Close();
                    _frm.MenuBar.HasFocus = false;
                    break;
                }
            };


            const int SUBJECT_COL_WIDTH = 20;
            const int DESC_COL_WIDTH    = 30;
            const int DUE_COL_WIDTH     = 10;
            const int PRIO_COL_WIDTH    = 13;

            _frm.AddChild(new Label(2, 2, "Subject".PadRight(SUBJECT_COL_WIDTH) + "|" + "Description".PadRight(DESC_COL_WIDTH) + "|" + "Due".PadRight(DUE_COL_WIDTH) + "|" + "Priority".PadRight(PRIO_COL_WIDTH))
            {
                BackgroundColor = ConsoleColor.DarkBlue,
                ForegroundColor = ConsoleColor.White
            });

            _lstTasks = new Listbox(2, 3, _frm.Size.width - 4, _frm.Size.height - 6)
            {
                FocusBackgroundColor = ConsoleColor.Black,
                Columns = new[] { SUBJECT_COL_WIDTH, DESC_COL_WIDTH, DUE_COL_WIDTH, PRIO_COL_WIDTH }
            };

            _lstTasks.OnPressed = (w, e) => {
                if (_lstTasks.CurrentItemIndex >= 0)
                {
                    OnEditTaskRequest((string)_lstTasks.CurrentItem.Attachment);
                }
            };
            _frm.AddChild(_lstTasks);

            _txtQuery = new TextLine(2, _lstTasks.Position.top + _lstTasks.Size.height + 1, 45)
            {
                Label = "query: words or #tags separated by spaces"
            };
            _frm.AddChild(_txtQuery);

            _frm.AddChild(new Button(_txtQuery.Position.left + _txtQuery.Size.width + 2, _txtQuery.Position.top, 10, "Filter")
            {
                OnPressed = (s, e) => {
                    OnQueryTasksRequest(Build_query());
                }
            });


            string Build_query()
            {
                var query = _txtQuery.Text;

                if (mnuFilterOverdue.Checked)
                {
                    query += " !overdue";
                }
                if (mnuFilterDue.Checked)
                {
                    query += " !due";
                }
                if (mnuFilterASAP.Checked)
                {
                    query += " !asap";
                }
                return(query);
            }
        }