From ced33027b84641344386dfcf4b51d7eb94f69290 Mon Sep 17 00:00:00 2001 From: David Sparer Date: Sat, 3 Mar 2018 12:05:38 -0600 Subject: [PATCH] made Shutdown and SettingsSaver non-static --- .../Protocol/IntegratedProgramTests.cs | 10 +++++-- .../UI/Forms/OptionsFormSetupAndTeardown.cs | 8 +++-- mRemoteV1/App/Runtime.cs | 2 -- mRemoteV1/App/Shutdown.cs | 29 ++++++++++++------- mRemoteV1/App/Windows.cs | 14 ++++++--- .../Config/Settings/ExternalAppsLoader.cs | 7 +++-- mRemoteV1/Config/Settings/SettingsLoader.cs | 13 +++++---- mRemoteV1/Config/Settings/SettingsSaver.cs | 23 ++++++++++----- mRemoteV1/Tools/NotificationAreaIcon.cs | 9 ++++-- .../UI/Forms/OptionsPages/AppearancePage.cs | 6 ++-- mRemoteV1/UI/Forms/frmMain.cs | 27 ++++++++++++----- mRemoteV1/UI/Forms/frmOptions.cs | 13 +++++---- mRemoteV1/UI/Menu/MainFileMenu.cs | 1 + mRemoteV1/UI/Window/UpdateWindow.cs | 15 ++++------ 14 files changed, 112 insertions(+), 65 deletions(-) diff --git a/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs b/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs index 592e6c2d..f641667f 100644 --- a/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs +++ b/mRemoteNGTests/Connection/Protocol/IntegratedProgramTests.cs @@ -1,11 +1,14 @@ -using System.Threading; +using System; +using System.Threading; using mRemoteNG.App; +using mRemoteNG.Config.Settings; using mRemoteNG.Connection; using mRemoteNG.Connection.Protocol; using mRemoteNG.Credential.Repositories; using mRemoteNG.Tools; using mRemoteNG.Tools.CustomCollections; using mRemoteNG.UI.Controls; +using mRemoteNG.UI.Forms; using mRemoteNG.UI.Window; using NSubstitute; using NUnit.Framework; @@ -70,7 +73,10 @@ namespace mRemoteNGTests.Connection.Protocol connectionTreeWindow.ConnectionTreeContextMenu = connectionTreeContextMenu; var errorAndInfoWindow = new ErrorAndInfoWindow(new DockContent(), connectionTreeWindow); var screenshotManagerWindow = new ScreenshotManagerWindow(new DockContent()); - var windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow, sshTransferWindow); + var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService())); + Func updateWindowBuilder = () => new UpdateWindow(new DockContent(), shutdown); + Func notificationAreaIconBuilder = () => new NotificationAreaIcon(FrmMain.Default, _connectionInitiator, shutdown); + var windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow, sshTransferWindow, updateWindowBuilder, notificationAreaIconBuilder); var connectionWindow = new ConnectionWindow(new DockContent(), _connectionInitiator, windows); var connectionInfo = new ConnectionInfo {ExtApp = extAppName}; return new InterfaceControl(connectionWindow, sut, connectionInfo); diff --git a/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs b/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs index c33333d8..e8063dc1 100644 --- a/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs +++ b/mRemoteNGTests/UI/Forms/OptionsFormSetupAndTeardown.cs @@ -1,4 +1,7 @@ -using mRemoteNG.Connection; +using mRemoteNG.App; +using mRemoteNG.Config.Settings; +using mRemoteNG.Connection; +using mRemoteNG.Tools; using mRemoteNG.UI.Forms; using NSubstitute; using NUnit.Framework; @@ -18,7 +21,8 @@ namespace mRemoteNGTests.UI.Forms public void Setup() { var connectionInitiator = Substitute.For(); - _optionsForm = new frmOptions(connectionInitiator, type => {}); + var shutdown = new Shutdown(new SettingsSaver(new ExternalToolsService())); + _optionsForm = new frmOptions(connectionInitiator, type => {}, () => new NotificationAreaIcon(FrmMain.Default, connectionInitiator, shutdown)); _optionsForm.Show(); } diff --git a/mRemoteV1/App/Runtime.cs b/mRemoteV1/App/Runtime.cs index 5cb95793..577986a4 100644 --- a/mRemoteV1/App/Runtime.cs +++ b/mRemoteV1/App/Runtime.cs @@ -7,8 +7,6 @@ using mRemoteNG.App.Info; using mRemoteNG.Config.DataProviders; using mRemoteNG.Config.Putty; using mRemoteNG.Connection; -using mRemoteNG.Credential; -using mRemoteNG.Credential.Repositories; using mRemoteNG.Messages; using mRemoteNG.Security; using mRemoteNG.Tools; diff --git a/mRemoteV1/App/Shutdown.cs b/mRemoteV1/App/Shutdown.cs index 56977bba..07b2375f 100644 --- a/mRemoteV1/App/Shutdown.cs +++ b/mRemoteV1/App/Shutdown.cs @@ -3,29 +3,36 @@ using System; using System.Diagnostics; using System.Windows.Forms; using mRemoteNG.Config.Putty; +using mRemoteNG.Config.Settings; using mRemoteNG.UI.Controls; using mRemoteNG.UI.Forms; // ReSharper disable ArrangeAccessorOwnerBody namespace mRemoteNG.App { - public static class Shutdown + public class Shutdown { + private readonly SettingsSaver _settingsSaver; private static string _updateFilePath; + public Shutdown(SettingsSaver settingsSaver) + { + _settingsSaver = settingsSaver.ThrowIfNull(nameof(settingsSaver)); + } + private static bool UpdatePending { get { return !string.IsNullOrEmpty(_updateFilePath); } } - public static void Quit(string updateFilePath = null) + public void Quit(string updateFilePath = null) { _updateFilePath = updateFilePath; FrmMain.Default.Close(); ProgramRoot.CloseSingletonInstanceMutex(); } - public static void Cleanup(Control quickConnectToolStrip, ExternalToolsToolStrip externalToolsToolStrip, MultiSshToolStrip multiSshToolStrip, FrmMain frmMain) + public void Cleanup(Control quickConnectToolStrip, ExternalToolsToolStrip externalToolsToolStrip, MultiSshToolStrip multiSshToolStrip, FrmMain frmMain) { try { @@ -41,34 +48,34 @@ namespace mRemoteNG.App } } - private static void StopPuttySessionWatcher() + private void StopPuttySessionWatcher() { PuttySessionsManager.Instance.StopWatcher(); } - private static void DisposeNotificationAreaIcon() + private void DisposeNotificationAreaIcon() { if (Runtime.NotificationAreaIcon != null && Runtime.NotificationAreaIcon.Disposed == false) Runtime.NotificationAreaIcon.Dispose(); } - private static void SaveConnections() + private void SaveConnections() { if (Settings.Default.SaveConsOnExit) Runtime.ConnectionsService.SaveConnections(); } - private static void SaveSettings(Control quickConnectToolStrip, ExternalToolsToolStrip externalToolsToolStrip, MultiSshToolStrip multiSshToolStrip, FrmMain frmMain) + private void SaveSettings(Control quickConnectToolStrip, ExternalToolsToolStrip externalToolsToolStrip, MultiSshToolStrip multiSshToolStrip, FrmMain frmMain) { - Config.Settings.SettingsSaver.SaveSettings(quickConnectToolStrip, externalToolsToolStrip, multiSshToolStrip, frmMain); + _settingsSaver.SaveSettings(quickConnectToolStrip, externalToolsToolStrip, multiSshToolStrip, frmMain); } - private static void UnregisterBrowsers() + private void UnregisterBrowsers() { IeBrowserEmulation.Unregister(); } - public static void StartUpdate() + public void StartUpdate() { try { @@ -80,7 +87,7 @@ namespace mRemoteNG.App } } - private static void RunUpdateFile() + private void RunUpdateFile() { if (UpdatePending) Process.Start(_updateFilePath); diff --git a/mRemoteV1/App/Windows.cs b/mRemoteV1/App/Windows.cs index 1c50b84a..b03774a4 100644 --- a/mRemoteV1/App/Windows.cs +++ b/mRemoteV1/App/Windows.cs @@ -5,6 +5,7 @@ using mRemoteNG.Tools; using mRemoteNG.UI; using mRemoteNG.UI.Forms; using mRemoteNG.UI.Window; +using WeifenLuo.WinFormsUI.Docking; namespace mRemoteNG.App { @@ -19,6 +20,8 @@ namespace mRemoteNG.App private UltraVNCWindow _ultravncscForm; private ComponentsCheckWindow _componentscheckForm; private UpdateWindow _updateForm; + private readonly Func _updateWindowBuilder; + private readonly Func _notificationAreaIconBuilder; internal ConnectionTreeWindow TreeForm { get; } internal ConfigWindow ConfigForm { get; } @@ -32,7 +35,9 @@ namespace mRemoteNG.App ConfigWindow configForm, ErrorAndInfoWindow errorAndInfoWindow, ScreenshotManagerWindow screenshotForm, - SSHTransferWindow sshtransferForm) + SSHTransferWindow sshtransferForm, + Func updateWindowBuilder, + Func notificationAreaIconBuilder) { _connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator)); TreeForm = treeForm.ThrowIfNull(nameof(treeForm)); @@ -40,7 +45,8 @@ namespace mRemoteNG.App ErrorsForm = errorAndInfoWindow.ThrowIfNull(nameof(errorAndInfoWindow)); ScreenshotForm = screenshotForm.ThrowIfNull(nameof(screenshotForm)); SshtransferForm = sshtransferForm.ThrowIfNull(nameof(sshtransferForm)); - _updateForm = new UpdateWindow(); + _updateWindowBuilder = updateWindowBuilder; + _notificationAreaIconBuilder = notificationAreaIconBuilder; } public void Show(WindowType windowType) @@ -62,7 +68,7 @@ namespace mRemoteNG.App _adimportForm.Show(dockPanel); break; case WindowType.Options: - using (var optionsForm = new frmOptions(_connectionInitiator, Show)) + using (var optionsForm = new frmOptions(_connectionInitiator, Show, _notificationAreaIconBuilder)) { optionsForm.ShowDialog(dockPanel); } @@ -74,7 +80,7 @@ namespace mRemoteNG.App break; case WindowType.Update: if (_updateForm == null || _updateForm.IsDisposed) - _updateForm = new UpdateWindow(); + _updateForm = _updateWindowBuilder(); _updateForm.Show(dockPanel); break; case WindowType.Help: diff --git a/mRemoteV1/Config/Settings/ExternalAppsLoader.cs b/mRemoteV1/Config/Settings/ExternalAppsLoader.cs index 8bbd6378..249a1951 100644 --- a/mRemoteV1/Config/Settings/ExternalAppsLoader.cs +++ b/mRemoteV1/Config/Settings/ExternalAppsLoader.cs @@ -16,12 +16,15 @@ namespace mRemoteNG.Config.Settings private readonly MessageCollector _messageCollector; private readonly ExternalToolsToolStrip _externalToolsToolStrip; private readonly IConnectionInitiator _connectionInitiator; + private readonly ExternalToolsService _externalToolsService; - public ExternalAppsLoader(MessageCollector messageCollector, ExternalToolsToolStrip externalToolsToolStrip, IConnectionInitiator connectionInitiator) + public ExternalAppsLoader(MessageCollector messageCollector, ExternalToolsToolStrip externalToolsToolStrip, + IConnectionInitiator connectionInitiator, ExternalToolsService externalToolsService) { _messageCollector = messageCollector.ThrowIfNull(nameof(messageCollector)); _externalToolsToolStrip = externalToolsToolStrip.ThrowIfNull(nameof(externalToolsToolStrip)); _connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator)); + _externalToolsService = externalToolsService.ThrowIfNull(nameof(externalToolsService)); } @@ -87,7 +90,7 @@ namespace mRemoteNG.Config.Settings } _messageCollector.AddMessage(MessageClass.InformationMsg, $"Adding External App: {extA.DisplayName} {extA.FileName} {extA.Arguments}", true); - Runtime.ExternalToolsService.ExternalTools.Add(extA); + _externalToolsService.ExternalTools.Add(extA); } _externalToolsToolStrip.SwitchToolBarText(mRemoteNG.Settings.Default.ExtAppsTBShowText); diff --git a/mRemoteV1/Config/Settings/SettingsLoader.cs b/mRemoteV1/Config/Settings/SettingsLoader.cs index 1746ec53..38095cda 100644 --- a/mRemoteV1/Config/Settings/SettingsLoader.cs +++ b/mRemoteV1/Config/Settings/SettingsLoader.cs @@ -23,7 +23,7 @@ namespace mRemoteNG.Config.Settings private readonly QuickConnectToolStrip _quickConnectToolStrip; private readonly ExternalToolsToolStrip _externalToolsToolStrip; private readonly MultiSshToolStrip _multiSshToolStrip; - private readonly IConnectionInitiator _connectionInitiator; + private readonly Func _notificationAreaIconBuilder; private FrmMain MainForm { get; } @@ -34,15 +34,16 @@ namespace mRemoteNG.Config.Settings QuickConnectToolStrip quickConnectToolStrip, ExternalToolsToolStrip externalToolsToolStrip, MultiSshToolStrip multiSshToolStrip, - IConnectionInitiator connectionInitiator) + ExternalAppsLoader externalAppsLoader, + Func notificationAreaIconBuilder) { - MainForm = mainForm.ThrowIfNull(nameof(mainForm)); + MainForm = mainForm.ThrowIfNull(nameof(mainForm)); _messageCollector = messageCollector.ThrowIfNull(nameof(messageCollector)); _quickConnectToolStrip = quickConnectToolStrip.ThrowIfNull(nameof(quickConnectToolStrip)); _externalToolsToolStrip = externalToolsToolStrip.ThrowIfNull(nameof(externalToolsToolStrip)); _multiSshToolStrip = multiSshToolStrip.ThrowIfNull(nameof(multiSshToolStrip)); - _externalAppsLoader = new ExternalAppsLoader(messageCollector, _externalToolsToolStrip, connectionInitiator.ThrowIfNull(nameof(connectionInitiator))); - _connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator)); + _externalAppsLoader = externalAppsLoader.ThrowIfNull(nameof(externalAppsLoader)); + _notificationAreaIconBuilder = notificationAreaIconBuilder; } #region Public Methods @@ -146,7 +147,7 @@ namespace mRemoteNG.Config.Settings private void SetShowSystemTrayIcon() { if (mRemoteNG.Settings.Default.ShowSystemTrayIcon) - Runtime.NotificationAreaIcon = new NotificationAreaIcon(MainForm, _connectionInitiator); + Runtime.NotificationAreaIcon = _notificationAreaIconBuilder(); } private void SetPuttyPath() diff --git a/mRemoteV1/Config/Settings/SettingsSaver.cs b/mRemoteV1/Config/Settings/SettingsSaver.cs index f41ed382..f9a50ca7 100644 --- a/mRemoteV1/Config/Settings/SettingsSaver.cs +++ b/mRemoteV1/Config/Settings/SettingsSaver.cs @@ -9,9 +9,16 @@ using mRemoteNG.UI.Forms; namespace mRemoteNG.Config.Settings { - public static class SettingsSaver + public class SettingsSaver { - public static void SaveSettings( + private readonly ExternalToolsService _externalToolsService; + + public SettingsSaver(ExternalToolsService externalToolsService) + { + _externalToolsService = externalToolsService.ThrowIfNull(nameof(externalToolsService)); + } + + public void SaveSettings( Control quickConnectToolStrip, ExternalToolsToolStrip externalToolsToolStrip, MultiSshToolStrip multiSshToolStrip, @@ -62,7 +69,7 @@ namespace mRemoteNG.Config.Settings } } - private static void SaveExternalAppsToolbarLocation(ExternalToolsToolStrip externalToolsToolStrip) + private void SaveExternalAppsToolbarLocation(ExternalToolsToolStrip externalToolsToolStrip) { mRemoteNG.Settings.Default.ExtAppsTBLocation = externalToolsToolStrip.Location; mRemoteNG.Settings.Default.ExtAppsTBVisible = externalToolsToolStrip.Visible; @@ -74,7 +81,7 @@ namespace mRemoteNG.Config.Settings } } - private static void SaveQuickConnectToolbarLocation(Control quickConnectToolStrip) + private void SaveQuickConnectToolbarLocation(Control quickConnectToolStrip) { mRemoteNG.Settings.Default.QuickyTBLocation = quickConnectToolStrip.Location; mRemoteNG.Settings.Default.QuickyTBVisible = quickConnectToolStrip.Visible; @@ -85,7 +92,7 @@ namespace mRemoteNG.Config.Settings } } - private static void SaveMultiSshToolbarLocation(MultiSshToolStrip multiSshToolStrip) + private void SaveMultiSshToolbarLocation(MultiSshToolStrip multiSshToolStrip) { mRemoteNG.Settings.Default.MultiSshToolbarLocation = multiSshToolStrip.Location; mRemoteNG.Settings.Default.MultiSshToolbarVisible = multiSshToolStrip.Visible; @@ -96,7 +103,7 @@ namespace mRemoteNG.Config.Settings } } - private static void SaveDockPanelLayout() + private void SaveDockPanelLayout() { var panelLayoutXmlFilePath = SettingsFileInfo.SettingsPath + "\\" + SettingsFileInfo.LayoutFileName; var panelLayoutSaver = new DockPanelLayoutSaver( @@ -106,10 +113,10 @@ namespace mRemoteNG.Config.Settings panelLayoutSaver.Save(); } - private static void SaveExternalApps() + private void SaveExternalApps() { var externalAppsSaver = new ExternalAppsSaver(); - externalAppsSaver.Save(Runtime.ExternalToolsService.ExternalTools); + externalAppsSaver.Save(_externalToolsService.ExternalTools); } } } \ No newline at end of file diff --git a/mRemoteV1/Tools/NotificationAreaIcon.cs b/mRemoteV1/Tools/NotificationAreaIcon.cs index 213fc807..718054e3 100644 --- a/mRemoteV1/Tools/NotificationAreaIcon.cs +++ b/mRemoteV1/Tools/NotificationAreaIcon.cs @@ -16,13 +16,16 @@ namespace mRemoteNG.Tools private readonly ToolStripMenuItem _cMenCons; private readonly IConnectionInitiator _connectionInitiator; private readonly FrmMain _frmMain; + private readonly Shutdown _shutdown; public bool Disposed { get; private set; } - public NotificationAreaIcon(FrmMain frmMain, IConnectionInitiator connectionInitiator) + public NotificationAreaIcon(FrmMain frmMain, IConnectionInitiator connectionInitiator, Shutdown shutdown) { _frmMain = frmMain.ThrowIfNull(nameof(frmMain)); _connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator)); + _shutdown = shutdown.ThrowIfNull(nameof(shutdown)); + try { _cMenCons = new ToolStripMenuItem @@ -124,9 +127,9 @@ namespace mRemoteNG.Tools _connectionInitiator.OpenConnection((ConnectionInfo) ((ToolStripMenuItem) sender).Tag); } - private static void cMenExit_Click(object sender, EventArgs e) + private void cMenExit_Click(object sender, EventArgs e) { - Shutdown.Quit(); + _shutdown.Quit(); } } } \ No newline at end of file diff --git a/mRemoteV1/UI/Forms/OptionsPages/AppearancePage.cs b/mRemoteV1/UI/Forms/OptionsPages/AppearancePage.cs index 720f8d5a..dfdcf6dc 100644 --- a/mRemoteV1/UI/Forms/OptionsPages/AppearancePage.cs +++ b/mRemoteV1/UI/Forms/OptionsPages/AppearancePage.cs @@ -9,10 +9,12 @@ namespace mRemoteNG.UI.Forms.OptionsPages public partial class AppearancePage { private readonly IConnectionInitiator _connectionInitiator; + private readonly Func _notificationAreaIconBuilder; - public AppearancePage(IConnectionInitiator connectionInitiator) + public AppearancePage(IConnectionInitiator connectionInitiator, Func notificationAreaIconBuilder) { _connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator)); + _notificationAreaIconBuilder = notificationAreaIconBuilder; InitializeComponent(); base.ApplyTheme(); } @@ -85,7 +87,7 @@ namespace mRemoteNG.UI.Forms.OptionsPages { if (Runtime.NotificationAreaIcon == null) { - Runtime.NotificationAreaIcon = new NotificationAreaIcon(FrmMain.Default, _connectionInitiator); + Runtime.NotificationAreaIcon = _notificationAreaIconBuilder(); } } else diff --git a/mRemoteV1/UI/Forms/frmMain.cs b/mRemoteV1/UI/Forms/frmMain.cs index 7dac82a4..d091512e 100644 --- a/mRemoteV1/UI/Forms/frmMain.cs +++ b/mRemoteV1/UI/Forms/frmMain.cs @@ -58,7 +58,11 @@ namespace mRemoteNG.UI.Forms private readonly Windows _windows; private readonly Startup _startup; private readonly Export _export; + private readonly SettingsLoader _settingsLoader; + private readonly SettingsSaver _settingsSaver; + private readonly Shutdown _shutdown; private readonly ICredentialRepositoryList _credentialRepositoryList; + private readonly Func _notificationAreaIconBuilder; internal FullscreenHandler Fullscreen { get; set; } @@ -83,15 +87,22 @@ namespace mRemoteNG.UI.Forms connectionTreeWindow.ConnectionTreeContextMenu = connectionTreeContextMenu; var errorAndInfoWindow = new ErrorAndInfoWindow(new DockContent(), connectionTreeWindow); var screenshotManagerWindow = new ScreenshotManagerWindow(); - _windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow, sshTransferWindow); + var externalToolsService = new ExternalToolsService(); + _settingsSaver = new SettingsSaver(externalToolsService); + _shutdown = new Shutdown(_settingsSaver); + Func updateWindowBuilder = () => new UpdateWindow(new DockContent(), _shutdown); + _notificationAreaIconBuilder = () => new NotificationAreaIcon(this, _connectionInitiator, _shutdown); + _windows = new Windows(_connectionInitiator, connectionTreeWindow, configWindow, errorAndInfoWindow, screenshotManagerWindow, sshTransferWindow, updateWindowBuilder, _notificationAreaIconBuilder); _panelAdder = new PanelAdder(_windowList, _connectionInitiator, _windows); _showFullPathInTitle = Settings.Default.ShowCompleteConsPathInTitle; _connectionInitiator.Adder = _panelAdder; _startup = new Startup(this, _windows); - connectionTreeContextMenu.ShowWindowAction = _windows.Show; + 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.GetSelectedConnectionFunc = () => SelectedConnection; _quickConnectToolStrip.ConnectionInitiator = _connectionInitiator; CredentialRecordTypeConverter.CredentialRepositoryList = _credentialRepositoryList; @@ -185,8 +196,7 @@ namespace mRemoteNG.UI.Forms SetMenuDependencies(); msMain.Location = Point.Empty; - var settingsLoader = new SettingsLoader(this, messageCollector, _quickConnectToolStrip, _externalToolsToolStrip, _multiSshToolStrip, _connectionInitiator); - settingsLoader.LoadSettings(); + _settingsLoader.LoadSettings(); var uiLoader = new DockPanelLayoutLoader(this, messageCollector, _windows); uiLoader.LoadPanelsFromXml(); @@ -252,6 +262,7 @@ namespace mRemoteNG.UI.Forms mainFileMenu1.WindowList = _windowList; mainFileMenu1.Windows = _windows; mainFileMenu1.Export = _export; + mainFileMenu1.Shutdown = _shutdown; viewMenu1.TsExternalTools = _externalToolsToolStrip; viewMenu1.TsQuickConnect = _quickConnectToolStrip; @@ -319,7 +330,7 @@ namespace mRemoteNG.UI.Forms if (CTaskDialog.CommandButtonResult != 1) return; - using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, Language.strTabUpdates)) + using (var optionsForm = new frmOptions(_connectionInitiator, _windows.Show, _notificationAreaIconBuilder, Language.strTabUpdates)) { optionsForm.ShowDialog(this); } @@ -366,7 +377,7 @@ namespace mRemoteNG.UI.Forms } } - Shutdown.Cleanup(_quickConnectToolStrip, _externalToolsToolStrip, _multiSshToolStrip, this); + _shutdown.Cleanup(_quickConnectToolStrip, _externalToolsToolStrip, _multiSshToolStrip, this); IsClosing = true; @@ -378,7 +389,7 @@ namespace mRemoteNG.UI.Forms } } - Shutdown.StartUpdate(); + _shutdown.StartUpdate(); Debug.Print("[END] - " + Convert.ToString(DateTime.Now, CultureInfo.InvariantCulture)); } @@ -405,7 +416,7 @@ namespace mRemoteNG.UI.Forms if (!Settings.Default.MinimizeToTray) return; if (Runtime.NotificationAreaIcon == null) { - Runtime.NotificationAreaIcon = new NotificationAreaIcon(this, _connectionInitiator); + Runtime.NotificationAreaIcon = new NotificationAreaIcon(this, _connectionInitiator, _shutdown); } Hide(); } diff --git a/mRemoteV1/UI/Forms/frmOptions.cs b/mRemoteV1/UI/Forms/frmOptions.cs index 5193ba87..6276886a 100644 --- a/mRemoteV1/UI/Forms/frmOptions.cs +++ b/mRemoteV1/UI/Forms/frmOptions.cs @@ -16,18 +16,19 @@ namespace mRemoteNG.UI.Forms private readonly string _pageName; private readonly IConnectionInitiator _connectionInitiator; private readonly Action _showWindowAction; + private readonly Func _notificationAreaIconBuilder; - - public frmOptions(IConnectionInitiator connectionInitiator, Action showWindowAction) - : this(connectionInitiator, showWindowAction, Language.strStartupExit) + public frmOptions(IConnectionInitiator connectionInitiator, Action showWindowAction, Func notificationAreaIconBuilder) + : this(connectionInitiator, showWindowAction, notificationAreaIconBuilder, Language.strStartupExit) { } - public frmOptions(IConnectionInitiator connectionInitiator, Action showWindowAction, string pageName) + public frmOptions(IConnectionInitiator connectionInitiator, Action showWindowAction, Func notificationAreaIconBuilder, string pageName) { _connectionInitiator = connectionInitiator.ThrowIfNull(nameof(connectionInitiator)); - _pageName = pageName.ThrowIfNull(nameof(pageName)); _showWindowAction = showWindowAction.ThrowIfNull(nameof(showWindowAction)); + _notificationAreaIconBuilder = notificationAreaIconBuilder; + _pageName = pageName.ThrowIfNull(nameof(pageName)); InitializeComponent(); } @@ -67,7 +68,7 @@ namespace mRemoteNG.UI.Forms _pages = new Dictionary { {typeof(StartupExitPage).Name, new StartupExitPage()}, - {typeof(AppearancePage).Name, new AppearancePage(_connectionInitiator)}, + {typeof(AppearancePage).Name, new AppearancePage(_connectionInitiator, _notificationAreaIconBuilder)}, {typeof(TabsPanelsPage).Name, new TabsPanelsPage()}, {typeof(NotificationsPage).Name, new NotificationsPage()}, {typeof(ConnectionsPage).Name, new ConnectionsPage()}, diff --git a/mRemoteV1/UI/Menu/MainFileMenu.cs b/mRemoteV1/UI/Menu/MainFileMenu.cs index bbc81ba2..75fca38f 100644 --- a/mRemoteV1/UI/Menu/MainFileMenu.cs +++ b/mRemoteV1/UI/Menu/MainFileMenu.cs @@ -42,6 +42,7 @@ namespace mRemoteNG.UI.Menu public ConnectionTreeWindow TreeWindow { get; set; } public IConnectionInitiator ConnectionInitiator { get; set; } public Export Export { get; set; } + public Shutdown Shutdown { get; set; } public MainFileMenu() { diff --git a/mRemoteV1/UI/Window/UpdateWindow.cs b/mRemoteV1/UI/Window/UpdateWindow.cs index aa814663..b2dc662b 100644 --- a/mRemoteV1/UI/Window/UpdateWindow.cs +++ b/mRemoteV1/UI/Window/UpdateWindow.cs @@ -8,6 +8,7 @@ using System.Windows.Forms; using mRemoteNG.App; using mRemoteNG.App.Update; using mRemoteNG.Messages; +using mRemoteNG.Tools; using WeifenLuo.WinFormsUI.Docking; namespace mRemoteNG.UI.Window @@ -15,21 +16,17 @@ namespace mRemoteNG.UI.Window public partial class UpdateWindow : BaseWindow { private AppUpdater _appUpdate; + private Shutdown _shutdown; private bool _isUpdateDownloadHandlerDeclared; - #region Public Methods - public UpdateWindow() : this(new DockContent()) - { - } - - public UpdateWindow(DockContent panel) + public UpdateWindow(DockContent panel, Shutdown shutdown) { - WindowType = WindowType.Update; + WindowType = WindowType.Update; DockPnl = panel; + _shutdown = shutdown.ThrowIfNull(nameof(shutdown)); InitializeComponent(); FontOverrider.FontOverride(this); } - #endregion #region Form Stuff @@ -262,7 +259,7 @@ namespace mRemoteNG.UI.Window { if (MessageBox.Show(Language.strUpdateDownloadComplete, Language.strMenuCheckForUpdates, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { - Shutdown.Quit(_appUpdate.CurrentUpdateInfo.UpdateFilePath); + _shutdown.Quit(_appUpdate.CurrentUpdateInfo.UpdateFilePath); } else {