Example #1
0
        public override TooltipItem GetItem(Mono.TextEditor.TextEditor editor, int offset)
        {
            var doc = IdeApp.Workbench.ActiveDocument;

            if (doc == null || doc.ParsedDocument == null)
            {
                return(null);
            }
            var unit = doc.ParsedDocument.GetAst <SyntaxTree> ();

            if (unit == null)
            {
                return(null);
            }

            var file = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile;

            if (file == null)
            {
                return(null);
            }

            ResolveResult result;
            AstNode       node;
            var           loc = editor.OffsetToLocation(offset);

            if (!doc.TryResolveAt(loc, out result, out node))
            {
                if (node is CSharpTokenNode)
                {
                    int startOffset2 = editor.LocationToOffset(node.StartLocation);
                    int endOffset2   = editor.LocationToOffset(node.EndLocation);

                    return(new TooltipItem(new ToolTipData(unit, result, node, null), startOffset2, endOffset2 - startOffset2));
                }
                return(null);
            }
            if (node == lastNode)
            {
                return(lastResult);
            }
            var resolver = new CSharpAstResolver(doc.Compilation, unit, file);

            resolver.ApplyNavigator(new NodeListResolveVisitorNavigator(node), CancellationToken.None);

            var hoverNode = node.GetNodeAt(loc) ?? node;

            int startOffset = editor.LocationToOffset(hoverNode.StartLocation);
            int endOffset   = editor.LocationToOffset(hoverNode.EndLocation);

            return(lastResult = new TooltipItem(new ToolTipData(unit, result, node, resolver), startOffset, endOffset - startOffset));
        }
        void PositionChanged_ITextCaret(CaretLocationEventArgs args)
        {
            //Some unit tests don't initialize full UI representation of MonoTextEditor
            //which means they don't depend on ITextCaret implementation, so we can return here
            //If something is using MonoTextEditor directly(e.g. DiffView) and is not initializing ITextView
            //TextBuffer is null, in that case don't depend on ITextCaret implementation, so we can return here
            if (TextEditor?.TextBuffer == null)
            {
                return;
            }
            // MD doesn't fire textEditor.CaretPositionChanged until after the command has gone completely through the command chain.
            //   Too much VS stuff depends on it getting updated earlier, so we'll use this event which fires earlier.
            int position             = TextEditor.Caret.Offset;
            VirtualSnapshotPoint vsp = new VirtualSnapshotPoint(TextEditor.TextSnapshot, position);

            insertionPoint = vsp;
            if (args.CaretChangeReason == CaretChangeReason.Movement)
            {
                oldCaretLocation = args.Location;
                var oldOffset        = TextEditor.LocationToOffset(args.Location);
                var snapshotPoint    = new SnapshotPoint(TextEditor.TextSnapshot, oldOffset);
                var mappingPoint     = TextEditor.BufferGraph.CreateMappingPoint(snapshotPoint, PointTrackingMode.Positive);
                var oldCaretPosition = new CaretPosition(vsp, mappingPoint, _caretAffinity);
                var eventArgs        = new CaretPositionChangedEventArgs(TextEditor, oldCaretPosition, ((ITextCaret)this).Position);

                ITextCaret_PositionChanged?.Invoke(this, eventArgs);
            }
        }
Example #3
0
        void PositionChanged_ITextCaret(CaretLocationEventArgs args)
        {
            //Some unit tests don't initialize full UI representation of MonoTextEditor
            //which means they don't depend on ITextCaret implementation, so we can return here
            //If something is using MonoTextEditor directly(e.g. DiffView) and is not initializing ITextView
            //TextBuffer is null, in that case don't depend on ITextCaret implementation, so we can return here
            if (TextEditor?.TextBuffer == null)
            {
                return;
            }
            // MD doesn't fire textEditor.CaretPositionChanged until after the command has gone completely through the command chain.
            //   Too much VS stuff depends on it getting updated earlier, so we'll use this event which fires earlier.
            int position             = TextEditor.Caret.Offset;
            VirtualSnapshotPoint vsp = new VirtualSnapshotPoint(TextEditor.TextSnapshot, position);

            insertionPoint = vsp;
            if (args.CaretChangeReason == CaretChangeReason.Movement)
            {
                oldCaretLocation = args.Location;
                var oldOffset        = TextEditor.LocationToOffset(args.Location);
                var snapshotPoint    = new SnapshotPoint(TextEditor.TextSnapshot, oldOffset);
                var mappingPoint     = TextEditor.BufferGraph.CreateMappingPoint(snapshotPoint, PointTrackingMode.Positive);
                var oldCaretPosition = new CaretPosition(vsp, mappingPoint, _caretAffinity);
                var eventArgs        = new CaretPositionChangedEventArgs(TextEditor, oldCaretPosition, ((ITextCaret)this).Position);

                ITextCaret_PositionChanged?.Invoke(this, eventArgs);
            }

            // Synchronize the MultiSelectionBroker with Caret.
            // In VS Editor 15.8 the MultiSelectionBroker is the single source of truth about carets and selections
            // (no selection / single caret, no selection / multiple carets, simple selection, block selection, multiple selections).
            // In our world, we still have our own Caret and Selection, so when our Caret moves, we need to synchronize
            // the MultiSelectionBroker to our values, and when the MultiSelectionBroker changes
            // (e.g. as a result of EditorOperations such as InsertNewLine), we need to synchronize our caret and selection
            // to the MultiSelectionBroker values.
            // Note that EditorOperations only updates the MultiSelectionBroker, it no longer moves caret or selection
            // (since in Editor 15.8 the Caret and Selection are shims implemented in terms of MultiSelectionBroker)
            // TODO: synchronize all our selections as well.
            TextEditorData.Parent.MultiSelectionBroker.PerformActionOnAllSelections(transformer => {
                transformer.MoveTo(vsp, select: false, PositionAffinity.Successor);
            });
        }
		public override TooltipItem GetItem (TextEditor editor, int offset)
		{
			if (offset >= editor.Document.TextLength)
				return null;
			
			if (!DebuggingService.IsDebugging || DebuggingService.IsRunning)
				return null;
				
			StackFrame frame = DebuggingService.CurrentFrame;
			if (frame == null)
				return null;

			var ed = (ExtensibleTextEditor)editor;
			DomRegion expressionRegion;
			string expression = null;
			ResolveResult res;
			int startOffset;

			if (ed.IsSomethingSelected && offset >= ed.SelectionRange.Offset && offset <= ed.SelectionRange.EndOffset) {
				startOffset = ed.SelectionRange.Offset;
				expression = ed.SelectedText;
			} else if ((res = ed.GetLanguageItem (offset, out expressionRegion)) != null && !res.IsError && res.GetType () != typeof (ResolveResult)) {
				if (!TryResolveExpression (editor.GetTextEditorData (), res, expressionRegion, out expression))
					return null;

				startOffset = editor.LocationToOffset (new DocumentLocation (expressionRegion.BeginLine, expressionRegion.BeginColumn));
			} else {
				var data = editor.GetTextEditorData ();
				startOffset = data.FindCurrentWordStart (offset);
				int endOffset = data.FindCurrentWordEnd (offset);

				expression = ed.GetTextBetween (ed.OffsetToLocation (startOffset), ed.OffsetToLocation (endOffset));
			}
			
			if (string.IsNullOrEmpty (expression))
				return null;
			
			ObjectValue val;
			if (!cachedValues.TryGetValue (expression, out val)) {
				val = frame.GetExpressionValue (expression, true);
				cachedValues [expression] = val;
			}
			
			if (val == null || val.IsUnknown || val.IsNotSupported)
				return null;
			
			val.Name = expression;
			
			return new TooltipItem (val, startOffset, expression.Length);
		}
		public AssemblyBrowserWidget ()
		{
			this.Build( );
			TreeView = new ExtensibleTreeView (new NodeBuilder[] { 
				new ErrorNodeBuilder (),
				new AssemblyNodeBuilder (this),
				new ModuleReferenceNodeBuilder (),
				new ModuleDefinitionNodeBuilder (this),
				new ReferenceFolderNodeBuilder (this),
				new ResourceFolderNodeBuilder (),
				new ResourceNodeBuilder (),
				new NamespaceBuilder (this),
				new DomTypeNodeBuilder (this),
				new DomMethodNodeBuilder (this),
				new DomFieldNodeBuilder (this),
				new DomEventNodeBuilder (this),
				new DomPropertyNodeBuilder (this),
				new BaseTypeFolderNodeBuilder (this),
				new DomReturnTypeNodeBuilder (this),
				new ReferenceNodeBuilder (this),
				}, new TreePadOption [] {
				new TreePadOption ("PublicApiOnly", GettextCatalog.GetString ("Show public members only"), true)
			});
			TreeView.Tree.Selection.Mode = Gtk.SelectionMode.Single;
			TreeView.Tree.CursorChanged += HandleCursorChanged;
			TreeView.ShadowType = ShadowType.In;
			treeViewPlaceholder.Add (TreeView);
			treeViewPlaceholder.ShowAll ();
			
//			this.descriptionLabel.ModifyFont (Pango.FontDescription.FromString ("Sans 9"));
			this.documentationLabel.ModifyFont (Pango.FontDescription.FromString ("Sans 12"));
			this.documentationLabel.ModifyBg (Gtk.StateType.Normal, new Gdk.Color (255, 255, 225));
			this.documentationLabel.Wrap = true;
			
			var options = new MonoDevelop.Ide.Gui.CommonTextEditorOptions () {
				ShowFoldMargin = false,
				ShowIconMargin = false,
				ShowInvalidLines = false,
				ShowLineNumberMargin = false,
				ShowSpaces = false,
				ShowTabs = false,
				HighlightCaretLine = true,
			};
			inspectEditor = new Mono.TextEditor.TextEditor (new Mono.TextEditor.Document (), options);
			inspectEditor.ButtonPressEvent += HandleInspectEditorButtonPressEvent;
			
			this.inspectEditor.Document.ReadOnly = true;
//			this.inspectEditor.Document.SyntaxMode = new Mono.TextEditor.Highlighting.MarkupSyntaxMode ();
			this.inspectEditor.TextViewMargin.GetLink = delegate(Mono.TextEditor.MarginMouseEventArgs arg) {
				var loc = inspectEditor.PointToLocation (arg.X, arg.Y);
				int offset = inspectEditor.LocationToOffset (loc);
				var referencedSegment = ReferencedSegments != null ? ReferencedSegments.FirstOrDefault (seg => seg.Contains (offset)) : null;
				if (referencedSegment == null)
					return null;
				if (referencedSegment.Reference is TypeDefinition)
					return new DomCecilType ((TypeDefinition)referencedSegment.Reference).HelpUrl;
				
				if (referencedSegment.Reference is MethodDefinition)
					return new DomCecilMethod ((MethodDefinition)referencedSegment.Reference).HelpUrl;
				
				if (referencedSegment.Reference is PropertyDefinition)
					return new DomCecilProperty ((PropertyDefinition)referencedSegment.Reference).HelpUrl;
				
				if (referencedSegment.Reference is FieldDefinition)
					return new DomCecilField ((FieldDefinition)referencedSegment.Reference).HelpUrl;
				
				if (referencedSegment.Reference is EventDefinition)
					return new DomCecilEvent ((EventDefinition)referencedSegment.Reference).HelpUrl;
				
				if (referencedSegment.Reference is FieldDefinition)
					return new DomCecilField ((FieldDefinition)referencedSegment.Reference).HelpUrl;
				
				if (referencedSegment.Reference is TypeReference) {
					var returnType = DomCecilMethod.GetReturnType ((TypeReference)referencedSegment.Reference);
					if (returnType.GenericArguments.Count == 0)
						return "T:" + returnType.FullName;
					return "T:" + returnType.FullName + "`" + returnType.GenericArguments.Count;
				}
				return referencedSegment.Reference.ToString ();
			};
			this.inspectEditor.LinkRequest += InspectEditorhandleLinkRequest;
			this.scrolledwindowEditor.Child = this.inspectEditor;
//			this.inspectLabel.ModifyBg (Gtk.StateType.Normal, new Gdk.Color (255, 255, 250));
			
//			this.vpaned1.ExposeEvent += VPaneExpose;
			this.hpaned1.ExposeEvent += HPaneExpose;
/*			this.notebook1.SwitchPage += delegate {
				// Hack for the switch page select all bug.
//				this.inspectLabel.Selectable = false;
			};*/

			this.languageCombobox.AppendText (GettextCatalog.GetString ("Summary"));
			this.languageCombobox.AppendText (GettextCatalog.GetString ("IL"));
			this.languageCombobox.AppendText (GettextCatalog.GetString ("C#"));
			this.languageCombobox.Active = PropertyService.Get ("AssemblyBrowser.InspectLanguage", 2);
			this.languageCombobox.Changed += LanguageComboboxhandleChanged;
			this.searchentry1.Ready = true;
			this.searchentry1.WidthRequest = 200;
			this.searchentry1.Visible = true;
			this.searchentry1.EmptyMessage = GettextCatalog.GetString ("Search for types or members");
			this.searchentry1.InnerEntry.Changed += SearchEntryhandleChanged;
			
			CheckMenuItem checkMenuItem = this.searchentry1.AddFilterOption (0, GettextCatalog.GetString ("Types"));
			checkMenuItem.Active = true;
			checkMenuItem.Toggled += delegate {
				if (checkMenuItem.Active) {
					searchMode = AssemblyBrowserWidget.SearchMode.Type;
					CreateColumns ();
					StartSearch ();
				}
			};
			
			CheckMenuItem checkMenuItem1 = this.searchentry1.AddFilterOption (1, GettextCatalog.GetString ("Members"));
			checkMenuItem1.Toggled += delegate {
				if (checkMenuItem1.Active) {
					searchMode = AssemblyBrowserWidget.SearchMode.Member;
					CreateColumns ();
					StartSearch ();
				}
			};
			comboboxVisibilty.InsertText (0, GettextCatalog.GetString ("Only public members"));
			comboboxVisibilty.InsertText (1, GettextCatalog.GetString ("All members"));
			comboboxVisibilty.Active = 0;
			comboboxVisibilty.Changed += delegate {
				PublicApiOnly = comboboxVisibilty.Active == 0;
				this.TreeView.GetRootNode ().Options[ "PublicApiOnly"] = PublicApiOnly;
				FillInspectLabel ();
			};
			/*
			this.searchInCombobox.Active = 0;
			this.searchInCombobox.Changed += SearchInComboboxhandleChanged;
			*/
			this.notebook1.SetTabLabel (this.documentationScrolledWindow, new Label (GettextCatalog.GetString ("Documentation")));
			this.notebook1.SetTabLabel (this.notebookInspection, new Label (GettextCatalog.GetString ("Inspect")));
			this.notebook1.SetTabLabel (this.searchWidget, new Label (GettextCatalog.GetString ("Search")));
			//this.searchWidget.Visible = false;
				
			typeListStore = new Gtk.ListStore (typeof (Gdk.Pixbuf), // type image
			                                   typeof (string),     // name
			                                   typeof (string),     // namespace
			                                   typeof (string),     // assembly
				                               typeof (IMember)
			                                  );
			
			memberListStore = new Gtk.ListStore (typeof (Gdk.Pixbuf), // member image
			                                   typeof (string),     // name
			                                   typeof (string),     // Declaring type full name
			                                   typeof (string),     // assembly
				                               typeof (IMember)
			                                  );
			CreateColumns ();
			SetInspectWidget ();
//			this.searchEntry.Changed += SearchEntryhandleChanged;
			this.searchTreeview.RowActivated += SearchTreeviewhandleRowActivated;
			this.searchentry1.ShowAll ();
			this.buttonBack.Clicked += this.OnNavigateBackwardActionActivated;
			this.buttonForeward.Clicked += this.OnNavigateForwardActionActivated;
			this.notebook1.ShowTabs = false;
			this.notebookInspection.ShowTabs = false;
			this.ShowAll ();
		}