How to get Visual Studio editor text with color formatting? - visual-studio-2013

I have a VS plug-in that currently takes the editor text by getting a TextDocument via app.ActiveDocument.Object() and then I get the text from that. This, however, is just plain text, and I'd like to have not just text but the color information (kind of like the RTF export). How can I get it?

Cast EnvDTE.TextDocument.Selection to EnvDTE.TextSelection and then use EnvDTE.TextSelection.Move(point1, false) and EnvDTE.TextSelection.Move(point2, true) and then EnvDTE.TextSelection.Copy() to copy to the clipboard, which you should preserve saving its content before copying and then restoring when done.

Related

How to disable formatting in TextEdit on Mac Yosemite

When I copy something and paste it from buffer in TextEdit, it saves text formatting (font-color, background-color, font-style) How can I turn that off?
I don't think you will be able to turn it off. But you can tweak it in the copy/paste process.
Take a look at this article here as it explains how you can copy/paste using a certain combination of keys to skip formatting.
Paste the copied text and match current style by using Command+Option+Shift+V.
Notice the difference from the normal Command+V paste trick, which would include the formatting.
If you don't want to save text with formatting, you should work with plain text format: menu Format > Make Plain Text (⇧⌘T). You can also set plain text format as your default document format in TextEdit Preferences.

Text kerning in Microsoft rich text box

This one has me awfully confused...
I am trying to display kerned RTF text in a Visual Studio Visual Basic RichTextBox control (having so far tried under VS2010 and VS2012). Simply, I create a Windows Form project, add two RichTextBox's (RichTextBox1 and RichTextBox2) to the form, no change to default properties, and include the following VB code:
Public Class Form1
Private Sub Initialise(sender As System.Object, e As System.EventArgs) Handles Me.Load
Dim txtRTF As String = "{\rtf1\ansi" & _
"{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}" & _
"\f0\pard" & _
"\expndtw-60 a" & _
"\expndtw200 b" & _
"\expndtw-20 c}"
RichTextBox1.Rtf = txtRTF
RichTextBox2.Paste() ' RichTextBox2 formats properly iff clipboard holds ANY valid rtf content
RichTextBox2.Rtf = txtRTF
End Sub
End Class
The txtRTF String contains, as best as I can tell, minimal valid RTF markup and text.
Here's the confusing bit: text displayed in RichTextBox1 is not kerned, despite \expndtw (expand twips) RTF markup, BUT text displayed in RichTextBox2 is properly kerned, if and only if the clipboard holds ANY valid RTF content (e.g., any text has first been copied into the clipboard from an MS Word document). Text displayed in RichTextBox2 is not properly kerned if clipboard contents is not RTF format.
Result of running if the clipboard does not contain RTF-formatted data (or if the RichTextBox2.Paste() code is removed or commented out):
Result of running if the clipboard holds any random RTF-formatted text:
Questions:
Why on earth should it matter that I have previously pasted RTF-format (and not non-RTF format) into the RichTextBox2 control before setting the RichTextBox2.Rtf field?
More importantly, how can I (in VB) programmatically display properly kerned text in a RichTextBox control without the absurdity of first pasting random RTF format text into it?
Well, that took a lot of work! Nevertheless, problem now solved.
It turns out that, although the RTF spec notes that \ltrch (left-to-right character run) is the default state, it seems that RichTextBox objects don't necessarily agree. Including a \ltrch (or even, oddly, a \rtlch) control sequence in the RTF markup stream completely solves the failure-to-kern problem. RTF text kerning via \expndtwN and \expndN now works perfectly well. No need for silly Paste() commands to pre-configure the RichTextBox control into its proper state!

Copy Selected Text with VBA and the Adpbe PDF Reader Control

I am trying to copy selected text directly out of a PDF viewer I have made with the Adobe PDF Reader Control in Visual Basic 2010.
I can utilize highlight text with a macro in Word using something this:
Private Sub CommandButton1_Click()
Dim Sel As Selection
Set Sel = Application.Selection
If Sel.Type <> wdSelectionIP Then
MsgBox Sel.Text
End If
End Sub
I am having trouble figuring out whether this bit of code can be used to perform actions with the highlighted text with Adobe PDF Reader. If not, does anyone know how I would go about doing that?
I don't think that the Adobe PDF viewer supports VBA.
However, I would suggest an indirect approach, using the clipboard.
By sending a control+c key, the content of the selection will be transferred to the clipboard, and the clipboard could be processed using "native" VBA.
Sending a control+c is done by using SendKeys("^C"), see This link
And the Clipboard can be manipulated using This exampe

How do I edit a text buffer (or selected text) with the Visual Studio 2010 SDK

I want to create a simple extension which modifies text buffers based on a command. No sample, documentation or template that I've found so far explains anything about working with text buffers. Anyone got a clue how to do this?
What I want to end up with is a format selection/document extension for text files, that wrap content around 72 characters per line.
I found this extension together with sample very helpful, and now I have something which works. Though it was very counter intuitive at first, I was trying to get the at the code window while this example instead uses a command filter to fiddle with the text view by extending the editor.
The ITextView interface provides access to the text in the editor, you can access the Buffer through that and make changes that way.
Link
http://github.com/noahric/alignassignments

VS2008 Resize text editor macro

I'm using Visual Studio 2008 and I split my text editor into two vertical text editors. I thought it would be useful to have a macro that re-size the active text editor to take up most of the screen but I haven't gotten very far. I get an error whenever I try to change the width oh a text editor.
DTE.ActiveWindow.Width = 800
And I'm not sure how to identify weather the active window is a text editor or not.
Anyone know what I'm doing wrong?
thanks
Check the Kind property. Should be "Document" for text editors, I suppose:
If DTE.ActiveWindow.Kind = "Document" Then
' ActiveWindow is a text editor '
End If

Resources