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

            if (res)
            {
                dstTabGroup.SetSelectedTab(srcTabItem);
            }
            return(res);
        }
Ejemplo n.º 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));
     }
 }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 20
0
 void AddToTabControl(TabItemImpl tabItem, int insertIndex)
 {
     tabControl.Items.Insert(insertIndex, tabItem);
     if (tabControl.Items.Count == 1) {
         tabControl.SelectedItem = tabItem;
         OnStylePropChange();
     }
 }
Ejemplo n.º 21
0
 internal void SetSelectedTab(TabItemImpl tabItem)
 {
     tabControl.SelectedItem = tabItem;
 }
Ejemplo n.º 22
0
 internal bool Contains(TabItemImpl impl)
 {
     return tabControl.Items.Contains(impl);
 }
Ejemplo n.º 23
0
 public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, int insertIndex)
 {
     bool res = MoveTo(dstTabGroup, srcTabItem, insertIndex);
     if (res)
         dstTabGroup.SetSelectedTab(srcTabItem);
     return res;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 25
0
 internal void Close(TabItemImpl impl) => Remove(impl.TabContent);
Ejemplo n.º 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;
		}
Ejemplo n.º 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();
			}
		}
Ejemplo n.º 28
0
 internal bool Contains(TabItemImpl impl)
 {
     return(tabControl.Items.Contains(impl));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 30
0
 public TheHeader(TabItemImpl impl)
 {
     this.impl       = impl;
     this.isSelected = impl.IsSelected;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 32
0
 public TheHeader(TabItemImpl impl)
 {
     this.impl = impl;
     this.isSelected = impl.IsSelected;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 35
0
 public bool MoveToAndSelect(TabGroup dstTabGroup, TabItemImpl srcTabItem, TabItemImpl insertBeforeThis)
 {
     bool res = MoveTo(dstTabGroup, srcTabItem, insertBeforeThis);
     if (res)
         dstTabGroup.SetSelectedTab(srcTabItem);
     return res;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 37
0
 internal void Close(TabItemImpl impl)
 {
     Remove(impl.TabContent);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 39
0
 internal bool SetActiveTab(TabItemImpl tabItem)
 {
     if (tabItem == null || !Contains(tabItem))
         return false;
     this.tabControl.SelectedItem = tabItem;
     return true;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 44
0
 internal void SetSelectedTab(TabItemImpl tabItem) => tabControl.SelectedItem = tabItem;
Ejemplo n.º 45
0
 void DetachTabItem(TabItemImpl tabItem)
 {
     DetachNoEvents(tabItem);
     RemoveEvents(tabItem);
     tabContentAttached.Raise(this, new TabContentAttachedEventArgs(false, tabItem.TabContent));
     NotifyIfEmtpy();
 }
Ejemplo n.º 46
0
 internal bool Contains(TabItemImpl impl) => tabControl.Items.Contains(impl);
Ejemplo n.º 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));
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 50
0
		internal bool Contains(TabItemImpl impl) => tabControl.Items.Contains(impl);