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(); }
void MoveAllToOtherTabGroup(TabManager <TState> dst, TabManager <TState> src) { var activeTab = src.ActiveTabState; Merge(dst, src, 0); dst.SetSelectedTab(activeTab); SetActive(dst); }
public bool MoveToAndSelect(TabManager <TState> dstTabManager, TState srcTabState, int insertIndex) { bool res = MoveTo(dstTabManager, srcTabState, insertIndex); if (res) { dstTabManager.SetSelectedTab(srcTabState); } return(res); }
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); } }
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); }
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)); } }
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++); } }
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); }
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)); } }
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); }