示例#1
0
        /*      private string SavePdf(bool SaveAs)
         *    {
         *        if (SaveAs == false && CurFileNeverSaved)
         *        {
         *            MainWindow.AddStatusLine("Please save document first", true);
         *            return "";
         *        }
         *
         *        string s = Helper.GetCurrentWorkingDir();
         *        string t = Helper.GetPreviewFilename();
         *        string PreviewPdfFilePath = System.IO.Path.GetFullPath(CurFile) + t + ".pdf";
         *        string PdfFilePath = Helper.RemoveFileExtension(System.IO.Path.GetFullPath(CurFile)) + ".pdf";
         *        //            string PreviewPdfFilePath = s + "\\" + CurFile + t + ".pdf";
         *        //            string PdfFilePath = s + "\\" + Helper.RemoveFileExtension(CurFile) + ".pdf";
         *
         *        if (SaveAs == true)
         *        {
         *            SaveFileDialog sfd = new SaveFileDialog();
         *
         *            sfd.Filter = "Pdf Files|*.pdf" +
         *         "|All Files|*.*";
         *            sfd.OverwritePrompt = true;
         *            sfd.ValidateNames = true;
         *
         *            sfd.FileName = System.IO.Path.GetFileName(CurFile);
         *            // change file extension to .pdf
         *            sfd.FileName = Helper.RemoveFileExtension(sfd.FileName) + ".pdf";
         *            sfd.InitialDirectory = System.IO.Path.GetDirectoryName(CurFile);
         *            if (sfd.ShowDialog() != true)
         *                return "";
         *            PdfFilePath = sfd.FileName;
         *        }
         *
         *        try
         *        {
         *            File.Copy(PreviewPdfFilePath, PdfFilePath, true);
         *        }
         *        catch (Exception Ex)
         *        {
         *            AddStatusLine("Could not save PDF. " + Ex.Message, true);
         *            return "";
         *        }
         *
         *        AddStatusLine("Preview PDF file saved as " + PdfFilePath);
         *        return PdfFilePath;
         *    } */



        // this is called upon latex error,... the error is extracted from the latex output in the TexCompiler class
        void addProblemMarker(object sender, TexOutputParser.TexError err, TexCompiler.Job job = null) //String error, int linenr, TexCompiler.Severity severity)
        {
            // if job = null, the error was generated by the parser => always display
            // otherwise display only if the job really was the current document
            if (job == null || job.DocumentID == DocumentID)
            {
                TexErrors.Add(err);
            }
        }
示例#2
0
 void addProblemMarker(string msg, int line, int pos, Severity severity, string file)
 {
     TexOutputParser.TexError err = new TexOutputParser.TexError();
     err.error             = msg;
     err.causingSourceFile = file;
     err.linenr            = line;
     err.pos      = pos;
     err.severity = severity;
     addProblemMarker(this, err);
 }
示例#3
0
        void AsyncParser_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            AsyncParserResultType Result = new AsyncParserResultType();

            //make sure that double typed numbers are converted with decimal point (not comma!) to string
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

            try
            {
                AsyncParserJob job = e.Argument as AsyncParserJob;
                Result.DocumentID = job.DocumentID;
                Tikz_ParseTree tp = TikzParser.Parse(job.code);
                Result.ParseTree = tp;

                //include any styles from include files via \input cmd
                string inputfile = "";
                try
                {
                    //find input files using Regex
                    MatchCollection files = InputsRegex.Matches(job.code);
                    foreach (Match file in files)
                    {
                        //open, read, parse, and close each included file.
                        inputfile = file.Groups["file"].ToString();
                        if (File.Exists(inputfile))
                        {
                            StreamReader sr        = new StreamReader(inputfile);
                            string       inputcode = sr.ReadToEnd();
                            sr.Close();
                            Tikz_ParseTree tp2 = TikzParser.ParseInputFile(inputcode);
                            //if tp2 == null there probably was nothing useful included.
                            if (tp2 != null)
                            {
                                //every style that was found in included file, add it to parse tree of main file.
                                foreach (KeyValuePair <string, Tikz_Option> style in tp2.styles)
                                {
                                    if (!Result.ParseTree.styles.ContainsKey(style.Key))
                                    {
                                        Result.ParseTree.styles.Add(style.Key, style.Value);
                                    }
                                    else
                                    {
                                        ParserException          pe = new ParserException("");
                                        TexOutputParser.TexError te = new TexOutputParser.TexError();
                                        te.Message  = "Style [" + style.Key + "] is defined multiple times. Check position " + style.Value.StartPosition() + " in " + inputfile + " and this definition.";
                                        te.pos      = Result.ParseTree.styles[style.Key].StartPosition();
                                        te.severity = Severity.WARNING;
                                        pe.e        = te;
                                        throw pe;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Result.Warning       = ex;
                    Result.WarningSource = inputfile;
                }
            }
            catch (Exception ex)
            {
                //never set e.Cancel = true;
                //if you do, you cannot access e.Result from AsyncParser_RunWorkerCompleted.
                Result.Error         = ex;
                Result.WarningSource = ShortFileName;
            }
            finally
            {
                e.Result = Result;
            }
        }
示例#4
0
        void AsyncParser_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            AsyncParserResultType Result = new AsyncParserResultType();
            //make sure that double typed numbers are converted with decimal point (not comma!) to string
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

            try
            {
                AsyncParserJob job = e.Argument as AsyncParserJob;
                Result.DocumentID = job.DocumentID;
                Tikz_ParseTree tp = TikzParser.Parse(job.code);
                Result.ParseTree = tp;

                //include any styles from include files via \input cmd
                string inputfile = "";
                try
                {
                    //find input files using Regex                    
                    MatchCollection files = InputsRegex.Matches(job.code);
                    foreach (Match file in files)
                    {
                        //open, read, parse, and close each included file.
                        inputfile = file.Groups["file"].ToString();
                        if (File.Exists(inputfile))
                        {
                            StreamReader sr = new StreamReader(inputfile);
                            string inputcode = sr.ReadToEnd();
                            sr.Close();
                            Tikz_ParseTree tp2 = TikzParser.ParseInputFile(inputcode);
                            //if tp2 == null there probably was nothing useful included.
                            if (tp2 != null)
                            {
                                //every style that was found in included file, add it to parse tree of main file.
                                foreach (KeyValuePair<string, Tikz_Option> style in tp2.styles)
                                {
                                    if (!Result.ParseTree.styles.ContainsKey(style.Key))
                                    {
                                        Result.ParseTree.styles.Add(style.Key, style.Value);
                                    }
                                    else
                                    {
                                        ParserException pe = new ParserException("");
                                        TexOutputParser.TexError te = new TexOutputParser.TexError();
                                        te.Message = "Style [" + style.Key + "] is defined multiple times. Check position " + style.Value.StartPosition() + " in " + inputfile + " and this definition.";
                                        te.pos = Result.ParseTree.styles[style.Key].StartPosition();
                                        te.severity = Severity.WARNING;
                                        pe.e = te;
                                        throw pe;
                                    }
                                }
                            }

                        }
                    }

                }
                catch (Exception ex)
                {
                    Result.Warning = ex;
                    Result.WarningSource = inputfile;
                }
            }
            catch (Exception ex)
            {
                //never set e.Cancel = true;
                //if you do, you cannot access e.Result from AsyncParser_RunWorkerCompleted.
                Result.Error = ex;
                Result.WarningSource = ShortFileName;
            }
            finally
            {
                e.Result = Result;
            }
        }
示例#5
0
 void addProblemMarker(string msg, int line, int pos, Severity severity, string file)
 {
     TexOutputParser.TexError err = new TexOutputParser.TexError();
     err.error = msg;
     err.causingSourceFile = file;
     err.linenr = line;
     err.pos = pos;
     err.severity = severity;
     addProblemMarker(this, err);
 }