Beispiel #1
0
        public DataBoundNSMenuItem(IScheduler dispatcher, MenuItem item, IReport log)
        {
            item.Menu.Do(submenu =>
                         MenuBuilder.CreateMenu(submenu, log, item.Name)
                         .ToObservable().Subscribe(t =>
                                                   Fusion.Application.MainThread.InvokeAsync(() => Submenu = t)));

            Action click = () => { };

            _subscription = Disposable.Combine
                            (
                item.Command.Action.CombineLatest(item.Name).Subscribe(cmdName =>
                                                                       dispatcher.Schedule(() =>
            {
                var cmd  = cmdName.Item1;
                var name = cmdName.Item2;
                Title    = name;
                Enabled  = cmd.HasValue;
                click    = () => log.TrySomethingBlocking(() => cmd.Do(x => x()));
                if (item.Hotkey != HotKey.None)
                {
                    KeyEquivalentModifierMask = item.Hotkey.Modifier.ToNSEventModifierMask();
                    KeyEquivalent             = item.Hotkey.Key.ToKeyEquivalent();
                }
            })),

                item.IsToggled.Subscribe(isToggled =>
                                         dispatcher.Schedule(() =>
                                                             State = isToggled ? NSCellStateValue.On : NSCellStateValue.Off)),

                Disposable.Create(() => item.Menu.Do(_ => Submenu.Dispose()))
                            );

            Activated += (s, a) => click();
        }
Beispiel #2
0
 protected override void DisposeManagedResources()
 {
     base.DisposeManagedResources();
     Command          = null;
     CommandParameter = null;
     Submenu?.Dispose();
     Submenu = null;
 }
        public new void Dispose()
        {
            base.Dispose();

            _refreshMenuItem.Activated    -= OnRefreshClickedInternal;
            _refreshAllMenuItem.Activated -= OnRefreshAllClickedInternal;
            _settingsMenuItem.Activated   -= OnPreferencesClickedInternal;
            _quitMenuItem.Activated       -= OnQuitClickedInternal;

            Submenu.Dispose();

            _refreshMenuItem.Dispose();
            _refreshAllMenuItem.Dispose();
            _settingsMenuItem.Dispose();
            _quitMenuItem.Dispose();
        }