Mercurial > servermonitor
diff ServerMonitor/Forms/ServerSummaryForm.cs @ 8:052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Sat, 09 Mar 2019 20:14:03 -0500 |
parents | c1dffaac66fa |
children | 9e77c0dccb66 |
line wrap: on
line diff
--- a/ServerMonitor/Forms/ServerSummaryForm.cs Fri Mar 01 21:39:22 2019 -0500 +++ b/ServerMonitor/Forms/ServerSummaryForm.cs Sat Mar 09 20:14:03 2019 -0500 @@ -40,6 +40,10 @@ private void ServerSummaryForm_Load(object sender, EventArgs e) { + Size size = Settings.Default.SummaryFormSize; + if (size.Height > 0 && size.Width > 0) + Size = size; + Helpers.FormatImageButton(NewServerButton); Helpers.FormatImageButton(SettingsButton); monitor = new ServerMonitor(this); @@ -61,7 +65,6 @@ } } } - NotifyIcon.Icon = new Icon(Icon, 16, 16); monitor.CheckStatusChanged += Monitor_CheckStatusChanged; RefreshDisplay(); CollectPrivateKeyPasswords(); @@ -103,11 +106,25 @@ control.Click += ServerSummaryControl_Click; ServerPanel.Controls.Add(control); } + UpdateIcon(); } private void RefreshServer(Server server) { ServerPanel.Controls.Cast<ServerSummaryControl>().FirstOrDefault(c => c.Server == server).Refresh(); + UpdateIcon(); + } + + private void UpdateIcon() + { + CheckStatus status = monitor.Servers + .Select(s => s.Enabled + ? s.Status + : s.KeyStatus == KeyStatus.NeedPassword ? CheckStatus.Warning : CheckStatus.Success) + .DefaultIfEmpty(CheckStatus.Success) + .Max(); + Icon = status.GetIcon(); + NotifyIcon.Icon = Icon; } private void CollectPrivateKeyPasswords() @@ -130,7 +147,9 @@ private void Monitor_CheckStatusChanged(object sender, CheckStatusChangedEventArgs e) { if (e.CheckResult != null) + { RefreshServer(e.Check.Server); + } } private ToolTipIcon GetToolTipIcon(CheckStatus status) @@ -229,5 +248,44 @@ { return ((ServerSummaryControl)menu.SourceControl).Server; } + + private void ServerSummaryForm_ResizeEnd(object sender, EventArgs e) + { + Settings.Default.SummaryFormSize = Size; + Settings.Default.Save(); + } + + protected override void WndProc(ref Message m) + { + if (m.Msg == Win32Helpers.WM_SHOWMONITOR) + ShowWindow(); + base.WndProc(ref m); + } + + private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + ShowWindow(); + else if (e.Button == MouseButtons.Right) + NotificationIconMenu.Show(); + } + + private void ShowWindow() + { + if (WindowState == FormWindowState.Minimized) + WindowState = FormWindowState.Normal; + Show(); + TopMost = true; + TopMost = false; + Activate(); + } + + private void NotificationIconMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e) + { + if (e.ClickedItem == ShowServerMonitorMenuItem) + ShowWindow(); + else if (e.ClickedItem == ExitMenuItem) + Application.Exit(); + } } }