Esempio n. 1
0
        protected override Size MeasureOverride(Size availableSize)
        {
            this.currentTabWidth = CalculateTabWidth(availableSize);
            ParentTabControl.SetCanAddTab(this.currentTabWidth > this.MinTabWidth);

            if (hideAddButton)
            {
                this.addButton.Visibility = System.Windows.Visibility.Hidden;
            }
            else if (ParentTabControl.IsAddButtonVisible)
            {
                this.addButton.Visibility = this.currentTabWidth > this.MinTabWidth ? Visibility.Visible : Visibility.Collapsed;
            }
            else
            {
                this.addButton.Visibility = System.Windows.Visibility.Collapsed;
            }

            double height     = double.IsPositiveInfinity(availableSize.Height) ? this.defaultMeasureHeight : availableSize.Height;
            Size   resultSize = new Size(0, availableSize.Height);

            foreach (UIElement child in this.Children)
            {
                ChromeTabItem item    = ItemsControl.ContainerFromElement(this.ParentTabControl, child) as ChromeTabItem;
                Size          tabSize = new Size(GetWidthForTabItem(item), height - item.Margin.Bottom);
                child.Measure(tabSize);
                resultSize.Width += child.DesiredSize.Width - Overlap;
            }
            if (ParentTabControl.IsAddButtonVisible)
            {
                this.addButton.Measure(this.addButtonSize);
                resultSize.Width += this.addButtonSize.Width;
            }
            return(resultSize);
        }
Esempio n. 2
0
        private void Reanimate(ChromeTabItem tab, double left, double duration, Action completed)
        {
            if (tab == null)
            {
                return;
            }
            Thickness          offset            = new Thickness(left, 0, -left, 0);
            ThicknessAnimation moveBackAnimation = new ThicknessAnimation(tab.Margin, offset, new Duration(TimeSpan.FromSeconds(duration)));

            Storyboard.SetTarget(moveBackAnimation, tab);
            Storyboard.SetTargetProperty(moveBackAnimation, new PropertyPath(FrameworkElement.MarginProperty));
            Storyboard sb = new Storyboard();

            sb.Children.Add(moveBackAnimation);
            sb.FillBehavior = FillBehavior.Stop;
            sb.AutoReverse  = false;
            sb.Completed   += (o, ea) =>
            {
                sb.Remove();
                if (completed != null)
                {
                    completed();
                }
            };
            sb.Begin();
        }
Esempio n. 3
0
        public void RemoveTab(object tab)
        {
            int           selectedIndex      = this.SelectedIndex;
            bool          removedSelectedTab = false;
            ChromeTabItem removeItem         = this.AsTabItem(tab);

            foreach (object item in this.Items)
            {
                ChromeTabItem tabItem = this.AsTabItem(item);
                if (tabItem != null && tabItem == removeItem)
                {
                    if (tabItem.Content == this.SelectedContent)
                    {
                        removedSelectedTab = true;
                    }
                    if (this.ObjectToContainer.ContainsKey(tab))
                    {
                        this.ObjectToContainer.Remove(tab);
                    }
                    this.Items.Remove(item);
                    break;
                }
            }
            if (removedSelectedTab && this.Items.Count > 0)
            {
                this.SelectedItem = this.Items[Math.Min(selectedIndex, this.Items.Count - 1)];
            }
            else if (removedSelectedTab)
            {
                this.SelectedItem    = null;
                this.SelectedContent = null;
            }
        }
Esempio n. 4
0
        internal void MoveTab(int fromIndex, int toIndex)
        {
            if (this.Items.Count == 0 || fromIndex == toIndex || fromIndex >= this.Items.Count)
            {
                return;
            }
            object        fromTab  = this.Items[fromIndex];
            object        toTab    = this.Items[toIndex];
            ChromeTabItem fromItem = AsTabItem(fromTab);
            ChromeTabItem toItem   = AsTabItem(toTab);

            if (fromItem.IsPinned && !toItem.IsPinned)
            {
                return;
            }
            if (!fromItem.IsPinned && toItem.IsPinned)
            {
                return;
            }
            if (this.ReorderTabsCommand != null)
            {
                this.ReorderTabsCommand.Execute(new TabReorder(fromIndex, toIndex));
            }

            for (int i = 0; i < this.Items.Count; i += 1)
            {
                var v = this.AsTabItem(this.Items[i]);
                v.Margin = new Thickness(0);
            }
            this.SelectedItem = fromTab;
        }
Esempio n. 5
0
        /// <summary>
        /// Grabs hold of the tab based on the input viewmodel and positions it at the mouse cursor.
        /// </summary>
        /// <param name="viewModel"></param>
        public void GrabTab(object viewModel)
        {
            ChromeTabPanel p    = (ChromeTabPanel)ItemsHost;
            ChromeTabItem  item = AsTabItem(viewModel);

            p.StartTabDrag(item, true);
        }
 private double GetWidthForTabItem(ChromeTabItem tab)
 {
     if (tab.IsPinned)
     {
         return(this.PinnedTabWidth);
     }
     return(this.currentTabWidth);
 }
        public void RemoveTab(object tab)
        {
            ChromeTabItem removeItem = this.AsTabItem(tab);

            if (CloseTabCommand != null)
            {
                CloseTabCommand.Execute(removeItem.DataContext);
            }
        }
Esempio n. 8
0
        internal void PinTab(object tab)
        {
            ChromeTabItem removeItem = this.AsTabItem(tab);

            if (PinTabCommand != null)
            {
                PinTabCommand.Execute(removeItem.DataContext);
            }
        }
Esempio n. 9
0
        private static void StickyReanimate(ChromeTabItem tab, double left, double duration)
        {
            Action completed = () =>
            {
                tab.Margin = new Thickness(left, 0, -left, 0);
            };

            Reanimate(tab, left, duration, completed);
        }
Esempio n. 10
0
        protected void SetSelectedContent(bool removeContent)
        {
            if (removeContent)
            {
                if (this.SelectedItem == null)
                {
                    if (this.Items.Count > 0)
                    {
                        if (_lastSelectedItem != null)
                        {
                            this.SelectedItem = _lastSelectedItem;
                        }
                        else
                        {
                            this.SelectedItem = this.Items[0];
                        }
                    }
                    else
                    {
                        this.SelectedItem    = null;
                        this.SelectedContent = null;
                    }
                }
                return;
            }

            if (this.SelectedIndex > 0)
            {
                this._lastSelectedItem = this.Items[this.SelectedIndex - 1];
            }
            else if (this.SelectedIndex == 0 && this.Items.Count > 1)
            {
                this._lastSelectedItem = this.Items[this.SelectedIndex + 1];
            }
            else
            {
                this._lastSelectedItem = null;
            }

            ChromeTabItem item = this.AsTabItem(this.SelectedItem);

            if (TabPersistBehavior != TabPersistBehavior.None)
            {
                if (item != null && itemsHolder != null)
                {
                    CreateChildContentPresenter(this.SelectedItem);
                    // show the right child
                    foreach (ContentPresenter child in itemsHolder.Children)
                    {
                        ChromeTabItem childTabItem = AsTabItem(child.Content);
                        child.Visibility = childTabItem.IsSelected ? Visibility.Visible : Visibility.Collapsed;
                    }
                }
            }

            this.SelectedContent = item != null ? item.Content : null;
        }
Esempio n. 11
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            var tab = new ChromeTabItem();

            if (this.SelectedTabBrush != null)
            {
                tab.SelectedTabBrush = this.SelectedTabBrush;
            }
            return(tab);
        }
Esempio n. 12
0
        private static void HandleCloseTabCommand(object sender, ExecutedRoutedEventArgs args)
        {
            ChromeTabItem item = sender as ChromeTabItem;

            if (item == null)
            {
                return;
            }
            item.Close();
        }
Esempio n. 13
0
        private static void HandleCloseTabCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ChromeTabItem item = sender as ChromeTabItem;

            if (item == null)
            {
                return;
            }
            item.ParentTabControl.RemoveTab(item);
        }
Esempio n. 14
0
        private static void SelectedTabBrushPropertyCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ChromeTabControl ctc = (ChromeTabControl)d;
            ChromeTabItem    cti = ctc.AsTabItem(ctc.SelectedItem);

            if (cti != null && e.NewValue != null && ctc.SelectedItem != null)
            {
                cti.SelectedTabBrush = (Brush)e.NewValue;
            }
        }
Esempio n. 15
0
        private ChromeTabItem AsTabItem(object item)
        {
            ChromeTabItem tabItem = item as ChromeTabItem;

            if (tabItem == null && item != null && this.ObjectToContainer.ContainsKey(item))
            {
                tabItem = this.ObjectToContainer[item] as ChromeTabItem;
            }
            return(tabItem);
        }
Esempio n. 16
0
        private static void HandlePinTabCommand(object sender, ExecutedRoutedEventArgs e)
        {
            ChromeTabItem item = sender as ChromeTabItem;

            if (item == null)
            {
                return;
            }
            item.ParentTabControl.PinTab(item.DataContext);
        }
Esempio n. 17
0
        protected override DependencyObject GetContainerForItemOverride()
        {
            ChromeTabItem item = null;

            item = new ChromeTabItem {
                Header = "New Tab"
            };
            //item.TabItemHaveClosedHandler = this.TabHaveClosedHandler;

            return(item);
        }
Esempio n. 18
0
        internal void ChangeSelectedIndex(int index)
        {
            //  int index = this.GetTabIndex(item);
            if (Items.Count <= index)
            {
                return;
            }
            ChromeTabItem item = AsTabItem(Items[index]);

            ChangeSelectedItem(item);
        }
Esempio n. 19
0
 internal int GetTabIndex(ChromeTabItem item)
 {
     for (int i = 0; i < this.Items.Count; i += 1)
     {
         ChromeTabItem tabItem = this.AsTabItem(this.Items[i]);
         if (tabItem == item)
         {
             return(i);
         }
     }
     return(-1);
 }
Esempio n. 20
0
        private void StickyReanimate(ChromeTabItem tab, double left, double duration)
        {
            Action completed = () =>
            {
                if (this.draggedTab != null)
                {
                    tab.Margin = new Thickness(left, 0, -left, 0);
                }
            };

            Reanimate(tab, left, duration, completed);
        }
Esempio n. 21
0
        internal void ChangeSelectedItem(ChromeTabItem item)
        {
            int index = this.GetTabIndex(item);

            if (index > -1)
            {
                if (this.SelectedItem != null)
                {
                    Canvas.SetZIndex(this.AsTabItem(this.SelectedItem), 0);
                }
                this.SelectedIndex = index;
                Canvas.SetZIndex(item, 1001);
            }
        }
Esempio n. 22
0
        internal void RemoveFromItemHolder(ChromeTabItem item)
        {
            if (itemsHolder == null)
            {
                return;
            }
            ContentPresenter presenter = FindChildContentPresenter(item);

            if (presenter != null)
            {
                itemsHolder.Children.Remove(presenter);
                Debug.WriteLine("Removing cached ContentPresenter");
            }
        }
Esempio n. 23
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);
            bool somethingSelected = false;

            foreach (UIElement element in this.Items)
            {
                somethingSelected |= ChromeTabItem.GetIsSelected(element);
            }
            if (!somethingSelected)
            {
                this.SelectedIndex = 0;
            }
            KeyboardNavigation.SetIsTabStop(this, false);
        }
Esempio n. 24
0
        protected void SetInitialSelection()
        {
            bool?somethingSelected = null;

            foreach (object element in this.Items)
            {
                if (element is DependencyObject)
                {
                    somethingSelected |= ChromeTabItem.GetIsSelected((DependencyObject)element);
                }
            }
            if (somethingSelected.HasValue && somethingSelected.Value == false)
            {
                this.SelectedIndex = 0;
            }
        }
Esempio n. 25
0
 private void SetTabItemsOnTabs()
 {
     for (int i = 0; i < this.Children.Count; i += 1)
     {
         DependencyObject depObj = this.Children[i] as DependencyObject;
         if (depObj == null)
         {
             continue;
         }
         ChromeTabItem item = ItemsControl.ContainerFromElement(this.ParentTabControl, depObj) as ChromeTabItem;
         if (item != null)
         {
             KeyboardNavigation.SetTabIndex(item, i);
         }
     }
 }
Esempio n. 26
0
        private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
        {
            ChromeTabItem tabItem = (ChromeTabItem)d;

            if (tabItem.ParentTabControl != null && tabItem.ParentTabControl.TabPersistBehavior == TabPersistBehavior.Timed)
            {
                if ((bool)args.NewValue == true)
                {
                    tabItem.StoptPersistTimer();
                }
                else
                {
                    tabItem.StartPersistTimer();
                }
            }
        }
        internal void StartTabDrag(ChromeTabItem tab = null, bool isTabGrab = false)
        {
            Point downPoint = MouseUtilities.CorrectGetPosition(this);

            if (tab != null)
            {
                this.UpdateLayout();
                double xPos = ((this.currentTabWidth - overlap) * tab.Index) + (this.currentTabWidth / 2);
                this.downPoint = new Point(xPos, downPoint.Y);
            }
            else
            {
                this.downPoint = downPoint;
            }

            StartTabDrag(downPoint, tab, isTabGrab);
        }
Esempio n. 28
0
        protected override void OnSelectionChanged(SelectionChangedEventArgs e)
        {
            base.OnSelectionChanged(e);
            this.SetChildrenZ();


            if (e.AddedItems.Count == 0)
            {
                if (this.SelectedItem == null)
                {
                    if (this.Items.Count > 0)
                    {
                        if (_lastSelectedItem != null)
                        {
                            this.SelectedItem = _lastSelectedItem;
                        }
                        else
                        {
                            this.SelectedItem = this.Items[0];
                        }
                    }
                    else
                    {
                        this.SelectedItem    = null;
                        this.SelectedContent = null;
                    }
                }
                return;
            }

            if (this.SelectedIndex > 0)
            {
                this._lastSelectedItem = this.Items[this.SelectedIndex - 1];
            }
            else if (this.SelectedIndex == 0 && this.Items.Count > 1)
            {
                this._lastSelectedItem = this.Items[this.SelectedIndex + 1];
            }
            else
            {
                this._lastSelectedItem = null;
            }
            ChromeTabItem item = this.AsTabItem(this.SelectedItem);

            this.SelectedContent = item != null ? item.Content : null;
        }
Esempio n. 29
0
        private object GenerateNewItem()
        {
            object itemToAdd = new Button { Content = "Moo " + this.newTabNumber };
            Interlocked.Increment(ref this.newTabNumber);
            if(this.title.Text.Length > 0)
            {
                itemToAdd = new ChromeTabs.ChromeTabItem
                {
                    Header = this.title.Text,
                    Content = itemToAdd
                };
                var x = (ChromeTabItem) itemToAdd;
                x.TabItemClosing += XTabItemClosing;

            }
            return itemToAdd;
        }
Esempio n. 30
0
        public void ChangeSelectedItem(ChromeTabItem item)
        {
            if (this.TabHaveSelectedHandler != null)
            {
                this.TabHaveSelectedHandler(item);
            }
            int index = this.GetTabIndex(item);

            if (index > -1)
            {
                if (this.SelectedItem != null)
                {
                    Canvas.SetZIndex(this.AsTabItem(this.SelectedItem), 0);
                }
                this.SelectedIndex = index;
                Canvas.SetZIndex(item, 1001);
            }
        }
Esempio n. 31
0
        internal void MoveTab(int fromIndex, int toIndex)
        {
            if (this.Items.Count == 0 || fromIndex == toIndex || fromIndex >= this.Items.Count)
            {
                return;
            }
            object        fromTab  = this.Items[fromIndex];
            object        toTab    = this.Items[toIndex];
            ChromeTabItem fromItem = AsTabItem(fromTab);
            ChromeTabItem toItem   = AsTabItem(toTab);

            if (fromItem.IsPinned && !toItem.IsPinned)
            {
                return;
            }
            if (!fromItem.IsPinned && toItem.IsPinned)
            {
                return;
            }
            if (this.ReorderTabsCommand != null)
            {
                this.ReorderTabsCommand.Execute(new TabReorder(fromIndex, toIndex));
            }
            else
            {
                var sourceType = ItemsSource.GetType();
                if (sourceType.IsGenericType)
                {
                    var sourceDefinition = sourceType.GetGenericTypeDefinition();
                    if (sourceDefinition == typeof(ObservableCollection <>))
                    {
                        var method = sourceType.GetMethod("Move");
                        method.Invoke(ItemsSource, new object[] { fromIndex, toIndex });
                    }
                }
            }

            for (int i = 0; i < this.Items.Count; i += 1)
            {
                var v = this.AsTabItem(this.Items[i]);
                v.Margin = new Thickness(0);
            }
            this.SelectedItem = fromTab;
        }
 public void NewTabHaveCreated(ChromeTabItem item)
 {
     //判断是否存在该解决方案
     //暂时无法判断该item是新建还是移动
     foreach(var sol in HeatSource.HeatSourceLayoutApp.solutions)
     {
         if(sol.TabItem == item)
         {
             return;
         }
     }
     item.CanDelete = true;
     item.TabItemHaveClosedHandler = this.TabHaveClosed;
     Solution s = new Solution(true);
     s.SolutionName = (String)item.Header;
     ObjectId objectid = Utility.ContainLayer(s.SolutionName);
     if (objectid == ObjectId.Null)
         s.BaseObjectId = HeatSource.Utils.Utility.CreateLayer(s.SolutionName);
     else
         s.BaseObjectId = objectid;
     s.TabItem = item;
     s.SId = Solution.NextDefaultSId();
     HeatSource.HeatSourceLayoutApp.solutions.Add(s);
 }
 protected override DependencyObject GetContainerForItemOverride()
 {
     var tab = new ChromeTabItem();
     if (this.SelectedTabBrush != null)
         tab.SelectedTabBrush = this.SelectedTabBrush;
     return tab;
 }
 internal int GetTabIndex(ChromeTabItem item)
 {
     for (int i = 0; i < this.Items.Count; i += 1)
     {
         ChromeTabItem tabItem = this.AsTabItem(this.Items[i]);
         if (tabItem == item)
         {
             return i;
         }
     }
     return -1;
 }
 internal void ChangeSelectedItem(ChromeTabItem item)
 {
     int index = this.GetTabIndex(item);
     if (index != this.SelectedIndex)
     {
         if (index > -1)
         {
             if (this.SelectedItem != null)
             {
                 Canvas.SetZIndex(this.AsTabItem(this.SelectedItem), 0);
             }
             this.SelectedIndex = index;
             Canvas.SetZIndex(item, 1001);
         }
     }
 }
Esempio n. 36
0
        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonUp(e);
            if (this.addButtonRect.Contains(e.GetPosition(this)) && this.addButton.Background == Brushes.DarkGray)
            {
                this.addButton.Background = null;
                this.InvalidateVisual();
                ParentTabControl.AddTab(new Label(), true); // HACK: Do something with default templates, here.
                return;
            }

            ParentTabControl.ChangeSelectedItem(draggedTab);
            draggedTab = null;
        }
 private double GetWidthForTabItem(ChromeTabItem tab)
 {
     if (tab.IsPinned)
     {
         return this.PinnedTabWidth;
     }
     return this.currentTabWidth;
 }
        private void OnTabRelease(Point p, bool closeTabOnRelease, double animationDuration = _stickyReanimateDuration)
        {
            lock (_lockObject)
            {
                this.draggingWindow = false;
                if (ParentTabControl.IsAddButtonVisible)
                {
                    if (this.addButtonRect.Contains(p) && this.addButton.Background == Brushes.DarkGray)
                    {
                        this.addButton.Background = null;
                        this.InvalidateVisual();
                        if (this.addButton.Visibility == Visibility.Visible)
                        {
                            ParentTabControl.AddTab();
                        }
                        return;
                    }

                }
                if (this.IsMouseCaptured)
                {

                    this.ReleaseMouseCapture();
                    double offset = 0;
                    if (this.slideIntervals != null)
                    {
                        if (this.slideIndex < this.originalIndex + 1)
                        {
                            offset = this.slideIntervals[this.slideIndex + 1] - 2 * this.currentTabWidth / 3 + this.overlap;
                        }
                        else if (this.slideIndex > this.originalIndex + 1)
                        {
                            offset = this.slideIntervals[this.slideIndex - 1] + 2 * this.currentTabWidth / 3 - this.overlap;
                        }
                    }
                    Action completed = () =>
                    {
                        if (this.draggedTab != null)
                        {
                            ParentTabControl.ChangeSelectedItem(this.draggedTab);
                            object vm = this.draggedTab.Content;
                            this.draggedTab.Margin = new Thickness(offset, 0, -offset, 0);
                            this.draggedTab = null;
                            this.captureGuard = 0;
                            ParentTabControl.MoveTab(this.originalIndex, this.slideIndex - 1);
                            this.slideIntervals = null;
                            this.addButton.Visibility = System.Windows.Visibility.Visible;
                            _hideAddButton = false;
                            this.InvalidateVisual();
                            if (closeTabOnRelease && ParentTabControl.CloseTabCommand != null)
                            {
                                Debug.WriteLine("sendt close tab command");
                                ParentTabControl.CloseTabCommand.Execute(vm);
                            }
                            if (this.Children.Count > 1)
                            {
                                //this fixes a bug where sometimes tabs got stuck in the wrong position.
                                RealignAllTabs();
                            }
                        }
                    };

                    Reanimate(this.draggedTab, offset, animationDuration, completed);

                }
                else
                {
                    if (this.draggedTab != null)
                    {
                        ParentTabControl.ChangeSelectedItem(this.draggedTab);
                        this.draggedTab.Margin = new Thickness(0);
                    }
                    this.draggedTab = null;
                    this.captureGuard = 0;
                    this.slideIntervals = null;
                }
            }
        }
Esempio n. 39
0
 private static void StickyReanimate(ChromeTabItem tab, double left, double duration)
 {
     Action completed = () =>
     {
         tab.Margin = new Thickness(left, 0, -left, 0);
     };
     Reanimate(tab, left, duration, completed);
 }
        public void TabHaveSelected(ChromeTabItem item)
        {
            if(currentItemHeader.CompareTo((string)(item.Header)) == 0)
            {
                return;
            }
            else
            {
                currentItemHeader = (string)item.Header;
            }
            //取消命令
            Application.DocumentManager.MdiActiveDocument.SendStringToExecute("\x1B", true, false, false);
            Utility.makeImageBottom();

            //先设置下clayer
            if (item.Name.CompareTo("OutlineLayer") == 0)
            {
                Utility.ResetCLayer(HeatSource.HeatSourceLayoutApp.globalProperty.BaseObjectId);
                HeatSource.HeatSourceLayoutApp.globalProperty.ActiveTab = -1;
            }
            else if (item.Name.CompareTo("OriginLayer") == 0)
            {
                HeatSource.Utils.Utility.ActiveOriginLayer();
                HeatSource.HeatSourceLayoutApp.globalProperty.ActiveTab = -1;
            }
            else
            {
                foreach (var sol in HeatSource.HeatSourceLayoutApp.solutions)
                {
                    if(sol.TabItem.Header.ToString().CompareTo(item.Header.ToString()) == 0 && sol.TabItem != item)
                    {
                        sol.TabItem = item;
                        sol.TabItem.CanDelete = true;
                    }
                    if (sol.TabItem == item)
                    {
                        Utility.ResetCLayer(sol.BaseObjectId);
                        HeatSource.HeatSourceLayoutApp.globalProperty.ActiveTab = sol.SId;
                    }
                }
            }
            //关闭其他图层
            if (item.Name.CompareTo("OutlineLayer") == 0)
            {
                HeatSource.HeatSourceLayoutApp.currentSolution = null;
                ObjectId layerId = HeatSource.HeatSourceLayoutApp.globalProperty.BaseObjectId;
                HeatSource.Utils.Utility.OpenOrCloseLayer(layerId, false);
            }
            else if (item.Name.CompareTo("OriginLayer") == 0)
            {
                HeatSource.HeatSourceLayoutApp.currentSolution = null;
                ObjectId layerId = HeatSource.HeatSourceLayoutApp.globalProperty.BaseObjectId;
                HeatSource.Utils.Utility.OpenOrCloseLayer(layerId, true);
            }
            else
            {
                ObjectId layerId = HeatSource.HeatSourceLayoutApp.globalProperty.BaseObjectId;
                HeatSource.Utils.Utility.OpenOrCloseLayer(layerId, false);
            }
            foreach(var sol in HeatSource.HeatSourceLayoutApp.solutions)
            {
                if(sol.TabItem == item)
                {
                    HeatSource.HeatSourceLayoutApp.currentSolution = sol;
                    //改变圈选的情况
                    HeatSource.View.ToolPanel.changeSolution(sol.SId - 1);
                    Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("选择了" + sol.SId.ToString()+"\n");

                }
                else
                {
                    HeatSource.Utils.Utility.OpenOrCloseLayer(sol.BaseObjectId, true);
                }
            }
            //
            List<ObjectId> ids = new List<ObjectId>();
            ids.Add(HeatSourceLayoutApp.globalProperty.BaseObjectId);
            foreach (var sol in HeatSourceLayoutApp.solutions)
            {
                ids.Add(sol.BaseObjectId);
            }
            CoreLayerUtilities.RegenLayers(ids.ToArray(), 0);
            //Autodesk.AutoCAD.DatabaseServices.ObjectId] layers, int regenPending);
            //Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.Regen();
            //Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.UpdateScreen();
        }
 public void AddCloseHandler(ChromeTabItem item)
 {
     item.TabItemHaveClosedHandler = this.TabHaveClosed;
 }
Esempio n. 42
0
 internal void ChangeSelectedItem(ChromeTabItem item)
 {
     for (int i = 0; i < this.Items.Count; i += 1)
     {
         object dep = this.Items[i];
         ChromeTabItem tabItem = this.AsTabItem(dep);
         if (tabItem == item)
         {
             this.SelectedIndex = i;
             return;
         }
     }
 }
 public void NewTabWillCreated(ChromeTabItem item)
 {
     item.Header = HeatSource.Model.Solution.NextDefaultName();
 }
        internal void StartTabDrag(ChromeTabItem tab = null, bool isTabGrab = false)
        {
            Point downPoint = MouseUtilities.CorrectGetPosition(this);
            if (tab != null)
            {
                this.UpdateLayout();
                double xPos = ((this.currentTabWidth - overlap) * tab.Index) + (this.currentTabWidth / 2);
                this.downPoint = new Point(xPos, downPoint.Y);
            }
            else
                this.downPoint = downPoint;

            StartTabDrag(downPoint, tab, isTabGrab);
        }
        internal void StartTabDrag(Point p, ChromeTabItem tab = null, bool isTabGrab = false)
        {
            this._lastMouseDown = DateTime.UtcNow;
            if (tab == null)
            {
                HitTestResult result = VisualTreeHelper.HitTest(this, this.downPoint);
                if (result == null) { return; }
                DependencyObject source = result.VisualHit;
                while (source != null && !this.Children.Contains(source as UIElement))
                {
                    source = VisualTreeHelper.GetParent(source);
                }
                if (source == null)
                {
                    //The mouse is not over a tab item, so just return.
                    return;
                }
                this.draggedTab = source as ChromeTabItem;
            }
            else if (tab != null)
                this.draggedTab = tab;
            else
            {
                return;
            }

            if (this.draggedTab != null)
            {
                if (this.Children.Count == 1
                    && ParentTabControl.DragWindowWithOneTab
                    && Mouse.LeftButton == MouseButtonState.Pressed
                    && !isTabGrab)
                {

                    this.draggingWindow = true;
                    Window.GetWindow(this).DragMove();
                }
                else
                {
                    this.downTabBoundsPoint = MouseUtilities.CorrectGetPosition(this.draggedTab);
                    Canvas.SetZIndex(this.draggedTab, 1000);
                    ParentTabControl.ChangeSelectedItem(this.draggedTab);
                    if (isTabGrab)
                    {
                        for (int i = 0; i < this.Children.Count; i++)
                        {
                            ProcessMouseMove(new Point(p.X + 0.1, p.Y));
                        }
                    }
                    else
                        ProcessMouseMove(new Point(p.X + 0.1, p.Y));
                }

            }
        }
        protected override DependencyObject GetContainerForItemOverride()
        {
            ChromeTabItem item = null;

            item = new ChromeTabItem { Header = "New Tab" };
            //item.TabItemHaveClosedHandler = this.TabHaveClosedHandler;

            return item;
        }
        private void StickyReanimate(ChromeTabItem tab, double left, double duration)
        {
            Action completed = () =>
            {
                if (this.draggedTab != null)
                {
                    tab.Margin = new Thickness(left, 0, -left, 0);
                }
            };

            Reanimate(tab, left, duration, completed);
        }
 public void ChangeSelectedItem(ChromeTabItem item)
 {
     if(this.TabHaveSelectedHandler != null)
     {
         this.TabHaveSelectedHandler(item);
     }
     int index = this.GetTabIndex(item);
     if(index > -1)
     {
         if(this.SelectedItem != null)
         {
             Canvas.SetZIndex(this.AsTabItem(this.SelectedItem), 0);
         }
         this.SelectedIndex = index;
         Canvas.SetZIndex(item, 1001);
     }
 }
Esempio n. 49
0
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);
            if (this.addButtonRect.Contains(e.GetPosition(this)))
            {
                this.addButton.Background = Brushes.DarkGray;
                this.InvalidateVisual();
                return;
            }

            this.downPoint = e.GetPosition(this);
            HitTestResult result = VisualTreeHelper.HitTest(this, this.downPoint);
            if (result == null) { return; }
            DependencyObject source = result.VisualHit;
            while (source != null && !this.Children.Contains(source as UIElement))
            {
                source = VisualTreeHelper.GetParent(source);
            }
            if (source == null) { return; }
            draggedTab = source as ChromeTabItem;
        }
Esempio n. 50
0
        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonUp(e);
            this.draggingWindow = false;
            if(this.addButtonRect.Contains(e.GetPosition(this)) && this.addButton.Background == Brushes.DarkGray)
            {
                this.addButton.Background = null;
                this.InvalidateVisual();
                if(this.addButton.Visibility == Visibility.Visible)
                {
                    ParentTabControl.AddTab(new Label(), true); // HACK: Do something with default templates, here.
                }
                return;
            }
            if(this.IsMouseCaptured)
            {
                Mouse.Capture(null);

                double offset = 0;
                if(this.slideIndex < this.originalIndex + 1)
                {
                    offset = this.slideIntervals[this.slideIndex + 1] - 2 * this.currentTabWidth / 3 + this.overlap;
                }
                else if(this.slideIndex > this.originalIndex + 1)
                {
                    offset = this.slideIntervals[this.slideIndex - 1] + 2 * this.currentTabWidth / 3 - this.overlap;
                }
                Console.WriteLine(offset);
                Action completed = () =>
                {
                    if(this.draggedTab != null)
                    {
                        ParentTabControl.ChangeSelectedItem(this.draggedTab);
                        this.draggedTab.Margin = new Thickness(offset, 0, -offset, 0);
                        this.draggedTab = null;
                        this.captureGuard = 0;
                        ParentTabControl.MoveTab(this.originalIndex, this.slideIndex - 1);
                    }
                };
                Reanimate(this.draggedTab, offset, .1, completed);
            }
            else
            {
                if(this.draggedTab != null)
                {
                    ParentTabControl.ChangeSelectedItem(this.draggedTab);
                    this.draggedTab.Margin = new Thickness(0);
                }
                this.draggedTab = null;
                this.captureGuard = 0;
            }
        }
Esempio n. 51
0
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);
            this.slideIntervals = null;
            if(this.addButtonRect.Contains(e.GetPosition(this)))
            {
                this.addButton.Background = Brushes.DarkGray;
                this.InvalidateVisual();
                return;
            }

            this.downPoint = e.GetPosition(this);
            HitTestResult result = VisualTreeHelper.HitTest(this, this.downPoint);
            if(result == null) { return; }
            DependencyObject source = result.VisualHit;
            while(source != null && !this.Children.Contains(source as UIElement))
            {
                source = VisualTreeHelper.GetParent(source);
            }
            if(source == null) { return; }
            draggedTab = source as ChromeTabItem;
            if(draggedTab != null && this.Children.Count > 1)
            {
                Canvas.SetZIndex(draggedTab, 1000);
            }
            else if(draggedTab != null && this.Children.Count == 1)
            {
                this.draggingWindow = true;
                Window.GetWindow(this).DragMove();
            }
        }
        public void TabHaveClosed(ChromeTabItem item)
        {
            Solution deleteSol = null;
            Solution lastSol = null;
            Solution nextSol = null;
            ChromeTabItem selItm = null;
            int index = 0;
            foreach (var sol in HeatSource.HeatSourceLayoutApp.solutions)
            {
                if(sol.TabItem == item)
                {
                    deleteSol = sol;
                    if(index < HeatSourceLayoutApp.solutions.Count - 1)
                    {
                        nextSol = HeatSourceLayoutApp.solutions[index + 1];
                    }
                    break;
                }
                lastSol = sol;
                index++;
            }
            if(lastSol != null)
            {
                selItm = lastSol.TabItem;
            }
            else if(nextSol != null)
            {
                selItm = nextSol.TabItem;
            }
            else
            {
                selItm = OutlineLayer;
            }

            if(deleteSol != null)
            {
                //select layer
                TabHaveSelected(selItm);
                //remove entity
                deleteSol.RemoveSelf();
                //delete layer
                Utility.RemoveLayer(deleteSol.BaseObjectId);

            }
        }
        internal void StartTabDrag(Point p, ChromeTabItem tab = null, bool isTabGrab = false)
        {
            this._lastMouseDown = DateTime.UtcNow;
            if (tab == null)
            {
                tab = GetTabFromMousePosition(this.downPoint);
            }

            if (tab != null)
                this.draggedTab = tab;
            else
            {
                //The mouse is not over a tab item, so just return.
                return;
            }

            if (this.draggedTab != null)
            {
                if (this.Children.Count == 1
                    && ParentTabControl.DragWindowWithOneTab
                    && Mouse.LeftButton == MouseButtonState.Pressed
                    && !isTabGrab)
                {

                    this.draggingWindow = true;
                    Window.GetWindow(this).DragMove();
                }
                else
                {
                    this.downTabBoundsPoint = MouseUtilities.CorrectGetPosition(this.draggedTab);
                    Canvas.SetZIndex(this.draggedTab, 1000);
                    ParentTabControl.ChangeSelectedItem(this.draggedTab);
                    if (isTabGrab)
                    {
                        for (int i = 0; i < this.Children.Count; i++)
                        {
                            ProcessMouseMove(new Point(p.X + 0.1, p.Y));
                        }
                    }
                }

            }
        }
 public ContainerOverrideEventArgs(RoutedEvent routedEvent, object source, object model, ChromeTabItem tabItem) : base(routedEvent, source) { this.Model = model; this.TabItem = tabItem; }
Esempio n. 55
0
 private static void Reanimate(ChromeTabItem tab, double left, double duration, Action completed)
 {
     if(tab == null)
     {
         return;
     }
     Thickness offset = new Thickness(left, 0, -left, 0);
     ThicknessAnimation moveBackAnimation = new ThicknessAnimation(tab.Margin, offset, new Duration(TimeSpan.FromSeconds(duration)));
     Storyboard.SetTarget(moveBackAnimation, tab);
     Storyboard.SetTargetProperty(moveBackAnimation, new PropertyPath(FrameworkElement.MarginProperty));
     Storyboard sb = new Storyboard();
     sb.Children.Add(moveBackAnimation);
     sb.Completed += (o, ea) =>
     {
         sb.Remove();
         if(completed != null)
         {
             completed();
         }
     };
     sb.Begin();
 }
        internal void StartTabDrag(ChromeTabItem tab = null, bool isTabGrab = false)
        {
            Point downPoint = MouseUtilities.CorrectGetPosition(this);
            if (tab != null)
            {
                this.UpdateLayout();
                double totalWidth = 0;
                for (int i = 0; i < tab.Index;i++ )
                {
                    totalWidth +=GetWidthForTabItem(Children[i] as ChromeTabItem)-overlap;
                }
                double xPos = totalWidth + ((GetWidthForTabItem(tab) / 2));
                this.downPoint = new Point(xPos, downPoint.Y);
            }
            else
                this.downPoint = downPoint;

            StartTabDrag(downPoint, tab, isTabGrab);
        }