<commit_before>﻿using System;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Practices.Composite.Presentation.Commands;
using SandRibbon.Components.Utility;
using SandRibbon.Providers;
using SandRibbon.Utils.Connection;
using System.Collections.Generic;
using SandRibbonInterop;
using SandRibbon.Components.Canvas;

namespace SandRibbon.Components
{
    public partial class Projector : UserControl
    {
        public static WidthCorrector WidthCorrector = new WidthCorrector();
        public static HeightCorrector HeightCorrector = new HeightCorrector();
        public ScrollViewer viewConstraint
        {
            set 
            {
                DataContext = value;
                value.ScrollChanged += new ScrollChangedEventHandler(value_ScrollChanged);
            }
        }
        private static Window windowProperty;
        public static Window Window
        {
            get { return windowProperty; }
            set 
            {
                windowProperty = value;
                value.Closed += (_sender, _args) =>
                {
                    windowProperty = null;
                    Commands.RequerySuggested(Commands.MirrorPresentationSpace);
                };
            }
        }
        private void value_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            scroll.ScrollToHorizontalOffset(e.HorizontalOffset);
            scroll.ScrollToVerticalOffset(e.VerticalOffset);
        }
        private Rect getContentBounds()
        {
            return new List<AbstractCanvas> { stack.images, stack.text, stack.handwriting }
                .Aggregate(new Rect(), (acc, item) =>
                    {
                        acc.Union(VisualTreeHelper.GetDescendantBounds(item));
                        return acc;
                    });
        }
        public Projector()
        {
            InitializeComponent();
            instance = this;
            Loaded += Projector_Loaded;
            stack.SetEditable(false);
            this.MouseLeave += Projector_MouseLeave;
            Commands.SetDrawingAttributes.RegisterCommand(new DelegateCommand<DrawingAttributes>(SetDrawingAttributes));
            Commands.PreParserAvailable.RegisterCommand(new DelegateCommand<PreParser>(PreParserAvailable));
            Commands.SetPrivacy.RegisterCommand(new DelegateCommand<string>(SetPrivacy));
            Commands.SetInkCanvasMode.RegisterCommand(new DelegateCommand<string>(SetInkCanvasMode));
            Commands.SetLayer.RegisterCommand(new DelegateCommand<object>(setLayer));
            Commands.MoveTo.RegisterCommand(new DelegateCommand<object>(moveTo));
            stack.handwriting.EditingModeChanged += modeChanged;
            stack.images.EditingModeChanged += modeChanged;
            stack.text.EditingModeChanged += modeChanged;
        }

        private void moveTo(object obj)
        {
            stack.Flush();
            startProjector(null);
        }


        private void Projector_MouseLeave(object sender, MouseEventArgs e)
        {
            PenUp();
        }
        void modeChanged(object sender, RoutedEventArgs e)
        {
            var canvas = (InkCanvas)sender;
            if (canvas.EditingMode != InkCanvasEditingMode.None)
                canvas.EditingMode = InkCanvasEditingMode.None;
        }
        private void Projector_Loaded(object sender, RoutedEventArgs e)
        {
            startProjector(null);
            //setProjectionLayers();
        }
        private void setLayer(object obj)
        {
        }
        private void startProjector(object obj)
        {
            setProjectionLayers();
            try
            {
                HistoryProviderFactory.provider.Retrieve<PreParser>(
                    JabberWire.dontDoAnything,
                    JabberWire.dontDoAnything,
                    PreParserAvailable,
                    Globals.slide.ToString());
            }
            catch (Exception)
            {
            }
            stack.handwriting.me = "projector";
            stack.images.me = "projector";
            stack.text.me = "projector";
        }
        private void setProjectionLayers()
        {
            Dispatcher.adoptAsync(delegate
                                                     {
                                                         var projectorImages = stack.images;
                                                         var projectorText = stack.text;
                                                         var projectorHandwriting = stack.handwriting;
                                                         stack.canvasStack.Children.Clear();<commit_msg>projector layers fixed<commit_after>﻿using System;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.Practices.Composite.Presentation.Commands;
using SandRibbon.Components.Utility;
using SandRibbon.Providers;
using SandRibbon.Utils.Connection;
using System.Collections.Generic;
using SandRibbonInterop;
using SandRibbon.Components.Canvas;

namespace SandRibbon.Components
{
    public partial class Projector : UserControl
    {
        public static WidthCorrector WidthCorrector = new WidthCorrector();
        public static HeightCorrector HeightCorrector = new HeightCorrector();
        public ScrollViewer viewConstraint
        {
            set 
            {
                DataContext = value;
                value.ScrollChanged += new ScrollChangedEventHandler(value_ScrollChanged);
            }
        }
        private static Window windowProperty;
        public static Window Window
        {
            get { return windowProperty; }
            set 
            {
                windowProperty = value;
                value.Closed += (_sender, _args) =>
                {
                    windowProperty = null;
                    Commands.RequerySuggested(Commands.MirrorPresentationSpace);
                };
            }
        }
        private void value_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            scroll.ScrollToHorizontalOffset(e.HorizontalOffset);
            scroll.ScrollToVerticalOffset(e.VerticalOffset);
        }
        private Rect getContentBounds()
        {
            return new List<AbstractCanvas> { stack.images, stack.text, stack.handwriting }
                .Aggregate(new Rect(), (acc, item) =>
                    {
                        acc.Union(VisualTreeHelper.GetDescendantBounds(item));
                        return acc;
                    });
        }
        public Projector()
        {
            InitializeComponent();
            instance = this;
            Loaded += Projector_Loaded;
            stack.SetEditable(false);
            this.MouseLeave += Projector_MouseLeave;
            Commands.SetDrawingAttributes.RegisterCommand(new DelegateCommand<DrawingAttributes>(SetDrawingAttributes));
            Commands.PreParserAvailable.RegisterCommand(new DelegateCommand<PreParser>(PreParserAvailable));
            Commands.SetPrivacy.RegisterCommand(new DelegateCommand<string>(SetPrivacy));
            Commands.SetInkCanvasMode.RegisterCommand(new DelegateCommand<string>(SetInkCanvasMode));
            Commands.SetLayer.RegisterCommand(new DelegateCommand<object>(setLayer));
            Commands.MoveTo.RegisterCommand(new DelegateCommand<object>(moveTo));
            stack.handwriting.EditingModeChanged += modeChanged;
            stack.images.EditingModeChanged += modeChanged;
            stack.text.EditingModeChanged += modeChanged;
        }

        private void moveTo(object obj)
        {
            stack.Flush();
            startProjector(null);
        }


        private void Projector_MouseLeave(object sender, MouseEventArgs e)
        {
            PenUp();
        }
        void modeChanged(object sender, RoutedEventArgs e)
        {
            var canvas = (InkCanvas)sender;
            if (canvas.EditingMode != InkCanvasEditingMode.None)
                canvas.EditingMode = InkCanvasEditingMode.None;
        }
        private void Projector_Loaded(object sender, RoutedEventArgs e)
        {
            startProjector(null);
            //setProjectionLayers();
        }
        private void setLayer(object obj)
        {
            foreach (var layer in stack.stack.Children)
            {
                ((UIElement)layer).Opacity = 1;
            } 
        }
        private void startProjector(object obj)
        {
            setProjectionLayers();
            try
            {
                HistoryProviderFactory.provider.Retrieve<PreParser>(
                    JabberWire.dontDoAnything,
                    JabberWire.dontDoAnything,
                    PreParserAvailable,
                    Globals.slide.ToString());
            }
            catch (Exception)
            {
            }
            stack.handwriting.me = "projector";
            stack.images.me = "projector";
            stack.text.me = "projector";
        }
        private void setProjectionLayers()
        {
            Dispatcher.adoptAsync(delegate
                                                     {
                                                         var projectorImages = stack.images;
                                                         var projectorText = stack.text;
                                                         var projectorHandwriting = stack.handwriting;
                                                         stack.canvasStack.Children.Clear();
{'fraction_non_alphanumeric': 0.07422033211826651, 'fraction_numerical': 0.0001012555690562981, 'mean_word_length': 1.6759685722026552, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3102043', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2243, 'n_words': 414}