Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / December 2005

Tip: Looking for answers? Try searching our database.

Macros and formatting  More Info provided

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Josh Stevens - 14 Dec 2005 02:21 GMT
I can't be sure without a concrete example, but it sounds as if the auto-formatting done by the editor is messing up your results.  What language are you using?  VB is especially susceptible to this because it auto-formats very aggressively.  Maybe you can get the results you want by turning off the auto-formatting in the Tools->Options dialog (under the Text Editor category).

-Josh
VS IDE team

-----Original Message-----
From: TroyR@discussions.microsoft.com
Posted At: Wednesday, November 30, 2005 1:29 PM
Posted To: microsoft.public.vstudio.extensibility
Conversation: Macros and formatting More Info provided
Subject: RE: Macros and formatting More Info provided

Just so it is a little clearer, I'm using the ActiveDocument.Selection object to alter the text of a new file I added to the project.  I have all the text formated the way I think it should look so I create the string and set the Text property of the selection object to that string.  For any line I add a vbTab to indent the text it moves the starting point of the next line out to the current tab position so each time a vbTab is added to the string, subsequent lines start one tab position further out.  I can't get it to undo the tabs on previous lines.  

"Troy R" wrote:

> Hi,
>   I'm not sure if this is an issue with the settings in the IDE or not
> but I have a macro that creates a new class and adds it to the startup project.
> The problem is that the text is not formatting correctly.  I am using
> the vbTab as part of the text to indent certain lines but this seems
> to have a cumulative affect.  If I add a vbCrLf to the line, it
> doesn't go back to the start of the line but to the last tab position.  
> I have tried using vbBack, using the selection.StartOfLine function
> but it doesn't seem to have any affect.  I know there are functions
> for doing indent, unindent but they affect the entire selection which
> isn't what I want.  I want to be able to create the entire string at
> once with the formatting set so I can just set the text property to
> that string.  Any suggestions on how to control the indentation on a line by line basis?
>   Thanks,
>      Troy
Troy R - 14 Dec 2005 19:33 GMT
Hi Josh,
 I turned off the smart Indent option for C/C++ but that didnt' have any
effect.
 Here is a snippet of the macro code that adds the text to create a C++
class to the file:

       Application.Documents.Add("Text")

       ActiveDocument.Selection.StartOfDocument()

       CPPText = GetClassCommentTemplate(ClassName, False) & "#include " +
Chr(34) + "stdafx.h" + Chr(34) + vbCrLf & _
       "#include " + Chr(34) + ClassName + ".h" + Chr(34) + vbCrLf & _
       GetTestLevelString(ClassName, testlevel) & _
       "" + vbCrLf & _
       "" + vbCrLf & _
       ClassName + "::" + ClassName + "()" + vbCrLf & _
       "{" + vbCrLf & _
       "}" + vbCrLf & _
       "" + vbCrLf & _
       "" + vbCrLf & _
       ClassName + "::~" + ClassName + "()" + vbCrLf & _
       "{" + vbCrLf & _
       "}" + vbCrLf + vbCrLf & _
       "void " + ClassName + "::TestSetUp()" + vbCrLf & _
       "{" + vbCrLf & _
       "}" + vbCrLf + vbCrLf & _
       "void " + ClassName + "::TestTearDown()" + vbCrLf & _
       "{" + vbCrLf & _
       "}" + vbCrLf + vbCrLf & _
       "CString " + ClassName + "::GetTestPath(void)" + vbCrLf & _
       "{" + vbCrLf & _
       "CString csToken1, csToken2, csPath, csArchivePath = ""$Archive$"";"
+ vbCrLf & _
       "int iStart = 10;" + vbCrLf & _
       "csToken1 = csArchivePath.Tokenize("" / "",iStart);" + vbCrLf & _
       "if (iStart > 0)" + vbCrLf & _
       "csToken2 = csArchivePath.Tokenize("" / "",iStart);" + vbCrLf & _
       "while (csToken1 != """" && csToken2 != """")" + vbCrLf & _
       "{" + vbCrLf + vbTab & _
       "if (!csPath.IsEmpty())" + vbCrLf & _
       "csPath += '\\';" + vbCrLf & _
       "csPath += csToken1;" + vbCrLf & _
       "csToken1 = csToken2;" + vbCrLf & _
       "csToken2 = csArchivePath.Tokenize("" / "",iStart);" + vbCrLf & _
       "}" + vbCrLf + vbCrLf & _
       "//Since we are relying on the $Archive$ macro to provide the path,"
+ vbCrLf & _
       "// we need to assert if the file hasn't been checked in yet.  If" +
vbCrLf & _
       "// that is the case, just hard code it for testing." + vbCrLf & _
       "ASSERT(!csPath.IsEmpty());" + vbCrLf & _
       "return csPath;" + vbCrLf & _
       "}" + GetSSLogCommentTemplate()

       Application.ActiveDocument.Selection.Text = CPPText

       Application.ActiveDocument.Save(MyCppName)

The functions GetSSLogCommentTemplate() and GetClassCommentTemplate() retun
strings.

Let me know if you need any more information.
  Thanks,
     Troy

> I can't be sure without a concrete example, but it sounds as if the auto-formatting done by the editor is messing up your results.  What language are you using?  VB is especially susceptible to this because it auto-formats very aggressively.  Maybe you can get the results you want by turning off the auto-formatting in the Tools->Options dialog (under the Text Editor category).
>
[quoted text clipped - 27 lines]
> >   Thanks,
> >      Troy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.