コード例 #1
0
        public bool validateUserInterfaceItem(NSObject sender)
        {
            bool enabled = false;

            Selector sel = (Selector) sender.Call("action");
            if (sel.Name == "sortByName:")
            {
                enabled = true;
                if (sender.respondsToSelector("setState:"))
                    sender.Call("setState:", m_sortByDate ? 0 : 1);
            }
            else if (sel.Name == "sortByDate:")
            {
                enabled = true;
                if (sender.respondsToSelector("setState:"))
                    sender.Call("setState:", m_sortByDate ? 1 : 0);
            }
            else if (sel.Name == "openWithFinder:" || sel.Name == "showInFinder:")
            {
                enabled = m_table.numberOfSelectedRows() > 0;
            }
            else if (respondsToSelector(sel))
            {
                enabled = true;
            }
            else if (SuperCall(NSWindowController.Class, "respondsToSelector:", new Selector("validateUserInterfaceItem:")).To<bool>())
            {
                enabled = SuperCall(NSWindowController.Class, "validateUserInterfaceItem:", sender).To<bool>();
            }

            return enabled;
        }
コード例 #2
0
        public bool validateUserInterfaceItem(NSObject sender)
        {
            bool enabled = false;

            Selector sel = (Selector) sender.Call("action");

            if (sel.Name == "dirHandler:")
            {
                int tag = (int) sender.Call("tag");

                var handler = m_boss.Get<IMenuHandler>();
                MenuState state = handler.GetState(tag);
                enabled = (state & MenuState.Enabled) == MenuState.Enabled;
                if (sender.respondsToSelector("setState:"))
                    sender.Call("setState:", (state & MenuState.Checked) == MenuState.Checked ? 1 : 0);

                if (enabled && tag == 50 && sender.isMemberOfClass(NSMenuItem.Class))
                {
                    Unused.Value = sender.Call("setTitle:", NSString.Create("Build " + m_name));
                }
                else if (enabled && tag == 1000 && sender.isMemberOfClass(NSMenuItem.Class))
                {
                    Unused.Value = sender.Call("setTitle:", NSString.Create(m_name + " Preferences"));
                }
            }
            else if (sel.Name == "targetChanged:")
            {
                enabled = m_builder != null && m_builder.CanBuild;
            }
            else if (sel.Name == "renameItem:")
            {
                NSIndexSet selections = m_table.selectedRowIndexes();
                enabled = selections.count() == 1;
            }
            else if (sel.Name == "duplicate:")
            {
                NSIndexSet selections = m_table.selectedRowIndexes();
                enabled = selections.count() > 0 && m_table.editedRow() < 0;	// cocoa crashes if we do a duplicate while editing...
            }
            else if (respondsToSelector(sel))
            {
                enabled = true;
            }
            else if (SuperCall(NSWindowController.Class, "respondsToSelector:", new Selector("validateUserInterfaceItem:")).To<bool>())
            {
                enabled = SuperCall(NSWindowController.Class, "validateUserInterfaceItem:", sender).To<bool>();
            }

            return enabled;
        }