
    Æe                      D    d dl mZmZmZmZ  G d d      Z G d d      Zy)    )change
exceptions
taskhandleutilsc                   d   e Zd ZdZddZd Zej                  fdZd Z	d Z
ddej                  fd	Zdej                  f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 ej<                  d      d               Zd Z y)Historyz"A class that holds project historyNc                     || _         g | _        g | _        || _        | j	                          | j                   j
                  j                  | j                         d | _        y N)	project
_undo_list
_redo_list	_maxundos_load_history
data_filesadd_write_hookwritecurrent_change)selfr   maxundoss      3/usr/lib/python3/dist-packages/rope/base/history.py__init__zHistory.__init__   sN    !..tzz:"    c                 X   | j                   r| j                  j                  j                  d      }|vt	        j
                  | j                        }|d   D ]#  }| j                  j                   ||             % |d   D ]#  }| j                  j                   ||             % y y y )Nhistoryr      )	saver   r   	read_datar   DataToChanger   appendr   )r   result	to_changedatas       r   r   zHistory._load_history   s    99\\,,66yAF!"//=	"1I <DOO**9T?;<"1I <DOO**9T?;<	 " r   c                    	 || _         |j                  t        j                  ||             d| _         | j	                  |      r+| j
                  j                  |       | j                          | j                  dd= y# d| _         w xY w)zPerform 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   dor   create_job_set_is_change_interesting	undo_listr   _remove_extra_items	redo_list)r   changestask_handles      r   r$   z
History.do   st    	'")DJJv,,['BC"&D&&w/NN!!'*$$&NN1	 #'Ds   ,B 	B
c                     t        | j                        | j                  kD  r0| j                  dt        | j                        | j                  z
  = y y Nr   )lenr'   	max_undosr   s    r   r(   zHistory._remove_extra_items+   s?    t~~/q3t~~#6#GGH 0r   c                 h    |j                         D ]  }| j                  j                  |      r y yNTF)get_changed_resourcesr   
is_ignored)r   r*   resources      r   r&   zHistory._is_change_interesting/   s4    557 	H<<**84	 r   Fc                 x   | j                   st        j                  d      || j                  d   }| j	                  | j                  |      }| j                  | j                  |       | j                  t        |      |       | j                  t        |       d }|r| j                  t        |       d= |S )a  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.

        zUndo list is emptyN)	r   r   HistoryErrorr'   _find_dependencies_move_front_perform_undosr.   r)   )r   r   dropr+   dependenciesr    s         r   undozHistory.undo5   s     ))*>??>^^B'F..t~~vF6C-{;\!2 2 45L 1134r   c                 >   | j                   st        j                  d      || j                   d   }| j                  | j                   |      }| j	                  | j                   |       | j                  t        |      |       | j                  t        |       d S )aV  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.

        zRedo list is emptyNr7   )r)   r   r8   r9   r:   _perform_redosr.   r'   )r   r   r+   r=   s       r   redozHistory.redoN   s     ~~))*>??>^^B'F..t~~vF6C-{;~~s<00233r   c                 V    |D ]$  }|j                  |       |j                  |       & y r
   )remover   )r   change_listr*   r   s       r   r:   zHistory._move_fronta   s-     	'Fv&v&	'r   c                 J    |j                  |      } t        ||d               S r
   )index_FindChangeDependencies)r   rD   r   rF   s       r   r9   zHistory._find_dependenciesf   s*    !!&);&{56':;==r   c                 P   t        |      D ]  }| j                  d   | _        	 t        j                  || j                        }| j                  j                  |       d | _        | j                  j                  | j                  j                                 y # d | _        w xY wNr7   )	ranger'   r   r   r%   r>   r)   r   popr   countr+   ijob_sets        r   r;   zHistory._perform_undosj   s    u 	8A"&.."4D+ //T=P=PQ##((1&*#NN!!$.."4"4"67	8 '+#   ;B	B%c                 P   t        |      D ]  }| j                  d   | _        	 t        j                  || j                        }| j                  j                  |       d | _        | j                  j                  | j                  j                                 y # d | _        w xY wrI   )	rJ   r)   r   r   r%   r$   r'   r   rK   rL   s        r   r@   zHistory._perform_redost   s    u 	8A"&.."4D+ //T=P=PQ##&&w/&*#NN!!$.."4"4"67	8 '+#rP   c                     | j                   y | j                  | j                   g|      }||S |j                         r |j                         s|j	                         S y r
   )r   _search_for_change_contentsexists	is_folderread)r   filer    s      r   contents_before_current_changez&History.contents_before_current_change~   sX    &1143F3F2GNM;;=!199;r   c                    t        |      D ]v  }t        |t        j                        r"| j	                  |j
                  |      }||c S t        |t        j                        sZ|j                  |k(  sj|j                  c S  y r
   )	reversed
isinstancer   	ChangeSetrS   r*   ChangeContentsr5   old_contents)r   rD   rW   change_r    s        r   rS   z#History._search_for_change_contents   sq    , 	,G'6#3#3499'//4P%!M'6#8#89g>N>NRV>V+++	,r   c                    | j                   rg }t        j                         }| j                          |j	                  | j
                  D cg c]
  } ||       c}       |j	                  | j                  D cg c]
  } ||       c}       | j                  j                  j                  d|       y y c c}w c c}w )Nr   )
r   r   ChangeToDatar(   r   r'   r)   r   r   
write_data)r   r"   to_datar_   s       r   r   zHistory.write   s    99D))+G$$&KKHg)HIKKHg)HILL##..y$?  IHs   B9;B>c                 f    | j                   D cg c]  }| |j                         v r| c}S c c}w r
   )r'   r3   )r   r5   r   s      r   get_file_undo_listzHistory.get_file_undo_list   s<     ..
767799 
 	
 
s   .c                 ^    dt        | j                        t        | j                        z   z  S )Nz"History holds %s changes in memory)r.   r'   r)   r0   s    r   __str__zHistory.__str__   s)    3#dnn"55
 	
r   c                     | j                   S r
   )r   r0   s    r   <lambda>zHistory.<lambda>   
    doo r   c                     | j                   S r
   )r   r0   s    r   ri   zHistory.<lambda>   rj   r   c                 :    | j                   r| j                   d   S y)z3The last done change if available, `None` otherwiser7   N)r'   r0   s    r   tobe_undonezHistory.tobe_undone        >>>>"%% r   c                 :    | j                   r| j                   d   S y)z5The last undone change if available, `None` otherwiser7   N)r)   r0   s    r   tobe_redonezHistory.tobe_redone   rn   r   c                 ~    | j                   &| j                  j                  j                  dd      S | j                   S )Nmax_history_itemsd   )r   r   prefsgetr0   s    r   r/   zHistory.max_undos   s4    >>!<<%%))*=sCC>>!r   c                 N    | j                   j                  j                  dd      S )Nsave_historyF)r   rt   ru   r0   s    r   r   zHistory.save   s    ||!!%%ne<<r   z'compress_history is no longer supportedc                      y)NF r0   s    r   compresszHistory.compress   s     r   c                 @    | j                   dd= | j                  dd= y)z$Forget all undo and redo informationN)r'   r)   r0   s    r   clearzHistory.clear   s    NN1NN1r   r
   )!__name__
__module____qualname____doc__r   r   r   DEFAULT_TASK_HANDLEr$   r(   r&   r>   rA   r:   r9   r;   r@   rX   rS   r   re   rg   propertyr'   r)   rm   rp   r/   r   r   
deprecatedrz   r|   ry   r   r   r   r      s   ,#< '1&D&D "I U
8V8V 2 J,J,J 4&'
>88	,@


 56I56I& &
 & &
 " " = = U?@ A r   r   c                       e Zd Zd Zd Zd Zy)rG   c                 v    |d   | _         || _        t        | j                   j                               | _        y r-   )r   rD   setr3   changed_resources)r   rD   s     r   r   z _FindChangeDependencies.__init__   s/    !!n&!$T[[%F%F%H!Ir   c                     | j                   g}| j                  dd  D ]P  }| j                  ||      s|j                  |       | j                  j                   |j                                R |S )Nr   )r   rD   _depends_onr   r   updater3   )r   r    r   s      r   __call__z _FindChangeDependencies.__call__   sn    ++&&qr* 	NF/f%&&--.Jf.J.J.LM	N r   c                    |j                         D ]o  }||| j                  v r y| j                  D ]K  }|j                         r|j                  |      r  y|j                         s8|j                  |      sJ  y q yr2   )r3   r   rU   contains)r   r*   r    r5   changeds        r   r   z#_FindChangeDependencies._depends_on   s    557 		 H411111  %%'H,=,=g,F$$&7+;+;H+E	 		  r   N)r}   r~   r   r   r   r   ry   r   r   rG   rG      s    J
r   rG   N)	rope.baser   r   r   r   r   rG   ry   r   r   <module>r      s"    ; ;E EP r   