예제 #1
0
//		public MonoDevelop.Projects.CodeGeneration.CodeGenerator CreateCodeGenerator ()
//		{
//			return MonoDevelop.Projects.CodeGeneration.CodeGenerator.CreateGenerator (Editor.Document.MimeType,
//				Editor.Options.TabsToSpaces, Editor.Options.TabSize, Editor.EolMarker);
//		}

        /// <summary>
        /// If the document shouldn't restore the settings after the load it can be disabled with this method.
        /// That is useful when opening a document and programmatically scrolling to a specified location.
        /// </summary>
        public void DisableAutoScroll()
        {
            if (IsFile)
            {
                FileSettingsStore.Remove(FileName);
            }
        }
예제 #2
0
        void ScrollToRequestedCaretLocation(Document doc, FileOpenInformation info)
        {
            if (info.Line < 1 && info.Offset < 0)
            {
                return;
            }

            if (editorOperationsFactoryService == null)
            {
                editorOperationsFactoryService = CompositionManager.Instance.GetExportedValue <IEditorOperationsFactoryService> ();
            }

            FileSettingsStore.Remove(doc.FileName);
            doc.DisableAutoScroll();

            doc.RunWhenContentAdded <ITextView> (textView => {
                var ipos = doc.Editor;
                if (ipos != null)
                {
                    var loc = new DocumentLocation(info.Line, info.Column >= 1 ? info.Column : 1);
                    if (info.Offset >= 0)
                    {
                        loc = ipos.OffsetToLocation(info.Offset);
                    }
                    if (loc.IsEmpty)
                    {
                        return;
                    }
                    ipos.SetCaretLocation(loc, info.Options.HasFlag(OpenDocumentOptions.HighlightCaretLine), info.Options.HasFlag(OpenDocumentOptions.CenterCaretLine));
                }
                else
                {
                    var offset = info.Offset;
                    if (offset < 0)
                    {
                        var line = textView.TextSnapshot.GetLineFromLineNumber(info.Line - 1);
                        if (info.Column >= 1)
                        {
                            offset = line.Start + info.Column - 1;
                        }
                        else
                        {
                            offset = line.Start;
                        }
                    }
                    if (editorOperationsFactoryService != null)
                    {
                        var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
                        var point            = new VirtualSnapshotPoint(textView.TextSnapshot, offset);
                        editorOperations.SelectAndMoveCaret(point, point, TextSelectionMode.Stream, EnsureSpanVisibleOptions.AlwaysCenter);
                    }
                    else
                    {
                        LoggingService.LogError("Missing editor operations");
                    }
                }
            });

/*			var navigator = (ISourceFileNavigator)newContent.GetContent (typeof (ISourceFileNavigator));
 *                      if (fileInfo.Offset >= 0)
 *                              navigator.JumpToOffset (fileInfo.Offset);
 *                      else
 *                              navigator.JumpToLine (fileInfo.Line, fileInfo.Column);*/
        }
예제 #3
0
        void ScrollToRequestedCaretLocation(Document doc, FileOpenInformation info)
        {
            if (info.Line < 1 && info.Offset < 0)
            {
                return;
            }

            if (editorOperationsFactoryService == null)
            {
                editorOperationsFactoryService = CompositionManager.Instance.GetExportedValue <IEditorOperationsFactoryService> ();
            }

            FileSettingsStore.Remove(doc.FileName);
            doc.DisableAutoScroll();

            doc.RunWhenContentAdded <ITextView> (textView => {
                var ipos = doc.Editor;
                if (ipos != null)
                {
                    var loc = new DocumentLocation(info.Line, info.Column >= 1 ? info.Column : 1);
                    if (info.Offset >= 0)
                    {
                        loc = ipos.OffsetToLocation(info.Offset);
                    }
                    if (loc.IsEmpty)
                    {
                        return;
                    }
                    ipos.SetCaretLocation(loc, info.Options.HasFlag(OpenDocumentOptions.HighlightCaretLine), info.Options.HasFlag(OpenDocumentOptions.CenterCaretLine));
                }
                else
                {
                    var offset = info.Offset;
                    if (offset < 0)
                    {
                        try {
                            if (info.Line - 1 > (textView?.TextSnapshot?.LineCount ?? 0))
                            {
                                LoggingService.LogInfo($"ScrollToRequestedCaretLocation line was over the snapshot's line count. "
                                                       + $"Called with {info.Line - 1} but line count was {textView?.TextSnapshot?.LineCount}");
                                return;
                            }

                            var line = textView.TextSnapshot.GetLineFromLineNumber(info.Line - 1);
                            if (info.Column >= 1)
                            {
                                offset = line.Start + Math.Min(info.Column - 1, line.Length);
                            }
                            else
                            {
                                offset = line.Start;
                            }
                        } catch (ArgumentException ae) {
                            LoggingService.LogError($"Calling GetLineFromLineNumber resulted in an argument exception."
                                                    + $"We tried calling with line number: {info.Line - 1}", ae);
                            // we should just abort in this case, since we can't really do anything
                            return;
                        }
                    }
                    if (editorOperationsFactoryService != null)
                    {
                        var editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
                        var point            = new VirtualSnapshotPoint(textView.TextSnapshot, offset);
                        editorOperations.SelectAndMoveCaret(point, point, TextSelectionMode.Stream, EnsureSpanVisibleOptions.AlwaysCenter);
                    }
                    else
                    {
                        LoggingService.LogError("Missing editor operations");
                    }
                }
            });

/*			var navigator = (ISourceFileNavigator)newContent.GetContent (typeof (ISourceFileNavigator));
 *                      if (fileInfo.Offset >= 0)
 *                              navigator.JumpToOffset (fileInfo.Offset);
 *                      else
 *                              navigator.JumpToLine (fileInfo.Line, fileInfo.Column);*/
        }