Esempio n. 1
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));

        }
Esempio n. 2
0
        /// <summary>
        /// Loads a document from file.
        ///
        /// </summary>
        /// <param name="cFile"></param>
        public void LoadFile(string cFile = null)
        {
            TEDocumentVM <T> doc;

            try
            {
                doc = new TEDocumentVM <T>(this, Compiler, cFile);
                //doc.OnClose += new EventHandler(doc_OnClose);
                // TEDocumentView view = new TEDocumentView(doc);
                doc.OnSaved += ((s, e) => GlobalUI.UI.RaiseRecentFileEvent(s, (s as TEDocumentVM <T>).FilePath, true));
                //Documents.Insert(0, view);
                //ActiveView = view;
                if (cFile != null)
                {
                    GlobalUI.UI.RaiseRecentFileEvent(doc, cFile, true);
                }

                TheDocument = doc;
            }
            catch (Exception ex)
            {
                GlobalUI.UI.ShowMessageBox(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                if (cFile != null)
                {
                    GlobalUI.UI.RaiseRecentFileEvent(this, cFile, false);
                }
            }
        }
Esempio n. 3
0
/*
 *      /// <summary>
 *      /// Tries to create a new file. Is the command parameter is not null, then a new instance of TikzEdt is opened.
 *      /// If the current file is unsaved, the user has to be asked to save.
 *      /// </summary>
 *      public void NewCommandHandler(object sender, ExecutedRoutedEventArgs e)
 *      {
 *          CreateNewFile(e.Parameter != null);
 *      } */

        /// <summary>
        /// Tries to cretae a new File.
        /// (If the current file contains changes and the user rejects to discard/save them, no file is created).
        /// </summary>
        /// <param name="InNewInstance">Whether to open a new instance of TikzEdt.</param>
        public void CreateNewFile(bool InNewInstance = false)
        {
            if (InNewInstance)
            {
                // open a new instance (TODO: in the same folder...)
                StartNewTEInstance();
            }
            else
            {
                if (TheDocument == null || TheDocument.TryDisposeFile())
                {
                    TheDocument          = new TEDocumentVM <T>(this, Compiler);
                    TheDocument.OnSaved += ((s, args) => GlobalUI.UI.RaiseRecentFileEvent(s, (s as TEDocumentVM <T>).FilePath, true));
                }
            }
        }
Esempio n. 4
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));

        }
Esempio n. 5
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);

        }
Esempio n. 6
0
        /// <summary>
        /// Tries to create a new file. Is the command parameter is not null, then a new instance of TikzEdt is opened.
        /// If the current file is unsaved, the user has to be asked to save.
        /// </summary>
        private void NewCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Parameter != null)
            {
                // open a new instance (TODO: in the same folder...)
                System.Diagnostics.Process.Start( System.Reflection.Assembly.GetExecutingAssembly().Location );
            }
            else
            {
                if (TheDocument == null || TheDocument.TryDisposeFile())
                {
                    TheDocument = new TEDocumentVM();
                    TheDocument.OnSaved += ((s, args) => MainWindow.recentFileList.InsertFile((s as TEDocumentVM).FilePath));
                }
            }

        }
Esempio n. 7
0
        /// <summary>
        /// Loads a document from file.
        /// 
        /// </summary>
        /// <param name="cFile"></param>
        public void LoadFile(string cFile = null)
        {
            TEDocumentVM doc;
            try
            {
                doc = new TEDocumentVM(cFile);
                //doc.OnClose += new EventHandler(doc_OnClose);
               // TEDocumentView view = new TEDocumentView(doc);
                doc.OnSaved += ( (s, e) => MainWindow.recentFileList.InsertFile((s as TEDocumentVM).FilePath) );
                //Documents.Insert(0, view);
                //ActiveView = view;
                if (cFile != null)
                    MainWindow.recentFileList.InsertFile(cFile);

                TheDocument = doc;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
                if (cFile != null)
                    MainWindow.recentFileList.RemoveFile(cFile);

            }
        }
Esempio n. 8
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"));
            
        }