Ejemplo n.º 1
0
        // Chapter 14 challenge
//		public override void DidResignActive(NSNotification notification)
//		{
//			AppKitFramework.NSBeep();
//		}
        #endregion

        #region - Helpers
        public void ChangeMenuItemTitle(string topMenuName, string itemName, string localizationKey)
        {
            NSMenu     menu     = NSApplication.SharedApplication.MainMenu;
            NSMenuItem fileMenu = menu.ItemWithTitle(topMenuName).Submenu.ItemWithTitle(itemName);

            fileMenu.Title = NSBundle.MainBundle.LocalizedString(localizationKey, null);
        }
        /// <summary>
        /// Populates the film menu items with all screenings of the current film.
        /// </summary>
        /// <param name="menu">Menu.</param>
        ///
        private void PopulateFilmScreeningsMenuItems(NSMenu menu)
        {
            // Remove the existing screening items from the menu.
            foreach (string title in _filmScreeningByMenuItemTitle.Keys)
            {
                menu.RemoveItem(menu.ItemWithTitle(title));
            }

            // Add the screenings with same film to the Screening menu.
            int screeningNumber = 0;
            var mask            = NSEventModifierMask.AlternateKeyMask | NSEventModifierMask.CommandKeyMask;

            _filmScreeningByMenuItemTitle = new Dictionary <string, Screening> {
            };
            _FilmScreeningEnabledByTag    = new Dictionary <nint, bool> {
            };
            var screenings = _screeningProvider.Screenings;

            foreach (var screening in screenings)
            {
                screeningNumber += 1;
                string     itemTitle = screening.ToMenuItemString();
                NSMenuItem item      = new NSMenuItem(itemTitle)
                {
                    Action = new Selector("NavigateFilmScreening:"),
                    Tag    = _filmMenuHeaderItemTag + screeningNumber,
                    State  = NSCellStateValue.Off
                };
                if (screeningNumber <= 9)
                {
                    item.KeyEquivalent             = screeningNumber.ToString();
                    item.KeyEquivalentModifierMask = mask;
                }
                menu.AddItem(item);
                bool enabled = AnalyserViewRunning() || screening != Screening;
                _FilmScreeningEnabledByTag.Add(item.Tag, enabled);
                _filmScreeningByMenuItemTitle.Add(itemTitle, screening);
            }
        }