Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 34 additions & 24 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public partial class MainWindow
private bool isProgressBarStoryboardPaused;
private Settings _settings;
private NotifyIcon _notifyIcon;
private ContextMenu contextMenu;
private MainViewModel _viewModel;

#endregion
Expand Down Expand Up @@ -159,14 +160,19 @@ private void InitializePosition()

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;

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") };
menu.Items[0] = header;
menu.Items[1] = open;
menu.Items[2] = settings;
menu.Items[3] = exit;
open.Click += (o, e) => Visibility = Visibility.Visible;
settings.Click += (o, e) => App.API.OpenSettingDialog();
exit.Click += (o, e) => Close();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this part, why not keep the original one? I don't see any difference from that. Just need to change 0 to 1, 1 to 2, 2 to 3 because you have added a header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

original : ContextMenuStrip
New : Context Menu

}

private void InitializeNotifyIcon()
Expand All @@ -178,29 +184,33 @@ private void InitializeNotifyIcon()
Visible = !_settings.HideNotifyIcon
};
var menu = new ContextMenuStrip();
var items = menu.Items;
contextMenu = new ContextMenu();

MenuItem header = new MenuItem() { Header = "Flow Launcher", IsEnabled = false };
MenuItem open = new MenuItem() { Header = InternationalizationManager.Instance.GetTranslation("iconTrayOpen") };
MenuItem settings = new MenuItem() { Header = InternationalizationManager.Instance.GetTranslation("iconTraySettings") };
MenuItem 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 = menu; /*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;
}
};
}
Expand Down