
    j                        d dl mZmZmZmZmZ d dlmZmZ dej                  j                  idej                  j                  iddidej                  j                  idd	id
diej                  j                  dddddddddiddiddidZg dZg dZ G d de      Z G d de      Z G d de      Z G d  d!e      Z G d" d#e      Z G d$ d%e      Z G d& d'e      Z G d( d)ej4                        Z G d* d+ej8                        Zy,)-    )GdkGLibGObjectGtkPango)ends_with_urlget_url_startweightstylefamily	Monospace	underlinestrikethroughT
backgroundyellowblue)r   
foregroundg      ?i        )scaler
   zpixels-above-lineszpixels-below-linesr   g~?g333333?g
ףp=
?)bolditalic	monospacer   r   	highlightlinkheadersmalllargelarger)r   normalr   r   )
	 .,;:c                       e Zd Zd Zy)GenericActionc                      yNF self
new_actions     /usr/lib/sticky/note_buffer.py
maybe_joinzGenericAction.maybe_join   s        N)__name__
__module____qualname__r1   r,   r2   r0   r)   r)      s    r2   r)   c                   0     e Zd Z fdZd Zd Zd Z xZS )AdditionActionc                 p    t         t        |           || _        || _        |j                         | _        y N)superr7   __init__buffertext
get_offsetposition)r.   r<   r=   location	__class__s       r0   r;   zAdditionAction.__init__   s.    nd,.	 ++-r2   c                 ~   | j                   j                  | j                        }| j                   j                  | j                  t        | j                        z         }| j                   j                  ||       | j                   j                  | j                        }| j                   j                  ||       y r9   r<   get_iter_at_offsetr?   lenr=   deleteselect_ranger.   startendposs       r0   undozAdditionAction.undo&       ..t}}=kk,,T]]S^-KL5#& kk,,T]];  c*r2   c                 D   | j                   j                  | j                   j                  | j                        | j                         | j                   j                  | j                  t        | j                        z         }| j                   j                  ||       y r9   )r<   insertrD   r?   r=   rE   rG   )r.   rK   s     r0   redozAdditionAction.redo/   sh    4;;99$--H$))T kk,,T]]S^-KL  c*r2   c                     t        |t              sy|j                  dk(  ry|j                  | j                  t	        | j                        z   k(  r | xj                  |j                  z  c_        yy)NFr!   T)
isinstancer7   r=   r?   rE   r-   s     r0   r1   zAdditionAction.maybe_join6   sU    *n5??d"$--#dii."@@II(Ir2   r3   r4   r5   r;   rL   rP   r1   __classcell__rA   s   @r0   r7   r7      s    .++r2   r7   c                   0     e Zd Z fdZd Zd Zd Z xZS )DeletionActionc                    t         t        |           || _        |j	                  ||d      | _        |j                         | _        |j                         rH|j                         \  }}|j                  |      dk(  r|j                  |      rd| _        y d| _        y | j                  j                  | j                  j                               j                  |      dk(  rd| _        y | j                  j                  | j                  j                               j                  |      dk(  rd| _        y d| _        y )NTr   	selectionotherbackwardforward)r:   rW   r;   r<   	get_slicer=   r>   r?   get_has_selectionget_selection_boundscomparedeletion_typeget_iter_at_mark
get_insert)r.   r<   rI   rJ   buffer_start
buffer_endrA   s         r0   r;   zDeletionAction.__init__E   s   nd,.$$UC6	((*##%)/)D)D)F&\:##E*a/J4F4Fs4K%0"%,"[[))$++*@*@*BCKKCPTUU!+D[[))$++*@*@*BCKKERVWW!*D!(Dr2   c                    | j                   j                  | j                   j                  | j                        | j                         | j
                  dk(  rB| j                   j                  | j                        }| j                   j                  ||       y | j
                  dk(  rX| j                   j                  | j                  t        | j                        z         }| j                   j                  ||       y | j                   j                  | j                        }| j                   j                  | j                  t        | j                        z         }| j                   j                  ||       y )Nr\   r[   )r<   rO   rD   r?   r=   ra   rG   rE   )r.   rK   pos1pos2s       r0   rL   zDeletionAction.undoY   s   4;;99$--H$))T *++00?CKK$$S#.:-++00TYY1OPCKK$$S#. ;;11$--@D;;11$--#dii.2PQDKK$$T40r2   c                 ~   | j                   j                  | j                        }| j                   j                  | j                  t        | j                        z         }| j                   j                  ||       | j                   j                  | j                        }| j                   j                  ||       y r9   rC   rH   s       r0   rP   zDeletionAction.redoi   rM   r2   c                    t        |t              r|j                  | j                  k7  ry| j                  dk(  r9|j                  | j                  k(  r | xj                  |j                  z  c_        y| j                  dk(  rL|j                  | j                  dz
  k(  r0|j                  | j                  z   | _        |j                  | _        yy)NFr\   Tr[      )rR   rW   ra   r?   r=   r-   s     r0   r1   zDeletionAction.maybe_joinr   s    *n59Q9QUYUgUg9g*z/B/Bdmm/SII(I:-*2E2EYZIZ2Z"$))3DI&//DMr2   rS   rU   s   @r0   rW   rW   D   s    )(1 +r2   rW   c                   8     e Zd Zd fd	Zd Zd Zd Zd Z xZS )ObjectInsertActionc                 X   t         t        |           || _        || _        t        |j                         d   t        j                        rd| _	        n2t        |j                         d   t        j                        rd| _	        |j                  |      j                         | _        y )Nr   checkbullet)r:   rm   r;   r<   is_additionrR   get_widgetsr   CheckButtonanchor_typeImageget_iter_at_child_anchorr>   r?   )r.   r<   anchorrq   rA   s       r0   r;   zObjectInsertAction.__init__   s     $02&f((*1-s?&D**,Q/;'D77?JJLr2   c                 \   | j                   j                  | j                        }| j                   j                  | j                  dz         }| j                  dk(  r4|j	                         j                         d   j                         | _        | j                   j                  ||       y )Nrk   ro   r   )	r<   rD   r?   rt   get_child_anchorrr   
get_activecheckedrF   )r.   start_anchor_iterend_anchor_iters      r0   removezObjectInsertAction.remove   s     KK::4==I++889JKw&,==?KKMaP[[]DL,o>r2   c                 T   | j                   dk(  rK| j                  j                  | j                  j                  | j                        | j
                         y | j                   dk(  r?| j                  j                  | j                  j                  | j                               y y )Nro   r{   rp   )rt   r<   add_check_buttonrD   r?   r{   
add_bulletr.   s    r0   addzObjectInsertAction.add   sy    w&KK(()G)G)V`d`l`l(m)KK""4;;#A#A$--#PQ *r2   c                 ^    | j                   r| j                          y | j                          y r9   rq   r~   r   r   s    r0   rL   zObjectInsertAction.undo       KKMHHJr2   c                 ^    | j                   r| j                          y | j                          y r9   rq   r   r~   r   s    r0   rP   zObjectInsertAction.redo       HHJKKMr2   T	r3   r4   r5   r;   r~   r   rL   rP   rT   rU   s   @r0   rm   rm      s    	M?Rr2   rm   c                   8     e Zd Zd fd	Zd Zd Zd Zd Z xZS )	TagActionc                 L   t         t        |           || _        || _        || _        |j                         }d}d }g | _        |j                  |      dk  r|j                  |j                         j                  |            }	||	|k7  r|j                         }n4|r2|	|k(  r-| j                  j                  ||j                         f       d }|j                          |j                  |      dk  r|,| j                  j                  ||j                         f       y y )NFr   )r:   r   r;   r<   namerq   copyrangesr`   has_tagget_tag_tablelookupr>   appendforward_char)r.   r<   r   rI   rJ   rq   current_iterin_tagrange_startr   rA   s             r0   r;   zTagAction.__init__   s   i')	& zz|""3'!+"**6+?+?+A+H+H+NOG "w+'=*557K!7""K1H1H1J#KL"%%' ""3'!+ "KKS^^-=>? #r2   c                     | j                   D ]^  \  }}| j                  j                  | j                  | j                  j	                  |      | j                  j	                  |             ` y r9   )r   r<   remove_tag_by_namer   rD   r.   rI   rJ   s      r0   r~   zTagAction.remove   s_     KK 	BLUCKK**499dkk6T6TUZ6[]a]h]h]{]{|  ^A  B	Br2   c                     | j                   D ]^  \  }}| j                  j                  | j                  | j                  j	                  |      | j                  j	                  |             ` y r9   )r   r<   apply_tag_by_namer   rD   r   s      r0   r   zTagAction.add   s[     KK 	ALUCKK))$))T[[5S5STY5Z\`\g\g\z\z{~\  A	Ar2   c                 ^    | j                   r| j                          y | j                          y r9   r   r   s    r0   rL   zTagAction.undo   r   r2   c                 ^    | j                   r| j                          y | j                          y r9   r   r   s    r0   rP   zTagAction.redo   r   r2   r   r   rU   s   @r0   r   r      s    @6BAr2   r   c                   6     e Zd Z fdZd Zd Zd Zd Z xZS )ShiftActionc                     t         t        |           || _        || _        |j                         | _        |j                         | _        y r9   )r:   r   r;   r<   is_upget_linerI   rJ   )r.   r<   rI   rJ   r   rA   s        r0   r;   zShiftAction.__init__   s9    k4)+
^^%
<<>r2   c                 l   | j                   j                  | j                        }| j                   j                  | j                        }|j	                          | j                   j                  d |d      }| j                   j                  d |d      }|j                         }|j                          |j                         }|j	                          | j                   j                  d |d      }| j                   j                  d |d      }| j                   j                  |||       | j                   j                  |      j                         }	|	t        |	j                         d   t        j                        rX|	j                         d   j                         }
| j                   j!                  | j                   j                  |      |
      }n_t        |	j                         d   t        j"                        r4| j                   j%                  | j                   j                  |            }| j                   j'                  | j                   j                  |      dd       | j                   j                  |      }| j                   j                  |      }|j)                          | j                   j+                  ||       | j                   j-                  | j                   j                  |      | j                   j                  |             | j                   j/                  |       | j                   j/                  |       | j                   j/                  |       | j                   j/                  |       | xj                  dz  c_        | xj                  dz  c_        y )NFTr   r   r!   rk   )r<   get_iter_at_linerI   rJ   forward_to_line_endcreate_markr   backward_lineinsert_rangerb   ry   rR   rr   r   rs   rz   r   ru   r   rO   r   rF   rG   delete_mark)r.   
start_iterend_iter
start_markend_mark
move_startmove_endmove_start_markmove_end_markrw   r{   
obj_actiondelete_start
delete_ends                 r0   shift_upzShiftAction.shift_up   s   [[11$**=
;;//9$$&[[,,T:uE
;;**44@__&
  "??$$$&++11$
EJ//hE  :x@--o>OOQ&,,.q13??C ,,.q1<<>![[99$++:V:VW_:`jq9r
F..03SYY?![[33DKK4P4PQY4Z[
4;;77A4L{{33OD[[11-@
!<4 	  !=!=j!I4;;KgKghpKqr0.
+)

a
Ar2   c                    | j                   j                  | j                        }| j                   j                  | j                        }|j	                          | j                   j                  d |d      }| j                   j                  d |d      }| j                   j                  d |d      }|j                         }|j                          |j                         }|j	                          | j                   j                  d |d      }| j                   j                  d |d      }	| j                   j                  |||       | j                   j                  | j                   j                  |      dd       | j                   j                  |      j                         }
|
t        |
j                         d   t        j                        rX|
j                         d   j!                         }| j                   j#                  | j                   j                  |      |      }n_t        |
j                         d   t        j$                        r4| j                   j'                  | j                   j                  |            }| j                   j                  |      }|j)                          | j                   j                  |	      }| j                   j+                  ||       | j                   j-                  | j                   j                  |      | j                   j                  |             | j                   j/                  |       | j                   j/                  |	       | j                   j/                  |       | j                   j/                  |       | j                   j/                  |       | xj                  dz  c_        | xj                  dz  c_        y )NTFr!   r   r   r   rk   )r<   r   rI   rJ   r   r   r   forward_liner   rO   rb   ry   rR   rr   r   rs   rz   r   ru   r   backward_charrF   rG   r   )r.   r   r   
begin_markr   r   r   r   r   r   rw   r{   r   r   r   s                  r0   
shift_downzShiftAction.shift_down	  s   [[11$**=
;;//9$$&[[,,T:tD
[[,,T:uE
;;**44@]]_
!??$$$&++11$
EJ//hE  ZB4;;77
CT2N--o>OOQ&,,.q13??C ,,.q1<<>![[99$++:V:VWa:bls9t
F..03SYY?![[33DKK4P4PQ[4\]
{{33OD""$[[11-@
<4 	  !=!=j!I4;;KgKghpKqr0.
+)
+

a
Ar2   c                 ^    | j                   r| j                          y | j                          y r9   )r   r   r   r   s    r0   rL   zShiftAction.undo4  s    ::OOMMOr2   c                 ^    | j                   r| j                          y | j                          y r9   )r   r   r   r   s    r0   rP   zShiftAction.redo:  s    ::MMOOOr2   )	r3   r4   r5   r;   r   r   rL   rP   rT   rU   s   @r0   r   r      s    "'R)Vr2   r   c                   *     e Zd Z fdZd Zd Z xZS )CompositeActionc                 8    t         t        |           || _        y r9   )r:   r   r;   child_actions)r.   argsrA   s     r0   r;   zCompositeAction.__init__C  s    ot-/!r2   c                 X    t        | j                        D ]  }|j                           y r9   )reversedr   rL   r.   actions     r0   rL   zCompositeAction.undoG  s%    t112 	FKKM	r2   c                 F    | j                   D ]  }|j                           y r9   )r   rP   r   s     r0   rP   zCompositeAction.redoK  s     (( 	FKKM	r2   )r3   r4   r5   r;   rL   rP   rT   rU   s   @r0   r   r   B  s    "r2   r   c                   6     e Zd Z fdZd Zd Zd Zd Z xZS )CheckBoxc                 \    t        t        | 
  di | d | _        | j	                  d       y )NFr,   )r:   r   r;   event_windowset_has_window)r.   kwargsrA   s     r0   r;   zCheckBox.__init__Q  s+    h&00 E"r2   c                    t         j                  j                  |        | j                         }| j	                  |       | j                         }t        j                         }t        j                  j                  | j                         d      |_        t        j                  j                  |_        |j                  |_        |j                   |_        |j"                  |_        |j$                  |_        t        j&                  j(                  |_        | j-                         t        j.                  j0                  z  t        j.                  j2                  z  t        j.                  j4                  z  t        j.                  j6                  z  t        j.                  j8                  z  t        j.                  j:                  z  |_        t        j>                  j@                  t        j>                  jB                  z  t        j>                  jD                  z  }t        jF                  jI                  |||      | _%        | jM                  | jJ                         y )Ndefault)'r   rs   
do_realizeget_parent_window
set_windowget_allocationr   
WindowAttrCursornew_from_nameget_displaycursor
WindowTypeCHILDwindow_typexywidthheightWindowWindowClass
INPUT_ONLYwclass
get_events	EventMaskBUTTON_PRESS_MASKBUTTON_RELEASE_MASK
TOUCH_MASKENTER_NOTIFY_MASKLEAVE_NOTIFY_MASKPOINTER_MOTION_MASK
event_maskWindowAttributesTypeXYCURSORWindownewr   register_window)r.   parent_window
allocation
attributesattributes_masks        r0   r   zCheckBox.do_realizeX  s   ""4(..0&((*
^^%
JJ44T5E5E5GS
!$!5!5
!||
!||
%++
&--
11<<
 $ 1CMM4S4S SVYVcVcVwVw wz}  {H  {H  {S  {S  !S  VY  Vc  Vc  Vu  Vu  !u  x{  xE  xE  xW  xW  !W  Z]  Zg  Zg  Z{  Z{  !{
2244s7O7O7Q7QQTWTlTlTsTssJJNN=*oVT../r2   c                 v    t         j                  j                  |        | j                  j	                          y r9   )r   rs   do_mapr   showr   s    r0   r   zCheckBox.do_mapn  s&    t$ r2   c                 v    t         j                  j                  |        | j                  j	                          y r9   )r   rs   do_unmapr   hider   s    r0   r   zCheckBox.do_unmaps  s&      & r2   c                     t         j                  j                  | |       | j                  rG| j                  j	                  |j
                  |j                  |j                  |j                         y y r9   )	r   rs   do_size_allocater   move_resizer   r   r   r   )r.   r   s     r0   r  zCheckBox.do_size_allocatex  sS    ((z:))*,,
jFVFVXbXiXij r2   )	r3   r4   r5   r;   r   r   r   r  rT   rU   s   @r0   r   r   P  s    #0,!
!
kr2   r   c                   ~    e Zd ZdZdZg Zg Zg Zg Ze	j                  d        Ze	j                  d        Z e	j                  e	j                  j                  ee	j"                        d        Z fdZd Zd Zd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dZ#d Z$d Z%d Z&d Z'd Z(d Z)d Z* xZ+S ) 
NoteBufferr   c                 ,    t        | j                        S r9   )rE   undo_actionsr   s    r0   can_undozNoteBuffer.can_undo      4$$%%r2   c                 ,    t        | j                        S r9   )rE   redo_actionsr   s    r0   can_redozNoteBuffer.can_redo  r	  r2   )flagsreturn_typeaccumulatorc                      y r9   r,   r   s    r0   content_changedzNoteBuffer.content_changed  s     	r2   c                    t         t        |           g | _        t        j                         D ]1  \  }}| j                  j                   | j                  |fi |       3 | j                  d| j                         | j                  d| j                         | j                  d| j                         | j                  d| j                         y )Nzdelete-rangezbegin-user-actionzend-user-actionzmark-set)r:   r  r;   tagsTAG_DEFINITIONSitemsr   
create_tagconnect	on_deletebegin_composite_actionend_composite_actionon_mark_set)r.   r   r   rA   s      r0   r;   zNoteBuffer.__init__  s    j$(*	 / 5 5 7 	BD*II_T__T@Z@A	B 	^T^^4($*E*EF&(A(ABZ!1!12r2   c                       fd} fd}| _          j                   j                  d|        j                   j                  d|       y )Nc                    j                   j                  t        j                  j                        rt        j
                  S  j                   j                  j                   j                  t        j                  j                  |j                  |j                         d   }|j                  j                         j                  d            ryj                   j                   j"                  j%                  t        j&                  j)                  t        j*                  j-                         d             t        j.                  S t        j
                  S )Nrk   r   pointer)viewget_modifier_maskr   ModifierIntentEXTEND_SELECTIONEVENT_PROPAGATEget_iter_at_locationwindow_to_buffer_coordsr   TextWindowTypeTEXTr   r   r   r   r   propswindow
set_cursorr   r   Displayget_default
EVENT_STOP)vevent
mouse_iterr.   s      r0   track_motionz)NoteBuffer.set_view.<locals>.track_motion  s   yy**3+=+=+N+NO***7779Z9Z[^[m[m[r[rtyt{t{  ~C  ~E  ~E  :F  G  HI  JJ!!$"4"4"6"="=f"EF		&&11#**2J2J3;;KbKbKdfo2pq~~%&&&r2   c                    |j                   t        j                  j                  z  r|j                  dk7  rt        j
                  S j                         j                  d      } j                  j                  j                  j                  t        j                  j                  |j                  |j                         d   }|j!                  |      st        j
                  S |j#                         }|j%                  |       |j#                         }|j'                  |       j)                  ||d      }t        j*                  d ||j,                         t        j.                  S )Nrk   r   F)stater   ModifierTypeCONTROL_MASKbuttonr#  r   r   r  r$  r%  r   r&  r'  r   r   r   r   backward_to_tag_toggleforward_to_tag_toggler]   show_uritimer-  )r.  r/  tagr0  
start_linkend_linkurlr.   s          r0   handle_clickz)NoteBuffer.set_view.<locals>.handle_click  s-   ;;!1!1!>!>>5<<STCT***$$&--f5C7779Z9Z[^[m[m[r[rtyt{t{  ~C  ~E  ~E  :F  G  HI  JJ%%c****#*J--c2!(H**3/..Xu=CLLsEJJ/>>!r2   zmotion-notify-eventzbutton-press-event)r  r  )r.   r  r1  r?  s   `   r0   set_viewzNoteBuffer.set_view  s@    
	'	"& 			/>		.=r2   c                 F    | j                   dk(  r| j                  d       y y )Nr   zcontent-changed)internal_action_countemitr.   r   s     r0   trigger_changedzNoteBuffer.trigger_changed  s"    %%*II'( +r2   c                 8      G  fddt               } |       S )Nc                   $    e Zd Z fdZ fdZy)9NoteBuffer.internal_action.<locals>.InternalActionHandlerc                 0    xj                   dz  c_         y Nrk   )rB  )ar.   s    r0   	__enter__zCNoteBuffer.internal_action.<locals>.InternalActionHandler.__enter__  s    **a/*r2   c                     xj                   dz  c_         j                   dk(  r#r t        j                  j                         y y y Nrk   r   )rB  r   idle_addrE  )rK  exc_type	exc_value	tracebackr.   trigger_on_completes       r0   __exit__zBNoteBuffer.internal_action.<locals>.InternalActionHandler.__exit__  s@    **a/*--27JMM$"6"67 8K2r2   N)r3   r4   r5   rL  rT  )r.   rS  s   r0   InternalActionHandlerrH    s    08r2   rU  )object)r.   rS  rU  s   `` r0   internal_actionzNoteBuffer.internal_action  s    	8F 	8 %&&r2   c                    g }| j                   j                         }d}| j                  d      }	 |d d  D ]R  }|j                  |      r|d|j                  j
                  z  z  }|j                  |       |j                  |       T |d d  D ]R  }|j                  |      s|d|j                  j
                  z  z  }|j                  |       |j                  |       T |j                         }|dk(  r|dz  }n|j                         |j                         j                         d   }t        |t        j                        r+|j                         }|dt        t!        |            z   z  }n%t        |t        j"                        r|dz  }n||z  }|j%                         sn}|D ]  }|d|j                  j
                  z  z  }  |S )N r   z#tag:%s:###z#check:z#bullet:)r  r   rD   r   r(  r   r   r~   get_charry   rr   rR   r   rs   rz   strintru   r   )	r.   on_tagsoff_tagsr=   r   r;  current_charanchor_childr{   s	            r0   get_internal_markupzNoteBuffer.get_internal_markup  s   99>>#..q1qz (#++C0J77DOOC(NN3'	(  { )'',J77DNN3'OOC(	) (002Ls"..0<+<<>JJLQOlCOO<*557GICL(999Dcii8J&D$,,.? D  	0CJ//D	0 r2   c                 p   | j                  d      5  | j                  d       d}i }	 |j                  d|      }|dk(  r%| j                  | j	                         ||d         n| j                  | j	                         |||        |||dz    dk(  r'| j                  | j	                         d       |dz   }nf|||d	z    d
k(  rBt        t        ||dz                  }| j                  | j	                         |       |dz   }n|||dz    dk(  r%| j                  | j	                                |dz   }n|||dz    dk(  r|j                  d|d	z         }||dz   | }||v rW|j                  |      }| j                  |      }	| j	                         }
| j                  ||	|
       | j                  |       n$| j                  d | j	                         d      ||<   |d	z   t        |      z   }n0t        d       | j                  | j	                         d       |dz   }	 d d d        y # 1 sw Y   y xY w)NFrY  r   TrZ  r      r[     z#check   r      z#bulletr   z#tagr'      z-formatting error detected - attempting to fixrk   )rW  set_textfindrO   get_end_iterboolr^  r   r   poprb   r   r   r   rE   print)r.   r=   current_index	open_tags
next_indexr{   end_tag_indextag_namemarkrI   rJ   s              r0   set_from_internal_markupz#NoteBuffer.set_from_internal_markup  s=   !!%( (	3MM"MI!YYsM:
#KK 1 1 3T-.5IJD--/mJ1OP
:a<0D8KK 1 1 3S9$.NM*Z\2h>"3tJqL'9#:;G))$*;*;*=w)O$.NM*Z\2i?OOD$5$5$78$.NM*Z\2f<$(IIc:a<$@M#JqL?H9,(}}X6 $ 5 5d ;"//1..xD((..2.>.>tTEVEVEXZ^._	(+$.NS]$BMIJKK 1 1 3S9$.NMG  (	3 (	3 (	3s   HH,,H5c                 
   t        | j                        dk(  ry | j                         5  | j                  j                         }|j	                          | j
                  j                  |       d d d        y # 1 sw Y   y xY wNr   )rE   r  rW  rn  rL   r  r   r.   r   r   s      r0   rL   zNoteBuffer.undo:  j    t  !Q&!!# 	-&&**,FKKM$$V,	- 	- 	-   AA99Bc                 
   t        | j                        dk(  ry | j                         5  | j                  j                         }|j	                          | j
                  j                  |       d d d        y # 1 sw Y   y xY wrx  )rE   r  rW  rn  rP   r  r   ry  s      r0   rP   zNoteBuffer.redoC  rz  r{  c                 .    | xj                   dz  c_         y rJ  )in_compositerD  s     r0   r  z!NoteBuffer.begin_composite_actionL  s    Qr2   c                 \   | xj                   dz  c_         | j                   st        | j                        dk(  ry t        | j                        dk(  r| j                  | j                  d          n!| j                  t	        | j                          | j                  j                          y rN  )r~  rE   composite_actionsadd_undo_actionr   clearrD  s     r0   r  zNoteBuffer.end_composite_actionO  s    Q D$:$: ;q @ t%%&!+  !7!7!:;  $2H2H!IJ$$&r2   c                     | j                   r| j                  j                  |       y | j                  j                  |       | j                  j                          y r9   )r~  r  r   r  r  r  r   s     r0   r  zNoteBuffer.add_undo_action_  sE    ""))&1$$V,##%r2   c                    |j                         }t        | ||      }t        j                  j	                  | |||       | j
                  ry | j                         5  |dk(  r| j                  |dz         }|j                         }|j                          |j                         }|t        |j                         d   t        j                        r| j                  |      }	n<t        |j                         d   t        j                        r| j!                  |      }	t#        |	      }|j%                  | j                  |dz                | j                  |      }
|
j                         }|j'                          t)        |      dk(  rad}| j*                  D ]  }|t,        v r0d}t,        D ]%  }|dk7  s	t#        || j/                  ||
|            }' |
j                         }|dk(  rQ|j1                         |j3                  | j5                         j7                  |            z  rt#        || j/                  ||
|            }t#        || j9                  ||
|            } |
j;                  d      D ]k  }|j<                  j>                  }||dk(  r|dk(  r'|d	k(  r	|t@        v r5|| j*                  vsD|t,        vs|rOt#        || j9                  ||
|            }m g | _        | j<                  jB                  r| jD                  d
   jG                  |      s| jI                  |       d d d        |t@        v ro| jK                  | jM                         
d      }tO        |      }|r@| jI                  | j9                  d	| j                  |jQ                               |
             y y y # 1 sw Y   xY w)Nr!   rk   r   re  FTr    r   r   r   ))r>   r7   r   
TextBufferdo_insert_textrB  rW  rD   r   r   ry   rR   rr   rs   r   ru   r   r   assignr   rE   tag_togglesFONT_SCALES	strip_tagr   r   r   r   add_tagget_toggled_tagsr(  r   LINK_ENDERSr  r  r1   r  r]   get_start_iterr	   rI   )r.   r@   r=   lengthr?   r   	next_line	prev_linerw   r   rI   	next_charfont_scale_changedrt  scale_tag_nameprevr;  pre_textmatchs                      r0   r  zNoteBuffer.do_insert_textf  s}   &&(dH5%%dHdFC%%!!# E	-t| 33HQJ?	%NN,	'')"335%!&"4"4"6q"93??K%)%:%:9%E
#F$6$6$8$;SYYG%)__Y%?
,VZ@F
 OOD$;$;HqL$IJ ++H5E

I""$ 4yA~%*" $ 0 0 cH;.-1*.9 sN-9)8P^`egpAq)rs !::<D8+++-T=O=O=Q=X=XYa=b0cc!0RWYb9c!d!0hPUW`9a!bc" !11%8 cC"yy~~H'  t|H(<   6)dk.A   t'7'77X[=X`r!0hPUW`9a!b!c$ $& ::&&d.?.?.C.N.Nv.V$$V,KE	-P ;~~d&9&9&;UDIH!(+E$$T\\&$:Q:QRWR]R]R_:`bg%hi  QE	- E	-s!   EN7;DN7
N7A+N77O c                 >   | j                   rt        j                  S g }| j                         5  |j	                         }|j                         |j                          t        j                         }t        j                         }| j                  ||       | j                  ||       i }|j                  |      dk  r|j                         }	|	|j                         }
t        | |	d      }|j                  |       |j                          | j                  |
      }|j!                  | j#                  |             |j!                  | j#                  |             |j%                  d      D ]F  }|j&                  j(                  t*        v s |j                         ||j&                  j(                  <   H |j%                  d      D ]  }|j&                  j(                  t*        vr |j&                  j(                  |v rp|j                  t-        | |j&                  j(                  | j                  ||j&                  j(                           |d             ||j&                  j(                  = |j                  t-        | |j&                  j(                  ||d              |j                          |j                  |      dk  r|j/                         D ]2  \  }}|j                  t-        | || j                  |      |d             4 | j1                  |       | j1                  |       |j                  |      dk7  r|j                  t3        | ||             t5        |      dk(  rt        j6                  cd d d        S t5        |      dk(  r|d   }nt9        | }| j&                  j:                  r7| j<                  d   j?                  |      rt        j                  cd d d        S | jA                  |       d d d        y # 1 sw Y   y xY w)Nr   F)rq   Trk   r   )!rB  r   r#  rW  r   ry   r   r   TextMarkadd_markr`   r>   rm   r   r~   rD   r  rb   r  r(  r   r  r   r  r   rW   rE   r-  r   r  r  r1   r  )r.   r<   rI   rJ   actionsr   r   r   rq  rw   current_offsetr   r;  r   offsets                  r0   r  zNoteBuffer.on_delete  s}   %%&&& !!# @	) ::<L ##%1  "J||~HMM*e,MM(C(I&&s+a/%668%%1%<%<%>N/f%PFNN6*MMO#'#:#:>#JLJJt44X>?LL!6!6z!BC'88> NCyy~~84@4K4K4M	#))..1N
 (88? 	dCyy~~_< yy~~2ysyy~~tG^G^_hiliririwiw_xGy  |H  JO  (P  Q%ciinn5ysyy~~ul\a'bc	d ))+9 &&s+a/< !* 1 cfytT5L5LV5TVY[`abc Z(X& }}S!Q&~dE3?@7|q ~~o@	) @	)p W" ('2zz""t'8'8'<'G'G'O**}@	) @	)@   (A@	) @	) @	)s'   E&PD:PB4PAP9PPc                    | j                         r| j                         \  }}|j                         }d}|t        v rd}nl| j	                         j                  |      }|j                  |      dk  r9|j                  |      sd}n%|j                          |j                  |      dk  r9|r#| j                  | j                  |||             y | j                  | j                  |||             y |t        v r5| j                  D ]&  }|t        v s| j                  j                  |       ( || j                  v r| j                  j                  |       y | j                  j                  |       y )NTFr   )r^   r_   r   r  r   r   r`   r   r   r  r  r  r  r~   r   )r.   rt  rI   rJ   r   
remove_tagr;  r   s           r0   tag_selectionzNoteBuffer.tag_selection  sN   !!#446LUC ::<LJ;&"
((*11(;"**3/!3'//4%*
 --/ #**3/!3 $$T^^HeS%IJ$$T\\(E3%GH ;& ,, 6D{*((//56 4+++  ''1  ''1r2   c                 |   g }|t         v rSt         D ]J  }||k(  s|dk(  r| j                  |||      }t        |j                        dkD  s:|j	                  |       L |dk7  r0|j	                  t        | |||             | j                  |||       | j                          t        |      dk(  r|d   S t        | S )Nr    r   rk   )	r  r  rE   r   r   r   r   rE  r   )r.   rt  rI   rJ   r  font_tag_namer   s          r0   r  zNoteBuffer.add_tag(  s    {"!, + H,0IucBv}}%)NN6*+ xNN9T8UC@A""8UC8w<11:"G,,r2   c                 j    t        | |||d      }| j                  |||       | j                          |S r+   )r   r   rE  )r.   rt  rI   rJ   r   s        r0   r  zNoteBuffer.strip_tag<  s7    45#u=%5r2   c                    | j                         5  | j                  |      }t        d|dd      }|j                  d| j                         | j
                  j                  ||       t        | |      cd d d        S # 1 sw Y   y xY w)NTri  )visibleactivemargin_right
margin_toptoggled)rW  create_child_anchorr   r  rE  r  add_child_at_anchorrm   )r.   a_iterr{   rw   check_buttons        r0   r   zNoteBuffer.add_check_buttonC  sx    !!# 	4--f5F#Dq]^_L  D,@,@AII)),?%dF3	4 	4 	4s   A$A??Bc                     | j                         5  | j                  |      }t        j                  ddd      }| j                  j                  ||       t        | |      cd d d        S # 1 sw Y   y xY w)NTzmenu-bullet   )r  	icon_name
pixel_size)rW  r  r   ru   r  r  rm   )r.   r  rw   rp   s       r0   r   zNoteBuffer.add_bulletL  sd    !!# 	4--f5FYYt}QSTFII))&&9%dF3	4 	4 	4s   AA,,A5c           	         g }| j                         5  | j                         r| j                         \  }}n!| j                  | j	                               x}}|j                         }|j                         }d}t        ||dz         D ]%  }| j                  |      j                         #d} n t        ||dz         D ]  }|rQ| j                  |      j                         }	|	't        | |	d      }
|
j                          |j                  |
       V|j                  | j                  | j                  |                    t        |      r| j                  t        |        d d d        y # 1 sw Y   y xY wNTrk   F)rW  r^   r_   rb   rc   r   ranger   ry   rm   r~   r   r   rE   r  r   )r.   r   r  rI   rJ   line_index_startline_index_endall_have_checkboxeslinerw   r   s              r0   toggle_checklistzNoteBuffer.toggle_checklistT  sf   !!# 	@%%'#88:"33DOO4EFF$~~/ \\^N"&.0BC ((.??AI*/'
 .0BC W&!2248IIKF)!3D&%!Hv.NN4#8#89N9Nt9T#UVW 7|$$_g%>?5	@ 	@ 	@s   BE3-:E3(BE33E<c           	         g }| j                         5  | j                         r| j                         \  }}n!| j                  | j	                               x}}|j                         }|j                         }d}t        ||dz         D ]%  }| j                  |      j                         #d} n t        ||dz         D ]  }|rQ| j                  |      j                         }	|	't        | |	d      }
|
j                          |j                  |
       V|j                  | j                  | j                  |                    	 d d d        t        |      r| j                  t        |        y y # 1 sw Y   -xY wr  )rW  r^   r_   rb   rc   r   r  r   ry   rm   r~   r   r   rE   r  r   )r.   r   r  rI   rJ   r  r  all_have_bulletsr  rw   r   s              r0   toggle_bulletszNoteBuffer.toggle_bulletsr  si   !!# 	Q%%'#88:"33DOO4EFF$~~/ \\^N#.0BC ((.??AI',$
 .0BC Q#!2248IIKF)!3D&%!Hv.NN4??43H3H3N#OPQ	Q2 w<  '!:; 3	Q 	Qs   BE5-:E5(A E55E>c                    | j                         rt        j                  S | j                  | j	                               }|j                         }|j                          |j                         r|j                         st        j                  S |j                         }|"| j                  ||       t        j                  S t        j                  S r9   )r^   r   r#  rb   rc   r   r   	ends_linestarts_linery   rF   r-  )r.   r   	prev_charrw   s       r0   	on_returnzNoteBuffer.on_return  s    !!#&&&&&t'89KKM	!!)>)>)@&&&++-KK	6*>>!"""r2   c                 (   | j                         r| j                         \  }}n/| j                  | j                               }|j	                         }t        | |||      }| j                         5  |r=|j                  | j                               dk(  r
	 d d d        y |j                          n<|j                  | j                               dk(  r
	 d d d        y |j                          d d d        | j                  |       y # 1 sw Y   xY wrx  )r^   r_   rb   rc   r   r   rW  r`   r  r   rl  r   r  )r.   r   rI   rJ   r   s        r0   shiftzNoteBuffer.shift  s    !!#446LUC))$//*;<E**,CT5#u5!!# 	$==!4!4!671<	$ 	$
 ! ;;t0023q8	$ 	$ !!#	$ 	V$	$ 	$s   2&D!4DDDc                 :    |j                         dk(  rg | _        y y )NrO   )get_namer  )r.   blru  s       r0   r  zNoteBuffer.on_mark_set  s    ==?h&!D 'r2   c           	      l    t        t         | j                  g | j                         d              y r+   )ro  r   get_text
get_boundsr   s    r0   testzNoteBuffer.test  s)    mMDMMD4??+<DeDEFr2   r   )F),r3   r4   r5   rB  r~  r  r  r  r  r   Propertyr  r  SignalSignalFlagsRUN_LASTrm  signal_accumulator_true_handledr  r;   r@  rE  rW  rc  rv  rL   rP   r  r  r  r  r  r  r  r  r   r   r  r  r  r  r  r  rT   rU   s   @r0   r  r  ~  s    
 L LL K& & & & W^^'--66D ' G GII3">H)
'+Z)3V--' &UjnF)P!2F-(44@<<<#&%0"Gr2   r  N)gi.repositoryr   r   r   r   r   utilr   r	   WeightBOLDStyleITALIC	UnderlineSINGLEr  r  r  rV  r)   r7   rW   rm   r   r   r   rs   r   r  r  r,   r2   r0   <module>r     s*   9 8 - u||(()**+K(u556%t,)//00Gs"\]^~&s^o 53F #] #L:] :z# #L. .`g- gVm ,ks ,k\B	G B	Gr2   