Esempio n. 1
0
        private void MenuBarEvent()
        {
            fNewTool.Click += (object sender, EventArgs e) =>
            {
                CommandBox.ClearText();
                tabView[Index].Dgv.DataSource = null;
            };
            F0_Open.Click        += (object sender, EventArgs e) => { OpenFileDialog(); };
            fOpenTool.Click      += (object sender, EventArgs e) => { OpenFileDialog(); };
            F0_Save.Click        += (object sender, EventArgs e) => { SaveFileDialog(false); };
            fSaveTool.Click      += (object sender, EventArgs e) => { SaveFileDialog(false); };
            F0_Overwrite.Click   += (object sender, EventArgs e) => { SaveFileDialog(true); };
            fOverwriteTool.Click += (object sender, EventArgs e) => { SaveFileDialog(true); };
            fOutputTool.Click    += (object sender, EventArgs e) => { OutputCsvFile(); };
            fCloseTool.Click     += (object sender, EventArgs e) => { closeBtn_Click(sender, e); };

            F0_Undo.Click     += (object sender, EventArgs e) => { CommandBox.Undo(); };
            eUndo.Click       += (object sender, EventArgs e) => { CommandBox.Undo(); };
            F0_Redo.Click     += (object sender, EventArgs e) => { CommandBox.Redo(); };
            eRedo.Click       += (object sender, EventArgs e) => { CommandBox.Redo(); };
            eCutTool.Click    += (object sender, EventArgs e) => { CommandBox.Cut(); };
            eCopyTool.Click   += (object sender, EventArgs e) => { CommandBox.Copy(); };
            ePasteTool.Click  += (object sender, EventArgs e) => { CommandBox.Paste(); };
            eSelectTool.Click += (object sender, EventArgs e) => { CommandBox.SelectAll(); };

            vMenuTool.Click += (object sender, EventArgs e) => { menuBar.Visible = !menuBar.Visible; };
            vToolTool.Click += (object sender, EventArgs e) => { toolBar.Visible = !toolBar.Visible; };
            vTabTool.Click  += (object sender, EventArgs e) => { tabView.tabBar.Visible = !tabView.tabBar.Visible; };
            vInfoTool.Click += (object sender, EventArgs e) => { underBar.Visible = !underBar.Visible; };

            hVersionTool.Click += (object sender, EventArgs e) =>
            {
                using (VerInfoDialog form = new VerInfoDialog()) { form.ShowDialog(); }
            };
        }
Esempio n. 2
0
        private PSObject GetSingle(string caption, string message, string prompt, FieldDescription field, Type type)
        {
            string   help      = field.HelpMessage;
            PSObject psDefault = field.DefaultValue;

            if (null != type && type == typeof(PSCredential))
            {
                var credential = _host.UI.PromptForCredential(caption, message, psDefault?.ToString(), string.Empty, PSCredentialTypes.Default, PSCredentialUIOptions.Default);
                return(credential != null?PSObject.AsPSObject(credential) : null);
            }

            while (true)
            {
                // TODO: Only show the help message if they type '?' as their entry something, in which case show help and re-prompt.
                if (!String.IsNullOrEmpty(help))
                {
                    Write(ConsoleBrushes.ConsoleColorFromBrush(ConsoleBrushes.VerboseForeground), ConsoleBrushes.ConsoleColorFromBrush(ConsoleBrushes.VerboseBackground), help + "\n");
                }

                Write($"{prompt}: ");

                if (null != type && typeof(SecureString) == type)
                {
                    var userData = ReadLineAsSecureString() ?? new SecureString();
                    return(PSObject.AsPSObject(userData));
                } // Note: This doesn't look the way it does in PowerShell, but it should work :)
                else
                {
                    if (psDefault != null && psDefault.ToString().Length > 0)
                    {
                        if (Dispatcher.CheckAccess())
                        {
                            CurrentCommand = psDefault.ToString();
                            CommandBox.SelectAll();
                        }
                        else
                        {
                            Dispatcher.BeginInvoke(DispatcherPriority.Input, (Action <string>)(def =>
                            {
                                CurrentCommand = def;
                                CommandBox.SelectAll();
                            }), psDefault.ToString());
                        }
                    }

                    var userData = ReadLine();

                    if (type != null && userData.Length > 0)
                    {
                        object output;
                        var    ice = TryConvertTo(type, userData, out output);
                        // Special exceptions that happen when casting to numbers and such ...
                        if (ice == null)
                        {
                            return(PSObject.AsPSObject(output));
                        }
                        if ((ice.InnerException is FormatException) || (ice.InnerException is OverflowException))
                        {
                            Write(ConsoleBrushes.ErrorForeground, ConsoleBrushes.ErrorBackground,
                                  $@"Cannot recognize ""{userData}"" as a {type.FullName} due to a format error.\n");
                        }
                        else
                        {
                            return(PSObject.AsPSObject(String.Empty));
                        }
                    }
                    else if (userData.Length == 0)
                    {
                        return(PSObject.AsPSObject(String.Empty));
                    }
                    else
                    {
                        return(PSObject.AsPSObject(userData));
                    }
                }
            }
        }