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

Tip: Looking for answers? Try searching our database.

Urgent : Event Handling in VS .NET 2003 Extensibility

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pravin - 01 Feb 2005 05:45 GMT
Hi All,

I'm working with VS .NET Add-Ins. Using Visual Studio Extensibility
(EnvDTE) I have disabled the context-menu (right-click) mouse event of
deleting a project item. But I'm unable to lock/disable the Keyboard events.
If I select an project item and press the "Delete" key in the keyboard, the
VS .NET will does the process of deletion.

In the VS Extensibility, I come to know about the ProjectItemsEvents and the
following events:   
    (a) ItemAdded    
    (b) ItemRemoved
    (c) ItemRenamed

For above mention situation, I can't use ItemRemoved. Because it fires after
the removal of the project item.

In normal event handlers of System.EventArgs we will use e.Cancel = true to
stop the event proceeding further. But I couldn't find such an option here.

Kindly reply, if you have the solution.....

Awaiting your response...

Thanks in advance,
Pravinkumar KN
Dmitry Shaporenkov - 01 Feb 2005 10:03 GMT
Hello Pravin,

if I remember correctly, what you're trying to do is impossible when using
only Extensibility.
You need to use VSIP (it's easy to do in add-ins) and subscribe to the IVsTrackProjectDocuments
interface
that allows to cancel project items removal.

Regards,
Dmitry Shaporenkov

> Hi All,
>
[quoted text clipped - 23 lines]
> Thanks in advance,
> Pravinkumar KN
Carlos J. Quintero [.NET MVP] - 01 Feb 2005 13:38 GMT
Yes, there are no Before and After ProjectItemsEvents. Your best change is
to intercept the execution of the Edit.Delete command, which has
before/after and cancel in the before event (CancelDefault = True). There is
a bug in VS.NET using this approach, though. Anyway, go to my web site page:

http://www.mztools.com/resources_addin_developers.htm

and look at this article which illustrates what you want and the bug:

BUG: Command events fired only to last addin loaded in Visual Studio .NET.
http://support.microsoft.com/default.aspx?scid=kb;en-us;555090

Signature

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com

> Hi All,
>
[quoted text clipped - 28 lines]
> Thanks in advance,
> Pravinkumar KN
Pravin - 01 Feb 2005 15:25 GMT
Hi Carlos,

Thanks for your reply.
I have worked with your solution. It locks "Delete" key totally. It behaves
as desire in Solution Explorer Window. But in the Document Window, I'm unable
to delete the selected text.

So what the solution I'm implementing, it should affect Solution Explorer
Window only.

Also wish to know, whether is it possible to lock the Solution Explorer
Window.

Awaiting your response...

Thanks in advance,
Pravinkumar KN.

> Yes, there are no Before and After ProjectItemsEvents. Your best change is
> to intercept the execution of the Edit.Delete command, which has
[quoted text clipped - 40 lines]
> > Thanks in advance,
> > Pravinkumar KN
Carlos J. Quintero [.NET MVP] - 01 Feb 2005 16:43 GMT
I guess. So, you need to detect the "context" of the Delete action:

- The first thing is to guess if the Solution Explorer toolwindow is active
or not.  To do this you use DTE.ActiveWindow and then compare Window.Kind
against EnvDTE.Constants.vsWindowKindSolutionExplorer. Be sure not to use
captions since they are localized.

- If the Solution Explorer is the active window and you want to block only
project item deletions, then you have 2 ways:

* Use DTE.SelectedItems and for each SelectedItem use
SelectedItem.ProjectItem to see if it is a ProjectItem
* Use DTE.ActiveWindow.Object, cast to UIHierarchy, retrieve recursively
UIHierarchyItem and check UIHierarchyItem.IsSelected and
UIHierarchyItem.Object is ProjectItem.

Signature

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com

> Hi Carlos,
>
[quoted text clipped - 15 lines]
> Thanks in advance,
> Pravinkumar KN.
Pravin - 02 Feb 2005 06:41 GMT
Hi Carlos,

Your idea is working. Thanks for that.
But  comparing with ActiveWindow.Kind is not working. So I tried this way:
applicationObject.ActiveWindow.Type ==
vsWindowType.vsWindowTypeSolutionExplorer

and it is working fine now.

Also I have to stop firing the Cut (ctrl+X), Copy (ctrl+C), Paste (ctrl+V),
Rename (F2 - Function Key) events in the Solution Explorer, when the user
tries with the corresponding KeyPress. (I've disabled the corresponding
Context-Menu items of the mouse right-click).

Kindly help me to solve this issue.

Awaiting your response...

Thanks in advance,
Pravinkumar KN.

> I guess. So, you need to detect the "context" of the Delete action:
>
[quoted text clipped - 31 lines]
> > Thanks in advance,
> > Pravinkumar KN.
Carlos J. Quintero [.NET MVP] - 02 Feb 2005 10:10 GMT
> But  comparing with ActiveWindow.Kind is not working. So I tried this way:
> applicationObject.ActiveWindow.Type ==
> vsWindowType.vsWindowTypeSolutionExplorer
> and it is working fine now.

Ah, yes, I told by heart.

> Also I have to stop firing the Cut (ctrl+X), Copy (ctrl+C), Paste
> (ctrl+V),
> Rename (F2 - Function Key) events in the Solution Explorer, when the user
> tries with the corresponding KeyPress. (I've disabled the corresponding
> Context-Menu items of the mouse right-click).

I think that those keyboard shortcuts execute underlying commands such as
Edit.Copy, Edit.Cut,etc, so you can apply the same approach.

Signature

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com

Pravin - 02 Feb 2005 15:11 GMT
Hi Carlos,

Thanks for your smart & timely responses.

Other name "Rename" functionality, the things work fine.

For Rename, I have tried the command "File.Rename". But it is not working
and allows me to change the Project Item name by pressing the function key -
F2.

Kindly help me to solve this issue.

Thanks in advance,
Pravinkumar KN.

> > But  comparing with ActiveWindow.Kind is not working. So I tried this way:
> > applicationObject.ActiveWindow.Type ==
[quoted text clipped - 11 lines]
> I think that those keyboard shortcuts execute underlying commands such as
> Edit.Copy, Edit.Cut,etc, so you can apply the same approach.
Dmitry Shaporenkov - 02 Feb 2005 15:52 GMT
Hello Pravin,

will your solution work if some other add-in decides to remove a project
item programmatically using ProjectItem.Delete method?
I doubt that the abovementioned approaches will help to prevent that. Of
course, may be you're not going to prohibit a programmatic
deletion of a project item...

What I'm trying to say, if your real intention is to control the VS project
model, you cannot do that using Extensibility only, you need
to use VSIP API. If you target only the specific scenarios discussed in this
thread, the proposed solutions work well, though you need
to check many unrelated things (you need to know about windows, commands,
shortcuts, project items events etc),
while implementing IVsTrackProjectDocumentEvents in your class will give
you all you need at once.

This is not a advertisement of VSIP, VSIP is difficult to use, poorly documented
and sometimes simply awkward especially when called from
managed code (let MSFT forgive me for this grumble :)) But there are many
things that can be done only with VSIP - this is by design, and
it looks for me that you're trying to do one of such things.

Regards,
Dmitry Shaporenkov

> Hi Carlos,
>
[quoted text clipped - 34 lines]
>> MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET You can
>> code, design and document much faster. http://www.mztools.com
Carlos J. Quintero [.NET MVP] - 02 Feb 2005 19:01 GMT
Yes, I agree with you, maybe VSIP is the only way. Also, it would be
interesting to hear why Pravin wants to prevent deletion of project items,
Pravin?

Signature

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com

> Hello Pravin,
>
[quoted text clipped - 19 lines]
> Regards,
> Dmitry Shaporenkov
Pravin - 03 Feb 2005 06:03 GMT
Hi Carlos,

It's because:

For my project reasons, if I'm adding/deleting/modifying a project item,
I've to keep track of the items and on any change, I've to process (for
instance, if I'm deleting a Project Item and some other item depends on this
item then I should stop the deletion process) and then to update the changes
in the database.

So the idea is
(1) Create a routine that has your business logic to be executed before
Project Item deletion.

(2) Create your own "Delete" menu and restrict the usage of VS .NET "Delete"
menu. On menu click call the routine.
(or)
(2) Make VS .NET IDE to execute the routine before deletion by pressing its
"Delete" menu-item.

(3)  After successful execution, delete the project item.

Hope you can understand the situation now.

BTW, kindly let me know the VSIP help, tutorial urls that you know.

Thanks in advance,
Pravinkumar KN.

> Yes, I agree with you, maybe VSIP is the only way. Also, it would be
> interesting to hear why Pravin wants to prevent deletion of project items,
> Pravin?
Carlos J. Quintero [.NET MVP] - 03 Feb 2005 09:41 GMT
I understand now.

The URLs are:

Downloads:
http://www.vsipdev.com/downloads/

VSIP for newbies:
http://blogs.msdn.com/aaronmar/

Signature

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com

Dmitry Shaporenkov - 03 Feb 2005 10:27 GMT
OK, so if I understand correctly, Pravin wants to trigger some routine
whenever a project item is about to delete and allow deletion only
if the routine completes without errors.

How you'd do this using VSIP:

1) Create a class that implements IVsTrackProjectDocumentEvents2 interface.
In the method implementing
IVsTrackProjectDocumentEvents.OnQueryRemoveFiles, you need to run your routine
and set the result flags
(of type VSQUERYREMOVEFILERESULTS) accordingly hence telling VS if the items
can be removed. You may also
want to handle other OnQuery... methods

2) Retrieve a reference to the IVsTrackProjectDocuments interface using
IServiceProvider.QueryService method. You can obtain a reference to IServiceProvider
by simply casting the
EnvDTE.DTE object given to your add-in in the OnConnection method. This is
an undocumented but legal trick which
makes using VSIP from add-ins easy.

3) Advise your listener to the IVsTrackProjectDocuments using IVsTrackProjectDocuments.AdviseTrackProjectDocumentsEvents
method.

4) ... Ask your questions if you still have problems.

To the links provided by Carlos, I may add the specific project system interfaces
mentioned in this post - you can find their descriptions
in VSIP docs.

Hope this helps.

Regards,
Dmitry Shaporenkov

> I understand now.
>
[quoted text clipped - 6 lines]
> MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET You can
> code, design and document much faster. http://www.mztools.com
Pravin - 10 Feb 2005 05:21 GMT
Hi Dmitry Shaporenkov,

Regretting for the delayed response.
Hope VSIP is apart from our project scope. Any how, I've taken the issue to
my lead.
Thanks for you & Carlos for providing the timely replies.
BTW, I wish to know about VSIP personally. I'm new to VSIP. I need the basic
help regarding VSIP that where & how to start.
Kindly help me in this regard.

Thanks in advance,
Pravinkumar KN.
Dmitry Shaporenkov - 10 Feb 2005 16:58 GMT
Hello Pravin,

just download VSIP from MS site and take a look at the documentation integrated
into MSDN collection. It contains some useful information.
You can also check the VSIP site for presentations (.ppt) depicting VS's
architecture and VSIP in general.

Regards,
Dmitry Shaporenkov
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

> Hi Dmitry Shaporenkov,
>
[quoted text clipped - 9 lines]
> Thanks in advance,
> Pravinkumar KN.
Pravin - 03 Feb 2005 05:31 GMT
Hi Dmitry Shaporenkov,

Thanks for the interest shown to help me.
I'm new to VSIP and if you can, kindly let me know the VSIP help tutorial
urls.

Thanks in advance,
Pravinkumar KN.

Let me check VSIP can  

> Hello Pravin,
>
[quoted text clipped - 60 lines]
> >> MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET You can
> >> code, design and document much faster. http://www.mztools.com

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.