Visual Studio macro that navigates to file and function of selected text - c#

I work a lot with WPF, and have lots of files in a project which makes navigation sometimes a bugger. I tried to write a macro that helps me at it, but I haven't managed doing so far after struggling a few hours. And not using VB at all, it makes it a bit harder. Maybe someone can push me into the right direction, or help me out to accomplish it.
What I try to achieve is the following macro:
Retreive the selected text
-> CType(objDocument.Object, EnvDTE.TextDocument).Selection
Check if the word starts with 'Controllername'
-> text.Startswith("Controllername"))
Remove double qoutes
-> Text.Replace(Chr(34), "").Split("/")
Search for the file in the project where the function is located
Go to the line number of that function
The reason why I want to create this macro is because of the fact that in WPF, I use actionlinks which refer to a "controller/action", which is in stringformat. With this macro I could select the "controller/action" text, hit the keybinding, and go to the function (or display an error for instance if it doesn't exist).
Thanks for the input in advance! :)

Related

How can I open a text file with my executable?

I want to right-click on a text file and "Open With..." it with my own program, but I can't find any information on how to do that. I want to make my program in C++ or with WinForms (C#).
I want to open that file and to use my program as an interpreter on a small "homemade programming language", so I want to pass the data from the file directly to my program.
Can anyone help me?
*hope I'm clear enough on what I'm trying to do.
I'm just gonna to answer your Question for C#. If you still need C++ support you can tell me.
Option 1 - Drop down:
So if you for example create a Console-Application in C# (Visual Studio), it will look like this:
As you can see in the Picture: the Program accepts Arguments (args String Array)
If you drag & drop your file on your .exe, the filepath of the file you dropped will be saved in the args String Array. Now you can read the file (for example with the File-Class).
Option 2 - Right Click -> Open with my Program:
For that, you can simply add a new entry in HKEY_CLASSES_ROOT\Directory\Background\shell (Windows Registry) to register you Program as a "Right Click Menu Program".
Here is a detailed How-To:
https://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/
After you added your Program to the Windows Registry you can proceed as shown in Option 1 (args).
Any more questions? Let me know.
Greets
Bennet
EDIT:
Sorry, didnt really read the comments :D but i guess your Question is answered. I will let this stay here for future readers which dont read the comments either ;)

C#.NET & Translation of external component

I'm maintaining one program written in C# 2.0 (VS2005). It has pretty large codebase, lot of authors, it is almost internal app, but currently it is also one of our customers using it.
App is multilingual and translation of own forms and components works OK. But, there is one component - DockPanel Suite by WeifenLuo and I need to translate it to another language (zh-CN) - one of the chinese guys translated resource file to his language and now I'm trying to include and use in application, but I'm failing in it - although whole app is in chinese, this component remains in english. The untranslated resource file can be found on github: https://github.com/dockpanelsuite/dockpanelsuite/blob/master/WinFormsUI/Docking/Strings.resx
How to do that? I tried almost everything, naive approach (just resgen and compile by al, and trying to use it as satellite assembly - also tried ilmerge), then opening DockPanelSuite in VS2013 Express, adding resx as Strings.zh-CN.resx, but nothing works and tooltips and others are still in english.
Tried also stepping-in with debugger, but debugger broke at tooltip = Strings.DockPaneCaption_ToolTipAutoHide but it didn't step into getter defined in Strings.Designer.cs
I'm stuck and I don't know, how to do that. Any idea? Thanks very much!
I was able to translate a label in the demo application in a very simple process:
git clone the library
Copy & paste the Strings.resx file
Rename the copy into Strings.pt-BR.resx
Compile, it's done (in my case, I translated the "Close" label)
however, this project contains many Strings.resx files
Did you change all of them? Or did you just change one? (maybe a wrong one, like I did in my first try)

How to search for text within in a solution while excluding certain projects?

How do I find text in my Visual Studio solution while excluding certain projects? Preferably a macro within the text editor window itself and/or a setting somewhere.
Example: I want to find every instance of the text "barcode" in my solution but I want to exclude looking at the "LotsOfBarcodes" project because I already know that text string exists there a lot.
I'm not sure if this is acceptable to you, but one option is to temporarily unload the project(s) that you don't want to search from your solution. Follow that with a Look in: Entire Solution option in the Find and Replace dialog box. Reload the projects when you are done.

Visual Studio 2010 renaming project and main forms

I guess a lot of people start working on something. And then later they find-out the names don't really cover the end product. Or well at least, I do choose often poor names for stuff, I start programming faster then thinking about things like that (in the end I often rename my buttons too so my code becomes more clear too).
What is the best way of a current work in progress (not finished) to rename it? Without breaking the code, or do a lot after editing.
The reason I ask it here is I've seen it gone wrong a few times, leaving me code that didn't work any more so I better as how to do this and where in which pane, it's best to rename.
So what's wrong? Well in the upper right pane of Visual Studio 2010 C# (solution explorer):
The solution itself has a wrong name
The next line of it has the wrong name
And the main form could be improved too
If you were to rename the main form it would ask you if you want to change all references to it, you say yes and that problem is solved.
Renaming the solution is equally simple, just right click in the Solution Explorer and rename. It won't break your local build or anything.
I don't know what "The next line of it has the wrong name" is referring to (the project maybe?) but the same probably goes for it.
Well usually you should change the file name of your class in the solution explorer and it should ask if you want to change all references, though sometimes it can go wrong so to double check you can replace all command to find all references of old name and replace with the new one..
http://msdn.microsoft.com/en-us/library/139eef4h.aspx
Also if you change in code, the name of a class or variable or anything and then you should see small line under the changed name, stand with the mouse pointer on the variable and press ctrl+. (ctrl dot) And that shoul pop up small options and the first one should let you change all references of that variable new name also:
http://www.dofactory.com/ShortCutKeys/ShortCutKeys.aspx

C# Program Settings and Localizing

So I'm starting my first actual Program in C# now, and just before I dig into the actual functions, I'm asking myself about localization of a Program.
I thought, a .resx is nice for the language-variables to store. But how can I get that into the settings? I see there is a .settings file, where I can assign Settings for the program, but how can I add my language.resx to these settings, so if there are several installed the user can select which language to use?
Furthermore, I'm designin the program using the winform designer - how can I tell a control to use a string of the resourcce as a text rather than type it in by hand?
I'm sure there are a bunch of tutorials out there concerning my issues, but 2 hours of searching haven't got me anywhere, so if anyone has some suggestions for me, I'd be very thankful =)
This seems to be similar to question 1142802, so maybe that is a good place to start.
ed:
It depends on the control a bit I guess, but for a menu you could create a method that defines it's contents.
You'd then be able to do something like menuItem1.Text = string.Item1Text.

Categories

Resources