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; }
static EndPoint() { Root = new EndPoint() { CreatedBy = typeof(EndPoint), Name = "Root", Description = "(Root)", CreateMenuEntry = false, Type = EndPointType.Root, Parent = null }; }
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); }
public NavigationEventArgs(IEnumerable<object> oldViews, EndPoint destination, object newView) { OldViews = oldViews; Destination = destination; NewView = newView; }
public bool Show(EndPoint formEndPoint) { return Show(formEndPoint, false); }
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 }
public ICommand Create(string path, EndPoint owner, Action<object> eventMethod) { return Create(path, mi => { }, owner, () => new DelegateCommand<object>(eventMethod)); }
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(); }
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; }
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(); }
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; }
public ICommand Create(string path, Action<MenuItem> initialization, EndPoint owner, ICommand command) { return Create(path, initialization, owner, () => command); }
public ICommand Create(string path, EndPoint owner, ICommand command) { return Create(path, mi => { }, owner, () => command); }
private string GetLog(EndPoint endPoint) { if (endPoint == null || endPoint == EndPoint.Root) { return "desktop"; } return endPoint.GetFullPath(); }
/// <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; }
public ICommand Create(string path, Action<MenuItem> initialization, EndPoint owner, Action<object> eventMethod) { return Create(path, initialization, owner, () => new DelegateCommand<object>(eventMethod)); }