
    Je                     V    d Z ddlZddlmZ  ej                  e      Z G d de      Zy)a  
This module contains the editor extensions controller.

Adapted from pyqode/core/managers/modes.py of the
`PyQode project <https://github.com/pyQode/pyQode>`_.
Original file:
<https://github.com/pyQode/pyqode.core/raw/master/pyqode/core/managers/modes.py>
    N)Managerc                   R     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Z xZS )EditorExtensionsManagerz=Manages the list of editor extensions of the CodeEdit widget.c                 :    t         t        |   |       i | _        y)z-Initialize and add a reference to the editor.N)superr   __init___extensions)selfeditor	__class__s     J/usr/lib/python3/dist-packages/spyder/plugins/editor/extensions/manager.pyr   z EditorExtensionsManager.__init__    s    %t5f=    c                     t         j                  dj                  |j                               || j                  |j                  <   |j                  | j                         |S )zk
        Add a extension to the editor.

        :param extension: The extension instance to add.

        zadding extension {})loggerdebugformatnamer	   
on_installr   )r
   	extensions     r   addzEditorExtensionsManager.add%   sL     	*11)..AB+4(T[[)r   c                     t         j                  dj                  |             | j                  |      }|j	                          | j
                  j                  |j                         |S )z
        Remove a extension from the editor.

        :param name_or_klass: The name (or class) of the extension to remove.
        :returns: The removed extension.
        zremoving extension {})r   r   r   geton_uninstallr	   popr   )r
   name_or_klassr   s      r   removezEditorExtensionsManager.remove1   sT     	,33MBCHH]+	 Y^^,r   c                     t        | j                        rWt        t        | j                  j	                                     d   }| j                  |       t        | j                        rVyy)zr
        Remove all extensions from the editor.

        All extensions are removed fromlist and deleted.
        r   N)lenr	   sortedlistkeysr   )r
   keys     r   clearzEditorExtensionsManager.clear>   sQ     $""#d..33567:CKK $""#r   c                 X    t        |t              s|j                  }| j                  |   S )z
        Get a extension by name (or class).

        :param name_or_klass: The name or the class of the extension to get
        :type name_or_klass: str or type
        :rtype: spyder.api.mode.EditorExtension
        )
isinstancestr__name__r	   )r
   r   s     r   r   zEditorExtensionsManager.getH   s*     --)22M..r   c                 6    | j                   j                         S )zK
        Return the list of the names of the installed extensions.
        )r	   r!   r
   s    r   r!   zEditorExtensionsManager.keysT   s     $$&&r   c                 6    | j                   j                         S )z:
        Return the list of installed extensions.
        )r	   valuesr)   s    r   r+   zEditorExtensionsManager.valuesZ   s     &&((r   c                 Z    t        t        | j                  j                                     S )z*Return the amount of installed extensions.)r   r    r	   r+   r)   s    r   __len__zEditorExtensionsManager.__len__`   s!    4((//1233r   c                     t        t        | j                  j                               D cg c]  \  }}|	 c}}      S c c}}w )zB
        Return the list of extensions.

        :return:
        )iterr   r	   items)r
   kvs      r   __iter__z EditorExtensionsManager.__iter__d   s5     6$*:*:*@*@*B#CD41aQDEEDs   A 
)r'   
__module____qualname____doc__r   r   r   r#   r   r!   r+   r-   r3   __classcell__)r   s   @r   r   r      s4    G


/')4Fr   r   )r6   loggingspyder.api.managerr   	getLoggerr'   r   r    r   r   <module>r<      s8     ' 
		8	$MFg MFr   