<commit_before>/*
 * CPMenuItem.j
 * AppKit
 *
 * Created by <NAME>.
 * Copyright 2008, 280 North, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

@import <Foundation/CPCoder.j>
@import <Foundation/CPObject.j>
@import <Foundation/CPString.j>

@import <AppKit/CPImage.j>
@import <AppKit/CPMenu.j>
@import <AppKit/CPView.j>

/*! @class CPMenuItem

    A <objj>CPMenuItem</objj> is added to a <objj>CPMenu</objj>.
    It has an action and a target for that action to be sent to
    whenever the item is 'activated'.
*/
@implementation CPMenuItem : CPObject
{
    CPString        _title;
    //CPAttributedString  _attributedTitle;
    
    CPFont          _font;
                  
    id              _target;
    SEL             _action;
                    
    BOOL            _isEnabled;
    BOOL            _isHidden;
                    
    int             _tag;
    int             _state;
                    
    CPImage         _image;
    CPImage         _alternateImage;
    CPImage         _onStateImage;
    CPImage         _offStateImage;
    CPImage         _mixedStateImage;
                    
    CPMenu          _submenu;
    CPMenu          _menu;
                    
    CPString        _keyEquivalent;
    unsigned        _keyEquivalentModifierMask;
                    
    int             _mnemonicLocation;
                    
    BOOL            _isAlternate;
    int             _indentationLevel;
                    
    CPString        _toolTip;
    id              _representedObject;
    CPView          _view;
    
    _CPMenuItemView _menuItemView;
}

/*!
    Initializes the menu item with a title, action, and keyboard equivalent.
    @param aTitle the menu item's title
    @param anAction the action that gets triggered when the item is selected
    @param aKeyEquivalent the keyboard shortcut for the item
    @return the initialized menu item
*/
- (id)initWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent
{
    self = [super init];
    
    if (self)
    {
        _title = aTitle;
        _action = anAction;
        
        _isEnabled = YES;
        
        _state = CPOffState;
        
        _keyEquivalent = aKeyEquivalent;
        _keyEquivalentModifierMask = CPPlatformActionKeyMask;
        
        _mnemonicLocation = CPNotFound;
    }
    
    return self;
}

// Enabling a Menu Item
/*!
    Sets whether the menu item is enabled or not
    @param isEnabled <code>YES</code> enables the item. <code>NO</code> disables it.
*/
- (void)setEnabled:(BOOL)isEnabled
{
    if ([_menu autoenablesItems])
        return;
        
    _isEnabled = isEnabled;
    
    [_menuItemView setDirty];
    
    [_menu itemChanged:self];
}

/*!
    Returns <code>YES</code> if the item is enabled.
*/
- (BOOL)isEnabled
{
    return _isEnabled;
}

// Managing Hidden Status
/*!
    Sets whether the item should be hidden. A hidden item can not be triggered by keyboard shortcuts.
    @param isHidden <code>YES</code> hides the item. <code>NO</code> reveals it.
*/
- (void)setHidden:(BOOL)isHidden
{
    _isHidden = isHidden;
}

/*!
    Returns <code>YES</code> if the item is hidden.
*/
- (BOOL)isHidden
{
    return _isHidden;
}

/*!
    Returns <code>YES</code> if the item is hidden or if one of it's supermenus is hidden.
*/
- (BOOL)isHiddenOrHasHiddenAncestor
{
    if (_isHidden)
        return YES;
    
    if ([[[_menu supermenu] indexOfItemWithSubmenu:_menu] isHiddenOrHasHiddenAncestor])
        return YES;

    return NO;
}

// Managing Target and Action
/*!
    Sets the menu item's action target.
    @param aTarget the target for the action
*/
- (void)setTarget:(id)aTarget
{
    _target = aTarget;
}

/*!
    Returns the item's action target
*/
- (id)target
{
    return _target;<commit_msg>Fix for setHidden: not working in main menu bar.<commit_after>/*
 * CPMenuItem.j
 * AppKit
 *
 * Created by <NAME>.
 * Copyright 2008, 280 North, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

@import <Foundation/CPCoder.j>
@import <Foundation/CPObject.j>
@import <Foundation/CPString.j>

@import <AppKit/CPImage.j>
@import <AppKit/CPMenu.j>
@import <AppKit/CPView.j>

/*! @class CPMenuItem

    A <objj>CPMenuItem</objj> is added to a <objj>CPMenu</objj>.
    It has an action and a target for that action to be sent to
    whenever the item is 'activated'.
*/
@implementation CPMenuItem : CPObject
{
    CPString        _title;
    //CPAttributedString  _attributedTitle;
    
    CPFont          _font;
                  
    id              _target;
    SEL             _action;
                    
    BOOL            _isEnabled;
    BOOL            _isHidden;
                    
    int             _tag;
    int             _state;
                    
    CPImage         _image;
    CPImage         _alternateImage;
    CPImage         _onStateImage;
    CPImage         _offStateImage;
    CPImage         _mixedStateImage;
                    
    CPMenu          _submenu;
    CPMenu          _menu;
                    
    CPString        _keyEquivalent;
    unsigned        _keyEquivalentModifierMask;
                    
    int             _mnemonicLocation;
                    
    BOOL            _isAlternate;
    int             _indentationLevel;
                    
    CPString        _toolTip;
    id              _representedObject;
    CPView          _view;
    
    _CPMenuItemView _menuItemView;
}

/*!
    Initializes the menu item with a title, action, and keyboard equivalent.
    @param aTitle the menu item's title
    @param anAction the action that gets triggered when the item is selected
    @param aKeyEquivalent the keyboard shortcut for the item
    @return the initialized menu item
*/
- (id)initWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent
{
    self = [super init];
    
    if (self)
    {
        _title = aTitle;
        _action = anAction;
        
        _isEnabled = YES;
        
        _state = CPOffState;
        
        _keyEquivalent = aKeyEquivalent;
        _keyEquivalentModifierMask = CPPlatformActionKeyMask;
        
        _mnemonicLocation = CPNotFound;
    }
    
    return self;
}

// Enabling a Menu Item
/*!
    Sets whether the menu item is enabled or not
    @param isEnabled <code>YES</code> enables the item. <code>NO</code> disables it.
*/
- (void)setEnabled:(BOOL)isEnabled
{
    if ([_menu autoenablesItems])
        return;
        
    _isEnabled = isEnabled;
    
    [_menuItemView setDirty];
    
    [_menu itemChanged:self];
}

/*!
    Returns <code>YES</code> if the item is enabled.
*/
- (BOOL)isEnabled
{
    return _isEnabled;
}

// Managing Hidden Status
/*!
    Sets whether the item should be hidden. A hidden item can not be triggered by keyboard shortcuts.
    @param isHidden <code>YES</code> hides the item. <code>NO</code> reveals it.
*/
- (void)setHidden:(BOOL)isHidden
{
    if (_isHidden == isHidden)
        return;
    
    _isHidden = isHidden;

    [_menu itemChanged:self];
}

/*!
    Returns <code>YES</code> if the item is hidden.
*/
- (BOOL)isHidden
{
    return _isHidden;
}

/*!
    Returns <code>YES</code> if the item is hidden or if one of it's supermenus is hidden.
*/
- (BOOL)isHiddenOrHasHiddenAncestor
{
    if (_isHidden)
        return YES;
    
    var supermenu = [_menu supermenu];
    
    if ([[supermenu itemAtIndex:[supermenu indexOfItemWithSubmenu:_menu]] isHiddenOrHasHiddenAncestor])
        return YES;

    return NO;
}

// Managing Target and Action
/*!
    Sets the menu item's action target.
    @param aTarget the target for the action
*/
- (void)setTarget:(id)aTarget
{
    _target = aTarget;
}

/*!
    Returns the item's action target
*/
- (id)target
{
    return _target;
{'fraction_non_alphanumeric': 0.07932692307692307, 'fraction_numerical': 0.004370629370629371, 'mean_word_length': 2.139965694682676, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6771098', 'n_tokens_mistral': 2742, 'n_tokens_neox': 2623, 'n_words': 873}