a
    ze$                     @   sR   d Z ddlZddlmZ G dd dZdd ZedkrNdd	lmZ ed
dd dS )zidlelib.filelist    N)
messageboxc                   @   s^   e Zd ZddlmZ dd ZdddZddd	Zdd
dZdd Z	dd Z
dd Zdd ZdS )FileListr   EditorWindowc                 C   s   || _ i | _i | _i | _d S N)rootdictinversedictvars)selfr    r   &/usr/lib/python3.9/idlelib/filelist.py__init__   s    zFileList.__init__Nc                 C   s   |  |}tj|r2tjdd|f | jd d S tj|}|| jv r`| j| }|j	
  |S |rl||S | | ||}|jr|S |  d S d S )Nz
File Errorz%r is a directory.Zmaster)canonizeospathisdirr   	showerrorr   normcaser   topwakeupr   Z	good_load_close)r   filenameactionkeyeditr   r   r   open   s(    



zFileList.openc                 C   s(   |  |}|d ur$|d ur$|| d S r   )r   Zgotoline)r   r   linenor   r   r   r   gotofileline,   s    
zFileList.gotofilelinec                 C   s   |  | |S r   r   )r   r   r   r   r   new1   s    zFileList.newc                 O   s(   t | jD ]}| }|dkr
 q$q
dS )Ncancelbreak)listr	   close)r   argskwdsr   Zreplyr   r   r   close_all_callback4   s
    zFileList.close_all_callbackc                 C   sT   z| j | }W n ty*   td Y d S 0 |r8| j|= | j |= | j sP| j  d S )Nz-Don't know this EditorWindow object.  (close))r	   KeyErrorprintr   r   quit)r   r   r   r   r   r   unregister_maybe_terminate;   s    z#FileList.unregister_maybe_terminatec                 C   s   |   z| j| }W n ty2   td Y d S 0 |jj}|sZ|rL| j|= d | j|< d S | |}tj	
|}||kr|d S || jv r| j| }d | j|< tjdd|f | jd || j|< || j|< |rz| j|= W n ty   Y n0 d S )Nz.Don't know this EditorWindow object.  (rename)zName Conflictz.You now have multiple edit windows open for %rr   )Zsaved_change_hookr	   r(   r)   ior   r   r   r   r   r   r   r   r   )r   r   r   r   ZnewkeyZconflictr   r   r   filename_changed_editG   s>    






zFileList.filename_changed_editc                 C   sF   t j|s:zt  }W n ty*   Y n0 t j||}t j|S r   )r   r   isabsgetcwdOSErrorjoinnormpath)r   r   pwdr   r   r   r   g   s    zFileList.canonize)N)N)N)__name__
__module____qualname__idlelib.editorr   r   r   r   r    r'   r+   r-   r   r   r   r   r   r      s   


 r   c                  C   sd   ddl m}  ddlm} ddlm} |  }|| || |  t|}|  |j	r`|
  d S )Nr   )Tk)fixwordbreaks)fix_scaling)tkinterr8   r7   r9   Zidlelib.runr:   Zwithdrawr   r    r	   Zmainloop)r8   r9   r:   r   flistr   r   r   _testr   s    r=   __main__)mainzidlelib.idle_test.test_filelist   )	verbosity)	__doc__r   r;   r   r   r=   r4   Zunittestr?   r   r   r   r   <module>   s   k