<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlideView.Library.Primitives;
#if WINDOWS_PHONE
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Input;
#elif NETFX_CORE
using Windows.Foundation;
using Windows.UI.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Input;
#endif


namespace SlideView.Library
{
    [TemplatePart(Name = SlidingTransformName, Type = typeof(TranslateTransform))]
    [TemplatePart(Name = ItemsListName, Type = typeof(ItemsPresenter))]
    public class SlideView : ItemsControl
    {
        private const string SlidingTransformName = "SlidingTransform";
        private const string ItemsListName = "ItemsList";
#if WINDOWS_PHONE
        private const double FlickVelocity = 1000.0;
#elif NETFX_CORE
        private const double FlickVelocity = 1.0;
#endif

        #region SelectedIndex (DependencyProperty)

        /// <summary>
        /// Index for the selected children
        /// </summary>
        public int SelectedIndex
        {
            get { return (int)GetValue(SelectedIndexProperty); }
            set { SetValue(SelectedIndexProperty, value); }
        }
        public static readonly DependencyProperty SelectedIndexProperty =
            DependencyProperty.Register("SelectedIndex", typeof(int), typeof(SlideView),
            new PropertyMetadata(0, new PropertyChangedCallback(OnSelectedIndexChanged)));

        private static void OnSelectedIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((SlideView)d).OnSelectedIndexChanged(e);
        }

        protected virtual void OnSelectedIndexChanged(DependencyPropertyChangedEventArgs e)
        {
            GoToPanel(SelectedIndex);
        }

        #endregion

        #region IsSlideEnabled (DependencyProperty)

        /// <summary>
        /// If true, enables the slide interaction between panels, otherwise disables it
        /// </summary>
        public bool IsSlideEnabled
        {
            get { return (bool)GetValue(IsSlideEnabledProperty); }
            set { SetValue(IsSlideEnabledProperty, value); }
        }
        public static readonly DependencyProperty IsSlideEnabledProperty =
            DependencyProperty.Register("IsSlideEnabled", typeof(bool), typeof(SlideView),
              new PropertyMetadata(true));

        #endregion

        internal SlideViewPanel Panel { get; set; }

        public event EventHandler SelectionChanged;

        internal double ViewportWidth { get; private set; }
        internal double ViewportHeight { get; private set; }

        private ItemsPresenter _itemsList;
        private TranslateTransform _translate;
        private bool _suppressAnimations;

        private Storyboard _sidePanelStoryboard;
        private DoubleAnimation _sidePanelAnimation;

        public SlideView()
        {
            DefaultStyleKey = typeof(SlideView);

            _suppressAnimations = true;

#if NETFX_CORE
            this.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateRailsX | ManipulationModes.TranslateInertia;
            this.ManipulationStarted += SlideView_ManipulationStarted;
#endif

            this.ManipulationCompleted += SlideView_ManipulationCompleted;
            this.ManipulationDelta += SlideView_ManipulationDelta;
        }

#if WINDOWS_PHONE
        public
#elif NETFX_CORE
        protected
#endif
 override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _suppressAnimations = false;

            _itemsList = GetTemplateChild(ItemsListName) as ItemsPresenter;
#if WINDOWS_PHONE
            _itemsList.CacheMode = new BitmapCache();
#endif
            _translate = GetTemplateChild(SlidingTransformName) as TranslateTransform;
        }

        protected override Size MeasureOverride(Size availableSize)
        {
#if WINDOWS_PHONE
            var appSize = new Size(Application.Current.Host.Content.ActualWidth, Application.Current.Host.Content.ActualHeight);
#elif NETFX_CORE
            var appSize = new Size(Window.Current.Bounds.Width, Window.Current.Bounds.Height);
#endif

            if (appSize.Width > 0)
            {
                ViewportWidth = !double.IsInfinity(availableSize.Width) ? availableSize.Width : appSize.Width;
                ViewportHeight = !double.IsInfinity(availableSize.Height) ? availableSize.Height : appSize.Height;
            }
            else
            {
                ViewportWidth = Math.Min(availableSize.Width, 480);
                ViewportHeight = Math.Min(availableSize.Height, 800);
            }

            base.MeasureOverride(new Size(double.PositiveInfinity, ViewportHeight));

            return new Size(ViewportWidth, ViewportHeight);
        }

        protected override Size ArrangeOverride(Size finalSize)
        {
            finalSize.Width = DesiredSize.Width;
            base.ArrangeOverride(finalSize);

            if (SelectedIndex > 0)
                _translate.X = Panel.GetOffset(SelectedIndex);

            return finalSize;
        }

#if NETFX_CORE
        private void SlideView_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs manipulationStartedEventArgs)
        {
//            if (_itemsList.CacheMode == null)
//                _itemsList.CacheMode = new BitmapCache();
        }
#endif

#if WINDOWS_PHONE
        void SlideView_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
#elif NETFX_CORE
        void SlideView_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
#endif
        {
            if (!IsSlideEnabled)
            {
                e.Complete();
                return;<commit_msg>Fix lagginess of slide view<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlideView.Library.Primitives;
#if WINDOWS_PHONE
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Input;
#elif NETFX_CORE
using Windows.Foundation;
using Windows.UI.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Animation;
using Windows.UI.Xaml.Input;
#endif


namespace SlideView.Library
{
    [TemplatePart(Name = SlidingTransformName, Type = typeof(TranslateTransform))]
    [TemplatePart(Name = ItemsListName, Type = typeof(ItemsPresenter))]
    public class SlideView : ItemsControl
    {
        private const string SlidingTransformName = "SlidingTransform";
        private const string ItemsListName = "ItemsList";
#if WINDOWS_PHONE
        private const double FlickVelocity = 1000.0;
#elif NETFX_CORE
        private const double FlickVelocity = 1.0;
#endif

        #region SelectedIndex (DependencyProperty)

        /// <summary>
        /// Index for the selected children
        /// </summary>
        public int SelectedIndex
        {
            get { return (int)GetValue(SelectedIndexProperty); }
            set { SetValue(SelectedIndexProperty, value); }
        }
        public static readonly DependencyProperty SelectedIndexProperty =
            DependencyProperty.Register("SelectedIndex", typeof(int), typeof(SlideView),
            new PropertyMetadata(0, new PropertyChangedCallback(OnSelectedIndexChanged)));

        private static void OnSelectedIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((SlideView)d).OnSelectedIndexChanged(e);
        }

        protected virtual void OnSelectedIndexChanged(DependencyPropertyChangedEventArgs e)
        {
            GoToPanel(SelectedIndex);
        }

        #endregion

        #region IsSlideEnabled (DependencyProperty)

        /// <summary>
        /// If true, enables the slide interaction between panels, otherwise disables it
        /// </summary>
        public bool IsSlideEnabled
        {
            get { return (bool)GetValue(IsSlideEnabledProperty); }
            set { SetValue(IsSlideEnabledProperty, value); }
        }
        public static readonly DependencyProperty IsSlideEnabledProperty =
            DependencyProperty.Register("IsSlideEnabled", typeof(bool), typeof(SlideView),
              new PropertyMetadata(true));

        #endregion

        internal SlideViewPanel Panel { get; set; }

        public event EventHandler SelectionChanged;

        internal double ViewportWidth { get; private set; }
        internal double ViewportHeight { get; private set; }

        private ItemsPresenter _itemsList;
        private TranslateTransform _translate;
        private bool _suppressAnimations;

        private Storyboard _sidePanelStoryboard;
        private DoubleAnimation _sidePanelAnimation;

        public SlideView()
        {
            DefaultStyleKey = typeof(SlideView);

            _suppressAnimations = true;

#if NETFX_CORE
            this.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateRailsX | ManipulationModes.TranslateInertia;
            this.ManipulationStarted += SlideView_ManipulationStarted;
#endif

            this.ManipulationCompleted += SlideView_ManipulationCompleted;
            this.ManipulationDelta += SlideView_ManipulationDelta;
        }

#if WINDOWS_PHONE
        public
#elif NETFX_CORE
        protected
#endif
 override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _suppressAnimations = false;

            _itemsList = GetTemplateChild(ItemsListName) as ItemsPresenter;
#if WINDOWS_PHONE
            _itemsList.CacheMode = new BitmapCache();
#endif
            _translate = GetTemplateChild(SlidingTransformName) as TranslateTransform;
        }

        protected override Size MeasureOverride(Size availableSize)
        {
#if WINDOWS_PHONE
            var appSize = new Size(Application.Current.Host.Content.ActualWidth, Application.Current.Host.Content.ActualHeight);
#elif NETFX_CORE
            var appSize = new Size(Window.Current.Bounds.Width, Window.Current.Bounds.Height);
#endif

            if (appSize.Width > 0)
            {
                ViewportWidth = !double.IsInfinity(availableSize.Width) ? availableSize.Width : appSize.Width;
                ViewportHeight = !double.IsInfinity(availableSize.Height) ? availableSize.Height : appSize.Height;
            }
            else
            {
                ViewportWidth = Math.Min(availableSize.Width, 480);
                ViewportHeight = Math.Min(availableSize.Height, 800);
            }

            base.MeasureOverride(new Size(double.PositiveInfinity, ViewportHeight));

            return new Size(ViewportWidth, ViewportHeight);
        }

        protected override Size ArrangeOverride(Size finalSize)
        {
            finalSize.Width = DesiredSize.Width;
            base.ArrangeOverride(finalSize);

            if (SelectedIndex > 0)
                _translate.X = Panel.GetOffset(SelectedIndex);

            return finalSize;
        }

#if NETFX_CORE
        private void SlideView_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs manipulationStartedEventArgs)
        {
            if (_itemsList.CacheMode == null)
                _itemsList.CacheMode = new BitmapCache();
        }
#endif

#if WINDOWS_PHONE
        void SlideView_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
#elif NETFX_CORE
        void SlideView_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
#endif
        {
            if (!IsSlideEnabled)
            {
                e.Complete();
                return;
{'fraction_non_alphanumeric': 0.07529610829103214, 'fraction_numerical': 0.0027072758037225042, 'mean_word_length': 2.665426356589147, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3622671', 'n_tokens_mistral': 3147, 'n_tokens_neox': 3009, 'n_words': 675}