
    g
f#                         d Z dZdZdZdZdZddlZddlZdd	lm	Z	 dd
lm
Z
 ddlmZ ddlmZ ddlmZ  G d d      Z G d d      Zd Zy)z(Provides support for a flat review find.z$Id$z
$Revision$z$Date$zLCopyright (c) 2006-2008 Sun Microsystems Inc.Copyright (c) 2022 Igalia, S.L.LGPL    N   )debug)messages)
orca_state)script_manager)Contextc                   "    e Zd ZdZd Zd Zd Zy)_SearchQueryMatchzRepresents a SearchQuery match.c                     |j                   | _        |j                  | _        |j                  | _        |j                  | _        || _        |j                  t        j                        d   | _        y )Nr   )	lineIndex_line	zoneIndex_zone	wordIndex_word	charIndex_char_pattern
getCurrentr	   LINE_lineString)selfcontextpatterns      +/usr/lib/python3/dist-packages/orca/find.py__init__z_SearchQueryMatch.__init__-   sY    &&
&&
&&
&&
"--gll;A>    c                     d| j                   | j                  | j                  | j                  | j                  | j
                  fz  S )NzFSEARCH QUERY MATCH: '%s' (line %i, zone %i, word %i, char %i) for '%s')r   r   r   r   r   r   r   s    r   __str__z_SearchQueryMatch.__str__5   s>    W!!4::tzz4::tzzSWS`S`ab 	br   c                    |sy| j                   |j                   k(  xrj | j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )NF)r   r   r   r   r   )r   others     r   __eq__z_SearchQueryMatch.__eq__9   sy    5#4#44 )zzU[[()zzU[[() zzU[[() zzU[[(		)r   N)__name__
__module____qualname____doc__r   r!   r$    r   r   r   r   *   s    )?b)r   r   c                   L    e 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y)SearchQueryz3Represents a search that the user wants to perform.c                     d| _         d| _        d| _        d| _        d| _        d| _        t        j                  | _        g d| _	        d| _
        d| _        y)a  Creates a new SearchQuery. A searchQuery has the following
           properties:

           searchString     - the string to find
           searchBackwards  - if true, search upward for matches
           caseSensitive    - if true, case counts
           matchEntireWord  - if true, only match on the entire string
           startAtTop       - if true, begin the search from the top of
                              the window, rather than at the current
                              location
           windowWrap       - if true, when the top/bottom edge of the
                              window is reached wrap to the bottom/top
                              and continue searching
         Fr   r   r   r   N)searchStringsearchBackwardscaseSensitivematchEntireWord
windowWrap
startAtTopr   
LEVEL_INFO
debugLevel_contextLocation_match_wrappedr    s    r   r   zSearchQuery.__init__F   sU      $"$** ,r   c                    d| j                    d}g }| j                  r|j                  d       | j                  r|j                  d       | j                  r|j                  d       | j
                  r|j                  d       | j                  r|j                  d       |r|dd	j                  |       z  }| j                  r|d
| j                   z  }|S )NzFIND QUERY: 'z'.zsearch backwardszcase sensitivezmatch entire wordwrapzstart at topz
 Options: z, z Last match: )	r/   r0   appendr1   r2   r3   r4   joinr8   )r   stringoptionss      r   r!   zSearchQuery.__str__a   s     !2!2 326NN-.NN+,NN./??NN6"??NN>*
499W#5"677F;;dkk]33Fr   c                 X    t         j                  sy t         j                  j                  S N)r   searchQueryr8   r    s    r   previousMatchzSearchQuery.previousMatcht   s     %%%%,,,r   c                 j    |j                   |j                  |j                  |j                  g| _        y rA   )r   r   r   r   r7   r   r   s     r   _saveContextLocationz SearchQuery._saveContextLocationy   s0    !(!2!2!(!2!2!(!2!2!(!2!2!4r   c                 H     |j                   | j                    g d| _        y )Nr.   )
setCurrentr7   rE   s     r   _restoreContextLocationz#SearchQuery._restoreContextLocation   s     D112 ,r   c                 j   |t         j                  k(  rd}n-|t         j                  k(  rd}n|t         j                  k(  rd}ny|j	                  |      d   }t        j                  ||      }d|d|j                  dd	      d
|}t        j                  | j                  |d       t        |      S )Nr   ZONEWORDFr   zFIND: z='
z\nz
'. Match: T)r	   r   rK   rL   r   researchreplacer   printlnr6   bool)r   r   r   contextType
typeStringr>   matchmsgs           r   _currentContextMatchesz"SearchQuery._currentContextMatches   s    ',,&JGLL(JGLL(J##K03		'6*,6tU8SUZ[doosD1E{r   c                 H   |t         j                  k(  rh| j                  r.|j                  t         j                  t         j                        S |j                  t         j                  t         j                        S |t         j                  k(  r| j                  rO|j                  t         j                  t         j                        }|j                  t         j                         |S |j                  t         j                  t         j                        S |t         j                  k(  rw| j                  rN|j                  t         j                  t         j                        }|j                  t         j                         n.|j                  t         j                  t         j                        }|ry| j                  r| j                  ryd| _
        t        j                         j                         }| j                  rO|j                  t        j                          |j                  t         j                  t         j"                        }|S |j                  t        j$                         |j                  t         j                  t         j"                        }|S y)NTF)r	   rL   r0   
goPrevious	WRAP_LINEgoNextrK   goEndr   r3   r9   r   
getManagergetActiveScriptpresentMessager   WRAPPING_TO_BOTTOMWRAP_ALLWRAPPING_TO_TOP)r   r   rS   movedscripts        r   _movezSearchQuery._move   s   ',,&##))',,8I8IJJ>>',,0A0ABB',,&##**7<<9J9JKgll+>>',,0A0ABB',,&##**7<<9J9JKgll+w||W5F5FG??dmm DM#..0@@BF##%%h&A&AB**7<<9I9IJ L %%h&>&>?w||W5E5EFLr   c                     | j                  |||      }|s+| j                  ||      s	 |S | j                  |||      }|s+|S rA   )rW   re   )r   r   r   rS   founds        r   _findMatchInzSearchQuery._findMatchIn   sS    ++GWkJ::g{3  //+NE 
 r   c                    | j                  ||t        j                        sy| j                  ||t        j                        sy| j                  ||t        j                        sy| j                         syt        ||      }|| j                         k7  ry| j                  |t        j                        r"| j                  ||t        j                        ry| j                  |t        j                        r"| j                  ||t        j                        ry| j                  |t        j                        r| j                  ||      S y)NFT)	rh   r	   r   rK   rL   rC   r   re   
_findMatch)r   r   r   candidateMatchs       r   rj   zSearchQuery._findMatch   s      '7<<@  '7<<@  '7<<@!!#*7G<T//11::gw||,!!'7GLLA::gw||,!!'7GLLA::gw||,??7G44r   c                    t        j                  | j                  t        |       d       t        j
                  }| j                  s|t        j                  z  }| j                  rd| j                  z   dz   }n| j                  }t	        j                  ||      }| j                  |       | j                  r|j                  t        j                         d}| j!                  ||      r?| j                  |       t#        ||      | _        d| _        t)        j(                  |      }n| j+                  |       t)        j(                  |       t,        _        |S )zPerforms a search on the string specified in searchQuery.

           Arguments:
           - context: The context from active script

           Returns:
           - The context of the match, if found
        Tz\bNF)r   rQ   r6   strrN   Ur1   
IGNORECASEr2   r/   compilerF   r4   goBeginr	   WINDOWrj   r   r8   r9   copyrI   r   rB   )r   r   flagsregexpr   locations         r   	findQueryzSearchQuery.findQuery   s    	doos4y$7!!BMM)ET...6F&&F**VU+!!'*??OOGNN+??7G,%%g.+GW=DK!DMyy)H((1!%4
r   N)r%   r&   r'   r(   r   r!   rC   rF   rI   rW   re   rh   rj   rw   r)   r   r   r+   r+   C   s8    =6&-
4- !F<!r   r+   c                  L    t        j                   t        j                        } | S )zGrabs the last search query performed from orca_state.

       Returns:
       - A copy of the last search query, if it exists
    )rs   r   rB   )	lastQuerys    r   getLastQueryrz      s     		*001Ir   )r(   __id____version____date____copyright____license__rs   rN   r-   r   r   r   r   flat_reviewr	   r   r+   rz   r)   r   r   <module>r      sX   * /2  	      ) )2{ {zr   