Example #1
0
        //PdfOverlay pdfOverlay1;

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

            (GlobalUI.UI as GlobalUIWinForms).MainForm = this;
            TheVM = new MainWindowVM<TextEditorDocumentWrapper>(TheCompiler.Instance);

            InitializeComponent();

            if (DesignMode)
                return;
			
			
            TextEditorDocumentWrapper.TheOneAndOnly = txtCode;

            // The order should be exactly the same as that in the OverlayToolType enum!!!
            ToolButtons = new List<ToolStripButton> { cmdMove, cmdNode, cmdEdge, cmdPath, cmdSmoothCurve, cmdBezier, cmdRectangle, cmdEllipse, cmdGrid, cmdArc, cmdArcEdit };
            ToolPaneButtons = new List<ToolStripButton> { cmdSnippets, cmdFiles, cmdDynPreamble };

            SetupComponents();

            SetupBindings();
							
            GlobalUI.UI.OnRecentFileEvent += (s, e) => { if (e.IsInsert) MyMRU.Insert(e.FileName); else MyMRU.Remove(e.FileName); };
            MyMRU.OnFileOpen += (s, e) => TheVM.Open(e.FileName, ModifierKeys.HasFlag(Keys.Control));    

            TheVM.CreateNewFile(false);

            
        }
Example #2
0
        //public static List<TexOutputParser.TexError> TexErrors = new List<TexOutputParser.TexError>();
  //      public static System.Collections.ObjectModel.ObservableCollection<TexOutputParser.TexError> TexErrors = new System.Collections.ObjectModel.ObservableCollection<TexOutputParser.TexError>();
   //     public FileSystemWatcher fileWatcher = new FileSystemWatcher();
        public MainWindow()
        {
            this.DataContext = TheVM = new ViewModels.MainWindowVM<AvalonDocumentWrapper>(TheCompiler.Instance);
            InitializeComponent();
            
            // register GlobalUI events 
            GlobalUIWPF GlobUI = (GlobalUIWPF)GlobalUI.UI;
            GlobUI.OnGlobalStatus += (s, e) => AddStatusLine(e.StatusLine, e.IsError);
            GlobUI.OnExportCompile += (s, e) => ExportCompiler.ExportCompileDialog.Export(e.Code, e.File);
            GlobUI.OnRecentFileEvent += (s, e) => { if (e.IsInsert) recentFileList.InsertFile(e.FileName); else recentFileList.RemoveFile(e.FileName); };
            GlobUI.MessageBoxOwner = this;

            // Register events with the global compiler
            TheCompiler.Instance.OnCompileEvent += TexCompiler_OnCompileEvent;
            TheCompiler.Instance.OnTexOutput += TexCompiler_OnTexOutput;

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

            // set up command bindings
            CommandBindings.Add(TheVM.GetNewCommandBinding());
            CommandBindings.Add(TheVM.GetOpenCommandBinding());
            CommandBindings.Add(TheVM.GetSaveCommandBinding());
            CommandBindings.Add(TheVM.GetSaveAsCommandBinding());

            //ICSharpCode.AvalonEdit.Document.TextDocument doc; doc.
            
            CommandBinding CommentCommandBinding = new CommandBinding(CommentCommand, CommentCommandHandler, AlwaysTrue);
            CommandBinding UnCommentCommandBinding = new CommandBinding(UnCommentCommand, UnCommentCommandHandler, AlwaysTrue);
       //     CommandBinding FindNextCommandBinding = new CommandBinding(FindNextCommand, FindNextCommandHandler, AlwaysTrue);
        //    CommandBinding FindPreviousCommandBinding = new CommandBinding(FindPreviousCommand, FindPreviousCommandHandler, AlwaysTrue);
        //    CommandBinding ShowCodeCompletionsCommandBinding = new CommandBinding(ShowCodeCompletionsCommand, ShowCodeCompletionsCommandHandler, AlwaysTrue);
        //    CommandBinding CompileCommandBinding = new CommandBinding(CompileCommand, CompileCommandHandler, AlwaysTrue);
       //     CommandBinding SavePdfCommandBinding = new CommandBinding(SavePdfCommand, SavePdfHandler, AlwaysTrue);
       //     CommandBinding SavePdfAsCommandBinding = new CommandBinding(SavePdfAsCommand, SavePdfAsHandler, AlwaysTrue);
            CommandBinding ShowPdfCommandBinding = new CommandBinding(ShowPdfCommand, ShowPdfHandler, AlwaysTrue);
       //     CommandBinding ExportFileCommandBinding = new CommandBinding(ExportFileCommand, ExportFileHandler, AlwaysTrue);
            CommandBinding OpenPgfManualBinding = new CommandBinding(OpenPgfManualCommand, OpenPgfManualHandler, AlwaysTrue); 
            
            pdfOverlay1.Rasterizer = rasterControl1.TheModel;
      //      EnsureFindDialogExists();

            TikzToBMPFactory.Instance.JobNumberChanged += TikzToBmpFactory_JobNumberChanged;

            // set up find/replace dialog
            FindReplaceManager.CurrentEditor = new FindReplace.TextEditorAdapter(txtCode);
            FindReplaceManager.ShowSearchIn = false;
            FindReplaceManager.OwnerWindow = this;
            CommandBindings.Add(FindReplaceManager.FindBinding);
            CommandBindings.Add(FindReplaceManager.ReplaceBinding);
            CommandBindings.Add(FindReplaceManager.FindNextBinding);

            updateChecker.Status += (s, e) => AddStatusLine(e.Description, e.HasFailed);
            updateChecker.Success += new EventHandler<TESharedComponents.UpdateChecker.SuccessEventArgs>(updateChecker_Success);

            recentFileList = RecentFileList;
            recentFileList.UseXmlPersister(System.IO.Path.Combine(Helper.GetAppdataPath(), "RecentFileList.xml"));
            
            //recentFileList.UseXmlPersister();
       //     AsyncParser.DoWork += new System.ComponentModel.DoWorkEventHandler(AsyncParser_DoWork);
       //     AsyncParser.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(AsyncParser_RunWorkerCompleted);

            //fileWatcher.NotifyFilter = NotifyFilters.LastWrite;
    //        fileWatcher.Changed += new FileSystemEventHandler(fileWatcher_Changed);

            this.KeyDown += new KeyEventHandler(MainWindow_KeyDown);

            // manually bind dynamic preamble
            DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(DynPreamble.DynPreambleView.PreambleProperty, typeof(DynPreamble.DynPreambleView) );
            if (dpd != null)
            {
                dpd.AddValueChanged(preambleView, delegate
                {
                    if (TheVM != null) TheVM.DynamicPreamble = preambleView.Preamble;
                });
            }
            if (TheVM != null) TheVM.DynamicPreamble = preambleView.Preamble;

            // bind lstError to TexErrors (make sure that TexErrors is suitable object for data binding!)
            //lstErrors.ItemsSource = TexErrors;
            //lstErrors.Items.GroupDescriptions.Add(new System.ComponentModel.GroupDescription())
            //lstErrors.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("severity", System.ComponentModel.ListSortDirection.Ascending));

            // in the constructor:
  //          txtCode.TextArea.TextEntering += textEditor_TextArea_TextEntering;
  //          txtCode.TextArea.TextEntered += textEditor_TextArea_TextEntered;

  /*          ofd.CheckFileExists = true;
            ofd.ValidateNames = true;
            ofd.Filter = "Tex Files|*.tex"+"|All Files|*.*";
            sfd.Filter = "Tex Files|*.tex"+"|All Files|*.*";
            sfd.OverwritePrompt = true;
            sfd.ValidateNames = true;

   * */
            txtStatus.Document.Blocks.Clear();

            RecentFileList.MenuClick += (s, e) => TheVM.Open(e.Filepath, Keyboard.Modifiers.HasFlag(ModifierKeys.Control));

            //cmbGrid.SelectedIndex = 4;
        }
        public void StdFileHandlingTest()
        {

            MainWindowVM target = new MainWindowVM(TheCompiler.Instance); 
            // To execute commands, we need to take a detour and bind them in a dummy
            StackPanel dummy = new StackPanel();
            dummy.CommandBindings.Add(target.SaveAsCommandBinding);
            dummy.CommandBindings.Add(target.NewCommandBinding);
            dummy.CommandBindings.Add(target.SaveCommandBinding);
            dummy.CommandBindings.Add(target.OpenCommandBinding);

            Console.WriteLine(Directory.GetCurrentDirectory());                        

            // create a new file 
            ApplicationCommands.New.Execute(null, dummy);
            GlobalUI.LastMessage = "";
            GlobalUI.MockResult = MessageBoxResult.Cancel;
            // create a new file again, the file was not changed, so the use should not be asked to save
            ApplicationCommands.New.Execute(null, dummy);
            Assert.AreEqual(GlobalUI.LastMessage, "");
            //Application.DoEvents();
        //    Thread.Sleep(10000);
            //DispatcherUtil.DoEvents();
            //Application.DoEvents();

            // now change the file a bit
            target.TheDocument.Document.Insert(0, "   ");
            string oldText = target.TheDocument.Document.Text;

          //  Thread.Sleep(1000);
            //DispatcherUtil.DoEvents();

            // try to override again
            ApplicationCommands.New.Execute(null, dummy);
            // now a messagebox must have been shown, and the file contents should be unchanged
            Assert.IsTrue(GlobalUI.LastMessage != "");
            Assert.AreEqual(target.TheDocument.Document.Text, oldText);

         //   Thread.Sleep(1000);
            //DispatcherUtil.DoEvents();

            // Now save the file to a temp file
            string filename = Directory.GetCurrentDirectory() + "\\temp.tex";
            if (File.Exists(filename))
                File.Delete(filename);

            Thread.Sleep(1000);
           // DispatcherUtil.DoEvents();

            GlobalUI.MockFileDialogFileName = filename;
            GlobalUI.MockFileDialogResult = true;
            ApplicationCommands.SaveAs.Execute(null, dummy);
            Assert.IsTrue(File.Exists(filename));
                       

            // Let pdflatex do its job (hack)
       //     Thread.Sleep(2000);
            //DispatcherUtil.DoEvents();

            //return;
            // check that temp files are removed, but pdf should exist
            Assert.IsTrue(File.Exists(filename+".preview.pdf"));
            //Assert.IsFalse(File.Exists("temp.tex.preview.log")); // are deleted upon destruction
            //Assert.IsFalse(File.Exists("temp.tex.preview.aux"));
            
            // change file on disk... change should be detected, and user asked to reload file
            GlobalUI.MockResult = MessageBoxResult.Yes; // reload the file
            File.WriteAllText(filename, "\\begin{tikzpicture} \r\n blabla\r\n \\end{tikzpicture}");
        //    System.Threading.Thread.Sleep(2000);
            System.Threading.Thread.Sleep(1000);
            DispatcherUtil.DoEvents();
            System.Threading.Thread.Sleep(1000);
            DispatcherUtil.DoEvents();
            Assert.IsTrue(target.TheDocument.Document.Text.Contains("blabla"));
            // file should not be marked as changed
            Assert.IsFalse(target.TheDocument.ChangesMade);

      //      Thread.Sleep(1000);

        }
Example #4
0
        //Gtk.Action actOpen = new Gtk.Action("Open", "Open", "Open file", Stock.Open);

        public MainWindow() : base("TikzEdt ")
        {
            (GlobalUI.UI as GlobalUIGTK).MainForm = this;
            ScintillaDocumentWrapper.TheOneAndOnly = txtCode;
            TheVM = new MainWindowVM<ScintillaDocumentWrapper>(TheCompiler.Instance);

            rasterControl1 = rasterControl1Box.RasterControl;
            rasterControl1.Rasterizer = rasterControl1.TheRasterModel;

            txtStatus.Buffer.TagTable.Add(new TextTag("red") { Foreground="red" });
            //txtCode.LexerLanguage = "html";
            txtCode.Lexer = 4; // html

            Resize(800, 600);
            Destroyed += (s, e) => Application.Quit();
            myLabel.Text = "Hello World!!!!";

            CreateMenus();
            CreateToolBars();

            VBox vb = new VBox(false, 0);
            vb.PackStart(mainMenu, false, false, 0);
            vb.PackStart(mainToolbar, false, false, 0);
            vb.PackStart(toolsToolbar, false, false, 0);

            HBox hb = new HBox(false, 0);
            hb.PackStart(toolsPaneBar, false, false, 0);

            ScrolledWindow scrw = txtStatusWnd = new ScrolledWindow();
            scrw.Add(txtStatus);
            statusTabPanel.AppendPage(scrw, new Label("Status"));

            statusTabPanel.AppendPage(lstErrors, new Label("Errors"));
            scrw = new ScrolledWindow();
            scrw.Add(txtTexOut);
            statusTabPanel.AppendPage(scrw, new Label("TeX Output"));

            //txtCode.SetText("This is Scintilla");

            vSplitter1.Add1(txtCode);
            vSplitter1.Add2(statusTabPanel);
            vSplitter1.Position = 400;

            hSplitter1.Add1(vSplitter1);
            var sw = new ScrolledWindow();
            sw.HscrollbarPolicy = Gtk.PolicyType.Automatic;
			sw.VscrollbarPolicy = Gtk.PolicyType.Automatic;
            //sw.Placement = CornerType.
			//Alignment a = new Alignment(0.5f,0.5f,0,0);
            //var vv = new Table(1,1,false);
            //vv.Attach(rasterControl1, 0, 0, 1,1,AttachOptions.Expand, AttachOptions.Expand, 0,0);
            /*var vv = new VBox();
            var vh = new HBox();
            vv.PackStart(rasterControl1, true, false, 0);
            vh.PackStart(vv, true, false, 0);*/
            Alignment al = new Alignment(.5f, .5f, 0, 0);
            al.Add(rasterControl1Box);
            sw.Add(al);
            hSplitter1.Add2(sw);
            hSplitter1.Position = 350;

            hSplitter2.Add1(new TextView() );
            hSplitter2.Add2(hSplitter1);
            hSplitter2.Position = 150;
            hb.PackStart(hSplitter2, true, true, 0);

            vb.PackStart(hb, true, true, 0);


            statusBar.PackStart(new Alignment(.5f, .5f, 1, 1), true, true, 0);
            statusBar.PackStart(lblStandAlone, false, false, 0);
            statusBar.PackStart(new Label("Grid"), false, false, 0);
            statusBar.PackStart(cmbGrid, false, false, 0);
            statusBar.PackStart(new Label("RS"), false, false, 0);
            statusBar.PackStart(txtRadialSteps, false, false, 0);
            statusBar.PackStart(new Label("RO"), false, false, 0);
            statusBar.PackStart(txtRadialOffset, false, false, 0);
            //statusBar.PackStart(new Separator(), false, false, 0);
            Button b = new Button(Stock.ZoomOut);
            //b.Label = "";
            statusBar.PackStart(b);
            statusBar.PackStart(scZoom);
            statusBar.PackStart(new Button(Stock.ZoomIn));
            vb.PackEnd(statusBar, false, false, 0);

            Add(vb);

            SetupBindings();

            ShowAll();

        }