public void ChangeOrdinal(int oldIndex, int newIndex)
        {
            var priorIndex  = oldIndex;
            var latterIndex = newIndex;

            var changedItem = Items[oldIndex];

            if (newIndex < oldIndex)
            {
                // add one to where we delete, because we're increasing the index by inserting
                priorIndex += 1;
            }
            else
            {
                // add one to where we insert, because we haven't deleted the original yet
                latterIndex += 1;
            }

            Items.Insert(latterIndex, changedItem);
            Items.RemoveAt(priorIndex);

            OrderChanged?.Invoke(this, EventArgs.Empty);

            OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, changedItem, newIndex, oldIndex));
        }
        public void ChangeOrdinal(int oldIndex, int newIndex)
        {
            //var priorIndex = oldIndex;
            //var latterIndex = newIndex;

            //var changedItem = Items[oldIndex];
            //if (newIndex < oldIndex)
            //{
            //    // add one to where we delete, because we're increasing the index by inserting
            //    priorIndex += 1;
            //}
            //else
            //{
            //    // add one to where we insert, because we haven't deleted the original yet
            //    latterIndex += 1;
            //}

            //Items.Insert(latterIndex, changedItem);
            //Items.RemoveAt(priorIndex);

            // using MoveItem is simpler and it automatically updates the UI, Call of OnCollectionChanged not neccessary
            if (oldIndex == newIndex)
            {
                return;
            }
            this.MoveItem(oldIndex, newIndex);

            OrderChanged?.Invoke(this, EventArgs.Empty);

            // this call is not needed if you use MoveItem (see above)
            //OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move, changedItem, newIndex, oldIndex));
        }
Example #3
0
 /// <summary>
 /// Raises event 'OrderChanged'
 /// </summary>
 protected virtual void OnOrderChanged()
 {
     if (OrderChanged != null)
     {
         OrderChanged.Invoke(this, System.EventArgs.Empty);
     }
 }
Example #4
0
        private void OnCountChanged(object sender, DecimalValueChangedEventArgs e)
        {
            DecimalValueChangedEventArgs args =
                new DecimalValueChangedEventArgs(e.Id, e.OldValue, e.NewValue, MenuItemName.Orders);

            CountChanged?.Invoke(this, args);
            OrderChanged?.Invoke(sender, e);
        }
Example #5
0
 private void EventsInit()
 {
     OrderDishez.CollectionChanged   += ((sender, e) => { Order.DishPackages = OrderDishez.ToList(); OrderChanged?.Invoke(); }); //OrderDishez_CollectionChanged;
     OrderDishez.ItemPropertyChanged += ((sender, e) => { OrderChanged?.Invoke(); });
     Order.PropertyChanged           += ((sender, e) =>
     {
         OrderChanged?.Invoke();
     });
 }
Example #6
0
        /// <summary>
        ///     Sortear aleatoriamente a ordem dos participantes.
        /// </summary>
        public void Sort()
        {
            var index = 0;

            _positions = _positions
                         .OrderBy(a => Guid.NewGuid())
                         .ToDictionary(a => a.Key, a => index++);
            this.MakeChildrenOrganized(control => _positions[control]);
            OrderChanged?.Invoke();
        }
Example #7
0
 void NotifyOrderChanged()
 {
     try
     {
         OrderChanged?.Invoke(this, new BfxChildOrderEventArgs(this));
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"Exception occuted in user handler. {ex.Message}");
     }
 }
        public override void ChangeOrder(int oldFlatIndex, int newFlatIndex)
        {
            if (newFlatIndex == 0)
            {
                return;
            }

            var moveDirection   = oldFlatIndex < newFlatIndex ? MoveDirection.Down : MoveDirection.Up;
            var priorFlatIndex  = oldFlatIndex;
            var latterFlatIndex = newFlatIndex;

            var oldGroup = GetGroupFromFlatIndex(priorFlatIndex, moveDirection);
            var newGroup = GetGroupFromFlatIndex(latterFlatIndex, moveDirection);

            var changedItem = GetItemFromFlatIndex(priorFlatIndex);

            if (moveDirection == MoveDirection.Up)
            {
                // add one to where we delete, because we're increasing the index by inserting
                if (oldGroup.Equals(newGroup))
                {
                    priorFlatIndex += 1;
                }
            }
            else
            {
                // add one to where we insert, because we haven't deleted the original yet
                latterFlatIndex += 1;
            }

            var priorNestedIndex  = GetNestedItemIndexFromFlatIndex(priorFlatIndex);
            var latterNestedIndex = GetNestedItemIndexFromFlatIndex(latterFlatIndex);


            newGroup.Insert(latterNestedIndex, changedItem);
            ((IList)oldGroup).RemoveAt(priorNestedIndex);

            //if (AutoOrdinals) {
            //	oldGroup.ResetOrdinals(OrdinalType.Nested);

            //	if (newGroup != oldGroup) {
            //		newGroup.ResetOrdinals(OrdinalType.Nested);
            //	}
            //}

            OrderChanged?.Invoke(
                this,
                new GroupedOrderableCollectionChangedEventArgs(changedItem,
                                                               oldGroup,
                                                               newGroup,
                                                               priorNestedIndex,
                                                               latterNestedIndex)
                );
        }
        public void ChangeOrdinal(int oldIndex, int newIndex)
        {
            if (oldIndex == newIndex)
            {
                return;
            }

            var priorIndex  = oldIndex;
            var latterIndex = newIndex;

            var changedItem = Items[oldIndex];

            if (newIndex < oldIndex)
            {
                // add one to where we delete, because we're increasing the index by inserting
                priorIndex += 1;
            }
            else
            {
                // add one to where we insert, because we haven't deleted the original yet
                latterIndex += 1;
            }

            Items.Insert(latterIndex, changedItem);
            Items.RemoveAt(priorIndex);

            OrderChanged?.Invoke(this, EventArgs.Empty);

            OnCollectionChanged(
                new NotifyCollectionChangedEventArgs(
                    NotifyCollectionChangedAction.Move,
                    changedItem,
                    newIndex,
                    oldIndex));

            if (Items is IEnumerable <Alarm> alarms)
            {
                if (alarms != null)
                {
                    int i = 0;
                    foreach (var alarm in alarms)
                    {
                        alarm.Index = i++;
                    }
                }

                App.AlarmService.SaveAlarmsAtLocal(alarms);
            }
        }
        private async Task ChangeOrderUpCommandExecutionAsync(object parameter)
        {
            var changeOrderUpCommand       = new ChangeActivityRecordOrder(ActivityRecord.Id, ActivityRecord.Order + 1);
            var changeOrderUpCommandResult = await _dispatcher.DispatchCommandAndGetResultAsync(changeOrderUpCommand);

            if (changeOrderUpCommandResult.Successful == false)
            {
                // TODO
                return;
            }

            ActivityRecord = ActivityRecord with {
                Order = ActivityRecord.Order + 1
            };
            RaisePropertyChanged(nameof(ActivityRecord));
            RaisePropertyChanged(nameof(Order));

            await OrderChanged?.Invoke();
        }
Example #11
0
        public void ChangeOrdinal(int oldIndex, int newIndex)
        {
            T changed = Items[oldIndex];

            if (newIndex < oldIndex)
            {
                // add one to where we delete because we're increasing
                // the index by inserting
                oldIndex += 1;
            }
            else
            {
                // add one to where we insert, because we haven't deleted
                // the original
                newIndex += 1;
            }

            Items.Insert(newIndex, changed);
            Items.RemoveAt(oldIndex);

            OrderChanged?.Invoke(this, EventArgs.Empty);
        }
Example #12
0
            protected override void OnDragDrop(DragEventArgs drgevent)
            {
                CustomButtonIB btn = (CustomButtonIB)drgevent.Data.GetData(typeof(CustomButtonIB));
                MyFlowPanel    dst = this;
                MyFlowPanel    src = btn?.Parent as MyFlowPanel;

                if (btn != null && src != null && dst != null && src == dst)
                {
                    drgevent.Effect = DragDropEffects.Move;

                    int oldindex = dst.Controls.GetChildIndex(btn);
                    OrderChanged?.Invoke(oldindex, dragInsertIndex);
                    dragInsertIndex = -1;
                }
                else
                {
                    drgevent.Effect = DragDropEffects.None;
                    dragInsertIndex = -1;
                }

                base.OnDragDrop(drgevent);
            }
Example #13
0
            protected override void OnDragDrop(DragEventArgs drgevent)
            {
                CustomButtonIB btn = (CustomButtonIB)drgevent.Data.GetData(typeof(CustomButtonIB));
                MyFlowPanel    dst = this;
                MyFlowPanel    src = btn?.Parent as MyFlowPanel;

                if (btn != null && src != null && dst != null && src == dst)
                {
                    drgevent.Effect = DragDropEffects.Move;

                    Point   p        = dst.PointToClient(new Point(drgevent.X, drgevent.Y));
                    Control item     = dst.GetChildAtPoint(p);
                    int     oldindex = dst.Controls.GetChildIndex(btn);
                    int     newindex = dst.Controls.GetChildIndex(item, false);

                    OrderChanged?.Invoke(oldindex, newindex);
                }
                else
                {
                    drgevent.Effect = DragDropEffects.None;
                }

                base.OnDragDrop(drgevent);
            }
Example #14
0
 protected void FireOrderChanged()
 {
     OrderChanged?.Invoke(this, EventArgs.Empty);
 }
 internal virtual void OnOrderChanged(OrderChangedEventArgs e)
 {
     OrderChanged?.Invoke(this, e);
 }
 public void ItemAdded(object changedItem)
 {
     OrderChanged?.Invoke(this, EventArgs.Empty);
     OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, changedItem));
 }
Example #17
0
        /// <summary>
        ///     Quando um controle no container é solto pelo mouse.
        /// </summary>
        /// <param name="sender">Origem do evento.</param>
        /// <param name="args">Informações do evento.</param>
        private void ControlOnMouseUp(object sender, MouseEventArgs args)
        {
            if (args.Button != MouseButtons.Left)
            {
                return;
            }

            // Controle sendo arrastado.
            var target = (Control)sender;

            // Control que contem todos os outros.
            var container = target.Parent;

            // Lista de todos os outros controles em ordem.
            var controls = container
                           .Controls
                           .OfType <Control>()
                           .Except(new[] { target })
                           .GroupBy(control => control.Top)
                           .OrderBy(line => line.Key)
                           .SelectMany(line => line
                                       .OrderBy(control => control.Left))
                           .ToList();

            // Lista dos controles em posição acima.
            var sameRegionControls = controls
                                     .Where(control => control.Bottom >= target.Top && control.Top <= target.Bottom)
                                     .ToList();

            // O Controle não caiu em cima de nenhum outro.
            if (sameRegionControls.Count == 0)
            {
                // Se a lista era vazia, adiciona nela.
                if (controls.Count == 0)
                {
                    controls.Add(target);
                }

                // Se caiu acima do topo é o primeiro.
                else if (controls[0].Top > target.Top)
                {
                    controls.Insert(0, target);
                }

                // Então caiu no final.
                else
                {
                    controls.Add(target);
                }
            }

            // O controle caiu em cima de alguns outros.
            else
            {
                var sameLineControls = sameRegionControls
                                       // Agrupa por linha.
                                       .GroupBy(control => control.Top + control.Height / 2)

                                       // Ordena as linhas pela mais próxima primeira.
                                       .OrderBy(group => Math.Abs(target.Top + target.Height / 2 - group.Key))

                                       // Seleciona a primeira linha que é a mais próxima do controle alvo.
                                       .First();

                var next = sameLineControls
                           // Seleciona o primeiro control depois do control alvo.
                           .FirstOrDefault(control => control.Left > target.Left);

                controls.Insert(
                    next != null

                    // Insere na lista no lugar do controle encontrado.
                        ? controls.IndexOf(next)

                    // Se não encontrar fica na última posição
                        : controls.IndexOf(sameLineControls.Last()) + 1,
                    target);
            }

            _positions.Clear();
            this.MakeChildrenOrganized(control => _positions[control] = controls.IndexOf(control));
            target.MakeHighlight();

            OrderChanged?.Invoke();
        }
        public void ChangeOrdinal(int oldIndex, int newIndex)
        {
            if (oldIndex < 0 || newIndex < 0)
            {
                return;
            }

            var priorIndex  = oldIndex;
            var latterIndex = newIndex;

            var changedItem = Items[oldIndex];

            if (newIndex < oldIndex)
            {
                // add one to where we delete, because we're increasing the index by inserting
                priorIndex += 1;
            }
            else
            {
                // add one to where we insert, because we haven't deleted the original yet
                latterIndex += 1;
            }

            Items.Insert(latterIndex, changedItem);
            Items.RemoveAt(priorIndex);

            OrderChanged?.Invoke(this, EventArgs.Empty);

            OnCollectionChanged(
                new NotifyCollectionChangedEventArgs(
                    NotifyCollectionChangedAction.Move,
                    changedItem,
                    newIndex,
                    oldIndex));

            if (Items is IEnumerable <Habit> habits)
            {
                if (habits != null)
                {
                    int i = 0;
                    foreach (var toDo in habits)
                    {
                        toDo.Index = i++;
                    }
                }

                App.HabitService.SaveHabits(habits);
            }

            if (Items is IEnumerable <RecommendedHabit> recommendedHabits)
            {
                if (recommendedHabits != null)
                {
                    int i = 0;
                    foreach (var reommendedHabit in recommendedHabits)
                    {
                        reommendedHabit.Index = i++;
                    }
                }

                foreach (var reommendedHabit in recommendedHabits)
                {
                    App.RecommendedHabitRepo.SaveRecommendedHabit(reommendedHabit);
                }
            }

            if (Items is IEnumerable <Routine> routines)
            {
                if (routines != null)
                {
                    int i = 0;
                    foreach (var routine in routines)
                    {
                        routine.Index = i++;
                    }
                }

                foreach (var routine in routines)
                {
                    App.RoutineService.SaveRoutineAtLocal(routine);
                }
                App.RoutineService.RefreshRoutines();

                App.MessagingCenter.SendChangeRoutineMessage();
            }
        }
Example #19
0
 private void RaiseOrderChanged(Order order)
 {
     OrderChanged?.Invoke(order);
     OrdersChanged?.Invoke(new[] { order });
 }
Example #20
0
 private void OnDeletedItem(object sender, EventArgs e)
 {
     SelectEntities();
     OrderChanged?.Invoke(sender, e);
 }
Example #21
0
 /// <summary>
 /// Fires the OnOrderChanged event.
 /// </summary>
 protected virtual void OnOrderChanged()
 {
     OrderChanged?.Invoke(this, EventArgs.Empty);
     OnListChanged();
 }
Example #22
0
 private void NotifyChanged() => OrderChanged?.Invoke();