Example #1
0
        public void TryDisposeFileTest()
        {
            TexCompiler tc = new TexCompiler();
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            TEDocumentVM target = new TEDocumentVM(null, tc);

            GlobalUI.MockResult  = MessageBoxResult.Cancel;
            GlobalUI.LastMessage = "";

            // no changes made -> user should not be asked
            bool ret = target.TryDisposeFile();

            Assert.AreEqual(GlobalUI.LastMessage, "");
            Assert.IsTrue(ret);

            // make a change
            target.Document.Insert(0, " ");
            ret = target.TryDisposeFile();
            Assert.AreNotEqual(GlobalUI.LastMessage, "");
            Assert.IsFalse(ret);
            Assert.IsTrue(target.ChangesMade);

            // say we don't want to save changes
            GlobalUI.MockResult = MessageBoxResult.No;
            ret = target.TryDisposeFile();
            Assert.IsTrue(ret);
        }
Example #2
0
        public void ExportFileTest()
        {
            TexCompiler tc = new TexCompiler();
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            TEDocumentVM target = new TEDocumentVM(null, tc);

            GlobalUI.MockResult  = MessageBoxResult.Cancel;
            GlobalUI.LastMessage = "";
            string jpgfile = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\test.jpg";

            if (File.Exists(jpgfile))
            {
                File.Delete(jpgfile);
            }
            GlobalUI.MockFileDialogResult = true;
            target.ExportFileCommand.Execute(null);
            Assert.IsTrue(File.Exists(jpgfile));

            // now save file, and try again with different extension
            string filename = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\" + "temp2.tex";

            GlobalUI.MockFileDialogResult = true;
            target.SaveCurFile();

            jpgfile = GlobalUI.MockFileDialogFileName = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\test.png";
            if (File.Exists(jpgfile))
            {
                File.Delete(jpgfile);
            }
            target.ExportFileCommand.Execute(null);
            // check that file is actually there
            Assert.IsTrue(File.Exists(jpgfile));
        }
Example #3
0
        public void SavePdfTest()
        {
            TexCompiler tc = new TexCompiler();
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            string       cFile  = string.Empty; // TODO: Initialize to an appropriate value
            TEDocumentVM target = new TEDocumentVM(null, tc);

            GlobalUI.MockResult  = MessageBoxResult.Cancel;
            GlobalUI.LastMessage = "";
            // try to save pdf -> should not work, file should be saved first
            string pdffile = target.SavePdf(false);

            Assert.AreEqual("", pdffile);

            // now save file
            string filename = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\" + "temp2.tex";

            GlobalUI.MockFileDialogResult = true;
            target.SaveCurFile();

            pdffile = target.SavePdf(false);
            Assert.That(pdffile, Is.EqualTo(Helper.RemoveFileExtension(filename) + ".pdf").IgnoreCase);

            // check that file is actually there
            Assert.IsTrue(File.Exists(pdffile));
        }
Example #4
0
        public void TestSetup()
        {
            tc          = new TexCompiler();
            tc.JobDone += (s, e) => { LastReceivedJob = e.job; LastReceivedEA = e; JobFailed_Reported = e.ExitCode != 0; };

            LastReceivedJob    = null;
            LastReceivedEA     = null;
            JobFailed_Reported = false;
        }
Example #5
0
        public void IsStandaloneTest()
        {
            string code     = string.Empty; // TODO: Initialize to an appropriate value
            bool   expected = false;        // TODO: Initialize to an appropriate value
            bool   actual;

            actual = TexCompiler.IsStandalone(code);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Example #6
0
        /// <summary>
        /// Starts the compilation.
        /// </summary>
        /// <param name="TexCode">The raw Tex code, possibly without preamble.</param>
        /// <param name="OutputFile">The desired output file. The extension determines the file type.</param>
        public void DoCompile(string TexCode, string OutputFile)
        {
            DesiredOutputFile = OutputFile;
            WorkingDir        = Directory.GetCurrentDirectory();



            // add pre- and postamble if file is not standalone... don't use precompiled headers here since we need
            // to add a \def\pgfsysdriver{pgfsys-tex4ht.def}
            if (!TexCompiler.IsStandalone(TexCode))
            {
                TexCode = CompilerSettings.Instance.Tex_Preamble
                          + Environment.NewLine
                          + "\\begin{document}"
                          + Environment.NewLine
                          + TexCode
                          + Environment.NewLine
                          + CompilerSettings.Instance.Tex_Postamble;
            }

            switch (System.IO.Path.GetExtension(OutputFile).ToLower())
            {
            case ".htm":
            case ".html":
            case ".svg":
                // inject a \def\pgfsysdriver{pgfsys-tex4ht.def} after the line with \documentclass
                TexCode = InsertAfterDocumentClass(TexCode, @"\def\pgfsysdriver{pgfsys-tex4ht.def}");
                break;

            default:
                AddStatusLine("Error: unsupported file type: " + System.IO.Path.GetExtension(OutputFile));
                return;
            }

            // get a temp filename and save the tex file
            TempFile = Consts.cTempExportFile + DateTime.Now.Ticks.ToString();
            try
            {
                File.WriteAllText(TempFile + ".tex", TexCode);
            }
            catch (Exception)
            {
                AddStatusLine("Failed to save temporary tex file to: " + TempFile + ".tex");
                AddStatusLine("Export cancelled");
                return;
            }

            // finally run htlatex...
            texProcess.StartInfo.Arguments = TempFile + ".tex"; // ".tex \"\" \"\" \"\" \"-interaction=nonstopmode \"";
            AddStatusLine("Running htlatex: " + texProcess.StartInfo.FileName + " " + texProcess.StartInfo.Arguments);
            texProcess.Start();
            texProcess.BeginOutputReadLine();
        }
Example #7
0
        public void SavePdfTest()
        {
            TexCompiler tc = new TexCompiler();
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            string cFile = string.Empty; // TODO: Initialize to an appropriate value
            TEDocumentVM <AvalonDocumentWrapper> target = new TEDocumentVM <AvalonDocumentWrapper>(null, tc);
            string filename = GlobUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\" + "temp2.tex";

            GlobUI.MockFileDialogResult = true;
            target.SaveCurFile();

            Thread.Sleep(1000);

            target.SavePdf(false);

            Assert.IsTrue(File.Exists(Helper.RemoveFileExtension(filename) + ".pdf"));
        }
Example #8
0
        public MainWindowVM(TexCompiler compiler)
        {
            Compiler = compiler;
            //Documents = new ObservableCollection<TEDocumentView>();
            // create one document to start with
            //AddDocument();

            /*  for (int i = 0; i < 3; i++)
             * {
             *    AvalonDock.DocumentContent ad = new AvalonDock.DocumentContent() { Title = "Hallo Welt" };
             *    ICSharpCode.AvalonEdit.TextEditor aedit = new ICSharpCode.AvalonEdit.TextEditor();
             *    //avalonDoc.DataContext = tabViewModel;
             *    ad.Content = aedit;
             *    //DocumentContents.Insert(0, avalonDoc);
             *    //avalonDoc.Focus();
             *
             *    DocumentsAD.Add(ad);
             * }*/
        }
Example #9
0
        void TheCompiler_JobSucceeded(object sender, TexCompiler.Job job)
        {
            // it may happen that pdflatex returns after a new document has been created->then don't load the pdf
            if (job.DocumentID == DocumentID)
            {
                if (!job.GeneratePrecompiledHeaders)
                {
                    // set the currrent BB, if the BB could be determined.
                    // if not, and we are in preview mode, we have a problem
                    if (job.hasBB)
                    {
                        Rect newBB = job.BB;
                        newBB.Inflate(Properties.Settings.Default.BB_Margin, Properties.Settings.Default.BB_Margin);
                        CurrentBB = newBB;
                    }
                    BBvalid = job.hasBB;
                    // (re-)load the pdf to display                
                    PdfPath = Helper.RemoveFileExtension(job.path) + ".pdf";
                    if (OnPdfReady != null)
                        OnPdfReady(this, new PdfReadyEventArgs() { ReloadPdf = true });
                    ReloadPdf++;

                }
            }

        }
Example #10
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);
        }