mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
Ready for Review - [Mouse Without Borders] - refactoring "Common" classes (Part 3) - #35155 (#36950)
* [MWB] - refactoring MachineInf from Common.MachineStuff.cs into MachineInf.cs - #35155 * [MWB] - fixing references to MachineInf - #35155 * [MWB] - cleaning up MachineInf.cs - #35155 * [MWB] - moving MyRectangle from Common.MachineStuff.cs into MyRectangle.cs - #35155 * [MWB] - cleaning up MyRectangle.cs - #35155 * [MWB] - moving Common.MachineStuff.cs to MachineStuff.cs - #35155 * [MWB] - fixing references to MachineStuff - #35155 * [MWB] - cleaning up MachineStuff.cs - #35155 * [MWB] - cleaning up MachineStuff.cs - #35155 * [MWB] - moving Common.DragDrop.cs to DragDrop.cs - #35155 * [MWB] - fixing references to DragDrop - #35155 * [MWB] - fixing unit test - #35155 * [MWB] - cleaning up DragDrop.cs - #35155 * [MWB] - cleaning up DragDrop.cs - #35155
This commit is contained in:
@@ -39,7 +39,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
Common.Settings = null;
|
||||
MachineStuff.Settings = null;
|
||||
|
||||
if (_currentPage != null)
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
using MouseWithoutBorders.Form.Settings;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
@@ -59,8 +60,8 @@ namespace MouseWithoutBorders
|
||||
MessageBoxDefaultButton.Button2) == DialogResult.Yes)
|
||||
{
|
||||
Setting.Values.FirstRun = false;
|
||||
Common.CloseSetupForm();
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.CloseSetupForm();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
public partial class SetupPage1 : SettingsFormPage
|
||||
@@ -12,7 +14,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Common.ClearComputerMatrix();
|
||||
MachineStuff.ClearComputerMatrix();
|
||||
}
|
||||
|
||||
private void NoButtonClick(object sender, EventArgs e)
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using MouseWithoutBorders.Class;
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
@@ -92,12 +93,12 @@ namespace MouseWithoutBorders
|
||||
SecurityCode = Common.MyKey;
|
||||
}
|
||||
|
||||
Common.MachineMatrix = new string[Common.MAX_MACHINE] { ComputerNameField.Text.Trim().ToUpper(CultureInfo.CurrentCulture), Common.MachineName.Trim(), string.Empty, string.Empty };
|
||||
MachineStuff.MachineMatrix = new string[MachineStuff.MAX_MACHINE] { ComputerNameField.Text.Trim().ToUpper(CultureInfo.CurrentCulture), Common.MachineName.Trim(), string.Empty, string.Empty };
|
||||
|
||||
string[] machines = Common.MachineMatrix;
|
||||
Common.MachinePool.Initialize(machines);
|
||||
string[] machines = MachineStuff.MachineMatrix;
|
||||
MachineStuff.MachinePool.Initialize(machines);
|
||||
|
||||
Common.UpdateMachinePoolStringSetting();
|
||||
MachineStuff.UpdateMachinePoolStringSetting();
|
||||
SendNextPage(new SetupPage3a { ReturnToSettings = !Setting.Values.FirstRun });
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
ShowStatus($"Connecting...");
|
||||
|
||||
Common.SwitchToMultipleMode(false, false);
|
||||
MachineStuff.SwitchToMultipleMode(false, false);
|
||||
Common.ReopenSockets(true);
|
||||
|
||||
int timeOut = 0;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
using System;
|
||||
|
||||
using MouseWithoutBorders.Core;
|
||||
|
||||
namespace MouseWithoutBorders
|
||||
{
|
||||
public partial class SetupPage5 : SettingsFormPage
|
||||
@@ -16,8 +18,8 @@ namespace MouseWithoutBorders
|
||||
private void DoneButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
// SendNextPage(new SettingsPage1());
|
||||
Common.CloseSetupForm();
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.CloseSetupForm();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,8 +76,8 @@ namespace MouseWithoutBorders
|
||||
return;
|
||||
}
|
||||
|
||||
string[] st = new string[Common.MAX_MACHINE];
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
string[] st = new string[MachineStuff.MAX_MACHINE];
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
|
||||
{
|
||||
if (machines[i].MachineEnabled)
|
||||
{
|
||||
@@ -98,7 +98,7 @@ namespace MouseWithoutBorders
|
||||
}
|
||||
}
|
||||
|
||||
Common.MachineMatrix = st;
|
||||
MachineStuff.MachineMatrix = st;
|
||||
Setting.Values.MatrixOneRow = matrixOneRow = !checkBoxTwoRow.Checked;
|
||||
|
||||
if (Process.GetCurrentProcess().SessionId != NativeMethods.WTSGetActiveConsoleSessionId())
|
||||
@@ -124,7 +124,7 @@ namespace MouseWithoutBorders
|
||||
Common.MMSleep(0.2);
|
||||
}
|
||||
|
||||
Common.SendMachineMatrix();
|
||||
MachineStuff.SendMachineMatrix();
|
||||
}
|
||||
|
||||
buttonOK.Enabled = true;
|
||||
@@ -150,13 +150,13 @@ namespace MouseWithoutBorders
|
||||
bool meAdded = false;
|
||||
string machineName;
|
||||
|
||||
if (Common.MachineMatrix != null && Common.MachineMatrix.Length == Common.MAX_MACHINE)
|
||||
if (MachineStuff.MachineMatrix != null && MachineStuff.MachineMatrix.Length == MachineStuff.MAX_MACHINE)
|
||||
{
|
||||
Logger.LogDebug("LoadMachines: Machine Matrix: " + Setting.Values.MachineMatrixString);
|
||||
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
|
||||
{
|
||||
machineName = Common.MachineMatrix[i].Trim();
|
||||
machineName = MachineStuff.MachineMatrix[i].Trim();
|
||||
machines[i].MachineName = machineName;
|
||||
|
||||
if (string.IsNullOrEmpty(machineName))
|
||||
@@ -168,7 +168,7 @@ namespace MouseWithoutBorders
|
||||
machines[i].MachineEnabled = true;
|
||||
}
|
||||
|
||||
bool found = Common.MachinePool.TryFindMachineByName(machineName, out MachineInf machineInfo);
|
||||
bool found = MachineStuff.MachinePool.TryFindMachineByName(machineName, out MachineInf machineInfo);
|
||||
if (found)
|
||||
{
|
||||
if (machineInfo.Id == Common.MachineID)
|
||||
@@ -340,7 +340,7 @@ namespace MouseWithoutBorders
|
||||
string newMachine;
|
||||
Machine unUsedMachine;
|
||||
|
||||
foreach (MachineInf inf in Common.MachinePool.ListAllMachines())
|
||||
foreach (MachineInf inf in MachineStuff.MachinePool.ListAllMachines())
|
||||
{
|
||||
bool found = false;
|
||||
unUsedMachine = null;
|
||||
@@ -519,7 +519,7 @@ namespace MouseWithoutBorders
|
||||
return true;
|
||||
}
|
||||
|
||||
private readonly Machine[] machines = new Machine[Common.MAX_MACHINE];
|
||||
private readonly Machine[] machines = new Machine[MachineStuff.MAX_MACHINE];
|
||||
private Machine dragDropMachine;
|
||||
private Machine desMachine;
|
||||
private Machine desMachineX;
|
||||
@@ -530,7 +530,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
private void CreateMachines()
|
||||
{
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
|
||||
{
|
||||
Machine m = new();
|
||||
m.MouseDown += Machine_MouseDown;
|
||||
@@ -550,7 +550,7 @@ namespace MouseWithoutBorders
|
||||
int dx = (groupBoxMachineMatrix.Width - 40) / 4;
|
||||
int yOffset = groupBoxMachineMatrix.Height / 3;
|
||||
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
|
||||
{
|
||||
machines[i].Left = matrixOneRow ? 22 + (i * dx) : 22 + dx + ((i % 2) * dx);
|
||||
machines[i].Top = matrixOneRow ? yOffset : (yOffset / 2) + (i / 2 * (machines[i].Width + 2));
|
||||
@@ -649,7 +649,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
desMachineX = desMachineY = desMachine;
|
||||
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
|
||||
{
|
||||
if (machines[i] == dragDropMachine)
|
||||
{
|
||||
@@ -703,9 +703,9 @@ namespace MouseWithoutBorders
|
||||
dragDropMachine.Top = desMachinePos.Y;
|
||||
|
||||
Machine tmp;
|
||||
for (int i = 0; i < Common.MAX_MACHINE - 1; i++)
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE - 1; i++)
|
||||
{
|
||||
for (int j = 0; j < Common.MAX_MACHINE - 1 - i; j++)
|
||||
for (int j = 0; j < MachineStuff.MAX_MACHINE - 1 - i; j++)
|
||||
{
|
||||
if (machines[j + 1].Top < machines[j].Top || (machines[j + 1].Top == machines[j].Top && machines[j + 1].Left < machines[j].Left))
|
||||
{
|
||||
@@ -1041,7 +1041,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
Setting.Values.MatrixCircle = checkBoxCircle.Checked;
|
||||
ShowUpdateMessage();
|
||||
Common.SendMachineMatrix();
|
||||
MachineStuff.SendMachineMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1187,8 +1187,8 @@ namespace MouseWithoutBorders
|
||||
ButtonCancel_Click(this, new EventArgs());
|
||||
Setting.Values.FirstRun = true;
|
||||
Setting.Values.EasyMouse = (int)EasyMouseOption.Enable;
|
||||
Common.ClearComputerMatrix();
|
||||
Common.ShowSetupForm(true);
|
||||
MachineStuff.ClearComputerMatrix();
|
||||
MachineStuff.ShowSetupForm(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace MouseWithoutBorders
|
||||
internal void MenuOnClick(object sender, EventArgs e)
|
||||
{
|
||||
string name = (sender as ToolStripMenuItem).Text;
|
||||
Common.SwitchToMachine(name);
|
||||
MachineStuff.SwitchToMachine(name);
|
||||
}
|
||||
|
||||
internal void UpdateMenu()
|
||||
@@ -199,11 +199,11 @@ namespace MouseWithoutBorders
|
||||
menuGetScreenCapture.DropDown.Items.Count - 1]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
|
||||
{
|
||||
string newMachine = Common.MachineMatrix[i].Trim();
|
||||
string newMachine = MachineStuff.MachineMatrix[i].Trim();
|
||||
|
||||
if (Common.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf))
|
||||
if (MachineStuff.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf))
|
||||
{
|
||||
ToolStripMenuItem newItem = new(
|
||||
newMachine,
|
||||
@@ -372,14 +372,14 @@ namespace MouseWithoutBorders
|
||||
Common.MyKey = Setting.Values.MyKey;
|
||||
}
|
||||
|
||||
Common.UpdateMachinePoolStringSetting();
|
||||
MachineStuff.UpdateMachinePoolStringSetting();
|
||||
|
||||
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop && (Setting.Values.FirstRun || Common.KeyCorrupted))
|
||||
{
|
||||
if (!shownSetupFormOneTime)
|
||||
{
|
||||
shownSetupFormOneTime = true;
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
|
||||
if (Common.KeyCorrupted && !Setting.Values.FirstRun)
|
||||
{
|
||||
@@ -439,7 +439,7 @@ namespace MouseWithoutBorders
|
||||
Common.GetMachineName();
|
||||
Logger.LogDebug("Common.pleaseReopenSocket: " + Common.PleaseReopenSocket.ToString(CultureInfo.InvariantCulture));
|
||||
Common.ReopenSockets(false);
|
||||
Common.NewDesMachineID = Common.DesMachineID = Common.MachineID;
|
||||
MachineStuff.NewDesMachineID = Common.DesMachineID = Common.MachineID;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -457,7 +457,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
Common.PleaseReopenSocket = 0;
|
||||
Thread.Sleep(1000);
|
||||
Common.UpdateClientSockets("REOPEN_WHEN_WSAECONNRESET");
|
||||
MachineStuff.UpdateClientSockets("REOPEN_WHEN_WSAECONNRESET");
|
||||
}
|
||||
|
||||
if (Common.RunOnLogonDesktop)
|
||||
@@ -496,7 +496,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
|
||||
{
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
|
||||
Common.MatrixForm?.UpdateKeyTextBox();
|
||||
|
||||
@@ -511,7 +511,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
if (myKeyDaysToExpire <= 0)
|
||||
{
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
|
||||
Common.Sk?.Close(false);
|
||||
|
||||
@@ -532,7 +532,7 @@ namespace MouseWithoutBorders
|
||||
// if (Common.RunOnLogonDesktop) ShowMouseWithoutBordersUiOnWinLogonDesktop(false);
|
||||
#endif
|
||||
Common.CheckForDesktopSwitchEvent(true);
|
||||
Common.UpdateClientSockets("helperTimer_Tick"); // Sockets may be closed by the remote host when both machines switch desktop at the same time.
|
||||
MachineStuff.UpdateClientSockets("helperTimer_Tick"); // Sockets may be closed by the remote host when both machines switch desktop at the same time.
|
||||
}
|
||||
|
||||
count++;
|
||||
@@ -553,11 +553,11 @@ namespace MouseWithoutBorders
|
||||
Logger.LogAll();
|
||||
|
||||
// Need to review this code on why it is needed (moved from MoveToMyNeighbourIfNeeded(...))
|
||||
for (int i = 0; i < Common.MachineMatrix.Length; i++)
|
||||
for (int i = 0; i < MachineStuff.MachineMatrix.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Common.MachineMatrix[i]) && !Common.InMachineMatrix(Common.MachineName))
|
||||
if (string.IsNullOrEmpty(MachineStuff.MachineMatrix[i]) && !MachineStuff.InMachineMatrix(Common.MachineName))
|
||||
{
|
||||
Common.MachineMatrix[i] = Common.MachineName;
|
||||
MachineStuff.MachineMatrix[i] = Common.MachineName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ namespace MouseWithoutBorders
|
||||
if (Setting.Values.BlockScreenSaver || count % 3000 == 0)
|
||||
{
|
||||
Common.SendAwakeBeat();
|
||||
Common.RemoveDeadMachines();
|
||||
MachineStuff.RemoveDeadMachines();
|
||||
|
||||
// GC.Collect();
|
||||
// GC.WaitForPendingFinalizers();
|
||||
@@ -601,12 +601,12 @@ namespace MouseWithoutBorders
|
||||
|
||||
private void MenuMachineMatrix_Click(object sender, EventArgs e)
|
||||
{
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
}
|
||||
|
||||
private void FrmScreen_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (!Common.IsDropping)
|
||||
if (!Core.DragDrop.IsDropping)
|
||||
{
|
||||
if (Cursor != dotCur)
|
||||
{
|
||||
@@ -702,7 +702,7 @@ namespace MouseWithoutBorders
|
||||
internal void MenuAllPC_Click(object sender, EventArgs e)
|
||||
{
|
||||
Logger.LogDebug("menuAllPC_Click");
|
||||
Common.SwitchToMultipleMode(MenuAllPC.Checked, true);
|
||||
MachineStuff.SwitchToMultipleMode(MenuAllPC.Checked, true);
|
||||
CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE;
|
||||
ChangeIcon(CurIcon);
|
||||
}
|
||||
@@ -711,7 +711,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
Common.DoSomethingInUIThread(() =>
|
||||
{
|
||||
MenuAllPC.Checked = Common.NewDesMachineID == ID.ALL;
|
||||
MenuAllPC.Checked = MachineStuff.NewDesMachineID == ID.ALL;
|
||||
CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE;
|
||||
ChangeIcon(CurIcon);
|
||||
});
|
||||
@@ -819,7 +819,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
case NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP:
|
||||
Logger.LogDebug("Got WM_CHECK_EXPLORER_DRAG_DROP!");
|
||||
Common.DragDropStep04();
|
||||
Core.DragDrop.DragDropStep04();
|
||||
break;
|
||||
|
||||
case NativeMethods.WM_QUIT:
|
||||
@@ -841,7 +841,7 @@ namespace MouseWithoutBorders
|
||||
case NativeMethods.WM_SHOW_SETTINGS_FORM:
|
||||
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop)
|
||||
{
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -856,7 +856,7 @@ namespace MouseWithoutBorders
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
{
|
||||
Common.ShowMachineMatrix();
|
||||
MachineStuff.ShowMachineMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -872,7 +872,7 @@ namespace MouseWithoutBorders
|
||||
|
||||
internal void UpdateNotifyIcon()
|
||||
{
|
||||
string[] x = Common.MachineMatrix;
|
||||
string[] x = MachineStuff.MachineMatrix;
|
||||
string iconText;
|
||||
if (x != null && (x[0].Length > 0 || x[1].Length > 0 || x[2].Length > 0 || x[3].Length > 0))
|
||||
{
|
||||
@@ -943,13 +943,13 @@ namespace MouseWithoutBorders
|
||||
string menuCaption = (sender as ToolStripMenuItem).Text;
|
||||
|
||||
// Send CaptureScreenCommand
|
||||
ID des = menuCaption.Equals("All", StringComparison.OrdinalIgnoreCase) ? ID.ALL : Common.IdFromName(menuCaption);
|
||||
ID des = menuCaption.Equals("All", StringComparison.OrdinalIgnoreCase) ? ID.ALL : MachineStuff.IdFromName(menuCaption);
|
||||
Common.SendPackage(des, PackageType.CaptureScreenCommand);
|
||||
}
|
||||
|
||||
private void FrmScreen_Shown(object sender, EventArgs e)
|
||||
{
|
||||
Common.AssertOneInstancePerDesktopSession();
|
||||
MachineStuff.AssertOneInstancePerDesktopSession();
|
||||
|
||||
Common.MainForm = this;
|
||||
Hide();
|
||||
@@ -1057,11 +1057,11 @@ namespace MouseWithoutBorders
|
||||
r.Right = Common.ScreenWidth - (Common.ScreenWidth / 5);
|
||||
r.Bottom = 20;
|
||||
|
||||
for (int i = 0; i < Common.MAX_MACHINE; i++)
|
||||
for (int i = 0; i < MachineStuff.MAX_MACHINE; i++)
|
||||
{
|
||||
string newMachine = Common.MachineMatrix[i].Trim();
|
||||
string newMachine = MachineStuff.MachineMatrix[i].Trim();
|
||||
|
||||
if (Common.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf))
|
||||
if (MachineStuff.MachinePool.TryFindMachineByName(newMachine, out MachineInf inf) && MachinePool.IsAlive(inf))
|
||||
{
|
||||
machineMatrix += "[" + inf.Name.Trim() + "]";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user