示例#1
0
 private static void SetParameters(EditorManager manager, string[] args)
 {
     while (true)
     {
         try
         {
             manager.ClipEditor.SetParameters(args);
             break;
         }
         catch (ClippyLib.InvalidParameterException pe)
         {
             Console.WriteLine("Error: " + pe.ParameterMessage);
             Console.WriteLine("Press enter to continue, results are not guaranteed\r\n");
             Console.ReadLine();
             break;
         }
         catch (ClippyLib.UndefinedFunctionException udfe)
         {
             manager.ClipEditor.EditorResponse -= HandleResponseFromClippy;
             Console.WriteLine(udfe.FunctionMessage);
             Console.WriteLine(manager.Help(args));
             Console.WriteLine("Awaiting command");
             args = manager.GetArgumentsFromString(Console.ReadLine());
             manager.GetClipEditor(args[0]);
             manager.ClipEditor.EditorResponse += new EventHandler <EditorResponseEventArgs>(HandleResponseFromClippy);
         }
     }
 }
示例#2
0
        static void Main(string[] args)
        {
            EditorManager manager  = new EditorManager();
            StringBuilder contentb = new StringBuilder();
            string        line;

            while ((line = Console.In.ReadLine()) != null)
            {
                contentb.AppendLine(line);
            }
            string content = contentb.ToString();

            if (args.Length > 0 && (args[0].Equals("help", StringComparison.CurrentCultureIgnoreCase) || args[0].Equals("/?", StringComparison.CurrentCultureIgnoreCase)))
            {
                manager.Help(args).PrintToConsole();
                Console.ReadLine();
            }
            else
            {
                if (args.Length == 0)
                {
                    manager.Help(args).PrintToConsole();
                    Console.WriteLine("Awaiting command");
                    args = manager.GetArgumentsFromString(Console.ReadLine());
                }
                manager.GetClipEditor(args[0]);
                manager.ClipEditor.EditorResponse           += HandleResponseFromClippy;
                manager.ClipEditor.PersistentEditorResponse += HandleResponseFromClippy;

                SetParameters(manager, args);

                if (!manager.ClipEditor.HasAllParameters)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Y O U   M U S T   P A S S   A L L   R E Q U I R E D   P A R A M E T E R S");
                    Console.ResetColor();

                    manager.ClipEditor.LongDescription.PrintToConsole();
                    return;
                }

                manager.ClipEditor.SourceData = content;
                manager.ClipEditor.Edit();
                content = manager.ClipEditor.SourceData;
                manager.ClipEditor.EditorResponse           -= HandleResponseFromClippy;
                manager.ClipEditor.PersistentEditorResponse -= HandleResponseFromClippy;
            }

            // write, not writeline here, on purpose (run this with writeline as !Manip inside of VIM and you'll see why)
            Console.Write(content);
        }
示例#3
0
        static void Main(string[] args)
        {
            _manager = new EditorManager();
            if (ShowingHelp(args) || ShowingUdfEditor(args))
            {
                return;
            }

            if (args.Length == 0)
            {
                Console.WriteLine(_manager.Help(args));
                Console.WriteLine("Awaiting command");
                args = _manager.GetArgumentsFromString(Console.ReadLine());
            }

            _manager.GetClipEditor(args[0]);
            _manager.ClipEditor.EditorResponse           += HandleResponseFromClippy;
            _manager.ClipEditor.PersistentEditorResponse += HandleResponseFromClippy;

            SetParametersObtainedFromConsole(args);

            if (AtLeastOneParameterPassedIn(args))
            {
                UseDefaultForRemainingParameters(args);
            }

            PromptForRemainingParameters();

            _manager.ClipEditor.GetClipboardContent();
            _manager.ClipEditor.Edit();
            _manager.ClipEditor.SetClipboardContent();

            SaveThisCommand(args[0]);


            _manager.ClipEditor.EditorResponse           -= HandleResponseFromClippy;
            _manager.ClipEditor.PersistentEditorResponse -= HandleResponseFromClippy;
        }
示例#4
0
文件: Form1.cs 项目: Mnrikard/Clippy
        private void FunctionOnLeave(object sender, EventArgs e)
        {
            errorLabel.Text     = String.Empty;
            functions.BackColor = Color.White;

            string[] arguments = clipManager.GetArgumentsFromString(functions.Text);
            if (arguments.Length == 0)
            {
                return;
            }

            if (functions.Text.Equals(_currentCommand, StringComparison.CurrentCultureIgnoreCase))
            {
                string[] newArgs = new string[parametersGrid.Rows.Count + 1];
                newArgs[0] = arguments[0];
                for (int ia = 1; ia < newArgs.Length; ia++)
                {
                    newArgs[ia] = parametersGrid.Rows[ia - 1].Cells[1].Value.ToString();
                }
                arguments = newArgs;
            }

            _currentCommand = arguments[0];

            clipManager.GetClipEditor(arguments[0]);
            clipManager.ClipEditor.EditorResponse           += HandleResponseFromClippy;
            clipManager.ClipEditor.PersistentEditorResponse += HandlePersistentResponse;
            try
            {
                clipManager.ClipEditor.SetParameters(arguments);
            }
            catch (ClippyLib.InvalidParameterException pe)
            {
                MessageBox.Show(pe.ParameterMessage, "Error creating parameters", MessageBoxButtons.OK, MessageBoxIcon.Error);
                functions.Focus();
            }
            catch (ClippyLib.UndefinedFunctionException udfe)
            {
                errorLabel.Text     = udfe.FunctionMessage;
                functions.BackColor = Color.Yellow;
                functions.Focus();
                return;
            }

            DataTable parms = new DataTable();

            parms.Columns.Add("Parameter");
            parms.Columns.Add("Value");
            foreach (Parameter p in clipManager.ClipEditor.ParameterList)
            {
                DataRow dr = parms.NewRow();
                dr["Parameter"] = p.ParameterName;
                dr["Value"]     = p.Value ?? p.DefaultValue ?? String.Empty;

                parms.Rows.Add(dr);
            }
            parametersGrid.DataSource = parms;

            int parmRow = 0;

            foreach (Parameter p in clipManager.ClipEditor.ParameterList)
            {
                parametersGrid.Rows[parmRow++].Cells[1].ToolTipText = p.Expecting;
            }

            if (clipManager.ClipEditor.ParameterList.Count == 0)
            {
                executeButton.Focus();
            }
        }