示例#1
0
        ///<summary>
        ///Raises the <see cref="E:System.Windows.Forms.Control.MouseMove"></see> event.
        ///</summary>
        ///
        ///<param name="e">A <see cref="T:System.Windows.Forms.MouseEventArgs"></see> that contains the event data. </param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            HitTestInfo test = HitTest(e.Location);

            if (test != null && test.Area != HitTestArea.None)
            {
                if (test.Area == HitTestArea.Item && !showing && autoToolTip)
                {
                    showing = true;
                    Point       loc  = new Point(this[test.Index].TextRect.X, this[test.Index].TextRect.Y + this[test.Index].Font.Height);
                    ToolTipData data = new ToolTipData(this[test.Index].ToolTipText, test.Index, loc);
                    GenericCancelEventArgs <ToolTipData> args = new GenericCancelEventArgs <ToolTipData>(data, false);
                    OnBeforeToolTip(args);
                    if (!args.Cancel)
                    {
                        ttMain.Show(args.Value.ToolTipText, this, data.Location);
                    }
                }

                if (test.Area == HitTestArea.Item && this[test.Index].IsLink)
                {
                    Cursor = CursorHelper.NormalCursor;
                }
                else
                {
                    Cursor = Cursors.Default;
                    if (showing && autoToolTip)
                    {
                        ttMain.Hide(this);
                        showing = false;
                    }
                }
            }
        }
示例#2
0
 public ToolTipData(ToolTipData other)
 {
     foreach (KeyValuePair <ToolTipElementID, string> entry in other.toolTipElementsDict)
     {
         toolTipElementsDict.Add(entry.Key, entry.Value);
     }
 }
    public bool SetupToolTip(ToolTipData data)
    {
        ResetToolTip();
        if (!data.HasElement(ToolTipElementID.SmallToolTipText))
        {
            return(false);
        }
        uiElementsDict [ToolTipElementID.SmallToolTipText].textElement.text = data.GetElement(ToolTipElementID.SmallToolTipText);
        uiElementsDict [ToolTipElementID.SmallToolTipText].UpdateElement();

        if (data.HasElement(ToolTipElementID.SmallDescriptionImage))
        {
            //Debug.Log ("ToolTipObjTest::SetupToolTip:Data has small image: "+data.GetElement (ToolTipElementID.SmallDescriptionImage));

            Sprite tempSprite = Resources.Load(data.GetElement(ToolTipElementID.SmallDescriptionImage), typeof(Sprite)) as Sprite;
            //Debug.Log ("ToolTipObjTest::SetupToolTip:small image: "+tempSprite);
            //Debug.Log ("ToolTipObjTest::SetupToolTip:small image size: "+tempSprite.rect.size );
            uiElementsDict [ToolTipElementID.SmallDescriptionImage].imageElement.sprite = tempSprite;
            uiElementsDict [ToolTipElementID.SmallDescriptionImage].UpdateElement();
        }
        if (data.HasElement(ToolTipElementID.DetailedToolTipText))
        {
            uiElementsDict [ToolTipElementID.DetailedToolTipText].textElement.text = data.GetElement(ToolTipElementID.DetailedToolTipText);
            uiElementsDict [ToolTipElementID.DetailedToolTipText].UpdateElement();
        }

        UpdateToolTip();
        return(true);
    }
示例#4
0
 public void ShowToolTip(ToolTipData tooltip)
 {
     toolTipHolder.SetActive(true);
     tooltip.shown = true;
     tooltip.toolTip.LoadToolTip(toolTipNameText, toolTipDescriptionText);
     currentToolTip = tooltip.toolTip;
     StartCoroutine(HideTimer());
 }
    private void ParseToolTipsData()
    {
        string ToolTipID             = "";
        string SmallToolTipText      = "";
        string DetailedToolTipText   = "";
        string SmallDescriptionImage = "";
        string LargeDescriptionImage = "";
        string HelpLinkURL           = "";

        if (xmlDataHandler != null && xmlDataHandler.GetXMLDoc() != null)
        {
            foreach (XmlElement node in xmlDataHandler.GetXMLDoc().SelectNodes("ToolTipsData/ToolTipData"))
            {
                ToolTipData temp = new ToolTipData();

                ToolTipID        = node.GetAttribute("ToolTipID");
                SmallToolTipText = node.SelectSingleNode("SmallToolTipText").InnerText;
                if (!string.IsNullOrEmpty(SmallToolTipText))
                {
                    temp.AddElement(ToolTipElementID.SmallToolTipText, SmallToolTipText);
                    DetailedToolTipText = node.SelectSingleNode("DetailedToolTipText").InnerText;
                    if (!string.IsNullOrEmpty(DetailedToolTipText))
                    {
                        temp.AddElement(ToolTipElementID.DetailedToolTipText, DetailedToolTipText);
                    }
                    SmallDescriptionImage = node.SelectSingleNode("SmallDescriptionImage").InnerText;
                    if (!string.IsNullOrEmpty(SmallDescriptionImage))
                    {
                        temp.AddElement(ToolTipElementID.SmallDescriptionImage, SmallDescriptionImage);
                    }
                    LargeDescriptionImage = node.SelectSingleNode("LargeDescriptionImage").InnerText;
                    if (!string.IsNullOrEmpty(LargeDescriptionImage))
                    {
                        temp.AddElement(ToolTipElementID.LargeDescriptionImage, LargeDescriptionImage);
                    }
                    HelpLinkURL = node.SelectSingleNode("HelpLinkURL").InnerText;
                    if (!string.IsNullOrEmpty(HelpLinkURL))
                    {
                        temp.AddElement(ToolTipElementID.HelpLinkURL, HelpLinkURL);
                    }
                    toolTipIDToDataDict.Add(ToolTipID, temp);
                }
            }

            foreach (KeyValuePair <string, ToolTipData> entry in toolTipIDToDataDict)
            {
                Debug.Log("<color=purple>UIElementsDataManager::ParseToolTipsData:Found ToolTip: " + entry.Key +
                          " \n" + entry.Value.GetElement(ToolTipElementID.SmallToolTipText)
                          + " \n" + entry.Value.GetElement(ToolTipElementID.DetailedToolTipText)
                          + " \n" + entry.Value.GetElement(ToolTipElementID.SmallDescriptionImage)
                          + " \n" + entry.Value.GetElement(ToolTipElementID.LargeDescriptionImage)
                          + " \n" + entry.Value.GetElement(ToolTipElementID.HelpLinkURL) + "</color>");
            }
        }
    }
示例#6
0
        void CreateTip(ToolTipData _Data)
        {
            //find the object on the alert and add the tooltips on top of it
            CToolTip tTT = CAlert.ActiveAlertObject.transform.FindChildRecursive(_Data.CreateOn).gameObject.AddComponent <CToolTip>();

            //reset the data of the Toltip to the data that is stored in .this creation script
            tTT.DataBase = _Data.DataBase; // give string databease
            tTT.ToolTip  = _Data.ToolTip;  // give settings

            //initialize and finalize the ToolTip
            tTT.InitTheToolTip();
        }
    private void InitializeToolTipData()
    {
        // Create a new Tool Tip Data
        // In the actual code this will be passed
        smallTextData    = new ToolTipData("This yqgpj is a small tooltip only");
        detailedTextData = new ToolTipData("This yqgpj is the small tooltip with detailed text",
                                           "This is the large multiline Tool tip Text\n The quick brown fox jumped over the lazy dog");

        smallImageData = new ToolTipData("This yqgpj is the small tooltip text",
                                         "This is the large multiline Tool tip Text\n The quick brown fox jumped over the lazy dog",
                                         "smallImageTestRect64");

        smallTextWithImageData = new ToolTipData("This yqgpj is a small tooltip with image only");
        smallTextWithImageData.AddElement(ToolTipElementID.SmallDescriptionImage, "smallImageTestRect");
    }
 public ToolTipData GetToolTipForUIElement(string _elementID)
 {
     if (!string.IsNullOrEmpty(_elementID))
     {
         string _toolTipID = "";
         uiElementToToolTipIDsDict.TryGetValue(_elementID, out _toolTipID);
         if (!string.IsNullOrEmpty(_toolTipID))
         {
             ToolTipData temp = new ToolTipData();
             toolTipIDToDataDict.TryGetValue(_toolTipID, out temp);
             return(temp);
         }
     }
     return(null);
 }
示例#9
0
        public List <string> PobierzToolTipDlaPola(string nazwaPola, ToolTipData rodzaj = ToolTipData.INFO)
        {
            var    field = _fields.ToList().Find(s => s.Label == nazwaPola);
            string value = "";
            string sATTR = (rodzaj == ToolTipData.ERROR ? "data-errorqtip" : "data-qtip");

            switch (field.Type)
            {
            case FiledTypes.COMBOBOX:
            {
                var tdValueTag = GetTdForValue(nazwaPola);
                var combo      = tdValueTag.FindDescendants <InputTag>();
                if (combo.Count != 1)
                {
                    throw new Exception("To nie jest comboBox");
                }
                value = combo[0].Element[sATTR].ToString();
                break;
            }

            case FiledTypes.TEXTBOX:
            {
                var tdValueTag = GetTdForValue(nazwaPola);
                var texBox     = tdValueTag.FindDescendants <InputTag>();
                if (texBox.Count != 1)
                {
                    throw new Exception("To nie jest textBox");
                }
                value = texBox[0].Element[sATTR].ToString();
                break;
            }

            case FiledTypes.DATEPICKER:
            {
                var tdValueTag = GetTdForValue(nazwaPola);
                var datePick   = tdValueTag.FindDescendants <InputTag>();
                if (datePick.Count != 1)
                {
                    throw new Exception("To nie jest datePicker");
                }
                value = datePick[0].Element[sATTR].ToString();
                break;
            }
            }

            return(GetTooltipFromHtml(value));
        }
示例#10
0
    // Use this for initialization
    void Start()
    {
        toolTipData = new ToolTipData();
        if (smallToolTipText != null && smallToolTipText.Length > 0)
        {
            // populate the tool tip data object manually
            // TODO: This should be editable in the inspector
            toolTipData.AddElement(ToolTipElementID.SmallToolTipText, smallToolTipText);
            if (detailedToolTipText != null && detailedToolTipText.Length > 0)
            {
                toolTipData.AddElement(ToolTipElementID.DetailedToolTipText, detailedToolTipText);
            }
            if (smallToolTipDescriptionImage != null && smallToolTipDescriptionImage.Length > 0)
            {
                toolTipData.AddElement(ToolTipElementID.SmallDescriptionImage, smallToolTipDescriptionImage);
            }
        }

        if (toolTipController == null)
        {
            Debug.LogError("BtnWithData::toolTipController was null, it should never be NULL");
        }
    }
		TooltipInformation CreateTooltip (ToolTipData data, int offset, Ambience ambience)
		{
			ResolveResult result = data.Result;
			var doc = IdeApp.Workbench.ActiveDocument;
			if (doc == null)
				return null;
			try {

				if (result is AliasNamespaceResolveResult) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetAliasedNamespaceTooltip ((AliasNamespaceResolveResult)result);
				}
				
				if (result is AliasTypeResolveResult) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetAliasedTypeTooltip ((AliasTypeResolveResult)result);
				}
				
				if (data.Node is TypeOfExpression) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetTypeOfTooltip ((TypeOfExpression)data.Node, result as TypeOfResolveResult);
				}
				if (data.Node is PrimitiveType && data.Node.Parent is Constraint) {
					var t = (PrimitiveType)data.Node;
					if (t.Keyword == "class" || t.Keyword == "new" || t.Keyword == "struct") {
						var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
						var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
						sig.BreakLineAfterReturnType = false;
						return sig.GetConstraintTooltip (t.Keyword);
					}
					return null;
				}
				if (data.Node is ExternAliasDeclaration) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetExternAliasTooltip ((ExternAliasDeclaration)data.Node, doc.Project as DotNetProject);
				}
				if (result == null && data.Node is CSharpTokenNode) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetKeywordTooltip (data.Node);
				}
				if (data.Node is PrimitiveType && ((PrimitiveType)data.Node).KnownTypeCode == KnownTypeCode.Void) {
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					return sig.GetKeywordTooltip ("void", null);
				}

				if (result is UnknownIdentifierResolveResult) {
					return new TooltipInformation () {
						SignatureMarkup = string.Format ("error CS0103: The name `{0}' does not exist in the current context", ((UnknownIdentifierResolveResult)result).Identifier)
					};
				} else if (result is UnknownMemberResolveResult) {
					var ur = (UnknownMemberResolveResult)result;
					if (ur.TargetType.Kind != TypeKind.Unknown) {
						return new TooltipInformation () {
							SignatureMarkup = string.Format ("error CS0117: `{0}' does not contain a definition for `{1}'", ur.TargetType.FullName, ur.MemberName)
						};
					}
				} else if (result.IsError) {
					return new TooltipInformation () {
						SignatureMarkup = "Unknown resolve error."
					};
				}
				if (result is LocalResolveResult) {
					var lr = (LocalResolveResult)result;
					var tooltipInfo = new TooltipInformation ();
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					tooltipInfo.SignatureMarkup = sig.GetLocalVariableMarkup (lr.Variable);
					return tooltipInfo;
				} else if (result is MethodGroupResolveResult) {
					var mrr = (MethodGroupResolveResult)result;
					var allMethods = new List<IMethod> (mrr.Methods);
					foreach (var l in mrr.GetExtensionMethods ()) {
						allMethods.AddRange (l);
					}
				
					var method = allMethods.FirstOrDefault ();
					if (method != null) {
						return MemberCompletionData.CreateTooltipInformation (
						doc.Compilation,
						doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
						doc.Editor,
						doc.GetFormattingPolicy (),
						method, 
						false);
					}
				} else if (result is CSharpInvocationResolveResult) {
					var member = ((CSharpInvocationResolveResult)result).ReducedMethod ?? (IMethod)((CSharpInvocationResolveResult)result).Member;
					return MemberCompletionData.CreateTooltipInformation (
						doc.Compilation,
						doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
						doc.Editor,
						doc.GetFormattingPolicy (),
						member, 
						false);
				} else if (result is MemberResolveResult) {
					var member = ((MemberResolveResult)result).Member;
					return MemberCompletionData.CreateTooltipInformation (
					doc.Compilation,
					doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
					doc.Editor,
					doc.GetFormattingPolicy (),
					member, 
					false);
				}else if (result is NamespaceResolveResult) {
					var tooltipInfo = new TooltipInformation ();
					var resolver = (doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile).GetResolver (doc.Compilation, doc.Editor.Caret.Location);
					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
					sig.BreakLineAfterReturnType = false;
					try {
						tooltipInfo.SignatureMarkup = sig.GetMarkup (((NamespaceResolveResult)result).Namespace);
					} catch (Exception e) {
						LoggingService.LogError ("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e);
						return new TooltipInformation ();
					}
					return tooltipInfo;
				} else {
					return MemberCompletionData.CreateTooltipInformation (
					doc.Compilation,
					doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile,
					doc.Editor,
					doc.GetFormattingPolicy (),
					result.Type, 
					false);
				}
			} catch (Exception e) {
				LoggingService.LogError ("Error while creating tooltip.", e);
				return null;
			}
		
			return null;
		}
示例#12
0
文件: Main.cs 项目: ztomer/PowerToys
        public List <Result> Query(Query query)
        {
            var results = new List <Result>();

            if (query != null)
            {
                // Search opened workspaces
                _workspacesApi.Workspaces.ForEach(a =>
                {
                    var title = $"{a.FolderName}";

                    var typeWorkspace = a.WorkspaceTypeToString();
                    if (a.TypeWorkspace == TypeWorkspace.Codespaces)
                    {
                        title += $" - {typeWorkspace}";
                    }
                    else if (a.TypeWorkspace != TypeWorkspace.Local)
                    {
                        title += $" - {(a.ExtraInfo != null ? $"{a.ExtraInfo} ({typeWorkspace})" : typeWorkspace)}";
                    }

                    var tooltip = new ToolTipData(title, $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : "")}: {SystemPath.RealPath(a.RelativePath)}");

                    results.Add(new Result
                    {
                        Title       = title,
                        SubTitle    = $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : "")}: {SystemPath.RealPath(a.RelativePath)}",
                        Icon        = a.VSCodeInstance.WorkspaceIcon,
                        ToolTipData = tooltip,
                        Action      = c =>
                        {
                            bool hide;
                            try
                            {
                                var process = new ProcessStartInfo
                                {
                                    FileName        = a.VSCodeInstance.ExecutablePath,
                                    UseShellExecute = true,
                                    Arguments       = $"--folder-uri {a.Path}",
                                    WindowStyle     = ProcessWindowStyle.Hidden
                                };
                                Process.Start(process);

                                hide = true;
                            }
                            catch (Win32Exception)
                            {
                                var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
                                var msg  = "Can't Open this file";
                                _context.API.ShowMsg(name, msg, string.Empty);
                                hide = false;
                            }
                            return(hide);
                        },
                        ContextData = a,
                    });
                });


                // Search opened remote machines
                _machinesApi.Machines.ForEach(a =>
                {
                    var title = $"{a.Host}";

                    if (a.User != null && a.User != String.Empty && a.HostName != null && a.HostName != String.Empty)
                    {
                        title += $" [{a.User}@{a.HostName}]";
                    }

                    var tooltip = new ToolTipData(title, Resources.SSHRemoteMachine);

                    results.Add(new Result
                    {
                        Title       = title,
                        SubTitle    = Resources.SSHRemoteMachine,
                        Icon        = a.VSCodeInstance.RemoteIcon,
                        ToolTipData = tooltip,
                        Action      = c =>
                        {
                            bool hide;
                            try
                            {
                                var process = new ProcessStartInfo()
                                {
                                    FileName        = a.VSCodeInstance.ExecutablePath,
                                    UseShellExecute = true,
                                    Arguments       = $"--new-window --enable-proposed-api ms-vscode-remote.remote-ssh --remote ssh-remote+{((char)34) + a.Host + ((char)34)}",
                                    WindowStyle     = ProcessWindowStyle.Hidden,
                                };
                                Process.Start(process);

                                hide = true;
                            }
                            catch (Win32Exception)
                            {
                                var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
                                var msg  = "Can't Open this file";
                                _context.API.ShowMsg(name, msg, string.Empty);
                                hide = false;
                            }
                            return(hide);
                        },
                        ContextData = a,
                    });
                });
            }

            results.ForEach(x =>
            {
                if (x.Score == 0)
                {
                    x.Score = 100;
                }

                //if is a remote machine give it 12 extra points
                if (x.ContextData is VSCodeRemoteMachine)
                {
                    x.Score = x.Score + (query.Search.Count() * 5);
                }

                //intersect the title with the query
                var intersection = x.Title.ToLower().Intersect(query.Search.ToLower()).Count();
                x.Score          = x.Score - (Convert.ToInt32(((x.Title.Count() - intersection) * 2.5)));
            });

            results = results.OrderBy(x => x.Title).ToList();

            if (query.ActionKeyword == String.Empty || (query.ActionKeyword != String.Empty && query.Search != String.Empty))
            {
                results = results.Where(a => a.Title.ToLower().Contains(query.Search.ToLower())).ToList();
            }

            return(results);
        }
		TooltipInformation CreateTooltip (ToolTipData data, TextEditor editor, DocumentContext doc, int offset, Gdk.ModifierType modifierState)
		{
			bool createFooter = true; //(modifierState & Gdk.ModifierType.Mod1Mask) != 0;
			try {
				TooltipInformation result;
				var sig = new SignatureMarkupCreator (doc, offset);
				sig.BreakLineAfterReturnType = false;
				
				var typeOfExpression = data.Token.Parent as TypeOfExpressionSyntax;
				if (typeOfExpression != null && data.Symbol is ITypeSymbol)
					return sig.GetTypeOfTooltip (typeOfExpression, (ITypeSymbol)data.Symbol);
				
//				var parentKind = data.Token.Parent != null ? data.Token.Parent.Kind () : SyntaxKind.None;
//				switch (parentKind) {
//					case SyntaxKind.ConstructorConstraint:
//					case SyntaxKind.ClassConstraint:
//					case SyntaxKind.StructConstraint:
//						return sig.GetConstraintTooltip (data.Token);
//				}
//
//				if (data.Node is ThisReferenceExpression && result is ThisResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//					sig.BreakLineAfterReturnType = false;
//					
//					return sig.GetKeywordTooltip ("this", data.Node);
//				}
//				
//				if (data.Node is TypeOfExpression) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetTypeOfTooltip ((TypeOfExpression)data.Node, result as TypeOfResolveResult);
//				}
//				if (data.Node is PrimitiveType && data.Node.Parent is Constraint) {
//					var t = (PrimitiveType)data.Node;
//					if (t.Keyword == "class" || t.Keyword == "new" || t.Keyword == "struct") {
//						var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//						var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//						sig.BreakLineAfterReturnType = false;
//						return sig.GetConstraintTooltip (t.Keyword);
//					}
//					return null;
//				}
				result = sig.GetKeywordTooltip (data.Token); 
				if (result != null)
					return result;
				
				if (data.Symbol != null) {
					result = RoslynSymbolCompletionData.CreateTooltipInformation (CancellationToken.None, editor, doc, data.Symbol, false, createFooter).Result;
				}
				
//				if (result == null && parentKind == SyntaxKind.IdentifierName) {
//					if (data.SymbolInfo.CandidateReason == CandidateReason.None) {
//						if (data.Token.Parent.Parent.Kind () == SyntaxKind.SimpleMemberAccessExpression ||
//							data.Token.Parent.Parent.Kind () == SyntaxKind.PointerMemberAccessExpression) {
//							var ma = (MemberAccessExpressionSyntax)data.Token.Parent.Parent;
//							return new TooltipInformation {
//								SignatureMarkup = string.Format ("error CS0117: `{0}' does not contain a definition for `{1}'", ma.Expression, ma.Name)
//							};
//						}
//						return new TooltipInformation {
//							SignatureMarkup = string.Format ("error CS0103: The name `{0}' does not exist in the current context", data.Token)
//						};
//					}
//				}
				
				return result;

//				if (result is AliasNamespaceResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (doc);
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetAliasedNamespaceTooltip ((AliasNamespaceResolveResult)result);
//				}
//				
//				if (result is AliasTypeResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (doc);
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetAliasedTypeTooltip ((AliasTypeResolveResult)result);
//				}
//				
//				
//				if (data.Node is ExternAliasDeclaration) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetExternAliasTooltip ((ExternAliasDeclaration)data.Node, doc.Project as DotNetProject);
//				}
//				if (result is MethodGroupResolveResult) {
//					var mrr = (MethodGroupResolveResult)result;
//					var allMethods = new List<IMethod> (mrr.Methods);
//					foreach (var l in mrr.GetExtensionMethods ()) {
//						allMethods.AddRange (l);
//					}
//				
//					var method = allMethods.FirstOrDefault ();
//					if (method != null) {
////						return MemberCompletionData.CreateTooltipInformation (
////							doc.Compilation,
////							file,
////							doc.Editor,
////							doc.GetFormattingPolicy (),
////							method,
////							false,
////							createFooter);
//					}
//				} else if (result is CSharpInvocationResolveResult) {
//					var invocationResult = (CSharpInvocationResolveResult)result;
//					var member = (IMember)invocationResult.ReducedMethod ?? invocationResult.Member;
////						return MemberCompletionData.CreateTooltipInformation (
////							doc.Compilation,
////							file,
////							doc.Editor,
////							doc.GetFormattingPolicy (),
////							member, 
////							false,
////							createFooter);
//				} else if (result is MemberResolveResult) {
//					var member = ((MemberResolveResult)result).Member;
////					return MemberCompletionData.CreateTooltipInformation (
////						doc.Compilation,
////						file,
////						doc.Editor,
////						doc.GetFormattingPolicy (),
////						member, 
////						false,
////						createFooter);
//				} else {
//					return MemberCompletionData.CreateTooltipInformation (
//						doc.Compilation,
//						file,
//						doc.Editor,
//						doc.GetFormattingPolicy (),
//						result.Type, 
//						false,
//						createFooter);
//				}
			} catch (Exception e) {
				LoggingService.LogError ("Error while creating tooltip.", e);
				return null;
			}
		}
示例#14
0
        TooltipInformation CreateTooltip(ToolTipData data, int offset, Ambience ambience, Gdk.ModifierType modifierState)
        {
            ResolveResult result = data.Result;
            var           doc    = IdeApp.Workbench.ActiveDocument;

            if (doc == null)
            {
                return(null);
            }
            bool createFooter = (modifierState & Gdk.ModifierType.Mod1Mask) != 0;
            var  file         = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile;

            if (file == null)
            {
                return(null);
            }
            try {
                if (result is AliasNamespaceResolveResult)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetAliasedNamespaceTooltip((AliasNamespaceResolveResult)result));
                }

                if (result is AliasTypeResolveResult)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetAliasedTypeTooltip((AliasTypeResolveResult)result));
                }

                if (data.Node is TypeOfExpression)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetTypeOfTooltip((TypeOfExpression)data.Node, result as TypeOfResolveResult));
                }
                if (data.Node is PrimitiveType && data.Node.Parent is Constraint)
                {
                    var t = (PrimitiveType)data.Node;
                    if (t.Keyword == "class" || t.Keyword == "new" || t.Keyword == "struct")
                    {
                        var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                        var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                        sig.BreakLineAfterReturnType = false;
                        return(sig.GetConstraintTooltip(t.Keyword));
                    }
                    return(null);
                }
                if (data.Node is ExternAliasDeclaration)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetExternAliasTooltip((ExternAliasDeclaration)data.Node, doc.Project as DotNetProject));
                }
                if (result == null && data.Node is CSharpTokenNode)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetKeywordTooltip(data.Node));
                }
                if (data.Node is PrimitiveType && ((PrimitiveType)data.Node).KnownTypeCode == KnownTypeCode.Void)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetKeywordTooltip("void", null));
                }
                if (data.Node is NullReferenceExpression)
                {
                    var resolver = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig      = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    return(sig.GetKeywordTooltip("null", null));
                }

                if (result is UnknownIdentifierResolveResult)
                {
                    return(new TooltipInformation()
                    {
                        SignatureMarkup = string.Format("error CS0103: The name `{0}' does not exist in the current context", ((UnknownIdentifierResolveResult)result).Identifier)
                    });
                }
                else if (result is UnknownMemberResolveResult)
                {
                    var ur = (UnknownMemberResolveResult)result;
                    if (ur.TargetType.Kind != TypeKind.Unknown)
                    {
                        return(new TooltipInformation()
                        {
                            SignatureMarkup = string.Format("error CS0117: `{0}' does not contain a definition for `{1}'", ur.TargetType.FullName, ur.MemberName)
                        });
                    }
                }
                else if (result.IsError)
                {
                    return(new TooltipInformation()
                    {
                        SignatureMarkup = "Unknown resolve error."
                    });
                }
                if (result is LocalResolveResult)
                {
                    var lr          = (LocalResolveResult)result;
                    var tooltipInfo = new TooltipInformation();
                    var resolver    = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig         = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    tooltipInfo.SignatureMarkup  = sig.GetLocalVariableMarkup(lr.Variable);
                    return(tooltipInfo);
                }
                else if (result is MethodGroupResolveResult)
                {
                    var mrr        = (MethodGroupResolveResult)result;
                    var allMethods = new List <IMethod> (mrr.Methods);
                    foreach (var l in mrr.GetExtensionMethods())
                    {
                        allMethods.AddRange(l);
                    }

                    var method = allMethods.FirstOrDefault();
                    if (method != null)
                    {
                        return(MemberCompletionData.CreateTooltipInformation(
                                   doc.Compilation,
                                   file,
                                   doc.Editor,
                                   doc.GetFormattingPolicy(),
                                   method,
                                   false,
                                   createFooter));
                    }
                }
                else if (result is CSharpInvocationResolveResult)
                {
                    var invocationResult = (CSharpInvocationResolveResult)result;
                    var member           = (IMember)invocationResult.ReducedMethod ?? invocationResult.Member;
                    return(MemberCompletionData.CreateTooltipInformation(
                               doc.Compilation,
                               file,
                               doc.Editor,
                               doc.GetFormattingPolicy(),
                               member,
                               false,
                               createFooter));
                }
                else if (result is MemberResolveResult)
                {
                    var member = ((MemberResolveResult)result).Member;
                    return(MemberCompletionData.CreateTooltipInformation(
                               doc.Compilation,
                               file,
                               doc.Editor,
                               doc.GetFormattingPolicy(),
                               member,
                               false,
                               createFooter));
                }
                else if (result is NamespaceResolveResult)
                {
                    var tooltipInfo = new TooltipInformation();
                    var resolver    = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig         = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    try {
                        tooltipInfo.SignatureMarkup = sig.GetMarkup(((NamespaceResolveResult)result).Namespace);
                    } catch (Exception e) {
                        LoggingService.LogError("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e);
                        return(new TooltipInformation());
                    }
                    return(tooltipInfo);
                }
                else if (result is OperatorResolveResult)
                {
                    var or          = result as OperatorResolveResult;
                    var tooltipInfo = new TooltipInformation();
                    var resolver    = file.GetResolver(doc.Compilation, doc.Editor.Caret.Location);
                    var sig         = new SignatureMarkupCreator(resolver, doc.GetFormattingPolicy().CreateOptions());
                    sig.BreakLineAfterReturnType = false;
                    try {
                        tooltipInfo.SignatureMarkup = sig.GetMarkup(or.UserDefinedOperatorMethod);
                    } catch (Exception e) {
                        LoggingService.LogError("Got exception while creating markup for :" + ((NamespaceResolveResult)result).Namespace, e);
                        return(new TooltipInformation());
                    }
                    return(tooltipInfo);
                }
                else
                {
                    return(MemberCompletionData.CreateTooltipInformation(
                               doc.Compilation,
                               file,
                               doc.Editor,
                               doc.GetFormattingPolicy(),
                               result.Type,
                               false,
                               createFooter));
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while creating tooltip.", e);
                return(null);
            }

            return(null);
        }
示例#15
0
 public PositionInfoTool(Func <double, double, string> getString)
 {
     _posData   = new ToolTipData(@"Position", "", true);
     _getString = getString;
 }
示例#16
0
        public List <Result> Query(Query query)
        {
            var results = new List <Result>();

            if (query != null)
            {
                // Search opened workspaces
                _workspacesApi.Workspaces.ForEach(a =>
                {
                    var title = a.WorkspaceType == WorkspaceType.ProjectFolder ? a.FolderName : a.FolderName.Replace(".code-workspace", $" ({Resources.Workspace})");

                    var typeWorkspace = a.WorkspaceEnvironmentToString();
                    if (a.WorkspaceEnvironment != WorkspaceEnvironment.Local)
                    {
                        title = $"{title}{(a.ExtraInfo != null ? $" - {a.ExtraInfo}" : string.Empty)} ({typeWorkspace})";
                    }

                    var tooltip = new ToolTipData(title, $"{(a.WorkspaceType == WorkspaceType.WorkspaceFile ? Resources.Workspace : Resources.ProjectFolder)}{(a.WorkspaceEnvironment != WorkspaceEnvironment.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}");

                    results.Add(new Result
                    {
                        Title       = title,
                        SubTitle    = $"{(a.WorkspaceType == WorkspaceType.WorkspaceFile ? Resources.Workspace : Resources.ProjectFolder)}{(a.WorkspaceEnvironment != WorkspaceEnvironment.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}",
                        Icon        = a.VSCodeInstance.WorkspaceIcon,
                        ToolTipData = tooltip,
                        Action      = c =>
                        {
                            bool hide;
                            try
                            {
                                var process = new ProcessStartInfo
                                {
                                    FileName        = a.VSCodeInstance.ExecutablePath,
                                    UseShellExecute = true,
                                    Arguments       = a.WorkspaceType == WorkspaceType.ProjectFolder ? $"--folder-uri {a.Path}" : $"--file-uri {a.Path}",
                                    WindowStyle     = ProcessWindowStyle.Hidden,
                                };
                                Process.Start(process);

                                hide = true;
                            }
                            catch (Win32Exception)
                            {
                                var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
                                var msg  = "Can't Open this file";
                                _context.API.ShowMsg(name, msg, string.Empty);
                                hide = false;
                            }

                            return(hide);
                        },
                        ContextData = a,
                    });
                });

                // Search opened remote machines
                _machinesApi.Machines.ForEach(a =>
                {
                    var title = $"{a.Host}";

                    if (a.User != null && a.User != string.Empty && a.HostName != null && a.HostName != string.Empty)
                    {
                        title += $" [{a.User}@{a.HostName}]";
                    }

                    var tooltip = new ToolTipData(title, Resources.SSHRemoteMachine);

                    results.Add(new Result
                    {
                        Title       = title,
                        SubTitle    = Resources.SSHRemoteMachine,
                        Icon        = a.VSCodeInstance.RemoteIcon,
                        ToolTipData = tooltip,
                        Action      = c =>
                        {
                            bool hide;
                            try
                            {
                                var process = new ProcessStartInfo()
                                {
                                    FileName        = a.VSCodeInstance.ExecutablePath,
                                    UseShellExecute = true,
                                    Arguments       = $"--new-window --enable-proposed-api ms-vscode-remote.remote-ssh --remote ssh-remote+{((char)34) + a.Host + ((char)34)}",
                                    WindowStyle     = ProcessWindowStyle.Hidden,
                                };
                                Process.Start(process);

                                hide = true;
                            }
                            catch (Win32Exception)
                            {
                                var name = $"Plugin: {_context.CurrentPluginMetadata.Name}";
                                var msg  = "Can't Open this file";
                                _context.API.ShowMsg(name, msg, string.Empty);
                                hide = false;
                            }

                            return(hide);
                        },
                        ContextData = a,
                    });
                });
            }

            results = results.Where(a => a.Title.ToLowerInvariant().Contains(query.Search.ToLowerInvariant())).ToList();

            results.ForEach(x =>
            {
                if (x.Score == 0)
                {
                    x.Score = 100;
                }

                // intersect the title with the query
                var intersection        = Convert.ToInt32(x.Title.ToLowerInvariant().Intersect(query.Search.ToLowerInvariant()).Count() * query.Search.Length);
                var differenceWithQuery = Convert.ToInt32((x.Title.Length - intersection) * query.Search.Length * 0.7);
                x.Score = x.Score - differenceWithQuery + intersection;

                // if is a remote machine give it 12 extra points
                if (x.ContextData is VSCodeRemoteMachine)
                {
                    x.Score = Convert.ToInt32(x.Score + (intersection * 2));
                }
            });

            results = results.OrderByDescending(x => x.Score).ToList();
            if (query.Search == string.Empty || query.Search.Replace(" ", string.Empty) == string.Empty)
            {
                results = results.OrderBy(x => x.Title).ToList();
            }

            return(results);
        }
示例#17
0
    // Primarily this function recieves the data from the controller and performs basic validation
    // If we have some valid data then we setup the tool tip object and copy the data
    public bool SetupToolTip(ToolTipData data, ToolTipPlacementData placementToBeUsed)
    {
        //Check if the data object is valid
        if (data == null)
        {
            Debug.LogError("SimpleToolTipObj::Tool Tip Data Validation failed, data was NULL, This should never be null ");
            return(false);
        }

        ////Check if the bare minimum data is present (small tool tip text)
        //if (data.HasElement (ToolTipElementID.SmallToolTipText))
        //{
        //	// if we have the right data copy it to our variables
        //	smallText.text = data.GetElement(ToolTipElementID.SmallToolTipText);
        //	//selectedAnchor = SelectAnchor (anchorToBeUsed, data);
        //	gameObject.transform.position = new Vector3 (posToBeUsed.x, posToBeUsed.y, 0);
        //	//CalculatePosition (posToBeUsed, selectedAnchor);
        //	//CalculateSize ();
        //	return true;
        //}
        //else
        //{
        //	return false;
        //}

        // We dont position the tool tip yet since it will be positioned when it start appearing (after the tipAppearingDelay)
        ResetToolTip();

        // Check if the bare minimum data is present (small tool tip text)
        if (!data.HasElement(ToolTipElementID.SmallToolTipText))
        {
            // cannot setup the tool tip return false
            return(false);
        }
        uiElementsDict [ToolTipElementID.SmallToolTipText].textElement.text = data.GetElement(ToolTipElementID.SmallToolTipText);
        uiElementsDict [ToolTipElementID.SmallToolTipText].UpdateElement();

        if (data.HasElement(ToolTipElementID.SmallDescriptionImage))
        {
            //Debug.Log ("ToolTipObjTest::SetupToolTip:Data has small image: "+data.GetElement (ToolTipElementID.SmallDescriptionImage));

            Sprite tempSprite = Resources.Load(data.GetElement(ToolTipElementID.SmallDescriptionImage), typeof(Sprite)) as Sprite;
            if (tempSprite != null)
            {
                //Debug.Log ("ToolTipObjTest::SetupToolTip:small image: "+tempSprite);
                //Debug.Log ("ToolTipObjTest::SetupToolTip:small image size: "+tempSprite.rect.size );
                uiElementsDict[ToolTipElementID.SmallDescriptionImage].imageElement.sprite = tempSprite;
                uiElementsDict[ToolTipElementID.SmallDescriptionImage].UpdateElement();
            }
            else
            {
                Debug.Log("<color=orange>ToolTipObjTest::SetupToolTip:Could not load image with name: " + data.GetElement(ToolTipElementID.SmallDescriptionImage) + "</color>");
            }
        }
        if (data.HasElement(ToolTipElementID.DetailedToolTipText))
        {
            uiElementsDict [ToolTipElementID.DetailedToolTipText].textElement.text = data.GetElement(ToolTipElementID.DetailedToolTipText);
            uiElementsDict [ToolTipElementID.DetailedToolTipText].UpdateElement();
        }

        UpdateToolTip();
        return(true);
    }
    public void ToolTipNeedsToBeShown(ToolTipData data)
    {
        // TODO: Add a return Status
        // This might return a status based on validation of the data

        // A tool tip can only be setup is it is in the waiting to be called state
        // If it is not in the waiting to be called state, it means that either it has not been
        // initialized yet (case where the mouse pointer is on a button etc right from when the application was
        // launched
        // or it is already trying to show a tool tip somewhere else (Should not be possible in a system where there is
        // only one tool tip obj)
        // In both these cases the object that was trying to setup a tool tip should be notified so that it can act accordingly
        // In the case of initialization scenario we might try to queue it
        // In other scenarios it might be an error (which needs to be handled accordingly)
        // Debug.Log ("ToolTipController::ToolTipNeedsToBeShown:State: "+CurrentState.Name);
        if (CurrentState == WaitingToBeCalled)
        {
            // We were in the right state, lets setup the tooltip
            // First thing that we need to do is to Validate that we have the valid data to show it
            // This means that the position on the screen is valid
            // And we have valid tool tip data
//			if (objOnWhichNeedsToolTip == null)
//			{
//				Debug.LogError ("ToolTipContorller::Obj that wants to show tool tip is NULL, it should never be NULL");
//				return;
//			}


            if (!toolTipObj.SetupToolTip(data, preferredToolTipPlacement))
            {
                Debug.LogError("ToolTipContorller::Invalid Tool Tip Data!");
                return;
            }


            // We need to change the state so that it does not interfere with another call
            UpdateState(WaitingToBeShown);
            //DebugStates ();
        }
        else
        {
            if (CurrentState == WaitingToBeShown || CurrentState == SmallTipAppearing || CurrentState == SmallTipFullyDisplayed ||
                CurrentState == DetailedTipAppearing || CurrentState == DetailedTipFullyDisplayed)
            {
                Debug.Log("ShiftingToolTip: " + data);
                foreach (KeyValuePair <ToolTipElementID, string> entry in data.toolTipElementsDict)
                {
                    Debug.Log("data.Key: " + entry.Key);
                    //toolTipElementsDict.Add(entry.Key, entry.Value);
                }
                dataToUseForShift = data;
                UpdateState(ShiftToolTip);
            }
            else if (CurrentState == WaitingToBeHidden || CurrentState == TipDisappearing)
            {
                // This happens when the user quickly shifts from one UI element to another (or the same)
                // and the disappearing duration is long
                Debug.Log("<color=blue>ToolTipController::Trying to show a tool tip while it was disappearing: " + CurrentState.Name + "</color>");
                animationHelper.StopAnimation(disappearAnimID);
                //if (!toolTipObj.SetupToolTip(data, preferredToolTipPlacement))
                //{
                //    Debug.LogError("ToolTipContorller::Invalid Tool Tip Data!");
                //    return;
                //}


                // We need to change the state so that it does not interfere with another call
                //UpdateState(SmallTipFullyDisplayed);
                dataToUseForShift = data;
                UpdateState(ShiftToolTip);
            }
            else
            {
                // Something unexpected happened. This should not be the case
                // Currently we are just showing a log. Need to handle this situation better
                Debug.LogError("ToolTipController::Trying to show a tool tip when it is not ready, ToolTipController state was: " + CurrentState.Name);
                DebugStates();
            }
        }
    }
示例#19
0
        TooltipInformation CreateTooltip(ToolTipData data, TextEditor editor, DocumentContext doc, int offset, Gdk.ModifierType modifierState)
        {
            bool createFooter = true;             //(modifierState & Gdk.ModifierType.Mod1Mask) != 0;

            try {
                TooltipInformation result;
                var sig = new SignatureMarkupCreator(doc, offset);
                sig.BreakLineAfterReturnType = false;

                var typeOfExpression = data.Token.Parent as TypeOfExpressionSyntax;
                if (typeOfExpression != null && data.Symbol is ITypeSymbol)
                {
                    return(sig.GetTypeOfTooltip(typeOfExpression, (ITypeSymbol)data.Symbol));
                }

//				var parentKind = data.Token.Parent != null ? data.Token.Parent.Kind () : SyntaxKind.None;
//				switch (parentKind) {
//					case SyntaxKind.ConstructorConstraint:
//					case SyntaxKind.ClassConstraint:
//					case SyntaxKind.StructConstraint:
//						return sig.GetConstraintTooltip (data.Token);
//				}
//
//				if (data.Node is ThisReferenceExpression && result is ThisResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//					sig.BreakLineAfterReturnType = false;
//
//					return sig.GetKeywordTooltip ("this", data.Node);
//				}
//
//				if (data.Node is TypeOfExpression) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetTypeOfTooltip ((TypeOfExpression)data.Node, result as TypeOfResolveResult);
//				}
//				if (data.Node is PrimitiveType && data.Node.Parent is Constraint) {
//					var t = (PrimitiveType)data.Node;
//					if (t.Keyword == "class" || t.Keyword == "new" || t.Keyword == "struct") {
//						var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//						var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//						sig.BreakLineAfterReturnType = false;
//						return sig.GetConstraintTooltip (t.Keyword);
//					}
//					return null;
//				}
                result = sig.GetKeywordTooltip(data.Token);
                if (result != null)
                {
                    return(result);
                }

                if (data.Symbol != null)
                {
                    result = RoslynSymbolCompletionData.CreateTooltipInformation(CancellationToken.None, editor, doc, data.Symbol, false, createFooter).Result;
                }

//				if (result == null && parentKind == SyntaxKind.IdentifierName) {
//					if (data.SymbolInfo.CandidateReason == CandidateReason.None) {
//						if (data.Token.Parent.Parent.Kind () == SyntaxKind.SimpleMemberAccessExpression ||
//							data.Token.Parent.Parent.Kind () == SyntaxKind.PointerMemberAccessExpression) {
//							var ma = (MemberAccessExpressionSyntax)data.Token.Parent.Parent;
//							return new TooltipInformation {
//								SignatureMarkup = string.Format ("error CS0117: `{0}' does not contain a definition for `{1}'", ma.Expression, ma.Name)
//							};
//						}
//						return new TooltipInformation {
//							SignatureMarkup = string.Format ("error CS0103: The name `{0}' does not exist in the current context", data.Token)
//						};
//					}
//				}

                return(result);

//				if (result is AliasNamespaceResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (doc);
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetAliasedNamespaceTooltip ((AliasNamespaceResolveResult)result);
//				}
//
//				if (result is AliasTypeResolveResult) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (doc);
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetAliasedTypeTooltip ((AliasTypeResolveResult)result);
//				}
//
//
//				if (data.Node is ExternAliasDeclaration) {
//					var resolver = file.GetResolver (doc.Compilation, doc.Editor.Caret.Location);
//					var sig = new SignatureMarkupCreator (resolver, doc.GetFormattingPolicy ().CreateOptions ());
//					sig.BreakLineAfterReturnType = false;
//					return sig.GetExternAliasTooltip ((ExternAliasDeclaration)data.Node, doc.Project as DotNetProject);
//				}
//				if (result is MethodGroupResolveResult) {
//					var mrr = (MethodGroupResolveResult)result;
//					var allMethods = new List<IMethod> (mrr.Methods);
//					foreach (var l in mrr.GetExtensionMethods ()) {
//						allMethods.AddRange (l);
//					}
//
//					var method = allMethods.FirstOrDefault ();
//					if (method != null) {
////						return MemberCompletionData.CreateTooltipInformation (
////							doc.Compilation,
////							file,
////							doc.Editor,
////							doc.GetFormattingPolicy (),
////							method,
////							false,
////							createFooter);
//					}
//				} else if (result is CSharpInvocationResolveResult) {
//					var invocationResult = (CSharpInvocationResolveResult)result;
//					var member = (IMember)invocationResult.ReducedMethod ?? invocationResult.Member;
////						return MemberCompletionData.CreateTooltipInformation (
////							doc.Compilation,
////							file,
////							doc.Editor,
////							doc.GetFormattingPolicy (),
////							member,
////							false,
////							createFooter);
//				} else if (result is MemberResolveResult) {
//					var member = ((MemberResolveResult)result).Member;
////					return MemberCompletionData.CreateTooltipInformation (
////						doc.Compilation,
////						file,
////						doc.Editor,
////						doc.GetFormattingPolicy (),
////						member,
////						false,
////						createFooter);
//				} else {
//					return MemberCompletionData.CreateTooltipInformation (
//						doc.Compilation,
//						file,
//						doc.Editor,
//						doc.GetFormattingPolicy (),
//						result.Type,
//						false,
//						createFooter);
//				}
            } catch (Exception e) {
                LoggingService.LogError("Error while creating tooltip.", e);
                return(null);
            }
        }
示例#20
0
        /// <summary>
        /// Return a filtered list, based on the given query.
        /// </summary>
        /// <param name="query">The query to filter the list.</param>
        /// <returns>A filtered list, can be empty when nothing was found.</returns>
        public List <Result> Query(Query query)
        {
            if (query?.Search is null)
            {
                return(new List <Result>(0));
            }

            var value = query.Search;

            if (string.IsNullOrEmpty(value))
            {
                return(Emoji.All.Select(GetResult).ToList());
            }

            var emojis = Emoji.Find(value);

            if (emojis.Any())
            {
                return(emojis.Select(GetResult).ToList());
            }

            var results = new List <Result>();

            if (HasAlias(value))
            {
                var result = Emoji.Emojify(value);

                results.Add(
                    new Result
                {
                    QueryTextDisplay = value,
                    IcoPath          = IconPath,
                    Title            = result,
                    SubTitle         = "Replace aliases in text with raw emojis",
                    ToolTipData      = new ToolTipData("Emojify", $"{value}\n{result}"),
                    Action           = _ => CopyToClipboard(result),
                    ContextData      = new EmojifiedString(result),
                });
            }

            if (HasEmoji(value))
            {
                var result = Emoji.Demojify(value);

                results.Add(
                    new Result
                {
                    QueryTextDisplay = value,
                    IcoPath          = IconPath,
                    Title            = result,
                    SubTitle         = "Replace raw emojis in text with aliases",
                    ToolTipData      = new ToolTipData("Demojify", $"{value}\n{result}"),
                    Action           = _ => CopyToClipboard(result),
                    ContextData      = new DemojifiedString(result),
                });
            }

            return(results);

            Result GetResult(GEmoji emoji) => new()
            {
                QueryTextDisplay = value,
                IcoPath          = IconPath,
                Title            = emoji.Raw,
                SubTitle         = string.Join(" ", emoji.Aliases.Select(x => x.PadAlias())),
                ToolTipData      = new ToolTipData("GEmoji", $"Description: {emoji.Description}\nCategory: {emoji.Category}\nTags: {string.Join(", ", emoji.Tags ?? Enumerable.Empty<string>())}\n"),
                Action           = _ => CopyToClipboard(emoji.Raw),
                ContextData      = emoji,
            };

            bool HasAlias(string value)
            {
                return(Regex.IsMatch(value, @":([\w+-]+):", RegexOptions.Compiled));
            }

            bool HasEmoji(string value)
            {
                return(Regex.IsMatch(value, Emoji.RegexPattern, RegexOptions.Compiled));
            }
        }