private void ChangeTab(object sender, SelectionChangedEventArgs e)
        {
            TabItem tab = (TabItem)((TabControl)sender).SelectedValue;

            if (tab.Equals(LogTab))
            {
                LogTab.Header = "[0] Log";
            }
            else if (tab.Equals(RespondTab))
            {
                RespondTab.Header = "Respond";
            }
        }
예제 #2
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string  tabName = (sender as Button).CommandParameter.ToString();
            var     item    = tabDynamic.Items.Cast <TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();
            TabItem tab     = item as TabItem;

            if (tab != null)
            {
                if (_tabItems.Count < 3)
                {
                    MessageBox.Show("Cannot delete last NFA Diagram.");
                }
                else if (MessageBox.Show(string.Format("Are are sure to delete {0} ?", tab.Header.ToString()),
                                         "Delete NFA", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    // get selected tab
                    TabItem selectedTab = tabDynamic.SelectedItem as TabItem;

                    // clear tab control binding
                    tabDynamic.DataContext = null;

                    _tabItems.Remove(tab);

                    // bind tab control
                    tabDynamic.DataContext = _tabItems;

                    // select previously selected tab. if that is removed then select first tab
                    if (selectedTab == null || selectedTab.Equals(tab))
                    {
                        selectedTab = _tabItems[0];
                    }
                    tabDynamic.SelectedItem = selectedTab;
                }
            }
        }
예제 #3
0
        private void tabDynamic_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TabItem tab = tabDynamic.SelectedItem as TabItem;

            if (tab == null)
            {
                return;
            }

            if (tab.Equals(_tabAdd))
            {
                // clear tab control binding
                tabDynamic.DataContext = null;

                TabItem newTab = this.AddTabItem();

                // bind tab control
                tabDynamic.DataContext = _tabItems;

                // select newly added tab item
                tabDynamic.SelectedItem = newTab;
            }
            else
            {
                // your code here...
            }
        }
예제 #4
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string tabName = (sender as Button).CommandParameter.ToString();

            var item = tabDynamic.Items.Cast <TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();

            TabItem tab = item as TabItem;

            if (tab != null)
            {
                if (_tabItems.Count < 3)
                {
                    MessageBox.Show("Cannot remove last tab.");
                }
                else if (MessageBox.Show(string.Format("Are you sure you want to remove notepad {0}?", tab.Header.ToString()),
                                         "Remove Tab", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    TabItem selectedTab = tabDynamic.SelectedItem as TabItem;
                    tabDynamic.DataContext = null;
                    _tabItems.Remove(tab);
                    Notepad.DeletePage(tab.Name);

                    tabDynamic.DataContext = _tabItems;

                    if (selectedTab == null || selectedTab.Equals(tab))
                    {
                        selectedTab = _tabItems[0];
                    }
                    tabDynamic.SelectedItem = selectedTab;
                }
            }
        }
예제 #5
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string  tabName = (sender as Button).CommandParameter.ToString();
            var     item    = tabDynamic.Items.Cast <TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();
            TabItem tab     = item as TabItem;

            if (tab != null)
            {
                if (_tabItems.Count < 2)
                {
                    MessageBox.Show("At least one invoice should be in queue you can’t remove this invoice.");
                }
                else
                if (MessageBox.Show(string.Format("Any Unsaved Data will be loss, Are you sure to close this invoice?"),
                                    "Remove Tab", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    TabItem selectedTab = tabDynamic.SelectedItem as TabItem;
                    tabDynamic.DataContext = null;
                    _tabItems.Remove(tab);
                    tabDynamic.DataContext = _tabItems;
                    // select previously selected tab. if that is removed then select first tab
                    if (selectedTab == null || selectedTab.Equals(tab))
                    {
                        selectedTab = _tabItems[0];
                    }
                    tabDynamic.SelectedItem = selectedTab;
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Fecha o separador de Chat.
        /// <para>Não deixa fechar o separador do "Lobby".</para>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseTabButton_OnClick(object sender, RoutedEventArgs e)
        {
            string tabName = ((Button)sender).CommandParameter.ToString();

            if (tabName == "id0")
            {
                return;                   // Se for o Lobby
            }
            TabItem tab = ChatTabControl.Items.Cast <TabItem>().SingleOrDefault(i => i.Name.Equals(tabName));

            if (tab == null)
            {
                return;
            }
            if (TabItems.Count <= 1)
            {
                return;
            }
            TabItem selectedTabItem = (TabItem)ChatTabControl.SelectedItem;

            ChatTabControl.DataContext = null;
            TabItems.Remove(tab);
            ChatTabControl.DataContext = TabItems;
            if (selectedTabItem == null || selectedTabItem.Equals(tab))
            {
                selectedTabItem = TabItems[0];
            }

            ChatTabControl.SelectedItem = selectedTabItem;
        }
예제 #7
0
        public void CloseButton_Handler(object sender, RoutedEventArgs args)
        {
            string tabName = (sender as Button).CommandParameter.ToString();
            var    item    = tabControl_DynamicTabs.Items.Cast <TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();

            if (item is TabItem)
            {
                if (MessageBox.Show(string.Format("Are you sure you want to remove the tab '{0}'?", item.Header.ToString()), "Remove Tab", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    // Get selected tab
                    TabItem selectedTab = tabControl_DynamicTabs.SelectedItem as TabItem;

                    // Unhook DataContext vector, remove the tab from said vector and hook back the vector to the DataContext property of the control
                    tabControl_DynamicTabs.DataContext = null;
                    tabItems.Remove(item);
                    tabControl_DynamicTabs.DataContext = tabItems;

                    // If the tab closed was the current tab, then select first tab
                    if (selectedTab == null || selectedTab.Equals(item))
                    {
                        selectedTab = tabItems[0];
                    }
                    tabControl_DynamicTabs.SelectedItem = selectedTab;
                }
            }
        }
예제 #8
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            if (button == null)
            {
                return;
            }
            string tabName = button.CommandParameter.ToString();

            var item = tabDynamic.Items.Cast <TabItem>().SingleOrDefault(i => i.Name.Equals(tabName));

            var tab = item;

            if (tab == null)
            {
                return;
            }
            if (_tabItems.Count < 3)
            {
                Close();
            }
            else
            {
                // get selected tab
                TabItem selectedTab = tabDynamic.SelectedItem as TabItem;

                // clear tab control binding
                tabDynamic.DataContext = null;

                //get the index for latter
                var index = _tabItems.IndexOf(selectedTab);
                _tabItems.Remove(tab);

                // bind tab control
                tabDynamic.DataContext = _tabItems;

                // select previously selected tab. if that is removed then select first tab
                if (selectedTab == null || selectedTab.Equals(tab))
                {
                    try
                    {
                        selectedTab = _tabItems[index + 1]; //go to the right?
                    }
                    catch
                    {
                        selectedTab = _tabItems[0];
                    }
                }
                tabDynamic.SelectedItem = selectedTab;
            }
        }
예제 #9
0
        private void DeleteTabItem(string tag)
        {
            var validTags = tabDynamic.Items.Cast <TabItem>().Where(i => ((i.Tag != null) && i.Tag.Equals(tag)));

            if (validTags.Count() > 1)
            {
                throw new Exception("有重名设置!");
            }
            var item = validTags.SingleOrDefault();

            TabItem tab = item as TabItem;

            if (tab != null)
            {
                // get selected tab
                TabItem selectedTab = tabDynamic.SelectedItem as TabItem;

                // clear tab control binding
                tabDynamic.DataContext = null;

                //call dispose for the editor
                UserControl editor = (UserControl)(((Grid)tab.Content).Children[0]);
                if (typeof(IDisposable).IsAssignableFrom(editor.GetType()))
                {
                    ((IDisposable)editor).Dispose();
                }

                // If the editor is a RecipeEditor, unsubscribe its EditWare event
                if (editor is LayoutEditor)
                {
                    LayoutEditor recipeEditor = editor as LayoutEditor;
                    recipeEditor.EditWare -= this.OnLayoutEditorEditWare;
                }

                // Remove the tab
                _tabItems.Remove(tab);

                // bind tab control
                tabDynamic.DataContext = _tabItems;

                // select previously selected tab. if that is removed then select first tab
                if ((selectedTab == null || selectedTab.Equals(tab)) && _tabItems.Count > 0)
                {
                    selectedTab = _tabItems[0];
                }
                tabDynamic.SelectedItem = selectedTab;
            }
        }
예제 #10
0
 /// <summary>
 /// 隐藏搜索页标签
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         TabItem item = (TabItem)tabControl.SelectedItem;
         if (item == null || item.Equals(schTabItem))
         {
             return;
         }
         schTabItem.Visibility = Visibility.Collapsed;
         fileListBox.Items.Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #11
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            string tabName = (sender as Button).CommandParameter.ToString();

            var item = tabDynamic.Items.Cast <TabItem>().Where(i => i.Name.Equals(tabName)).SingleOrDefault();

            TabItem tab = item as TabItem;

            if (tab != null)
            {
                if (MessageBox.Show(string.Format("Are you sure you want to remove the tab '{0}'?", tab.Header.ToString()),
                                    "Remove Tab", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    // get selected tab
                    TabItem selectedTab = tabDynamic.SelectedItem as TabItem;

                    _tabItems.Remove(tab);

                    if (_tabItems.Count > 0)
                    {
                        // clear tab control binding
                        tabDynamic.Items.Clear();
                        foreach (var tabItem in _tabItems)
                        {
                            tabDynamic.Items.Add(tabItem);
                        }

                        // select previously selected tab. if that is removed then select first tab
                        if (selectedTab == null || selectedTab.Equals(tab))
                        {
                            selectedTab = _tabItems[0];
                        }
                        tabDynamic.SelectedItem = selectedTab;
                    }
                    else
                    {
                        tabDynamic.Items.Clear();
                    }
                }
            }
        }
예제 #12
0
        private void tabDynamic_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TabItem tab = tabDynamic.SelectedItem as TabItem;

            if (tab == null)
            {
                return;
            }

            if (tab.Equals(_tabAdd))
            {
                tabDynamic.DataContext = null;
                TabItem newTab = this.AddTabItem();
                tabDynamic.DataContext  = _tabItems;
                tabDynamic.SelectedItem = newTab;
            }
            else
            {
                // your code here...
            }
        }
예제 #13
0
        public bool SwapTabItems(TabItem source, TabItem target)
        {
            if (source == null || target == null)
            {
                return(false);
            }

            if (!target.Equals(source))
            {
                var tabControl = target.Parent as TabControl;
                int sourceIdx  = tabControl.Items.IndexOf(source);
                int targetIdx  = tabControl.Items.IndexOf(target);

                tabControl.Items.Remove(source);
                tabControl.Items.Insert(targetIdx, source);

                tabControl.SelectedIndex = targetIdx;
                return(true);
            }
            return(false);
        }
예제 #14
0
        private void DropTab(object sender, System.Windows.DragEventArgs e)
        {
            TabItem tabItem = e.Source as TabItem;

            if (tabItem != null)
            {
                TabItem tabItem2 = e.Data.GetData(typeof(TabItem)) as TabItem;
                if (tabItem2 != null)
                {
                    if (!tabItem.Equals(tabItem2))
                    {
                        TabControl tabControl  = tabItem.Parent as TabControl;
                        int        insertIndex = tabControl.Items.IndexOf(tabItem2);
                        int        num         = tabControl.Items.IndexOf(tabItem);
                        tabControl.Items.Remove(tabItem2);
                        tabControl.Items.Insert(num, tabItem2);
                        tabControl.Items.Remove(tabItem);
                        tabControl.Items.Insert(insertIndex, tabItem);
                        tabControl.SelectedIndex = num;
                    }
                    return;
                }
            }
        }
예제 #15
0
        private void FakeTab(Point drahPosition)
        {
            TabItem replaceItem = null;

            foreach (TabItem tab in Items)
            {
                Rect tabRect = TabItemRect(tab);
                if (tabRect.Contains(drahPosition))
                {
                    replaceItem = tab;
                    break;
                }
            }
            if (replaceItem != null)
            {
                TabberItem tabberItem = replaceItem as TabberItem;
                if (tabberItem != null && !tabberItem.Pin && (oldReplaceItem == null || !oldReplaceItem.Equals(replaceItem)))
                {
                    oldReplaceItem = replaceItem;
                    int shadowIndex = shadowItem != null?Items.IndexOf(shadowItem) : -1;

                    if (shadowItem == null)
                    {
                        shadowItem        = new ShadowTabberItem();
                        shadowItem.Header = new string(' ', 24);
                    }
                    int replaceItemIndex = Items.IndexOf(replaceItem);

                    if (shadowIndex > -1 && shadowIndex < replaceItemIndex)
                    {
                        Items.Remove(replaceItem);
                        Items.Insert(shadowIndex, replaceItem);
                    }
                    else
                    {
                        Items.Remove(shadowItem);
                        Items.Insert(replaceItemIndex, shadowItem);
                    }
                    shadowItem.IsSelected = true;
                }
            }
            else if ((Items[Items.Count - 1] as ShadowTabberItem) == null)
            {
                if (shadowItem == null)
                {
                    shadowItem        = new ShadowTabberItem();
                    shadowItem.Header = new string(' ', 24);
                    Items.Add(shadowItem);
                }
                else
                {
                    Items.Remove(shadowItem);
                    Items.Add(shadowItem);
                }
                oldReplaceItem        = null;
                shadowItem.IsSelected = true;
            }
        }
 /// <summary>
 /// Checks if tabItem is add-item.
 /// </summary>
 /// <param name="tabItem"></param>
 /// <returns></returns>
 public bool IsAddTabItem(TabItem tabItem)
 {
     return(tabItem.Equals(_addTabItem));
 }