Extend visual studio code editor - visual-studio-2013

I'm looking at creating an extension that can essentially generate code at the cursor position.
So to use the extension you would click anywhere (for example in a method), and then right click, context menu comes up, select a custom menu option (something that is part of the extension), and then after this selection it would run some business logic and generate code at the cursor position.
As far as I know T4 templates are only good for generating whole files. So I guess the route to go is create an extension.
Just to be clear I'm not looking for a full solution, just a overview of what to how to go about doing this. I've started by creating a Visual Studio package.
And now would like to just get some basic grips with what objects to use to implement the custom right click command and how to deal with the active document.
Just a push in the right direction would be great.

You need to create a command in your VSCT, handle it using MenuCommandService, get the active text view, and replace or insert text into its buffer.

Related

Visual Studio Team Explorer Extension

I am trying to create an extension for Team Explorer window in VS2017.
I want to put another button on the changes screen, or even hook into the commit method, so that I can take the comments, and integrate with a Kanbanize board.
It seems like it should be possible to but a button onto the Team Explorer window, but there doesn't seem to be any documentation I can find, or examples.
I have looked around and can only really find this link below, which I tried but doesn't seem to work, but isn't really what I am wanting to do.
https://hamidshahid.blogspot.com/2017/09/extending-team-explorer-in-vs2017.html
The Team Explorer extensibility is designed to enable adding new sections to an existing page, but altering the existing sections to change their UI/behavior is not allowed. Given this design constraint, you can add your own UI, but it'll need to be in a separate section. You should be able to read the selection data from other sections on the Git Changes page via IChangesExt.
Hope this helps.

How do I prevent Sharp Develop from renaming my controls?

I'm using a TabControl. I want to paste lots of controls from one tab to another but I want to only add a number at the end of the current name of each control so I don't have to name them all over again.
Is there a way to prevent auto renaming in Sharp Develop?
This method is of no use in SharpDevelop!
So I am assuming you are using the Windows Forms designer in SharpDevelop.
Currently SharpDevelop has the same behaviour as Visual Studio. If you copy and paste a control, say a button, it will create a new button with a name of button1. The Windows Forms designer needs a unique name for each control so they have to be given a new name.
One possibility would be to only add a number at the end of the control and keep the rest of the name. However this is not currently implemented. To get this feature you would have to modify SharpDevelop's source code. However I am not sure this is straightforward to do.

Is there a way to record and replay coding in visual studio 2012?

I'm going to do demo based presentation. So what I want is prerecord(not a video record) my demo and replay while the I'm doing the presentation. Pre-record and play as in save code segments and generated some kind of list and then when I click on the list item generate relevant code and insert into code editor. Is there any macro base or any other way to do this?
Please do ask question if this is not clear.
Update 1
#jerek has answered the initial question. Going forward is there anyway to replace/edit existing code?
Open Toolbox (View | Toolbox)
Select code from editor
Drag and Drop into Toolbox (you can give it a short name from context menu)
When needed drag and drop back from Toolbox back to code editor
PS: 3b - instead of drag and drop you can also paste code from clipboard using context menu on Toolbox window
The Undo and Redo stack buttons are really useful. They might be enough for what you want to do (basically CTRL-Z and CTRL-SHIFT-Z but you can roll forward over multiple redo's)
This might be a bit basic, but essentially will allow you to go forwards and backwards through your edits.
With Visual Studio, you can code everything and then undo and redo your work. Then record everything with one of these.

Associate web page with project in Visual Studio

Is there any way to associate a web page with a project in Visual Studio, and have it load up in the IDE? For example, I have a project who's task list is maintained on a web site. It would be ideal to see those tasks within the IDE instead of a separate page. I can accomplish that now by following these steps:
Press Ctrl-Alt-R to open a Web Browser page
Change the URL to my desired path
Position the page as desired (like in its own tab group, off to the right of my code)
It would be nice to have a link somewhere in my project that I could click and open this page in the IDE without changing the URL every time. I have several different projects that would benefit from this. Any ideas?
Something like this happens with Visual Studio Team Foundation Server. The various documents and guidance associated with your current Team Project area accessible from within Visual Studio, in the Team Explorer window.
You can also create a Guidance Package to apply various commands and pieces of documentation at appropriate places within your projects. see Guidance Automation Extensions and Guidance Automation Toolkit.
Nice idea. The only thing that I can think of is via Visual Studio Extensibility. Basically,
Define an MSBuild property in the project file or a custom field in the solution file that has the project url.
Write a VS package that subscribes to the solution load event or something similar (I am not familiar with VS object model but I am sure there is an event like that) and looks for that custom field and extracts the url if it exists in the solution or the project file and then opens a web browser within VS that points to that url.
Here's my quick hack around this problem:
Create a text file in the project. I called my "notes.txt", and I use it to store notes, ideas, etc. that don't have a home elsewhere in the project.
Add the web link to the top of the file.
Open the text file in the IDE and put it in a new tab group. I put mine in a vertical tab group off to the right.
Drag the separator as far over as it will go to "hide" the tab group. This way it's always open and available but not taking up much space.
When you want the web page, "show" the tab group (i.e. drag the separator back) and ctrl-click the link.
This has the added benefit of opening the web page in the same tab group as the text file, so you can push them both aside when not using them.
I'm sure there's more that could be done by writing packages as others have suggested, but this was a low-effort way to get me close enough to what I wanted. I'd love to hear other suggestions or modifications that might make this setup better.

How do I edit work items in the Visual Studio 2008 xml editor?

I'm trying to customize some TFS work items via the VS2008 xml editor, but every time I open a work item xml file it jumps to the graphical designer. All that gives me is a "View XML" button that doesn't let you edit the xml directly.
I don't have TFS but I know in regular VS there is an Open With... option in most items' contextual menu that even let you change the default editor. Very useful when you are tired of the Designer opening instead of the Code file on Windows forms.
Ah, looks like you have to go to File->Open and click the down arrow next to the Open button to "Open With" the xml editor. If someone wants to copy and paste this, free accepted answer :P
As per Coincoin's answer, this feature is also great for setting the default editor for ASPX. If you want to go to the Code Editor most often, then this is a default you'd want to change.
Reading this - I think perhaps you don't realize - that there is no need to edit the XML - in fact it is very difficult to do so. The graphical designer will actually let you change the Work Item type, adding new fields, changing workflow, rules etc.
The only reason to change the XML is if there's a bug in the Process Editor (the tool that gives the graphic designer). I have done extensive modifications of Work Item types and only had one instance where I had to change the XML.

Resources