Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
 void DetachTabItem(TabItemImpl tabItem)
 {
     DetachNoEvents(tabItem);
     RemoveEvents(tabItem);
     tabContentAttached.Raise(this, new TabContentAttachedEventArgs(false, tabItem.TabContent));
     NotifyIfEmtpy();
 }
Пример #4
0
 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));
 }
Пример #5
0
 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);
 }
Пример #6
0
 internal bool SetActiveTab(TabItemImpl tabItem)
 {
     if (tabItem == null || !Contains(tabItem))
     {
         return(false);
     }
     this.tabControl.SelectedItem = tabItem;
     return(true);
 }
Пример #7
0
 void AddToTabControl(TabItemImpl tabItem, int insertIndex)
 {
     tabControl.Items.Insert(insertIndex, tabItem);
     if (tabControl.Items.Count == 1)
     {
         tabControl.SelectedItem = tabItem;
         OnStylePropChange();
     }
 }
Пример #8
0
 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);
     }
 }
Пример #9
0
        public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, int insertIndex)
        {
            bool res = MoveTo(dstTabGroup, srcTabItem, insertIndex);

            if (res)
            {
                dstTabGroup.SetSelectedTab(srcTabItem);
            }
            return(res);
        }
Пример #10
0
 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));
     }
 }
Пример #11
0
 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();
     }
 }
Пример #12
0
 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();
 }
Пример #13
0
 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);
 }
Пример #14
0
        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);
        }
Пример #15
0
 internal bool SetActiveTab(TabItemImpl tabItem)
 {
     if (!stackedContent.Contains(tabItem.Owner))
     {
         return(false);
     }
     if (!tabItem.Owner.SetActiveTab(tabItem))
     {
         return(false);
     }
     SetActive(tabItem.Owner);
     return(true);
 }
Пример #16
0
        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);
        }
Пример #17
0
        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);
        }
Пример #18
0
        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);
        }
Пример #19
0
        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);
            }
        }
Пример #20
0
 void AddToTabControl(TabItemImpl tabItem, int insertIndex)
 {
     tabControl.Items.Insert(insertIndex, tabItem);
     if (tabControl.Items.Count == 1) {
         tabControl.SelectedItem = tabItem;
         OnStylePropChange();
     }
 }
Пример #21
0
 internal void SetSelectedTab(TabItemImpl tabItem)
 {
     tabControl.SelectedItem = tabItem;
 }
Пример #22
0
 internal bool Contains(TabItemImpl impl)
 {
     return tabControl.Items.Contains(impl);
 }
Пример #23
0
 public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, int insertIndex)
 {
     bool res = MoveTo(dstTabGroup, srcTabItem, insertIndex);
     if (res)
         dstTabGroup.SetSelectedTab(srcTabItem);
     return res;
 }
Пример #24
0
        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;
        }
Пример #25
0
 internal void Close(TabItemImpl impl) => Remove(impl.TabContent);
Пример #26
0
		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;
		}
Пример #27
0
		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();
			}
		}
Пример #28
0
 internal bool Contains(TabItemImpl impl)
 {
     return(tabControl.Items.Contains(impl));
 }
Пример #29
0
 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;
 }
Пример #30
0
 public TheHeader(TabItemImpl impl)
 {
     this.impl       = impl;
     this.isSelected = impl.IsSelected;
 }
Пример #31
0
 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);
 }
Пример #32
0
 public TheHeader(TabItemImpl impl)
 {
     this.impl = impl;
     this.isSelected = impl.IsSelected;
 }
Пример #33
0
 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);
 }
Пример #34
0
 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));
 }
Пример #35
0
 public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, TabItemImpl insertBeforeThis)
 {
     bool res = MoveTo(dstTabGroup, srcTabItem, insertBeforeThis);
     if (res)
         dstTabGroup.SetSelectedTab(srcTabItem);
     return res;
 }
Пример #36
0
 internal bool SetActiveTab(TabItemImpl tabItem)
 {
     if (!stackedContent.Contains(tabItem.Owner))
         return false;
     if (!tabItem.Owner.SetActiveTab(tabItem))
         return false;
     SetActive(tabItem.Owner);
     return true;
 }
Пример #37
0
 internal void Close(TabItemImpl impl)
 {
     Remove(impl.TabContent);
 }
Пример #38
0
 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);
 }
Пример #39
0
 internal bool SetActiveTab(TabItemImpl tabItem)
 {
     if (tabItem == null || !Contains(tabItem))
         return false;
     this.tabControl.SelectedItem = tabItem;
     return true;
 }
Пример #40
0
        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;
        }
Пример #41
0
 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);
 }
Пример #42
0
 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();
 }
Пример #43
0
 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;
 }
Пример #44
0
 internal void SetSelectedTab(TabItemImpl tabItem) => tabControl.SelectedItem = tabItem;
Пример #45
0
 void DetachTabItem(TabItemImpl tabItem)
 {
     DetachNoEvents(tabItem);
     RemoveEvents(tabItem);
     tabContentAttached.Raise(this, new TabContentAttachedEventArgs(false, tabItem.TabContent));
     NotifyIfEmtpy();
 }
Пример #46
0
 internal bool Contains(TabItemImpl impl) => tabControl.Items.Contains(impl);
Пример #47
0
 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));
 }
Пример #48
0
 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));
 }
Пример #49
0
 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;
 }
Пример #50
0
		internal bool Contains(TabItemImpl impl) => tabControl.Items.Contains(impl);