
    c                      R    d dl mZmZmZmZ  G d d          Z G d d          ZdS )    )change
exceptions
taskhandleutilsc                   t   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 dS )Historyz"A class that holds project historyNc                     || _         g | _        g | _        || _        |                                  | j         j                            | j                   d | _        d S N)	project
_undo_list
_redo_list	_maxundos_load_history
data_filesadd_write_hookwritecurrent_change)selfr   maxundoss      1lib/python3.11/site-packages/rope/base/history.py__init__zHistory.__init__   sY    !..tz:::"    c                 H   | j         r| j        j                            d          }|wt	          j        | j                  }|d         D ]%}| j                             ||                     &|d         D ])}| j                             ||                     &d S d S d S )Nhistoryr      )	saver   r   	read_datar   DataToChanger   appendr   )r   result	to_changedatas       r   r   zHistory._load_history   s    9 	<\,66yAAF <"/==	"1I < <DO**99T??;;;;"1I < <DO**99T??;;;;	< 	<< << <r   c                 (   	 || _         |                    t          j        ||                     d| _         n# d| _         w xY w|                     |          r.| j                            |           |                                  | j        dd= dS )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   s    	'")DJJv,['BBCCC"&D$D&&&&&&w// 	'N!!'***$$&&&N111s	   /9 	Ac                     t          | j                  | j        k    r&| j        dt          | j                  | j        z
  = d S d S Nr   )lenr'   	max_undosr   s    r   r(   zHistory._remove_extra_items+   sN    t~/ 	Iq3t~#6#6#GGHHH	I 	Ir   c                 n    |                                 D ]}| j                            |          s dS  dS NTF)get_changed_resourcesr   
is_ignored)r   r*   resources      r   r&   zHistory._is_change_interesting/   sF    5577 	 	H<**844 ttur   Fc                 z   | j         st          j        d          || j        d         }|                     | 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F666C--{;;;\!2!2 2 4 45 	5L 1 11334r   c                 B   | j         st          j        d          || j         d         }|                     | 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F666C--{;;;~s<0002233r   c                 d    |D ],}|                     |           |                    |           -d S r
   )remover   )r   change_listr*   r   s       r   r:   zHistory._move_fronta   sF     	' 	'Fv&&&v&&&&	' 	'r   c                 j    |                     |          } t          ||d                                S r
   )index_FindChangeDependencies)r   rD   r   rF   s       r   r9   zHistory._find_dependenciesf   s5    !!&));&{566':;;===r   c                 B   t          |          D ]}| j        d         | _        	 t          j        || j                  }| j                            |           d | _        n# d | _        w xY w| j                            | j                                                   d S Nr7   )	ranger'   r   r   r%   r>   r)   r   popr   countr+   ijob_sets        r   r;   zHistory._perform_undosj   s    u 	8 	8A"&."4D+ /T=PQQ#((111&*##d#****N!!$."4"4"6"67777	8 	8   4A!!	A*c                 B   t          |          D ]}| j        d         | _        	 t          j        || j                  }| j                            |           d | _        n# d | _        w xY w| j                            | j                                                   d S rI   )	rJ   r)   r   r   r%   r$   r'   r   rK   rL   s        r   r@   zHistory._perform_redost   s    u 	8 	8A"&."4D+ /T=PQQ#&&w///&*##d#****N!!$."4"4"6"67777	8 	8rP   c                     | j         d S |                     | j         g|          }||S |                                r(|                                s|                                S d S r
   )r   _search_for_change_contentsexists	is_folderread)r   filer    s      r   contents_before_current_changez&History.contents_before_current_change~   sn     	41143F2GNN 	M;;== 	!1!1 	99;;4r   c                     t          |          D ]k}t          |t          j                  r!|                     |j        |          }||c S t          |t          j                  r|j        |k    r	|j        c S ld S r
   )	reversed
isinstancer   	ChangeSetrS   r*   ChangeContentsr5   old_contents)r   rD   rW   change_r    s        r   rS   z#History._search_for_change_contents   s    ,, 	, 	,G'6#344 "99'/4PP "!MMM'6#899 ,g>NRV>V ,++++	, 	,r   c                 D   | j         rg }t          j                    |                                  |                    fd| j        D                        |                    fd| j        D                        | j        j        	                    d|           d S d S )Nc                 &    g | ]} |          S  rb   .0r_   to_datas     r   
<listcomp>z!History.write.<locals>.<listcomp>   #    HHHg))HHHr   c                 &    g | ]} |          S rb   rb   rc   s     r   rf   z!History.write.<locals>.<listcomp>   rg   r   r   )
r   r   ChangeToDatar(   r   r'   r)   r   r   
write_data)r   r"   re   s     @r   r   zHistory.write   s    9 	@D)++G$$&&&KKHHHHHHHIIIKKHHHHHHHIIIL#..y$?????	@ 	@r   c                 *    fd| j         D             S )Nc                 6    g | ]} |j                     v |S rb   )r3   )rd   r   r5   s     r   rf   z.History.get_file_undo_list.<locals>.<listcomp>   s@     
 
 
767999

 
 
r   r'   )r   r5   s    `r   get_file_undo_listzHistory.get_file_undo_list   s0    
 
 
 
.
 
 
 	
r   c                 Z    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#dn"5"55
 	
r   c                     | j         S r
   )r   r0   s    r   <lambda>zHistory.<lambda>       do r   c                     | j         S r
   )r   r0   s    r   rr   zHistory.<lambda>   rs   r   c                 .    | j         r| j         d         S dS )z3The last done change if available, `None` otherwiser7   Nrm   r0   s    r   tobe_undonezHistory.tobe_undone   %     > 	&>"%%	& 	&r   c                 .    | j         r| j         d         S dS )z5The last undone change if available, `None` otherwiser7   N)r)   r0   s    r   tobe_redonezHistory.tobe_redone   rw   r   c                 ^    | j          | j        j                            dd          S | j         S )Nmax_history_itemsd   )r   r   prefsgetr0   s    r   r/   zHistory.max_undos   s0    > 	"<%))*=sCCC>!r   c                 B    | j         j                            dd          S )Nsave_historyF)r   r}   r~   r0   s    r   r   zHistory.save   s    |!%%ne<<<r   z'compress_history is no longer supportedc                     dS )NFrb   r0   s    r   compresszHistory.compress   s	     ur   c                 .    | j         dd= | j        dd= dS )z$Forget all undo and redo informationN)r'   r)   r0   s    r   clearzHistory.clear   s$    N111N111r   r
   )!__name__
__module____qualname____doc__r   r   r   DEFAULT_TASK_HANDLEr$   r(   r&   r>   rA   r:   r9   r;   r@   rX   rS   r   rn   rp   propertyr'   r)   rv   ry   r/   r   r   
deprecatedr   r   rb   r   r   r   r      s       ,,# # # #< < < '1&D    "I I I   U
8V    2 J,J 4 4 4 4&' ' '
> > >8 8 88 8 8	 	 	, , ,@ @ @
 
 

 
 

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