diff --git a/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs b/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs index 4182a129b..362bf6c68 100644 --- a/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs +++ b/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs @@ -75,7 +75,7 @@ namespace mRemoteNGTests.Connection.Protocol connectionTreeWindow.ConnectionTreeContextMenu = connectionTreeContextMenu; var errorAndInfoWindow = new ErrorAndInfoWindow(new DockContent(), connectionTreeWindow); var screenshotManagerWindow = new ScreenshotManagerWindow(new DockContent()); - var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance, import)); + var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance, import), FrmMain.Default); var appUpdater = new AppUpdater(encryptionKeySelectionFunc); Func updateWindowBuilder = () => new UpdateWindow(new DockContent(), shutdown, appUpdater); Func notificationAreaIconBuilder = () => new NotificationAreaIcon(FrmMain.Default, _connectionInitiator, shutdown); diff --git a/mRemoteNGTests/UI/Controls/TextBoxExtensionsTests.cs b/mRemoteNGTests/UI/Controls/TextBoxExtensionsTests.cs index 88f38fda7..54a9a0d98 100644 --- a/mRemoteNGTests/UI/Controls/TextBoxExtensionsTests.cs +++ b/mRemoteNGTests/UI/Controls/TextBoxExtensionsTests.cs @@ -30,7 +30,8 @@ namespace mRemoteNGTests.UI.Controls { const string text = "Type Here"; var textBox = new TextBoxTester(_textBoxExtensionsTestForm.textBox1.Name); - Assert.That(textBox.Properties.SetCueBannerText(text), Is.True); + var textWasSet = textBox.Properties.SetCueBannerText(text); + Assert.That(textWasSet, Is.True); } [Test] diff --git a/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs b/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs index 43e288769..d84d1b747 100644 --- a/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs +++ b/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs @@ -27,13 +27,13 @@ namespace mRemoteNGTests.UI.Forms { var connectionInitiator = Substitute.For(); var import = new Import(); - var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance, import)); + var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService()), new ConnectionsService(PuttySessionsManager.Instance, import), FrmMain.Default); Func notificationIconBuilder = () => new NotificationAreaIcon(FrmMain.Default, connectionInitiator, shutdown); var connectionsService = new ConnectionsService(PuttySessionsManager.Instance, import); Func encryptionKeySelectionFunc = () => connectionsService.EncryptionKey; var databaseConnectorFactory = new DatabaseConnectorFactory(encryptionKeySelectionFunc); var appUpdater = new AppUpdater(encryptionKeySelectionFunc); - _optionsForm = new frmOptions(connectionInitiator, type => {}, notificationIconBuilder, connectionsService, appUpdater, databaseConnectorFactory); + _optionsForm = new frmOptions(connectionInitiator, type => {}, notificationIconBuilder, connectionsService, appUpdater, databaseConnectorFactory, FrmMain.Default); _optionsForm.Show(); } diff --git a/mRemoteV1/App/Screens.cs b/mRemoteV1/App/Screens.cs index b561fbdbb..6494b621c 100644 --- a/mRemoteV1/App/Screens.cs +++ b/mRemoteV1/App/Screens.cs @@ -1,31 +1,38 @@ using System.Windows.Forms; +using mRemoteNG.Tools; using mRemoteNG.UI.Forms; using WeifenLuo.WinFormsUI.Docking; namespace mRemoteNG.App { - public static class Screens + public class Screens { - public static void SendFormToScreen(Screen screen) + private readonly FrmMain _frmMain; + + public Screens(FrmMain frmMain) + { + _frmMain = frmMain.ThrowIfNull(nameof(frmMain)); + } + + public void SendFormToScreen(Screen screen) { - var frmMain = FrmMain.Default; var wasMax = false; - if (frmMain.WindowState == FormWindowState.Maximized) + if (_frmMain.WindowState == FormWindowState.Maximized) { wasMax = true; - frmMain.WindowState = FormWindowState.Normal; + _frmMain.WindowState = FormWindowState.Normal; } - frmMain.Location = screen.Bounds.Location; + _frmMain.Location = screen.Bounds.Location; if (wasMax) { - frmMain.WindowState = FormWindowState.Maximized; + _frmMain.WindowState = FormWindowState.Maximized; } } - public static void SendPanelToScreen(DockContent panel, Screen screen) + public void SendPanelToScreen(DockContent panel, Screen screen) { panel.DockState = DockState.Float; if (panel.ParentForm == null) return; diff --git a/mRemoteV1/App/Shutdown.cs b/mRemoteV1/App/Shutdown.cs index 7e0c1883e..5add1bb7f 100644 --- a/mRemoteV1/App/Shutdown.cs +++ b/mRemoteV1/App/Shutdown.cs @@ -15,12 +15,14 @@ namespace mRemoteNG.App { private readonly SettingsSaver _settingsSaver; private readonly ConnectionsService _connectionsService; + private readonly FrmMain _frmMain; private static string _updateFilePath; - public Shutdown(SettingsSaver settingsSaver, ConnectionsService connectionsService) + public Shutdown(SettingsSaver settingsSaver, ConnectionsService connectionsService, FrmMain frmMain) { _settingsSaver = settingsSaver.ThrowIfNull(nameof(settingsSaver)); _connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService)); + _frmMain = frmMain.ThrowIfNull(nameof(frmMain)); } private static bool UpdatePending @@ -31,7 +33,7 @@ namespace mRemoteNG.App public void Quit(string updateFilePath = null) { _updateFilePath = updateFilePath; - FrmMain.Default.Close(); + _frmMain.Close(); ProgramRoot.CloseSingletonInstanceMutex(); } diff --git a/mRemoteV1/App/Windows.cs b/mRemoteV1/App/Windows.cs index 4b7f23edb..0afc094e5 100644 --- a/mRemoteV1/App/Windows.cs +++ b/mRemoteV1/App/Windows.cs @@ -87,7 +87,7 @@ namespace mRemoteNG.App _adimportForm.Show(dockPanel); break; case WindowType.Options: - using (var optionsForm = new frmOptions(_connectionInitiator, Show, _notificationAreaIconBuilder, _connectionsService, _appUpdater, _databaseConnectorFactory)) + using (var optionsForm = new frmOptions(_connectionInitiator, Show, _notificationAreaIconBuilder, _connectionsService, _appUpdater, _databaseConnectorFactory, FrmMain.Default)) { optionsForm.ShowDialog(dockPanel); } diff --git a/mRemoteV1/UI/Forms/OptionsPages/ConnectionsPage.cs b/mRemoteV1/UI/Forms/OptionsPages/ConnectionsPage.cs index 302c2b434..fd250206d 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/ConnectionsPage.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/ConnectionsPage.cs @@ -1,16 +1,18 @@ using System; using mRemoteNG.Config; +using mRemoteNG.Tools; namespace mRemoteNG.UI.Forms.OptionsPages { public partial class ConnectionsPage { - private FrmMain _frmMain = FrmMain.Default; + private readonly FrmMain _frmMain; - public ConnectionsPage() + public ConnectionsPage(FrmMain frmMain) { InitializeComponent(); base.ApplyTheme(); + _frmMain = frmMain.ThrowIfNull(nameof(frmMain)); } public override string PageName diff --git a/mRemoteV1/UI/Forms/frmMain.cs b/mRemoteV1/UI/Forms/frmMain.cs index 757f1eb40..056b58a03 100644 --- a/mRemoteV1/UI/Forms/frmMain.cs +++ b/mRemoteV1/UI/Forms/frmMain.cs @@ -69,6 +69,7 @@ namespace mRemoteNG.UI.Forms private readonly Import _import; private readonly AppUpdater _appUpdater; private readonly DatabaseConnectorFactory _databaseConnectorFactory; + private readonly Screens _screens; internal FullscreenHandler Fullscreen { get; set; } @@ -77,6 +78,8 @@ namespace mRemoteNG.UI.Forms private FrmMain() { + InitializeComponent(); + _windowList = new WindowList(); _credentialRepositoryList = new CredentialRepositoryList(); var externalToolsService = new ExternalToolsService(); @@ -101,7 +104,7 @@ namespace mRemoteNG.UI.Forms var errorAndInfoWindow = new ErrorAndInfoWindow(new DockContent(), connectionTreeWindow); var screenshotManagerWindow = new ScreenshotManagerWindow(new DockContent()); _settingsSaver = new SettingsSaver(externalToolsService); - _shutdown = new Shutdown(_settingsSaver, _connectionsService); + _shutdown = new Shutdown(_settingsSaver, _connectionsService, this); Func updateWindowBuilder = () => new UpdateWindow(new DockContent(), _shutdown, _appUpdater); _notificationAreaIconBuilder = () => new NotificationAreaIcon(this, _connectionInitiator, _shutdown); Func externalToolsWindowBuilder = () => new ExternalToolsWindow(_connectionInitiator, externalToolsService, () => connectionTree.SelectedNode); @@ -112,15 +115,14 @@ namespace mRemoteNG.UI.Forms sshTransferWindow, updateWindowBuilder, _notificationAreaIconBuilder, externalToolsWindowBuilder, _connectionsService, portScanWindowBuilder, activeDirectoryImportWindowBuilder, _appUpdater, _databaseConnectorFactory); Func connectionWindowBuilder = () => new ConnectionWindow(new DockContent(), _connectionInitiator, _windows, externalToolsService); - _panelAdder = new PanelAdder(_windowList, connectionWindowBuilder); + _screens = new Screens(this); + _panelAdder = new PanelAdder(_windowList, connectionWindowBuilder, _screens); _showFullPathInTitle = Settings.Default.ShowCompleteConsPathInTitle; _connectionInitiator.Adder = _panelAdder; _connectionsService.DatabaseConnectorFactory = _databaseConnectorFactory; _startup = new Startup(this, _windows, _connectionsService, _appUpdater, _databaseConnectorFactory); connectionTreeContextMenu.ShowWindowAction = _windows.Show; - InitializeComponent(); - var externalAppsLoader = new ExternalAppsLoader(Runtime.MessageCollector, _externalToolsToolStrip, _connectionInitiator, externalToolsService); _settingsLoader = new SettingsLoader(this, Runtime.MessageCollector, _quickConnectToolStrip, _externalToolsToolStrip, _multiSshToolStrip, externalAppsLoader, _notificationAreaIconBuilder); _externalToolsToolStrip.ExternalToolsService = externalToolsService; @@ -359,7 +361,7 @@ namespace mRemoteNG.UI.Forms if (CTaskDialog.CommandButtonResult != 1) return; - using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, _notificationAreaIconBuilder, _connectionsService, _appUpdater, _databaseConnectorFactory, Language.strTabUpdates)) + using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, _notificationAreaIconBuilder, _connectionsService, _appUpdater, _databaseConnectorFactory, Language.strTabUpdates, this)) { optionsForm.ShowDialog(this); } @@ -519,7 +521,7 @@ namespace mRemoteNG.UI.Forms case NativeMethods.WM_SYSCOMMAND: var screen = _screenSystemMenu.GetScreenById(m.WParam.ToInt32()); if (screen != null) - Screens.SendFormToScreen(screen); + _screens.SendFormToScreen(screen); break; case NativeMethods.WM_DRAWCLIPBOARD: NativeMethods.SendMessage(_fpChainedWindowHandle, m.Msg, m.LParam, m.WParam); diff --git a/mRemoteV1/UI/Forms/frmOptions.cs b/mRemoteV1/UI/Forms/frmOptions.cs index 7d8fef26f..3848962a5 100644 --- a/mRemoteV1/UI/Forms/frmOptions.cs +++ b/mRemoteV1/UI/Forms/frmOptions.cs @@ -22,19 +22,21 @@ namespace mRemoteNG.UI.Forms private readonly ConnectionsService _connectionsService; private readonly AppUpdater _appUpdater; private readonly DatabaseConnectorFactory _databaseConnectorFactory; + private readonly FrmMain _frmMain; public frmOptions(IConnectionInitiator connectionInitiator, Action showWindowAction, Func notificationAreaIconBuilder, - ConnectionsService connectionsService, AppUpdater appUpdater, DatabaseConnectorFactory databaseConnectorFactory) - : this(connectionInitiator, showWindowAction, notificationAreaIconBuilder, connectionsService, appUpdater, databaseConnectorFactory, Language.strStartupExit) + ConnectionsService connectionsService, AppUpdater appUpdater, DatabaseConnectorFactory databaseConnectorFactory, FrmMain frmMain) + : this(connectionInitiator, showWindowAction, notificationAreaIconBuilder, connectionsService, appUpdater, databaseConnectorFactory, Language.strStartupExit, frmMain) { } public frmOptions(IConnectionInitiator connectionInitiator, Action showWindowAction, Func notificationAreaIconBuilder, - ConnectionsService connectionsService, AppUpdater appUpdater, DatabaseConnectorFactory databaseConnectorFactory, string pageName) + ConnectionsService connectionsService, AppUpdater appUpdater, DatabaseConnectorFactory databaseConnectorFactory, string pageName, FrmMain frmMain) { _connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator)); _showWindowAction = showWindowAction.ThrowIfNull(nameof(showWindowAction)); _notificationAreaIconBuilder = notificationAreaIconBuilder; + _frmMain = frmMain.ThrowIfNull(nameof(frmMain)); _databaseConnectorFactory = databaseConnectorFactory.ThrowIfNull(nameof(databaseConnectorFactory)); _connectionsService = connectionsService.ThrowIfNull(nameof(connectionsService)); _appUpdater = appUpdater.ThrowIfNull(nameof(appUpdater)); @@ -82,7 +84,7 @@ namespace mRemoteNG.UI.Forms {typeof(AppearancePage).Name, new AppearancePage(_connectionInitiator, _notificationAreaIconBuilder)}, {typeof(TabsPanelsPage).Name, new TabsPanelsPage()}, {typeof(NotificationsPage).Name, new NotificationsPage()}, - {typeof(ConnectionsPage).Name, new ConnectionsPage()}, + {typeof(ConnectionsPage).Name, new ConnectionsPage(_frmMain)}, {typeof(CredentialsPage).Name, new CredentialsPage()}, {typeof(SqlServerPage).Name, new SqlServerPage(_connectionsService, _databaseConnectorFactory)}, {typeof(UpdatesPage).Name, new UpdatesPage(_appUpdater, _showWindowAction)}, diff --git a/mRemoteV1/UI/Panels/PanelAdder.cs b/mRemoteV1/UI/Panels/PanelAdder.cs index e553731c1..e2e5fdff7 100644 --- a/mRemoteV1/UI/Panels/PanelAdder.cs +++ b/mRemoteV1/UI/Panels/PanelAdder.cs @@ -14,11 +14,13 @@ namespace mRemoteNG.UI.Panels public class PanelAdder { private readonly WindowList _windowList; + private readonly Screens _screens; private readonly Func _connectionWindowBuilder; - public PanelAdder(WindowList windowList, Func connectionWindowBuilder) + public PanelAdder(WindowList windowList, Func connectionWindowBuilder, Screens screens) { _connectionWindowBuilder = connectionWindowBuilder; + _screens = screens; _windowList = windowList.ThrowIfNull(nameof(windowList)); } @@ -60,7 +62,7 @@ namespace mRemoteNG.UI.Panels connectionForm.SetFormText(title.Replace("&", "&&")); } - private static void BuildConnectionWindowContextMenu(DockContent pnlcForm) + private void BuildConnectionWindowContextMenu(DockContent pnlcForm) { var cMen = new ContextMenuStrip(); var cMenRen = CreateRenameMenuItem(pnlcForm); @@ -69,7 +71,7 @@ namespace mRemoteNG.UI.Panels pnlcForm.TabPageContextMenuStrip = cMen; } - private static ToolStripMenuItem CreateScreensMenuItem(DockContent pnlcForm) + private ToolStripMenuItem CreateScreensMenuItem(DockContent pnlcForm) { var cMenScreens = new ToolStripMenuItem { @@ -114,7 +116,7 @@ namespace mRemoteNG.UI.Panels } } - private static void cMenConnectionPanelScreens_DropDownOpening(object sender, EventArgs e) + private void cMenConnectionPanelScreens_DropDownOpening(object sender, EventArgs e) { try { @@ -140,7 +142,7 @@ namespace mRemoteNG.UI.Panels } } - private static void cMenConnectionPanelScreen_Click(object sender, EventArgs e) + private void cMenConnectionPanelScreen_Click(object sender, EventArgs e) { Screen screen = null; DockContent panel = null; @@ -160,7 +162,7 @@ namespace mRemoteNG.UI.Panels panel = (DockContent)obj; } } - Screens.SendPanelToScreen(panel, screen); + _screens.SendPanelToScreen(panel, screen); } catch (Exception ex) {