Пример #1
0
        protected override void OnInitialized(EventArgs e)
        {
            // ListView should never be null.
            classListView = WpfUtilities.FindUpVisualTree <ListView>(this);
            collection    = classListView.ItemsSource as ObservableCollection <ISearchEntryViewModel>;
            collection.Add(new ClassInformationViewModel());
            classListView.SelectionChanged += OnClassViewSelectionChanged;

            this.KeyDown += OnLibraryWrapPanelKeyDown;

            base.OnInitialized(e);
        }
Пример #2
0
        private CustomPopupPlacement[] PlacementCallback(Size popup, Size target, Point offset)
        {
            // http://stackoverflow.com/questions/1918877/how-can-i-get-the-dpi-in-wpf
            // MAGN 7397 Library tooltip popup is offset over library items on highres monitors (retina and >96 dpi)
            //Youtrack http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-7397
            PresentationSource source  = PresentationSource.FromVisual(this);
            double             xfactor = 1.0;

            if (source != null)
            {
                xfactor = source.CompositionTarget.TransformToDevice.M11;
            }

            double gap          = Configurations.ToolTipTargetGapInPixels;
            var    dynamoWindow = WpfUtilities.FindUpVisualTree <DynamoView>(this.PlacementTarget);

            if (dynamoWindow == null)
            {
                SetDataContext(null, true);
                return(null);
            }
            Point targetLocation = this.PlacementTarget
                                   .TransformToAncestor(dynamoWindow)
                                   .Transform(new Point(0, 0));

            // Count width.
            // multiplying by xfactor scales the placement point of the library UI tooltip to the correct location
            //otherwise direct pixel coordinates are off by this factor due to screen dpi.
            double x = 0;

            x = (WpfUtilities.FindUpVisualTree <SearchView>(this.PlacementTarget).ActualWidth
                 + gap * 2 + targetLocation.X * (-1)) * xfactor;

            // Count height.
            var availableHeight = dynamoWindow.ActualHeight - popup.Height
                                  - (targetLocation.Y + Configurations.NodeButtonHeight);

            double y = 0;

            if (availableHeight < Configurations.BottomPanelHeight)
            {
                y = availableHeight - (Configurations.BottomPanelHeight + gap * 4);
            }

            return(new CustomPopupPlacement[]
            {
                new CustomPopupPlacement()
                {
                    Point = new Point(x, y),
                    PrimaryAxis = PopupPrimaryAxis.Horizontal
                }
            });
        }
Пример #3
0
        private Size ComputeSmallContentSize()
        {
            var maxSize = new Size()
            {
                Width  = Configurations.MaxCondensedPreviewWidth,
                Height = Configurations.MaxCondensedPreviewHeight
            };

            smallContentGrid.Measure(maxSize);
            Size smallContentGridSize = smallContentGrid.DesiredSize;

            // Condensed bubble should be the same width as node or wider.
            if (smallContentGridSize.Width == 0)
            {
                var nodeView = WpfUtilities.FindUpVisualTree <NodeView>(this);
                if (nodeView != null)
                {
                    smallContentGridSize.Width = nodeView.ActualWidth;
                }
            }

            // Count children size.
            var childrenSize = new Size()
            {
                Width = 0, Height = 0
            };

            foreach (UIElement child in smallContentGrid.Children)
            {
                child.Measure(maxSize);

                childrenSize.Width += child.DesiredSize.Width;
                if (child.DesiredSize.Height > childrenSize.Height)
                {
                    childrenSize.Height = child.DesiredSize.Height;
                }
            }

            // If children are smaller, update smallContentGridSize.
            if (childrenSize.Height < smallContentGridSize.Height)
            {
                smallContentGridSize.Height = childrenSize.Height;
            }
            if (childrenSize.Width < smallContentGridSize.Width)
            {
                // But don't make it smaller, then min width.
                smallContentGridSize.Width = childrenSize.Width < smallContentGrid.MinWidth
                    ? smallContentGrid.MinWidth
                    : childrenSize.Width;
            }
            // Add padding since we are sizing the centralizedGrid.
            return(ContentToControlSize(smallContentGridSize));
        }
Пример #4
0
        private void InitializeOnce()
        {
            var workspaceView = WpfUtilities.FindUpVisualTree <WorkspaceView>(this);

            if (workspaceView == null)
            {
                throw new InvalidOperationException(
                          "InfiniteGridView should be a nested element of WorkspaceView");
            }

            workspaceModel = workspaceView.ViewModel.Model;
        }
Пример #5
0
        // We should load main window after Popup has been initialized.
        // If we try to load it before, we will get null.
        private void LoadMainDynamoWindow(object sender, RoutedEventArgs e)
        {
            mainDynamoWindow = WpfUtilities.FindUpVisualTree <DynamoView>(this);
            if (mainDynamoWindow == null)
            {
                return;
            }

            // When Dynamo window goes behind another app, the tool-tip should be hidden right
            // away. We cannot use CloseLibraryToolTipPopup because it only hides the tool-tip
            // window after a pause.
            mainDynamoWindow.Deactivated += (Sender, args) =>
            {
                this.DataContext = null;
                IsOpen           = false;
            };
        }
Пример #6
0
        public FunctionNamePrompt(IEnumerable <string> categories)
        {
            InitializeComponent();

            Owner = WpfUtilities.FindUpVisualTree <DynamoView>(this);
            WindowStartupLocation = WindowStartupLocation.CenterOwner;

            nameBox.Focus();

            var sortedCats = categories.ToList();

            sortedCats.Sort();

            foreach (var item in sortedCats)
            {
                categoryBox.Items.Add(item);
            }
        }
Пример #7
0
        public SearchView(SearchViewModel searchViewModel, DynamoViewModel dynamoViewModel)
        {
            viewModel            = searchViewModel;
            this.dynamoViewModel = dynamoViewModel;

            InitializeComponent();
            Loaded   += OnSearchViewLoaded;
            Unloaded += OnSearchViewUnloaded;

            SearchTextBox.IsVisibleChanged += delegate
            {
                if (SearchTextBox.IsVisible)
                {
                    this.viewModel.SearchCommand.Execute(null);
                    Keyboard.Focus(this.SearchTextBox);
                    var view = WpfUtilities.FindUpVisualTree <DynamoView>(this);
                    SearchTextBox.InputBindings.AddRange(view.InputBindings);
                }
            };
        }
Пример #8
0
        /// <summary>
        /// Construct a ModelessChildWindow.
        /// </summary>
        /// <param name="viewParent">A UI object in the Dynamo visual tree.</param>
        /// <param name="rect">A reference to the Rect object that will store the window's position during this session.</param>
        public ModelessChildWindow(DependencyObject viewParent, ref WindowRect rect)
        {
            Owner          = WpfUtilities.FindUpVisualTree <DynamoView>(viewParent);
            Owner.Closing += OwnerWindow_Closing;

            if (rect == null || !IsRectVisibleOnScreen(rect, Owner))
            {
                rect = new WindowRect();
                WindowStartupLocation = WindowStartupLocation.CenterOwner;

                LocationChanged += ModelessChildWindow_LocationChanged;
                SizeChanged     += ModelessChildWindow_SizeChanged;
            }
            else
            {
                WindowStartupLocation = WindowStartupLocation.Manual;
                Loaded += ModelessChildWindow_Loaded;
            }

            SavedWindowRect = rect;
        }
Пример #9
0
        public InCanvasSearchControl()
        {
            InitializeComponent();

            this.Loaded += (sender, e) =>
            {
                if (workspaceView == null)
                {
                    workspaceView = WpfUtilities.FindUpVisualTree <WorkspaceView>(this.Parent);
                }
                if (dynamoView == null)
                {
                    dynamoView = WpfUtilities.FindUpVisualTree <DynamoView>(this.Parent);
                    if (dynamoView != null)
                    {
                        dynamoView.Deactivated += (s, args) => { OnRequestShowInCanvasSearch(ShowHideFlags.Hide); }
                    }
                    ;
                }
            };
        }
Пример #10
0
        private CustomPopupPlacement[] PlacementCallback(Size popup, Size target, Point offset)
        {
            double gap          = Configurations.ToolTipTargetGapInPixels;
            var    dynamoWindow = WpfUtilities.FindUpVisualTree <DynamoView>(this.PlacementTarget);

            if (dynamoWindow == null)
            {
                SetDataContext(null, true);
                return(null);
            }
            Point targetLocation = this.PlacementTarget
                                   .TransformToAncestor(dynamoWindow)
                                   .Transform(new Point(0, 0));

            // Count width.
            double x = 0;

            x = WpfUtilities.FindUpVisualTree <SearchView>(this.PlacementTarget).ActualWidth
                + gap * 2 + targetLocation.X * (-1);

            // Count height.
            var availableHeight = dynamoWindow.ActualHeight - popup.Height
                                  - (targetLocation.Y + Configurations.NodeButtonHeight);

            double y = 0;

            if (availableHeight < Configurations.BottomPanelHeight)
            {
                y = availableHeight - (Configurations.BottomPanelHeight + gap * 4);
            }

            return(new CustomPopupPlacement[]
            {
                new CustomPopupPlacement()
                {
                    Point = new Point(x, y),
                    PrimaryAxis = PopupPrimaryAxis.Horizontal
                }
            });
        }
Пример #11
0
        private void OnTreeViewItemPreviewMouseLeftButton(object sender, MouseButtonEventArgs e)
        {
            var categoryButton = sender as TreeViewItem;

            if (!(categoryButton.DataContext is RootNodeCategoryViewModel))
            {
                return;
            }

            var wrapPanels = categoryButton.ChildrenOfType <LibraryWrapPanel>();

            if (!wrapPanels.Any())
            {
                return;
            }

            var selectedElement = e.OriginalSource as FrameworkElement;
            var selectedClass   = selectedElement.DataContext as NodeCategoryViewModel;

            // Continue work with real class: not null, not ClassInformationViewModel.
            if (selectedClass == null || selectedClass is ClassInformationViewModel)
            {
                return;
            }

            // Go through all available for current top category LibraryWrapPanel.
            // Select class if wrapPanel contains selectedClass.
            // Unselect class in other case.
            foreach (var wrapPanel in wrapPanels)
            {
                if (wrapPanel.MakeOrClearSelection(selectedClass))
                {
                    // If class button was clicked, then handle, otherwise leave it.
                    e.Handled = selectedClass.IsClassButton;

                    var classInfoPanel = wrapPanel.Children.Cast <FrameworkElement>().
                                         Where(child => child.DataContext is ClassInformationViewModel).FirstOrDefault();

                    classInfoPanel.Loaded += (send, handler) =>
                    {
                        // This call is made whenever a class button is clicked on to expand the class
                        // information (right after the corresponding "ClassInformationView" view is created).
                        // "selectedElement" here can either be the TextBlock or Image on the class button.
                        //
                        // Required height is calculated by adding class button and "ClassInformationView" heights.
                        // If the required height is larger than the visible library height, then the class
                        // button is placed on the top of library, with the rest of the space occupied by the
                        // "ClassInformationView".

                        var selectedClassButton = WpfUtilities.FindUpVisualTree <Border>(selectedElement);
                        var height = classInfoPanel.RenderSize.Height + selectedClassButton.RenderSize.Height;
                        if (height > ScrollLibraryViewer.ActualHeight)
                        {
                            selectedClassButton.BringIntoView(new Rect(0, 0, 0, ScrollLibraryViewer.ActualHeight));
                        }
                        else
                        {
                            // If the class button is already visible on the library, simply bring the
                            // "ClassInformationView" into view. Otherwise, the class button is brought into view.
                            if (IsElementVisible(selectedClassButton, ScrollLibraryViewer))
                            {
                                classInfoPanel.BringIntoView();
                            }
                            else
                            {
                                selectedClassButton.BringIntoView();
                            }
                        }
                    };
                }
            }

            ExpandCategory(categoryButton.Items.OfType <NodeCategoryViewModel>(), selectedClass);

            e.Handled = !(selectedClass is RootNodeCategoryViewModel);
        }
Пример #12
0
        /// <summary>
        /// Construct a ModelessChildWindow.
        /// </summary>
        /// <param name="viewParent">A UI object in the Dynamo visual tree.</param>
        /// <param name="rect">A reference to the Rect object that will store the window's position during this session.</param>
        public ModelessChildWindow(DependencyObject viewParent, ref WindowRect rect)
        {
            Owner = WpfUtilities.FindUpVisualTree <DynamoView>(viewParent);

            rect = InitWindowRect(rect);
        }
Пример #13
0
 /// <summary>
 /// Construct a ModelessChildWindow.
 /// </summary>
 /// <param name="viewParent">A UI object in the Dynamo visual tree.</param>
 public ModelessChildWindow(DependencyObject viewParent)
 {
     Owner = WpfUtilities.FindUpVisualTree <DynamoView>(viewParent);
     WindowStartupLocation = WindowStartupLocation.CenterOwner;
     Owner.Closing        += OwnerWindow_Closing;
 }
Пример #14
0
        void NotificationsControl_Loaded(object sender, RoutedEventArgs e)
        {
            var window = WpfUtilities.FindUpVisualTree <DynamoView>(this);

            window.PreviewMouseDown += window_PreviewMouseDown;
        }