示例#1
0
 public void Remove(TextEditor item)
 {
     Items.Remove(item);
     item.Closed();
 }
示例#2
0
        DockPanel GetTabLabel(Tabs tabs, bool tiles, TextEditor item)
        {
            var dockPanel = new DockPanel {
                Margin = new Thickness(0, 0, tiles ? 0 : 2, 1), Tag = item
            };

            var multiBinding = new MultiBinding {
                Converter = new NEExpressionConverter(), ConverterParameter = "p0 o== p2 ? \"CadetBlue\" : (p1 ? \"LightBlue\" : \"LightGray\")"
            };

            multiBinding.Bindings.Add(new Binding {
                Source = item
            });
            multiBinding.Bindings.Add(new Binding(nameof(TextEditor.Active))
            {
                Source = item
            });
            multiBinding.Bindings.Add(new Binding(nameof(TopMost))
            {
                Source = tabs
            });
            dockPanel.SetBinding(DockPanel.BackgroundProperty, multiBinding);

            dockPanel.MouseLeftButtonDown += (s, e) => tabs.TopMost = item;
            dockPanel.MouseMove           += (s, e) =>
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    var active = item.TabsParent.Items.Where(tab => tab.Active).ToList();
                    DragDrop.DoDragDrop(s as DockPanel, new DataObject(typeof(List <TextEditor>), active), DragDropEffects.Move);
                }
            };

            var text = new TextBlock {
                VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 0, 2, 0)
            };

            text.SetBinding(TextBlock.TextProperty, new Binding(nameof(TextEditor.TabLabel))
            {
                Source = item
            });
            dockPanel.Children.Add(text);

            var closeButton = new Button
            {
                Content             = "x",
                BorderThickness     = new Thickness(0),
                Style               = FindResource(ToolBar.ButtonStyleKey) as Style,
                VerticalAlignment   = VerticalAlignment.Center,
                Margin              = new Thickness(2, 0, 5, 0),
                Foreground          = new SolidColorBrush(Color.FromRgb(128, 32, 32)),
                Focusable           = false,
                HorizontalAlignment = HorizontalAlignment.Right,
            };

            closeButton.Click += (s, e) =>
            {
                if (item.CanClose())
                {
                    tabs.Remove(item);
                }
            };
            dockPanel.Children.Add(closeButton);
            return(dockPanel);
        }
示例#3
0
 public bool TabIsActive(TextEditor item) => Items.Where(x => x == item).Select(x => x.Active).DefaultIfEmpty(false).First();