
    G@d%                         d Z ddlZddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddZ
d	 Zd
 Zd Z G d de          Z G d de          ZdS )a  Outline explorer API.

You need to declare a OutlineExplorerProxy, and a function for handle the
edit_goto Signal.

class OutlineExplorerProxyCustom(OutlineExplorerProxy):
    ...


def handle_go_to(name, line, text):
    ...

outlineexplorer = OutlineExplorerWidget(None)
oe_proxy = OutlineExplorerProxyCustom(name)
outlineexplorer.set_current_editor(oe_proxy, update=True, clear=False)

outlineexplorer.edit_goto.connect(handle_go_to)
    N)SignalQObject)
QTextBlock)_)running_under_pytestTc              #     K   |                                  sdS |r|                                 } n|                                 } |                                  sdS |Ut          |          }|                                 }|r|D ]\  }}||k    r|V  n|ddd         D ]\  }}||k    r|V  dS |                                  r|                                 }|r*|j        r#|j        j        t          j	        k    r	|j        V  |r|                                 } n|                                 } |                                  dS dS )ai  
    Get cells oedata before or after block in the document.

    Parameters
    ----------
    forward : bool, optional
        Whether to iterate forward or backward from the current block.
    cell_list: list of tuple containing (block_number, oedata)
        This is the list of all cells in a file to avoid having to parse
        the file every time.
    N)
isValidnextprevioussortedblockNumberuserDataoedatadef_typeOutlineExplorerDataCELL)blockforward	cell_list
block_line	cell_liner   datas          Blib/python3.11/site-packages/spyder/plugins/outlineexplorer/api.pydocument_cellsr   !   s      ==??  !

  ==?? 9%%	&&((
 	!%. ! !!	6
** LLL! &/ttt_ ! !!	6
** LLL --// 	%~~ 	K	K(,?,DDD+ 	%JJLLEENN$$E --// 	% 	% 	% 	% 	%    c                     |                                  sdS |                                 }|o |j        o|j        j        t          j        k    S )z*Check if the given block is a cell header.F)r
   r   r   r   r   r   )r   r   s     r   is_cell_headerr   S   sQ    ==?? u>>D AA$(;(@@Br   c                     t          t          t          | d                              }t          |           r|dz   S |S )z&Get the cell index of the given block.Fr      )lenlistr   r   )r   indexs     r   
cell_indexr%   ]   sC    ^E5999::;;Ee qyLr   c                 
   t          |           r|                                 j        }n1	 t          t	          | d                    }n# t
          $ r Y dS w xY w|                                r|j        S t          |           S )zh
    Get the cell name the block is in.

    If the cell is unnamed, return the cell index instead.
    Fr    r   )	r   r   r   r   r   StopIterationhas_namedef_namer%   )r   headers     r   	cell_namer+   e   s     e !!(	.>>>??FF 	 	 	11	  ! %   s   A
 

AAc                        e Zd ZdZ eee          Z ee          Z e            Z	 fdZ
d Zd Zd Zd Zd Zd Zd	 Zd
 Zed             Z xZS )OutlineExplorerProxyz@
    Proxy class between editors and OutlineExplorerWidget.
    c                 d    t          t          |                                            d | _        d S N)superr-   __init__fname)self	__class__s    r   r1   zOutlineExplorerProxy.__init__   s+    "D))22444


r   c                     t           )z2Return whether the editor is a python file or not.NotImplementedErrorr3   s    r   	is_pythonzOutlineExplorerProxy.is_python       !!r   c                     t           )z8Return an unique id, used for identify objects in a dictr6   r8   s    r   get_idzOutlineExplorerProxy.get_id   r:   r   c                     t           )z[Give focus to the editor, called when toogling visibility of
        OutlineExplorerWidget.r6   r8   s    r   
give_focuszOutlineExplorerProxy.give_focus   s
     "!r   c                     t           )z/Return the number of lines of the editor (int).r6   r8   s    r   get_line_countz#OutlineExplorerProxy.get_line_count   r:   r   c                     dS )z;This is used for diferenciate editors in multi-window mode.N r8   s    r   parentzOutlineExplorerProxy.parent   s    tr   c                     t           )zReturn the cursor line number.r6   r8   s    r   get_cursor_line_numberz+OutlineExplorerProxy.get_cursor_line_number   r:   r   c                     t           )z(Returns a list of outline explorer data.r6   r8   s    r   outlineexplorer_data_listz.OutlineExplorerProxy.outlineexplorer_data_list   r:   r   c                     t           )zRequest current editor symbols.r6   r8   s    r   request_symbolsz$OutlineExplorerProxy.request_symbols   r:   r   c                     dS )z)Check if the associated editor is cloned.FrB   r8   s    r   	is_clonedzOutlineExplorerProxy.is_cloned   s	     ur   )__name__
__module____qualname____doc__r   intsig_cursor_position_changedr#   !sig_outline_explorer_data_changedsig_start_outline_spinnerr1   r9   r<   r>   r@   rC   rE   rG   rI   propertyrK   __classcell__r4   s   @r   r-   r-   z   s         #)&c"2"2(.t% &    " " "" " "" " "
" " "  " " "" " "" " "   X    r   r-   c                        e Zd Z e ed                    \  ZZZZZ	dZ
dZ e            Z	 	 d fd	Zd Zd Zd Zd	 Zd
 Zd Zed             Zej        d             Zd Zd Zd Zd Z xZS )r      defclassNc                     t          t          |                                            || _        || _        || _        || _        || _        t                      r	|| _	        dS t          |          | _	        dS )z
        Args:
            text (str)
            fold_level (int)
            def_type (int): [CLASS, FUNCTION, STATEMENT, COMMENT, CELL]
            def_name (str)
            color (PyQt.QtGui.QTextCharFormat)
        N)r0   r   r1   text
fold_levelr   r)   colorr   r   r   )r3   r   r\   r]   r   r)   r^   r4   s          r   r1   zOutlineExplorerData.__init__   ss     	!4((11333	$  
!! 	+DJJJ $E**DJJJr   c                 ,    | j         | j        | j        fvS r/   r   CLASSFUNCTIONr8   s    r   is_not_class_nor_functionz-OutlineExplorerData.is_not_class_nor_function   s    }TZ$???r   c                 ,    | j         | j        | j        fv S r/   r`   r8   s    r   is_class_or_functionz(OutlineExplorerData.is_class_or_function   s    }T] ;;;r   c                 ,    | j         | j        | j        fv S r/   )r   COMMENTr   r8   s    r   
is_commentzOutlineExplorerData.is_comment   s    }ty 999r   c                 4    | j         | j        k    r| j        S d S r/   )r   ra   r)   r8   s    r   get_class_namez"OutlineExplorerData.get_class_name   s!    =DJ&&=  '&r   c                 4    | j         | j        k    r| j        S d S r/   )r   rb   r)   r8   s    r   get_function_namez%OutlineExplorerData.get_function_name   s!    =DM))=  *)r   c                 d    | j         | j        k    r| j        }n| j         | j        k    r| j        }|S r/   )r   rb   FUNCTION_TOKENra   CLASS_TOKEN)r3   tokens     r   	get_tokenzOutlineExplorerData.get_token   s7    =DM))'EE]dj(($Er   c                   	
 | j         | j        k    r| j        S d 	 	|           
g 	
fd}d}t          | j        d          D ]} ||          r|dz  }t                    }d}t          | j        d          D ]} ||          r|dz  }fdt          ||z   dz             D             }|||z
           }||z   dk    r
d	                    |dz             z   S 
S )
zGet the cell name.c                 6    | j         }|st          d          }|S )NzUnnamed Cell)	_def_namer   )r   names     r   get_namez.OutlineExplorerData.def_name.<locals>.get_name   s$    #D )((Kr   c                      |           }dt          j                  z   dz   }t          j        ||          }|r@|                                d         }|r"                    t          |                     dS dS )N^z(?:, #(\d+))?$r   TF)reescapematchgroupsappendrP   )r   
other_namepatternr{   numberexisting_numbersrv   	self_names        r   check_matchz1OutlineExplorerData.def_name.<locals>.check_match   s    !&))JBIi0003DDGHWj11E * 9$++CKK888t5r   r   Fr    r!   Tc                 "    g | ]}|d z   v	|S )r!   rB   ).0idxr   s     r   
<listcomp>z0OutlineExplorerData.def_name.<locals>.<listcomp>  s2     < < <7*::: :::r   z, #{})r   r   rt   r   r   r"   rangeformat)r3   r   N_prevr   N_fix_previousN_nextfree_indexesr   r   rv   r   s           @@@r   r)   zOutlineExplorerData.def_name   sl    =DI%%>!	 	 	 HTNN		 	 	 	 	 	 	 $TZ??? 	 	F{6"" !-..$TZ>>> 	 	F{6"" !< < < <uVf_q-@'A'A < < < 6N23F?Qw~~cAg6666r   c                     || _         dS )z	Set name.Nrt   )r3   values     r   r)   zOutlineExplorerData.def_name  s     r   c                    | j         |j         k    r| j        |j        k    r|j        | _        | j        }|j        | _        |j        | _        | j                                         | j         | j        k    rT| j        |j        k    rdS t          | j
        d          D ]+}|j        | j        |fv r|j                                         ,dS dS )z,Try to update to avoid reloading everything.FTr    )r   r]   r\   rt   r^   
sig_updateemitr   
cell_levelr   r   )r3   otherold_def_namer   s       r   updatezOutlineExplorerData.update   s    MU^++5#333
DI>L"_DNDJO  """}	))?e&666 5,TZFFF 1 1F'DNL+III)..0004ur   c                     | j         }|r|                                sdS |                                }|rt          |d          sdS |j        | k    S )z/Check if the oedata has a valid block attached.Fr   )r   r
   r   hasattrr   )r3   r   	user_datas      r   is_validzOutlineExplorerData.is_valid3  s`    
 	EMMOO 	5NN$$	 		8 < < 	54''r   c                     | j         rdS dS )zCheck if cell has a name.TFr   r8   s    r   r(   zOutlineExplorerData.has_name=  s    > 	45r   c                 `    |                                  sdS | j                                        S )zGet the block number.N)r   r   r   r8   s    r   get_block_numberz$OutlineExplorerData.get_block_numberD  s+    }} 	4z%%'''r   )NNNNN)rL   rM   rN   r#   r   ra   rb   	STATEMENTrg   r   rn   ro   r   r   r1   rc   re   rh   rj   rl   rq   rT   r)   setterr   r   r(   r   rU   rV   s   @r   r   r      sL       04UU1XX-E8YNK JCG&*+ + + + + +.@ @ @< < <: : :! ! !! ! !   2 2 X2h _  _  &( ( (  ( ( ( ( ( ( (r   r   )TN)rO   ry   qtpy.QtCorer   r   
qtpy.QtGuir   spyder.config.baser   r   r   r   r%   r+   r-   r   rB   r   r   <module>r      s   $ 
			 ' ' ' ' ' ' ' ' ! ! ! ! ! !             3 3 3 3 3 3/% /% /% /%dB B B  ! ! !*1 1 1 1 17 1 1 1h[( [( [( [( [(' [( [( [( [( [(r   