diff --git a/src/OneWare.Essentials/Helpers/PlatformHelper.cs b/src/OneWare.Essentials/Helpers/PlatformHelper.cs index 1027cb7..9f40cd2 100644 --- a/src/OneWare.Essentials/Helpers/PlatformHelper.cs +++ b/src/OneWare.Essentials/Helpers/PlatformHelper.cs @@ -1,4 +1,6 @@ using System.Diagnostics; +using System.Net; +using System.Net.Sockets; using System.Runtime.InteropServices; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; @@ -305,5 +307,15 @@ public static void ActivateWindow(IntPtr mainWindowHandle, IntPtr displayHandle) : KeyModifiers.Control; #endregion + + private static readonly IPEndPoint DefaultLoopbackEndpoint = new(IPAddress.Loopback, 0); + + public static int GetAvailablePort() + { + using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + socket.Bind(DefaultLoopbackEndpoint); + + return (socket.LocalEndPoint as IPEndPoint)?.Port ?? throw new Exception("Error getting free port!"); + } } } \ No newline at end of file diff --git a/src/OneWare.Essentials/ViewModels/IEditor.cs b/src/OneWare.Essentials/ViewModels/IEditor.cs index 2aad140..3d13dff 100644 --- a/src/OneWare.Essentials/ViewModels/IEditor.cs +++ b/src/OneWare.Essentials/ViewModels/IEditor.cs @@ -6,7 +6,12 @@ namespace OneWare.Essentials.ViewModels; public interface IEditor : IExtendedDocument { public ExtendedTextEditor Editor { get; } + public TextDocument CurrentDocument { get; } + public void Select(int offset, int length); + + public void JumpToLine(int lineNumber, bool select = true); + public event EventHandler? FileSaved; } \ No newline at end of file