mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
commit
99fcdc166b
1 changed files with 39 additions and 25 deletions
|
|
@ -11,6 +11,7 @@ using Flow.Launcher.Core.Resource;
|
|||
using Flow.Launcher.Helper;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.ViewModel;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Application = System.Windows.Application;
|
||||
using Screen = System.Windows.Forms.Screen;
|
||||
using ContextMenuStrip = System.Windows.Forms.ContextMenuStrip;
|
||||
|
|
@ -30,6 +31,7 @@ namespace Flow.Launcher
|
|||
private bool isProgressBarStoryboardPaused;
|
||||
private Settings _settings;
|
||||
private NotifyIcon _notifyIcon;
|
||||
private ContextMenu contextMenu;
|
||||
private MainViewModel _viewModel;
|
||||
|
||||
#endregion
|
||||
|
|
@ -159,14 +161,10 @@ namespace Flow.Launcher
|
|||
|
||||
private void UpdateNotifyIconText()
|
||||
{
|
||||
var menu = _notifyIcon.ContextMenuStrip;
|
||||
var open = menu.Items[0];
|
||||
var setting = menu.Items[1];
|
||||
var exit = menu.Items[2];
|
||||
|
||||
open.Text = InternationalizationManager.Instance.GetTranslation("iconTrayOpen");
|
||||
setting.Text = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
|
||||
exit.Text = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
|
||||
var menu = contextMenu;
|
||||
((MenuItem)menu.Items[1]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen");
|
||||
((MenuItem)menu.Items[2]).Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings");
|
||||
((MenuItem)menu.Items[3]).Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit");
|
||||
}
|
||||
|
||||
private void InitializeNotifyIcon()
|
||||
|
|
@ -177,30 +175,46 @@ namespace Flow.Launcher
|
|||
Icon = Properties.Resources.app,
|
||||
Visible = !_settings.HideNotifyIcon
|
||||
};
|
||||
var menu = new ContextMenuStrip();
|
||||
var items = menu.Items;
|
||||
contextMenu = new ContextMenu();
|
||||
|
||||
var header = new MenuItem
|
||||
{
|
||||
Header = "Flow Launcher",
|
||||
IsEnabled = false
|
||||
};
|
||||
var open = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen")
|
||||
};
|
||||
var settings = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings")
|
||||
};
|
||||
var exit = new MenuItem
|
||||
{
|
||||
Header = InternationalizationManager.Instance.GetTranslation("iconTrayExit")
|
||||
};
|
||||
|
||||
var open = items.Add(InternationalizationManager.Instance.GetTranslation("iconTrayOpen"));
|
||||
open.Click += (o, e) => Visibility = Visibility.Visible;
|
||||
var setting = items.Add(InternationalizationManager.Instance.GetTranslation("iconTraySettings"));
|
||||
setting.Click += (o, e) => App.API.OpenSettingDialog();
|
||||
var exit = items.Add(InternationalizationManager.Instance.GetTranslation("iconTrayExit"));
|
||||
settings.Click += (o, e) => App.API.OpenSettingDialog();
|
||||
exit.Click += (o, e) => Close();
|
||||
contextMenu.Items.Add(header);
|
||||
contextMenu.Items.Add(open);
|
||||
contextMenu.Items.Add(settings);
|
||||
contextMenu.Items.Add(exit);
|
||||
|
||||
_notifyIcon.ContextMenuStrip = menu;
|
||||
_notifyIcon.ContextMenuStrip = new ContextMenuStrip(); // it need for close the context menu. if not, context menu can't close.
|
||||
_notifyIcon.MouseClick += (o, e) =>
|
||||
{
|
||||
if (e.Button == MouseButtons.Left)
|
||||
switch (e.Button)
|
||||
{
|
||||
if (menu.Visible)
|
||||
{
|
||||
menu.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = System.Windows.Forms.Cursor.Position;
|
||||
menu.Show(p);
|
||||
}
|
||||
case MouseButtons.Left:
|
||||
_viewModel.ToggleFlowLauncher();
|
||||
break;
|
||||
|
||||
case MouseButtons.Right:
|
||||
contextMenu.IsOpen = true;
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue