Beispiel #1
0
        // deletes the UI component that corresponds to a rule
        private void DeleteRuleUserControl(object sender, EventArgs e)
        {
            BeepRuleUserControl bruc = sender as BeepRuleUserControl;

            beepRules.Remove(bruc.Rule);
            BeepRulesUIComponents.Remove(bruc);
        }
Beispiel #2
0
 // starts a drag drop sequence
 private void RuleUserControlDragPreviewMouseDown(object sender, MouseEventArgs e)
 {
     if (sender is BeepRuleUserControl && e.LeftButton == MouseButtonState.Pressed)
     {
         BeepRuleUserControl draggedItem = sender as BeepRuleUserControl;
         DragDrop.DoDragDrop(draggedItem, new DataObject("drag", draggedItem.DataContext), DragDropEffects.Move);
     }
 }
Beispiel #3
0
        // creates BeepRuleUserControl, a UI component
        private BeepRuleUserControl CreateBeepRuleUserControl(BeepRule rule)
        {
            BeepRuleUserControl bruc = BeepRuleUserControl.Create(rule);

            bruc.SelectedRule += RuleUserControlRuleSelection;
            bruc.Deleting     += DeleteRuleUserControl;
            bruc.Dragging     += RuleUserControlDragPreviewMouseDown;
            bruc.PrepareColorPickers(StandardColorItems);
            bruc.UpdateColorPickers(clrPickMouse.AvailableColors);
            return(bruc);
        }
Beispiel #4
0
        //select different rules in UI
        private void RuleUserControlRuleSelection(object sender, EventArgs e)
        {
            BeepRuleUserControl bruc = sender as BeepRuleUserControl;

            // selected rule must be different
            if (bruc.SelectedRuleName == bruc.RuleName)
            {
                return;
            }

            beepRules.Remove(bruc.Rule);

            int index = BeepRulesUIComponents.IndexOf(bruc);

            BeepRulesUIComponents.Remove(bruc);

            BeepRule br = BeepRule.Create(bruc.SelectedRuleName, bw.tiles);

            beepRules.Add(br);

            BeepRulesUIComponents.Insert(index, CreateBeepRuleUserControl(br));
        }
Beispiel #5
0
        // swaps position of user controls after drag drop
        private void RuleUserControlDragDropped(object sender, DragEventArgs e)
        {
            BeepRuleUserControl draggedBruc = e.Data.GetData("drag") as BeepRuleUserControl;
            BeepRuleUserControl targetBruc  = ((ListBoxItem)(sender)).DataContext as BeepRuleUserControl;

            int removedIdx = lbRules.Items.IndexOf(draggedBruc);
            int targetIdx  = lbRules.Items.IndexOf(targetBruc);

            if (removedIdx < targetIdx)
            {
                BeepRulesUIComponents.Insert(targetIdx + 1, draggedBruc);
                BeepRulesUIComponents.RemoveAt(removedIdx);
            }
            else
            {
                int remIdx = removedIdx + 1;
                if (BeepRulesUIComponents.Count + 1 > remIdx)
                {
                    BeepRulesUIComponents.Insert(targetIdx, draggedBruc);
                    BeepRulesUIComponents.RemoveAt(remIdx);
                }
            }
        }