private void NotifyPanelShortcutsChanged(IStaticPanelDefinition definition)
 {
     if (!LoadingScope.IsInScope)
     {
         EventAggregator.GetEvent <ShortcutChangedEvent>().Publish(new BringPanelIntoViewShortcutChangedArgs(definition));
     }
 }
示例#2
0
        private void BringStaticPanelIntoViewInternal(IStaticPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));
            LayoutAnchorable anchorable = null;

            try
            {
                anchorable = anchorableDefinitions.GetKeysForValue(definition).Single();
            }
            catch (InvalidOperationException)
            {
                throw new Exception($"Error : Cannot find a unique registered anchorable associated with the static panel definition " +
                                    $"{definition.IView},{definition.View}, {definition.IViewModel}, {definition.ViewModel}");
            }

            if (anchorable.IsHidden && definition.CanChangeVisibility(false))
            {
                VisibilityManager.SetVisibility(anchorable, true);
            }
            else
            {
                var group = anchorable.Parent.SafeCast <LayoutAnchorablePane>();
                group.SelectedContentIndex = group.Children.IndexOf(anchorable);
            }
        }
示例#3
0
        private void InvalidateStaticPanel(IStaticPanelDefinition definition)
        {
            if (!IsUILoaded)
            {
                return;
            }

            var anchorable = anchorableDefinitions.GetKeysForValue(definition).Single();
            var config     = definition.OfType <StaticPanelConfiguration>().Single();

            var canOpen  = config.CanOpen();
            var canClose = config.CanClose();

            if (canOpen == false && canClose == false)
            {
                throw new Exception($"Error invaidating static panel {definition.ViewModel}. CanOpen() and CanClose() defined " +
                                    $"in the panel definition's configuration metadata can't both return false at the same time.");
            }

            if (!canOpen && !anchorable.IsHidden)
            {
                VisibilityManager.SetVisibility(anchorable, false);
            }
            else if (!canClose && anchorable.IsHidden)
            {
                VisibilityManager.SetVisibility(anchorable, true);
            }

            anchorable.Title = config.Title();

            EventAggregator.GetEvent <StaticPanelInvalidationEvent>().Publish(new StaticPanelInvalidationArgs(definition));
        }
示例#4
0
        internal static bool CanChangeVisibility(this IStaticPanelDefinition definition, bool currentVisibility)
        {
            definition.AssertNotNull(nameof(definition));

            var panelConfig = definition.OfType <StaticPanelConfiguration>().Single();

            return(currentVisibility ? panelConfig.CanClose() : panelConfig.CanOpen());
        }
示例#5
0
        public bool Matches(IStaticPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));

            return(ViewGuid == definition.View.GetGuid() &&
                   IViewGuid == definition.IView.GetGuid() &&
                   ViewModelGuid == definition.ViewModel.GetGuid() &&
                   IViewModelGuid == definition.IViewModel.GetGuid());
        }
        public bool HasShortcut(IStaticPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));
            if (!PanelManager.IsRegistered(definition))
            {
                throw new Exception("Error : Requesting BringIntoView shortcut information of an unknown static panel definition : The definition is not registered in the panel manager.");
            }

            return(definition.OfType <BringIntoViewOnKeyShortcut>().Any());
        }
示例#7
0
        private void AssertStaticPanelDefinition(IStaticPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));

            definition.IView.AssertNotNull($"IStaticPanelDefinition.IView");
            definition.View.AssertNotNull($"IStaticPanelDefinition.View");
            definition.IViewModel.AssertNotNull($"IStaticPanelDefinition.IViewModel");
            definition.ViewModel.AssertNotNull($"IStaticPanelDefinition.ViewModel");

            definition.IView.AssertTypeHasGuid(ComposeAssertGuidMessage(definition.IView));
            definition.View.AssertTypeHasGuid(ComposeAssertGuidMessage(definition.View));
            definition.IViewModel.AssertTypeHasGuid(ComposeAssertGuidMessage(definition.IViewModel));
            definition.ViewModel.AssertTypeHasGuid(ComposeAssertGuidMessage(definition.ViewModel));


            if (!definition.View.IsClass ||
                !definition.View.IsSubclassOf(typeof(UserControl)) ||
                definition.View.GetConstructors().Count() != 1 ||
                definition.View.GetConstructors().Single().GetParameters().Any())
            {
                throw new Exception($"Error : {definition.View.Name} must be a class inheriting from user control with an empty constructor.");
            }

            if (!definition.View.Implements(definition.IView))
            {
                throw new Exception($"Error : {definition.View.Name} does not implement {definition.IView.Name}.");
            }

            if (!definition.ViewModel.Implements(definition.IViewModel))
            {
                throw new Exception($"Error : {definition.ViewModel.Name} does not implement {definition.IViewModel.Name}.");
            }

            if (StaticPanelDefinitions.Any(def => def.View == definition.View))
            {
                throw new Exception($"Error! A StaticPanelDefinition with the associated {definition.View.Name} View has already been registered.");
            }
            if (StaticPanelDefinitions.Any(def => def.IView == definition.IView))
            {
                throw new Exception($"Error! A StaticPanelDefinition with the associated View interface {definition.IView.Name} has already been registered.");
            }
            if (StaticPanelDefinitions.Any(def => def.ViewModel == definition.ViewModel))
            {
                throw new Exception($"Error! A StaticPanelDefinition with the associated ViewModel : {definition.ViewModel.Name} has already been registered.");
            }
            if (StaticPanelDefinitions.Any(def => def.IViewModel == definition.IViewModel))
            {
                throw new Exception($"Error! A StaticPanelDefinition with the associated ViewModel interface : {definition.IViewModel.Name} has already been registered.");
            }

            MetadataAsserter.AssertMetadataCollection <IStaticPanelDefinition, IStaticPanelMetadata>(definition, $"StaticPanelDefinition<{definition.IView.Name}, {definition.View.Name}, {definition.IViewModel.Name}, {definition.ViewModel.Name}>");
        }
示例#8
0
        public void OnBringIntoViewRequest(BringStaticPanelIntoViewArgs args)
        {
            IStaticPanelDefinition definition = null;

            try
            {
                definition = anchorableDefinitions.Select(o => o.Value).Single(o => o.ViewModel == args.PanelViewModel || o.IViewModel == args.PanelViewModel);
            }
            catch (InvalidOperationException)
            {
                throw new Exception($"Error : BringStaticPanelIntoView({args.PanelViewModel.Name}) : \n" +
                                    $"There is no StaticPanelDefinition registered associated with the given ViewModel type.");
            }

            BringStaticPanelIntoViewInternal(definition);
        }
        public void ClearShortcut(IStaticPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));
            if (!PanelManager.IsRegistered(definition))
            {
                throw new Exception($"Error : Requesting shortcut cleanup on an unknown static panel definition : The definition is not registered in the PanelManager.");
            }

            if (HasShortcut(definition))
            {
                var shortcut           = GetShortcut(definition);
                var metadataCollection = definition as MetadataCollection <IStaticPanelMetadata>;
                metadataCollection.Remove(shortcut);
                NotifyPanelShortcutsChanged(definition);
            }
        }
示例#10
0
        public BringIntoViewOnKeyShortcut GetShortcut(IStaticPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));

            if (!PanelManager.IsRegistered(definition))
            {
                throw new Exception("Error : Requesting BringIntoView shortcut information of an unknown static panel definition : The definition is not registered in the panel manager.");
            }

            try
            {
                return(definition.OfType <BringIntoViewOnKeyShortcut>().Single());
            }
            catch (InvalidOperationException)
            {
                throw new Exception($"Error : The specified static panel definition({definition.ViewModel.Name}) doesn't have an associated BringIntoView shortcut.");
            }
        }
示例#11
0
        public static StaticPanelShortcutInformation CreateFromDefinition(IStaticPanelDefinition definition)
        {
            definition.AssertParameterNotNull(nameof(definition));

            bool hasShortcut = definition.OfType <BringIntoViewOnKeyShortcut>().Any();

            return(new StaticPanelShortcutInformation()
            {
                ViewGuid = definition.View.GetGuid(),
                IViewGuid = definition.IView.GetGuid(),
                ViewModelGuid = definition.ViewModel.GetGuid(),
                IViewModelGuid = definition.IViewModel.GetGuid(),

                HasShortcut = hasShortcut,
                IsDefault = true,
                ModifierKeys = hasShortcut ? definition.OfType <BringIntoViewOnKeyShortcut>().Single().ModifierKeys : ModifierKeys.None,
                Key = hasShortcut ? definition.OfType <BringIntoViewOnKeyShortcut>().Single().Key : Key.None
            });
        }
示例#12
0
        public void SetShortcut(IStaticPanelDefinition definition, ModifierKeys modifierKeys, Key key)
        {
            definition.AssertParameterNotNull(nameof(definition));
            if (!PanelManager.IsRegistered(definition))
            {
                throw new Exception("Error : Cannot set the BringIntoView shortcut for the specified static panel definition : The definition is not registered in the panel manager.");
            }

            if (!LoadingScope.IsInScope)
            {
                var matchingElements = GetElementsMatchingShortcut(modifierKeys, key).Where(o => !(o == definition));
                if (matchingElements.Any())
                {
                    throw new Exception($"Error setting the shortcut {modifierKeys.ToString()}+{key.ToString()} on command {GetElementName(definition)} " +
                                        $"because element(s) {string.Join(",", matchingElements.Select(o => GetElementName(o)))} already have a shortcut with the same " +
                                        $"key combination.");
                }
            }

            if (HasShortcut(definition))
            {
                var shortcut = GetShortcut(definition);
                if (shortcut.ModifierKeys == modifierKeys && shortcut.Key == key)
                {
                    return;
                }
                shortcut.ModifierKeys = modifierKeys;
                shortcut.Key          = key;
            }
            else
            {
                var metadataCollection = definition as MetadataCollection <IStaticPanelMetadata>;
                metadataCollection.Add(new BringIntoViewOnKeyShortcut(modifierKeys, key));
            }

            NotifyPanelShortcutsChanged(definition);
        }
示例#13
0
 public MainMenuPanelEntryViewModel(IObjectInitializationService initSvc, IMainMenuCommandExtractor commandExtractor, IStaticPanelDefinition definition)
     : base(initSvc)
 {
     CommandExtractor = commandExtractor;
     PanelDefinition  = definition;
 }
示例#14
0
 public BringPanelIntoViewShortcutChangedArgs(IStaticPanelDefinition panelDefinition)
 {
     PanelDefinition = panelDefinition;
 }
 public TMetadata GetPanelMenuOptionMetadata <TMetadata>(IStaticPanelDefinition definition) where TMetadata : IPanelMenuEntryMetadata
 {
     return(definition.OfType <PanelMenuOption>().Single().OfType <TMetadata>().SingleOrDefault());
 }
 internal StaticPanelInvalidationArgs(IStaticPanelDefinition definition)
 {
     Definition = definition;
 }
示例#17
0
 public void RegisterStaticPanelDefinition(IStaticPanelDefinition definition)
 {
     AssertStaticPanelDefinition(definition);
     Container.RegisterService(definition.IViewModel, definition.ViewModel);
     staticPanelDefinitions.Add(definition);
 }
示例#18
0
 public bool IsRegistered(IStaticPanelDefinition definition)
 {
     definition.AssertParameterNotNull(nameof(definition));
     return(StaticPanelDefinitions.Contains(definition));
 }