Exemple #1
0
            public CMenu(VT100Display disp)
            {
                m_disp = disp;
                using (this.SuspendLayout(false))
                {
                    #region Clear
                    {
                        var item = Items.Add2(new ToolStripMenuItem("Clear", null));
                        item.Click += (s, e) => m_disp.Clear();
                    }
                    #endregion
                    Items.Add(new ToolStripSeparator());
                    #region Copy
                    {
                        var item = Items.Add2(new ToolStripMenuItem("Copy", null));
                        item.Click += (s, e) => m_disp.Copy();
                    }
                    #endregion
                    #region Paste
                    {
                        var item = Items.Add2(new ToolStripMenuItem("Paste", null));
                        item.Click += (s, e) => m_disp.Paste();
                    }
                    #endregion
                    Items.Add(new ToolStripSeparator());
                    #region Capture To File
                    {
                        var item = Items.Add2(new ToolStripMenuItem("Capture To File", null));
                        Opening += (s, a) =>
                        {
                            item.Enabled = m_disp.Buffer != null;
                            item.Checked = m_disp.CapturingToFile;
                        };
                        item.Click += (s, e) =>
                        {
                            m_disp.CaptureToFile(!m_disp.CapturingToFile);
                        };
                    }
                    #endregion
                    #region Send File
                    {
                        var item = Items.Add2(new ToolStripMenuItem("Send File", null));
                        Opening += (s, a) =>
                        {
                            item.Enabled = m_disp.Buffer != null;
                        };
                        item.Click += (s, e) =>
                        {
                            m_disp.SendFile(true);
                        };
                    }
                    #endregion
                    if (m_disp.Settings != null)
                    {
                        Items.Add(new ToolStripSeparator());
                        var options = Items.Add2(new ToolStripMenuItem("Terminal Options", null));

                        #region Local Echo
                        {
                            var item = options.DropDownItems.Add2(new ToolStripMenuItem("Local Echo")
                            {
                                CheckOnClick = true
                            });
                            options.DropDown.Opening += (s, a) =>
                            {
                                item.Checked = m_disp.Settings.LocalEcho;
                            };
                            item.Click += (s, a) =>
                            {
                                m_disp.Settings.LocalEcho = item.Checked;
                            };
                        }
                        #endregion
                        #region Terminal Width
                        {
                            var item = options.DropDownItems.Add2(new ToolStripMenuItem("Terminal Width"));
                            var edit = item.DropDownItems.Add2(new ToolStripTextBox());
                            item.DropDown.Opening += (s, a) =>
                            {
                                edit.Text = m_disp.Settings.TerminalWidth.ToString();
                            };
                            item.DropDown.Closing += (s, a) =>
                            {
                                int w;
                                if (!(a.Cancel = !int.TryParse(edit.Text, out w)))
                                {
                                    m_disp.Settings.TerminalWidth = w;
                                }
                            };
                            edit.KeyDown += (s, e) =>
                            {
                                if (e.KeyCode != Keys.Return)
                                {
                                    return;
                                }
                                item.DropDown.Close();
                            };
                        }
                        #endregion
                        #region Terminal Height
                        {
                            var item = options.DropDownItems.Add2(new ToolStripMenuItem("Terminal Height"));
                            var edit = item.DropDownItems.Add2(new ToolStripTextBox());
                            item.DropDown.Opening += (s, a) =>
                            {
                                edit.Text = m_disp.Settings.TerminalHeight.ToString();
                            };
                            item.DropDown.Closing += (s, e) =>
                            {
                                int h;
                                if (!(e.Cancel = !int.TryParse(edit.Text, out h)))
                                {
                                    m_disp.Settings.TerminalHeight = h;
                                }
                            };
                            edit.KeyDown += (s, e) =>
                            {
                                if (e.KeyCode != Keys.Return)
                                {
                                    return;
                                }
                                item.DropDown.Close();
                            };
                        }
                        #endregion
                        #region Tab Size
                        {
                            var item = options.DropDownItems.Add2(new ToolStripMenuItem("Tab Size"));
                            var edit = item.DropDownItems.Add2(new ToolStripTextBox());
                            item.DropDown.Opening += (s, a) =>
                            {
                                edit.Text = m_disp.Settings.TabSize.ToString();
                            };
                            item.DropDown.Closing += (s, e) =>
                            {
                                int sz;
                                if (!(e.Cancel = !int.TryParse(edit.Text, out sz)))
                                {
                                    m_disp.Settings.TabSize = sz;
                                }
                            };
                            edit.KeyDown += (s, e) =>
                            {
                                if (e.KeyCode != Keys.Return)
                                {
                                    return;
                                }
                                Close();
                            };
                        }
                        #endregion
                        #region Newline Recv
                        {
                            var item = options.DropDownItems.Add2(new ToolStripMenuItem("Newline Recv"));
                            var cb   = new ComboBox(); cb.Items.AddRange(Enum <VT100.ENewLineMode> .Values.Cast <object>().ToArray());
                            var edit = item.DropDownItems.Add2(new ToolStripControlHost(cb));
                            item.DropDown.Opening += (s, a) =>
                            {
                                cb.SelectedItem = m_disp.Settings.NewlineRecv;
                            };
                            cb.SelectedIndexChanged += (s, e) =>
                            {
                                m_disp.Settings.NewlineRecv = (VT100.ENewLineMode)cb.SelectedItem;
                            };
                        }
                        #endregion
                        #region Newline Send
                        {
                            var item = options.DropDownItems.Add2(new ToolStripMenuItem("Newline Send"));
                            var cb   = new ComboBox(); cb.Items.AddRange(Enum <VT100.ENewLineMode> .Values.Cast <object>().ToArray());
                            var edit = item.DropDownItems.Add2(new ToolStripControlHost(cb));
                            item.DropDown.Opening += (s, a) =>
                            {
                                cb.SelectedItem = m_disp.Settings.NewlineSend;
                            };
                            cb.SelectedIndexChanged += (s, e) =>
                            {
                                m_disp.Settings.NewlineSend = (VT100.ENewLineMode)cb.SelectedItem;
                            };
                        }
                        #endregion
                        #region Hex Output
                        {
                            var item = options.DropDownItems.Add2(new ToolStripMenuItem("Hex Output")
                            {
                                CheckOnClick = true
                            });
                            options.DropDown.Opening += (s, a) =>
                            {
                                item.Checked = m_disp.Settings.HexOutput;
                            };
                            item.Click += (s, e) =>
                            {
                                m_disp.Settings.HexOutput = item.Checked;
                            };
                        }
                        #endregion
                    }
                }
            }