Exemplo n.º 1
0
        public void EditGridDefinition()
        {
            if (!FociList.Any())
            {
                return;
            }
            Focus biggestY = FociList.Aggregate((i1, i2) => i1.Y > i2.Y ? i1 : i2);
            Focus biggestX = FociList.Aggregate((i1, i2) => i1.X > i2.X ? i1 : i2);

            RowCount    = biggestY.Y >= RowCount ? biggestY.Y + 1 : RowCount;
            ColumnCount = biggestX.X >= ColumnCount ? biggestX.X + 1 : ColumnCount;
        }
        public void EditGridDefinition()
        {
            if (!FociList.Any())
            {
                return;
            }
            FocusModel biggestY = FociList.Aggregate((i1, i2) => i1.DisplayY >
                                                     i2.DisplayY ? i1 : i2);
            FocusModel biggestX = FociList.Aggregate((i1, i2) => i1.DisplayX >
                                                     i2.DisplayX ? i1 : i2);

            RowCount    = biggestY.DisplayY >= RowCount ? biggestY.DisplayY + 1 : RowCount;
            ColumnCount = biggestX.DisplayX >= ColumnCount ? biggestX.DisplayX + 1 : ColumnCount;
        }
        private void NotificationMessageReceived(NotificationMessage msg)
        {
            //If this is not the intended target
            if (msg.Target != null && msg.Target != this)
            {
                return;
            }
            //If this is a dead tab waiting to be destroyed
            if (VisibleName == null)
            {
                return;
            }
            FocusModel Model = msg.Sender as FocusModel;

            switch (msg.Notification)
            {
            case "CloseEditFocus":
                switch (ModeType)
                {
                case RelationMode.Add:
                    ManageFocusViewModel viewModel = msg.Sender as ManageFocusViewModel;
                    if (viewModel != null)
                    {
                        addFocusToList(viewModel.Focus);
                    }
                    DrawOnCanvas();
                    break;

                case RelationMode.Edit:
                    EditGridDefinition();
                    DrawOnCanvas();
                    break;
                }
                ModeType = RelationMode.None;
                break;

            case "DeleteFocus":
                if (Model == null)
                {
                    return;
                }
                //Check if model is in the selected foci
                if (Model.IsSelected && SelectedFocuses.Contains(Model))
                {
                    //Delete everyone
                    foreach (FocusModel item in SelectedFocuses)
                    {
                        DeleteFocus(item);
                    }
                    break;
                }
                //Otherwise, kill the current focus
                DeleteFocus(Model);
                break;

            case "AddFocusMutually":
                ModeType = RelationMode.MutuallyExclusive;
                if (Model != null)
                {
                    ChosenFocusForLink = Model;
                    Model.IsWaiting    = true;
                }
                break;

            case "FinishAddFocusMutually":
                if (ChosenFocusForLink != null && ChosenFocusForLink != Model &&
                    FociList.Any(f => f == Model))
                {
                    UndoService.Current[GetUndoRoot()]
                    .BeginChangeSetBatch("AddMutuallyExclusive", false);
                    ModeType = RelationMode.None;
                    ChosenFocusForLink.IsWaiting = false;
                    MutuallyExclusiveSetModel tempo =
                        new MutuallyExclusiveSetModel(ChosenFocusForLink, Model);
                    ChosenFocusForLink.MutualyExclusive.Add(tempo);
                    Model?.MutualyExclusive.Add(tempo);
                    ChosenFocusForLink = null;
                    Messenger.Default.Send(new NotificationMessage(this,
                                                                   new ViewModelLocator().StatusBar, "Clear_message"));
                    UndoService.Current[GetUndoRoot()].EndChangeSetBatch();
                    RaisePropertyChanged(() => FociList);
                    DrawOnCanvas();
                }
                break;

            case "AddFocusPrerequisite":
                ModeType = RelationMode.Prerequisite;
                if (Model != null)
                {
                    ChosenFocusForLink = Model;
                    Model.IsWaiting    = true;
                }
                break;

            case "FinishAddFocusPrerequisite":
                if (ChosenFocusForLink != null && ChosenFocusForLink != Model &&
                    FociList.Any(f => f == Model))
                {
                    UndoService.Current[GetUndoRoot()]
                    .BeginChangeSetBatch("AddPrerequisite", false);
                    ModeType = RelationMode.None;
                    if (ModeParam == RelationModeParam.Required)
                    {
                        //Create new set
                        PrerequisitesSetModel set = new PrerequisitesSetModel(ChosenFocusForLink);
                        set.FociList.Add(Model);
                        ChosenFocusForLink.Prerequisite.Add(set);
                    }
                    else if (ModeParam == RelationModeParam.Optional)
                    {
                        //Create new set if no exist
                        if (!ChosenFocusForLink.Prerequisite.Any())
                        {
                            PrerequisitesSetModel set = new PrerequisitesSetModel(ChosenFocusForLink);
                            ChosenFocusForLink.Prerequisite.Add(set);
                        }
                        //Add Model to last Set
                        ChosenFocusForLink.Prerequisite.Last().FociList.Add(Model);
                    }
                    ChosenFocusForLink.IsWaiting = false;
                    ChosenFocusForLink           = null;
                    Messenger.Default.Send(new NotificationMessage(this,
                                                                   new ViewModelLocator().StatusBar, "Clear_message"));
                    UndoService.Current[GetUndoRoot()].EndChangeSetBatch();
                    RaisePropertyChanged(() => FociList);
                    DrawOnCanvas();
                }
                break;

            case "MakeRelativeTo":
                ModeType = RelationMode.RelativeTo;
                if (Model != null)
                {
                    ChosenFocusForLink = Model;
                    Model.IsWaiting    = true;
                }
                break;

            case "FinishMakeRelativeTo":
                if (ChosenFocusForLink != null && ChosenFocusForLink != Model &&
                    FociList.Any(f => f == Model))
                {
                    if (Model != null)
                    {
                        UndoService.Current[GetUndoRoot()]
                        .BeginChangeSetBatch("MakeRelativeTo", false);
                        ModeType = RelationMode.None;
                        ChosenFocusForLink.IsWaiting             = false;
                        ChosenFocusForLink.X                     = ChosenFocusForLink.DisplayX - Model.DisplayX;
                        ChosenFocusForLink.Y                     = ChosenFocusForLink.DisplayY - Model.DisplayY;
                        ChosenFocusForLink.CoordinatesRelativeTo = Model;
                        ChosenFocusForLink = null;
                        Messenger.Default.Send(new NotificationMessage(this,
                                                                       new ViewModelLocator().StatusBar, "Clear_message"));
                        UndoService.Current[GetUndoRoot()].EndChangeSetBatch();
                        RaisePropertyChanged(() => FociList);
                        DrawOnCanvas();
                    }
                }
                break;

            case "PositionChanged":
                if (Model != null)
                {
                    foreach (FocusModel focus in FociList.Where(f => f.CoordinatesRelativeTo == Model))
                    {
                        focus.RaisePropertyChanged(() => focus.DisplayX);
                        focus.RaisePropertyChanged(() => focus.DisplayY);
                    }
                    DrawOnCanvas();
                }
                UndoService.Current[GetUndoRoot()].EndChangeSetBatch();
                break;
            }
            if (msg.Target == this)
            {
                //Resend to the tutorial View model if this was the target
                Messenger.Default.Send(new NotificationMessage(msg.Sender,
                                                               new ViewModelLocator().Tutorial, msg.Notification));
            }
        }