From 4c3d41dcbd9d1e085180e13e0a58187b5a7a7606 Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Sun, 3 May 2020 19:12:09 +0900 Subject: [PATCH] =?utf8?q?=E3=82=B3=E3=83=B3=E3=83=86=E3=82=AD=E3=82=B9?= =?utf8?q?=E3=83=88=E3=83=A1=E3=83=8B=E3=83=A5=E3=83=BC=E3=82=92ContextMen?= =?utf8?q?u{Main,NotifyIcon}=E3=81=AB=E5=88=86=E9=9B=A2=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KancolleSniffer/KancolleSniffer.csproj | 6 ++ KancolleSniffer/Main.cs | 5 ++ KancolleSniffer/MainForm.Designer.cs | 93 --------------------------- KancolleSniffer/MainForm.cs | 61 +++++++++--------- KancolleSniffer/MainForm.resx | 6 -- KancolleSniffer/View/ContextMenuMain.cs | 57 ++++++++++++++++ KancolleSniffer/View/ContextMenuNotifyIcon.cs | 38 +++++++++++ 7 files changed, 137 insertions(+), 129 deletions(-) create mode 100644 KancolleSniffer/View/ContextMenuMain.cs create mode 100644 KancolleSniffer/View/ContextMenuNotifyIcon.cs diff --git a/KancolleSniffer/KancolleSniffer.csproj b/KancolleSniffer/KancolleSniffer.csproj index 5d8bf01..843117b 100644 --- a/KancolleSniffer/KancolleSniffer.csproj +++ b/KancolleSniffer/KancolleSniffer.csproj @@ -91,6 +91,12 @@ Component + + Component + + + Component + Component diff --git a/KancolleSniffer/Main.cs b/KancolleSniffer/Main.cs index 1b59cfe..7b7d89c 100644 --- a/KancolleSniffer/Main.cs +++ b/KancolleSniffer/Main.cs @@ -358,6 +358,11 @@ namespace KancolleSniffer Sniffer.SaveState(); } + public void ShowReport() + { + Process.Start("http://localhost:" + Config.Proxy.Listen + "/"); + } + public void StartCapture() { try diff --git a/KancolleSniffer/MainForm.Designer.cs b/KancolleSniffer/MainForm.Designer.cs index d9bc4f4..a0d70fc 100644 --- a/KancolleSniffer/MainForm.Designer.cs +++ b/KancolleSniffer/MainForm.Designer.cs @@ -52,15 +52,6 @@ namespace KancolleSniffer this.labelQuest = new System.Windows.Forms.Label(); this.labelMissionCaption = new System.Windows.Forms.Label(); this.notifyIconMain = new System.Windows.Forms.NotifyIcon(this.components); - this.contextMenuStripNotifyIcon = new System.Windows.Forms.ContextMenuStrip(this.components); - this.NotifyIconOpenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.NotifyIconExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.contextMenuStripMain = new System.Windows.Forms.ContextMenuStrip(this.components); - this.listToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.LogToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.CaptureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ConfigToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.ExitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.labelMaterialCaption = new System.Windows.Forms.Label(); this.label31 = new System.Windows.Forms.Label(); this.labelAkashiRepair = new System.Windows.Forms.Label(); @@ -76,8 +67,6 @@ namespace KancolleSniffer this.materialHistoryPanel = new KancolleSniffer.View.MaterialHistoryPanel(); this.dropDownButtonMaterialHistory = new KancolleSniffer.View.DropDownButton(); this.mainFleetPanel = new KancolleSniffer.View.MainFleetPanel(); - this.contextMenuStripNotifyIcon.SuspendLayout(); - this.contextMenuStripMain.SuspendLayout(); this.SuspendLayout(); // // labelAkashiRepairTimer @@ -127,81 +116,11 @@ namespace KancolleSniffer // // notifyIconMain // - this.notifyIconMain.ContextMenuStrip = this.contextMenuStripNotifyIcon; this.notifyIconMain.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIconMain.Icon"))); this.notifyIconMain.Text = "KancolleSniffer"; this.notifyIconMain.Visible = true; this.notifyIconMain.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIconMain_MouseDoubleClick); // - // contextMenuStripNotifyIcon - // - this.contextMenuStripNotifyIcon.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.NotifyIconOpenToolStripMenuItem, - this.NotifyIconExitToolStripMenuItem}); - this.contextMenuStripNotifyIcon.Name = "contextMenuStripNotifyIcon"; - this.contextMenuStripNotifyIcon.Size = new System.Drawing.Size(122, 48); - // - // NotifyIconOpenToolStripMenuItem - // - this.NotifyIconOpenToolStripMenuItem.Font = new System.Drawing.Font("メイリオ", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128))); - this.NotifyIconOpenToolStripMenuItem.Name = "NotifyIconOpenToolStripMenuItem"; - this.NotifyIconOpenToolStripMenuItem.Size = new System.Drawing.Size(121, 22); - this.NotifyIconOpenToolStripMenuItem.Text = "開く(&O)"; - this.NotifyIconOpenToolStripMenuItem.Click += new System.EventHandler(this.NotifyIconOpenToolStripMenuItem_Click); - // - // NotifyIconExitToolStripMenuItem - // - this.NotifyIconExitToolStripMenuItem.Name = "NotifyIconExitToolStripMenuItem"; - this.NotifyIconExitToolStripMenuItem.Size = new System.Drawing.Size(121, 22); - this.NotifyIconExitToolStripMenuItem.Text = "終了(&X)"; - this.NotifyIconExitToolStripMenuItem.Click += new System.EventHandler(this.ExitToolStripMenuItem_Click); - // - // contextMenuStripMain - // - this.contextMenuStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.listToolStripMenuItem, - this.LogToolStripMenuItem, - this.CaptureToolStripMenuItem, - this.ConfigToolStripMenuItem, - this.ExitToolStripMenuItem}); - this.contextMenuStripMain.Name = "contextMenuStripToolTip"; - this.contextMenuStripMain.Size = new System.Drawing.Size(126, 114); - // - // listToolStripMenuItem - // - this.listToolStripMenuItem.Name = "listToolStripMenuItem"; - this.listToolStripMenuItem.Size = new System.Drawing.Size(125, 22); - this.listToolStripMenuItem.Text = "一覧(&L)"; - this.listToolStripMenuItem.Click += new System.EventHandler(this.ShipListToolStripMenuItem_Click); - // - // LogToolStripMenuItem - // - this.LogToolStripMenuItem.Name = "LogToolStripMenuItem"; - this.LogToolStripMenuItem.Size = new System.Drawing.Size(125, 22); - this.LogToolStripMenuItem.Text = "報告書(&R)"; - this.LogToolStripMenuItem.Click += new System.EventHandler(this.LogToolStripMenuItem_Click); - // - // CaptureToolStripMenuItem - // - this.CaptureToolStripMenuItem.Name = "CaptureToolStripMenuItem"; - this.CaptureToolStripMenuItem.Size = new System.Drawing.Size(125, 22); - this.CaptureToolStripMenuItem.Text = "撮影(&C)"; - this.CaptureToolStripMenuItem.Click += new System.EventHandler(this.CaptureToolStripMenuItem_Click); - // - // ConfigToolStripMenuItem - // - this.ConfigToolStripMenuItem.Name = "ConfigToolStripMenuItem"; - this.ConfigToolStripMenuItem.Size = new System.Drawing.Size(125, 22); - this.ConfigToolStripMenuItem.Text = "設定(&O)"; - this.ConfigToolStripMenuItem.Click += new System.EventHandler(this.ConfigToolStripMenuItem_Click); - // - // ExitToolStripMenuItem - // - this.ExitToolStripMenuItem.Name = "ExitToolStripMenuItem"; - this.ExitToolStripMenuItem.Size = new System.Drawing.Size(125, 22); - this.ExitToolStripMenuItem.Text = "終了(&X)"; - this.ExitToolStripMenuItem.Click += new System.EventHandler(this.ExitToolStripMenuItem_Click); - // // labelMaterialCaption // this.labelMaterialCaption.AutoSize = true; @@ -344,7 +263,6 @@ namespace KancolleSniffer this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(232, 456); - this.ContextMenuStrip = this.contextMenuStripMain; this.Controls.Add(this.mainFleetPanel); this.Controls.Add(this.dropDownButtonMaterialHistory); this.Controls.Add(this.materialHistoryPanel); @@ -370,8 +288,6 @@ namespace KancolleSniffer this.MaximizeBox = false; this.Name = "MainForm"; this.Text = "KancolleSniffer"; - this.contextMenuStripNotifyIcon.ResumeLayout(false); - this.contextMenuStripMain.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -383,18 +299,9 @@ namespace KancolleSniffer private System.Windows.Forms.Label labelQuest; private System.Windows.Forms.Label labelMissionCaption; private System.Windows.Forms.NotifyIcon notifyIconMain; - private System.Windows.Forms.ContextMenuStrip contextMenuStripMain; - private System.Windows.Forms.ToolStripMenuItem ConfigToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem ExitToolStripMenuItem; private System.Windows.Forms.Label labelMaterialCaption; private DropDownButton dropDownButtonRepairList; private System.Windows.Forms.Label label31; - private System.Windows.Forms.ContextMenuStrip contextMenuStripNotifyIcon; - private System.Windows.Forms.ToolStripMenuItem NotifyIconOpenToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem NotifyIconExitToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem listToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem LogToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem CaptureToolStripMenuItem; private System.Windows.Forms.Label labelAkashiRepairTimer; private System.Windows.Forms.Label labelAkashiRepair; private RepairListForMain panelRepairList; diff --git a/KancolleSniffer/MainForm.cs b/KancolleSniffer/MainForm.cs index c05ea41..404baba 100644 --- a/KancolleSniffer/MainForm.cs +++ b/KancolleSniffer/MainForm.cs @@ -14,7 +14,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; using System.Linq; using System.Threading.Tasks; @@ -31,6 +30,8 @@ namespace KancolleSniffer private readonly ResizableToolTip _toolTip = new ResizableToolTip(); private readonly ResizableToolTip _tooltipCopy = new ResizableToolTip {ShowAlways = false, AutomaticDelay = 0}; private readonly ListFormGroup _listFormGroup; + private readonly ContextMenuMain _contextMenuMain = new ContextMenuMain(); + private readonly ContextMenuNotifyIcon _contextMenuNotifyIcon = new ContextMenuNotifyIcon(); private IEnumerable _updateable; private IEnumerable _timers; @@ -44,6 +45,9 @@ namespace KancolleSniffer public MainForm(Main main) { InitializeComponent(); + notifyIconMain.ContextMenuStrip = _contextMenuNotifyIcon; + // ReSharper disable once VirtualMemberCallInConstructor + ContextMenuStrip = _contextMenuMain; SetupMain(main); _listFormGroup = new ListFormGroup(this); Notifier = new Notifier(FlashWindow, ShowTaster, PlaySound); @@ -62,6 +66,7 @@ namespace KancolleSniffer SetScaleFactorOfDpiScaling(); SetupQuestPanel(); SetMainFormEventHandler(); + SetContextMenuEventHandler(); mainFleetPanel.AkashiRepairTimer = labelAkashiRepairTimer; mainFleetPanel.ShowShipOnList = ShowShipOnShipList; panelRepairList.CreateLabels(panelRepairList_Click); @@ -80,6 +85,27 @@ namespace KancolleSniffer Activated += MainForm_Activated; } + private void SetContextMenuEventHandler() + { + SetContextMenuMainEventHandler(); + SetContextMenuNotifyIconEventHandler(); + } + + private void SetContextMenuMainEventHandler() + { + _contextMenuMain.SetClickHandlers( + _listFormGroup.ShowOrCreate, + _main.ShowReport, + _main.StartCapture, + _main.ShowConfigDialog, + Close); + } + + private void SetContextMenuNotifyIconEventHandler() + { + _contextMenuNotifyIcon.SetEventHandlers(RevertFromIcon, Close); + } + private void SetupUpdateable() { _updateable = new IUpdateContext[] @@ -216,26 +242,16 @@ namespace KancolleSniffer } } - private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e) - { - NotifyIconOpenToolStripMenuItem_Click(sender, e); - } - - private void NotifyIconOpenToolStripMenuItem_Click(object sender, EventArgs e) + private void RevertFromIcon() { ShowInTaskbar = true; WindowState = FormWindowState.Normal; TopMost = _listFormGroup.TopMost = Config.TopMost; // 最前面に表示されなくなることがあるのを回避する } - private void ExitToolStripMenuItem_Click(object sender, EventArgs e) - { - Close(); - } - - private void ConfigToolStripMenuItem_Click(object sender, EventArgs e) + private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e) { - _main.ShowConfigDialog(); + RevertFromIcon(); } private void PerformZoom() @@ -250,7 +266,7 @@ namespace KancolleSniffer foreach (var control in new Control[] { this, mainFleetPanel.Guide, hqPanel.Login, - contextMenuStripMain + _contextMenuMain }.Concat(_main.Controls)) { control.Font = ZoomFont(control.Font); @@ -415,16 +431,6 @@ namespace KancolleSniffer dropDownButtonRepairList.BackColor = DefaultBackColor; } - private void ShipListToolStripMenuItem_Click(object sender, EventArgs e) - { - _listFormGroup.ShowOrCreate(); - } - - private void LogToolStripMenuItem_Click(object sender, EventArgs e) - { - Process.Start("http://localhost:" + Config.Proxy.Listen + "/"); - } - private void labelClearQuest_Click(object sender, EventArgs e) { Sniffer.ClearQuests(); @@ -455,10 +461,5 @@ namespace KancolleSniffer _tooltipCopy.Active = false; }); } - - private void CaptureToolStripMenuItem_Click(object sender, EventArgs e) - { - _main.StartCapture(); - } } } \ No newline at end of file diff --git a/KancolleSniffer/MainForm.resx b/KancolleSniffer/MainForm.resx index a5ddaef..ae211f6 100644 --- a/KancolleSniffer/MainForm.resx +++ b/KancolleSniffer/MainForm.resx @@ -120,9 +120,6 @@ 129, 17 - - 577, 26 - @@ -678,9 +675,6 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - - 269, 17 - AAABAAQAQEAAAAEAIAAoQAAARgAAACAgAAABACAAKBAAAG5AAAAYGAAAAQAgACgJAACWUAAAEBAAAAEA diff --git a/KancolleSniffer/View/ContextMenuMain.cs b/KancolleSniffer/View/ContextMenuMain.cs new file mode 100644 index 0000000..19c6fa8 --- /dev/null +++ b/KancolleSniffer/View/ContextMenuMain.cs @@ -0,0 +1,57 @@ +using System; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; + +namespace KancolleSniffer.View +{ + public class ContextMenuMain : ContextMenuStrip + { + private readonly ToolStripMenuItem[] _menuItems = + { + new ToolStripMenuItem + { + Name = "listToolStripMenuItem", + Size = new Size(125, 22), + Text = "一覧(&L)" + }, + new ToolStripMenuItem + { + Name = "LogToolStripMenuItem", + Size = new Size(125, 22), + Text = "報告書(&R)" + }, + new ToolStripMenuItem + { + Name = "CaptureToolStripMenuItem", + Size = new Size(125, 22), + Text = "撮影(&C)" + }, + new ToolStripMenuItem + { + Name = "ConfigToolStripMenuItem", + Size = new Size(125, 22), + Text = "設定(&O)" + }, + new ToolStripMenuItem + { + Name = "ExitToolStripMenuItem", + Size = new Size(125, 22), + Text = "終了(&X)" + } + }; + + public ContextMenuMain() + { + // ReSharper disable once VirtualMemberCallInConstructor + Items.AddRange(_menuItems.ToArray()); + } + + public void SetClickHandlers(Action list, Action report, Action capture, + Action config, Action exit) + { + foreach (var entry in _menuItems.Zip(new []{list, report, capture, config, exit}, (item, handler) => new {item, handler})) + entry.item.Click += (sender, e) => entry.handler(); + } + } +} \ No newline at end of file diff --git a/KancolleSniffer/View/ContextMenuNotifyIcon.cs b/KancolleSniffer/View/ContextMenuNotifyIcon.cs new file mode 100644 index 0000000..a4e3c00 --- /dev/null +++ b/KancolleSniffer/View/ContextMenuNotifyIcon.cs @@ -0,0 +1,38 @@ +using System; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; + +namespace KancolleSniffer.View +{ + public class ContextMenuNotifyIcon : ContextMenuStrip + { + private readonly ToolStripMenuItem[] _menuItems = + { + new ToolStripMenuItem + { + Font = new Font("メイリオ", 9F, FontStyle.Bold, + GraphicsUnit.Point, 128), + Size = new Size(121, 22), + Text = "開く(&O)" + }, + new ToolStripMenuItem + { + Size = new Size(121, 22), + Text = "終了(&X)" + } + }; + + public ContextMenuNotifyIcon() + { + // ReSharper disable once VirtualMemberCallInConstructor + Items.AddRange(_menuItems.ToArray()); + } + + public void SetEventHandlers(Action open, Action exit) + { + _menuItems[0].Click += (sender , e) => open(); + _menuItems[1].Click += (sender , e) => exit(); + } + } +} \ No newline at end of file -- 2.11.0