示例#1
0
        private void Items_ItemRemoving(object sender, ItemRemovingEventArgs <TabItem> e)
        {
            if (_internalAction)
            {
                return;
            }
            if (e.Item != null)
            {
                TabItemClosingEventArgs ee = new TabItemClosingEventArgs(e.Item);
                TabClosing?.Invoke(this, ee);

                if (ee.Cancel)
                {
                    // don't remove or close anything, just exit
                    closedTabIndex = -1;
                    e.Cancel       = true;
                    return;
                }

                if (Items.SelectedItems.Contains(e.Item) && (SelectedTabClosedAction == SelectedTabCloseAction.SelectTabToLeft || SelectedTabClosedAction == SelectedTabCloseAction.SelectTabToRight))
                {
                    closedTabIndex = Items.IndexOf(e.Item);
                }
                else
                {
                    closedTabIndex = -1;
                }
            }
        }
示例#2
0
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            if (hoveredIndex != -1)
            {
                if (hoveringOverClose)
                {
                    DocumentTabClosingEventArgs args = new DocumentTabClosingEventArgs(tabs[hoveredIndex]);

                    TabClosing?.Invoke(this, args);

                    if (!args.Cancel)
                    {
                        RemoveTab(hoveredIndex);
                    }
                }
                else
                {
                    Select(hoveredIndex);
                }

                Invalidate();
            }
        }
示例#3
0
        /// <summary>
        /// User is closing this tab.
        /// </summary>
        private void OnCloseTabClick(object sender, EventArgs e)
        {
            if (TabClosing != null)
            {
                TabClosing.Invoke(this, e);
            }

            if (TabControl.SelectedTab.Text != indexTabText)
            {
                TabControl.TabPages.Remove(TabControl.SelectedTab);
            }
        }
示例#4
0
        public async void CloseTab(HostedWindowItem hostedWindowItem)
        {
            await tabCloseSemaphore.WaitAsync();

            try
            {
                var index = tabs.IndexOf(hostedWindowItem.TabItem);
                if (index == -1)
                {
                    return;
                }

                TabClosing?.Invoke(this, new TabCloseEventArgs
                {
                    WindowHandle  = hostedWindowItem.WindowHandle,
                    RemainingTabs = tabs.Count - 1,
                });
                tabs[index].Exiting = true;
                SetTabReferenceSize(tabs.Count - 1);

                var activeIndex = ActiveTabIndex;
                if (tabs.Count > 1 && activeIndex == index)
                {
                    if (index == tabs.Count - 1)
                    {
                        ActivateTab(tabs.Count - 2);
                    }
                    else
                    {
                        ActivateTab(index + 1);
                    }
                }

                await Task.Delay(200);

                tabs.RemoveAt(index);

                TabClosed?.Invoke(this, new TabCloseEventArgs
                {
                    WindowHandle  = hostedWindowItem.WindowHandle,
                    RemainingTabs = tabs.Count,
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception in CloseTab: " + ex.ToString());
            }
            finally
            {
                tabCloseSemaphore.Release();
            }
        }
示例#5
0
        public void OnCloseBtnClick(object o, EventArgs e)
        {
            int tabPage = GetTabOfWidget(o);

            if (tabPage > 0)
            {
                if (TabClosing != null)
                {
                    TabClosingArgs args = new TabClosingArgs();
                    args.tabIndex = tabPage;
                    TabClosing.Invoke(this, args);
                }
                notebook1.RemovePage(tabPage);
            }
        }
示例#6
0
        /// <summary>
        /// Trys clearing all tabs while checking if each one can be closed without interuption
        /// </summary>
        /// <returns>Weither there was an interuption</returns>
        public bool TryClearTabs()
        {
            while (tabs.Count != 0)
            {
                DocumentTabClosingEventArgs args = new DocumentTabClosingEventArgs(tabs[selectedIndex]);
                TabClosing?.Invoke(this, args);

                if (args.Cancel)
                {
                    return(false);
                }

                RemoveTab(selectedIndex);
            }

            return(true);
        }
示例#7
0
        /// <summary>User is closing a tab.</summary>
        private void OnCloseTabClick2(object sender, EventArgs e)
        {
            TabClosingEventArgs args = new TabClosingEventArgs();

            args.LeftTabControl = false;

            if (TabClosing != null)
            {
                args.Name  = tabControl2.SelectedTab.Text;
                args.Index = tabControl2.SelectedIndex;
                TabClosing.Invoke(this, args);
            }

            if (args.AllowClose && tabControl2.SelectedTab.Text != indexTabText)
            {
                tabControl2.TabPages.Remove(tabControl2.SelectedTab);
            }
        }
示例#8
0
 public void on_eventbox1_button_press_event(object o, ButtonPressEventArgs e)
 {
     if (e.Event.Button == 2)
     {
         int tabPage = GetTabOfWidget(o);
         notebook1.CurrentPage = tabPage;
         if (tabPage > 0)
         {
             if (TabClosing != null)
             {
                 TabClosingArgs args = new TabClosingArgs();
                 args.tabIndex = tabPage;
                 TabClosing.Invoke(this, args);
             }
             notebook1.RemovePage(tabPage);
         }
     }
 }
示例#9
0
        private void OnTabCloseDown(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && _HoverTabIndex != -1 && _CloseButtonTarget.Contains(e.Location) ||
                e.Button == MouseButtons.Middle && _HoverTabIndex != -1)
            {
                var tabIndex = _HoverTabIndex;

                TabClosing?.Invoke(new TabsEventArgs()
                {
                    TabIndex = tabIndex
                });

                if (tabIndex > -1)
                {
                    TabPages.RemoveAt(tabIndex);

                    SelectedIndex = tabIndex != TabPages.Count ? tabIndex : TabPages.Count - 1;
                }
            }
        }
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);

            if (MouseDownIndex < 0)
            {
                return;
            }

            if (GetCloseBtnRect(MouseDownIndex).Contains(e.Location))
            {
                CancelEventArgs args = new CancelEventArgs(false);
                TabClosing?.Invoke(this, args);

                if (!args.Cancel)
                {
                    TabPages.RemoveAt(MouseDownIndex);
                }
            }

            MouseDownIndex = -1;
            Invalidate();
        }
示例#11
0
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);

            if (hoveredIndex != -1)
            {
                if (hoveringOverClose)
                {
                    DocumentTabClosingEventArgs args = new DocumentTabClosingEventArgs(tabs[hoveredIndex]);

                    TabClosing?.Invoke(this, args);

                    if (!args.Cancel)
                    {
                        RemoveTab(hoveredIndex);
                    }
                }
                else
                {
                    Select(hoveredIndex);
                }

                Invalidate();
            }

            if (hoveredArrow == HoveredArrow.LEFT)
            {
                scrollIndexOffset--;
                Refresh();
            }
            else if (hoveredArrow == HoveredArrow.RIGHT)
            {
                scrollIndexOffset++;
                Refresh();
            }
        }
示例#12
0
 protected internal void OnTabClosing(CancelEventArgs e)
 {
     TabClosing?.Invoke(this, e);
 }
示例#13
0
 protected virtual void OnTabClosing(TabControlCancelEventArgs e) => TabClosing?.Invoke(this, e);