Exemple #1
0
        TabItem CreateTab(TabData tabData)
        {
            int max =
                tabControlMain.Items
                .OfType <TabItem>( )
                .Where(i => i != tabNew && i.Header is string)
                .Select(i =>
            {
                var m = Regex.Match((string)i.Header, @"^Tab\s*(\d+)$");
                if (m.Success)
                {
                    return(int.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture));
                }
                else
                {
                    return(0);
                }
            })
                .Concat(new[] { 0 })
                .Max( );


            var new_tab_item = new TabItem( );

            //new_tab_item.Header = string.IsNullOrWhiteSpace( tab_data?.Name ) ? $"Tab {max + 1}" : tab_data.Name;
            new_tab_item.Header         = $"Tab {max + 1}";
            new_tab_item.HeaderTemplate = (DataTemplate)tabControlMain.Resources["TabTemplate"];

            var uc_main = new UCMain
            {
                Width  = double.NaN,
                Height = double.NaN
            };

            new_tab_item.Content = uc_main;

            tabControlMain.Items.Insert(tabControlMain.Items.IndexOf(tabNew), new_tab_item);

            if (tabData != null)
            {
                uc_main.ApplyTabData(tabData);
            }

            uc_main.Changed += UCMain_Changed;

            tabControlMain.SelectedItem = new_tab_item;             //?

            return(new_tab_item);
        }
Exemple #2
0
        void DuplicateTab( )
        {
            TabItem new_tab_item = null;
            var     tab_data     = new TabData( );

            UCMain uc_main = GetSingleModeControl( );

            if (uc_main != null)
            {
                uc_main.ExportTabData(tab_data);
                new_tab_item = NewTab(tab_data);
            }
            else
            {
                TabItem selected_tab_item = tabControlMain.IsVisible ? tabControlMain.SelectedItem as TabItem : null;

                if (selected_tab_item != null && selected_tab_item.Content is UCMain)
                {
                    uc_main = (UCMain)selected_tab_item.Content;
                    uc_main.ExportTabData(tab_data);
                    new_tab_item = NewTab(tab_data);

                    if (tabControlMain.Items.IndexOf(new_tab_item) != tabControlMain.Items.IndexOf(selected_tab_item) + 1)
                    {
                        tabControlMain.Items.Remove(new_tab_item);
                        int i = tabControlMain.Items.IndexOf(selected_tab_item);
                        tabControlMain.Items.Insert(i + 1, new_tab_item);
                    }
                }
            }

            if (new_tab_item == null)
            {
                SystemSounds.Beep.Play( );
            }
            else
            {
                tabControlMain.SelectedItem = new_tab_item;

                RenumberTabs( );
            }
        }
Exemple #3
0
        private void tabControlMain_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!IsFullyLoaded)
            {
                return;
            }

            TabItem old_tab_item = e.RemovedItems?.AsQueryable( ).OfType <TabItem>( ).SingleOrDefault( );
            UCMain  old_uc_main  = old_tab_item?.Content as UCMain;

            TabItem new_tab_item = e.AddedItems?.AsQueryable( ).OfType <TabItem>( ).SingleOrDefault( );
            UCMain  new_uc_main  = new_tab_item?.Content as UCMain;

            if (old_uc_main != null &&
                new_uc_main != null)
            {
                var old_metrics = old_uc_main.GetMetrics( );
                new_uc_main.ApplyMetrics(old_metrics);
            }
        }
Exemple #4
0
        void CloseTab(TabItem tabItem)
        {
            var index = tabControlMain.Items.IndexOf(tabItem);

            tabControlMain.SelectedItem = tabItem;

            var r = MessageBox.Show(this, "Remove this tab?", "WARNING",
                                    MessageBoxButton.OKCancel, MessageBoxImage.Exclamation,
                                    MessageBoxResult.OK, MessageBoxOptions.None);

            if (r != MessageBoxResult.OK)
            {
                return;
            }

            UCMain uc_main = (UCMain)tabItem.Content;

            uc_main.Shutdown( );

            tabControlMain.Items.Remove(tabItem);

            if (tabControlMain.Items[index] == tabNew)
            {
                --index;
            }

            if (index < 0)
            {
                CreateTab(null);
                index = 0;
            }

            tabControlMain.SelectedIndex = index;

            RenumberTabs( );

            TrySwitchToSingleMode( );
        }