using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.PPC.Jobs.Models;
namespace Tango.PPC.Jobs.UndoRedoCommands
{
public class RemoveSegmentsCommand : IUndoRedoCommand
{
private JobModel _jobModel;
private Dictionary<int, ISegmentModel> _removedSegmentsDict;
public RemoveSegmentsCommand(JobModel job )
{
_jobModel = job;
_removedSegmentsDict = _jobModel.GroupingSegments.Select((segm, ind) => new { Index = ind, Segment = segm }).Where(x => x.Segment.IsSelected).ToDictionary(i => i.Index, i => i.Segment); ;
}
public void Execute()
{
foreach (var obj pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Tango.Core.EventArguments;
namespace Tango.Touch.Controls
{
public class TouchNotificationBar : ContentControl
{
private const double HEIGHT_RATIO = 0.75;
private bool _isMouseDown;
private Point _mouseDownLocation;
private bool _isMoving;
private Point _downLocation;
private TouchDevice _touchDevice;
private double _last_manipulation_delta;
private DateTime _last_delta_measure_time;
private double _last_mouse_y;
private Border _border_notifications;
private Border _border_drag;
private Grid _grid_container;
private Grid _grid_mask;
private ItemsControl _items_control;
private Grid _notification_counter_grid;
static TouchNotificationBar()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchNotificationBar), new FrameworkPropertyMetadata(typeof(TouchNotificationBar)));
}
public String ItemExpandedPropertyPath
{
get { return (String)GetValue(ItemExpandedPropertyPathProperty); }
set { SetValue(ItemExpandedPropertyPathProperty, value); }
}
public static readonly DependencyProperty ItemExpandedPropertyPathProperty =
DependencyProperty.Register("ItemExpandedPropertyPath", typeof(String), typeof(TouchNotificationBar), new PropertyMetadata(null));
public bool HasNotifications
{
get { return (bool)GetValue(HasNotificationsProperty); }
set { SetValue(HasNotificationsProperty, value); }
}
public static readonly DependencyProperty HasNotificationsProperty =
DependencyProperty.Register("HasNotifications", typeof(bool), typeof(TouchNotificationBar), new PropertyMetadata(false, (d, e) => (d as TouchNotificationBar).OnHasNotificationsChanged()));
public IList Notifications
{
get { return (IList)GetValue(NotificationsProperty); }
set { SetValue(NotificationsProperty, value); }
}
public static readonly DependencyProperty NotificationsProperty =
DependencyProperty.Register("Notifications", typeof(IList), typeof(TouchNotificationBar), new PropertyMetadata(null));
public DataTemplate NotificationTemplate
{
get { return (DataTemplate)GetValue(NotificationTemplateProperty); }
set { SetValue(NotificationTemplateProperty, value); }
}
public static readonly DependencyProperty NotificationTemplateProperty =
DependencyProperty.Register("NotificationTemplate", typeof(DataTemplate), typeof(TouchNotificationBar), new PropertyMetadata(null));
public double CurrentMinHeight
{
get { return (double)GetValue(CurrentMinHeightProperty); }
set { SetValue(CurrentMinHeightProperty, value); }
}
public static readonly DependencyProperty CurrentMinHeightProperty =
DependencyProperty.Register("CurrentMinHeight", typeof(double), typeof(TouchNotificationBar), new PropertyMetadata(0.0));
public bool IsExpanded
{
get { return (bool)GetValue(IsExpandedProperty); }
set { SetValue(IsExpandedProperty, value); }
}
public static readonly DependencyProperty IsExpandedProperty =
DependencyProperty.Register("IsExpanded", typeof(bool), typeof(TouchNotificationBar), new PropertyMetadata(false));
public TouchNotificationBar()
{
Loaded += TouchNotificationBar_Loaded;
}
private void TouchNotificationBar_Loaded(object sender, RoutedEventArgs e)
{
_border_drag.MaxHeight = ActualHeight;
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_border_notifications = GetTemplateChild("PART_BorderNotifications") as Border;
_border_drag = GetTemplateChild("PART_BorderDrag") as Border;
_grid_container = GetTemplateChild("PART_Grid_Container") as Grid;
_grid_mask = GetTemplateChild("PART_GridMask") as Grid;
_items_control = GetTemplateChild("PART_ItemsControl") as ItemsControl;
_notification_counter_grid = GetTemplateChild("PART_NotificationCounterGrid") as Grid;
//border_notifications.IsManipulationEnabled = true;
_border_drag.RegisterForPreviewMouseOrTouchDown(GridNotificationMouseDown);
_border_drag.RegisterForMouseOrTouchMove(GridNotificationMouseMove);
_border_drag.RegisterForPreviewMouseOrTouchUp(GridNotificationMouseUp);
_border_drag.SizeChanged += Drag_Border_SizeChanged;
_items_control.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
}
private void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
{
if (_items_control.ItemContainerGenerator.Status == System.Windows.Controls.Primitives.GeneratorStatus.ContainersGenerated)
{
if (_items_control.Items.Count > 0)
{
var element = _items_control.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
if (element != null)
{
element.RegisterForLoadedOrNow((x, y) =>
{
CurrentMinHeight = element.ActualHeight;
ResizeNotification(element);
});
}
}
else
{
CurrentMinHeight = 0;
}
}
}
private FrameworkElement GetLastNotification()
{
return _items_control.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
}
private void Drag_Border_SizeChanged(object sender, SizeChangedEventArgs e)
{
_grid_mask.Opacity = _border_drag.ActualHeight / ActualHeight;
ResizeNotifications();
if (e.NewSize.Height > CurrentMinHeight)
{
_notification_counter_grid.Visibility = Visibility.Hidden;
}
else
{
_notification_counter_grid.Visibility = Visibility.Visible;
}
}
private void ResizeNotifications()
{
for (int i = 0; i < _items_control.Items.Count; i++)
{
FrameworkElement element = _items_control.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
ResizeNotification(element);
}
}
private void ResizeNotification(FrameworkElement element)
{
var control = element.FindChild<UserControl>();
if (control != null && !double.IsNaN(_border_drag.Height))
{
control.Height = ((_border_drag.Height - CurrentMinHeight) / ActualHeight) * (control.MaxHeight - control.MinHeight) + control.MinHeight;
}
}
private void OnHasNotificationsChanged()
{
DoubleAnimation ani = new DoubleAnimation();
ani.Duration = TimeSpan.FromSeconds(0.2);
_grid_container.EnsureHeight();
if (HasNotifications)
{
var last = GetLastNotification();
last.RegisterForLoadedOrNow((x, e) =>
{
ani.To = last.ActualHeight;
_grid_container.BeginAnimation(Grid.HeightProperty, ani);
_border_notifications.Height = last.ActualHeight;
});
}
else
{
CurrentMinHeight = 0;
ani.To = 0;
CloseNotifications();
_grid_container.BeginAnimation(Grid.HeightProperty, ani);
}
}
private void OpenNotifications()
{
_border_drag.EnsureHeight();
_border_notifications.EnsureHeight();
_border_drag.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), _border_drag.MaxHeight, null, null, 1);
_border_notifications.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), ActualHeight * HEIGHT_RATIO, null, null, 1);
if (ItemExpandedPropertyPath != null)
{
foreach (var item in Notifications)
{
item.SetPropertyValueByPath(ItemExpandedPropertyPath, true);
}
}
IsExpanded = true;
}
private void CloseNotifications()
{
_border_drag.EnsureHeight();
_border_notifications.EnsureHeight();
_border_notifications.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), CurrentMinHeight, null, 1, null, () =>
{
_border_notifications.BeginAnimation(Border.HeightProperty, null);
_border_notifications.Height = CurrentMinHeight;
for (int i = 0; i < _items_control.Items.Count; i++)
{
FrameworkElement element = _items_control.ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement;
var control = element.FindChild<UserControl>();
if (control != null)
{
control.Height = control.MinHeight;
}
}
});
_border_drag.StartDoubleAnimation(Border.HeightProperty, TimeSpan.FromSeconds(0.2), CurrentMinHeight, null, 1, null, () =>
{
_border_drag.BeginAnimation(Border.HeightProperty, null);
_border_drag.Height = double.NaN;
});
ThicknessAnimation tAni = new ThicknessAnimation();
tAni.Duration = TimeSpan.FromSeconds(0.3);
tAni.To = new Thickness(0);
_border_notifications.BeginAnimation(Border.BorderThicknessProperty, tAni);
if (ItemExpandedPropertyPath != null)
{
foreach (var item in Notifications)
{
item.SetPropertyValueByPath(ItemExpandedPropertyPath, false);
}
}
IsExpanded = false;
}
private void GridNotificationMouseUp(object sender, MouseOrTouchEventArgs e)
{
_isMouseDown = false;
if (_isMoving)
{
if (_touchDevice != null)
{
_border_drag.ReleaseTouchCapture(_touchDevice);
_touchDevice = null;
}
else
{
_border_drag.ReleaseMouseCapture();
}
e.Handled = true;
_isMoving = false;
if ((e.GetPosition(this).Y > ActualHeight / 2 && _last_manipulation_delta > 0) || _last_manipulation_delta > 20)
{
OpenNotifications();
}
else if ((e.GetPosition(this).Y < ActualHeight / 2 && _last_manipulation_delta < 0) || _last_manipulation_delta < 20)
{
CloseNotifications();
}
}
}
private void GridNotificationMouseMove(object sender, MouseOrTouchEventArgs e)
{
if (_isMouseDown)
{
if (Math.Abs(e.Location.Y - _downLocation.Y) > 5)
{
_isMoving = true;
}
if (_isMoving)
{
DateTime curTime = DateTime.Now;
if (curTime > _last_delta_measure_time.AddMilliseconds(10))
{
_last_delta_measure_time = curTime;
double delta = e.Location.Y - _last_mouse_y;
if (delta != 0)
{
_last_manipulation_delta = delta;
}
_last_mouse_y = e.Location.Y;
}
if (e.TouchDevice != null)
{
_border_drag.CaptureTouch(e.TouchDevice);
}
else
{
Mouse.Capture(_border_drag);
}
_border_drag.Height = Math.Max(e.Location.Y + _mouseDownLocation.Y, CurrentMinHeight);
_border_notifications.Height = Math.Min(_border_drag.Height * HEIGHT_RATIO, ActualHeight * HEIGHT_RATIO);
_border_drag.BeginAnimation(Border.HeightProperty, null);
_border_notifications.BeginAnimation(Border.HeightProperty, null);
_border_notifications.BeginAnimation(Border.BorderThicknessProperty, null);
if (_border_notifications.ActualHeight > CurrentMinHeight)
{
_border_notifications.BorderThickness = new Thickness(0, 0, 0, 20);
}
else
{
_border_notifications.BorderThickness = new Thickness(0);
}
}
}
}
private void GridNotificationMouseDown(object sender, MouseOrTouchEventArgs e)
{
_mouseDownLocation = new Point(e.Location.X, _border_drag.ActualHeight - e.Location.Y);
_downLocation = e.Location;
_last_mouse_y = _downLocation.Y;
_last_delta_measure_time = DateTime.Now;
_last_manipulation_delta = 0;
_isMouseDown = true;
}
}
}