Beispiel #1
0
        public TabItem MakeTab(string text = "", string title = "New Tab")
        {
            bool       loaded     = false;
            TextEditor textEditor = MakeEditor();

            textEditor.Text = text;
            TextBox tbox = new TextBox
            {
                Text             = title,
                IsEnabled        = false,
                TextWrapping     = TextWrapping.NoWrap,
                IsHitTestVisible = false,
                Style            = (TryFindResource("InvisibleTextBox") as Style)
            };
            TabItem tab = new TabItem
            {
                Content   = textEditor,
                Style     = (TryFindResource("Tab") as Style),
                Header    = tbox,
                AllowDrop = true
            };

            tab.MouseWheel += ScrollTabs;
            tab.Loaded     += delegate
            {
                if (!loaded)
                {
                    tab.GetTemplateChild <Button>("CloseButton").Click += delegate
                    {
                        EditorTabs.Items.Remove(tab);
                    };
                    tabScroller.ScrollToRightEnd();
                    loaded = true;
                }
            };
            tab.MouseDown += delegate(object sender, MouseButtonEventArgs e)
            {
                if (e.OriginalSource is Border)
                {
                    if (e.MiddleButton == MouseButtonState.Pressed)
                    {
                        EditorTabs.Items.Remove(tab);
                    }
                    else if (e.RightButton == MouseButtonState.Pressed)
                    {
                        tabEditWindow.Left = e.GetPosition(null).X - 12.0 + base.Left;
                        tabEditWindow.Top  = e.GetPosition(null).Y - 12.0 + base.Top;
                        tabEditWindow.Show(tab);
                    }
                }
            };
            tab.MouseMove += this.MoveTab;
            tab.Drop      += this.DropTab;
            tbox.GotFocus += delegate
            {
                title           = tbox.Text;
                tbox.CaretIndex = tbox.Text.Length - 1;
            };
            tbox.KeyDown += delegate(object s, System.Windows.Input.KeyEventArgs e)
            {
                switch (e.Key)
                {
                default:
                    return;

                case Key.Escape:
                    tbox.Text = title;
                    break;

                case Key.Return:
                    break;
                }
                tbox.IsEnabled = false;
            };
            tbox.LostFocus += delegate
            {
                tbox.IsEnabled = false;
            };
            EditorTabs.SelectedIndex = EditorTabs.Items.Add(tab);
            return(tab);
        }