F# interactive - "reset session" hotkey - visual-studio-2010

I have assigned a new Global hotkey to
VS 2010/Options/Environment/Keyboard/OtherContextMenus.FSIConsoleContext.ResetSession
But it seems to work only in the FSI window. How can I make the hotkey work globally?

I don't think you can do it the way you describe it (the hotkey will only work within the context of the FSI window), but you can use a VS Macro to change the focus to the FSI console, reset the session and move back;
the following worked for me: (needs additional error handling etc)
Sub ResetFSharpMacro()
Dim WindowName As String
WindowName = DTE.ActiveDocument.Name
DTE.ExecuteCommand("View.F#Interactive")
DTE.ExecuteCommand("OtherContextMenus.FSIConsoleContext.ResetSession")
DTE.Windows.Item(WindowName).Activate()
End Sub
You can then use Macros.MyMacro.... to assign a global hotkey

Related

Crash when calling getOpenFileName from QItemDelegate's custom editor

Prerequisites:
I have a custom QItemDelegate which creates custom editor for treeview items.
The editor consists of a QLineEdit and QToolButton. The button is used to open the file dialog for selecting the file and placing it's path into line edit.
I use a call to QFileDialog::getOpenFileName to open the file dialog. The dialog is native Windows file dialog (this is important).
When the editor is created the first time, everything works ok no matter how often I press that button. But after the editor is closed and reopened again the first press on the button results in a crash. The reason of the crash is that my custom editor eventually gets deleted.
Here is some code:
void CCustomEditor::on_RunSetupBtn_clicked()
{
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
if (qFilename.isEmpty())
return;
SetCommandLine(QDir::toNativeSeparators(qFilename), m_qParameters);
}
I have made some digging and found out that calling WinAPI function GetOpenFileName results in the very same way: my editor gets deleted (although crash doesn't happen). It seems that Qt calls it also internally.
I have tracked down the reason of why my editor gets deleted and found out that when getOpenFileName is called, active window changes and focus changes with it.
In the first case the focus is moved from TreeView item, but in the second case it is moved from the editor itself!
This results in the deletion of editor because of 'focus out' event.
It is important to say that this situation doesn't happen if 'DontUseNativeDialog' flag is set when file dialog is created. Therefore this should be a bug in Qt's window management between native windows and Qt widgets.
As a workaround of this bug I suggest the following solution: before making a call to getOpenFileName set the focus to the button itself.
m_pUI->RunSetupBtn->setFocus();
auto qFilename = QFileDialog::getOpenFileName(this,
"Select application to run",
QString(),
"Executable files (*.exe)");
The other workaround is to use 'DontUseNativeDialog' flag, but the resulting file dialog doesn't look native, in fact it is quite ugly.
If someone has a better solution, feel free to share.
I have a similar problem with getOpenFileName and getSaveFileName. My solution is, after getOpenFileName, getSaveFileName or at the end of the function set the windows as active with activateWindow().

Visual studio 2010 ouput window maximize on build

Is there way to automatically maximize the output window on hitting build and then to automatically restore to previous state when the build completes?
You could create a macro that builds the solution then activates the output window. For example:
DTE.ExecuteCommand("Build.BuildSolution")
DTE.Windows.Item(Constants.vsWindowKindOutput).Activate()
You could then replace the Build button or the build keyboard shortcut to execute that macro.
I could implement a solution using a combination of macros.
Part of the solution is in this SO question:
OnBuildBegin does not fire in Visual Studio Macro until I run it from Macro Explorer
And the other part is to use 2 exported window settings and to toggle them on build events.
Something like:
Public Sub BuildEvents_OnBuildBegin() Handles BuildEvents.OnBuildBegin
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-import:C:\Development\VsSettings\build_inprocess.vssettings")
End Sub
Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) _
Handles BuildEvents.OnBuildDone
DTE.ExecuteCommand("Tools.ImportandExportSettings", "-import:C:\Development\VsSettings\Two_Screen.vssettings")
End Sub

Any way to auto collapse to definitions whenever you close a document?

I know this might not sound very useful to most people, but i really like having all my code collapsed in VS and it's getting kinda annoying having to ctrl+m ctrl+o everytime i'm closing a document.
Is there some add-in that does this, or can someone give me general tips to create the add-in? thanks
You can achieve the functionality you desire by creating a macro in visual studio that executes the CollapsetoDefinitions command when ever the DocumentClosing event is raised.
Simply go: Tools -> Macros -> Macros IDE.
Then add the following code to the EnvironmentEvents module.
Private Sub DocumentEvents_DocumentClosing(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentClosing
Dim thread As New System.Threading.Thread(AddressOf CollapsToDefinition)
thread.Start()
End Sub
Public Sub CollapsToDefinition()
Try
If DTE.ActiveDocument Is Nothing Then Exit Sub
DTE.ExecuteCommand("Edit.CollapsetoDefinitions")
Catch
'Ignore any error
End Try
End Sub

How to Break All without changing window focus

When testing a Windows Forms UI I shall often want to modify the code whilst it is running. Clicking on the "Break All" arrow does this for me, however Visual Studio always displays the Program.cs window and sets focus on the Application.Run() method, which kinda makes. However most of the time I have the code I want to edit right in front of me and having to close the Program.cs window is an annoyance and something I just don't want to do.
Is there an easy way to get the code to Break in the current window?
The only way I've found is to write a little macro that will pause the code, check if a new window has been created and, if so, close it. It's not ideal and it is rather rudimentary but it does the job. I've then just added a Toolbar command called "Break In Place" which sits in my Debug Toolbar. The code for the macro if anyone is interested is:
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module Break
Sub BreakInPlace()
Dim activeWindow As EnvDTE.Window
activeWindow = DTE.ActiveWindow
DTE.Debugger.Break(True)
If Not activeWindow Is DTE.ActiveWindow Then
DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo)
End If
End Sub
End Module
To move back to your previous position use View->Navigate Backward (Ctrl + -) - once or max few times. It speeds a lot moving over latests cursor positions.
On the other hand View->Navigate Forward (Ctrl + Shift + -) lets move forward (as shown by the name).
If you've multiple computers available (or possibly even Virtual machines) you could use a remote debugger.
There is a free extension for this: Disable No Source Available Tab. Works great.
This small extension will prevent the tool window with title "No Source Available" from appearing in Visual Studio, and preserve the focus on the currently active tab.

"SVN Blame" plugin for VisualStudio

I found this question but the referenced options don't say anything about supporting "blame". What I'm looking for is an integrated way to ask "Who edited the line under the cursor last?".
I know most/all SVN clients give this in some form but I'd like something that makes it easy enough that I can do it on a whim: "Humm, who wrote that? [tap tap] Oh him."
The daily builds of AnkhSVN 2.0 have a completely new annotate (blame) implementation inspired by the TFS annotate feature.
(source: qqn.nl)
Not really visible in these screenshots, but it uses the Visual Studio editor for syntax coloring, etc. (You can see the sizeof() in the right bottom of the next image is blue). As you can see in the second picture it also allows several commands on the revision regions in the left bar.
It currently doesn't implement the jump to active line. But you can use the Visual Studio goto line (Ctrl+G) command in it. (You might be able to script this in a macro)
The easiest way to start annotate is right click on the editor ->Subversion->Annotate.
(source: qqn.nl)
[Update 2009-02-03: This feature is now commonly available in the new Stable release]
I wrote a Visual Studio macro to get line number info and pass it to tortoiseproc.exe (which is part of TortoiseSVN)
Take a look at the parameter info:
http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-automation.html
Here is my macro:
Sub Blame()
sCurrFileFull = DTE.ActiveDocument.FullName
Dim activeDoc As Document
activeDoc = DTE.ActiveDocument
Dim nLine As Integer
nLine = activeDoc.Selection.CurrentLine
sShellCommand = sTorEXE & " /command:blame /startrev:1 /endrev:-1 /path:""" &
sCurrFileFull & """ /notempfile /line:" & nLine.ToString()
Shell(sShellCommand, AppWinStyle.MaximizedFocus, False)
End Sub
I use a set of external tools wired to TortoiseProc.exe to perform SVN operations like log, diff, blame, revert, commit, update, etc. Then I create toolbar shortcuts to these external tools so that I have all the basic SVN operations accessible within the IDE.
Here are the steps to create a button to do a blame on the current file:
Go to tools -> external tools and click "Add"
Enter whatever title you want (e.g. "Blame")
For the command, enter the following (the path will be different if you installed TortoiseSVN to a different directory): c:\Program Files\TortoiseSVN\bin\TortoiseProc.exe
For the arguments, enter the following: /command:blame /path:"$(ItemPath)" /notempfile
For the initial directory, enter:$(ItemDir)
Now, whenever you have a file open, simply go to tools -> Blame and it should generate the Blame in a popup window. You can also customize the toolbar and create a shortcut for this external tool to make it even easier.
In VisualSVN supports blame to some extent - you can right-click on a file and select "Blame". However, it pops up a new window, which may not be as integrated as you want.
Here's a working version of crashmstr's and Derek Dahmer's macro code:
Sub Blame()
Dim sCurrFileFull = DTE.ActiveDocument.FullName
Dim activeDoc = DTE.ActiveDocument
Dim nLine = activeDoc.Selection.CurrentLine
Dim sTorEXE = "TortoiseProc.exe"
' Add path if you don't have TortoiseSVN on your PATH
Dim sShellCommand = sTorEXE & " /command:blame /startrev:1 /endrev:-1 /path:""" & sCurrFileFull & """ /notempfile /line:" & nLine.ToString()
Shell(sShellCommand, AppWinStyle.MaximizedFocus, False)
End Sub
As per Derek Dahmer's instructions, add it to a new or existing macro module using the Tools > Macros > Macro IDE.
For easy access, I added the macro to my code window context menu:
Customize > Commands > Context menu > Editor Context Menus | Code Window
Add Command > Macros > Find your macro
Modify Selection > Name: Bla&me
Having it in the context menu enables easy keyboard access, but you can, of course, add a keyboard shortcut to it as well. I have it on Ctrl-Shift-M, which is not used by anything useful by default :).

Resources