Saturday, September 17, 2016

VS2015 Tips - Useful Commands in Solution Explorer Toolbar

After a brief hiatus, I started coding again and developing with Visual Studio 2015 Professional.  Came across the following new commands (at least new to me) that I wanted to share:

Pending Changes Filter (Ctrl+[, P)

I wanted to create a summary of my changes and was hoping it allows me to filter only those files that are changed/added.  Sure enough, there is such an option.  Right next to the Home icon in the Solution Explorer panel you see a Clock icon with the tooltip "Pending Changes Filter" as shown below. It did exactly what I needed. 

Open Files Filter (Ctrl+[, O)

If you do not see this Clock icon, then you should see the Open Files Filter as shown below.  Once you click on it, it should only show the files that you have currently opened.

Sync with Active Document (Ctrl+[, S)

I remember having to hunt down this setting in the Options menu to sync the current file open with the item in Solution Explorer, but having it always sync gets in the way too.  So instead of having it always sync, but when you need it is really useful. 

Preview Selected Items

The following option is really nice as you want to quickly browse through the contents of various files, you can do so without actually having to open them.  Just have all the documents closed and this icon selected and then click on the items in Solution Explorer to have it simply show the contents of each file you selected.  You do not want to double-click on any item as that will open it. It won't do anything for images, references or any other binary files.  It seems to work only for files that of type "text."

I do not remember seeing these options in earlier versions of Visual Studio, so very happy to find these in VS2015.

Have Fun Coding!


C# Object Initialization Examples (Cheat Sheet)

I really like the elegant object initialization facility in C# (I believe you can do the same in VB.NET also). Here are some examples of how you might initialize objects: Hope you find this cheat-sheet useful. Sonny

IE and setting HTML Global Attribute draggable to true results in weird behavior

I recently had to make a popup dialog box draggable or movable so that the user can read the text underneath it. I found the HTML Global Attribute draggable and set it to true. As the MDN page suggests, it does not quite work at least in the browsers I tested. I ended up adding an Angular Directive for draggable behavior as detailed on Angular Docs page. A working version of this directive can be seen on Plunker. Couple of things to be aware of if you are using somewhat similar approach: 1) I happened to have an input form in this dialog box and I could not enter text into any of the input fields. This is because of the event.preventDefault() line in the element.on event. Comment this line if you are making a draggable/movable input form. 2) Even though I was able to get the drag/move behavior for my dialog, I left the draggable="true" in there thinking it could not possibly hurt. Turns out that it is causing a weird behavior in IE. When I click on an input text box to enter text, I was not getting the input cursor and I had to double-click on it. Also when I double-click, it puts the focus at the beginning of text instead of where I double-clicked. Once I remove the draggable attribute, everything is working as expected. I spent quite a bit of time trying to figure what caused this weird behavior and hopefully this tip would help others find a solution quicker. Happy Coding! Sonny