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 / IDE / November 2004

Tip: Looking for answers? Try searching our database.

VS.NET Add-in - context menus and selection text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ondrej Maler - 26 Nov 2004 09:13 GMT
HI all,

I am creating small VS.NET add-in and have 2 problems:

1. I am extending context menus in the different windows. I am able
succesfully add commands to context menus of  code editor ("Code Window"),
help window ("DefaultContext") and selection context in help window
("SelectionContext")

But I do not know, how to extend the context menus in WebPage - HTMLView and
when editing XML file. I have used Command Browser sample tool but it seems
the two context menus name is "Context" and there are more such menus named
"Context".

2. I would like to access the selection text of the currently active window.
I am able access the selection text in the "Code Window" using this code:

TextSelection selectedText = (TextSelection)
applicationDTEObject.ActiveWindow.Document.Selection;

but when I use this code in the "DefaultContext" or "SelectionContext", the
ActiveWindow property is null and I am not able to get the selected text in
the help window.

I will need to access the selected text from the WebPage -> HTML View and
XML file editor too, if I will solve the problem 1.

Thanks for your answers.

Ondrej
Ondrej Maler - 26 Nov 2004 09:21 GMT
To be correct:

ActiveWindow is not null, but ActiveWindow.Document is null and
ActiveWindow.Selection is null too.

Ondrej

> TextSelection selectedText = (TextSelection)
> applicationDTEObject.ActiveWindow.Document.Selection;
>
> but when I use this code in the "DefaultContext" or "SelectionContext", the
> ActiveWindow property is null and I am not able to get the selected text in
> the help window.

----------------------------------------------------------------------------
----------------
> HI all,
>
[quoted text clipped - 26 lines]
>
> Ondrej
Carlos J. Quintero [MVP] - 26 Nov 2004 09:57 GMT
1) See this article of mine:

HOWTO: Guessing the name of a command bar to add a custom menu entry in
Visual Studio .NET add-ins.
http://support.microsoft.com/default.aspx?scid=kb;en-us;555154

2) I am not sure if add-ins can get the selection of HTML windows using the
extensibility model, because I think that these use internally MSHTML. Try
this little add-in:

Public Sub OnConnection(ByVal application As Object, ByVal connectMode As
Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom As
System.Array) Implements Extensibility.IDTExtensibility2.OnConnection

 Dim objWindow As Window
 Dim objObject As Object
 Dim objHTMLWindow As HTMLWindow

 Try
  applicationObject = CType(application, EnvDTE.DTE)
  addInInstance = CType(addInInst, EnvDTE.AddIn)

  objHTMLWindow = CType(applicationObject.ActiveWindow.Object, HTMLWindow)

  objObject = objHTMLWindow.CurrentTabObject

  System.Windows.Forms.MessageBox.show(Microsoft.VisualBasic.Information.TypeName(objObject)

 Catch objException As Exception
  System.Windows.Forms.MessageBox.Show(objException.ToString)
 End Try

End Sub

For HTML windows in Design tab, you get that the type name of the editor is
"CoClassMshtml". You can get more information about MSHTML at:

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/editing/msht
mleditor.asp


Signature

Carlos J. Quintero

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com

> HI all,
>
[quoted text clipped - 32 lines]
>
> Ondrej

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.