示例#1
0
        UIElement TryGetToolTipUIElement(CompletionVM completionVM)
        {
            if (completionVM == null)
            {
                return(null);
            }

            var description = completionVM.Completion.Description;

            if (string.IsNullOrEmpty(description))
            {
                return(null);
            }

            var contentType = session.TextView.TextDataModel.ContentType;

            foreach (var provider in completionUIElementProviders)
            {
                if (!contentType.IsOfAnyType(provider.Metadata.ContentTypes))
                {
                    continue;
                }
                var elem = provider.Value.GetUIElement(completionVM.Completion, session, UIElementType.Tooltip);
                if (elem != null)
                {
                    return(elem);
                }
            }

            return(CreateDefaultToolTipUIElement(description));
        }
示例#2
0
        CompletionVM GetExistingCompletionVM(Completion completion)
        {
            if (completion == null)
            {
                return(null);
            }
            var vm = CompletionVM.TryGet(completion);

            Debug.Assert(vm != null);
            return(vm);
        }
示例#3
0
        public FrameworkElement GetSuffix(CompletionVM vm)
        {
            var completion = vm.Completion;

            if (string.IsNullOrEmpty((completion as Completion4)?.Suffix))
            {
                return(null);
            }
            var elem = CreateFrameworkElement(completion, CompletionClassifierKind.Suffix);

            elem.Margin = new Thickness(5, 0, 2, 0);
            return(elem);
        }
示例#4
0
 void HideToolTip()
 {
     if (toolTip == null)
     {
         return;
     }
     toolTip.IsOpen          = false;
     toolTip.Visibility      = Visibility.Collapsed;
     toolTip.Content         = null;
     toolTip.PlacementTarget = null;
     toolTip             = null;
     toolTipCompletionVM = null;
 }
示例#5
0
        void ShowToolTip()
        {
            if (session.IsDismissed)
            {
                return;
            }
            var completionVM = control.completionsListBox.SelectedItem as CompletionVM;

            if (completionVM == toolTipCompletionVM)
            {
                return;
            }
            HideToolTip();
            if (completionVM == null)
            {
                return;
            }
            var container = control.completionsListBox.ItemContainerGenerator.ContainerFromItem(completionVM) as ListBoxItem;

            if (container == null || !container.IsVisible)
            {
                return;
            }
            var toolTipElem = TryGetToolTipUIElement(completionVM);

            if (toolTipElem == null)
            {
                return;
            }

            // When the tooltip was reused, it was empty every other time, so always create a new one.
            toolTip = new ToolTip {
                Placement  = PlacementMode.Right,
                Visibility = Visibility.Collapsed,
                IsOpen     = false,
            };
            toolTip.SetResourceReference(FrameworkElement.StyleProperty, "CompletionToolTipStyle");

            // There's a scrollbar; place the tooltip to the right of the main control and not the ListBoxItem
            var pointRelativeToControl = container.TranslatePoint(new Point(0, 0), control);

            toolTip.VerticalOffset  = pointRelativeToControl.Y;
            toolTip.PlacementTarget = control;
            toolTip.Content         = toolTipElem;
            toolTip.Visibility      = Visibility.Visible;
            Debug.Assert(!toolTip.IsOpen, "Can't set the tool tip's LayoutTransform if it's open");
            PopupHelper.SetScaleTransform(wpfTextView, toolTip);
            toolTipCompletionVM = completionVM;
            toolTip.IsOpen      = true;
        }
示例#6
0
        void CompletionList_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            int i;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                Debug.Assert(e.NewItems != null);
                i = e.NewStartingIndex;
                var newList = new List <CompletionVM>();
                foreach (Completion c in e.NewItems)
                {
                    var vm = GetOrCreateVM(c);
                    newList.Add(vm);
                    list.Insert(i++, vm);
                }
                CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, newList, e.NewStartingIndex));
                break;

            case NotifyCollectionChangedAction.Remove:
                Debug.Assert(e.OldItems != null);
                var oldList = new List <CompletionVM>();
                foreach (Completion c in e.OldItems)
                {
                    var vm = CompletionVM.TryGet(c);
                    oldList.Add(vm);
                    Debug.Assert(list[e.OldStartingIndex].Completion == vm?.Completion);
                    list.RemoveAt(e.OldStartingIndex);
                }
                CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, oldList, e.NewStartingIndex));
                break;

            case NotifyCollectionChangedAction.Replace:
                throw new NotSupportedException();

            case NotifyCollectionChangedAction.Move:
                throw new NotSupportedException();

            case NotifyCollectionChangedAction.Reset:
                ReinitializeList();
                CollectionChanged?.Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
                break;

            default:
                Debug.Fail($"Unknown action: {e.Action}");
                break;
            }
        }
示例#7
0
 CompletionVM GetOrCreateVM(Completion completion) => CompletionVM.TryGet(completion) ?? new CompletionVM(completion, imageMonikerService);
示例#8
0
		public FrameworkElement GetSuffix(CompletionVM vm) {
			var completion = vm.Completion;
			if (string.IsNullOrEmpty((completion as Completion4)?.Suffix))
				return null;
			var elem = CreateFrameworkElement(completion, CompletionClassifierKind.Suffix);
			elem.Margin = new Thickness(5, 0, 2, 0);
			return elem;
		}
示例#9
0
		public FrameworkElement GetDisplayText(CompletionVM vm) => CreateFrameworkElement(vm.Completion, CompletionClassifierKind.DisplayText);
示例#10
0
		void HideToolTip() {
			if (toolTip == null)
				return;
			toolTip.IsOpen = false;
			toolTip.Visibility = Visibility.Collapsed;
			toolTip.Content = null;
			toolTip.PlacementTarget = null;
			toolTip = null;
			toolTipCompletionVM = null;
		}
示例#11
0
		UIElement TryGetToolTipUIElement(CompletionVM completionVM) {
			if (completionVM == null)
				return null;

			var description = completionVM.Completion.Description;
			if (string.IsNullOrEmpty(description))
				return null;

			var contentType = session.TextView.TextDataModel.ContentType;
			foreach (var provider in completionUIElementProviders) {
				if (!contentType.IsOfAnyType(provider.Metadata.ContentTypes))
					continue;
				var elem = provider.Value.GetUIElement(completionVM.Completion, session, UIElementType.Tooltip);
				if (elem != null)
					return elem;
			}

			return CreateDefaultToolTipUIElement(description);
		}
示例#12
0
		void ShowToolTip() {
			if (session.IsDismissed)
				return;
			var completionVM = control.completionsListBox.SelectedItem as CompletionVM;
			if (completionVM == toolTipCompletionVM)
				return;
			HideToolTip();
			if (completionVM == null)
				return;
			var container = control.completionsListBox.ItemContainerGenerator.ContainerFromItem(completionVM) as ListBoxItem;
			if (container == null || !container.IsVisible)
				return;
			var toolTipElem = TryGetToolTipUIElement(completionVM);
			if (toolTipElem == null)
				return;

			// When the tooltip was reused, it was empty every other time, so always create a new one.
			toolTip = new ToolTip {
				Placement = PlacementMode.Right,
				Visibility = Visibility.Collapsed,
				IsOpen = false,
			};
			toolTip.SetResourceReference(FrameworkElement.StyleProperty, "CompletionToolTipStyle");

			// There's a scrollbar; place the tooltip to the right of the main control and not the ListBoxItem
			var pointRelativeToControl = container.TranslatePoint(new Point(0, 0), control);
			toolTip.VerticalOffset = pointRelativeToControl.Y;
			toolTip.PlacementTarget = control;
			toolTip.Content = toolTipElem;
			toolTip.Visibility = Visibility.Visible;
			Debug.Assert(!toolTip.IsOpen, "Can't set the tool tip's LayoutTransform if it's open");
			PopupHelper.SetScaleTransform(wpfTextView, toolTip);
			toolTipCompletionVM = completionVM;
			toolTip.IsOpen = true;
		}
示例#13
0
 public FrameworkElement GetDisplayText(CompletionVM vm) => CreateFrameworkElement(vm.Completion, CompletionClassifierKind.DisplayText);