public RasterControl() { InitializeComponent(); if (DesignMode) { return; } disablerPanel = new Panel() { Dock = DockStyle.Fill, BackColor = Color.Transparent, Visible = false, Cursor = Cursors.No }; toolTip1.SetToolTip(disablerPanel, "Overlay out of sync. WYSIWYG editing is disabled"); //toolTip1.SetToolTip(this, "The WYSIWYG area"); //toolTip1.Popup += new PopupEventHandler(toolTip1_Popup); //toolTip1.ReshowDelay = 50; //toolTip1.InitialDelay = 100; //toolTip1.ShowAlways = true; toolTip1.Active = true; this.MouseHover += new EventHandler(RasterControl_MouseHover); this.Controls.Add(disablerPanel); CreateContextMenu(); //this.CanFocus = true; this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer | ControlStyles.Selectable, true); TheRasterModel = new RasterControlModel(this); IPdfToBmp <Bitmap> Pdf2Bmp; if (CompilerSettings.Instance.UseExternalRenderer) { Pdf2Bmp = new PdfToBmpExtWinForms(); } else { Pdf2Bmp = new PdfToBmp(); } TheDisplayModel = new TikzDisplayModel <Bitmap>(this, Pdf2Bmp); TheOverlayModel = new PdfOverlayModel(this, this); TheOverlayModel.DisplayTree.DisplayTreeChanged += new EventHandler <TikzDisplayTree.DisplayTreeChangedEventArgs>(DisplayTree_DisplayTreeChanged); MarkObject_Timer.Interval = 500; MarkObject_Timer.Tick += new EventHandler(MarkObject_Timer_Tick); // listen to Bitmap changes MyBindings.Add(BindingFactory.CreateBinding(TheDisplayModel, "Bmp", (o) => this.Invalidate(), null)); }
public DynamicPreamble() { InitializeComponent(); txtPreamble.SetHighlighting("Tikz"); txtPreamble.IsReadOnly = true; // setup bindings TheVM = new DynPreambleVM(vm => DynPreambleDialog.ShowDynPreambleDialog(this.ParentForm, vm)); cmdAdd.Click += (s, e) => TheVM.AddCommand.Execute(null); cmdRemove.Click += (s, e) => TheVM.DeleteCommand.Execute(null); cmdUp.Click += (s, e) => TheVM.MoveUpCommand.Execute(null); cmdDown.Click += (s, e) => TheVM.MoveDownCommand.Execute(null); cmdEdit.Click += (s, e) => TheVM.EditCommand.Execute(null); BindingFactory.CreateBinding(TheVM, "Preamble", vm => { txtPreamble.Text = vm.Preamble; txtPreamble.Refresh(); if (PreambleChanged != null) { PreambleChanged(this, new EventArgs()); } }, () => txtPreamble.Text = "<unavailable>"); BindingFactory.CreateIListBinding(TheVM.ElementList, lstItems.Items, (DynPreambleElementVM i) => CreateItemFromVM(i), (ListViewItem lvi) => (lvi as ListViewItem).Tag as DynPreambleElementVM); BindingFactory.CreateBinding(TheVM, "CurrentIndex", vm => { if (vm.CurrentIndex >= 0 && vm.CurrentIndex < lstItems.Items.Count) { lstItems.Items[vm.CurrentIndex].Selected = true; } else { foreach (var i in lstItems.Items.OfType <ListViewItem>()) { i.Selected = false; } } }, null); lstItems.SelectedIndexChanged += (s, e) => TheVM.CurrentIndex = lstItems.SelectedIndices.Count > 0 ? lstItems.SelectedIndices[0] : -1; this.HandleDestroyed += (o, e) => { if (PreamblesFile != null) { TheVM.SavePreambles(PreamblesFile); } }; }
ListViewItem CreateItemFromVM(DynPreambleElementVM vm) { var ret = new ListViewItem() { Tag = vm }; ret.SubItems.Add(""); BindingFactory.CreateBinding(vm, "Name", v => { ret.Text = v.Name; }, () => ret.Text = "<Error>", false); BindingFactory.CreateBinding(vm, "Code", v => { ret.SubItems[1].Text = v.CodeOneLine; }, () => ret.SubItems[1].Text = "<Error>", false); ret.Checked = vm.IsActive; return(ret); }
public ExportCompileDialog() { InitializeComponent(); // set up bindings TheVM = new ExportCompileVM(); BindingFactory.CreateBinding(TheVM, "CloseButtonText", vm => cmdCancel.Text = vm.CloseButtonText, null); BindingFactory.CreateBinding(TheVM, "StatusText", vm => { txtStatus.Text = vm.StatusText; txtStatus.SelectionStart = txtStatus.Text.Length; txtStatus.ScrollToCaret(); }, null); BindingFactory.CreateBinding(TheVM, "SuccessLabelVisible", vm => lblSuccess.Visible = vm.SuccessLabelVisible, null); BindingFactory.CreateBinding(TheVM, "FailedLabelVisible", vm => lblFailed.Visible = vm.FailedLabelVisible, null); BindingFactory.CreateBinding(TheVM, "ProgressBarVisible", vm => progressBar1.Visible = vm.ProgressBarVisible, null); TheVM.RequestClose += (s, e) => Close(); FormClosing += (s, e) => TheVM.KillProcess(); }
void DisplayTree_DisplayTreeChanged(object sender, TikzDisplayTree.DisplayTreeChangedEventArgs e) { if (e.Type == TikzDisplayTree.DisplayTreeChangedType.Clear) { // clear bindings foreach (var b in DisplayTreeBindings) { b.Source = null; } DisplayTreeBindings.Clear(); Invalidate(); } if (e.Type == TikzDisplayTree.DisplayTreeChangedType.Insert) { // listen to BB changed to redraw if necessary foreach (var os in e.AffectedItems) { DisplayTreeBindings.Add(BindingFactory.CreateBinding(os, "BB", o => this.Invalidate(), null)); } Invalidate(); } }
/// <summary> /// Wire controls to viewmodels (etc). /// </summary> void SetupBindings() { splitContainer2.Panel2.ClientSizeChanged += new EventHandler(Panel2_Resize); //rasterControl1.Resize += new EventHandler(Panel2_Resize); rasterControl1.SizeChanged += new EventHandler(Panel2_Resize); rasterControl1.MouseMove += new MouseEventHandler(rasterControl1_MouseMove); rasterControl1.MouseWheel += new MouseEventHandler(rasterControl1_MouseWheel); rasterControl1.JumpToSource += new EventHandler <RasterControl.JumpToSourceEventArgs>(rasterControl1_JumpToSource); rasterControl1.ReplaceText += new EventHandler <TikzEdt.Overlay.ReplaceTextEventArgs>(rasterControl1_ReplaceText); //rasterControl1.MouseDown += (s, e) => { if (e.Button == System.Windows.Forms.MouseButtons.Middle) AddStatusLine("hjhjkh"); }; cmbEdgeStyle.TextChanged += (s, e) => TheVM.TheDocument.EdgeStyle = cmbEdgeStyle.Text; cmbNodeStyle.TextChanged += (s, e) => TheVM.TheDocument.NodeStyle = cmbNodeStyle.Text; cmbEdgeStyle.DropDown += (s, e) => { cmbEdgeStyle.Items.Clear(); cmbEdgeStyle.Items.AddRange(TheVM.TheDocument.TikzStyles.ToArray()); }; cmbNodeStyle.DropDown += (s, e) => { cmbNodeStyle.Items.Clear(); cmbNodeStyle.Items.AddRange(TheVM.TheDocument.TikzStyles.ToArray()); }; dynamicPreamble.PreambleChanged += (s, e) => TheVM.DynamicPreamble = dynamicPreamble.Preamble; TheVM.DynamicPreamble = dynamicPreamble.Preamble; //TheVM.NewCommandHandler(this, new System.Windows.Input.ExecutedRoutedEventArgs()) ; // add bindings rasterControl1.DataBindings.Add("ShowOverlay", cmdShowOverlay, "Checked"); rasterControl1.DataBindings.Add("UsePolarCoordinates", chkUsePolar, "Checked"); // Note that the TheDocument.Document property is bound "automatically" by the hack described in the TextEditorDocumentWrapper class. var sp = BindingFactory.CreateProvider(TheVM, "TheDocument", vm => vm.TheDocument); BindingFactory.CreateBindingSP(sp, "ParseTree", doc => rasterControl1.ParseTree = doc.ParseTree, () => rasterControl1.ParseTree = null); BindingFactory.CreateBindingSP(sp, "PdfPath", doc => rasterControl1.PdfPath = doc.PdfPath, () => rasterControl1.PdfPath = ""); BindingFactory.CreateBindingSP(sp, "ReloadPdf", doc => rasterControl1.ReloadPdf = doc.ReloadPdf, null); BindingFactory.CreateBindingSP(sp, "Resolution", doc => rasterControl1.Resolution = doc.Resolution, null); BindingFactory.CreateBindingSP(sp, "CurrentBB", doc => rasterControl1.BB = doc.CurrentBB, null); BindingFactory.CreateBindingSP(sp, "AllowEditing", doc => rasterControl1.AllowEditing = doc.AllowEditing, null); BindingFactory.CreateBindingSP(sp, "EdgeStyle", doc => rasterControl1.EdgeStyle = doc.EdgeStyle, null); BindingFactory.CreateBindingSP(sp, "NodeStyle", doc => rasterControl1.NodeStyle = doc.NodeStyle, null); BindingFactory.CreateBindingSP(sp, "Resolution", doc => zoomCtrl.Value = Convert.ToInt32(doc.Resolution), null); zoomCtrl.ValueChanged += (s, e) => TheVM.TheDocument.Resolution = zoomCtrl.Value; BindingFactory.CreateBindingSP(sp, "DisplayString", doc => this.Text = "TikzEdt - " + doc.DisplayString, () => this.Text = "TikzEdt"); BindingFactory.CreateBindingSP(sp, "IsStandAlone", doc => lblStandalone.Visible = doc.IsStandAlone, () => lblStandalone.Visible = false); BindingFactory.CreateBinding(TheVM, "RasterRadialOffset", vm => { txtRadialOffset.Value = (decimal)vm.RasterRadialOffset; rasterControl1.RadialOffset = vm.RasterRadialOffset; }, null); BindingFactory.CreateBinding(TheVM, "RasterSteps", vm => { txtRadialSteps.Value = vm.RasterSteps; rasterControl1.RasterRadialSteps = (uint)vm.RasterSteps; }, null); BindingFactory.CreateBinding(TheVM, "RasterWidth", vm => { txtGrid.Value = (decimal)vm.RasterWidth; rasterControl1.RasterWidth = vm.RasterWidth; }, null); txtRadialOffset.ValueChanged += (s, e) => TheVM.RasterRadialOffset = (double)txtRadialOffset.Value; txtRadialSteps.ValueChanged += (s, e) => TheVM.RasterSteps = Convert.ToInt32(txtRadialSteps.Value); txtGrid.ValueChanged += (s, e) => TheVM.RasterWidth = (double)txtGrid.Value; rasterControl1.ToolChanged += (sender, e) => TheVM.CurrentTool = rasterControl1.Tool; BindingFactory.CreateBinding(TheVM, "EditorMode", vm => { wYSIWYGToolStripMenuItem.Checked = vm.EditorMode == TEMode.Wysiwyg; productionToolStripMenuItem.Checked = vm.EditorMode == TEMode.Production; previewToolStripMenuItem.Checked = vm.EditorMode == TEMode.Preview; }, null); var errlistsp = BindingFactory.CreateProviderSP(sp, "TexErrors", doc => doc.TexErrors); BindingFactory.CreateCollectionBindingSP(errlistsp, (s, e) => FillErrorsList()); BindingFactory.CreateBinding(TheVM, "CurrentTool", vm => { ToolButtons.Each((tsb, i) => tsb.Checked = ((int)vm.CurrentTool == i)); rasterControl1.Tool = vm.CurrentTool; }, null); BindingFactory.CreateBinding(TheCompiler.Instance, "Compiling", (c) => { cmdAbortCompile.Enabled = abortCompilationToolStripMenuItem.Enabled = c.Compiling; }, () => { cmdAbortCompile.Enabled = abortCompilationToolStripMenuItem.Enabled = true; }); txtCode.Document.UndoStack.OperationPushed += UndoStack_OperationPushed; txtCode.Document.UndoStack.ActionRedone += UndoStack_OperationPushed; txtCode.Document.UndoStack.ActionUndone += UndoStack_OperationPushed; BindingFactory.CreateBinding(TheVM, "TheDocument", vm => UndoStack_OperationPushed(this, null), null); // document changed -> update undo state // load settings var S = Properties.Settings.Default; Width = S.Window_Width; Height = S.Window_Height; SizeChanged += (s, e) => { Properties.Settings.Default.Window_Height = Height; Properties.Settings.Default.Window_Width = Width; }; this.Left = S.Window_Left; this.Top = S.Window_Top; LocationChanged += (s, e) => { Properties.Settings.Default.Window_Top = Top; Properties.Settings.Default.Window_Left = Left; }; WindowState = S.Window_State; ClientSizeChanged += (s, e) => Properties.Settings.Default.Window_State = this.WindowState; try { splitContainer2.SplitterDistance = S.OverlayCanvasCol2WidthSetting; splitContainer1.SplitterDistance = S.LeftToolsColWidthSetting; } catch (Exception) { } splitContainer2.SplitterMoved += (s, e) => Properties.Settings.Default.OverlayCanvasCol2WidthSetting = splitContainer2.SplitterDistance; splitContainer1.SplitterMoved += (s, e) => Properties.Settings.Default.LeftToolsColWidthSetting = splitContainer1.SplitterDistance; BindingFactory.CreateBinding(S, "Editor_ShowLineNumbers", s => txtCode.ShowLineNumbers = s.Editor_ShowLineNumbers, null); BindingFactory.CreateBinding(S, "Editor_Font", s => { txtCode.Font = s.Editor_Font; }, null); BindingFactory.CreateBinding(S, "Snippets_ThumbnailSize", s => snippetList1.ThumbnailSize = s.Snippets_ThumbnailSize, null); snippetList1.ThumbnailSizeChanged += (s, e) => Properties.Settings.Default.Snippets_ThumbnailSize = snippetList1.ThumbnailSize; BindingFactory.CreateBinding(S, "AutoCompileOnDocumentChange", s => { autoCompilationOnChangeToolStripMenuItem.Checked = s.AutoCompileOnDocumentChange; TheVM.AutoCompileOnDocumentChange = s.AutoCompileOnDocumentChange; }, null); autoCompilationOnChangeToolStripMenuItem.CheckedChanged += (s, e) => { S.AutoCompileOnDocumentChange = TheVM.AutoCompileOnDocumentChange = autoCompilationOnChangeToolStripMenuItem.Checked; }; }