<commit_before>""" An action that toggles a view's visibility (ie. hides/shows it). """


# Enthought library imports.
from enthought.pyface.workbench.api import IView
from enthought.traits.api import Delegate, Instance, on_trait_change

# Local imports.
from workbench_action import WorkbenchAction


class ToggleViewVisibilityAction(WorkbenchAction):
    """ An action that toggles a view's visibility (ie. hides/shows it). """

    #### 'Action' interface ###################################################

    # The action's unique identifier (may be None).
    id = Delegate('view')

    # The action's name (displayed on menus/tool bar tools etc).
    name = Delegate('view')
    
    # The action's style.
    style = 'toggle'

    #### 'ViewAction' interface ###############################################

    # The view that we toggle the visibility for.
    view = Instance(IView)

    ###########################################################################
    # 'Action' interface.
    ###########################################################################

    def perform(self, event):
        """ Perform the action. """

        # fixme: In a world of commands this could be:-
        #
        # command = ToggleViewVisibilityCommand(window=window, view=view)
        # command.execute()
        self._toggle_view_visibility(self.window, self.view)

        return
    
    ###########################################################################
    # Private interface.
    ###########################################################################

    def _toggle_view_visibility(self, window, view):
        """ Toggle the visibility of a view. """
        
        if view.visible:
            window.hide_view(view)

        else:
            window.show_view(view)

        return

    #### Trait change handlers ################################################

    @on_trait_change('view.visible')
    def _when_visible_changed_for_view(self, new):
        """ Dynamic trait change handler. """

        self.checked = new

        return
    
#### EOF ######################################################################<commit_msg>- made sure the view visibility toggle action has its checked state set when it is instantiated<commit_after>""" An action that toggles a view's visibility (ie. hides/shows it). """


# Enthought library imports.
from enthought.pyface.workbench.api import IView
from enthought.traits.api import Delegate, Instance, on_trait_change

# Local imports.
from workbench_action import WorkbenchAction


class ToggleViewVisibilityAction(WorkbenchAction):
    """ An action that toggles a view's visibility (ie. hides/shows it). """

    #### 'Action' interface ###################################################

    # The action's unique identifier (may be None).
    id = Delegate('view')

    # The action's name (displayed on menus/tool bar tools etc).
    name = Delegate('view')
    
    # The action's style.
    style = 'toggle'

    #### 'ViewAction' interface ###############################################

    # The view that we toggle the visibility for.
    view = Instance(IView)

    ###########################################################################
    # 'object' interface.
    ###########################################################################

    def __init__(self, **traits):
        """ Constructor. """

        super(ToggleViewVisibilityAction, self).__init__(**traits)

        # Make sure that the action is checked if its view is already visible.
        self._refresh_checked()

        return

    ###########################################################################
    # 'Action' interface.
    ###########################################################################

    def perform(self, event):
        """ Perform the action. """

        # fixme: In a world of commands this could be:-
        #
        # command = ToggleViewVisibilityCommand(window=window, view=view)
        # command.execute()
        self._toggle_view_visibility(self.window, self.view)

        return
    
    ###########################################################################
    # Private interface.
    ###########################################################################

    def _toggle_view_visibility(self, window, view):
        """ Toggle the visibility of a view. """
        
        if view.visible:
            window.hide_view(view)

        else:
            window.show_view(view)

        return

    ###########################################################################
    # Private interface.
    ###########################################################################

    @on_trait_change('view.visible')
    def _refresh_checked(self):
        """ Refresh the checked state of the action. """

        self.checked = self.view.visible

        return
    
#### EOF ######################################################################
{'fraction_non_alphanumeric': 0.3317326930772309, 'fraction_numerical': 0.0, 'mean_word_length': 3.620147874306839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1565000', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1101, 'n_words': 316}