Esempio n. 1
0
    protected virtual void Preferences_OnActivated(object sender, System.EventArgs e)
    {
        PrefWin Pref = new PrefWin();

        Pref.DebugFile = DebugFile;

        Pref.PipeFont   = PipeTextView.Style.FontDescription.ToString();
        Pref.TextFont   = InputTextView.Style.FontDescription.ToString();
        Pref.ErrorsFont = ErrorsTextView.Style.FontDescription.ToString();

        Pref.WrapText = InputTextView.WrapMode != WrapMode.None;
        Pref.CommandAutoCompletion = commandAutoCompletion;

        try
        {
            if (Pref.Run() == (int)ResponseType.Ok)
            {
                DebugFile = Pref.DebugFile;

                PipeTextView.ModifyFont(Pango.FontDescription.FromString(Pref.PipeFont));
                ArgsEntry.ModifyFont(Pango.FontDescription.FromString(Pref.PipeFont));
                InputTextView.ModifyFont(Pango.FontDescription.FromString(Pref.TextFont));
                OutputTextView.ModifyFont(Pango.FontDescription.FromString(Pref.TextFont));
                ErrorsTextView.ModifyFont(Pango.FontDescription.FromString(Pref.ErrorsFont));

                if (Pref.WrapText)
                {
                    InputTextView.WrapMode  = WrapMode.Word;
                    OutputTextView.WrapMode = WrapMode.Word;
                }
                else
                {
                    InputTextView.WrapMode  = WrapMode.None;
                    OutputTextView.WrapMode = WrapMode.None;
                }

                commandAutoCompletion = Pref.CommandAutoCompletion;

                SaveConfiguration();
            }
        }

        finally
        {
            Pref.Destroy();
        }
    }
Esempio n. 2
0
    protected virtual void FilterButton_OnActivated(object sender, System.EventArgs e)
    {
        TextIter InsertIter = PipeTextView.Buffer.GetIterAtMark(
            PipeTextView.Buffer.InsertMark);

        string filterName = ((ToolButton)sender).Label;

        PipeTextView.Buffer.Insert(ref InsertIter, filterName + " ");

        // Update the status bar:

        CommandSpec CmdSpec = GetCmdSpec(filterName);

        StatusBarTextLabel.Text = CmdSpec.Name + " " + CmdSpec.Prompt;

        // Set focus to the pipe:

        PipeTextView.GrabFocus();
    }
Esempio n. 3
0
    /// <summary>
    /// Executes the pipe.
    /// </summary>
    private void ExecutePipe(string pipeText)
    {
        try
        {
            ErrorsTextView.Buffer.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(ArgsEntry.Text, 0, string.Empty, 0);

            if (ThePipe.Errors.Count == 0)
            {
                MessageDialog WarningMesgDlg = new MessageDialog(this,
                                                                 DialogFlags.DestroyWithParent, MessageType.Warning,
                                                                 ButtonsType.YesNo, "Overwrite output file?");

                try
                {
                    if ((!File.Exists(OutputFileEntry.Text)) || (WarningMesgDlg.Run() == (int)ResponseType.Yes))
                    {
                        if ((DebugFile != null) && (File.Exists(DebugFile)))
                        {
                            File.Delete(DebugFile);
                        }

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

                        try
                        {
                            if (InputFileEntry.Text == string.Empty)
                            {
                                File.WriteAllText(inTempFile, InputTextView.Buffer.Text);
                            }
                            else
                            {
                                File.Copy(InputFileEntry.Text, inTempFile, true);
                            }

                            ThePipe.Execute(ref inTempFile, ref outTempFile);

                            if (OutputFileEntry.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:

                                OutputTextView.Buffer.Changed -= IOTextBuffer_OnChanged;

                                // Write changes to the output text box:

                                OutputTextView.Buffer.Text = File.ReadAllText(outTempFile);

                                // Re-subscribe to the TextChanged event handler:

                                OutputTextView.Buffer.Changed += IOTextBuffer_OnChanged;
                            }
                            else
                            {
                                File.Copy(outTempFile, OutputFileEntry.Text, true);
                            }
                        }

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

                        TextNotebook.CurrentPage = 1;
                        PipeTextView.GrabFocus();
                    }
                }

                finally
                {
                    WarningMesgDlg.Destroy();
                }
            }
            else
            {
                // The pipe had compile (syntax) errors.

                ErrorsTextView.Buffer.Text = ThePipe.Errors.ToString();
                TextNotebook.CurrentPage   = 2;
            }
        }

        catch (PipeWrenchTemplateException ex)
        {
            string tempStr = (string)ex.Data["Template"] + System.Environment.NewLine;

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

            tempStr += System.Environment.NewLine + "   " + ex.Message;

            ErrorsTextView.Buffer.Text = tempStr;
            TextNotebook.CurrentPage   = 2;
        }

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

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

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

            tempStr += System.Environment.NewLine + "      " + ex.Message;
            ErrorsTextView.Buffer.Text = tempStr;
            TextNotebook.CurrentPage   = 2;
        }

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

            ErrorsTextView.Buffer.Text = ex.Message;
            TextNotebook.CurrentPage   = 2;
            PipeEng.Log.WriteText(ex.ToString(), "Fatal error...", "   ");
        }
    }
Esempio n. 4
0
    /// <summary>
    /// Configures the application.
    /// </summary>
    private void LoadConfiguration()
    {
        try
        {
            if (!File.Exists(ConfigFile))
            {
                // Configuration file doesn't exist. Create it:

                string configContents =
                    "<Config>" + System.Environment.NewLine +
                    "  <DebugFile>" + applDataFolder + System.IO.Path.DirectorySeparatorChar + "Debug.txt</DebugFile>" + System.Environment.NewLine +
                    "  <TextWrapping>True</TextWrapping>" + System.Environment.NewLine +
                    "  <CmdAutoCompletion>True</CmdAutoCompletion>" + System.Environment.NewLine +
                    "  <PipeFont>FreeMono Bold 10</PipeFont>" + System.Environment.NewLine +
                    "  <TextFont>FreeMono 10</TextFont>" + System.Environment.NewLine +
                    "  <ErrorFont>FreeMono 10</ErrorFont>" + System.Environment.NewLine +
                    "</Config>" + System.Environment.NewLine;

                File.WriteAllText(ConfigFile, configContents);
            }

            // Load the configuration file:

            XmlDocument XmlDoc = new XmlDocument();
            XmlDoc.Load(ConfigFile);
            XmlElement RootElem = XmlDoc["Config"];

            // Configure debugging:

            XmlElement Elem = RootElem["DebugFile"];
            DebugFile = Elem.InnerText;

            // Configure text wrapping:

            Elem = RootElem["TextWrapping"];

            if (Elem.InnerText.ToUpper() == "TRUE")
            {
                InputTextView.WrapMode  = WrapMode.Word;
                OutputTextView.WrapMode = WrapMode.Word;
            }
            else
            {
                InputTextView.WrapMode  = WrapMode.None;
                OutputTextView.WrapMode = WrapMode.None;
            }

            // Configure command auto-completion:

            Elem = RootElem["CmdAutoCompletion"];
            commandAutoCompletion = Elem.InnerText.ToUpper() == "TRUE";

            // Configure fonts:

            string tempStr = LoadFont("PipeFont", RootElem);
            PipeTextView.ModifyFont(Pango.FontDescription.FromString(tempStr));
            ArgsEntry.ModifyFont(Pango.FontDescription.FromString(tempStr));
            InputTextView.ModifyFont(Pango.FontDescription.FromString(LoadFont("TextFont", RootElem)));
            OutputTextView.ModifyFont(Pango.FontDescription.FromString(LoadFont("TextFont", RootElem)));
            ErrorsTextView.ModifyFont(Pango.FontDescription.FromString(LoadFont("ErrorFont", RootElem)));
        }

        catch (Exception)
        {
            throw new PipeWrenchEngineException("Could not create/load app. configuration (" +
                                                ConfigFile + ").");
        }
    }