Exemple #1
0
        public MenuDefinition(EndPoint endPoint)
        {
            EndPoint = endPoint;
            ParentMenuPath = string.Empty;

            if (endPoint == EndPoint.Root)
            {
                Caption = string.Empty;
                return;
            }

            Caption = endPoint.Description;

            var parentEndPoint = endPoint.Parent;

            while (true)
            {
                if (parentEndPoint == EndPoint.Root)
                {
                    ParentMenuPath = "/" + ParentMenuPath;
                    break;
                }

                ParentMenuPath = parentEndPoint.Description + ((ParentMenuPath == string.Empty) ? string.Empty : ("/" + ParentMenuPath));
                parentEndPoint = parentEndPoint.Parent;
            }
            Position = endPoint.Ordinal;
        }
        public ExistingEndPointFactory(EndPoint existing)
        {
            if (existing == null)
            {
                throw new ArgumentNullException("existing");
            }

            _Existing = existing;
        }
Exemple #3
0
 static EndPoint()
 {
     Root = new EndPoint()
     {
         CreatedBy = typeof(EndPoint),
         Name = "Root",
         Description = "(Root)",
         CreateMenuEntry = false,
         Type = EndPointType.Root,
         Parent = null
     };
 }
Exemple #4
0
        public bool Show(EndPoint formEndPoint, bool throwOnFormMissing)
        {
            if (!FormsByEndPoint.ContainsKey(formEndPoint))
            {
                if (throwOnFormMissing)
                {
                    throw new ArgumentException(formEndPoint.GetFullPath() + " does not have an associated form");
                }

                return true;
            }

            return RegionNavigator.NavigateTo(formEndPoint);
        }
Exemple #5
0
 public NavigationEventArgs(IEnumerable<object> oldViews, EndPoint destination, object newView)
 {
     OldViews = oldViews;
     Destination = destination;
     NewView = newView;
 }
Exemple #6
0
 public bool Show(EndPoint formEndPoint)
 {
     return Show(formEndPoint, false);
 }
Exemple #7
0
        public bool NavigateTo(EndPoint endPoint)
        {
            Logger.Instance.Log("Navigation to " + GetLog(endPoint) + " requested");

            if (endPoint == null)
            {
                throw new ArgumentException("endPoint");
            }

            DoLocked(() =>
                {
                    if (_IsProcessingNotifications)
                    {
                        throw new InvalidOperationException("Invalid navigation to " + GetLog(endPoint) + " : navigation to EndPoints is not allowed while start-up notifications are being processed");
                    }
                });

            ViewModelForm form = null;

            if (!_FormsManager.FormsByEndPoint.TryGetValue(endPoint, out form))
            {
                throw new ArgumentException(GetLog(endPoint) + " does not have an associated form");
            }

#if!DEBUG
            try
            {
#endif
                if (!IsRequestGranted(endPoint, form.RegionName))
                {
                    Logger.Instance.Log("Request to Navigate to " + GetLog(endPoint) + " denied");  
                    return false;
                }

                EnqueueUIWork(() =>
                    {
                        CompleteNavigation(form);
                    });

                return true;
#if!DEBUG
            }
            catch (Exception e)
            {
                Dialogs.ShowModalMessage("Navigation to " + endPoint.Description + " failed");  
                Logger.Instance.LogException("Navigation failed :", e);
                return false;
            }
#endif
        }
Exemple #8
0
 public ICommand Create(string path, EndPoint owner, Action<object> eventMethod)
 {
     return Create(path, mi => { }, owner, () => new DelegateCommand<object>(eventMethod));
 }
Exemple #9
0
        private void PrepareRegionForChange(string regionName, EndPoint endPoint, object content)
        {
            var activeViewModels = GetActiveViewModels(regionName);
            FrameworkElement dataContextHolder = null;

            var args = new NavigationEventArgs(activeViewModels.ToList(), endPoint, content);
            Navigating(this, args);

            Logger.Instance.Log("Removing " + regionName + " Region content not for " + GetLog(endPoint));
            foreach (var view in _RegionManager.Regions[regionName].Views.ToList())
            {
                if (view != content)
                {
                    if (_DisposableViewStates.ContainsKey(view))
                    {
                        _DisposableViewStates[view].Dispose();
                        _DisposableViewStates.Remove(view);
                    }

                    dataContextHolder = view as FrameworkElement;
                    if (dataContextHolder != null)
                    {
                        dataContextHolder.DataContext = null;
                    }

                    _RegionManager.Regions[regionName].Remove(view);
                }
            }

            activeViewModels.Clear();
        }
Exemple #10
0
        private bool IsRequestGranted(EndPoint destination, string regionName)
        {
            Logger.Instance.Log("Checking for objections for navigation to " + GetLog(destination));

            var request = new NavigationRequest(destination, regionName, this);

            foreach (var subscriber in GetActiveViewModels(regionName))
            {
                subscriber.NavigationRequested(request);
                if (request.Cancel)
                {
                    return false;
                }
            }

            return true;
        }
Exemple #11
0
        public bool NavigateTo(EndPoint destination)
        {
            if (!destination.CreateMenuEntry)
            {
                throw new ArgumentException(destination.GetFullPath() + " does not have a menu entry");
            }

            var menu = FindMenu(destination.GetMenuPath());

            if (menu == null)
            {
                return false;
            }

            return menu.Navigate();
        }
Exemple #12
0
        private ICommand Create(string path, Action<MenuItem> initialization, EndPoint owner, Func<ICommand> commandFactory)
        {
            var command = commandFactory();
            var menuTree = path.Split('\\');
            MenuItem parentMenuItem;
            MenuItem child = null;
            ItemCollection children;
            Stack<Action> cleanup;

            if(!_CleanupsByOwner.TryGetValue(owner, out cleanup))
            {
                cleanup = new Stack<Action>();
                _CleanupsByOwner.Add(owner, cleanup);
            }

            parentMenuItem = MenuBar.Items.OfType<MenuItem>().FirstOrDefault(mi => (string)mi.Header == menuTree[0]);

            if (parentMenuItem == null)
            {
                parentMenuItem = new MenuItem() { Header = menuTree[0] };
                MenuBar.Items.Add(parentMenuItem);
            }
            children = parentMenuItem.Items;

            cleanup.Push(() =>
                {
                    var parentChildren = parentMenuItem.ItemsSource as List<MenuItem>;
                    if (parentChildren.Count == 1)
                    {
                        parentMenuItem.ItemsSource = null;
                        parentChildren.Clear();
                        MenuBar.Items.Remove(parentMenuItem);
                    }
                });

            for (int i = 1; i < menuTree.Length; i++)
            {
                child = children.OfType<MenuItem>().FirstOrDefault(c => (string)c.Header == menuTree[i]);
                if (child == null)
                {
                    child = new MenuItem();
                    child.Header = menuTree[i];
                    children.Add(child);

                    children = child.Items;
                }
                else
                {
                    if (i == menuTree.Length - 1)
                    {
                        throw new ArgumentException("MenuItem " + path + " already exists");
                    }
                    children = child.Items;
                }

                var cleanupChild = child;
                cleanup.Push(() =>
                {
                    var cleanupChildren = cleanupChild.Items;

                    if (cleanupChildren.Count == 1)
                    {
                        cleanupChildren.Clear();
                    }
                });
            }

            child.Command = command;
            initialization(child);

            return command;
        }
Exemple #13
0
 public ICommand Create(string path, Action<MenuItem> initialization, EndPoint owner, ICommand command)
 {
     return Create(path, initialization, owner, () => command);
 }
Exemple #14
0
 public ICommand Create(string path, EndPoint owner, ICommand command)
 {
     return Create(path, mi => { }, owner, () => command);
 }
Exemple #15
0
        private string GetLog(EndPoint endPoint)
        {
            if (endPoint == null || endPoint == EndPoint.Root)
            {
                return "desktop";
            }

            return endPoint.GetFullPath(); 
        }
Exemple #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="destination">Intended destination</param>
 /// <param name="regionName">Region whose view contents will be altered</param>
 /// <param name="regionNavigator">Navigation manager</param>
 public NavigationRequest(EndPoint destination, string regionName, IViewNavigator regionNavigator)
 {
     Destination = destination;
     RegionName = regionName;
     RegionNavigator = regionNavigator;
 }
Exemple #17
0
 public ICommand Create(string path, Action<MenuItem> initialization, EndPoint owner, Action<object> eventMethod)
 {
     return Create(path, initialization, owner, () => new DelegateCommand<object>(eventMethod));
 }