/// <summary> /// Builds a new instance of SourceCodeDisplay. /// </summary> public SourceCodeDisplay() { ErrorList errorList = new ErrorList(); _codeBox = new CodeBox(); _stacktraceView = errorList; _stacktraceView.AutoSelectFirstItem = true; _stacktraceView.SelectedItemChanged += new EventHandler(SelectedItemChanged); _codeView = _codeBox; _btnPlugin = ErrorToolbar.NewStripButton(true, "Display source code context", Resources.ImageSourceCodeDisplay, null); _btnSwap = ErrorToolbar.NewStripButton(false, "ReverseOrder item order", Resources.ImageReverseItemOrder, OnClick); SplitterBox splitter = new SplitterBox(); _splitter = splitter; _splitter.SplitterDistanceChanged += new EventHandler(_splitter_DistanceChanged); _splitter.OrientationChanged += new EventHandler(_splitter_OrientationChanged); splitter.Control1 = errorList; splitter.Control2 = _codeBox; _codeBox.ShowCurrentLine = true; return; }
public DecompileTask(ICodeView view, AssemblyDefinition callingAssembly, object source) { View = view; View.CurrentTask = this; CallingAssembly = callingAssembly; Source = source; }
/// <summary> /// creates a constructor to implement the interface and initialize the instance variables, /// removes the comments and blocks so that it can be ignored while parsing the user written code /// </summary> /// <param name="codeView">required interface passed from the coding form</param> public CommandParserPresenter(ICodeView codeView) { this.codeView = codeView; this.code = codeView.editorCode.ToLower(); removeComments(); }
/// <summary> /// creates a constructor to implement the interface and initialize instance variables /// </summary> /// <param name="codeView">required interface passed from the coding form</param> public CodingPresenter(ICodeView codeView) { this.codeView = codeView; newPageButton = codeView.newPage; resources = codeView.resource; user = new UserInfo(); }
public void SetUp() { _mockStack = Substitute.For<IStackTraceView>(); _mockCode = Substitute.For<ICodeView>(); _code = new TestingCode(_mockStack, _mockCode); return; }
public void SetUp() { _mockStack = Substitute.For <IStackTraceView>(); _mockCode = Substitute.For <ICodeView>(); _code = new TestingCode(_mockStack, _mockCode); return; }
/// <summary> /// creates a constructor to implement the interface and initialize the instance variables, /// clears the error messages and resets the value of counter variables, /// parses the keywords and validates the code written by the user, /// adds a log of error messages in the listview for each error message, /// saves the block commands detected in the code to GeneratedLists to be used later during parsing, /// checks if pen or moveto/drawto command is declared and throws a exception if not found /// </summary> /// <param name="codeView">required interface passed from the coding form</param> public CommandValidatorPresenter(ICodeView codeView) { GeneratedLists.goodToRun = true; this.codeView = codeView; this.code = codeView.editorCode.ToLower(); this.fileName = codeView.fileName; codeView.ListView.Items.Clear(); GeneratedLists.errorMessages.Clear(); Counters.initialCode = code; ErrorPOSCounters.indexStartFORPos = 0; BlockCounters.indexStart = 0; BlockCounters.indexSecondStart = 0; parseKeyWords(); validateCode(); foreach (ErrorMessage msg in GeneratedLists.errorMessages) { ListViewItem listViewItem = new ListViewItem(new string[] { "DG" + msg.index, msg.message, "" + msg.line, msg.fileName }); codeView.ListView.Items.Add(listViewItem); } GeneratedLists.blockComsInCode = blockList; try { if (valueCmdList.Count > 0 && !valueCmdList.Any(x => x.name.Equals("pen"))) { throw new PenNotFoundException("Pen not found"); } } catch (PenNotFoundException) { GeneratedLists.goodToRun = false; MessageBox.Show("Pen is not declared. Drawing commands might not work.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } try { if (valueCmdList.Count > 0 && !valueCmdList.Any(x => x.name.Equals("moveto") || x.name.Equals("drawto"))) { throw new MoveToNotFoundException("Moveto not found"); } } catch (MoveToNotFoundException) { GeneratedLists.goodToRun = false; MessageBox.Show("Moveto is not declared. Moveto and drawto commands are used to position the drawing commands.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public static DispatcherOperation MainUpdateContinuation(ICodeView iface1, CustomTextSource4 source) { return(iface1.Dispatcher.InvokeAsync(() => { iface1.CustomTextSource = source; Debug.WriteLine("Return from await inner update"); // ;(int.TryParse("Setting reactangle width to " +new NTComputer ({ff, line) || Device<int>()))}; iface1.PerformingUpdate = false; iface1.InitialUpdate = false; iface1.RaiseEvent(new RoutedEventArgs(RoslynCodeBase.RenderCompleteEvent, iface1)); iface1.Status = CodeControlStatus.Rendered; var insertionPoint = iface1.InsertionPoint; if (insertionPoint == 0) { iface1.InsertionCharInfo = iface1.CharInfos.FirstOrDefault(); } }, DispatcherPriority.Send)); }
public static async Task <CustomTextSource4> UpdateFormattedText(ICodeView iface1) { Debug.WriteLine("Enteirng updateformattedtext " + iface1.PerformingUpdate); if (iface1.PerformingUpdate) { Debug.WriteLine("Already performing update"); return(null); } iface1.PerformingUpdate = true; iface1.Status = CodeControlStatus.Rendering; iface1.RaiseEvent(new RoutedEventArgs(RoslynCodeControl.RenderStartEvent, iface1)); var textStorePosition = 0; var linePosition = new Point(iface1.XOffset, 0); iface1.TextDestination.Children.Clear(); var line = 0; Debug.WriteLine("Calling inner update"); // ScrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; var fontFamilyFamilyName = iface1.FontFamily.FamilyNames[XmlLanguage.GetLanguage("en-US")]; Debug.WriteLine(fontFamilyFamilyName); Debug.WriteLine("OutputWidth " + iface1.OutputWidth); // not sure what to do here !! // Rectangle.Width = OutputWidth + Rectangle.StrokeThickness * 2; var emSize = iface1.FontSize; var fontWeight = iface1.FontWeight; var customTextSource4Parameters = iface1.CreateDefaultTextSourceArguments(); var mainUpdateParameters = new MainUpdateParameters(textStorePosition, line, linePosition, RoslynCodeControl.Formatter, iface1.OutputWidth, iface1.PixelsPerDip, emSize, fontFamilyFamilyName, iface1.UpdateChannel.Writer, fontWeight, iface1.DocumentPaginator, customTextSource4Parameters); await iface1.JTF2.SwitchToMainThreadAsync(); var source = await iface1.InnerUpdateAsync(mainUpdateParameters, customTextSource4Parameters); return(source); }
public TestingCode(IStackTraceView stack, ICodeView code) { _stacktraceView = stack; _codeView = code; }
public RoslynPaginator(ICodeView control, Size?pageSize = null, Thickness?margins = null) { _hdpi = 96; _vdpi = 96; var defaultSizeInches = new Size(8.5, 11); var defaultPageSize = new Size(defaultSizeInches.Width * _hdpi, defaultSizeInches.Height * _vdpi); var marginInches = 1.0; var defaultMargins = new Thickness(marginInches * _hdpi, marginInches * _vdpi, marginInches * _hdpi, marginInches * _vdpi); var ps = pageSize.GetValueOrDefault(defaultPageSize); var m = margins.GetValueOrDefault(defaultMargins); _control = control; DocPageSize = new Size(ps.Width - m.Left - m.Right, ps.Height - m.Top - m.Bottom); Debug.WriteLine( $"PAge size is {DocPageSize} or {DocPageSize.Width / _hdpi}\"x{DocPageSize.Height / _vdpi}\""); if (_control.TextDestination.Bounds.IsEmpty) { throw new InvalidOperationException(); } var visual = (Control)_control; var sourceDpi = VisualTreeHelper.GetDpi(visual); double w = _control.TextDestination.Bounds.Width; double h0 = _control.TextDestination.Bounds.Height; int pixelWidth; int pixelHeight; using (var graphics = Graphics.FromHwnd(IntPtr.Zero)) { pixelWidth = (int)(w * graphics.DpiX / 96.0); pixelHeight = (int)(h0 * graphics.DpiY / 96.0); } var intWidth = (int)_control.TextDestination.Bounds.Width; Debug.WriteLine("Width of textdest is " + intWidth); var intHeight0 = (int)_control.TextDestination.Bounds.Height; Debug.WriteLine("Height of textdest is " + intHeight0); _margins = m; _pageSize = ps; var b = new DrawingBrush { Drawing = _control.TextDestination, // Viewbox = _control.TextDestination.Bounds, // ViewboxUnits = BrushMappingMode.Absolute }; bool fRando = false; if (fRando) { var v = new DrawingVisual(); var dpi = VisualTreeHelper.GetDpi(v); var dpiPixelsPerInchX = dpi.PixelsPerInchX; var dpiPixelsPerInchY = dpi.PixelsPerInchY; var p1 = Math.Floor(intHeight0 / DocPageSize.Height); if (Math.Abs(intHeight0 % DocPageSize.Height) > 0.5) { p1++; } var h = (int)Math.Floor(p1 * DocPageSize.Height); var dc = v.RenderOpen(); var rectangle = new Rect(0, 0, _control.TextDestination.Bounds.Width, _control.TextDestination.Bounds.Height); dc.DrawRectangle(b, null, rectangle); var formattedText = new FormattedText($"{intWidth}x{h} @ {dpiPixelsPerInchX}x{dpiPixelsPerInchY}", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), 16, Brushes.Yellow , null, TextFormattingMode.Ideal, 1); var origin = new Point(5, 5); var bg = new Rect(origin, new Size(formattedText.Width, formattedText.Height)); dc.DrawRectangle(Brushes.Black, null, bg); dc.DrawText( formattedText, origin); dc.Close(); var bmp = new RenderTargetBitmap(pixelWidth , pixelHeight , dpiPixelsPerInchX * 2, dpiPixelsPerInchY * 2, PixelFormats.Pbgra32); bmp.Render(v); _bmp = bmp; } else { DrawingImage di = new DrawingImage(_control.TextDestination); DrawingVisual v = new DrawingVisual(); var dc = v.RenderOpen(); dc.DrawImage(di, _control.TextDestination.Bounds ); dc.Close(); var bmp = new RenderTargetBitmap(pixelWidth , pixelHeight , _hdpi, _vdpi, PixelFormats.Pbgra32); bmp.Render(v); _bmp = bmp; } var zz = new TiffBitmapEncoder(); var bitmapFrame = BitmapFrame.Create(_bmp); zz.Frames.Add(bitmapFrame); using (var stream = new FileStream(@"c:\temp\new.tiff", FileMode.Create)) { zz.Save(stream); } PageCount = (int)(b.Drawing.Bounds.Height / DocPageSize.Height + 1) + (coverPage ? 1 : 0); Source = control as IDocumentPaginatorSource; }
public static DocumentPage CreateCoverPage(int hdpi, Thickness thickness, int vdpi, Size pageSize, ICodeView codeView, out Info1 info) { var dv1 = new DrawingVisual(); var dc0 = dv1.RenderOpen(); var text = new FormattedText(codeView.DocumentTitle ?? "Untitled", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new FontFamily("Times new Roman"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), 32, Brushes.Black, null, TextFormattingMode.Ideal, 1); ; dc0.DrawText(text, new Point((pageSize.Width - text.Width) / 2, 4 * vdpi)); var info1 = $"Margins:\t\tLeft: {thickness.Left / hdpi:N1};\t\tRight: {thickness.Right / hdpi:N1}; \r\n\t\tTop: {thickness.Top / vdpi:N1};\t\tBottom: {thickness.Bottom / vdpi:N1}\r\nPage Size:\t{pageSize.Width / hdpi:N1}\"x{pageSize.Height / vdpi:N1}\"\r\n"; var text1 = new FormattedText(info1, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), 16, Brushes.Black, null, TextFormattingMode.Ideal, 1); ; dc0.DrawText(text1, new Point((pageSize.Width - text1.Width) / 2, 5 * vdpi)); dc0.Close(); info = null; return(new DocumentPage(dv1, pageSize, new Rect(0, -1 * vdpi, pageSize.Width, pageSize.Height + vdpi), new Rect(0, 0, pageSize.Width, pageSize.Height))); }