ó
†Å•Zc           @   sL   d  d l  m Z m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t
   exceptionst   changet
   taskhandlet   Historyc           B   s7  e  Z d  Z d d „ Z d „  Z e j ƒ  d „ Z d „  Z	 d „  Z
 d e e j ƒ  d „ Z d e j ƒ  d „ Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z RS(   s"   A class that holds project historyc         C   sQ   | |  _  g  |  _ g  |  _ | |  _ |  j ƒ  |  j  j j |  j ƒ d  |  _	 d  S(   N(
   t   projectt
   _undo_listt
   _redo_listt	   _maxundost   _load_historyt
   data_filest   add_write_hookt   writet   Nonet   current_change(   t   selfR   t   maxundos(    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   __init__   s    				
c         C   s«   |  j  r§ |  j j j d d |  j d t ƒ} | d  k	 r§ t j |  j ƒ } x( | d D] } |  j	 j
 | | ƒ ƒ qV Wx+ | d D] } |  j j
 | | ƒ ƒ q Wq§ n  d  S(   Nt   historyt   compresst   import_i    i   (   t   saveR   R	   t	   read_dataR   t   TrueR   R   t   DataToChangeR   t   appendR   (   R   t   resultt	   to_changet   data(    (    s0   lib/python2.7/site-packages/rope/base/history.pyR      s    	c         C   sj   z& | |  _  | j t j | | ƒ ƒ Wd d |  _  X|  j | ƒ r_ |  j j | ƒ |  j ƒ  n  |  j	 2d S(   sµ   Perform the change and add it to the `self.undo_list`

        Note that uninteresting changes (changes to ignored files)
        will not be appended to `self.undo_list`.

        N(
   R   t   doR   t   create_job_setR   t   _is_change_interestingt	   undo_listR   t   _remove_extra_itemst	   redo_list(   R   t   changest   task_handle(    (    s0   lib/python2.7/site-packages/rope/base/history.pyR      s    	
c         C   s<   t  |  j ƒ |  j k r8 |  j d t  |  j ƒ |  j 5n  d  S(   Ni    (   t   lenR   t	   max_undos(   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR    ,   s    c         C   s1   x* | j  ƒ  D] } |  j j | ƒ s t Sq Wt S(   N(   t   get_changed_resourcesR   t
   is_ignoredR   t   False(   R   R"   t   resource(    (    s0   lib/python2.7/site-packages/rope/base/history.pyR   0   s    c         C   s§   |  j  s t j d ƒ ‚ n  | d k r7 |  j d } n  |  j |  j | ƒ } |  j |  j | ƒ |  j t | ƒ | ƒ |  j	 t | ƒ } | r£ |  j	 t | ƒ 3n  | S(   s°  Redo done changes from the history

        When `change` is `None`, the last done change will be undone.
        If change is not `None` it should be an item from
        `self.undo_list`; this change and all changes that depend on
        it will be undone.  In both cases the list of undone changes
        will be returned.

        If `drop` is `True`, the undone change will not be appended to
        the redo list.

        s   Undo list is emptyiÿÿÿÿN(
   R   R    t   HistoryErrorR   R   t   _find_dependenciest   _move_frontt   _perform_undosR$   R!   (   R   R   t   dropR#   t   dependenciesR   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   undo6   s    	c         C   s‡   |  j  s t j d ƒ ‚ n  | d k r7 |  j  d } n  |  j |  j  | ƒ } |  j |  j  | ƒ |  j t | ƒ | ƒ |  j t | ƒ S(   sV  Redo undone changes from the history

        When `change` is `None`, the last undone change will be
        redone.  If change is not `None` it should be an item from
        `self.redo_list`; this change and all changes that depend on
        it will be redone.  In both cases the list of redone changes
        will be returned.

        s   Redo list is emptyiÿÿÿÿN(	   R!   R    R*   R   R+   R,   t   _perform_redosR$   R   (   R   R   R#   R/   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   redoP   s    
	c         C   s/   x( | D]  } | j  | ƒ | j | ƒ q Wd  S(   N(   t   removeR   (   R   t   change_listR"   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR,   c   s    c         C   s    | j  | ƒ } t | | ƒ ƒ  S(   N(   t   indext   _FindChangeDependencies(   R   R4   R   R5   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR+   h   s    c         C   sz   xs t  | ƒ D]e } |  j d |  _ z) t j | |  j ƒ } |  j j | ƒ Wd  d  |  _ X|  j j |  j j	 ƒ  ƒ q Wd  S(   Niÿÿÿÿ(
   t   rangeR   R   R   R   R0   R   R!   R   t   pop(   R   t   countR#   t   it   job_set(    (    s0   lib/python2.7/site-packages/rope/base/history.pyR-   l   s    	
c         C   sz   xs t  | ƒ D]e } |  j d |  _ z) t j | |  j ƒ } |  j j | ƒ Wd  d  |  _ X|  j j |  j j	 ƒ  ƒ q Wd  S(   Niÿÿÿÿ(
   R7   R!   R   R   R   R   R   R   R   R8   (   R   R9   R#   R:   R;   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR1   w   s    	
c         C   sf   |  j  d  k r d  S|  j |  j  g | ƒ } | d  k	 r; | S| j ƒ  r^ | j ƒ  r^ | j ƒ  Sd  Sd  S(   N(   R   R   t   _search_for_change_contentst   existst	   is_foldert   read(   R   t   fileR   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   contents_before_current_change‚   s    
c         C   s}   xv t  | ƒ D]h } t | t j ƒ rM |  j | j | ƒ } | d  k	 rM | Sn  t | t j ƒ r | j | k r | j	 Sq Wd  S(   N(
   t   reversedt
   isinstanceR   t	   ChangeSetR<   R"   R   t   ChangeContentsR)   t   old_contents(   R   R4   R@   t   change_R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR<      s    	c         C   s   |  j  r™ g  } t j ƒ  } |  j ƒ  | j g  |  j D] } | | ƒ ^ q5 ƒ | j g  |  j D] } | | ƒ ^ q^ ƒ |  j j j	 d | d |  j
 ƒn  d  S(   NR   R   (   R   R   t   ChangeToDataR    R   R   R!   R   R	   t
   write_dataR   (   R   R   t   to_dataRG   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR   ˜   s    	
))c         C   s@   g  } x3 |  j  D]( } | | j ƒ  k r | j | ƒ q q W| S(   N(   R   R&   R   (   R   R)   R   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   get_file_undo_list¢   s
    c         C   s   d t  |  j ƒ t  |  j ƒ S(   Ns"   History holds %s changes in memory(   R$   R   R!   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   __str__©   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   <lambda>­   t    c         C   s   |  j  S(   N(   R   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyRM   ®   RN   c         C   s   |  j  r |  j  d Sd S(   s3   The last done change if available, `None` otherwiseiÿÿÿÿN(   R   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   tobe_undone°   s    	c         C   s   |  j  r |  j  d Sd S(   s5   The last undone change if available, `None` otherwiseiÿÿÿÿN(   R!   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   tobe_redone¶   s    	c         C   s0   |  j  d  k r% |  j j j d d ƒ S|  j  Sd  S(   Nt   max_history_itemsid   (   R   R   R   t   prefst   get(   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR%   ¼   s    c         C   s   |  j  j j d t ƒ S(   Nt   save_history(   R   RR   RS   R(   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR   Ã   s    c         C   s   |  j  j j d t ƒ S(   Nt   compress_history(   R   RR   RS   R(   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR   Ç   s    c         C   s   |  j  2|  j 2d S(   s$   Forget all undo and redo informationN(   R   R!   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   clearË   s    N(    t   __name__t
   __module__t   __doc__R   R   R   R   t   NullTaskHandleR   R    R   R(   R0   R2   R,   R+   R-   R1   RA   R<   R   RK   RL   t   propertyR   R!   RO   RP   R%   R   R   RV   (    (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR      s4   											
		R6   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s2   | d |  _  | |  _ t |  j  j ƒ  ƒ |  _ d  S(   Ni    (   R   R4   t   setR&   t   changed_resources(   R   R4   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR   Ó   s    	c         C   s`   |  j  g } xM |  j d D]> } |  j | | ƒ r | j | ƒ |  j j | j ƒ  ƒ q q W| S(   Ni   (   R   R4   t   _depends_onR   R]   t   updateR&   (   R   R   R   (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   __call__Ø   s    c         C   s’   x‹ | j  ƒ  D]} } | d  k r% q n  | |  j k r8 t SxO |  j D]D } | j ƒ  rg | j | ƒ rg t S| j ƒ  rB | j | ƒ rB t SqB Wq Wt S(   N(   R&   R   R]   R   R>   t   containsR(   (   R   R"   R   R)   t   changed(    (    s0   lib/python2.7/site-packages/rope/base/history.pyR^   à   s    (   RW   RX   R   R`   R^   (    (    (    s0   lib/python2.7/site-packages/rope/base/history.pyR6   Ñ   s   		N(   t	   rope.baseR    R   R   t   objectR   R6   (    (    (    s0   lib/python2.7/site-packages/rope/base/history.pyt   <module>   s   Í