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 / September 2005

Tip: Looking for answers? Try searching our database.

Full pathname of file shown in current view of core editor?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don B. - 12 Sep 2005 20:35 GMT
In our project, we use the core editor with a custom Language Service.    
When the core editor has multiple files open, each of these opened files is
represented within the environment by a tab in the view pane.  By clicking on
a tab, it
displays the contents of that file, making it the "current view".

We use the current view successfully for a number of tasks, including
editing, colorization, setting breakpoints, etc.   We also need to retrieve
the full path name of the current opened file, or the VSITEMID of the file,
in order to access some file properties and to do other things with the file
in our project system.

We successfully get the current text view (each open file has an IVsTextView
associated with it) as follows:

      CComPtr<IVsTextManager> n_srpTextMgr;
      CComPtr<IVsTextView> n_srpTextView;
      // first get the manager
      _AtlModule.QueryService(SID_SVsTextManager,
                          IID_IVsTextManager, (void**)&n_srpTextMgr);
      // now get the current view
      hrLocal = n_srpTextMgr->GetActiveView(TRUE, NULL,
                                &n_srpTextView);

This procedure gives us a text view of the currently open file, and the
IVsTextView interface gives us access to the contents of the view: number of
lines, buffer content, caret location, doing update completion and method
tips, and so on.

How do we find the full path name of the file (or the VSITEMID of the file)
this current view is associated with?

Thanks
--Don
Ed Dore [MSFT] - 13 Sep 2005 03:57 GMT
Hi Don,

That's a timely question. Just answered this same question for Parag Chandra
back on the 7th :-)

All you need to do is retrieve the IVsTextLines/IVsTextBuffer associated
with that IVsTextView, and then do the following:

QI for IVsUserData (just cast it if your using managed code), then call
IVsUserData.GetData with GUID_VsBuferMoniker, to retrieve the
filename/moniker associated with the buffer.

In TEXTMGR.IDL GUID_VsBufferMoniker is defined as

   //--------------------------------------------------------------------------
   // GUID_VsBufferMoniker  VT_BSTR
   cpp_quote("#define GUID_VsBufferMoniker IID_IVsUserData")

So in C#, you can do the following (courtesy of Parag):

  typeof(IVsUserData).GUID

There are a couple Microsoft packages that do this as well.

Sincerely,
Ed Dore [MSFT]

This post is "AS IS" with no warranties, and confers no rights.
Don B. - 14 Sep 2005 18:15 GMT
Thanks Ed, it worked like a champ!

BTW, we never were able to find the other answer you referred to.  I guess
we need to improve our search skills.

Thanks again!
--Don

> Hi Don,
>
[quoted text clipped - 24 lines]
>
> This post is "AS IS" with no warranties, and confers no rights.
"Ed Dore [MSFT]" - 14 Sep 2005 18:53 GMT
Hi Don,

Glad to hear that worked. Finding previous posts in the newsgroup can be a
pain. If you're using Outlook Express be sure to dial up the number of days
you keep messages in the download cache. I'm not sure how long messages
actually stay on the server before they scroll off.

I use Outlook Express from home, but at work we have a utility that imports
the messages into a monster SQL database, and a front end application that
we can run queries on. Even so, it took a bit of work to dig out my earlier
response back on the 7th.

Alas, the MSDN Extensibility forum is a lot better at retaining stuff,
though we don't have the managed MSDN customer tracking stuff there yet.

Sincerely,
Ed Dore [MSFT]

This post is 'AS IS' with no warranties, and confers no rights.

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.