示例#1
0
        private string CurrentLine()
        {
            int    i    = PipeTextBox.GetLineFromCharIndex(PipeTextBox.SelectionStart);
            string line = PipeTextBox.Lines[i];

            return(line);
        }
示例#2
0
        private void UpdateCmdSyntax()
        {
            // Update command syntax on status bar:

            string text       = PipeTextBox.Text + System.Environment.NewLine;
            int    startIndex = PipeTextBox.GetFirstCharIndexOfCurrentLine();
            int    endIndex   = text.IndexOf(System.Environment.NewLine, startIndex);
            int    length     = endIndex - startIndex;

            if (length > 0)
            {
                text = PipeTextBox.Text.Substring(startIndex, length);
                string filterName = ParseFilterName(text);

                CommandSpec cmdSpec = GetCmdSpec(filterName);

                if (cmdSpec != null)
                {
                    mainStatusStripHintLabel.Text = cmdSpec.Name + " " + cmdSpec.Prompt;
                }
                else
                {
                    mainStatusStripHintLabel.Text = string.Empty;
                }
            }
            else
            {
                mainStatusStripHintLabel.Text = string.Empty;
            }
        }
示例#3
0
 private void PipeTextBox_MouseDown(object sender, MouseEventArgs args)
 {
     if (PipeTextBox.Lines.Length > 0)
     {
         int charIndex = PipeTextBox.GetCharIndexFromPosition(args.Location);
         int lineIndex = PipeTextBox.GetLineFromCharIndex(charIndex);
         pipeLine = PipeTextBox.Lines[lineIndex];
     }
 }
示例#4
0
        /// <summary>
        /// Inserts the caret's position for a "text" textbox (that was recently
        /// clicked on) into the pipe at the pipe's caret position.
        /// </summary>
        private void InsertCursorColAction(object sender, EventArgs e)
        {
            string tempStr = cursorColumnNo.ToString() + " ";
            int    start   = PipeTextBox.SelectionStart;

            PipeTextBox.Text           = PipeTextBox.Text.Insert(start, tempStr);
            PipeTextBox.SelectionStart = start + tempStr.Length;
            PipeTextBox.Focus();
            PipeTextBox.SelectionLength = 0;
        }
示例#5
0
        private void PipeTextBox_OnKeyUp(object sender, KeyEventArgs e)
        {
            char theChar = (char)e.KeyValue;

            if (commandAutoCompletion)
            {
                if (Char.IsLetter(theChar) && (!e.Control) && (!e.Alt))
                {
                    // It's just a letter.

                    string theLine            = CurrentLine();
                    int    lineCaretPos       = PipeTextBox.SelectionStart - PipeTextBox.GetFirstCharIndexOfCurrentLine();
                    string charsToLeftOfCaret = theLine.Substring(0, lineCaretPos).TrimStart();

                    if (IsAlphabetic(charsToLeftOfCaret))
                    {
                        int    savedCaretPos = PipeTextBox.SelectionStart;
                        string suffix        = MatchCommand(charsToLeftOfCaret);
                        int    i             = theLine.IndexOf(' ', lineCaretPos - 1);

                        if (i > -1)
                        {
                            // Found the space following the filter name.

                            int noOfChars = i - lineCaretPos + 1;
                            theLine = theLine.Remove(lineCaretPos - 1, noOfChars);
                            theLine = theLine.Insert(lineCaretPos - 1, suffix);
                        }
                        else
                        {
                            // No space was found.

                            theLine  = theLine.Remove(lineCaretPos - 1);
                            theLine += suffix;
                        }

                        // Update the pipe textbox:

                        int lineNo     = PipeTextBox.GetLineFromCharIndex(PipeTextBox.SelectionStart) + 1;
                        int startIndex = PipeTextBox.GetFirstCharIndexOfCurrentLine();
                        int lineLength = PipeTextBox.Lines[lineNo - 1].Length;
                        PipeTextBox.Text           = PipeTextBox.Text.Remove(startIndex, lineLength);
                        PipeTextBox.Text           = PipeTextBox.Text.Insert(startIndex, theLine);
                        PipeTextBox.SelectionStart = savedCaretPos;
                        PipeTextBox.Modified       = true;
                    }
                }
            }

            UpdateCursorLocation((TextBox)sender);
            UpdateCmdSyntax();
            UpdateControls();
        }
示例#6
0
        void Filter_DoubleClick(object sender, EventArgs e)
        {
            ListView listView   = (ListView)sender;
            string   filterName = listView.SelectedItems[0].Text;
            int      newLoc     = PipeTextBox.SelectionStart + filterName.Length + 1;

            PipeTextBox.Text     = PipeTextBox.Text.Insert(PipeTextBox.SelectionStart, filterName + " ");
            PipeTextBox.Modified = true;

            // Set focus to the pipe:

            PipeTextBox.Focus();
            PipeTextBox.SelectionStart  = newLoc;
            PipeTextBox.SelectionLength = 0;

            // Update the status bar:

            PipeTextBox_OnChanged(PipeTextBox, null);
        }
示例#7
0
 private void PipePasteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     PipeTextBox.Paste();
 }
示例#8
0
 private void PipeCopyToolStripMenuItem_Click(object sender, EventArgs e)
 {
     PipeTextBox.Copy();
 }
示例#9
0
        private void RunToLineAction(object sender, EventArgs e)
        {
            int cursorLineNo = PipeTextBox.GetLineFromCharIndex(PipeTextBox.SelectionStart) + 1;

            ExecutePipe(TopOfPipe(cursorLineNo));
        }
示例#10
0
        /// <summary>
        /// Executes the pipe.
        /// </summary>
        private void ExecutePipe(string pipeText)
        {
            try
            {
                ErrorsTextBox.Text = string.Empty;
                string pipeFolder = string.Empty;
                string pipeName   = "<new pipe>";

                if (PipePath != string.Empty)
                {
                    string tempStr = System.IO.Path.GetFullPath(PipePath);
                    pipeFolder = System.IO.Path.GetDirectoryName(tempStr);
                    pipeName   = System.IO.Path.GetFileName(tempStr);
                }

                Pipe ThePipe = new Pipe(pipeText, PipeEng, pipeFolder, pipeName, CoreLogging, false);
                ThePipe.DebugFile = DebugFile;
                ThePipe.Compile(ArgsTextBox.Text, 0, string.Empty, 0);

                if (ThePipe.Errors.Count == 0)
                {
                    if ((!File.Exists(OutputFileTextBox.Text)) ||
                        MessageBox.Show("Overwrite output file?", "Warning!", MessageBoxButtons.YesNoCancel,
                                        MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        if ((DebugFile != null) && (File.Exists(DebugFile)))
                        {
                            File.Delete(DebugFile);
                        }

                        string inTempFile  = System.IO.Path.GetTempFileName();
                        string outTempFile = System.IO.Path.GetTempFileName();

                        try
                        {
                            if (InputFileTextBox.Text == string.Empty)
                            {
                                File.WriteAllText(inTempFile, InputTextBox.Text);
                            }
                            else
                            {
                                File.Copy(InputFileTextBox.Text, inTempFile, true);
                            }

                            ThePipe.Execute(ref inTempFile, ref outTempFile);

                            if (OutputFileTextBox.Text == string.Empty)
                            {
                                // Unsubscribe from the TextChanged event handler so that
                                // the updates made to the ouput textbox don't change
                                // the caret's current location:

                                OutputTextBox.TextChanged -= IOTextBox_OnChanged;

                                // Write changes to the output text box:

                                OutputTextBox.Text = File.ReadAllText(outTempFile);

                                // Re-subscribe to the TextChanged event handler:

                                OutputTextBox.TextChanged += IOTextBox_OnChanged;
                            }
                            else
                            {
                                File.Copy(outTempFile, OutputFileTextBox.Text, true);
                            }
                        }

                        finally
                        {
                            File.Delete(inTempFile);
                            File.Delete(outTempFile);
                        }

                        TextTabControl.SelectedTab = OutputTabPage;
                        PipeTextBox.Focus();
                    }
                }
                else
                {
                    // Errors.

                    ErrorsTextBox.Text         = ThePipe.Errors.ToString();
                    TextTabControl.SelectedTab = ErrorsTabPage;
                }
            }

            catch (PipeWrenchExecException ex2)
            {
                // Pipe execution (runtime) exception.

                string tempStr = string.Empty;
                string source  = (string)ex2.Data["Source"];
                tempStr += source + System.Environment.NewLine;
                string lineNoStr = ((int)ex2.Data["LineNo"]).ToString();
                string cmdLine   = (string)ex2.Data["CmdLine"];
                tempStr += "   line " + lineNoStr + ": " + cmdLine + System.Environment.NewLine;

                if (ex2.Data.Contains("CharPos"))
                {
                    int charPos = (int)ex2.Data["CharPos"];
                    tempStr += "^".PadLeft(charPos + 10 + lineNoStr.Length, ' ');
                }

                tempStr                   += System.Environment.NewLine + "      " + ex2.Message;
                ErrorsTextBox.Text         = tempStr;
                TextTabControl.SelectedTab = ErrorsTabPage;
            }

            catch (Exception ex3)
            {
                // Anything not already handled...

                ErrorsTextBox.Text         = ex3.Message;
                TextTabControl.SelectedTab = ErrorsTabPage;
                PipeEng.Log.WriteText(ex3.ToString(), "Fatal error...", "   ");
            }
        }