예제 #1
0
			public CodeCompletionContext CreateCodeCompletionContext (int triggerOffset)
			{
				var savedCtx = realDocument.GetContent<ICompletionWidget> ().CreateCodeCompletionContext (realDocument.Editor.Caret.Offset + triggerOffset - localInfo.CaretPosition);
				CodeCompletionContext result = new CodeCompletionContext ();
				result.TriggerOffset = triggerOffset;
				DocumentLocation loc = localInfo.HiddenDocument.Editor.Document.OffsetToLocation (triggerOffset);
				result.TriggerLine   = loc.Line;
				result.TriggerLineOffset = loc.Column - 1;
				
				result.TriggerXCoord = savedCtx.TriggerXCoord;
				result.TriggerYCoord = savedCtx.TriggerYCoord;
				result.TriggerTextHeight = savedCtx.TriggerTextHeight;
				return result;
			}
        public static void QueueQuickFixAnalysis(MonoDevelop.Ide.Gui.Document doc, TextLocation loc, CancellationToken token, Action <List <MonoDevelop.CodeActions.CodeAction> > callback)
        {
            var ext    = doc.GetContent <MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
            var issues = ext != null?ext.GetResultsAtOffset(doc.Editor.LocationToOffset(loc), token).OrderBy(r => r.Level).ToList() : new List <Result> ();

            ThreadPool.QueueUserWorkItem(delegate {
                try {
                    var result = new List <MonoDevelop.CodeActions.CodeAction> ();
                    foreach (var r in issues)
                    {
                        if (token.IsCancellationRequested)
                        {
                            return;
                        }
                        var fresult = r as FixableResult;
                        if (fresult == null)
                        {
                            continue;
                        }
                        foreach (var action in FixOperationsHandler.GetActions(doc, fresult))
                        {
                            result.Add(new AnalysisContextActionProvider.AnalysisCodeAction(action, r)
                            {
                                DocumentRegion = action.DocumentRegion
                            });
                        }
                    }
                    result.AddRange(GetValidActions(doc, loc).Result);
                    callback(result);
                } catch (Exception ex) {
                    LoggingService.LogError("Error in analysis service", ex);
                }
            });
        }
예제 #3
0
        public static void QueueQuickFixAnalysis(MonoDevelop.Ide.Gui.Document doc, TextLocation loc, Action <List <MonoDevelop.CodeActions.CodeAction> > callback)
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate {
                try {
                    var result = new List <MonoDevelop.CodeActions.CodeAction> ();

                    var ext = doc.GetContent <MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
                    if (ext != null)
                    {
                        foreach (var r in ext.GetResultsAtOffset(doc.Editor.LocationToOffset(loc)).OrderBy(r => r.Level))
                        {
                            var fresult = r as FixableResult;
                            if (fresult == null)
                            {
                                continue;
                            }
                            foreach (var action in FixOperationsHandler.GetActions(doc, fresult))
                            {
                                result.Add(new AnalysisContextActionProvider.AnalysisCodeAction(action, r));
                            }
                        }
                    }
                    result.AddRange(GetValidActions(doc, loc).Result);
                    callback(result);
                } catch (Exception ex) {
                    LoggingService.LogError("Error in analysis service", ex);
                }
            });
        }
예제 #4
0
        public static void QueueQuickFixAnalysis(MonoDevelop.Ide.Gui.Document doc, DomLocation loc, Action <List <ContextAction> > callback)
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate {
                try {
                    string disabledNodes = PropertyService.Get("ContextActions." + doc.Editor.Document.MimeType, "") ?? "";

                    var availableFixes = new List <ContextAction> (contextActions.Where(fix => disabledNodes.IndexOf(fix.Type.FullName) < 0 && fix.Action.IsValid(doc, loc)).Select(fix => fix.Action));
                    var ext            = doc.GetContent <MonoDevelop.AnalysisCore.Gui.ResultsEditorExtension> ();
                    if (ext != null)
                    {
                        foreach (var result in ext.GetResultsAtOffset(doc.Editor.LocationToOffset(loc.Line, loc.Column)))
                        {
                            var fresult = result as FixableResult;
                            if (fresult == null)
                            {
                                continue;
                            }
                            foreach (var action in FixOperationsHandler.GetActions(doc, fresult))
                            {
                                availableFixes.Add(new AnalysisContextAction(result, action));
                            }
                        }
                    }

                    callback(availableFixes);
                } catch (Exception ex) {
                    LoggingService.LogError("Error in analysis service", ex);
                }
            });
        }
        protected override void Run()
        {
            MonoDevelop.Ide.Gui.Document doc = IdeApp.Workbench.ActiveDocument;
            var    textEditorData            = doc.GetContent <ITextEditorDataProvider>().GetTextEditorData();
            string date = DateTime.Now.ToString();

            textEditorData.InsertAtCaret(date);
        }
예제 #6
0
        public void Selected()
        {
            if (!TryReloadCoverageFile())
            {
                return;
            }

            var sourceEditor = origDoc.GetContent <MonoDevelop.SourceEditor.SourceEditorView> ();

            if (sourceEditor != null)
            {
                try {
                    TextEditor.Caret.Location    = sourceEditor.TextEditor.Caret.Location;
                    TextEditor.VAdjustment.Value = sourceEditor.TextEditor.VAdjustment.Value;
                } catch {
                }
            }
        }
예제 #7
0
        public static ResolveResult GetResolveResult(MonoDevelop.Ide.Gui.Document doc)
        {
            ITextEditorResolver textEditorResolver = doc.GetContent <ITextEditorResolver> ();

            if (textEditorResolver != null)
            {
                return(textEditorResolver.GetLanguageItem(doc.Editor.Caret.Offset));
            }
            return(null);
        }
예제 #8
0
        void SetCurrentView(int newIndex)
        {
            BaseViewContent subViewContent;

            int oldIndex = subViewNotebook.CurrentPage;

            subViewNotebook.CurrentPage = newIndex;

            if (oldIndex != -1)
            {
                subViewContent = viewContents[oldIndex] as BaseViewContent;
                if (subViewContent != null)
                {
                    subViewContent.OnDeselected();
                }
            }

            subViewContent = viewContents[newIndex] as BaseViewContent;

            DetachFromPathedDocument();

            MonoDevelop.Ide.Gui.Content.IPathedDocument pathedDocument;
            if (newIndex < 0 || newIndex == viewContents.IndexOf((BaseViewContent)ViewContent))
            {
                pathedDocument = Document != null?Document.GetContent <IPathedDocument> () : (IPathedDocument)ViewContent.GetContent(typeof(IPathedDocument));
            }
            else
            {
                pathedDocument = (IPathedDocument)viewContents[newIndex].GetContent(typeof(IPathedDocument));
            }

            var toolbarVisible = false;

            foreach (var t in documentToolbars)
            {
                toolbarVisible = ActiveViewContent == t.Key;
                t.Value.Container.GetNativeWidget <Gtk.Widget> ().Visible = toolbarVisible;
            }

            if (pathedDocument != null && !toolbarVisible)
            {
                AttachToPathedDocument(pathedDocument);
            }

            if (subViewContent != null)
            {
                subViewContent.OnSelected();
            }

            OnActiveViewContentChanged(new ActiveViewContentEventArgs(this.ActiveViewContent));
        }
예제 #9
0
        static DocumentUserPrefs CreateDocumentPrefs(UserPreferencesEventArgs args, Document document)
        {
            string path = (string)document.OriginalFileName ?? document.FileName;

            var dp = new DocumentUserPrefs();

            dp.FileName = FileService.AbsoluteToRelativePath(args.Item.BaseDirectory, path);
            if (document.GetContent <ITextView> () is ITextView view)
            {
                var pos  = view.Caret.Position.BufferPosition;
                var line = pos.Snapshot.GetLineFromPosition(pos.Position);
                dp.Line   = line.LineNumber + 1;
                dp.Column = pos.Position - line.Start + 1;
            }
            return(dp);
        }
        void SetCurrentView(int newIndex)
        {
            IAttachableViewContent subViewContent;

            int oldIndex = subViewNotebook.CurrentPage;

            subViewNotebook.CurrentPage = newIndex;

            if (oldIndex != -1)
            {
                subViewContent = viewContents[oldIndex] as IAttachableViewContent;
                if (subViewContent != null)
                {
                    subViewContent.Deselected();
                }
            }

            subViewContent = viewContents[newIndex] as IAttachableViewContent;
            if (subViewContent != null)
            {
                subViewContent.Selected();
            }

            DetachFromPathedDocument();

            MonoDevelop.Ide.Gui.Content.IPathedDocument pathedDocument;
            if (newIndex < 0 || newIndex == viewContents.IndexOf(ViewContent))
            {
                pathedDocument = Document != null?Document.GetContent <IPathedDocument> () : (IPathedDocument)ViewContent.GetContent(typeof(IPathedDocument));
            }
            else
            {
                pathedDocument = (IPathedDocument)viewContents[newIndex].GetContent(typeof(IPathedDocument));
            }

            if (pathedDocument != null)
            {
                AttachToPathedDocument(pathedDocument);
            }

            foreach (var t in documentToolbars)
            {
                t.Value.Container.Visible = ActiveViewContent == t.Key;
            }

            OnActiveViewContentChanged(new ActiveViewContentEventArgs(this.ActiveViewContent));
        }
예제 #11
0
        void SetCurrentView(int newIndex)
        {
            subViewNotebook.CurrentPage = newIndex;

            if (oldIndex > 0)
            {
                IAttachableViewContent secondaryViewContent = subViewContents[oldIndex - 1] as IAttachableViewContent;
                if (secondaryViewContent != null)
                {
                    secondaryViewContent.Deselected();
                }
            }

            if (subViewNotebook.CurrentPage > 0)
            {
                IAttachableViewContent secondaryViewContent = subViewContents[subViewNotebook.CurrentPage - 1] as IAttachableViewContent;
                if (secondaryViewContent != null)
                {
                    secondaryViewContent.Selected();
                }
            }
            oldIndex = subViewNotebook.CurrentPage;
            DetachFromPathedDocument();

            MonoDevelop.Ide.Gui.Content.IPathedDocument pathedDocument;
            if (oldIndex <= 0)
            {
                pathedDocument = Document != null?Document.GetContent <MonoDevelop.Ide.Gui.Content.IPathedDocument> () : ViewContent.GetContent <MonoDevelop.Ide.Gui.Content.IPathedDocument> ();
            }
            else
            {
                pathedDocument = subViewContents[oldIndex - 1].GetContent <MonoDevelop.Ide.Gui.Content.IPathedDocument> ();
            }

            if (pathedDocument != null)
            {
                AttachToPathedDocument(pathedDocument);
            }
            OnActiveViewContentChanged(new ActiveViewContentEventArgs(this.ActiveViewContent));
        }
예제 #12
0
 public T GetContent <T>() where T : class
 {
     return(doc.GetContent <T> (true));
 }
 protected override void Update(CommandInfo info)
 {
     MonoDevelop.Ide.Gui.Document doc = MonoDevelop.Ide.IdeApp.Workbench.ActiveDocument;
     info.Enabled = doc != null && doc.GetContent <ITextEditorDataProvider>() != null;
 }