static void OnTitleChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) { ViewSource viewSource = obj as ViewSource; if (viewSource != null && string.IsNullOrWhiteSpace(viewSource.Title)) { viewSource.Title = viewSource.ViewCreator.DisplayName; } }
public void ReadState(XElement element, IDictionary <string, IViewCreationCommand> viewCreators) { this.nextSlotName = int.Parse(element.Attribute("NextSlotName").Value); this.nextViewId = int.Parse(element.Attribute("NextViewId").Value); this.SlotDefinition = LoadSlotFromState(element.Element("Slot")); foreach (var viewElement in element.Elements("View")) { var id = int.Parse(viewElement.Attribute("Id").Value); var slotName = viewElement.Attribute("SlotName").Value; IViewCreationCommand creator; if (viewCreators.TryGetValue(viewElement.Attribute("RegisteredName").Value, out creator)) { var viewSource = new ViewSource(this, id, slotName, creator); this.ViewSources.Add(viewSource); } } }
public ViewSource AddViewSource(IViewCreationCommand creator, Slot targetSlot, Dock?dock) { ViewSource source; if (creator == null) { return(null); } if (this.ViewSources.Count == 0) { source = new ViewSource(this, this.nextViewId++, this.SlotDefinition.Name, creator); this.ViewSources.Add(source); var handler = this.PlaceholderModified; // Note that this is the only place where this event could fire (going from 0 to 1 sources) if (this.IsNewPlaceholder && handler != null) { handler(this, EventArgs.Empty); } return(source); } if (targetSlot == null) { return(null); } Slot newSlot = targetSlot; if (dock.HasValue) { newSlot = SplitSlot(targetSlot, dock.Value); } source = new ViewSource(this, this.nextViewId++, newSlot.Name, creator); this.ViewSources.Add(source); RecomputeViewShortcutKeys(); return(source); }
public ViewSite(IActivationSite parentSite, ViewSource viewSource, DataTemplate template, bool editMode, IServiceProvider serviceProvider) { this.ParentSite = parentSite; this.ViewSource = viewSource; this.Template = template; if (!editMode) { this.View = viewSource.ViewCreator.CreateView(serviceProvider); this.View.DocumentAffinity = this.ViewSource.Parent.DocumentFactoryName; this.View.Site = this; // This binding allows views to control the view source title by simply changing their View.Title property. BindingOperations.SetBinding(this.View, View.TitleProperty, new Binding { Source = this.ViewSource, Path = new PropertyPath(ViewSource.TitleProperty), Mode = BindingMode.TwoWay }); } }
public Slot RemoveViewSource(ViewSource source) { this.ViewSources.Remove(source); var slot = this.SlotDefinition.FindSlot(source.SlotName); if (slot == this.SlotDefinition) { // Never remove the root slot. slot = null; } if (this.ViewSources.Any(s => StringComparer.Ordinal.Equals(s.SlotName, source.SlotName))) { // There are still view sources in this slot, so leave it slot = null; } RecomputeViewShortcutKeys(); return(slot); }
public void ConfirmViewSource(ViewSource source) { this.sources.Add(source); }
public void ReadState(XElement element, IDictionary<string, IViewCreationCommand> viewCreators) { this.nextSlotName = int.Parse(element.Attribute("NextSlotName").Value); this.nextViewId = int.Parse(element.Attribute("NextViewId").Value); this.SlotDefinition = LoadSlotFromState(element.Element("Slot")); foreach (var viewElement in element.Elements("View")) { var id = int.Parse(viewElement.Attribute("Id").Value); var slotName = viewElement.Attribute("SlotName").Value; IViewCreationCommand creator; if (viewCreators.TryGetValue(viewElement.Attribute("RegisteredName").Value, out creator)) { var viewSource = new ViewSource(this, id, slotName, creator); this.ViewSources.Add(viewSource); } } }
public Slot RemoveViewSource(ViewSource source) { this.ViewSources.Remove(source); var slot = this.SlotDefinition.FindSlot(source.SlotName); if (slot == this.SlotDefinition) { // Never remove the root slot. slot = null; } if (this.ViewSources.Any(s => StringComparer.Ordinal.Equals(s.SlotName, source.SlotName))) { // There are still view sources in this slot, so leave it slot = null; } RecomputeViewShortcutKeys(); return slot; }
public ViewSource AddViewSource(IViewCreationCommand creator, Slot targetSlot, Dock? dock) { ViewSource source; if (creator == null) { return null; } if (this.ViewSources.Count == 0) { source = new ViewSource(this, this.nextViewId++, this.SlotDefinition.Name, creator); this.ViewSources.Add(source); var handler = this.PlaceholderModified; // Note that this is the only place where this event could fire (going from 0 to 1 sources) if (this.IsNewPlaceholder && handler != null) { handler(this, EventArgs.Empty); } return source; } if (targetSlot == null) { return null; } Slot newSlot = targetSlot; if (dock.HasValue) { newSlot = SplitSlot(targetSlot, dock.Value); } source = new ViewSource(this, this.nextViewId++, newSlot.Name, creator); this.ViewSources.Add(source); RecomputeViewShortcutKeys(); return source; }
public bool Sweep(bool editMode, DataTemplate singleViewTemplate, DataTemplate tabbedViewTemplate, IServiceProvider serviceProvider) { if (this.sources.Count == 0) { // Nothing added back to this slot, so we're toast. Remove our old content (close all views) and die. SetSlotPanelContent(null); CloseRemainingViews(new Dictionary <ViewSource, ViewSite>()); return(false); } var newSites = new Dictionary <ViewSource, ViewSite>(); if (this.sources.Count == 1) { var presenter = this.slotPanelChild as ContentPresenter; // We need our content to be a simple ContentPresenter. If it isn't, we need to replace. if (presenter == null) { presenter = new ContentPresenter() { ContentTemplate = singleViewTemplate }; } // Need to call this regardless, as it ensures that it has been added to the slot panel SetSlotPanelContent(presenter); ViewSite site; if (!this.sites.TryGetValue(this.sources[0], out site)) { // NOTE: Passing singleViewTemplate here has no effect -- the important thing is that it's set as the // content template of the presenter (above). site = new ViewSite(this, this.sources[0], singleViewTemplate, editMode, serviceProvider); } else { this.sites.Remove(this.sources[0]); } presenter.Content = site; if (presenter.IsLoaded) { OnViewPresenterLoaded(presenter, null); } else { presenter.Loaded += OnViewPresenterLoaded; } newSites.Add(this.sources[0], site); } else { var tabControl = this.slotPanelChild as ViewTabControl; // We need our content to be a tab control. If it isn't, we need to replace. if (tabControl == null) { tabControl = new ViewTabControl(); } // Call regardless, in case the layout control didn't have its template applied last time... SetSlotPanelContent(tabControl); for (int i = 0; i < this.sources.Count; i++) { ViewSource source = this.sources[i]; ViewSite site; if (!this.sites.TryGetValue(source, out site)) { site = new ViewSite(this, source, tabbedViewTemplate, editMode, serviceProvider); } else { this.sites.Remove(source); } int index = tabControl.Items.IndexOf(site); if (index < i) { Debug.Assert(index == -1, "A view site has been added twice?!?"); tabControl.Items.Insert(i, site); } else { while (index > i) { // Other (presumably old) view contents are in the way. Remove them. tabControl.Items.RemoveAt(i); index--; } } newSites.Add(source, site); } while (tabControl.Items.Count > this.sources.Count) { tabControl.Items.RemoveAt(tabControl.Items.Count - 1); } if (tabControl.SelectedIndex < 0) { tabControl.SelectedIndex = 0; } } CloseRemainingViews(newSites); this.sites = newSites; return(true); }
public void RemoveViewSource(ViewSource viewSource) { var slot = this.LayoutDefinition.RemoveViewSource(viewSource); if (slot == null) { // No slot to remove, we're done. return; } if (slot.Children.Count > 0) { Debug.Fail("What?"); return; } var parentSlot = slot.Parent; if (parentSlot.Children.Count < 2) { Debug.Fail("Huh?"); return; } parentSlot.Children.Remove(slot); if (parentSlot.Children.Count == 1) { var otherSlot = parentSlot.Children[0]; // The parent slot is no longer necessary, because it now has a single child. // If that child has no children itself, then make the parent slot look like that child. // That includes the slot name (which moves the child's elements into place). if (otherSlot.Children.Count == 0) { parentSlot.Children.Remove(otherSlot); parentSlot.Orientation = otherSlot.Orientation; parentSlot.Name = otherSlot.Name; } else if ((parentSlot == this.LayoutDefinition.SlotDefinition) || (otherSlot.Orientation != parentSlot.Parent.Orientation)) { // We can just copy the children (and the orientation) of the other slot up to the parent. // This will make the parent slot look just like its remaining child. parentSlot.Children.Remove(otherSlot); foreach (var child in otherSlot.Children) { parentSlot.Children.Add(child); } parentSlot.Orientation = otherSlot.Orientation; } else { // The parent slot goes away, and is replaced by the children of the other slot var grandparent = parentSlot.Parent; int index = grandparent.Children.IndexOf(parentSlot); grandparent.Children.Remove(parentSlot); foreach (var child in otherSlot.Children) { grandparent.Children.Insert(index++, child); } } } }