Copy and Paste Formatting with Visual Studio’s Dark Theme May 17, 2013
Posted by codinglifestyle in CodeProject, Visual Studio, Visual Studio 2012.Tags: copy, dark, dark theme, fomatting, format, paste, theme
12 comments
I recently upgraded to VS2012 and, like most of you, was aghast at the default theme. Sure, after installing the updates the blue theme was good. But before updating I tried the dark theme… and I liked it! As our phones and tablets often use dark themes and websites are being remade to look like tablet apps the dark theme had a modern look to it and is easy on the eyes.
Look, it doesn’t matter what I think of the dark theme. I simply want to discuss an undesirable side effect affecting Copy & Paste (don’t forget Cut too). When copying code to an email, Word, or your IM window you realize the dark theme has a dark side:
What we get in the first paste attempt is a WYSIWYG copy of the formatting from Visual Studio. Clearly what most of us want is the second paste attempt. And the formatting issue can get even worse. When pasting to some programs you get white text on a white background. The problem is so obvious it seems the people who made the dark theme don’t actually use it day to day.
I was finding that I needed to: open options, select the blue theme, copy my code to the clipboard, open options again, and reselect the dark theme.
What a tedious workaround! So I went on a quest this morning and am happy to report I have a solution!
- Open Tools → Extensions and Updates
- Select Online (Visual Studio Gallery) and search for Productivity Power Tools 2012
- Download and restart Visual Studio when prompted
- Open Tools → Options
- Expand Productivity Power Tools and select HTML Copy
-
Change the BeforeCodeSnippet option to:
- <style type=”text/css”>.identifier {color:black !important;}</style><pre style=”{font-family}{font-size}{font-weight}{font-style}”>
- <style type=”text/css”>.identifier {color:black !important;}</style><pre style=”{font-family}{font-size}{font-weight}{font-style}”>
-
Change EmitSpanClass to:
- True
- True
-
Check EmitSpanStyle is:
- True
- True
You may want to optionally turn off all other features other than HTML Copy from the “All Extensions” menu.
Let’s take a look at what this feature is doing. When you copy text to the clipboard you can have multiple data formats such as Text, RTF, and HTML. When we’re pasting our code in to Word or an email it will typically use the HTML format (configuration dependent). Here is what we actually see in the clipboard when we do a copy after configuring VS as above.
</pre> <!--StartFragment--> <style type="text/css"> .identifier { color: black !important; } </style> <pre style="font-family: Consolas; font-size: 13;"><span class="keyword" style="color:#569cd6;">var</span> <span class="identifier" style="color:white;">bob</span> <span class="operator" style="color:#b4b4b4;">=</span> <span class="keyword" style="color:#569cd6;">string</span><span class="operator" style="color:#b4b4b4;">.</span><span class="identifier" style="color:white;">Empty</span>; </pre> <!--EndFragment-->
Note that we’ve removed the background colour which means all of our identifier text is being set as white on a white background. However the style element is overriding the identifier color and setting it to black. This gives us the desired results:
var bob = string.Empty;
VS Solution Explorer – Collapse All May 15, 2009
Posted by codinglifestyle in CodeProject, Visual Studio.Tags: collapse, macro, ReShaper, solution, Visual Studio, vs2008
1 comment so far
I never knew I needed this until I saw it was a feature in a ReSharper demo. After a quick search and I found a macro that has been around for years. Slap to the head! The amount of time I spend collapsing all my solution folders and this existed the whole time!
I never use macros, but even I was able to quickly get this working.
- Open Tools->Macros->Macro Explorer (Alt-F8)
- Right click MyMacros
- Select New Module
- Select default template and name to VSMacros
- Right-click VSMacros and click New Macro
- Copy and paste this over the opened macro file
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module VSMacros
Sub SolutionCollapseAll()
‘ Get the the Solution Explorer tree
Dim solutionExplorer As UIHierarchy
solutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
‘ Check if there is any open solution
If (solutionExplorer.UIHierarchyItems.Count = 0) Then
Return
End If
‘ Get the top node (the name of the solution)
Dim rootNode As UIHierarchyItem = solutionExplorer.UIHierarchyItems.Item(1)
rootNode.DTE.SuppressUI = True
‘Find selected node
Dim selectedNode As UIHierarchyItem = FindSelectedNode(rootNode, solutionExplorer)
‘ Collapse each node
Collapse(selectedNode, solutionExplorer)
‘ Select the selceted node
selectedNode.Select(vsUISelectionType.vsUISelectionTypeSelect)
rootNode.DTE.SuppressUI = False
End Sub
Private Sub Collapse(ByVal item As UIHierarchyItem, ByRef solutionExplorer As UIHierarchy)
For Each innerItem As UIHierarchyItem In item.UIHierarchyItems
If innerItem.UIHierarchyItems.Count > 0 Then
If innerItem.UIHierarchyItems.Expanded Then
‘ Re-cursive call
Collapse(innerItem, solutionExplorer)
End If
‘ Collapse
If innerItem.UIHierarchyItems.Expanded Then
innerItem.UIHierarchyItems.Expanded = False
If innerItem.UIHierarchyItems.Expanded = True Then
‘ Bug in VS 2005
innerItem.Select(vsUISelectionType.vsUISelectionTypeSelect)
solutionExplorer.DoDefaultAction()
End If
End If
End If
Next
End Sub
Private Function FindSelectedNode(ByVal item As UIHierarchyItem, ByRef solutionExplorer As UIHierarchy) As UIHierarchyItem
If item.IsSelected Then
Return item
End If
For Each innerItem As UIHierarchyItem In item.UIHierarchyItems
If innerItem.UIHierarchyItems.Count > 0 Then
If innerItem.UIHierarchyItems.Expanded Then
‘ Re-cursive call
Dim result As UIHierarchyItem
result = FindSelectedNode(innerItem, solutionExplorer)
If Not result Is Nothing Then
Return result
End If
End If
If innerItem.IsSelected Then
Return innerItem
End If
End If
Next
Return Nothing
End Function
End Module
- You may now execute the macro via the Macro Explorer. Click the folder you wish to collapse (or the Solution root to collapse everything). Right click and run the macro. To set a shortcut continue on with the steps below…
- Click Tools->Options->Environment->Keyboard
- Search for your macro in the Show commands containing textbox
- Select your macro, keep scope global, and in the assign macro keys textbox enter your preferred shortcut (I used “ALT-CTRL-\”)
- Click ASSIGN and then OK
- To use, select a node and then ALT-CTRL-\. To collapse the entire solution, select the root of the solution.
Reference: http://www.codeproject.com/KB/macros/collapseall.aspx?df=100&forumid=7565&exp=0&select=396167
VS2005 Web Setup Projects August 17, 2006
Posted by codinglifestyle in ASP.NET, Visual Studio.Tags: project output, setup, web deployment, web project
add a comment
Upon wrapping up my first major project on VS2005 I went to create a web setup project and noticed what I thought was a bug. When adding Project Output and selecting my website, only Content files were listed. This would include source code rather than being a release version of the project. Being that this behavior differs from VS2003 my collegues were at a loss to explain it and googling didn’t yeild much. I was forced to Add Files which referenced the files I wanted but was sure this wasn’t correct. After another round of googling I found the answer:
For some reason beyond me, you need to create an interim project which will hold the deployment of the web site. You may then add this project to your setup and select Project Output. But wait, there’s more. You can’t create a deployment project out of the box, because they didn’t seem fit to include it as standard.
- So, what you need to do first is download the Web Deployment setup from Microsoft which allows you to create the interim deployment project: http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx
- After this is installed and you restart VS2005, right click your web project and select “Add deployment project”. This project allows you to specify how you’d like your assemblies compiled and few other options.
- Now create a Web Setup Project, add Project Output, select the deployment project and the configuration.
Congratulations, you’ve now done in three steps what you used to be able to do in two.