Beispiel #1
0
        void OnWindowClosed(object sender, EventArgs e)
        {
            var window = sender as ToolsUIWindow;

            if (window == null)
            {
                return;
            }

            this.allWindows.Remove(window);

            if (this.allWindows.Count == 0)
            {
                // That was the last window. If we're not shutting down by now, do it.
                if (!this.ShuttingDown)
                {
                    this.ShuttingDown = true;
                    DoShutdown();
                }
            }

            if (window == this.mainWindow)
            {
                this.mainWindow = this.allWindows.OrderBy(w => - w.ActivationIndex).FirstOrDefault();
            }

            if (!this.ShuttingDown && (this.mainWindow != null))
            {
                RequestViewBindingUpdate();
                Notify("WindowCount");
            }
        }
        public LayoutInstance(IServiceProvider serviceProvider, IActivationSite parentSite, LayoutDefinition layoutDefinition, bool isInEditMode)
        {
            this.LayoutDefinition = layoutDefinition;
            this.LayoutDefinition.SlotDefinition.Changed        += OnRootSlotChanged;
            this.LayoutDefinition.ViewSources.CollectionChanged += OnLayoutDefinitionViewSourcesChanged;
            this.ParentSite   = parentSite;
            this.IsInEditMode = isInEditMode;

            this.serviceContainer = new ServiceContainer(serviceProvider);
            this.serviceContainer.AddService(typeof(IViewBindingService), this);

            this.ServiceProvider = serviceContainer;

            this.LayoutControl = new LayoutControl(this);
            this.LayoutControl.SlotDefinition = isInEditMode ? this.LayoutDefinition.SlotDefinition : this.LayoutDefinition.SlotDefinition.Clone();

            this.singleViewContentTemplate = this.LayoutControl.FindResource(isInEditMode ? "EditModeSingleViewContentTemplate" : "SingleViewContentTemplate") as DataTemplate;
            this.tabbedViewContentTemplate = this.LayoutControl.FindResource(isInEditMode ? "EditModeTabbedViewContentTemplate" : "TabbedViewContentTemplate") as DataTemplate;

            this.ourWindow = serviceProvider.GetService(typeof(ToolsUIWindow)) as ToolsUIWindow;

            object stateObject;

            // We do this trick (storing our activation state in our window per layout definition) so that
            // the layout editor can create an instance that matches the "real" layout states.
            if (!this.ourWindow.StateTable.TryGetValue(this.LayoutDefinition, out stateObject))
            {
                stateObject = new LayoutInstanceState();
                this.ourWindow.StateTable[this.LayoutDefinition] = stateObject;
            }

            this.state = (LayoutInstanceState)stateObject;

            EnsureSlotContentPopulation();
        }
Beispiel #3
0
        public ToolsUIWindow CreateWindow()
        {
            var window = CreateToolsUIWindow();

            if (this.mainWindow == null)
            {
                this.mainWindow = window;
            }

            this.allWindows.Add(window);
            window.Closed += OnWindowClosed;
            Notify("WindowCount");
            return(window);
        }
Beispiel #4
0
        internal void LoadWindowState(ToolsUIWindow mainWindow)
        {
            this.mainWindow = mainWindow;

            try
            {
                var defaultStateText         = GetDefaultWindowStateResourceText();
                var stateDoc                 = XElement.Parse(defaultStateText);
                var layoutDefinitionsElement = stateDoc.Element("LayoutDefinitions");

                this.defaultLayoutDefinitions = layoutDefinitionsElement.Elements("LayoutDefinition")
                                                .Select(e => LayoutDefinition.LoadFromState(e, this.viewCreators))
                                                .ToList();
            }
            catch (Exception)
            {
                this.defaultLayoutDefinitions = new List <LayoutDefinition>();
            }

            LoadWindowState();
        }
        public IEnumerable <MetadataView> GetMetadataViews(Window window)
        {
            DebugHelper.AssertUIThread();

            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            while (window.Owner != null)
            {
                window = window.Owner;
            }

            IEnumerable <MetadataView> value = null;

            ToolsUIWindow toolsWindow = window as ToolsUIWindow;

            if (toolsWindow != null)
            {
                LayoutTabControl tabControl = toolsWindow.LayoutTabControl;

                if (tabControl != null)
                {
                    int layoutIndex = tabControl.SelectedIndex;

                    List <MetadataView> activeTab = new List <MetadataView>();
                    List <MetadataView> otherTabs = new List <MetadataView>();
                    List <MetadataView> temp      = new List <MetadataView>();

                    for (int i = 0; i < tabControl.Items.Count; ++i)
                    {
                        List <MetadataView> list = (i == layoutIndex) ? activeTab : temp;

                        LayoutInstance layout = tabControl.Items[i] as LayoutInstance;
                        if (layout != null)
                        {
                            foreach (View v in layout.FindViews("MetadataView"))
                            {
                                MetadataView mv = v as MetadataView;

                                if (mv != null)
                                {
                                    list.Add(mv);
                                }
                            }
                        }

                        if ((i != layoutIndex) && (list.Count > 0))
                        {
                            if (otherTabs.Count > 0)
                            {
                                otherTabs.Add(null);
                            }

                            otherTabs.AddRange(list.OrderBy(mv => mv.Title));

                            list.Clear();
                        }
                    }

                    List <MetadataView> metadataViews = new List <MetadataView>();

                    if (activeTab.Count > 0)
                    {
                        metadataViews.AddRange(activeTab.OrderBy(mv => mv.Title));

                        if (otherTabs.Count > 0)
                        {
                            metadataViews.Add(null);
                        }
                    }

                    metadataViews.AddRange(otherTabs);
                    value = metadataViews;
                }
            }

            return(value);
        }