
    G@d                         d dl mZ d dlmZ d dlmZmZmZm	Z	 d dl
mZmZmZ d dlmZ d dlmZ d ZdZdZd	Zd
ZdZdZ G d de          ZdS )    N)getexistingdirectory)QEventQtSignalSlot)	QComboBoxQMessageBoxQSizePolicy)_)to_unicode_from_fs                  c                        e Zd ZdZ ee          Zg ddf fd	Zd Zd Z	d Z
d Zd Zd	 Z e            d
             Z e            d             Zd Zd Z xZS )SearchInComboBoxz[
    Non editable combo box handling the path locations of the FindOptions
    widget.
    Nc                 "   t                                          |           |                     t          j        t          j                   |                     t          d                     |                     d           d| _	        d | _
        d | _        d | _        ||| _        |                     t          d                     d}|                     d|t           j                   |                     t          d                     t          d          }|                     d	|t           j                   |                                                     d	d                              d           |                     t          d
                              dd                     t          d          }|                     d|t           j                   |                     d           |                     t          d                     t          d          }|                     d|t           j                   |                     t          d                     t          d          }|                     d|t           j                   |                     d           |D ]}|                     |           | j                            | j                   |                                                     |            d S )NzSearch directoryF zCurrent working directoryzFSearch in all files and directories present on the current Spyder pathr   ProjectzSSearch in all files and directories present on the current project path (if opened)r   File&zSearch in current opened filer      zSelect other directoryz1Search in other folder present on the file systemr   zClear this listz#Clear the list of other directoriesr      )super__init__setSizePolicyr
   	ExpandingFixed
setToolTipr   setEditablepathproject_path	file_pathexternal_pathIDaddItemsetItemDatar   ToolTipRolemodelitem
setEnabledreplaceinsertSeparatoradd_external_pathcurrentIndexChangedconnectpath_selection_changedviewinstallEventFilter)selfexternal_path_historyparentid_ttipr#   	__class__s         Klib/python3.11/site-packages/spyder/plugins/findinfiles/widgets/combobox.pyr   zSearchInComboBox.__init__*   s      ;0+2CDDD,--...	 !?DGQ233444D".111Qy\\""" 5 6 6D".111

!Q**5111QvYY&&sB//000011D".111QQ/00111DEED".111Q())***677D".111Q) 	) 	)D""4(((( (()DEEE		&&t,,,,,    c                    t          j        |          sdS |                     |                     |                     |                     |           |                     |                                 dz
  |t          j                   |                                 t          t          z   k    rA|                     t                     |                                 t          t          z   k    ?dS dS )a@  
        Adds an external path to the combobox if it exists on the file system.
        If the path is already listed in the combobox, it is removed from its
        current position and added back at the end. If the maximum number of
        paths is reached, the oldest external path is removed from the list.
        Nr   )ospexists
removeItemfindTextr(   r)   countr   r*   MAX_PATH_HISTORYEXTERNAL_PATHSr6   r#   s     r<   r0   z"SearchInComboBox.add_external_pathY   s     z$ 	Fd++,,,T)4@@@jjll->>>OON+++ jjll->>>>>>>r=   c                 j      fdt          t                                                     D             S )z<Returns a list of the external paths listed in the combobox.c                 T    g | ]$}t                              |                    %S  )stritemText).0ir6   s     r<   
<listcomp>z7SearchInComboBox.get_external_paths.<locals>.<listcomp>j   s=     > > > DMM!$$%% > > >r=   )rangerE   rC   r6   s   `r<   get_external_pathsz#SearchInComboBox.get_external_pathsh   s@    > > > >~tzz||<<> > > 	>r=   c                     |                                  t          k    r9|                     t                     |                                  t          k    7dS dS )z5Remove all the external paths listed in the combobox.N)rC   rE   rA   rP   s    r<   clear_external_pathsz%SearchInComboBox.clear_external_pathsm   sH    jjll^++OON+++ jjll^++++++r=   c                     |                                  }|t          k    r| j        S |t          k    r| j        S |t
          k    r| j        S | j        S )zh
        Returns the path corresponding to the currently selected item
        in the combobox.
        )currentIndexCWDr#   PROJECTr$   	FILE_PATHr%   r&   )r6   idxs     r<   get_current_searchpathz'SearchInComboBox.get_current_searchpathr   sT    
 !!#::9G^^$$I>!%%r=   c                     |?t          ||                                 dz
            }|t          t          fv rt          n|}nt          }|                     |           dS )z(Set the current index of this combo box.Nr   )minrC   
CLEAR_LISTSELECT_OTHERrV   setCurrentIndex)r6   indexs     r<   set_current_searchpath_indexz-SearchInComboBox.set_current_searchpath_index   s]    tzz||a/00E Z$>>>CCEEEEU#####r=   c                 D    |                                  t          k    rdS dS )z2Returns whether the current search path is a file.TF)rU   rX   rP   s    r<   is_file_searchzSearchInComboBox.is_file_search   s#    )++45r=   c                    |                                  }|t          k    r|                                 }t          |          dk    rA|                     |           |                     |                                 dz
             dS |                     t                     dS |t          k    rt          j
        | t          d          t          d          t          j        t          j        z            }|t          j        k    r|                                  |                     t                     dS |t          k    r)t!          |                     |                    | _        dS dS )z7Handles when the current index of the combobox changes.r   r   zClear other directoriesz3Do you want to clear the list of other directories?N)rU   r^   select_directorylenr0   r_   rC   rV   r]   r	   questionr   YesNorS   rE   rJ   rK   r&   )r6   rY   r&   replys       r<   r3   z'SearchInComboBox.path_selection_changed   sL    !!, 1133M=!!A%%&&}555$$TZZ\\A%566666$$S)))))J(!566KLLOkn46 6E ''))+++  %%%%%N""!$T]]3%7%7!8!8D #"r=   c                     | j                             d           t          | t          d           | j                  }|r!t          t          j        |                    }| j                             d           |S )zSelect directoryFT)sig_redirect_stdio_requestedemitr   r   r#   r   r?   abspath)r6   	directorys     r<   re   z!SearchInComboBox.select_directory   s}     	)..u555( !!I
 
	
  	C*3;y+A+ABBI)..t444r=   c                    |d| _         |                                                     t          d                              d           |                                 t          k    r|                     t                     dS dS t          j	        |          }|| _         |                                                     t          d                              d           dS )z}
        Sets the project path and disables the project search in the combobox
        if the value of path is None.
        Nr   FT)
r$   r+   r,   rW   r-   rU   r_   rV   r?   rn   rF   s     r<   set_project_pathz!SearchInComboBox.set_project_path   s    
 < $DJJLLgq))44U;;;  ""g--$$S))))) .- ;t$$D $DJJLLgq))44T:::::r=   c                    |                                 t          j        k    r'|                                t          j        k    r|                                                                                                 }|t          k    r| 
                    |           |                                  t          |                                 dz
  |          }|t          k     rdn|}|                                                     |                                                     |d                     |                     |           dS t#          j        | ||          S )z;Used to handle key events on the QListView of the combobox.r   r   T)typer   KeyPresskeyr   
Key_Deleter4   rU   rowrE   rA   	showPopupr\   rC   r_   r+   r`   r   eventFilter)r6   widgeteventr`   	new_indexs        r<   ry   zSearchInComboBox.eventFilter   s   ::<<6?**uyy{{bm/K/KIIKK,,..2244E&&&&&   

q 0%88	!*^!;!;AA			++DJJLL,>,>y!,L,LMMM$$Y///4$T65999r=   )__name__
__module____qualname____doc__r   boolrl   r   r0   rQ   rS   rZ   ra   rc   r   r3   re   rq   ry   __classcell__)r;   s   @r<   r   r   !   s         $*6$<< -/$ -- -- -- -- -- --^, , ,> > >
, , ,
& & &$ $ $   
TVV9 9 V9* 
TVV  V; ; ;: : : : : : :r=   r   )os.pathr#   r?   qtpy.compatr   qtpy.QtCorer   r   r   r   qtpy.QtWidgetsr   r	   r
   spyder.api.translationsr   spyder.utils.encodingr   rV   rW   rX   r^   r]   rE   rD   r   rI   r=   r<   <module>r      s          - , , , , , 0 0 0 0 0 0 0 0 0 0 0 0 > > > > > > > > > > & % % % % % 4 4 4 4 4 4
 
	
 
s: s: s: s: s:y s: s: s: s: s:r=   