B
    nôb\£u  ã               @   s  d dl mZ d dlZd dlmZ d dlmZmZm	Z	m
Z
mZmZ d dlmZmZmZ d dlmZmZmZmZmZmZmZmZ d dlmZ d dlmZmZ d dlm Z! d d	l"m#Z# d d
l$m%Z%m&Z& dd„ Z'dd„ Z(dd„ Z)G dd„ de	ƒZ*G dd„ deƒZ+G dd„ deƒZ,dS )é    )Úprint_functionN)ÚSignalÚQEventÚQObjectÚQRegExpÚQSizeÚQt)ÚQIconÚQRegExpValidatorÚQTextCursor)ÚQDialogÚQHBoxLayoutÚQLabelÚ	QLineEditÚQListWidgetÚQListWidgetItemÚQVBoxLayoutÚQMainWindow)Ú_)Ú	iteritemsÚto_text_string)Úicon_manager)Úget_search_scores)ÚHelperToolButtonÚHTMLDelegatec             C   sP   g }xB| D ]:}| | }|r
|dkr
|  ¡ r
| ||j|j| ¡ f¡ q
W t|ƒS )zAReturns a list with line number, definition name, fold and token.Zfound_cell_separators)Zis_class_or_functionÚappendZdef_nameÚ
fold_levelZ	get_tokenÚsorted)ÚoedataÚsymbol_listÚkeyÚval© r"   ú:lib/python3.7/site-packages/spyder/widgets/fileswitcher.pyÚprocess_python_symbol_data   s    
r$   c             C   sš  t  d¡}t  d¡}t  d¡}t  d¡}t  d¡}t| ƒ}tttdd„ |D ƒƒƒƒ}dgt|ƒ }dgt|ƒ }	g }
d}xX|D ]P}xJt|ƒD ]>\}}|\}}}}||
krªqŒ||krÂ|
 |¡ |}qŒ|||< qŒW q~W xÂt|ƒD ]¶\}}|| }|d	 d
kr||	|< n"|d	 dkr||	|< n
t	ƒ |	|< |dk	rÜ|d	 dkrÜ|d	 d
krb|d  
d¡rb||	|< qÜ|d	 d
krŠ|d  
d¡rŠ||	|< qÜ||	|< qÜW |	S )z3Return a list of icons for oedata of a python file.ÚclassÚmethodZfunctionZprivate1Zprivate2c             S   s   g | ]}|d  ‘qS )é   r"   )Ú.0Úsr"   r"   r#   ú
<listcomp>3   s    z+get_python_symbol_icons.<locals>.<listcomp>NéÿÿÿÿÚdefé   Ú__r   )ÚimaÚiconr$   r   ÚlistÚsetÚlenÚ	enumerater   r	   Ú
startswith)r   Z
class_iconZmethod_iconZfunction_iconZprivate_iconZsuper_private_iconZsymbolsZfold_levelsÚparentsÚiconsZindexesÚparentÚlevelÚindexÚitemÚlineÚnamer   Útokenr"   r"   r#   Úget_python_symbol_icons(   sF    











r?   c                s¼   | dd… } g ‰ xxt t| |ƒƒD ]f\}\}}|rHˆ  tdƒ¡ d| |< q t t |¡¡\}}ˆ  |tj ¡ dd„ | tj¡D ƒ| |< q W ‡ ‡fdd„‰ˆdd„ t | ƒD ƒƒ d	d„ ˆ D ƒS )
aL  
    Takes a list of paths and tries to "intelligently" shorten them all. The
    aim is to make it clear to the user where the paths differ, as that is
    likely what they care about. Note that this operates on a list of paths
    not on individual paths.

    If the path ends in an actual file name, it will be trimmed off.
    Nzunsaved filec             S   s   g | ]}|r|‘qS r"   r"   )r(   Úpartr"   r"   r#   r*   s   s    z!shorten_paths.<locals>.<listcomp>c                sV  t j}t|  ¡ ƒsd S t|  ¡ ƒd ‰ˆs0d‰n4x2tˆƒD ]&\‰‰t‡‡fdd„|  ¡ D ƒƒs:P q:W ˆdkrrd}nzˆdkr„ˆd }n2ˆdkr¢ˆd | ˆd  }nd| ˆˆd   }x4| D ],}ˆ|  || 7  < | | ˆd … | |< q¼W xb| rPd|  ‰ }x†‡ fdd	„| ¡ D ƒ}|r.ˆ dkr,|}P tt	|ƒƒ\}‰‡ ‡fd
d	„| ¡ D ƒ}t
|ƒt
|ƒksrˆ dkr€|}ˆ d7 ‰ nP qW tt	|ƒƒ\}‰ˆ dkr¨d}nPˆ dkr¼ˆd }n<ˆ dkrÜˆd | ˆd  }nˆd d | ˆˆ d   }x:| ¡ D ].}ˆ|  |ˆ dkr|nd 7  < | |= qW ˆ‡ fdd	„| ¡ D ƒƒ qðW d S )Nr   c             3   s&   | ]}t |ƒˆ ko|ˆ  ˆkV  qd S )N)r3   )r(   Útoks)r)   Ú
sample_valr"   r#   ú	<genexpr>ƒ   s   z7shorten_paths.<locals>.recurse_level.<locals>.<genexpr>Ú r-   r'   z...c                s"   i | ]\}}t |ƒˆ kr||“qS r"   )r3   )r(   ÚidxrA   )Úkr"   r#   ú
<dictcomp>š   s    z8shorten_paths.<locals>.recurse_level.<locals>.<dictcomp>c                s&   i | ]\}}|ˆ  ˆˆ  kr||“qS r"   r"   )r(   rE   rA   )rF   Úsample_toksr"   r#   rG   ¢   s    c                s   i | ]\}}|ˆ d … |“qS )Nr"   )r(   rE   rA   )rF   r"   r#   rG   ¶   s    )ÚosÚsepÚanyÚvaluesr1   r4   ÚallÚitemsÚnextr   r3   Úkeys)Z	level_idxrJ   Z
short_formrE   ÚgroupZprospective_groupr   )Únew_path_listÚrecurse_level)rF   r)   rH   rB   r#   rS   u   s`    










"z$shorten_paths.<locals>.recurse_levelc             S   s   i | ]\}}|r||“qS r"   r"   )r(   ÚiZplr"   r"   r#   rG   ¸   s    z!shorten_paths.<locals>.<dictcomp>c             S   s   g | ]}|  tj¡‘qS r"   )ÚrstriprI   rJ   )r(   Úpathr"   r"   r#   r*   º   s    )	r4   Úzipr   r   ÚospÚ
splitdriveÚdirnamerJ   Úsplit)Ú	path_listZ
is_unsavedZiirV   Zis_unsavZdriver"   )rR   rS   r#   Úshorten_paths[   s    
Cr]   c                   s8   e Zd ZdZddg\ZZeƒ Zeƒ Z‡ fdd„Z	‡  Z
S )ÚKeyPressFilterzDUse with `installEventFilter` to get up/down arrow key press signal.r+   r-   c                sR   |  ¡ tjkr@| ¡ tjkr(| j ¡  n| ¡ tjkr@| j	 ¡  t
t| ƒ ||¡S )N)Útyper   ZKeyPressr    r   ZKey_UpÚsig_up_key_pressedÚemitZKey_DownÚsig_down_key_pressedÚsuperr^   ÚeventFilter)ÚselfÚsrcÚe)Ú	__class__r"   r#   rd   Ä   s    
zKeyPressFilter.eventFilter)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZUPZDOWNr   r`   rb   rd   Ú__classcell__r"   r"   )rh   r#   r^   ½   s
   r^   c                   s$   e Zd ZdZdZ‡ fdd„Z‡  ZS )ÚFilesFilterLinez'QLineEdit used to filter files by name.Fc                s   d| _ tt| ƒ |¡S )z«
        Detect when the focus goes out of this widget.

        This is used to make the file switcher leave focus on the
        last selected file by the user.
        T)Úclicked_outsiderc   r   ÚfocusOutEvent)re   Zevent)rh   r"   r#   rp   Ô   s    zFilesFilterLine.focusOutEvent)ri   rj   rk   rl   ro   rp   rm   r"   r"   )rh   r#   rn   Î   s   rn   c                   s„  e Zd ZdZeeeƒZddg\ZZ	dZ
dd„ Zedd„ ƒZed	d
„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Z d/d0„ Z!d1d2„ Z"d3d4„ Z#d5d6„ Z$d7d8„ Z%d9d:„ Z&dPd<d=„Z'd>d?„ Z(d@dA„ Z)dBdC„ Z*dDdE„ Z+dFdG„ Z,dHdI„ Z-dJdK„ Z.‡ fdLdM„Z/dNdO„ Z0‡  Z1S )QÚFileSwitcherzA Sublime-like file switcher.r-   r'   iX  c             C   s¤  t  | |¡ g | _g | _g | _|  ||||¡ d | _| j| _d | _	d | _
d | _d | _d| _tdƒ}tdƒ}t| ƒ| _tƒ | _t| ƒ| _tƒ | _t|| jƒ}|  tjtjB ¡ |  d¡ | j | j¡ | j |¡ | j  |¡ | j !t"| ƒ¡ t#ƒ }	|	 $| j¡ |	 $| j¡ t%ƒ }
|
 &|	¡ |
 $| j¡ |  '|
¡ | j( )| j*¡ | jj+ )| j,¡ | jj- )| j.¡ | jj/ )| j0¡ | jj1 )| j2¡ | jj3 )| j4¡ | jj5 )| jj6¡ d S )NFa+  Press <b>Enter</b> to switch files or <b>Esc</b> to cancel.<br><br>Type to filter filenames.<br><br>Use <b>:number</b> to go to a line, e.g. <b><code>main:42</code></b><br>Use <b>@symbol_text</b> to go to a symbol, e.g. <b><code>@init</code></b><br><br> Press <b>Ctrl+W</b> to close current tab.<br>zQ([A-Za-z0-9_]{0,100}@[A-Za-z0-9_]{0,100})|([A-Za-z0-9_]{0,100}:{0,1}[0-9]{0,100})gffffffî?)7r   Ú__init__Úplugins_tabsÚplugins_dataÚplugins_instancesÚ
add_pluginÚpluginÚ	FILE_MODEÚmodeÚinitial_cursorsÚinitial_pathÚinitial_widgetÚline_numberÚ
is_visibler   r   rn   Úeditr   Úhelpr   r1   r^   Úfilterr
   ZsetWindowFlagsr   ZPopupZFramelessWindowHintZsetWindowOpacityZinstallEventFilterZsetValidatorÚ
setToolTipZsetItemDelegater   r   Z	addWidgetr   Z	addLayoutZ	setLayoutZrejectedZconnectÚrestore_initial_stater`   Úprevious_rowrb   Únext_rowZreturnPressedÚacceptZtextChangedÚsetupZitemSelectionChangedÚitem_selection_changedZclickedÚsetFocus)re   r8   rw   ÚtabsÚdatar0   Z	help_textZregexZregex_validatorZedit_layoutZlayoutr"   r"   r#   rr   é   sN    	




zFileSwitcher.__init__c                sB   g }x8| j D ].‰ |  ˆ ¡‰|‡ ‡fdd„tˆ ¡ ƒD ƒ7 }qW |S )Nc                s   g | ]}ˆ  |¡ˆ f‘qS r"   )Úwidget)r(   r:   )rw   rŠ   r"   r#   r*   ,  s   z(FileSwitcher.widgets.<locals>.<listcomp>)ru   Úget_plugin_tabwidgetÚrangeÚcount)re   Úwidgetsr"   )rw   rŠ   r#   r   '  s    
zFileSwitcher.widgetsc          	   C   sL   g }xB| j D ]8}y|d  ¡ }W n tk
r8   d}Y nX | |¡ qW |S )Nr   )r   Zget_line_countÚAttributeErrorr   )re   Ú
line_countrŒ   Zcurrent_line_countr"   r"   r#   r’   0  s    
zFileSwitcher.line_countc             C   s.   g }x$| j D ]\}}|dd„ |D ƒ7 }qW |S )Nc             S   s   g | ]}t |d dƒ‘qS )Znewly_createdF)Úgetattr)r(   Útdr"   r"   r#   r*   ?  s    z,FileSwitcher.save_status.<locals>.<listcomp>)rt   )re   Úsave_statusÚdar0   r"   r"   r#   r•   ;  s    zFileSwitcher.save_statusc             C   s4   g }x*| j D ] }|  |¡}|dd„ |D ƒ7 }qW |S )Nc             S   s   g | ]}t |d dƒ‘qS )ÚfilenameN)r“   )r(   r”   r"   r"   r#   r*   G  s    z&FileSwitcher.paths.<locals>.<listcomp>)ru   Úget_plugin_data)re   Úpathsrw   r–   r"   r"   r#   r™   B  s
    
zFileSwitcher.pathsc             C   s4   g }x*| j D ] }|  |¡}|dd„ |D ƒ7 }qW |S )Nc             S   s    g | ]}t j t|d dƒ¡‘qS )r—   N)rI   rV   Úbasenamer“   )r(   r”   r"   r"   r#   r*   O  s   z*FileSwitcher.filenames.<locals>.<listcomp>)ru   r˜   )re   Ú	filenamesrw   r–   r"   r"   r#   r›   J  s    
zFileSwitcher.filenamesc                s2   g }x(| j D ]\}‰ |‡ fdd„|D ƒ7 }qW |S )Nc                s   g | ]}ˆ ‘qS r"   r"   )r(   r”   )r0   r"   r#   r*   X  s    z&FileSwitcher.icons.<locals>.<listcomp>)rt   )re   r7   r–   r"   )r0   r#   r7   T  s    zFileSwitcher.iconsc             C   s   | j  |  ¡ d ¡S )N)Úpaths_by_widgetÚgetÚ
get_widget)re   r"   r"   r#   Úcurrent_path[  s    zFileSwitcher.current_pathc             C   s    dd„ | j D ƒ}tt|| jƒƒS )Nc             S   s   g | ]}|d  ‘qS )r   r"   )r(   Úwr"   r"   r#   r*   a  s    z0FileSwitcher.paths_by_widget.<locals>.<listcomp>)r   ÚdictrW   r™   )re   r   r"   r"   r#   rœ   _  s    zFileSwitcher.paths_by_widgetc             C   s    dd„ | j D ƒ}tt| j|ƒƒS )Nc             S   s   g | ]}|d  ‘qS )r   r"   )r(   r    r"   r"   r#   r*   f  s    z0FileSwitcher.widgets_by_path.<locals>.<listcomp>)r   r¡   rW   r™   )re   r   r"   r"   r#   Úwidgets_by_pathd  s    zFileSwitcher.widgets_by_pathc             C   s   t | j ¡ ƒ ¡ S )z9Get the normalized (lowecase) content of the filter text.)r   r   ÚtextÚlower)re   r"   r"   r#   Úfilter_texti  s    zFileSwitcher.filter_textc             C   s   | j  |¡ d S )N)r   ZsetText)re   Ú_strr"   r"   r#   Úset_search_textn  s    zFileSwitcher.set_search_textc          	   C   sr   | j }|  ¡ | _i | _xVt| jƒD ]H\}}|| jkr>|| | _y| ¡ | j|| < W q" tk
rh   Y q"X q"W dS )z/Save initial cursors and initial active widget.N)	r™   rž   r|   rz   r4   r   r{   Z
textCursorr‘   )re   r™   rT   Úeditorr"   r"   r#   Úsave_initial_stateq  s    


zFileSwitcher.save_initial_statec             C   s   d| _ t | ¡ | j ¡  d S )NF)r~   r   r†   r1   Úclear)re   r"   r"   r#   r†     s    
zFileSwitcher.acceptc             C   sz   | j  ¡  d| _| j}| jjsvx0| jD ]&}| j| }||kr&|  || |¡ q&W | j| j	krv| j
 | j¡}| j |¡ dS )z3Restores initial cursors and initial active editor.FN)r1   rª   r~   r¢   r   ro   rz   Úset_editor_cursorr|   rœ   r™   r:   r{   Úsig_goto_filera   )re   r   rV   Úcursorr:   r"   r"   r#   rƒ   †  s    

z"FileSwitcher.restore_initial_statec             C   sÀ   |   ¡ }| ¡ }| j ¡ }| ¡  ¡ d |d  }t|tƒr`|j ¡  ¡ | ¡  ¡  ¡  d }n| j	d d  
¡  ¡  ¡ d }x0|r®| ¡ }|| ¡ 7 }|| ¡ 7 }|  ¡ }q€W |  ||¡ dS )z#Positions the file switcher dialog.r'   r-   r   N)r8   Úgeometryr1   ÚwidthÚ
isinstancer   Ztoolbars_menuÚheightZmenuBarrs   ZtabBarÚtopÚleftZmove)re   r8   Zgeor¯   r³   r²   r"   r"   r#   Úset_dialog_position–  s    

$z FileSwitcher.set_dialog_positionc                sb   g }|r^x6|D ].}t |ƒ}| tj¡ | | ¡ ¡ | ¡ ‰ qW t‡ fdd„|D ƒƒˆ  ¡ fS dS )zp
        Get the max size (width and height) for the elements of a list of
        strings as a QLabel.
        c                s   g | ]}ˆ   |¡d  ‘qS )gÍÌÌÌÌÌô?)r¯   )r(   r)   )Úfmr"   r#   r*   ¸  s    z.FileSwitcher.get_item_size.<locals>.<listcomp>N)	r   ZsetTextFormatr   Z	PlainTextr   r£   ZfontMetricsÚmaxr±   )re   ÚcontentZstringsÚ	rich_textZlabelr"   )rµ   r#   Úget_item_size«  s    
zFileSwitcher.get_item_sizec             C   s   |rŒ|   |¡\}}|  ¡ }| ¡  ¡ d }|| jkr:| j}| j |¡ t|ƒdk r\t|ƒ}nd}|| d }| j |¡ | j 	|| j 
¡ ¡ dS )z
        Adjusts the width and height of the file switcher
        based on the relative size of the parent and content.
        gÍÌÌÌÌÌä?é   g      @N)r¹   r8   r®   r¯   Ú	MAX_WIDTHr1   ZsetMinimumWidthr3   ZsetMinimumHeightZresizer±   )re   r·   r¯   r±   r8   Zrelative_widthZmax_entriesZ
max_heightr"   r"   r#   Úfix_sizeº  s    

zFileSwitcher.fix_sizec             C   s
   | j  ¡ S )z'Gets the item count in the list widget.)r1   r   )re   r"   r"   r#   r   Ö  s    zFileSwitcher.countc             C   s
   | j  ¡ S )z4Returns the current selected row in the list widget.)r1   Z
currentRow)re   r"   r"   r#   Úcurrent_rowÚ  s    zFileSwitcher.current_rowc             C   s   | j  |¡S )z1Sets the current selected row in the list widget.)r1   ZsetCurrentRow)re   Úrowr"   r"   r#   Úset_current_rowÞ  s    zFileSwitcher.set_current_rowc             C   s6   |   ¡ | }d|  kr$|  ¡ k r2n n
|  |¡ dS )z•Select row in list widget based on a number of steps with direction.

        Steps can be positive (next rows) or negative (previous rows).
        r   N)r½   r   r¿   )re   Zstepsr¾   r"   r"   r#   Ú
select_rowâ  s    zFileSwitcher.select_rowc             C   s‚   | j | jkr|  d¡ dS |  ¡ d }|dkr@| j |¡ ¡ }nd}|dkr`d|kr`| j ¡  nd|krt|  d¡ n
|  d¡ dS )z#Select previous row in list widget.r+   Nr-   r   rD   z</b></big><br>éþÿÿÿ)ry   ÚSYMBOL_MODErÀ   r½   r1   r;   r£   ZscrollToTop)re   Úprev_rowÚtitler"   r"   r#   r„   ë  s    
zFileSwitcher.previous_rowc             C   s`   | j | jkr|  d¡ dS |  ¡ d }||  ¡ k r\d| j |¡ ¡ krR|  d¡ n
|  d¡ dS )zSelect next row in list widget.r-   Nz</b></big><br>r'   )ry   rÂ   rÀ   r½   r   r1   r;   r£   )re   r…   r"   r"   r#   r…   ý  s    
zFileSwitcher.next_rowc             C   s(   t dd„ | jd|… D ƒƒ}|| }|S )z(Get the real index of the selected item.c             S   s   g | ]}|d    ¡ ‘qS )r   )r   )r(   Z
other_tabsr"   r"   r#   r*     s   z0FileSwitcher.get_stack_index.<locals>.<listcomp>N)Úsumrs   )re   Ústack_indexÚplugin_indexZother_plugins_countÚ
real_indexr"   r"   r#   Úget_stack_index
  s    zFileSwitcher.get_stack_indexc             C   s2   y|  ¡ j}W n tk
r,   |  ¡ j}Y nX |S )z8Get the data object of the plugin's current tab manager.)Úget_current_tab_managerr‹   r‘   Zclients)re   rw   r‹   r"   r"   r#   r˜     s
    zFileSwitcher.get_plugin_datac             C   s2   y|  ¡ j}W n tk
r,   |  ¡ j}Y nX |S )z6Get the tabwidget of the plugin's current tab manager.)rÊ   rŠ   r‘   Ú	tabwidget)re   rw   rË   r"   r"   r#   r     s
    z!FileSwitcher.get_plugin_tabwidgetNc             C   sF   |r|s|r|r|  |¡S | jr0|  | j¡ ¡ S | jd d  ¡ S dS )zlGet widget by index.

        If no tabs and index specified the current active widget is returned.
        r   N)rŒ   rw   r   ZcurrentWidgetrs   )re   r:   rV   rŠ   r"   r"   r#   rž   *  s
    
zFileSwitcher.get_widgetc             C   sP   |  ¡ }| ¡ }tƒ }||kr*| |¡ n| |¡ | |tj¡ | |¡ dS )zSet the cursor of an editor.N)ZpositionÚanchorr   ZmovePositionZ
KeepAnchorZsetTextCursor)re   r¨   r­   ÚposrÌ   Z
new_cursorr"   r"   r#   r«   6  s    
zFileSwitcher.set_editor_cursorc             C   s6   |r2t |ƒ}y| j |¡ W n tk
r0   Y nX dS )z5Go to specified line number in current active editor.N)Úintrw   Z
go_to_liner‘   )re   r}   r"   r"   r#   Ú	goto_lineC  s    zFileSwitcher.goto_linec             C   s.   y|   ¡  ¡ }W n tk
r(   i }Y nX |S )z,Get the list of symbols present in the file.)rž   Zget_outlineexplorer_datar‘   )re   r   r"   r"   r#   Úget_symbol_listM  s
    
zFileSwitcher.get_symbol_listc             C   s  |   ¡ }|  ¡ r|dkrd| j ¡  ¡ kr>|dkr>|  ¡  | j| jkrøy–| j 	| j
| ¡}| j| d | _| j 	| j¡}|  ||¡}| j || j ¡ ¡ |  | j¡ y| j ¡  |  ¡  W n tk
rÒ   Y nX | j ¡  W n tk
rô   Y nX n| j| }|  |¡ dS )z*List widget item selection change handler.r   z</b></big><br>r-   N)r½   r   r1   ZcurrentItemr£   r…   ry   rx   r™   r:   Úfiltered_pathr   rw   ru   rÉ   r¬   ra   rÊ   rÏ   r}   Zswitch_to_pluginZraise_r‘   r   r‰   Ú
ValueErrorÚfiltered_symbol_lines)re   r¾   rÆ   rÇ   rÈ   r}   r"   r"   r#   rˆ   V  s0    

z#FileSwitcher.item_selection_changedc             C   s¨  t | j| jƒ}| j}| j}g }d|k}|rV| d¡\}}|dkrDd}td| jdd}	nd}t|| jdd}	|  |¡d }
|  |¡ x¶t	|	ƒD ]ª\}}|\}}}|dkrŒd| 
d	d¡ d
 }|rØ|d | j| tdƒ¡7 }|
| j ¡ krú|d || ¡7 }n|d || ¡7 }|r"| j| dks&|sŒ| |||f¡ qŒW g | _d}xt|ƒD ]}|d }|| }|| }d}yˆ| j| d  ¡  d¡}||d krø|d }|d| d 7 }t|ƒ}| |¡ | tddƒ¡ | tj¡ | j |¡ | j |¡ W n   Y nX d}||d 7 }t||ƒ}| |¡ | tddƒ¡ | j |¡ | j |¡ qPW d| j_|| jkr‚|  | j |¡¡ n| jr”|  d¡ || _ |  !|¡ dS )z0Setup list widget content for file list display.ú:rD   Nz
<b>{0}</b>)Útemplater   r+   z<big>ú&z</big>z [{0:} {1:}]Úlinesz<br><i>{0:}</i>r-   z - z<br><big><b>z</b></big><br>é   T)"r]   r™   r•   r7   r[   r   r›   r¹   r¼   r4   ÚreplaceÚformatr’   r   r1   r¯   r   rÑ   r   r   Zget_plugin_titler   r‚   ÚsetSizeHintr   ZsetFlagsr   ZItemIsEditableÚaddItemÚ
files_listr¿   r:   r}   rÏ   )re   r¥   rŸ   Zshort_pathsr™   r7   ÚresultsZtrying_for_line_numberr}   ÚscoresZ	max_widthr:   Úscorer£   r¸   Úscore_valueZ	text_itemrw   ÚresultrV   r0   rÄ   r;   r"   r"   r#   Úsetup_file_listu  s~    






zFileSwitcher.setup_file_listc          
   C   sR  |  d¡\}}|  ¡ }t|ƒ}| j}|  |¡ t|ƒ}dd„ |D ƒ}dd„ |D ƒ}	t||	dd}
g }g }g | _xZt|
ƒD ]N\}}|\}}}|| \}}}| 	|¡ |dkrx| 	||||||| |f¡ qxW d}xlt
|ƒD ]`\}}}}}}}d	| }|d
 }| j 	|¡ | ||¡}t||ƒ}| tddƒ¡ | j |¡ qØW d| j_| j ¡  dS )z2Setup list widget content for symbol list display.ú@c             S   s"   g | ]}|d  |d |d f‘qS )r   r'   é   r"   )r(   r;   r"   r"   r#   r*   Ü  s    z2FileSwitcher.setup_symbol_list.<locals>.<listcomp>c             S   s   g | ]}|d  ‘qS )r-   r"   )r(   r;   r"   r"   r#   r*   Ý  s    z
<b>{0}</b>)rÕ   r+   z{0}{1}z&nbsp;r-   r   é   FN)r[   rÐ   r?   r™   r¼   r$   r   rÓ   r4   r   r   rÚ   r   rÛ   r   r1   rÜ   rÝ   r   r‰   )re   r¥   rŸ   Zsymbol_textr   r7   r™   r   Zline_fold_tokenÚchoicesrß   rÞ   r×   r:   rà   r£   r¸   rá   r<   r   r>   rÕ   r0   Z
fold_spacer}   Ztextliner;   r"   r"   r#   Úsetup_symbol_listË  s>    



zFileSwitcher.setup_symbol_listc             C   st   t | jƒdkr|  ¡  dS | j ¡  | j}| j}d| jk}|rT| j| _|  	||¡ n| j
| _|  ||¡ |  ¡  dS )zSetup list widget content.r   Nrä   )r3   rs   Úcloser1   rª   rŸ   r¥   rÂ   ry   rè   rx   rã   r´   )re   rŸ   r¥   Ztrying_for_symbolr"   r"   r#   r‡     s    

zFileSwitcher.setupc                s   |   ¡  tt| ƒ ¡  dS )z„
        Override Qt method to force an update of the fileswitcher before
        showing it. See Issue #5317 and PR #5389.
        N)r‡   rc   rq   Úshow)re   )rh   r"   r#   rê     s    zFileSwitcher.showc             C   s0   | j  ||f¡ | j ||f¡ | j |¡ dS )z"Add a plugin to display its files.N)rs   r   rt   ru   )re   rw   rŠ   r‹   r0   r"   r"   r#   rv   '  s    zFileSwitcher.add_plugin)NNN)2ri   rj   rk   rl   r   rÎ   Úobjectr¬   rx   rÂ   r»   rr   Úpropertyr   r’   r•   r™   r›   r7   rŸ   rœ   r¢   r¥   r§   r©   r†   rƒ   r´   r¹   r¼   r   r½   r¿   rÀ   r„   r…   rÉ   r˜   r   rž   r«   rÏ   rÐ   rˆ   rã   rè   r‡   rê   rv   rm   r"   r"   )rh   r#   rq   ß   sR   
>	
	


	V=rq   )-Z
__future__r   rI   Úos.pathrV   rX   Zqtpy.QtCorer   r   r   r   r   r   Z
qtpy.QtGuir	   r
   r   Zqtpy.QtWidgetsr   r   r   r   r   r   r   r   Zspyder.config.baser   Zspyder.py3compatr   r   Zspyder.utilsr   r/   Zspyder.utils.stringmatchingr   Zspyder.widgets.helperwidgetsr   r   r$   r?   r]   r^   rn   rq   r"   r"   r"   r#   Ú<module>   s     (3b