public SysTrayMenu(Action helpCallback, Action exitApplicationCallback) { Current = this; if (_proxy == null) { _proxy = new SysTrayMenuProxy(); Mubox.Extensions.ExtensionManager.Instance.RegisterInstance(typeof(ISysTrayMenu), _proxy); } try { Resources["imageShortcutIcon"] = new Image { Source = (new ImageSourceConverter()).ConvertFromString("pack://application:,,,/Mubox;component/Content/Images/GotoShortcutsHS.png") as ImageSource }; Resources["imageNavForwardIcon"] = new Image { Source = (new ImageSourceConverter()).ConvertFromString("pack://application:,,,/Mubox;component/Content/Images/NavForward.png") as ImageSource }; Resources["imageMenuHelpIcon"] = new Image { Source = (new ImageSourceConverter()).ConvertFromString("pack://application:,,,/Mubox;component/Content/Images/HelpIcon.png") as ImageSource }; } catch (Exception ex) { ex.Log(); } try { System.Drawing.Point mousePosition = new System.Drawing.Point(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - 16, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - 24); WinAPI.Cursor.GetCursorPos(out mousePosition); List<object> quickLaunchMenuItems = new List<object>(); ItemsSource = quickLaunchMenuItems; MenuItem menuItem = null; foreach (var profile in Mubox.Configuration.MuboxConfigSection.Default.Profiles.OfType<Mubox.Configuration.ProfileSettings>()) { menuItem = CreateProfileShortcutMenu(profile); if (menuItem != null) { quickLaunchMenuItems.Add(menuItem); } } // New Game Profile quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.Click += (sender, e) => { try { string profileName = Mubox.View.Profile.PromptForProfileNameDialog.PromptForProfileName(); // TODO try and enforce "unique" profile names var profileSettings = Mubox.Configuration.MuboxConfigSection.Default.Profiles.GetOrCreateNew(profileName); Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile = profileSettings; Mubox.Configuration.MuboxConfigSection.Save(); } catch (Exception ex) { ex.Log(); } }; menuItem.Header = "_Configure New Game Profile..."; menuItem.Icon = Resources["imageSettingsIcon"]; quickLaunchMenuItems.Add(menuItem); // Launch Mubox Server quickLaunchMenuItems.Add(new Separator()); if (Mubox.View.Server.ServerWindow.Instance == null) { menuItem = new MenuItem(); menuItem.Click += (sender, e) => { CreateServerUI(); }; menuItem.Header = "Mubox _Server..."; quickLaunchMenuItems.Add(menuItem); } else { // "Disable 'Client Switching' Feature" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.DisableAltTabHook; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.DisableAltTabHook = !Mubox.Configuration.MuboxConfigSection.Default.DisableAltTabHook; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Disable \"Client Switching\" Feature"; menuItem.ToolTip = "Enable this option to use the default Windows Task Switcher instead of the Mubox Server UI, this only affects Client Switching."; quickLaunchMenuItems.Add(menuItem); // "Reverse Client Switching" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.ReverseClientSwitching; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.ReverseClientSwitching = !Mubox.Configuration.MuboxConfigSection.Default.ReverseClientSwitching; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Reverse Client Switching"; menuItem.ToolTip = "Enable this option to reverse the order that Client Switcher will switch between clients."; quickLaunchMenuItems.Add(menuItem); // "Toggle Server UI" menuItem = new MenuItem(); menuItem.Click += (sender, e) => { if (Mubox.View.Server.ServerWindow.Instance != null) { Mubox.View.Server.ServerWindow.Instance.SetInputCapture((Mubox.View.Server.ServerWindow.Instance.Visibility == Visibility.Visible), (Mubox.View.Server.ServerWindow.Instance.Visibility != Visibility.Visible)); } }; menuItem.Header = "Toggle Server UI"; menuItem.ToolTip = "Show/Hide the Server UI"; quickLaunchMenuItems.Add(menuItem); quickLaunchMenuItems.Add(new Separator()); // "Enable Input Capture" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled; menuItem.Click += (sender, e) => { if (Mubox.View.Server.ServerWindow.Instance != null) { Mubox.View.Server.ServerWindow.Instance.ToggleInputCapture(false); } }; menuItem.Header = "Enable Input Capture"; menuItem.ToolTip = "'Input Capture' includes both Mouse and Keyboard Input"; quickLaunchMenuItems.Add(menuItem); // "Configure Keyboard" menuItem = new MenuItem(); menuItem.Click += (sender, e) => { Mubox.View.Server.MulticastConfigDialog.ShowStaticDialog(); }; menuItem.Header = "Configure Keyboard.."; quickLaunchMenuItems.Add(menuItem); //if (Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled) { // "Enable Multicast" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.EnableMulticast; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.EnableMulticast = !Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.EnableMulticast; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Enable Multicast"; menuItem.ToolTip = "'Keyboard Multicast' replicates your Key Presses to all Clients."; quickLaunchMenuItems.Add(menuItem); // "Enable Mouse Capture" quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture = !Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Enable Mouse Capture"; menuItem.ToolTip = "Disable Mouse Capture if you use a third-party application for the Mouse."; quickLaunchMenuItems.Add(menuItem); //if (Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture) { { // "Mouse Multicast" Menu List<MenuItem> mouseMulticastModeMenu = new List<MenuItem>(); // "Disabled" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode == MouseMulticastModeType.Disabled; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode = MouseMulticastModeType.Disabled; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Disabled"; menuItem.ToolTip = "Use this option to Disable the Mouse Multicast feature."; mouseMulticastModeMenu.Add(menuItem); // "Toggled" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = (Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode == Mubox.Model.MouseMulticastModeType.Toggled); menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode = Mubox.Model.MouseMulticastModeType.Toggled; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Toggled"; menuItem.ToolTip = "Mouse Multicast is Active while CAPS LOCK is ON, and Inactive while CAPS LOCK is OFF."; mouseMulticastModeMenu.Add(menuItem); // "Pressed" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = (Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode == MouseMulticastModeType.Pressed); menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode = Mubox.Model.MouseMulticastModeType.Pressed; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Pressed"; menuItem.ToolTip = "Mouse Multicast is Active while CAPS LOCK Key is pressed, and Inactive while CAPS LOCK Key is released."; mouseMulticastModeMenu.Add(menuItem); menuItem = new MenuItem(); menuItem.Header = "Mouse Multicast"; menuItem.ItemsSource = mouseMulticastModeMenu; quickLaunchMenuItems.Add(menuItem); } { // "Click Buffer" Option List<MenuItem> mouseClickBufferMenu = new List<MenuItem>(); foreach (double time in new double[] { 0.0, 100.0, 150.0, 200.0, 250.0, 500.0, 750.0, 1000.0 }) { CreateMouseBufferMenuItem(menuItem, mouseClickBufferMenu, time); } menuItem = new MenuItem(); menuItem.Header = "Click Buffer"; menuItem.ToolTip = "Click Buffer prevents Mouse Movement from interrupting a Click gesture."; menuItem.ItemsSource = mouseClickBufferMenu; quickLaunchMenuItems.Add(menuItem); } } } quickLaunchMenuItems.Add(new Separator()); // "Auto-Start Server" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.AutoStartServer; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.AutoStartServer = !Mubox.Configuration.MuboxConfigSection.Default.AutoStartServer; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Auto Start Server"; quickLaunchMenuItems.Add(menuItem); } // Show Help quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.Click += (sender, e) => { helpCallback(); }; menuItem.Icon = Resources["imageMenuHelpIcon"]; menuItem.Header = "Help..."; quickLaunchMenuItems.Add(menuItem); // Cancel QuickLaunch Menu quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.Click += (sender, e) => { // NOP }; menuItem.Header = "Cancel Menu"; quickLaunchMenuItems.Add(menuItem); // Exit QuickLaunch Application menuItem = new MenuItem(); menuItem.Click += (sender, e) => { exitApplicationCallback(); foreach (System.Windows.Window window in System.Windows.Application.Current.Windows) { try { window.Close(); } catch (Exception ex) { ex.Log(); } } Mubox.View.Server.ServerWindow.Instance = null; exitApplicationCallback(); }; menuItem.Header = "E_xit Mubox"; quickLaunchMenuItems.Add(menuItem); Placement = System.Windows.Controls.Primitives.PlacementMode.AbsolutePoint; VerticalOffset = mousePosition.Y - 2; HorizontalOffset = mousePosition.X - 8; } catch (Exception ex) { ex.Log(); } }
public SysTrayMenu(Action helpCallback, Action exitApplicationCallback) { Current = this; if (_proxy == null) { _proxy = new SysTrayMenuProxy(); Mubox.Extensions.ExtensionManager.Instance.RegisterInstance(typeof(ISysTrayMenu), _proxy); } try { Resources["imageShortcutIcon"] = new Image { Source = (new ImageSourceConverter()).ConvertFromString("pack://application:,,,/Mubox;component/Content/Images/GotoShortcutsHS.png") as ImageSource }; Resources["imageNavForwardIcon"] = new Image { Source = (new ImageSourceConverter()).ConvertFromString("pack://application:,,,/Mubox;component/Content/Images/NavForward.png") as ImageSource }; Resources["imageMenuHelpIcon"] = new Image { Source = (new ImageSourceConverter()).ConvertFromString("pack://application:,,,/Mubox;component/Content/Images/HelpIcon.png") as ImageSource }; } catch (Exception ex) { ex.Log(); } try { System.Drawing.Point mousePosition = new System.Drawing.Point(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - 16, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - 24); WinAPI.Cursor.GetCursorPos(out mousePosition); List <object> quickLaunchMenuItems = new List <object>(); ItemsSource = quickLaunchMenuItems; MenuItem menuItem = null; foreach (var profile in Mubox.Configuration.MuboxConfigSection.Default.Profiles.OfType <Mubox.Configuration.ProfileSettings>()) { menuItem = CreateProfileShortcutMenu(profile); if (menuItem != null) { quickLaunchMenuItems.Add(menuItem); } } // New Game Profile quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.Click += (sender, e) => { try { string profileName = Mubox.View.Profile.PromptForProfileNameDialog.PromptForProfileName(); // TODO try and enforce "unique" profile names var profileSettings = Mubox.Configuration.MuboxConfigSection.Default.Profiles.GetOrCreateNew(profileName); Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile = profileSettings; Mubox.Configuration.MuboxConfigSection.Save(); } catch (Exception ex) { ex.Log(); } }; menuItem.Header = "_Configure New Game Profile..."; menuItem.Icon = Resources["imageSettingsIcon"]; quickLaunchMenuItems.Add(menuItem); // Launch Mubox Server quickLaunchMenuItems.Add(new Separator()); if (Mubox.View.Server.ServerWindow.Instance == null) { menuItem = new MenuItem(); menuItem.Click += (sender, e) => { CreateServerUI(); }; menuItem.Header = "Mubox _Server..."; quickLaunchMenuItems.Add(menuItem); } else { // "Disable 'Client Switching' Feature" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.DisableAltTabHook; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.DisableAltTabHook = !Mubox.Configuration.MuboxConfigSection.Default.DisableAltTabHook; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Disable \"Client Switching\" Feature"; menuItem.ToolTip = "Enable this option to use the default Windows Task Switcher instead of the Mubox Server UI, this only affects Client Switching."; quickLaunchMenuItems.Add(menuItem); // "Reverse Client Switching" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.ReverseClientSwitching; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.ReverseClientSwitching = !Mubox.Configuration.MuboxConfigSection.Default.ReverseClientSwitching; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Reverse Client Switching"; menuItem.ToolTip = "Enable this option to reverse the order that Client Switcher will switch between clients."; quickLaunchMenuItems.Add(menuItem); // "Toggle Server UI" menuItem = new MenuItem(); menuItem.Click += (sender, e) => { if (Mubox.View.Server.ServerWindow.Instance != null) { Mubox.View.Server.ServerWindow.Instance.SetInputCapture((Mubox.View.Server.ServerWindow.Instance.Visibility == Visibility.Visible), (Mubox.View.Server.ServerWindow.Instance.Visibility != Visibility.Visible)); } }; menuItem.Header = "Toggle Server UI"; menuItem.ToolTip = "Show/Hide the Server UI"; quickLaunchMenuItems.Add(menuItem); quickLaunchMenuItems.Add(new Separator()); // "Enable Input Capture" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled; menuItem.Click += (sender, e) => { if (Mubox.View.Server.ServerWindow.Instance != null) { Mubox.View.Server.ServerWindow.Instance.ToggleInputCapture(false); } }; menuItem.Header = "Enable Input Capture"; menuItem.ToolTip = "'Input Capture' includes both Mouse and Keyboard Input"; quickLaunchMenuItems.Add(menuItem); // "Configure Keyboard" menuItem = new MenuItem(); menuItem.Click += (sender, e) => { Mubox.View.Server.MulticastConfigDialog.ShowStaticDialog(); }; menuItem.Header = "Configure Keyboard.."; quickLaunchMenuItems.Add(menuItem); //if (Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled) { // "Enable Multicast" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.EnableMulticast; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.EnableMulticast = !Mubox.Configuration.MuboxConfigSection.Default.Profiles.ActiveProfile.EnableMulticast; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Enable Multicast"; menuItem.ToolTip = "'Keyboard Multicast' replicates your Key Presses to all Clients."; quickLaunchMenuItems.Add(menuItem); // "Enable Mouse Capture" quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture = !Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Enable Mouse Capture"; menuItem.ToolTip = "Disable Mouse Capture if you use a third-party application for the Mouse."; quickLaunchMenuItems.Add(menuItem); //if (Mubox.Configuration.MuboxConfigSection.Default.EnableMouseCapture) { { // "Mouse Multicast" Menu List <MenuItem> mouseMulticastModeMenu = new List <MenuItem>(); // "Disabled" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode == MouseMulticastModeType.Disabled; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode = MouseMulticastModeType.Disabled; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Disabled"; menuItem.ToolTip = "Use this option to Disable the Mouse Multicast feature."; mouseMulticastModeMenu.Add(menuItem); // "Toggled" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = (Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode == Mubox.Model.MouseMulticastModeType.Toggled); menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode = Mubox.Model.MouseMulticastModeType.Toggled; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Toggled"; menuItem.ToolTip = "Mouse Multicast is Active while CAPS LOCK is ON, and Inactive while CAPS LOCK is OFF."; mouseMulticastModeMenu.Add(menuItem); // "Pressed" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = (Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode == MouseMulticastModeType.Pressed); menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.MouseMulticastMode = Mubox.Model.MouseMulticastModeType.Pressed; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Pressed"; menuItem.ToolTip = "Mouse Multicast is Active while CAPS LOCK Key is pressed, and Inactive while CAPS LOCK Key is released."; mouseMulticastModeMenu.Add(menuItem); menuItem = new MenuItem(); menuItem.Header = "Mouse Multicast"; menuItem.ItemsSource = mouseMulticastModeMenu; quickLaunchMenuItems.Add(menuItem); } { // "Click Buffer" Option List <MenuItem> mouseClickBufferMenu = new List <MenuItem>(); foreach (double time in new double[] { 0.0, 100.0, 150.0, 200.0, 250.0, 500.0, 750.0, 1000.0 }) { CreateMouseBufferMenuItem(menuItem, mouseClickBufferMenu, time); } menuItem = new MenuItem(); menuItem.Header = "Click Buffer"; menuItem.ToolTip = "Click Buffer prevents Mouse Movement from interrupting a Click gesture."; menuItem.ItemsSource = mouseClickBufferMenu; quickLaunchMenuItems.Add(menuItem); } } } quickLaunchMenuItems.Add(new Separator()); // "Auto-Start Server" menuItem = new MenuItem(); menuItem.IsCheckable = true; menuItem.IsChecked = Mubox.Configuration.MuboxConfigSection.Default.AutoStartServer; menuItem.Click += (sender, e) => { Mubox.Configuration.MuboxConfigSection.Default.AutoStartServer = !Mubox.Configuration.MuboxConfigSection.Default.AutoStartServer; Mubox.Configuration.MuboxConfigSection.Save(); }; menuItem.Header = "Auto Start Server"; quickLaunchMenuItems.Add(menuItem); } // Show Help quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.Click += (sender, e) => { helpCallback(); }; menuItem.Icon = Resources["imageMenuHelpIcon"]; menuItem.Header = "Help..."; quickLaunchMenuItems.Add(menuItem); // Cancel QuickLaunch Menu quickLaunchMenuItems.Add(new Separator()); menuItem = new MenuItem(); menuItem.Click += (sender, e) => { // NOP }; menuItem.Header = "Cancel Menu"; quickLaunchMenuItems.Add(menuItem); // Exit QuickLaunch Application menuItem = new MenuItem(); menuItem.Click += (sender, e) => { exitApplicationCallback(); foreach (System.Windows.Window window in System.Windows.Application.Current.Windows) { try { window.Close(); } catch (Exception ex) { ex.Log(); } } Mubox.View.Server.ServerWindow.Instance = null; exitApplicationCallback(); }; menuItem.Header = "E_xit Mubox"; quickLaunchMenuItems.Add(menuItem); Placement = System.Windows.Controls.Primitives.PlacementMode.AbsolutePoint; VerticalOffset = mousePosition.Y - 2; HorizontalOffset = mousePosition.X - 8; } catch (Exception ex) { ex.Log(); } }