Ejemplo n.º 1
0
        private void ToggleTab(ITab tab)
        {
            Type openTabType = this.OpenTabType;

            if ((tab == null && openTabType == null) || tab.GetType() == openTabType)
            {
                this.OpenTabType = null;
                SoundDefOf.TabClose.PlayOneShotOnCamera();
            }
            else
            {
                tab.OnOpen();
                this.OpenTabType = tab.GetType();
                SoundDefOf.TabOpen.PlayOneShotOnCamera();
            }
        }
Ejemplo n.º 2
0
        protected virtual void OpenTab(ITab newTab) // method allows only one tab of particular type at time
        {
            var redundantTabs = Tabs.Where(tab => tab.GetType() == newTab.GetType());

            if (redundantTabs.Count() == 0)
            {
                Tabs.Add(newTab);
                SelectedTab = Tabs.Last();
            }
            else
            {
                SelectedTab = Tabs[Tabs.IndexOf(redundantTabs.First())];
            }
        }
Ejemplo n.º 3
0
        // -> Aux
        private void AddTabWithRedundanceControl(ITab tabToAdd) // adds specified tab only if there is no of it's kind :)
        {
            var similarTabs = Tabs.Where(tab => tab.GetType() == tabToAdd.GetType());

            if (similarTabs.Count() == 0)
            {
                Tabs.Add(tabToAdd);
                SelectedTab = Tabs.Last();
            }
            else
            {
                SelectedTab = Tabs[Tabs.IndexOf(similarTabs.First())];
            }
        }
Ejemplo n.º 4
0
        internal bool DockIntoTab(ITab sourceTab, ITabDock targetTabParent, DragAction action, DockOperation operation, bool bExecute)
        {
#if DEBUG
            Console.WriteLine($"{nameof(DockIntoTab)}: {sourceTab.Title} -> {targetTabParent.Title}");
#endif
            if (sourceTab.Parent is ITabDock sourceTabParent)
            {
                IView targetTab = targetTabParent.Views.LastOrDefault();

                switch (action)
                {
                case DragAction.Copy:
                {
                    if (bExecute)
                    {
                        // TODO: Clone item.
                    }
                    return(true);
                }

                case DragAction.Move:
                {
                    switch (operation)
                    {
                    case DockOperation.Fill:
                    {
                        if (sourceTabParent.Factory is IDockFactory factory)
                        {
                            if (bExecute)
                            {
                                factory.MoveView(sourceTabParent, targetTabParent, sourceTab, targetTab);
                            }
                            return(true);
                        }
                        return(false);
                    }

                    case DockOperation.Left:
                    case DockOperation.Right:
                    case DockOperation.Top:
                    case DockOperation.Bottom:
                    {
                        switch (sourceTab)
                        {
                        case IToolTab toolTab:
                        {
                            if (bExecute)
                            {
                                if (targetTabParent.Factory is IDockFactory factory)
                                {
                                    factory.RemoveView(sourceTab);

                                    IDock tool = factory.CreateToolDock();
                                    tool.Id          = nameof(IToolDock);
                                    tool.Title       = nameof(IToolDock);
                                    tool.CurrentView = sourceTab;
                                    tool.Views       = factory.CreateList <IView>();
                                    tool.Views.Add(sourceTab);

                                    factory.Split(targetTabParent, tool, operation);
                                }
                            }
                            return(true);
                        }

                        case IDocumentTab documentTab:
                        {
                            if (bExecute)
                            {
                                if (targetTabParent.Factory is IDockFactory factory)
                                {
                                    factory.RemoveView(sourceTab);

                                    IDock document = factory.CreateDocumentDock();
                                    document.Id          = nameof(IDocumentDock);
                                    document.Title       = nameof(IDocumentDock);
                                    document.CurrentView = sourceTab;
                                    document.Views       = factory.CreateList <IView>();
                                    document.Views.Add(sourceTab);

                                    factory.Split(targetTabParent, document, operation);
                                }
                            }
                            return(true);
                        }

                        default:
                        {
#if DEBUG
                            Console.WriteLine($"Not supported tab type {sourceTab.GetType().Name} to splitting : {sourceTab} -> {targetTabParent}");
#endif
                            return(false);
                        }
                        }
                    }

                    case DockOperation.Window:
                    {
                        return(false);
                    }
                    }
                    return(false);
                }

                case DragAction.Link:
                {
                    if (bExecute)
                    {
                        if (sourceTabParent.Factory is IDockFactory factory)
                        {
                            factory.SwapView(sourceTabParent, targetTabParent, sourceTab, targetTab);
                        }
                    }
                    return(true);
                }
                }
                return(false);
            }

            return(false);
        }