void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (sender != tabControl || e.Source != tabControl) { return; } Debug.Assert(e.RemovedItems.Count <= 1); Debug.Assert(e.AddedItems.Count <= 1); TabItemImpl selected = null, unselected = null; if (e.RemovedItems.Count >= 1) { unselected = e.RemovedItems[0] as TabItemImpl; if (unselected == null) { return; } } if (e.AddedItems.Count >= 1) { selected = e.AddedItems[0] as TabItemImpl; if (selected == null) { return; } } tabGroupService.SetActive(this); tabGroupService.OnSelectionChanged(this, selected, unselected); }
void DetachNoEvents(TabItemImpl tabItem) { if (tabItem == null) { return; } int index = tabControl.Items.IndexOf(tabItem); Debug.Assert(index >= 0); if (index < 0) { return; } if (tabControl.Items.Count == 1) { tabControl.Items.RemoveAt(index); tabControl.SelectedIndex = -1; } else if (index == 0) { tabControl.SelectedIndex = index + 1; tabControl.Items.RemoveAt(index); } else { tabControl.SelectedIndex = index - 1; tabControl.Items.RemoveAt(index); } }
void DetachTabItem(TabItemImpl tabItem) { DetachNoEvents(tabItem); RemoveEvents(tabItem); tabContentAttached.Raise(this, new TabContentAttachedEventArgs(false, tabItem.TabContent)); NotifyIfEmtpy(); }
void RemoveEvents(TabItemImpl impl) { impl.MouseRightButtonDown -= tabItem_MouseRightButtonDown; impl.PreviewMouseDown -= tabItem_PreviewMouseDown; impl.DragOver -= tabItem_DragOver; impl.Drop -= tabItem_Drop; impl.RemoveHandler(UIElement.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(tabItem_GotKeyboardFocus)); impl.RemoveHandler(UIElement.LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(tabItem_LostKeyboardFocus)); }
void AddEvents(TabItemImpl impl) { impl.MouseRightButtonDown += tabItem_MouseRightButtonDown; impl.PreviewMouseDown += tabItem_PreviewMouseDown; impl.DragOver += tabItem_DragOver; impl.Drop += tabItem_Drop; impl.AddHandler(UIElement.GotKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(tabItem_GotKeyboardFocus), true); impl.AddHandler(UIElement.LostKeyboardFocusEvent, new KeyboardFocusChangedEventHandler(tabItem_LostKeyboardFocus), true); }
internal bool SetActiveTab(TabItemImpl tabItem) { if (tabItem == null || !Contains(tabItem)) { return(false); } this.tabControl.SelectedItem = tabItem; return(true); }
void AddToTabControl(TabItemImpl tabItem, int insertIndex) { tabControl.Items.Insert(insertIndex, tabItem); if (tabControl.Items.Count == 1) { tabControl.SelectedItem = tabItem; OnStylePropChange(); } }
void Move(TabGroup dstTabGroup, TabGroup srcTabGroup, TabItemImpl srcTabItemImpl, int insertIndex = 0) { Debug.Assert(stackedContent.Contains(dstTabGroup)); Debug.Assert(stackedContent.Contains(srcTabGroup)); Debug.Assert(srcTabGroup.Contains(srcTabItemImpl)); if (srcTabGroup.MoveToAndSelect(dstTabGroup, srcTabItemImpl, insertIndex)) { SetActive(dstTabGroup); } }
public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, int insertIndex) { bool res = MoveTo(dstTabGroup, srcTabItem, insertIndex); if (res) { dstTabGroup.SetSelectedTab(srcTabItem); } return(res); }
public bool MoveTo(TabGroup dstTabGroup, TabItemImpl srcTabItem, TabItemImpl insertBeforeThis) { if (insertBeforeThis != null) { Debug.Assert(dstTabGroup.tabControl.Items.Contains(insertBeforeThis)); return(MoveTo(dstTabGroup, srcTabItem, dstTabGroup.tabControl.Items.IndexOf(insertBeforeThis))); } else { return(MoveTo(dstTabGroup, srcTabItem, -1)); } }
void AddToTabControl(TabItemImpl tabItem, int insertIndex) { tabControl.Items.Insert(insertIndex, tabItem); if (tabControl.Items.Count == 1) { // Don't select the item because it will always make the first tab active at startup. // The tab will then get an IsVisible event which could initialize stuff that takes // a long time to initialize (eg. the C# Interactive tool window) // DON'T: tabControl.SelectedItem = tabItem; OnStylePropChange(); } }
void RemoveTabItem(TabItemImpl tabItem) { if (tabItem == null) { return; } Debug.Assert(tabControl.Items.Contains(tabItem)); DetachNoEvents(tabItem); RemoveEvents(tabItem); tabItem.TabContent.OnVisibilityChanged(TabContentVisibilityEvent.Removed); tabItem.Dispose(); NotifyIfEmtpy(); }
TabItemImpl AttachTabItem(TabItemImpl tabItem, int insertIndex) { tabItem.Owner = this; AddEvents(tabItem); if (insertIndex < 0 || insertIndex > tabControl.Items.Count) { insertIndex = tabControl.Items.Count; } UpdateState(tabItem); AddToTabControl(tabItem, insertIndex); tabContentAttached.Raise(this, new TabContentAttachedEventArgs(true, tabItem.TabContent)); return(tabItem); }
public void Add(ITabContent content) { if (content == null) { throw new ArgumentNullException(nameof(content)); } var impl = new TabItemImpl(this, content, options.TabItemStyle); AddEvents(impl); content.OnVisibilityChanged(TabContentVisibilityEvent.Added); UpdateState(impl); AddToTabControl(impl, tabControl.Items.Count); }
internal bool SetActiveTab(TabItemImpl tabItem) { if (!stackedContent.Contains(tabItem.Owner)) { return(false); } if (!tabItem.Owner.SetActiveTab(tabItem)) { return(false); } SetActive(tabItem.Owner); return(true); }
bool GetInfo(object sender, DragEventArgs e, out TabItemImpl tabItemSource, out TabItemImpl tabItemTarget, out TabGroup tabGroupSource, out TabGroup tabGroupTarget, bool canBeSame) { tabItemSource = tabItemTarget = null; tabGroupSource = tabGroupTarget = null; if (!e.Data.GetDataPresent(typeof(TabItemImpl))) { return(false); } tabItemTarget = sender as TabItemImpl; tabItemSource = (TabItemImpl)e.Data.GetData(typeof(TabItemImpl)); if (tabItemTarget == null || tabItemSource == null || (!canBeSame && tabItemTarget == tabItemSource)) { return(false); } var tabControlTarget = tabItemTarget.Parent as TabControl; if (tabControlTarget == null) { return(false); } var tabControlSource = tabItemSource.Parent as TabControl; if (tabControlSource == null) { return(false); } tabGroupTarget = tabControlTarget.DataContext as TabGroup; tabGroupSource = tabControlSource.DataContext as TabGroup; if (tabGroupTarget == null || tabGroupSource == null) { return(false); } if (tabGroupTarget.tabGroupService.TabService != tabGroupSource.tabGroupService.TabService) { return(false); } if (tabGroupTarget.tabGroupService != this.tabGroupService) { return(false); } return(true); }
public bool MoveTo(TabGroup dstTabGroup, TabItemImpl srcTabItem, int insertIndex) { Debug.Assert(Contains(srcTabItem)); if (srcTabItem == null) { return(false); } DetachTabItem(srcTabItem); dstTabGroup.AttachTabItem(srcTabItem, insertIndex); if (srcTabItem.IsKeyboardFocusWithin) { tabGroupService.SetActiveTab(srcTabItem); this.IsActive = false; dstTabGroup.IsActive = true; } return(true); }
bool GetTabItem(object sender, MouseEventArgs e, out TabItemImpl tabItem, out TabControl tabControl) { tabItem = null; tabControl = null; tabItem = GetTabItemImpl(sender); if (tabItem == null) { return(false); } tabControl = tabItem.Parent as TabControl; if (tabControl == null) { return(false); } if (!IsDragArea(sender, e, tabItem)) { return(false); } return(true); }
void DetachNoEvents(TabItemImpl tabItem) { if (tabItem == null) return; int index = tabControl.Items.IndexOf(tabItem); Debug.Assert(index >= 0); if (index < 0) return; if (tabControl.Items.Count == 1) { tabControl.Items.RemoveAt(index); tabControl.SelectedIndex = -1; } else if (index == 0) { tabControl.SelectedIndex = index + 1; tabControl.Items.RemoveAt(index); } else { tabControl.SelectedIndex = index - 1; tabControl.Items.RemoveAt(index); } }
internal void SetSelectedTab(TabItemImpl tabItem) { tabControl.SelectedItem = tabItem; }
internal bool Contains(TabItemImpl impl) { return tabControl.Items.Contains(impl); }
public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, int insertIndex) { bool res = MoveTo(dstTabGroup, srcTabItem, insertIndex); if (res) dstTabGroup.SetSelectedTab(srcTabItem); return res; }
public bool MoveTo(TabGroup dstTabGroup, TabItemImpl srcTabItem, int insertIndex) { Debug.Assert(Contains(srcTabItem)); if (srcTabItem == null) return false; DetachTabItem(srcTabItem); dstTabGroup.AttachTabItem(srcTabItem, insertIndex); if (srcTabItem.IsKeyboardFocusWithin) { tabGroupManager.SetActiveTab(srcTabItem); this.IsActive = false; dstTabGroup.IsActive = true; } return true; }
internal void Close(TabItemImpl impl) => Remove(impl.TabContent);
bool GetTabItem(object sender, MouseEventArgs e, out TabItemImpl tabItem, out TabControl tabControl) { tabItem = null; tabControl = null; tabItem = GetTabItemImpl(sender); if (tabItem == null) return false; tabControl = tabItem.Parent as TabControl; if (tabControl == null) return false; if (!IsDragArea(sender, e, tabItem)) return false; return true; }
internal bool Contains(TabItemImpl impl) { return(tabControl.Items.Contains(impl)); }
void UpdateState(TabItemImpl tabItem) { Debug.Assert(tabControl.Items.IndexOf(tabItem) < 0); tabItem.IsSelected = false; // It's not inserted so can't be selected tabItem.IsActive = IsActive && tabControl.IsKeyboardFocusWithin; }
public TheHeader(TabItemImpl impl) { this.impl = impl; this.isSelected = impl.IsSelected; }
public void Add(ITabContent content) { if (content == null) throw new ArgumentNullException(); var impl = new TabItemImpl(this, content, options.TabItemStyle); AddEvents(impl); content.OnVisibilityChanged(TabContentVisibilityEvent.Added); UpdateState(impl); AddToTabControl(impl, tabControl.Items.Count); }
public bool MoveTo(TabGroup dstTabGroup, TabItemImpl srcTabItem, TabItemImpl insertBeforeThis) { if (insertBeforeThis != null) { Debug.Assert(dstTabGroup.tabControl.Items.Contains(insertBeforeThis)); return MoveTo(dstTabGroup, srcTabItem, dstTabGroup.tabControl.Items.IndexOf(insertBeforeThis)); } else return MoveTo(dstTabGroup, srcTabItem, -1); }
internal void OnSelectionChanged(TabGroup tabGroup, TabItemImpl selected, TabItemImpl unselected) { tabSelectionChanged.Raise(this, new TabSelectedEventArgs(tabGroup, selected == null ? null : selected.TabContent, unselected == null ? null : unselected.TabContent)); }
public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, TabItemImpl insertBeforeThis) { bool res = MoveTo(dstTabGroup, srcTabItem, insertBeforeThis); if (res) dstTabGroup.SetSelectedTab(srcTabItem); return res; }
internal bool SetActiveTab(TabItemImpl tabItem) { if (!stackedContent.Contains(tabItem.Owner)) return false; if (!tabItem.Owner.SetActiveTab(tabItem)) return false; SetActive(tabItem.Owner); return true; }
internal void Close(TabItemImpl impl) { Remove(impl.TabContent); }
void Move(TabGroup dstTabGroup, TabGroup srcTabGroup, TabItemImpl srcTabItemImpl, int insertIndex = 0) { Debug.Assert(stackedContent.Contains(dstTabGroup)); Debug.Assert(stackedContent.Contains(srcTabGroup)); Debug.Assert(srcTabGroup.Contains(srcTabItemImpl)); if (srcTabGroup.MoveToAndSelect(dstTabGroup, srcTabItemImpl, insertIndex)) SetActive(dstTabGroup); }
internal bool SetActiveTab(TabItemImpl tabItem) { if (tabItem == null || !Contains(tabItem)) return false; this.tabControl.SelectedItem = tabItem; return true; }
bool GetInfo(object sender, DragEventArgs e, out TabItemImpl tabItemSource, out TabItemImpl tabItemTarget, out TabGroup tabGroupSource, out TabGroup tabGroupTarget, bool canBeSame) { tabItemSource = tabItemTarget = null; tabGroupSource = tabGroupTarget = null; if (!e.Data.GetDataPresent(typeof(TabItemImpl))) return false; tabItemTarget = sender as TabItemImpl; tabItemSource = (TabItemImpl)e.Data.GetData(typeof(TabItemImpl)); if (tabItemTarget == null || tabItemSource == null || (!canBeSame && tabItemTarget == tabItemSource)) return false; var tabControlTarget = tabItemTarget.Parent as TabControl; if (tabControlTarget == null) return false; var tabControlSource = tabItemSource.Parent as TabControl; if (tabControlSource == null) return false; tabGroupTarget = tabControlTarget.DataContext as TabGroup; tabGroupSource = tabControlSource.DataContext as TabGroup; if (tabGroupTarget == null || tabGroupSource == null) return false; if (tabGroupTarget.tabGroupManager.TabManager != tabGroupSource.tabGroupManager.TabManager) return false; if (tabGroupTarget.tabGroupManager != this.tabGroupManager) return false; return true; }
void RemoveTabItem(TabItemImpl tabItem) { if (tabItem == null) return; Debug.Assert(tabControl.Items.Contains(tabItem)); DetachNoEvents(tabItem); RemoveEvents(tabItem); tabItem.TabContent.OnVisibilityChanged(TabContentVisibilityEvent.Removed); tabItem.Dispose(); NotifyIfEmtpy(); }
TabItemImpl AttachTabItem(TabItemImpl tabItem, int insertIndex) { tabItem.Owner = this; AddEvents(tabItem); if (insertIndex < 0 || insertIndex > tabControl.Items.Count) insertIndex = tabControl.Items.Count; UpdateState(tabItem); AddToTabControl(tabItem, insertIndex); tabContentAttached.Raise(this, new TabContentAttachedEventArgs(true, tabItem.TabContent)); return tabItem; }
internal void SetSelectedTab(TabItemImpl tabItem) => tabControl.SelectedItem = tabItem;
internal bool Contains(TabItemImpl impl) => tabControl.Items.Contains(impl);