Files
HLCaptain 2eb0a05145 Updated dependencies and added VS22 compatibility (#22)
* Dependencies updated to support VS22.

* Close throws exception if not running on main thread. Roslyn dependency set.

* Updated Visual Studio version to 2022 in README.md

* Updated dependencies. May break previous VS19 builds. Works on VS22 17.0.4.

* Updated dependencies, working properly with VS22, NOT WORKING WITH VS19, VISIT 1.X BRANCH TO WORK WITH VS19.

* Requirements updated in README.md

* Version updated to 2.0.0

* Reverted commit 35f18ad. Changed back Test project dependencies.
2022-01-25 20:07:03 +01:00

56 lines
1.7 KiB
C#

using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using EnvDTE;
using GodotTools.IdeMessaging;
using GodotTools.IdeMessaging.Requests;
using Microsoft.VisualStudio.Shell;
namespace GodotAddinVS.GodotMessaging
{
public class MessageHandler : ClientMessageHandler
{
private static ILogger Logger => GodotPackage.Instance.Logger;
protected override async Task<Response> HandleOpenFile(OpenFileRequest request)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var dte = GodotPackage.Instance.GetService<DTE>();
try
{
dte.ItemOperations.OpenFile(request.File);
}
catch (ArgumentException e)
{
Logger?.LogError("ItemOperations.OpenFile: Invalid path or file not found", e);
return new OpenFileResponse {Status = MessageStatus.InvalidRequestBody};
}
if (request.Line != null)
{
var textSelection = (TextSelection)dte.ActiveDocument.Selection;
if (request.Column != null)
{
textSelection.MoveToLineAndOffset(request.Line.Value, request.Column.Value);
}
else
{
textSelection.GotoLine(request.Line.Value, Select: true);
}
}
var mainWindow = dte.MainWindow;
mainWindow.Activate();
SetForegroundWindow(mainWindow.HWnd);
return new OpenFileResponse {Status = MessageStatus.Ok};
}
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
}
}