Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the currently selected item
        /// </summary>
        private void DeleteSelectedItems()
        {
            Stack <CalendarItem> toDelete = new Stack <CalendarItem>();

            foreach (CalendarItem item in Items)
            {
                if (item.Selected)
                {
                    CalendarItemCancelEventArgs evt = new CalendarItemCancelEventArgs(item);

                    OnItemDeleting(evt);

                    if (!evt.Cancel)
                    {
                        toDelete.Push(item);
                    }
                }
            }

            if (toDelete.Count > 0)
            {
                while (toDelete.Count > 0)
                {
                    CalendarItem item = toDelete.Pop();

                    Items.Remove(item);

                    OnItemDeleted(new CalendarItemEventArgs(item));
                }

                Renderer.PerformItemsLayout();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Activates the edit mode on the specified item
        /// </summary>
        /// <param name="item"></param>
        public void ActivateEditMode(CalendarItem item)
        {
            CalendarItemCancelEventArgs evt = new CalendarItemCancelEventArgs(item);

            if (!_creatingItem)
            {
                OnItemEditing(evt);
            }

            if (evt.Cancel)
            {
                return;
            }

            _editModeItem      = item;
            TextBox            = new CalendarTextBox(this);
            TextBox.KeyDown   += new KeyEventHandler(TextBox_KeyDown);
            TextBox.LostFocus += new RoutedEventHandler(TextBox_LostFocus);
            Rect r = item.Bounds;

            r.Inflate(-2, -2);
            TextBox.Margin = new Thickness(r.Left, r.Top, r.Right, r.Bottom);
            // TextBox.BorderBrush = new Brush();
            TextBox.Text         = item.Text;
            TextBox.TextWrapping = TextWrapping.Wrap;

            AddLogicalChild(TextBox);
            TextBox.Visibility = Visibility.Visible;
            TextBox.Focus();
            TextBox.SelectionStart = TextBox.Text.Length;

            SetState(CalendarState.EditingItemText);
        }
Ejemplo n.º 3
0
 protected virtual void OnItemEdited(CalendarItemCancelEventArgs e)
 {
     if (ItemTextEdited != null)
     {
         ItemTextEdited(this, e);
     }
 }
Ejemplo n.º 4
0
 protected virtual void OnItemDeleting(CalendarItemCancelEventArgs e)
 {
     if (ItemDeleting != null)
     {
         ItemDeleting(this, e);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Finalizes editing the <see cref="EditModeItem"/>.
        /// </summary>
        /// <param name="cancel">Value indicating if edition of item should be canceled.</param>
        public void FinalizeEditMode(bool cancel)
        {
            if (!EditMode || EditModeItem == null || _finalizingEdition)
            {
                return;
            }

            _finalizingEdition = true;

            string       cancelText = _editModeItem.Text;
            CalendarItem itemBuffer = _editModeItem;

            _editModeItem = null;
            CalendarItemCancelEventArgs evt = new CalendarItemCancelEventArgs(itemBuffer);

            if (!cancel)
            {
                itemBuffer.Text = TextBox.Text.Trim();
            }

            if (TextBox != null)
            {
                TextBox.Visibility = Visibility.Collapsed;
                RemoveLogicalChild(TextBox);
                TextBox.Dispose();
            }

            if (_editModeItem != null)
            {
                Invalidate(itemBuffer);
            }

            _textBox = null;

            if (_creatingItem)
            {
                OnItemCreated(evt);
            }
            else
            {
                OnItemEdited(evt);
            }

            if (evt.Cancel)
            {
                itemBuffer.Text = cancelText;
            }


            _creatingItem      = false;
            _finalizingEdition = false;

            if (State == CalendarState.EditingItemText)
            {
                SetState(CalendarState.Idle);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new item on the current selection.
        /// If there's no selection, this will be ignored.
        /// </summary>
        /// <param name="itemText">Text of the item</param>
        /// <param name="editMode">If <c>true</c> activates the edit mode so user can edit the text of the item.</param>
        public void CreateItemOnSelection(string itemText, bool editMode)
        {
            if (SelectedElementEnd == null || SelectedElementStart == null)
            {
                return;
            }

            CalendarTimeScaleUnit unitEnd = SelectedElementEnd as CalendarTimeScaleUnit;
            CalendarDayTop        dayTop  = SelectedElementEnd as CalendarDayTop;
            CalendarDay           day     = SelectedElementEnd as CalendarDay;
            TimeSpan     duration         = unitEnd != null ? unitEnd.Duration : new TimeSpan(23, 59, 59);
            CalendarItem item             = new CalendarItem(this);

            DateTime dstart = SelectedElementStart.Date;
            DateTime dend   = SelectedElementEnd.Date;

            if (dend.CompareTo(dstart) < 0)
            {
                DateTime dtmp = dend;
                dend   = dstart;
                dstart = dtmp;
            }

            item.StartDate = dstart;
            item.EndDate   = dend.Add(duration);
            item.Text      = itemText;

            CalendarItemCancelEventArgs evtA = new CalendarItemCancelEventArgs(item);

            OnItemCreating(evtA);

            if (!evtA.Cancel)
            {
                Items.Add(item);

                if (editMode)
                {
                    _creatingItem = true;
                    ActivateEditMode(item);
                }
            }
        }