示例#1
0
        public void Remove(TabManager <TState> tabManager)
        {
            int index = tabManagers.IndexOf(tabManager);

            Debug.Assert(index >= 0);
            if (index < 0)
            {
                return;
            }
            if (tabManagers.Count <= 1)
            {
                return;
            }
            if (ActiveIndex == index)
            {
                int newIndex = index == 0 ? index + 1 : index - 1;
                SetActive(tabManagers[newIndex]);
                ActiveIndex = newIndex;
            }
            var current = tabManagers[ActiveIndex];

            tabManagers.Remove(tabManager);
            ActiveIndex = tabManagers.IndexOf(current);
            Debug.Assert(ActiveIndex >= 0);
            if (OnTabGroupRemoved != null)
            {
                OnTabGroupRemoved(this, TabGroupEventArgs.Empty);
            }
            UpdateGrid();
        }
示例#2
0
        void MoveAllToOtherTabGroup(TabManager <TState> dst, TabManager <TState> src)
        {
            var activeTab = src.ActiveTabState;

            Merge(dst, src, 0);
            dst.SetSelectedTab(activeTab);
            SetActive(dst);
        }
示例#3
0
        public bool MoveToAndSelect(TabManager <TState> dstTabManager, TState srcTabState, int insertIndex)
        {
            bool res = MoveTo(dstTabManager, srcTabState, insertIndex);

            if (res)
            {
                dstTabManager.SetSelectedTab(srcTabState);
            }
            return(res);
        }
示例#4
0
 void Move(TabManager <TState> dstTabManager, TabManager <TState> srcTabManager, TState srcTabState, int insertIndex = 0)
 {
     Debug.Assert(tabManagers.Contains(dstTabManager));
     Debug.Assert(tabManagers.Contains(srcTabManager));
     Debug.Assert(srcTabManager.TabControl.Items.Contains(srcTabState.TabItem));
     if (srcTabManager.MoveToAndSelect(dstTabManager, srcTabState, insertIndex))
     {
         SetActive(dstTabManager);
     }
 }
示例#5
0
        public bool MoveTo(TabManager <TState> dstTabManager, TState srcTabState, int insertIndex)
        {
            Debug.Assert(this.TabControl.Items.Contains(srcTabState.TabItem));
            if (srcTabState == null)
            {
                return(false);
            }

            DetachTabState(srcTabState);
            dstTabManager.AttachTabState(srcTabState, insertIndex);
            return(true);
        }
示例#6
0
 public bool MoveTo(TabManager <TState> dstTabManager, TState srcTabState, TState insertBeforeThis)
 {
     if (insertBeforeThis != null)
     {
         Debug.Assert(dstTabManager.tabControl.Items.Contains(insertBeforeThis.TabItem));
         return(MoveTo(dstTabManager, srcTabState, dstTabManager.tabControl.Items.IndexOf(insertBeforeThis.TabItem)));
     }
     else
     {
         return(MoveTo(dstTabManager, srcTabState, -1));
     }
 }
示例#7
0
 void Merge(TabManager <TState> dstTabManager, TabManager <TState> srcTabManager, int insertIndex)
 {
     if (dstTabManager == srcTabManager)
     {
         return;
     }
     if (insertIndex < 0 || insertIndex > dstTabManager.Count)
     {
         insertIndex = dstTabManager.Count;
     }
     foreach (var srcTabState in srcTabManager.AllTabStates.ToArray())
     {
         srcTabManager.MoveTo(dstTabManager, srcTabState, insertIndex++);
     }
 }
示例#8
0
        TabManager <TState> CreateTabManager(int insertIndex)
        {
            var tabControl = new TabControl();

            tabControl.Style = App.Current.FindResource("TabStateDecompileTabControl") as Style;
            var tabManager = new TabManager <TState>(this, tabControl, onSelectionChanged, onAddRemoveTabState);

            tabManagers.Insert(insertIndex, tabManager);
            ContextMenuProvider.Add(tabManager.TabControl);
            if (OnTabGroupAdded != null)
            {
                OnTabGroupAdded(this, TabGroupEventArgs.Empty);
            }
            return(tabManager);
        }
示例#9
0
        public void SetActive(TabManager <TState> tabManager)
        {
            if (tabManager == tabManagers[ActiveIndex])
            {
                return;
            }
            int newIndex = tabManagers.IndexOf(tabManager);

            if (newIndex < 0)
            {
                throw new InvalidOperationException();
            }
            int oldIndex = ActiveIndex;

            ActiveIndex = newIndex;
            if (OnTabGroupSelected != null)
            {
                OnTabGroupSelected(this, new TabGroupSelectedEventArgs(oldIndex, newIndex));
            }
        }
示例#10
0
        bool GetInfo(object sender, DragEventArgs e, out TabItem source, out TabItem target, out TabControl tabControlSource, out TabControl tabControlTarget, out TState tabStateSource, out TState tabStateTarget, out TabManager <TState> tabManagerSource, out TabManager <TState> tabManagerTarget, bool canBeSame)
        {
            source           = target = null;
            tabControlSource = tabControlTarget = null;
            tabStateSource   = tabStateTarget = null;
            tabManagerSource = tabManagerTarget = null;

            if (!e.Data.GetDataPresent(typeof(TabItem)))
            {
                return(false);
            }

            target = sender as TabItem;
            source = (TabItem)e.Data.GetData(typeof(TabItem));
            if (target == null || source == null || (!canBeSame && target == source))
            {
                return(false);
            }
            tabControlTarget = target.Parent as TabControl;
            if (tabControlTarget == null)
            {
                return(false);
            }
            tabControlSource = source.Parent as TabControl;
            if (tabControlSource == null)
            {
                return(false);
            }

            tabManagerTarget = tabControlTarget.DataContext as TabManager <TState>;
            tabManagerSource = tabControlSource.DataContext as TabManager <TState>;
            if (tabManagerTarget == null || tabManagerSource == null)
            {
                return(false);
            }
            if (tabManagerTarget.tabGroupsManager != tabManagerSource.tabGroupsManager)
            {
                return(false);
            }
            if (tabManagerTarget.tabGroupsManager != this.tabGroupsManager)
            {
                return(false);
            }

            tabStateSource = source.DataContext as TState;
            tabStateTarget = target.DataContext as TState;
            if (tabStateSource == null || tabStateTarget == null)
            {
                return(false);
            }

            return(true);
        }