void okButtonClick(object sender, RoutedEventArgs e)
		{
			try {
				if (listBox.SelectedItem == null)
					return;
				object tag = ((GotoEntry)listBox.SelectedItem).Tag;
				if (tag is int) {
					ITextEditor editor = GetEditor();
					if (editor != null) {
						int i = Math.Min(editor.Document.TotalNumberOfLines, Math.Max(1, (int)tag));
						editor.JumpTo(i, int.MaxValue);
					}
				} else if (tag is IClass) {
					IClass c = tag as IClass;
					CodeCompletionDataUsageCache.IncrementUsage(c.DotNetName);
					GotoRegion(c.Region, c.CompilationUnit.FileName);
				} else if (tag is IMember) {
					IMember m = tag as IMember;
					CodeCompletionDataUsageCache.IncrementUsage(m.DotNetName);
					GotoRegion(m.Region, m.DeclaringType.CompilationUnit.FileName);
				} else if (tag is FileLineReference) {
					FileLineReference flref = (FileLineReference)tag;
					if (flref.Line <= 0) {
						FileService.OpenFile(flref.FileName);
					} else {
						FileService.JumpToFilePosition(flref.FileName, flref.Line, flref.Column);
					}
				} else {
					throw new NotImplementedException("Unknown tag: " + tag);
				}
			} finally {
				Close();
			}
		}
        public void ShowSourceCode(int lineNumber = 0)
        {
            this.WorkbenchWindow.ActiveViewContent = this.PrimaryViewContent;
            ITextEditor editor = this.primaryViewContent.GetService <ITextEditor>();

            if (editor != null)
            {
                editor.JumpTo(lineNumber, 1);
            }
        }
        private void memberNode_Selected(object sender, RoutedEventArgs e)
        {
            IVbMember member = ((TreeViewItem)e.Source).Tag as IVbMember;

            if (member == null)
            {
                return;
            }

            _textEditor.JumpTo(member.Location.Line, 1);
        }
        /// <summary>
        /// Replaces the text at the given region with the specified xml. After replacing
        /// the inserted text is indented and then selected.
        /// </summary>
        public void Replace(DomRegion region, string xml)
        {
            WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);

            using (textEditor.Document.OpenUndoGroup()) {
                // Replace the original xml with the new xml and indent it.
                int originalLineCount = document.TotalNumberOfLines;
                int initialIndent     = GetIndent(region.BeginLine);
                document.Replace(segment.Offset, segment.Length, xml);
                int addedLineCount = document.TotalNumberOfLines - originalLineCount;

                // Indent the xml.
                int insertedCharacterCount = IndentAllLinesTheSame(region.BeginLine + 1, region.EndLine + addedLineCount, initialIndent);

                // Make sure the text inserted is visible.
                textEditor.JumpTo(region.BeginLine, 1);

                // Select the text just inserted.
                int textInsertedLength = insertedCharacterCount + xml.Length;
                textEditor.Select(segment.Offset, textInsertedLength);
            }
        }
Beispiel #5
0
 void okButtonClick(object sender, RoutedEventArgs e)
 {
     try {
         if (listBox.SelectedItem == null)
         {
             return;
         }
         object tag = ((GotoEntry)listBox.SelectedItem).Tag;
         if (tag is int)
         {
             ITextEditor editor = GetEditor();
             if (editor != null)
             {
                 int i = Math.Min(editor.Document.LineCount, Math.Max(1, (int)tag));
                 editor.JumpTo(i, int.MaxValue);
             }
         }
         else if (tag is IUnresolvedEntity)
         {
             IUnresolvedEntity c = tag as IUnresolvedEntity;
             CodeCompletionDataUsageCache.IncrementUsage(c.ReflectionName);
             GotoRegion(c.Region);
         }
         else if (tag is IEntity)
         {
             IEntity m = tag as IEntity;
             CodeCompletionDataUsageCache.IncrementUsage(m.ReflectionName);
             GotoRegion(m.Region);
         }
         else if (tag is FileLineReference)
         {
             FileLineReference flref = (FileLineReference)tag;
             if (flref.Line <= 0)
             {
                 FileService.OpenFile(flref.FileName);
             }
             else
             {
                 FileService.JumpToFilePosition(flref.FileName, flref.Line, flref.Column);
             }
         }
         else
         {
             throw new NotImplementedException("Unknown tag: " + tag);
         }
     } finally {
         Close();
     }
 }
 /// <summary>
 /// Jumps to dialog element with corresponding dialog id. This is only used
 /// when the user opens a dialog from the Setup dialogs window or the cursor
 /// was not near a dialog when the designer was switched to. Jumping to the
 /// dialog selected ensures that when the user switches back, if they did
 /// not make any changes, then the dialog xml is displayed.
 /// </summary>
 void JumpToDialogElement(string dialogId)
 {
     try {
         if (dialogId != null)
         {
             ITextEditor textEditor = ActiveTextEditor;
             if (textEditor != null)
             {
                 WixDocumentReader wixReader = new WixDocumentReader(textEditor.Document.Text);
                 TextLocation      location  = wixReader.GetStartElementLocation("Dialog", dialogId);
                 textEditor.JumpTo(location.Line, 1);
             }
         }
     } catch (XmlException) {
         // Ignore
     }
 }
Beispiel #7
0
        public void Complete(CompletionContext context)
        {
            ITextEditor editor      = context.Editor;
            ClassFinder classFinder = new ClassFinder(ParserService.GetParseInformation(editor.FileName),
                                                      editor.Caret.Line, editor.Caret.Column);
            int           caretPosition = editor.Caret.Offset;
            IDocumentLine line          = editor.Document.GetLine(editor.Caret.Line);
            string        lineText      = editor.Document.GetText(line.Offset, caretPosition - line.Offset);

            foreach (char c in lineText)
            {
                if (!char.IsWhiteSpace(c) && !char.IsLetterOrDigit(c))
                {
                    editor.Document.Replace(context.StartOffset, context.Length, this.Text);
                    context.EndOffset = context.StartOffset + this.Text.Length;
                    return;
                }
            }

            string indentation = lineText.Substring(0, lineText.Length - lineText.TrimStart().Length);

            editor.Document.Remove(line.Offset, caretPosition - line.Offset);

            foreach (ICompletionItemHandler handler in handlers)
            {
                if (handler.Handles(this))
                {
                    editor.Document.Insert(line.Offset, indentation);
                    handler.Insert(context, this);
                    return;
                }
            }

            CodeGenerator codeGen = ParserService.CurrentProjectContent.Language.CodeGenerator;

            string text = codeGen.GenerateCode(codeGen.GetOverridingMethod(member, classFinder), indentation);

            text = text.TrimEnd(); // remove newline from end

            editor.Document.Insert(line.Offset, text);

            int endPos = line.Offset + text.Length;

            line = editor.Document.GetLineForOffset(endPos);
            editor.JumpTo(line.LineNumber, endPos - line.Offset + 1);
        }
        /// <summary>
        /// Scrolls to the specified line and column and also selects the given
        /// length of text at this location.
        /// </summary>
        static void ScrollTo(string filename, int line, int column, int length)
        {
            XmlView view = XmlView.ForFileName(filename);

            if (view != null)
            {
                ITextEditor editor = view.TextEditor;
                if (editor == null)
                {
                    return;
                }
                int corLine = Math.Min(line + 1, editor.Document.LineCount - 1);
                editor.JumpTo(corLine, column + 1);
                if (length > 0 && line < editor.Document.LineCount)
                {
                    int offset = editor.Document.PositionToOffset(line + 1, column + 1);
                    editor.Select(offset, length);
                }
            }
        }