
    cc                     0    d dl mZmZmZmZ  G d d      Zy)    )GdkGio	GdkPixbufGLibc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zi fdZd Zd Zy)DrHistoryManagerc                 J    || _         g | _        g | _        d| _        d| _        y )NTF)_image_undo_history_redo_history	_is_saved_waiting_for_rebuild)selfimagekwargss      9/usr/lib/python3/dist-packages/drawing/history_manager.py__init__zDrHistoryManager.__init__   s(    $+$$$.#$    c                     | j                   S N)r   r   s    r   	get_savedzDrHistoryManager.get_saved   s     
r   c                     | j                   D ]  }| j                  |        | j                  D ]  }| j                  |        | j                  | j                         y)z{Probably useless way to explicitly 'forget' the objects. It doesn't
		really free the memory, but it kinda helps i suppose.N)r   _delete_operationr   initial_operation)r   ops     r   empty_historyzDrHistoryManager.empty_history   s^      b" b"//0r   c                 $    |D ]  }d ||<   	 i }d }y r    )r   r   keys      r   r   z"DrHistoryManager._delete_operation!   s$     c2c7	""r   c                 d   | j                         r)| j                  j                         j                          y t	        | j
                        dkD  r5| j
                  j                         }| j                  j                  |       | j                          | j                  j                          y Nr   )_operation_is_ongoingr
   active_toolcancel_ongoing_operationlenr   popr   append_rebuild_from_history_asyncupdate_history_sensitivity)r   last_ops     r   try_undozDrHistoryManager.try_undo*   s    	!;;557			q ##%7W%""$++((*r   c                     | j                   j                         }|d   6| j                  j                  |       | j                  j                          y | j                  |d         j                  |       y )Ntool_id)r   r'   r   r(   r
   restore_last_state	_get_toolapply_operation)r   args	operations      r   try_redozDrHistoryManager.try_redo4   sa      $$&)y!Y';;!!#>>)I&'77	Br   c                 V    t        | j                        dkD  xs | j                         S r"   )r&   r   r#   r   s    r   can_undozDrHistoryManager.can_undo<   s&    
d  
!A
%	F$*D*D*FFr   c                 2    t        | j                        dkD  S r"   )r&   r   r   s    r   can_redozDrHistoryManager.can_redo@   s    	T	 1	$$r   c                     | j                   ddd   | j                  z   | _        g | _         | j                  j                          y)zkPut the entire 'undo' history into the 'redo' history, so the image
		can be reset without losing any data.N)r   r   r
   r*   r   s    r   rewind_historyzDrHistoryManager.rewind_historyW   s>     ))$B$/$2D2DD$$++((*r   c                 |    | j                   j                          d| _        | j                  j	                  |       y )NF)r
   set_surface_as_stable_pixbufr   r   r(   )r   r3   s     r   add_operationzDrHistoryManager.add_operationa   s/    ++**, $.I&r   c                     t        |d         }t        |d         }t        |d         }t        |d         }d |t        j                  ||||      ||d| _        y )Nr            )redgreenbluealpha)r.   pixbufrgbawidthheight)floatr   RGBAr   )	r   
rgba_arrayrG   rI   rJ   rgbas	            r   set_initial_operationz&DrHistoryManager.set_initial_operationn   sa    JqM!JqM!JqM!JqM!88!4V	$r   c                     |t        t        d            | j                  j                  d ||j	                         |j                         d       d| _        y )Nz Attempt to save an invalid state)r.   rG   rI   rJ   T)	Exception_r   r(   	get_width
get_heightr   )r   rG   s     r   	add_statezDrHistoryManager.add_statez   sX    ^	178	99 	  $.r   c                 $    | j                   d   d uS )NrG   )r   r   s    r   has_initial_pixbufz#DrHistoryManager.has_initial_pixbuf   s    				)	55r   c                 d    | j                  d      }|dk(  r| j                  S | j                  |   S )NFr:   )_get_last_state_indexr   r   )r   indexs     r   get_last_saved_statez%DrHistoryManager.get_last_saved_state   s6    

$
$U
+%
b[

 
  


U
##r   c                     d}d}| j                   D ]*  }|d   	|}| j                   j                  |      }|dz  }, |S )zReturn the index of the last "state" operation (dict whose 'tool_id'
		value is None) in the undo-history. If there is no such operation, the
		returned index is -1 which means the only known state is the
		self.initial_operation attribute.r:   r   r.   r@   )r   r]   )r   allow_yeeting_statesreturned_index	nbPixbufsr   last_saved_pixbuf_ops         r   r\   z&DrHistoryManager._get_last_state_index   sZ     .) bm''--b1NNI	 
r   c                 n    | j                   s)d| _         t        j                  d| j                  i        y y )NTi  )r   r   timeout_add_rebuild_from_historyr   s    r   r)   z,DrHistoryManager._rebuild_from_history_async   s0    		"	"#4C33R8 
#r   c                    | j                   syd| _         | j                  d      }| j                  j                          | j                  j                         }g | _        |D ]U  }|j                  |      |kD  r$| j                  |d         j                  |       ;| j                  j                  |       W | j                  j                          y)z}Rebuild the image according to the content of the current history.
		This is used as a GSourceFunc so it should return False.FTr.   )r   r\   r
   r/   r   copyr]   r0   simple_apply_operationr(   update)r   async_cb_datalast_save_indexhistoryr   s        r   rf   z&DrHistoryManager._rebuild_from_history   s     
	"	"
#$..t4/++  "##%'$ "bmmB/)NN2i=!88< 	b!" ++	r   c                 R    | j                   j                         j                         S r   )r
   r$   has_ongoing_operationr   s    r   r#   z&DrHistoryManager._operation_is_ongoing   s    		 	 	"	8	8	::r   c                     | j                   j                  j                  }||v r||   S | j                   j                  j                  t	        d|z               y )NzError: no tool '%s')r
   windowtoolsreveal_action_reportrU   )r   r.   	all_toolss      r   r0   zDrHistoryManager._get_tool   sM    kk  &&)	
G
;;**1-BW-L+MNr   N)__name__
__module____qualname____gtype_name__r   r   r   r   r,   r4   r6   r8   r;   r>   rR   rX   rZ   r^   r\   r)   rf   r#   r0   r   r   r   r   r      sn    $$
1+CG%.+'

6$.9 02 ,;Or   r   N)gi.repositoryr   r   r   r   r   r   r   r   <module>rz      s    4 3
GO GOr   