示例#1
0
        private IModelView RemoveVariantNode(string viewId)
        {
            ViewShortcut   viewShortcut  = View.CreateShortcut();
            IModelView     modelView     = Application.Model.Views[viewShortcut.ViewId];
            IModelVariants modelVariants = ((IModelViewVariants)modelView).Variants;
            IModelVariant  modelVariant  = modelVariants.Where(variant => variant.View.Id == viewId).Single();

            modelVariant.Remove();
            if (modelVariants.Count > 0)
            {
                modelVariants.Current = modelVariants[0];
                return(modelVariants.Current.View);
            }
            return(Application.Model.Views[viewShortcut.ViewId]);
        }
示例#2
0
        void ActivateVariant(IModelVariant newVariantNode)
        {
            var changeVariantController            = Frame.GetController <ChangeVariantController>();
            SingleChoiceAction changeVariantAction = changeVariantController.ChangeVariantAction;

            if (changeVariantController.Active.ResultValue)
            {
                var choiceActionItem = new ChoiceActionItem(newVariantNode.Caption, newVariantNode.View);
                changeVariantAction.Items.Add(choiceActionItem);
                changeVariantAction.SelectedItem = choiceActionItem;
            }
            else
            {
                changeVariantController.Frame.SetView(View);
                changeVariantAction.SelectedItem = (changeVariantAction.Items.Where(
                                                        item => item.Caption == newVariantNode.Caption)).Single();
            }
        }
        protected virtual void NewViewVariant(ViewVariantParameterObject parameter)
        {
            View.SaveModel();                                                                                                           //It is necessary to save the current View settings into the application model before copying them.
            string        newViewVariantId    = String.Format("{0}_{1}", GetRootViewId(), Guid.NewGuid());                              //Identifier of a new view variant will be based on the identifier of the root view variant.
            IModelVariant newModelViewVariant = ((ModelNode)rootModelViewVariants).AddNode <IModelVariant>(newViewVariantId);           // Adds a new child node of the IModelVariant type with a specific identifier to the parent IModelViewVariants node.

            newModelViewVariant.View    = ((ModelNode)modelViews).AddClonedNode((ModelNode)View.Model, newViewVariantId) as IModelView; // Creates a new node of the IModelView type by cloning the settings of the current View and then sets the clone to the View property of the view variant created above. Beware of the specificity described at Q411979.
            newModelViewVariant.Caption = parameter.Caption;                                                                            //Sets the Caption property of the view variant created above to the caption specified by an end-user in the dialog.
            if (rootModelViewVariants.Count == 1)                                                                                       //It is necessary to add a default view variant node for the current View for correct operation of the Change Variant Action.
            {
                IModelVariant currentModelViewVariant = ((ModelNode)rootModelViewVariants).AddNode <IModelVariant>(View.Id);
                currentModelViewVariant.Caption = CaptionHelper.GetLocalizedText("Texts", "DefaultViewVariantCaption");
                currentModelViewVariant.View    = View.Model;
            }
            if (changeVariantController != null)
            {
                changeVariantController.CurrentFrameViewVariantsManager.RefreshVariants(); //Updates the Change Variant Action structure based on the model customizations above.
            }
            UpdateCurrentViewVariant(newViewVariantId);                                    //Sets the current view variant to the newly created one.
            UpdateUserViewVariantsAction();                                                //Updates the items of our User View Variant Action based on the current the Change Variant Action structure.
        }