public SubMenu(string MenuText, MenuFlags Flags, NativeMenu Owner) { this.Owner = Owner; this.Flags = Flags; this.MenuText = MenuText; CreateHandle(); }
public void MenuAttached(object sender, VisualTreeAttachmentEventArgs e) { if (NativeMenu.GetIsNativeMenuExported(this) && sender is Menu mainMenu) { mainMenu.IsVisible = false; } }
public MainWindow() { this.InitializeComponent(); this.AttachDevTools(new Avalonia.Diagnostics.DevToolsOptions() { StartupScreenIndex = 1, }); //Renderer.DrawFps = true; //Renderer.DrawDirtyRects = Renderer.DrawFps = true; _notificationArea = new WindowNotificationManager(this) { Position = NotificationPosition.TopRight, MaxItems = 3 }; DataContext = new MainWindowViewModel(_notificationArea); _recentMenu = ((NativeMenu.GetMenu(this).Items[0] as NativeMenuItem).Menu.Items[2] as NativeMenuItem).Menu; var mainMenu = this.FindControl <Menu>("MainMenu"); mainMenu.AttachedToVisualTree += MenuAttached; ExtendClientAreaChromeHints = Avalonia.Platform.ExtendClientAreaChromeHints.OSXThickTitleBar; }
public AvaloniaNativeMenuExporter(IAvaloniaNativeFactory factory) { _factory = factory; _menu = NativeMenu.GetMenu(Application.Current); DoLayoutReset(); }
private void SetMenu(NativeMenu menu) { var appMenu = _factory.ObtainAppMenu(); if (appMenu is null) { appMenu = _factory.CreateMenu(); } var menuItem = menu.Parent; if (menu.Parent is null) { menuItem = new NativeMenuItem(); } menuItem.Menu = menu; appMenu.Clear(); AddItemsToMenu(appMenu, new List <NativeMenuItemBase> { menuItem }); _factory.SetAppMenu(appMenu); }
void DoLayoutReset() { _resetQueued = false; foreach (var i in _menuItems) { i.PropertyChanged -= OnItemPropertyChanged; if (i.Menu != null) { ((INotifyCollectionChanged)i.Menu.Items).CollectionChanged -= OnMenuItemsChanged; } } _menuItems.Clear(); if (_nativeWindow is null) { _menu = NativeMenu.GetMenu(Application.Current); if (_menu != null) { SetMenu(_menu); } } else { SetMenu(_nativeWindow, _menu?.Items); } _exported = true; }
private void DoLayoutReset(bool forceUpdate = false) { if (_resetQueued || forceUpdate) { _resetQueued = false; if (_nativeWindow is null) { var appMenu = NativeMenu.GetMenu(Application.Current); if (appMenu == null) { appMenu = CreateDefaultAppMenu(); NativeMenu.SetMenu(Application.Current, appMenu); } SetMenu(appMenu); } else { if (_menu != null) { SetMenu(_nativeWindow, _menu); } } _exported = true; } }
private void EnsureSubscribed(NativeMenu menu) { if (menu != null && _menus.Add(menu)) { ((INotifyCollectionChanged)menu.Items).CollectionChanged += OnMenuItemsChanged; } }
private IEnumerable <MenuItem> Populate(NativeMenu nativeMenu) { foreach (var menuItem in nativeMenu.Items) { if (menuItem is NativeMenuItemSeparator) { yield return(new MenuItem { Header = "-" }); } else if (menuItem is NativeMenuItem item) { var newItem = new MenuItem { Header = item.Header, Icon = item.Icon, Command = item.Command, CommandParameter = item.CommandParameter }; if (item.Menu != null) { newItem.Items = Populate(item.Menu); } else if (item.HasClickHandlers && item is INativeMenuItemExporterEventsImplBridge bridge) { newItem.Click += (_, __) => bridge.RaiseClicked(); } yield return(newItem); } } }
public override void AddToMenu(NativeMenu mainMenu, NativeMenuManager menuManager) { MainMenu = menuManager.AddSubMenu(mainMenu.Title, "LEVEL EDITOR", "Level Editor", "Create/Edit space levels.", mainMenu); MainMenu.Init(); OpenFileMenu = new OpenFileMenu(MenuManager); OpenFileMenu.AddToMenu(MainMenu, menuManager); }
public override void Initialize() { AvaloniaXamlLoader.Load(this); Name = "Avalonia"; _recentMenu = (NativeMenu.GetMenu(this).Items[1] as NativeMenuItem).Menu; }
private IList <NativeMenuItemBase> GetNativeItems(IEnumerable <MenuItemModel> items, NativeMenu menu = null) { var result = new List <NativeMenuItemBase>(); foreach (var item in items) { if (item is MenuItemSeparatorModel) { if (menu != null) { menu.Add(new NativeMenuItemSeperator()); } else { result.Add(new NativeMenuItemSeperator()); } } else { var gesture = item.Gesture; var nativeItem = new NativeMenuItem { Header = item.Label, Command = item.Command, }; if (gesture != null) { nativeItem.Gesture = KeyGesture.Parse(gesture); } if (nativeItem.Header == null) { nativeItem.Header = ""; } if (item.Children != null && item.Children.Any()) { var nativeMenu = new NativeMenu(); GetNativeItems(item.Children, nativeMenu); nativeItem.Menu = nativeMenu; } if (menu != null) { menu.Add(nativeItem); } else { result.Add(nativeItem); } } } return(result); }
private void AddEditMenuBinding(Entity entity, NativeMenu menu) { if (entityEditMenus.ContainsKey(entity)) { return; } entityEditMenus.Add(entity, menu); }
private void Init() { NativeMenuManager = new NativeMenuManager(); MainMenu = new NativeMenu("Grand Theft Space", $"VERSION {CoreScript.VersionNum}", MenuBannerType.SmuglersHangar); MainMenu.Init(); NativeMenuManager.AddMenu(MainMenu); LevelSelectionMenu = new LevelSelectionMenu(this); LevelSelectionMenu.AddToMenu(MainMenu, NativeMenuManager); }
internal void Initialize(AvaloniaNativeMenuExporter exporter, NativeMenu managedMenu, string title) { _exporter = exporter; ManagedMenu = managedMenu; ((INotifyCollectionChanged)ManagedMenu.Items).CollectionChanged += OnMenuItemsChanged; if (!string.IsNullOrWhiteSpace(title)) SetTitle(title); }
static IDisposable?InitMenuItems(NativeMenu menu) { #if !TRAY_INDEPENDENT_PROGRAM if (IViewModelManager.Instance.MainWindow is not MainWindowViewModel main) { return(null); } #else MainWindowViewModel main = new(); #endif var query = from x in main.AllTabItems let tabItem = x is TabItemViewModel item ? item : null where tabItem != null select tabItem; tabItems = new(); foreach (var item in query) { var menuItem = new NativeMenuItem { Header = item.Name, Command = ReactiveCommand.Create(() => { OnMenuClick(item.Id); }), }; tabItems.Add(item, menuItem); menu.Add(menuItem); } exitMenuItem = new NativeMenuItem { Header = Exit, Command = ReactiveCommand.Create(() => { OnMenuClick(TaskBarWindowViewModel.CommandExit); }), }; menu.Add(exitMenuItem); #if !TRAY_INDEPENDENT_PROGRAM return(R.Subscribe(() => { if (exitMenuItem != null) { exitMenuItem.Header = Exit; } foreach (var item in tabItems) { item.Value.Header = item.Key.Name; } })); #else return(null); #endif }
/// <summary> /// Adds a new <see cref="NativeSubmenuItem"/> using text localization system. /// </summary> /// <param name="menu">Instance of a<see cref="NativeMenu"/>.</param> /// <param name="menuName">Entry name.</param> /// <returns>Instance of the new <see cref="NativeSubmenuItem"/>.</returns> public NativeSubmenuItem NewSubmenu(NativeMenu menu, string menuName) { NativeSubmenuItem item = AddSubMenu(menu); //item.Title = GetItemTitle(menuName); //item.Description = GetItemDescription(menuName); item.Tag = menuName; return(item); }
public static void CreateMenus() { _menuPool = new ObjectPool(); ManagementMenu = new NativeMenu("ArrestManager+", "Scene Manager"); CreatePedManagementMenu(); CreateVehicleManagementMenu(); Game.FrameRender += Process; _menuPool.Add(ManagementMenu); MainLogic(); }
protected override void InitControls() { this.Text = "Little Editor"; this.Name = "MainWindow"; this.StatusBar = true; this._TextBox = new NativeRichTextBox { Left = 0, Top = 0, Width = 480, Height = 380 }; this.Width = 500; this.Height = 400; this.StartUpPosition = WindowsStartupPosition.CenterScreen; //Creating the File Menu NativeMenu menuFile = new NativeMenu("mnuFile", "&File"); //Create Sub-Items for File-Menu NativeMenuItem menuFileOpen = new NativeMenuItem("mnuOpen", "&Open"); NativeMenuItem menuFileClose = new NativeMenuItem("mnuSave", "&Save"); NativeMenuItem menuFileSep = new NativeMenuItem("mnuFileSep") { IsSeparator = true }; NativeMenuItem menFileExit = new NativeMenuItem("mnuExit", "E&xit"); //Add Menu Event Handlers menuFileClose.Click += FileSave_Click; menuFileOpen.Click += FileOpen_Click; menFileExit.Click += Menu_Exit; //Add The Sub-Items to File-Menu menuFile.Items.Add(menuFileOpen); menuFile.Items.Add(menuFileClose); menuFile.Items.Add(menuFileSep); menuFile.Items.Add(menFileExit); //Create Help-Menu NativeMenu menuHelp = new NativeMenu("&Help"); //Add Sub-Item to Help-Menu NativeMenuItem menuInfo = new NativeMenuItem("&Info"); //Add Event-Handler menuInfo.Click += MenuInfo_Click; //Add the Sub-Item to the Help-Menu menuHelp.Items.Add(menuInfo); //Add the Help-Menu to the File-Menu menuFile.Items.Add(menuHelp); //Add the first Element of the Menu to the Form this.Menu = menuFile; this.Controls.Add(this._TextBox); }
public void Run() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); NotificationCenter.Instance.AddObserver(TaskCompleted, "vagrant-manager.task-completed"); NotificationCenter.Instance.AddObserver(ThemeChanged, "vagrant-manager.theme-changed"); NotificationCenter.Instance.AddObserver(ShowRunningVmCountPreferenceChanged, "vagrant-manager.show-running-vm-count-preference-changed"); NotificationCenter.Instance.AddObserver(UsePathAsInstanceDisplayNamePreferenceChanged, "vagrant-manager.use-path-as-instance-display-name-preference-changed"); NotificationCenter.Instance.AddObserver(IncludeMachineNamesInMenuPreferenceChanged, "vagrant-manager.include-machine-names-in-menu-preference-changed"); NotificationCenter.Instance.AddObserver(ShowUpdateNotificationPreferenceChanged, "vagrant-manager.show-update-notification-preference-changed"); NotificationCenter.Instance.AddObserver(BookmarksUpdated, "vagrant-manager.bookmarks-updated"); _TaskOutputWindows = new List <TaskOutputWindow>(); _NativeMenu = new NativeMenu(); _NativeMenu.Delegate = this; VagrantManager.Instance.Delegate = this; VagrantManager.Instance.RegisterServiceProvider(new VirtualBoxServiceProvider()); BookmarkManager.Instance.LoadBookmarks(); if (Properties.Settings.Default.Guid.Length == 0) { Properties.Settings.Default.Guid = System.Guid.NewGuid().ToString(); Properties.Settings.Default.Save(); } Uri appcastUrl = Util.AddQuery(new Uri(Properties.Settings.Default.AppcastUrl), "machineid", Properties.Settings.Default.Guid); appcastUrl = Util.AddQuery(appcastUrl, "appversion", Application.ProductVersion); SharpSparkle.SharpSparkle.SetAppcastUrl(appcastUrl.AbsoluteUri); SharpSparkle.SharpSparkle.SetAppDetails(Application.CompanyName, Application.ProductName, Application.ProductVersion); SharpSparkle.SharpSparkle.Init(); Application.ApplicationExit += Application_ApplicationExit; var dummy = _NativeMenu.Menu.Handle; // forces handle creation so _NativeMenu.Menu.BeginInvoke can work before the menu was ever clicked this.VerifyVBoxManagePath(); this.RefreshVagrantMachines(); this.RefreshTimerState(); using (new SingleGlobalInstance(1000)) { Application.Run(); } }
internal void Initialise(AvaloniaNativeMenuExporter exporter, NativeMenu managedMenu, string title) { _exporter = exporter; ManagedMenu = managedMenu; ((INotifyCollectionChanged)ManagedMenu.Items).CollectionChanged += OnMenuItemsChanged; if (!string.IsNullOrWhiteSpace(title)) { using (var buffer = new Utf8Buffer(title)) { Title = buffer.DangerousGetHandle(); } } }
internal static void Loop() { LoadShopManager(); LoadShops(); shopMenu = new NativeMenu("Food Store", "FOOD STORES"); MenuManager.Pool.Add(shopMenu); while (Common.InstanceRunning) { GameFiber.Yield(); foreach (var shop in shops) { if (Game.LocalPlayer.Character.DistanceTo(shop.Position.GeneratedVector3) < 3.5f) { if (!alreadySetCurrentItems) { currentItems = shop.Items; shopMenu.Clear(); foreach (var item in currentItems) { var shopItem = new NativeItem(item.Name, "Buys the food."); shopItem.Activated += (sender, selectedItem) => { if (Functions.CostMoney(item.Price)) { Functions.IncreaseHungry(item.Amount); } }; shopMenu.Add(shopItem); } alreadySetCurrentItems = true; } Game.DisplayHelp("Press ~INPUT_CONTEXT~ to open the shop menu."); if (Game.IsControlPressed(0, GameControl.Context)) { shopMenu.Visible = !shopMenu.Visible; } break; } else { alreadySetCurrentItems = false; } } } }
public void SetNativeMenu(NativeMenu menu) { if (menu == null) { menu = new NativeMenu(); } if (_menu != null) { ((INotifyCollectionChanged)_menu.Items).CollectionChanged -= OnMenuItemsChanged; } _menu = menu; ((INotifyCollectionChanged)_menu.Items).CollectionChanged += OnMenuItemsChanged; DoLayoutReset(); }
public MainWindow() { this.InitializeComponent(); //Renderer.DrawFps = true; //Renderer.DrawDirtyRects = Renderer.DrawFps = true; _notificationArea = new WindowNotificationManager(this) { Position = NotificationPosition.TopRight, MaxItems = 3 }; DataContext = new MainWindowViewModel(_notificationArea); _recentMenu = ((NativeMenu.GetMenu(this)?.Items[0] as NativeMenuItem)?.Menu?.Items[2] as NativeMenuItem)?.Menu; }
public void Run() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _NativeMenu = new NativeMenu(); _NativeMenu.Delegate = this; Application.ApplicationExit += Application_ApplicationExit; var dummy = _NativeMenu.Menu.Handle; // forces handle creation so _NativeMenu.Menu.BeginInvoke can work before the menu was ever clicked Application.Run(); }
private AvaloniaList <MenuItem> Populate(NativeMenu nativeMenu) { var result = new AvaloniaList <MenuItem>(); foreach (var menuItem in nativeMenu.Items) { if (menuItem is NativeMenuItemSeparator) { result.Add(new MenuItem { Header = "-" }); } else if (menuItem is NativeMenuItem item) { var newItem = new MenuItem {
protected override void OnAttached() { base.OnAttached(); Observable.FromEventPattern(AssociatedObject, nameof(AssociatedObject.AttachedToVisualTree)) .Take(1) .Subscribe(x => { if (Menu != null) { if (AssociatedObject.GetVisualRoot() is TopLevel tl) { NativeMenu.SetMenu(tl, Menu); } } }); }
protected override void OnAttached() { base.OnAttached(); Observable.FromEventPattern(AssociatedObject, nameof(AssociatedObject.AttachedToVisualTree)) .Take(1) .Subscribe(x => { if (AssociatedObject.GetVisualRoot() is TopLevel tl) { if (NativeMenu.GetIsNativeMenuExported(tl)) { AssociatedObject.IsVisible = false; } } }); }
private Dictionary <Entity, NativeMenu> entityEditMenus; // The menus that are bound to entities. public SpaceLevelEditor(MenuManager menuManager) { entityEditMenus = new Dictionary <Entity, NativeMenu>(); MainMenu = new NativeMenu("Level Editor", "MAIN MENU", menuManager.MainMenu.BannerType) { AcceleratedScrolling = true, MaxDrawableItems = 10, }; MainMenu.Init(); menuManager.NativeMenuManager.AddMenu(MainMenu); MenuManager = menuManager; CameraManager = new SpaceLevelEditorCameraManager(); }
private NativeMenu CreateDefaultAppMenu() { var result = new NativeMenu(); var aboutItem = new NativeMenuItem("About Avalonia"); aboutItem.Click += async(_, _) => { var dialog = new AboutAvaloniaDialog(); if (Application.Current is { ApplicationLifetime : IClassicDesktopStyleApplicationLifetime { MainWindow : { } mainWindow } }) { await dialog.ShowDialog(mainWindow); } };